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 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Applies a forced text rendering direction if specified by a command-line | |
1345 // switch. | |
1346 void RenderTextHarfBuzz::CheckForcedDirection(UBiDiLevel* level) { | |
msw
2017/05/01 21:55:33
nit: make this a static local function in the line
Kevin Bailey
2017/05/01 22:06:32
Done.
| |
1347 static bool has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1348 switches::kForceTextDirection); | |
1349 if (!has_switch) | |
1350 return; | |
1351 | |
1352 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
1353 if (command_line->HasSwitch(switches::kForceTextDirection)) { | |
1354 std::string force_flag = | |
1355 command_line->GetSwitchValueASCII(switches::kForceTextDirection); | |
1356 | |
1357 if (force_flag == switches::kForceDirectionRTL) | |
1358 *level = UBIDI_RTL; | |
1359 if (force_flag == switches::kForceDirectionLTR) | |
1360 *level = UBIDI_LTR; | |
1361 } | |
1362 } | |
1363 | |
1342 void RenderTextHarfBuzz::ItemizeTextToRuns( | 1364 void RenderTextHarfBuzz::ItemizeTextToRuns( |
1343 const base::string16& text, | 1365 const base::string16& text, |
1344 internal::TextRunList* run_list_out) { | 1366 internal::TextRunList* run_list_out) { |
1345 DCHECK_NE(0U, text.length()); | 1367 DCHECK_NE(0U, text.length()); |
1346 | 1368 |
1347 // If ICU fails to itemize the text, we create a run that spans the entire | 1369 // 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 | 1370 // 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. | 1371 // to misbehave since they expect non-zero text metrics from a non-empty text. |
1350 base::i18n::BiDiLineIterator bidi_iterator; | 1372 base::i18n::BiDiLineIterator bidi_iterator; |
1351 if (!bidi_iterator.Open(text, GetTextDirection(text))) { | 1373 if (!bidi_iterator.Open(text, GetTextDirection(text))) { |
(...skipping 23 matching lines...) Expand all 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 |