OLD | NEW |
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_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/gfx/break_list.h" | 16 #include "ui/gfx/break_list.h" |
17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/font.h" |
18 #include "ui/gfx/render_text_harfbuzz.h" | 19 #include "ui/gfx/render_text_harfbuzz.h" |
19 | 20 |
20 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
21 #include "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
22 #include "ui/gfx/render_text_win.h" | 23 #include "ui/gfx/render_text_win.h" |
23 #endif | 24 #endif |
24 | 25 |
25 #if defined(OS_LINUX) && !defined(USE_OZONE) | 26 #if defined(OS_LINUX) && !defined(USE_OZONE) |
26 #include "ui/gfx/render_text_pango.h" | 27 #include "ui/gfx/render_text_pango.h" |
27 #endif | 28 #endif |
(...skipping 2252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2280 } | 2281 } |
2281 } | 2282 } |
2282 | 2283 |
2283 // Ensure that shaping with a non-existent font does not cause a crash. | 2284 // Ensure that shaping with a non-existent font does not cause a crash. |
2284 TEST_F(RenderTextTest, HarfBuzz_NonExistentFont) { | 2285 TEST_F(RenderTextTest, HarfBuzz_NonExistentFont) { |
2285 RenderTextHarfBuzz render_text; | 2286 RenderTextHarfBuzz render_text; |
2286 render_text.SetText(ASCIIToUTF16("test")); | 2287 render_text.SetText(ASCIIToUTF16("test")); |
2287 render_text.EnsureLayout(); | 2288 render_text.EnsureLayout(); |
2288 ASSERT_EQ(1U, render_text.runs_.size()); | 2289 ASSERT_EQ(1U, render_text.runs_.size()); |
2289 internal::TextRunHarfBuzz* run = render_text.runs_[0]; | 2290 internal::TextRunHarfBuzz* run = render_text.runs_[0]; |
2290 render_text.ShapeRunWithFont(run, "TheFontThatDoesntExist"); | 2291 render_text.ShapeRunWithFont( |
| 2292 run, "TheFontThatDoesntExist", FontRenderParams()); |
2291 } | 2293 } |
2292 | 2294 |
2293 // Ensure an empty run returns sane values to queries. | 2295 // Ensure an empty run returns sane values to queries. |
2294 TEST_F(RenderTextTest, HarfBuzz_EmptyRun) { | 2296 TEST_F(RenderTextTest, HarfBuzz_EmptyRun) { |
2295 internal::TextRunHarfBuzz run; | 2297 internal::TextRunHarfBuzz run; |
2296 const base::string16 kString = ASCIIToUTF16("abcdefgh"); | 2298 const base::string16 kString = ASCIIToUTF16("abcdefgh"); |
2297 scoped_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( | 2299 scoped_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( |
2298 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); | 2300 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); |
2299 ASSERT_TRUE(iter->Init()); | 2301 ASSERT_TRUE(iter->Init()); |
2300 | 2302 |
(...skipping 17 matching lines...) Expand all Loading... |
2318 render_text->ApplyStyle(BOLD, true, Range(0, 3)); | 2320 render_text->ApplyStyle(BOLD, true, Range(0, 3)); |
2319 render_text->SetElideBehavior(ELIDE_TAIL); | 2321 render_text->SetElideBehavior(ELIDE_TAIL); |
2320 | 2322 |
2321 render_text->SetDisplayRect(Rect(0, 0, 500, 100)); | 2323 render_text->SetDisplayRect(Rect(0, 0, 500, 100)); |
2322 EXPECT_EQ(kString, render_text->GetLayoutText()); | 2324 EXPECT_EQ(kString, render_text->GetLayoutText()); |
2323 render_text->SetDisplayRect(Rect(0, 0, render_text->GetContentWidth(), 100)); | 2325 render_text->SetDisplayRect(Rect(0, 0, render_text->GetContentWidth(), 100)); |
2324 EXPECT_EQ(kString, render_text->GetLayoutText()); | 2326 EXPECT_EQ(kString, render_text->GetLayoutText()); |
2325 } | 2327 } |
2326 | 2328 |
2327 } // namespace gfx | 2329 } // namespace gfx |
OLD | NEW |