| 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" | 10 #include "base/command_line.h" |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 level(0), | 651 level(0), |
| 652 script(USCRIPT_INVALID_CODE), | 652 script(USCRIPT_INVALID_CODE), |
| 653 glyph_count(static_cast<size_t>(-1)), | 653 glyph_count(static_cast<size_t>(-1)), |
| 654 font(template_font), | 654 font(template_font), |
| 655 font_size(0), | 655 font_size(0), |
| 656 baseline_offset(0), | 656 baseline_offset(0), |
| 657 baseline_type(0), | 657 baseline_type(0), |
| 658 italic(false), | 658 italic(false), |
| 659 weight(Font::Weight::NORMAL), | 659 weight(Font::Weight::NORMAL), |
| 660 strike(false), | 660 strike(false), |
| 661 diagonal_strike(false), | |
| 662 underline(false) {} | 661 underline(false) {} |
| 663 | 662 |
| 664 TextRunHarfBuzz::~TextRunHarfBuzz() {} | 663 TextRunHarfBuzz::~TextRunHarfBuzz() {} |
| 665 | 664 |
| 666 Range TextRunHarfBuzz::CharRangeToGlyphRange(const Range& char_range) const { | 665 Range TextRunHarfBuzz::CharRangeToGlyphRange(const Range& char_range) const { |
| 667 DCHECK(range.Contains(char_range)); | 666 DCHECK(range.Contains(char_range)); |
| 668 DCHECK(!char_range.is_reversed()); | 667 DCHECK(!char_range.is_reversed()); |
| 669 DCHECK(!char_range.is_empty()); | 668 DCHECK(!char_range.is_empty()); |
| 670 | 669 |
| 671 Range start_glyphs; | 670 Range start_glyphs; |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 &positions[colored_glyphs.start() - glyphs_range.start()], | 1318 &positions[colored_glyphs.start() - glyphs_range.start()], |
| 1320 &run.glyphs[colored_glyphs.start()], colored_glyphs.length()); | 1319 &run.glyphs[colored_glyphs.start()], colored_glyphs.length()); |
| 1321 int start_x = SkScalarRoundToInt( | 1320 int start_x = SkScalarRoundToInt( |
| 1322 positions[colored_glyphs.start() - glyphs_range.start()].x()); | 1321 positions[colored_glyphs.start() - glyphs_range.start()].x()); |
| 1323 int end_x = SkScalarRoundToInt( | 1322 int end_x = SkScalarRoundToInt( |
| 1324 (colored_glyphs.end() == glyphs_range.end()) | 1323 (colored_glyphs.end() == glyphs_range.end()) |
| 1325 ? (SkFloatToScalar(segment.width()) + preceding_segment_widths + | 1324 ? (SkFloatToScalar(segment.width()) + preceding_segment_widths + |
| 1326 SkIntToScalar(origin.x())) | 1325 SkIntToScalar(origin.x())) |
| 1327 : positions[colored_glyphs.end() - glyphs_range.start()].x()); | 1326 : positions[colored_glyphs.end() - glyphs_range.start()].x()); |
| 1328 renderer->DrawDecorations(start_x, origin.y(), end_x - start_x, | 1327 renderer->DrawDecorations(start_x, origin.y(), end_x - start_x, |
| 1329 run.underline, run.strike, | 1328 run.underline, run.strike); |
| 1330 run.diagonal_strike); | |
| 1331 } | 1329 } |
| 1332 preceding_segment_widths += SkFloatToScalar(segment.width()); | 1330 preceding_segment_widths += SkFloatToScalar(segment.width()); |
| 1333 } | 1331 } |
| 1334 } | 1332 } |
| 1335 | 1333 |
| 1336 renderer->EndDiagonalStrike(); | |
| 1337 | |
| 1338 UndoCompositionAndSelectionStyles(); | 1334 UndoCompositionAndSelectionStyles(); |
| 1339 } | 1335 } |
| 1340 | 1336 |
| 1341 size_t RenderTextHarfBuzz::GetRunContainingCaret( | 1337 size_t RenderTextHarfBuzz::GetRunContainingCaret( |
| 1342 const SelectionModel& caret) { | 1338 const SelectionModel& caret) { |
| 1343 DCHECK(!update_display_run_list_); | 1339 DCHECK(!update_display_run_list_); |
| 1344 size_t layout_position = TextIndexToDisplayIndex(caret.caret_pos()); | 1340 size_t layout_position = TextIndexToDisplayIndex(caret.caret_pos()); |
| 1345 LogicalCursorDirection affinity = caret.caret_affinity(); | 1341 LogicalCursorDirection affinity = caret.caret_affinity(); |
| 1346 internal::TextRunList* run_list = GetRunList(); | 1342 internal::TextRunList* run_list = GetRunList(); |
| 1347 for (size_t i = 0; i < run_list->size(); ++i) { | 1343 for (size_t i = 0; i < run_list->size(); ++i) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 DCHECK_LE(text.size(), style.max()); | 1392 DCHECK_LE(text.size(), style.max()); |
| 1397 internal::StyleIterator style(empty_colors, baselines(), weights(), styles()); | 1393 internal::StyleIterator style(empty_colors, baselines(), weights(), styles()); |
| 1398 | 1394 |
| 1399 for (size_t run_break = 0; run_break < text.length();) { | 1395 for (size_t run_break = 0; run_break < text.length();) { |
| 1400 auto run = base::MakeUnique<internal::TextRunHarfBuzz>( | 1396 auto run = base::MakeUnique<internal::TextRunHarfBuzz>( |
| 1401 font_list().GetPrimaryFont()); | 1397 font_list().GetPrimaryFont()); |
| 1402 run->range.set_start(run_break); | 1398 run->range.set_start(run_break); |
| 1403 run->italic = style.style(ITALIC); | 1399 run->italic = style.style(ITALIC); |
| 1404 run->baseline_type = style.baseline(); | 1400 run->baseline_type = style.baseline(); |
| 1405 run->strike = style.style(STRIKE); | 1401 run->strike = style.style(STRIKE); |
| 1406 run->diagonal_strike = style.style(DIAGONAL_STRIKE); | |
| 1407 run->underline = style.style(UNDERLINE); | 1402 run->underline = style.style(UNDERLINE); |
| 1408 run->weight = style.weight(); | 1403 run->weight = style.weight(); |
| 1409 int32_t script_item_break = 0; | 1404 int32_t script_item_break = 0; |
| 1410 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); | 1405 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); |
| 1411 CHECK_GT(static_cast<size_t>(script_item_break), run_break); | 1406 CHECK_GT(static_cast<size_t>(script_item_break), run_break); |
| 1412 CheckForcedDirection(&run->level); | 1407 CheckForcedDirection(&run->level); |
| 1413 // Odd BiDi embedding levels correspond to RTL runs. | 1408 // Odd BiDi embedding levels correspond to RTL runs. |
| 1414 run->is_rtl = (run->level % 2) == 1; | 1409 run->is_rtl = (run->level % 2) == 1; |
| 1415 // Find the length and script of this script run. | 1410 // Find the length and script of this script run. |
| 1416 script_item_break = ScriptInterval(text, run_break, | 1411 script_item_break = ScriptInterval(text, run_break, |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 if (run.underline) | 1718 if (run.underline) |
| 1724 style |= Font::UNDERLINE; | 1719 style |= Font::UNDERLINE; |
| 1725 | 1720 |
| 1726 // Get range relative to the decorated text. | 1721 // Get range relative to the decorated text. |
| 1727 DecoratedText::RangedAttribute attribute( | 1722 DecoratedText::RangedAttribute attribute( |
| 1728 Range(intersection.start() - range.GetMin(), | 1723 Range(intersection.start() - range.GetMin(), |
| 1729 intersection.end() - range.GetMin()), | 1724 intersection.end() - range.GetMin()), |
| 1730 run.font.Derive(0, style, run.weight)); | 1725 run.font.Derive(0, style, run.weight)); |
| 1731 | 1726 |
| 1732 attribute.strike = run.strike; | 1727 attribute.strike = run.strike; |
| 1733 attribute.diagonal_strike = run.diagonal_strike; | |
| 1734 decorated_text->attributes.push_back(attribute); | 1728 decorated_text->attributes.push_back(attribute); |
| 1735 } | 1729 } |
| 1736 } | 1730 } |
| 1737 return true; | 1731 return true; |
| 1738 } | 1732 } |
| 1739 | 1733 |
| 1740 } // namespace gfx | 1734 } // namespace gfx |
| OLD | NEW |