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

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

Issue 971673002: Mac: Implement GetFallbackFontFamilies for Harfbuzz (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150129-MacViews-Bringup5-RTHB-in-Label
Patch Set: Alexei comments Created 5 years, 9 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_harfbuzz.h ('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 <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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/skia/include/core/SkSurface.h" 17 #include "third_party/skia/include/core/SkSurface.h"
18 #include "ui/gfx/break_list.h" 18 #include "ui/gfx/break_list.h"
19 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/color_utils.h" 20 #include "ui/gfx/color_utils.h"
21 #include "ui/gfx/font.h" 21 #include "ui/gfx/font.h"
22 #include "ui/gfx/font_fallback.h"
22 #include "ui/gfx/range/range.h" 23 #include "ui/gfx/range/range.h"
23 #include "ui/gfx/range/range_f.h" 24 #include "ui/gfx/range/range_f.h"
24 #include "ui/gfx/render_text_harfbuzz.h" 25 #include "ui/gfx/render_text_harfbuzz.h"
25 26
26 #if defined(OS_WIN) 27 #if defined(OS_WIN)
27 #include "base/win/windows_version.h" 28 #include "base/win/windows_version.h"
28 #include "ui/gfx/platform_font_win.h" 29 #include "ui/gfx/platform_font_win.h"
29 #endif 30 #endif
30 31
31 using base::ASCIIToUTF16; 32 using base::ASCIIToUTF16;
(...skipping 2530 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 render_text.SetFontList(font_list); 2563 render_text.SetFontList(font_list);
2563 // Korean character "han". 2564 // Korean character "han".
2564 render_text.SetText(WideToUTF16(L"\xd55c")); 2565 render_text.SetText(WideToUTF16(L"\xd55c"));
2565 render_text.EnsureLayout(); 2566 render_text.EnsureLayout();
2566 internal::TextRunList* run_list = render_text.GetRunList(); 2567 internal::TextRunList* run_list = render_text.GetRunList();
2567 ASSERT_EQ(1U, run_list->size()); 2568 ASSERT_EQ(1U, run_list->size());
2568 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); 2569 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs());
2569 } 2570 }
2570 #endif // defined(OS_WIN) 2571 #endif // defined(OS_WIN)
2571 2572
2573 // Ensure that the fallback fonts offered by gfx::GetFallbackFontFamilies() are
2574 // tried. Note this test assumes the font "Arial" doesn't provide a unicode
2575 // glyph for a particular character, and that there exists a system fallback
2576 // font which does.
2577 #if defined(OS_WIN) || defined(OS_MACOSX)
2578 TEST_F(RenderTextTest, HarfBuzz_UnicodeFallback) {
2579 RenderTextHarfBuzz render_text;
2580 render_text.SetFontList(FontList("Arial, 12px"));
2581
2582 // Korean character "han".
2583 render_text.SetText(WideToUTF16(L"\xd55c"));
2584 render_text.EnsureLayout();
2585 internal::TextRunList* run_list = render_text.GetRunList();
2586 ASSERT_EQ(1U, run_list->size());
2587 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs());
2588 }
2589 #endif // defined(OS_WIN) || defined(OS_MACOSX)
2590
2591 // A targeted test for GetFallbackFontFamilies on Mac. It uses a system API that
2592 // only became publicly available in the 10.8 SDK. This test is to ensure it
2593 // behaves sensibly on all supported OS versions.
2594 #if defined(OS_MACOSX)
2595 TEST_F(RenderTextTest, HarfBuzz_GetFallbackFontFamilies) {
2596 std::vector<std::string> fallback_families = GetFallbackFontFamilies("Arial");
Alexei Svitkine (slow) 2015/03/04 16:23:02 Sounds like this should be in font_fallback_mac_un
tapted 2015/03/04 23:44:35 Done.
2597 // If there is only one fallback, it means the only fallback is the font
2598 // itself.
2599 EXPECT_LT(1u, fallback_families.size());
2600 }
2601 #endif // defined(OS_MACOSX)
2602
2572 // Ensure that the width reported by RenderText is sufficient for drawing. Draws 2603 // Ensure that the width reported by RenderText is sufficient for drawing. Draws
2573 // to a canvas and checks whether any pixel beyond the width is colored. 2604 // to a canvas and checks whether any pixel beyond the width is colored.
2574 TEST_F(RenderTextTest, TextDoesntClip) { 2605 TEST_F(RenderTextTest, TextDoesntClip) {
2575 const wchar_t* kTestStrings[] = { L"Save", L"Remove", L"TEST", L"W", L"WWW" }; 2606 const wchar_t* kTestStrings[] = { L"Save", L"Remove", L"TEST", L"W", L"WWW" };
2576 const Size kCanvasSize(300, 50); 2607 const Size kCanvasSize(300, 50);
2577 const int kTestWidth = 10; 2608 const int kTestWidth = 10;
2578 2609
2579 skia::RefPtr<SkSurface> surface = skia::AdoptRef( 2610 skia::RefPtr<SkSurface> surface = skia::AdoptRef(
2580 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); 2611 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()));
2581 scoped_ptr<Canvas> canvas( 2612 scoped_ptr<Canvas> canvas(
(...skipping 20 matching lines...) Expand all
2602 EXPECT_LT(220U, color_utils::GetLuminanceForColor(color)) << string; 2633 EXPECT_LT(220U, color_utils::GetLuminanceForColor(color)) << string;
2603 for (int x = 1; x < kTestWidth; ++x) { 2634 for (int x = 1; x < kTestWidth; ++x) {
2604 color = buffer[width + x + y * kCanvasSize.width()]; 2635 color = buffer[width + x + y * kCanvasSize.width()];
2605 EXPECT_EQ(SK_ColorWHITE, color) << string; 2636 EXPECT_EQ(SK_ColorWHITE, color) << string;
2606 } 2637 }
2607 } 2638 }
2608 } 2639 }
2609 } 2640 }
2610 2641
2611 } // namespace gfx 2642 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698