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

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

Issue 2853523002: [rendertext,i18n] Added flag to force RTL rendering (Closed)
Patch Set: Corrected ordering and text, added cached look-ups Created 3 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
OLDNEW
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
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 bool HasForcedTextDirectionSwitch() {
msw 2017/05/01 20:56:18 ditto nit: "// Get the cached switch presence; avo
Kevin Bailey 2017/05/01 21:21:42 Done. Again, absorbed code.
612 static bool value = base::CommandLine::ForCurrentProcess()->HasSwitch(
613 switches::kForceTextDirection);
614 return value;
615 }
616
609 } // namespace 617 } // namespace
610 618
611 namespace internal { 619 namespace internal {
612 620
613 #if !defined(OS_MACOSX) 621 #if !defined(OS_MACOSX)
614 sk_sp<SkTypeface> CreateSkiaTypeface(const Font& font, 622 sk_sp<SkTypeface> CreateSkiaTypeface(const Font& font,
615 bool italic, 623 bool italic,
616 Font::Weight weight) { 624 Font::Weight weight) {
617 SkFontStyle skia_style( 625 SkFontStyle skia_style(
618 static_cast<int>(weight), SkFontStyle::kNormal_Width, 626 static_cast<int>(weight), SkFontStyle::kNormal_Width,
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 return SelectionModel(position, CURSOR_BACKWARD); 1340 return SelectionModel(position, CURSOR_BACKWARD);
1333 } 1341 }
1334 1342
1335 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun( 1343 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun(
1336 const internal::TextRunHarfBuzz* run) { 1344 const internal::TextRunHarfBuzz* run) {
1337 size_t position = DisplayIndexToTextIndex(run->range.end()); 1345 size_t position = DisplayIndexToTextIndex(run->range.end());
1338 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); 1346 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD);
1339 return SelectionModel(position, CURSOR_FORWARD); 1347 return SelectionModel(position, CURSOR_FORWARD);
1340 } 1348 }
1341 1349
1350 void RenderTextHarfBuzz::CheckForcedDirection(UBiDiLevel* level) {
msw 2017/05/01 20:56:18 nit: "// Applies a forced direction if specified b
Kevin Bailey 2017/05/01 21:21:42 Done.
1351 if (!HasForcedTextDirectionSwitch())
1352 return;
1353
1354 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1355 if (command_line->HasSwitch(switches::kForceTextDirection)) {
1356 std::string force_flag =
1357 command_line->GetSwitchValueASCII(switches::kForceTextDirection);
1358
1359 if (force_flag == switches::kForceDirectionRTL)
1360 *level = UBIDI_RTL;
1361 if (force_flag == switches::kForceDirectionLTR)
1362 *level = UBIDI_LTR;
1363 }
1364 }
1365
1342 void RenderTextHarfBuzz::ItemizeTextToRuns( 1366 void RenderTextHarfBuzz::ItemizeTextToRuns(
1343 const base::string16& text, 1367 const base::string16& text,
1344 internal::TextRunList* run_list_out) { 1368 internal::TextRunList* run_list_out) {
1345 DCHECK_NE(0U, text.length()); 1369 DCHECK_NE(0U, text.length());
1346 1370
1347 // If ICU fails to itemize the text, we create a run that spans the entire 1371 // If ICU fails to itemize the text, we create a run that spans the entire
1348 // text. This is needed because leaving the runs set empty causes some clients 1372 // text. This is needed because leaving the runs set empty causes some clients
1349 // to misbehave since they expect non-zero text metrics from a non-empty text. 1373 // to misbehave since they expect non-zero text metrics from a non-empty text.
1350 base::i18n::BiDiLineIterator bidi_iterator; 1374 base::i18n::BiDiLineIterator bidi_iterator;
1351 if (!bidi_iterator.Open(text, GetTextDirection(text))) { 1375 if (!bidi_iterator.Open(text, GetTextDirection(text))) {
(...skipping 23 matching lines...) Expand all
1375 run->range.set_start(run_break); 1399 run->range.set_start(run_break);
1376 run->italic = style.style(ITALIC); 1400 run->italic = style.style(ITALIC);
1377 run->baseline_type = style.baseline(); 1401 run->baseline_type = style.baseline();
1378 run->strike = style.style(STRIKE); 1402 run->strike = style.style(STRIKE);
1379 run->diagonal_strike = style.style(DIAGONAL_STRIKE); 1403 run->diagonal_strike = style.style(DIAGONAL_STRIKE);
1380 run->underline = style.style(UNDERLINE); 1404 run->underline = style.style(UNDERLINE);
1381 run->weight = style.weight(); 1405 run->weight = style.weight();
1382 int32_t script_item_break = 0; 1406 int32_t script_item_break = 0;
1383 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); 1407 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level);
1384 CHECK_GT(static_cast<size_t>(script_item_break), run_break); 1408 CHECK_GT(static_cast<size_t>(script_item_break), run_break);
1409 CheckForcedDirection(&run->level);
1385 // Odd BiDi embedding levels correspond to RTL runs. 1410 // Odd BiDi embedding levels correspond to RTL runs.
1386 run->is_rtl = (run->level % 2) == 1; 1411 run->is_rtl = (run->level % 2) == 1;
1387 // Find the length and script of this script run. 1412 // Find the length and script of this script run.
1388 script_item_break = ScriptInterval(text, run_break, 1413 script_item_break = ScriptInterval(text, run_break,
1389 script_item_break - run_break, &run->script) + run_break; 1414 script_item_break - run_break, &run->script) + run_break;
1390 1415
1391 // Find the next break and advance the iterators as needed. 1416 // Find the next break and advance the iterators as needed.
1392 const size_t new_run_break = std::min( 1417 const size_t new_run_break = std::min(
1393 static_cast<size_t>(script_item_break), 1418 static_cast<size_t>(script_item_break),
1394 TextIndexToGivenTextIndex(text, style.GetRange().end())); 1419 TextIndexToGivenTextIndex(text, style.GetRange().end()));
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 1728
1704 attribute.strike = run.strike; 1729 attribute.strike = run.strike;
1705 attribute.diagonal_strike = run.diagonal_strike; 1730 attribute.diagonal_strike = run.diagonal_strike;
1706 decorated_text->attributes.push_back(attribute); 1731 decorated_text->attributes.push_back(attribute);
1707 } 1732 }
1708 } 1733 }
1709 return true; 1734 return true;
1710 } 1735 }
1711 1736
1712 } // namespace gfx 1737 } // namespace gfx
OLDNEW
« chrome/browser/flag_descriptions.h ('K') | « ui/gfx/render_text_harfbuzz.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698