Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 1941293002: RenderTextMac: Invoke SkiaTextRenderer::SetFontRenderParams() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase? Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/render_text_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 namespace test { 52 namespace test {
53 53
54 class RenderTextTestApi { 54 class RenderTextTestApi {
55 public: 55 public:
56 RenderTextTestApi(RenderText* render_text) : render_text_(render_text) {} 56 RenderTextTestApi(RenderText* render_text) : render_text_(render_text) {}
57 57
58 static SkPaint& GetRendererPaint(internal::SkiaTextRenderer* renderer) { 58 static SkPaint& GetRendererPaint(internal::SkiaTextRenderer* renderer) {
59 return renderer->paint_; 59 return renderer->paint_;
60 } 60 }
61 61
62 static internal::TextRunList* GetHarfbuzzRunList(
63 RenderTextHarfBuzz* harfbuzz) {
64 return harfbuzz->GetRunList();
65 }
66
62 void DrawVisualText(internal::SkiaTextRenderer* renderer) { 67 void DrawVisualText(internal::SkiaTextRenderer* renderer) {
63 render_text_->EnsureLayout(); 68 render_text_->EnsureLayout();
64 render_text_->DrawVisualText(renderer); 69 render_text_->DrawVisualText(renderer);
65 } 70 }
66 71
67 private: 72 private:
68 RenderText* render_text_; 73 RenderText* render_text_;
69 74
70 DISALLOW_COPY_AND_ASSIGN(RenderTextTestApi); 75 DISALLOW_COPY_AND_ASSIGN(RenderTextTestApi);
71 }; 76 };
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 271
267 void DrawVisualText() { 272 void DrawVisualText() {
268 test::RenderTextTestApi test_api(current_); 273 test::RenderTextTestApi test_api(current_);
269 test_api.DrawVisualText(&renderer_); 274 test_api.DrawVisualText(&renderer_);
270 } 275 }
271 276
272 void GetTextLogAndReset(std::vector<TestSkiaTextRenderer::TextLog>* log) { 277 void GetTextLogAndReset(std::vector<TestSkiaTextRenderer::TextLog>* log) {
273 renderer_.GetTextLogAndReset(log); 278 renderer_.GetTextLogAndReset(log);
274 } 279 }
275 280
276 SkTypeface* GetTypeface() { 281 SkPaint& paint() {
277 SkPaint& paint = test::RenderTextTestApi::GetRendererPaint(&renderer_); 282 return test::RenderTextTestApi::GetRendererPaint(&renderer_);
278 return paint.getTypeface(); 283 }
284
285 internal::TextRunList* GetHarfbuzzRunList() {
286 return test::RenderTextTestApi::GetHarfbuzzRunList(&render_text_harfbuzz_);
279 } 287 }
280 288
281 private: 289 private:
282 Canvas canvas_; 290 Canvas canvas_;
283 TestSkiaTextRenderer renderer_; 291 TestSkiaTextRenderer renderer_;
284 RenderText* current_; 292 RenderText* current_;
285 293
286 RenderTextHarfBuzz render_text_harfbuzz_; 294 RenderTextHarfBuzz render_text_harfbuzz_;
287 #if defined(OS_MACOSX) 295 #if defined(OS_MACOSX)
288 RenderTextMac render_text_mac_; 296 RenderTextMac render_text_mac_;
(...skipping 2979 matching lines...) Expand 10 before | Expand all | Expand 10 after
3268 // not map simply to a SkTypeface::Style (the full details in SkFontStyle is 3276 // not map simply to a SkTypeface::Style (the full details in SkFontStyle is
3269 // needed). They also vary depending on the OS version, so set a known font. 3277 // needed). They also vary depending on the OS version, so set a known font.
3270 gfx::FontList font_list(gfx::Font("Arial", 10)); 3278 gfx::FontList font_list(gfx::Font("Arial", 10));
3271 3279
3272 while (backend.Advance()) { 3280 while (backend.Advance()) {
3273 SCOPED_TRACE(testing::Message() << "backend: " << backend.GetName()); 3281 SCOPED_TRACE(testing::Message() << "backend: " << backend.GetName());
3274 backend->SetText(ASCIIToUTF16("x")); 3282 backend->SetText(ASCIIToUTF16("x"));
3275 backend->SetFontList(font_list); 3283 backend->SetFontList(font_list);
3276 3284
3277 backend.DrawVisualText(); 3285 backend.DrawVisualText();
3278 EXPECT_EQ(SkTypeface::kNormal, backend.GetTypeface()->style()); 3286 EXPECT_EQ(SkTypeface::kNormal, backend.paint().getTypeface()->style());
3279 3287
3280 backend->SetStyle(TextStyle::BOLD, true); 3288 backend->SetStyle(TextStyle::BOLD, true);
3281 backend.DrawVisualText(); 3289 backend.DrawVisualText();
3282 EXPECT_EQ(SkTypeface::kBold, backend.GetTypeface()->style()); 3290 EXPECT_EQ(SkTypeface::kBold, backend.paint().getTypeface()->style());
3283 3291
3284 backend->SetStyle(TextStyle::ITALIC, true); 3292 backend->SetStyle(TextStyle::ITALIC, true);
3285 backend.DrawVisualText(); 3293 backend.DrawVisualText();
3286 EXPECT_EQ(SkTypeface::kBoldItalic, backend.GetTypeface()->style()); 3294 EXPECT_EQ(SkTypeface::kBoldItalic, backend.paint().getTypeface()->style());
3287 3295
3288 backend->SetStyle(TextStyle::BOLD, false); 3296 backend->SetStyle(TextStyle::BOLD, false);
3289 backend.DrawVisualText(); 3297 backend.DrawVisualText();
3290 EXPECT_EQ(SkTypeface::kItalic, backend.GetTypeface()->style()); 3298 EXPECT_EQ(SkTypeface::kItalic, backend.paint().getTypeface()->style());
3291 } 3299 }
3292 } 3300 }
3293 3301
3302 // Ensure the painter adheres to RenderText::subpixel_rendering_suppressed().
3303 TEST_F(RenderTextTest, SubpixelRenderingSuppressed) {
3304 RenderTextAllBackends backend;
3305
3306 while (backend.Advance()) {
3307 SCOPED_TRACE(testing::Message() << "backend: " << backend.GetName());
3308 backend->SetText(ASCIIToUTF16("x"));
3309
3310 backend.DrawVisualText();
3311 #if defined(OS_LINUX)
3312 // On Linux, whether subpixel AA is supported is determined by the platform
3313 // FontConfig. Force it into a particular style after computing runs. Other
3314 // platforms use a known default FontRenderParams from a static local.
3315 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering =
3316 FontRenderParams::SUBPIXEL_RENDERING_RGB;
3317 backend.DrawVisualText();
3318 #endif
3319 EXPECT_TRUE(backend.paint().isLCDRenderText());
3320
3321 backend->set_subpixel_rendering_suppressed(true);
3322 backend.DrawVisualText();
3323 #if defined(OS_LINUX)
3324 // For Linux, runs shouldn't be re-calculated, and the suppression of the
3325 // SUBPIXEL_RENDERING_RGB set above should now take effect. But, after
3326 // checking, apply the override anyway to be explicit that it is suppressed.
3327 EXPECT_FALSE(backend.paint().isLCDRenderText());
3328 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering =
3329 FontRenderParams::SUBPIXEL_RENDERING_RGB;
3330 backend.DrawVisualText();
3331 #endif
3332 EXPECT_FALSE(backend.paint().isLCDRenderText());
3333 }
3334 }
3335
3294 } // namespace gfx 3336 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698