OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_harfbuzz.h" | 5 #include "ui/gfx/render_text_harfbuzz.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 | 9 |
| 10 #include "base/command_line.h" |
| 11 #include "base/i18n/base_i18n_switches.h" |
10 #include "base/i18n/bidi_line_iterator.h" | 12 #include "base/i18n/bidi_line_iterator.h" |
11 #include "base/i18n/break_iterator.h" | 13 #include "base/i18n/break_iterator.h" |
12 #include "base/i18n/char_iterator.h" | 14 #include "base/i18n/char_iterator.h" |
13 #include "base/macros.h" | 15 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
15 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
16 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
18 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
19 #include "build/build_config.h" | 21 #include "build/build_config.h" |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 }; | 601 }; |
600 | 602 |
601 // Function object for case insensitive string comparison. | 603 // Function object for case insensitive string comparison. |
602 struct CaseInsensitiveCompare { | 604 struct CaseInsensitiveCompare { |
603 bool operator() (const Font& a, const Font& b) const { | 605 bool operator() (const Font& a, const Font& b) const { |
604 return base::CompareCaseInsensitiveASCII(a.GetFontName(), b.GetFontName()) < | 606 return base::CompareCaseInsensitiveASCII(a.GetFontName(), b.GetFontName()) < |
605 0; | 607 0; |
606 } | 608 } |
607 }; | 609 }; |
608 | 610 |
| 611 // Applies a forced text rendering direction if specified by a command-line |
| 612 // switch. |
| 613 void CheckForcedDirection(UBiDiLevel* level) { |
| 614 static bool has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 615 switches::kForceTextDirection); |
| 616 if (!has_switch) |
| 617 return; |
| 618 |
| 619 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 620 if (command_line->HasSwitch(switches::kForceTextDirection)) { |
| 621 std::string force_flag = |
| 622 command_line->GetSwitchValueASCII(switches::kForceTextDirection); |
| 623 |
| 624 if (force_flag == switches::kForceDirectionRTL) |
| 625 *level = UBIDI_RTL; |
| 626 if (force_flag == switches::kForceDirectionLTR) |
| 627 *level = UBIDI_LTR; |
| 628 } |
| 629 } |
| 630 |
609 } // namespace | 631 } // namespace |
610 | 632 |
611 namespace internal { | 633 namespace internal { |
612 | 634 |
613 #if !defined(OS_MACOSX) | 635 #if !defined(OS_MACOSX) |
614 sk_sp<SkTypeface> CreateSkiaTypeface(const Font& font, | 636 sk_sp<SkTypeface> CreateSkiaTypeface(const Font& font, |
615 bool italic, | 637 bool italic, |
616 Font::Weight weight) { | 638 Font::Weight weight) { |
617 SkFontStyle skia_style( | 639 SkFontStyle skia_style( |
618 static_cast<int>(weight), SkFontStyle::kNormal_Width, | 640 static_cast<int>(weight), SkFontStyle::kNormal_Width, |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 run->range.set_start(run_break); | 1397 run->range.set_start(run_break); |
1376 run->italic = style.style(ITALIC); | 1398 run->italic = style.style(ITALIC); |
1377 run->baseline_type = style.baseline(); | 1399 run->baseline_type = style.baseline(); |
1378 run->strike = style.style(STRIKE); | 1400 run->strike = style.style(STRIKE); |
1379 run->diagonal_strike = style.style(DIAGONAL_STRIKE); | 1401 run->diagonal_strike = style.style(DIAGONAL_STRIKE); |
1380 run->underline = style.style(UNDERLINE); | 1402 run->underline = style.style(UNDERLINE); |
1381 run->weight = style.weight(); | 1403 run->weight = style.weight(); |
1382 int32_t script_item_break = 0; | 1404 int32_t script_item_break = 0; |
1383 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); | 1405 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); |
1384 CHECK_GT(static_cast<size_t>(script_item_break), run_break); | 1406 CHECK_GT(static_cast<size_t>(script_item_break), run_break); |
| 1407 CheckForcedDirection(&run->level); |
1385 // Odd BiDi embedding levels correspond to RTL runs. | 1408 // Odd BiDi embedding levels correspond to RTL runs. |
1386 run->is_rtl = (run->level % 2) == 1; | 1409 run->is_rtl = (run->level % 2) == 1; |
1387 // Find the length and script of this script run. | 1410 // Find the length and script of this script run. |
1388 script_item_break = ScriptInterval(text, run_break, | 1411 script_item_break = ScriptInterval(text, run_break, |
1389 script_item_break - run_break, &run->script) + run_break; | 1412 script_item_break - run_break, &run->script) + run_break; |
1390 | 1413 |
1391 // Find the next break and advance the iterators as needed. | 1414 // Find the next break and advance the iterators as needed. |
1392 const size_t new_run_break = std::min( | 1415 const size_t new_run_break = std::min( |
1393 static_cast<size_t>(script_item_break), | 1416 static_cast<size_t>(script_item_break), |
1394 TextIndexToGivenTextIndex(text, style.GetRange().end())); | 1417 TextIndexToGivenTextIndex(text, style.GetRange().end())); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 | 1726 |
1704 attribute.strike = run.strike; | 1727 attribute.strike = run.strike; |
1705 attribute.diagonal_strike = run.diagonal_strike; | 1728 attribute.diagonal_strike = run.diagonal_strike; |
1706 decorated_text->attributes.push_back(attribute); | 1729 decorated_text->attributes.push_back(attribute); |
1707 } | 1730 } |
1708 } | 1731 } |
1709 return true; | 1732 return true; |
1710 } | 1733 } |
1711 | 1734 |
1712 } // namespace gfx | 1735 } // namespace gfx |
OLD | NEW |