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

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

Issue 2853523002: [rendertext,i18n] Added flag to force RTL rendering (Closed)
Patch Set: 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 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 return SelectionModel(position, CURSOR_BACKWARD); 1334 return SelectionModel(position, CURSOR_BACKWARD);
1333 } 1335 }
1334 1336
1335 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun( 1337 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun(
1336 const internal::TextRunHarfBuzz* run) { 1338 const internal::TextRunHarfBuzz* run) {
1337 size_t position = DisplayIndexToTextIndex(run->range.end()); 1339 size_t position = DisplayIndexToTextIndex(run->range.end());
1338 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); 1340 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD);
1339 return SelectionModel(position, CURSOR_FORWARD); 1341 return SelectionModel(position, CURSOR_FORWARD);
1340 } 1342 }
1341 1343
1344 void RenderTextHarfBuzz::CheckForcedDirection(UBiDiLevel* level) {
1345 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1346 if (command_line->HasSwitch(switches::kForceTextDirection)) {
1347 std::string force_flag =
1348 command_line->GetSwitchValueASCII(switches::kForceTextDirection);
1349
1350 if (force_flag == switches::kForceUIDirectionRTL)
1351 *level = UBIDI_RTL;
1352 if (force_flag == switches::kForceUIDirectionLTR)
1353 *level = UBIDI_LTR;
1354 }
1355 }
1356
1342 void RenderTextHarfBuzz::ItemizeTextToRuns( 1357 void RenderTextHarfBuzz::ItemizeTextToRuns(
1343 const base::string16& text, 1358 const base::string16& text,
1344 internal::TextRunList* run_list_out) { 1359 internal::TextRunList* run_list_out) {
1345 DCHECK_NE(0U, text.length()); 1360 DCHECK_NE(0U, text.length());
1346 1361
1347 // If ICU fails to itemize the text, we create a run that spans the entire 1362 // 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 1363 // 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. 1364 // to misbehave since they expect non-zero text metrics from a non-empty text.
1350 base::i18n::BiDiLineIterator bidi_iterator; 1365 base::i18n::BiDiLineIterator bidi_iterator;
1351 if (!bidi_iterator.Open(text, GetTextDirection(text))) { 1366 if (!bidi_iterator.Open(text, GetTextDirection(text))) {
(...skipping 23 matching lines...) Expand all
1375 run->range.set_start(run_break); 1390 run->range.set_start(run_break);
1376 run->italic = style.style(ITALIC); 1391 run->italic = style.style(ITALIC);
1377 run->baseline_type = style.baseline(); 1392 run->baseline_type = style.baseline();
1378 run->strike = style.style(STRIKE); 1393 run->strike = style.style(STRIKE);
1379 run->diagonal_strike = style.style(DIAGONAL_STRIKE); 1394 run->diagonal_strike = style.style(DIAGONAL_STRIKE);
1380 run->underline = style.style(UNDERLINE); 1395 run->underline = style.style(UNDERLINE);
1381 run->weight = style.weight(); 1396 run->weight = style.weight();
1382 int32_t script_item_break = 0; 1397 int32_t script_item_break = 0;
1383 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); 1398 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level);
1384 CHECK_GT(static_cast<size_t>(script_item_break), run_break); 1399 CHECK_GT(static_cast<size_t>(script_item_break), run_break);
1400 CheckForcedDirection(&run->level);
msw 2017/04/28 22:04:03 I'm not sure this is needed; doesn't the underlyin
Kevin Bailey 2017/04/29 04:24:03 'GetTextDirection()' is returning RTL, but, when t
msw 2017/05/01 20:56:18 Acknowledged.
1385 // Odd BiDi embedding levels correspond to RTL runs. 1401 // Odd BiDi embedding levels correspond to RTL runs.
1386 run->is_rtl = (run->level % 2) == 1; 1402 run->is_rtl = (run->level % 2) == 1;
1387 // Find the length and script of this script run. 1403 // Find the length and script of this script run.
1388 script_item_break = ScriptInterval(text, run_break, 1404 script_item_break = ScriptInterval(text, run_break,
1389 script_item_break - run_break, &run->script) + run_break; 1405 script_item_break - run_break, &run->script) + run_break;
1390 1406
1391 // Find the next break and advance the iterators as needed. 1407 // Find the next break and advance the iterators as needed.
1392 const size_t new_run_break = std::min( 1408 const size_t new_run_break = std::min(
1393 static_cast<size_t>(script_item_break), 1409 static_cast<size_t>(script_item_break),
1394 TextIndexToGivenTextIndex(text, style.GetRange().end())); 1410 TextIndexToGivenTextIndex(text, style.GetRange().end()));
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 1719
1704 attribute.strike = run.strike; 1720 attribute.strike = run.strike;
1705 attribute.diagonal_strike = run.diagonal_strike; 1721 attribute.diagonal_strike = run.diagonal_strike;
1706 decorated_text->attributes.push_back(attribute); 1722 decorated_text->attributes.push_back(attribute);
1707 } 1723 }
1708 } 1724 }
1709 return true; 1725 return true;
1710 } 1726 }
1711 1727
1712 } // namespace gfx 1728 } // namespace gfx
OLDNEW
« chrome/browser/flag_descriptions.cc ('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