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/i18n/bidi_line_iterator.h" | 10 #include "base/i18n/bidi_line_iterator.h" |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 UpdateRTLSegmentRanges(); | 415 UpdateRTLSegmentRanges(); |
416 line->size.set_width(line->size.width() + segment.width()); | 416 line->size.set_width(line->size.width() + segment.width()); |
417 text_x_ += segment.width(); | 417 text_x_ += segment.width(); |
418 available_width_ -= segment.width(); | 418 available_width_ -= segment.width(); |
419 return; | 419 return; |
420 } | 420 } |
421 } | 421 } |
422 line->segments.push_back(segment); | 422 line->segments.push_back(segment); |
423 | 423 |
424 SkPaint paint; | 424 SkPaint paint; |
425 paint.setTypeface(run.skia_face.get()); | 425 paint.setTypeface(run.skia_face); |
426 paint.setTextSize(SkIntToScalar(run.font_size)); | 426 paint.setTextSize(SkIntToScalar(run.font_size)); |
427 paint.setAntiAlias(run.render_params.antialiasing); | 427 paint.setAntiAlias(run.render_params.antialiasing); |
428 SkPaint::FontMetrics metrics; | 428 SkPaint::FontMetrics metrics; |
429 paint.getFontMetrics(&metrics); | 429 paint.getFontMetrics(&metrics); |
430 | 430 |
431 line->size.set_width(line->size.width() + segment.width()); | 431 line->size.set_width(line->size.width() + segment.width()); |
432 // TODO(dschuyler): Account for stylized baselines in string sizing. | 432 // TODO(dschuyler): Account for stylized baselines in string sizing. |
433 max_descent_ = std::max(max_descent_, metrics.fDescent); | 433 max_descent_ = std::max(max_descent_, metrics.fDescent); |
434 // fAscent is always negative. | 434 // fAscent is always negative. |
435 max_ascent_ = std::max(max_ascent_, -metrics.fAscent); | 435 max_ascent_ = std::max(max_ascent_, -metrics.fAscent); |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 ApplyTextShadows(renderer); | 1137 ApplyTextShadows(renderer); |
1138 ApplyCompositionAndSelectionStyles(); | 1138 ApplyCompositionAndSelectionStyles(); |
1139 | 1139 |
1140 internal::TextRunList* run_list = GetRunList(); | 1140 internal::TextRunList* run_list = GetRunList(); |
1141 for (size_t i = 0; i < lines().size(); ++i) { | 1141 for (size_t i = 0; i < lines().size(); ++i) { |
1142 const internal::Line& line = lines()[i]; | 1142 const internal::Line& line = lines()[i]; |
1143 const Vector2d origin = GetLineOffset(i) + Vector2d(0, line.baseline); | 1143 const Vector2d origin = GetLineOffset(i) + Vector2d(0, line.baseline); |
1144 SkScalar preceding_segment_widths = 0; | 1144 SkScalar preceding_segment_widths = 0; |
1145 for (const internal::LineSegment& segment : line.segments) { | 1145 for (const internal::LineSegment& segment : line.segments) { |
1146 const internal::TextRunHarfBuzz& run = *run_list->runs()[segment.run]; | 1146 const internal::TextRunHarfBuzz& run = *run_list->runs()[segment.run]; |
1147 renderer->SetTypeface(run.skia_face.get()); | 1147 renderer->SetTypeface(run.skia_face); |
1148 renderer->SetTextSize(SkIntToScalar(run.font_size)); | 1148 renderer->SetTextSize(SkIntToScalar(run.font_size)); |
1149 renderer->SetFontRenderParams(run.render_params, | 1149 renderer->SetFontRenderParams(run.render_params, |
1150 subpixel_rendering_suppressed()); | 1150 subpixel_rendering_suppressed()); |
1151 Range glyphs_range = run.CharRangeToGlyphRange(segment.char_range); | 1151 Range glyphs_range = run.CharRangeToGlyphRange(segment.char_range); |
1152 std::unique_ptr<SkPoint[]> positions(new SkPoint[glyphs_range.length()]); | 1152 std::unique_ptr<SkPoint[]> positions(new SkPoint[glyphs_range.length()]); |
1153 SkScalar offset_x = preceding_segment_widths - | 1153 SkScalar offset_x = preceding_segment_widths - |
1154 ((glyphs_range.GetMin() != 0) | 1154 ((glyphs_range.GetMin() != 0) |
1155 ? run.positions[glyphs_range.GetMin()].x() | 1155 ? run.positions[glyphs_range.GetMin()].x() |
1156 : 0); | 1156 : 0); |
1157 for (size_t j = 0; j < glyphs_range.length(); ++j) { | 1157 for (size_t j = 0; j < glyphs_range.length(); ++j) { |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 sk_sp<SkTypeface> skia_face( | 1474 sk_sp<SkTypeface> skia_face( |
1475 internal::CreateSkiaTypeface(font, run->italic, run->weight)); | 1475 internal::CreateSkiaTypeface(font, run->italic, run->weight)); |
1476 if (!skia_face) | 1476 if (!skia_face) |
1477 return false; | 1477 return false; |
1478 | 1478 |
1479 run->skia_face = skia_face; | 1479 run->skia_face = skia_face; |
1480 run->font = font; | 1480 run->font = font; |
1481 run->render_params = params; | 1481 run->render_params = params; |
1482 | 1482 |
1483 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( | 1483 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( |
1484 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params, | 1484 run->skia_face, SkIntToScalar(run->font_size), run->render_params, |
1485 subpixel_rendering_suppressed()); | 1485 subpixel_rendering_suppressed()); |
1486 | 1486 |
1487 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz | 1487 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz |
1488 // buffer holds our text, run information to be used by the shaping engine, | 1488 // buffer holds our text, run information to be used by the shaping engine, |
1489 // and the resulting glyph data. | 1489 // and the resulting glyph data. |
1490 hb_buffer_t* buffer = hb_buffer_create(); | 1490 hb_buffer_t* buffer = hb_buffer_create(); |
1491 hb_buffer_add_utf16(buffer, reinterpret_cast<const uint16_t*>(text.c_str()), | 1491 hb_buffer_add_utf16(buffer, reinterpret_cast<const uint16_t*>(text.c_str()), |
1492 text.length(), run->range.start(), run->range.length()); | 1492 text.length(), run->range.start(), run->range.length()); |
1493 hb_buffer_set_script(buffer, ICUScriptToHBScript(run->script)); | 1493 hb_buffer_set_script(buffer, ICUScriptToHBScript(run->script)); |
1494 hb_buffer_set_direction(buffer, | 1494 hb_buffer_set_direction(buffer, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 DCHECK(!update_layout_run_list_); | 1584 DCHECK(!update_layout_run_list_); |
1585 DCHECK(!update_display_run_list_); | 1585 DCHECK(!update_display_run_list_); |
1586 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1586 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
1587 } | 1587 } |
1588 | 1588 |
1589 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1589 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
1590 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1590 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
1591 } | 1591 } |
1592 | 1592 |
1593 } // namespace gfx | 1593 } // namespace gfx |
OLD | NEW |