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

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

Issue 1925033002: RenderText: Don't default-construct gfx::Fonts unnecessarily (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove gfx::Font from RTM completely 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 2689 matching lines...) Expand 10 before | Expand all | Expand 10 after
2700 false 2700 false
2701 }, 2701 },
2702 { // From string "A B C D" to glyphs "d c c ba". 2702 { // From string "A B C D" to glyphs "d c c ba".
2703 { 3, 2, 2, 0 }, 2703 { 3, 2, 2, 0 },
2704 { Range(0, 2), Range(0, 2), Range(2, 3), Range(3, 4) }, 2704 { Range(0, 2), Range(0, 2), Range(2, 3), Range(3, 4) },
2705 { Range(3, 4), Range(3, 4), Range(1, 3), Range(0, 1) }, 2705 { Range(3, 4), Range(3, 4), Range(1, 3), Range(0, 1) },
2706 true 2706 true
2707 }, 2707 },
2708 }; 2708 };
2709 2709
2710 internal::TextRunHarfBuzz run; 2710 internal::TextRunHarfBuzz run((Font()));
2711 run.range = Range(0, 4); 2711 run.range = Range(0, 4);
2712 run.glyph_count = 4; 2712 run.glyph_count = 4;
2713 run.glyph_to_char.resize(4); 2713 run.glyph_to_char.resize(4);
2714 2714
2715 for (size_t i = 0; i < arraysize(cases); ++i) { 2715 for (size_t i = 0; i < arraysize(cases); ++i) {
2716 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 4, 2716 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 4,
2717 run.glyph_to_char.begin()); 2717 run.glyph_to_char.begin());
2718 run.is_rtl = cases[i].is_rtl; 2718 run.is_rtl = cases[i].is_rtl;
2719 2719
2720 for (size_t j = 0; j < 4; ++j) { 2720 for (size_t j = 0; j < 4; ++j) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2783 { Range(10, 20), Range(7, 10), Range(3, 7), Range(0, 3) }, 2783 { Range(10, 20), Range(7, 10), Range(3, 7), Range(0, 3) },
2784 true 2784 true
2785 }, 2785 },
2786 { // From string "A B C D" to glyphs "dc ba". 2786 { // From string "A B C D" to glyphs "dc ba".
2787 { 2, 0 }, 2787 { 2, 0 },
2788 { Range(15, 20), Range(10, 15), Range(5, 10), Range(0, 5) }, 2788 { Range(15, 20), Range(10, 15), Range(5, 10), Range(0, 5) },
2789 true 2789 true
2790 }, 2790 },
2791 }; 2791 };
2792 2792
2793 internal::TextRunHarfBuzz run; 2793 internal::TextRunHarfBuzz run((Font()));
2794 run.range = Range(0, 4); 2794 run.range = Range(0, 4);
2795 run.glyph_count = 2; 2795 run.glyph_count = 2;
2796 run.glyph_to_char.resize(2); 2796 run.glyph_to_char.resize(2);
2797 run.positions.reset(new SkPoint[4]); 2797 run.positions.reset(new SkPoint[4]);
2798 run.width = 20; 2798 run.width = 20;
2799 2799
2800 const base::string16 kString = ASCIIToUTF16("abcd"); 2800 const base::string16 kString = ASCIIToUTF16("abcd");
2801 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( 2801 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator(
2802 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); 2802 kString, base::i18n::BreakIterator::BREAK_CHARACTER));
2803 ASSERT_TRUE(iter->Init()); 2803 ASSERT_TRUE(iter->Init());
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 internal::TextRunList* run_list = render_text.GetRunList(); 2934 internal::TextRunList* run_list = render_text.GetRunList();
2935 ASSERT_EQ(1U, run_list->size()); 2935 ASSERT_EQ(1U, run_list->size());
2936 internal::TextRunHarfBuzz* run = run_list->runs()[0]; 2936 internal::TextRunHarfBuzz* run = run_list->runs()[0];
2937 render_text.ShapeRunWithFont(render_text.text(), 2937 render_text.ShapeRunWithFont(render_text.text(),
2938 Font("TheFontThatDoesntExist", 13), 2938 Font("TheFontThatDoesntExist", 13),
2939 FontRenderParams(), run); 2939 FontRenderParams(), run);
2940 } 2940 }
2941 2941
2942 // Ensure an empty run returns sane values to queries. 2942 // Ensure an empty run returns sane values to queries.
2943 TEST_F(RenderTextTest, HarfBuzz_EmptyRun) { 2943 TEST_F(RenderTextTest, HarfBuzz_EmptyRun) {
2944 internal::TextRunHarfBuzz run; 2944 internal::TextRunHarfBuzz run((Font()));
2945 const base::string16 kString = ASCIIToUTF16("abcdefgh"); 2945 const base::string16 kString = ASCIIToUTF16("abcdefgh");
2946 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( 2946 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator(
2947 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); 2947 kString, base::i18n::BreakIterator::BREAK_CHARACTER));
2948 ASSERT_TRUE(iter->Init()); 2948 ASSERT_TRUE(iter->Init());
2949 2949
2950 run.range = Range(3, 8); 2950 run.range = Range(3, 8);
2951 run.glyph_count = 0; 2951 run.glyph_count = 0;
2952 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5))); 2952 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5)));
2953 EXPECT_EQ(Range(0, 0), run.GetGraphemeBounds(iter.get(), 4).Round()); 2953 EXPECT_EQ(Range(0, 0), run.GetGraphemeBounds(iter.get(), 4).Round());
2954 Range chars; 2954 Range chars;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
3285 backend.DrawVisualText(); 3285 backend.DrawVisualText();
3286 EXPECT_EQ(SkTypeface::kBoldItalic, backend.GetTypeface()->style()); 3286 EXPECT_EQ(SkTypeface::kBoldItalic, backend.GetTypeface()->style());
3287 3287
3288 backend->SetStyle(TextStyle::BOLD, false); 3288 backend->SetStyle(TextStyle::BOLD, false);
3289 backend.DrawVisualText(); 3289 backend.DrawVisualText();
3290 EXPECT_EQ(SkTypeface::kItalic, backend.GetTypeface()->style()); 3290 EXPECT_EQ(SkTypeface::kItalic, backend.GetTypeface()->style());
3291 } 3291 }
3292 } 3292 }
3293 3293
3294 } // namespace gfx 3294 } // 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