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

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

Issue 738363002: Enable subpixel positioning for UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: std::round to std::floor(+0.5) Created 6 years 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_harfbuzz.cc ('k') | ui/gfx/win/direct_write.h » ('j') | 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/break_iterator.h" 10 #include "base/i18n/break_iterator.h"
(...skipping 2138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 for (size_t i = 0; i < arraysize(cases); ++i) { 2149 for (size_t i = 0; i < arraysize(cases); ++i) {
2150 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS, i)); 2150 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS, i));
2151 2151
2152 base::string16 text = WideToUTF16(cases[i]); 2152 base::string16 text = WideToUTF16(cases[i]);
2153 render_text.SetText(text); 2153 render_text.SetText(text);
2154 render_text.EnsureLayout(); 2154 render_text.EnsureLayout();
2155 ASSERT_EQ(1U, render_text.runs_.size()); 2155 ASSERT_EQ(1U, render_text.runs_.size());
2156 internal::TextRunHarfBuzz* run = render_text.runs_[0]; 2156 internal::TextRunHarfBuzz* run = render_text.runs_[0];
2157 2157
2158 base::i18n::BreakIterator* iter = render_text.grapheme_iterator_.get(); 2158 base::i18n::BreakIterator* iter = render_text.grapheme_iterator_.get();
2159 Range first_grapheme_bounds = run->GetGraphemeBounds(iter, 0); 2159 auto first_grapheme_bounds = run->GetGraphemeBounds(iter, 0);
2160 EXPECT_EQ(first_grapheme_bounds, run->GetGraphemeBounds(iter, 1)); 2160 EXPECT_EQ(first_grapheme_bounds, run->GetGraphemeBounds(iter, 1));
2161 Range second_grapheme_bounds = run->GetGraphemeBounds(iter, 2); 2161 auto second_grapheme_bounds = run->GetGraphemeBounds(iter, 2);
2162 EXPECT_EQ(first_grapheme_bounds.end(), second_grapheme_bounds.start()); 2162 EXPECT_EQ(first_grapheme_bounds.second, second_grapheme_bounds.first);
2163 } 2163 }
2164 } 2164 }
2165 2165
2166 // Test the partition of a multi-grapheme cluster into grapheme ranges. 2166 // Test the partition of a multi-grapheme cluster into grapheme ranges.
2167 TEST_F(RenderTextTest, HarfBuzz_SubglyphGraphemePartition) { 2167 TEST_F(RenderTextTest, HarfBuzz_SubglyphGraphemePartition) {
2168 struct { 2168 struct {
2169 uint32 glyph_to_char[2]; 2169 uint32 glyph_to_char[2];
2170 Range bounds[4]; 2170 Range bounds[4];
2171 bool is_rtl; 2171 bool is_rtl;
2172 } cases[] = { 2172 } cases[] = {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2206 2206
2207 for (size_t i = 0; i < arraysize(cases); ++i) { 2207 for (size_t i = 0; i < arraysize(cases); ++i) {
2208 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 2, 2208 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 2,
2209 run.glyph_to_char.begin()); 2209 run.glyph_to_char.begin());
2210 run.is_rtl = cases[i].is_rtl; 2210 run.is_rtl = cases[i].is_rtl;
2211 for (int j = 0; j < 2; ++j) 2211 for (int j = 0; j < 2; ++j)
2212 run.positions[j].set(j * 10, 0); 2212 run.positions[j].set(j * 10, 0);
2213 2213
2214 for (size_t j = 0; j < 4; ++j) { 2214 for (size_t j = 0; j < 4; ++j) {
2215 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j)); 2215 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j));
2216 EXPECT_EQ(cases[i].bounds[j], run.GetGraphemeBounds(iter.get(), j)); 2216 EXPECT_EQ(cases[i].bounds[j],
2217 internal::RoundRangeF(run.GetGraphemeBounds(iter.get(), j)));
2217 } 2218 }
2218 } 2219 }
2219 } 2220 }
2220 2221
2221 TEST_F(RenderTextTest, HarfBuzz_RunDirection) { 2222 TEST_F(RenderTextTest, HarfBuzz_RunDirection) {
2222 RenderTextHarfBuzz render_text; 2223 RenderTextHarfBuzz render_text;
2223 const base::string16 mixed = 2224 const base::string16 mixed =
2224 WideToUTF16(L"\x05D0\x05D1" L"1234" L"\x05D2\x05D3"); 2225 WideToUTF16(L"\x05D0\x05D1" L"1234" L"\x05D2\x05D3");
2225 render_text.SetText(mixed); 2226 render_text.SetText(mixed);
2226 render_text.EnsureLayout(); 2227 render_text.EnsureLayout();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 TEST_F(RenderTextTest, HarfBuzz_EmptyRun) { 2299 TEST_F(RenderTextTest, HarfBuzz_EmptyRun) {
2299 internal::TextRunHarfBuzz run; 2300 internal::TextRunHarfBuzz run;
2300 const base::string16 kString = ASCIIToUTF16("abcdefgh"); 2301 const base::string16 kString = ASCIIToUTF16("abcdefgh");
2301 scoped_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( 2302 scoped_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator(
2302 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); 2303 kString, base::i18n::BreakIterator::BREAK_CHARACTER));
2303 ASSERT_TRUE(iter->Init()); 2304 ASSERT_TRUE(iter->Init());
2304 2305
2305 run.range = Range(3, 8); 2306 run.range = Range(3, 8);
2306 run.glyph_count = 0; 2307 run.glyph_count = 0;
2307 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5))); 2308 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5)));
2308 EXPECT_EQ(Range(0, 0), run.GetGraphemeBounds(iter.get(), 4)); 2309 EXPECT_EQ(Range(0, 0),
2310 internal::RoundRangeF(run.GetGraphemeBounds(iter.get(), 4)));
2309 Range chars; 2311 Range chars;
2310 Range glyphs; 2312 Range glyphs;
2311 run.GetClusterAt(4, &chars, &glyphs); 2313 run.GetClusterAt(4, &chars, &glyphs);
2312 EXPECT_EQ(Range(3, 8), chars); 2314 EXPECT_EQ(Range(3, 8), chars);
2313 EXPECT_EQ(Range(0, 0), glyphs); 2315 EXPECT_EQ(Range(0, 0), glyphs);
2314 } 2316 }
2315 2317
2316 // Ensure a string fits in a display rect with a width equal to the string's. 2318 // Ensure a string fits in a display rect with a width equal to the string's.
2317 TEST_F(RenderTextTest, StringFitsOwnWidth) { 2319 TEST_F(RenderTextTest, StringFitsOwnWidth) {
2318 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 2320 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2366 2368
2367 render_text.SetFontList(font_list); 2369 render_text.SetFontList(font_list);
2368 // Korean character "han". 2370 // Korean character "han".
2369 render_text.SetText(WideToUTF16(L"\xd55c")); 2371 render_text.SetText(WideToUTF16(L"\xd55c"));
2370 render_text.EnsureLayout(); 2372 render_text.EnsureLayout();
2371 ASSERT_EQ(1U, render_text.runs_.size()); 2373 ASSERT_EQ(1U, render_text.runs_.size());
2372 EXPECT_EQ(0U, render_text.runs_[0]->CountMissingGlyphs()); 2374 EXPECT_EQ(0U, render_text.runs_[0]->CountMissingGlyphs());
2373 } 2375 }
2374 #endif // defined(OS_WIN) 2376 #endif // defined(OS_WIN)
2375 2377
2378 // Ensure that the width reported by RenderText is sufficient for drawing. Draws
2379 // to a canvas and checks whether any pixel beyond the width is colored.
2380 TEST_F(RenderTextTest, TextDoesntClip) {
2381 const wchar_t* kTestStrings[] = { L"Save", L"Remove", L"TEST", L"W", L"WWW" };
2382
2383 skia::RefPtr<SkCanvas> sk_canvas =
2384 skia::AdoptRef(SkCanvas::NewRasterN32(300, 50));
2385 scoped_ptr<Canvas> canvas(
2386 Canvas::CreateCanvasWithoutScaling(sk_canvas.get(), 1.0f));
2387 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
2388 render_text->SetDisplayRect(Rect(300, 50));
2389 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
2390 render_text->SetColor(SK_ColorBLACK);
2391
2392 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2393 sk_canvas->clear(SK_ColorWHITE);
2394 render_text->SetText(WideToUTF16(kTestStrings[i]));
2395 render_text->SetStyle(BOLD, true);
2396 render_text->Draw(canvas.get());
2397 int width = render_text->GetStringSize().width();
2398 ASSERT_LT(width, 300);
2399 const uint32* buffer = static_cast<const uint32*>(
2400 sk_canvas->peekPixels(NULL, NULL));
2401 ASSERT_NE(nullptr, buffer);
2402 for (int y = 0; y < 50; ++y) {
2403 EXPECT_EQ(SK_ColorWHITE, buffer[width + y * 300])
2404 << "String: " << kTestStrings[i];
2405 }
2406 }
2407 }
2408
2376 } // namespace gfx 2409 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_harfbuzz.cc ('k') | ui/gfx/win/direct_write.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698