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

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

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/i18n/bidi_line_iterator.h" 10 #include "base/i18n/bidi_line_iterator.h"
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 : width(0.0f), 569 : width(0.0f),
570 preceding_run_widths(0.0f), 570 preceding_run_widths(0.0f),
571 is_rtl(false), 571 is_rtl(false),
572 level(0), 572 level(0),
573 script(USCRIPT_INVALID_CODE), 573 script(USCRIPT_INVALID_CODE),
574 glyph_count(static_cast<size_t>(-1)), 574 glyph_count(static_cast<size_t>(-1)),
575 font_size(0), 575 font_size(0),
576 baseline_offset(0), 576 baseline_offset(0),
577 baseline_type(0), 577 baseline_type(0),
578 font_style(0), 578 font_style(0),
579 weight(gfx::Font::WEIGHT_NORMAL),
579 strike(false), 580 strike(false),
580 diagonal_strike(false), 581 diagonal_strike(false),
581 underline(false) { 582 underline(false) {}
582 }
583 583
584 TextRunHarfBuzz::~TextRunHarfBuzz() {} 584 TextRunHarfBuzz::~TextRunHarfBuzz() {}
585 585
586 Range TextRunHarfBuzz::CharRangeToGlyphRange(const Range& char_range) const { 586 Range TextRunHarfBuzz::CharRangeToGlyphRange(const Range& char_range) const {
587 DCHECK(range.Contains(char_range)); 587 DCHECK(range.Contains(char_range));
588 DCHECK(!char_range.is_reversed()); 588 DCHECK(!char_range.is_reversed());
589 DCHECK(!char_range.is_empty()); 589 DCHECK(!char_range.is_empty());
590 590
591 Range start_glyphs; 591 Range start_glyphs;
592 Range end_glyphs; 592 Range end_glyphs;
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 // Temporarily apply composition underlines and selection colors. 1252 // Temporarily apply composition underlines and selection colors.
1253 ApplyCompositionAndSelectionStyles(); 1253 ApplyCompositionAndSelectionStyles();
1254 1254
1255 // Build the run list from the script items and ranged styles and baselines. 1255 // Build the run list from the script items and ranged styles and baselines.
1256 // Use an empty color BreakList to avoid breaking runs at color boundaries. 1256 // Use an empty color BreakList to avoid breaking runs at color boundaries.
1257 BreakList<SkColor> empty_colors; 1257 BreakList<SkColor> empty_colors;
1258 empty_colors.SetMax(text.length()); 1258 empty_colors.SetMax(text.length());
1259 DCHECK_LE(text.size(), baselines().max()); 1259 DCHECK_LE(text.size(), baselines().max());
1260 for (const BreakList<bool>& style : styles()) 1260 for (const BreakList<bool>& style : styles())
1261 DCHECK_LE(text.size(), style.max()); 1261 DCHECK_LE(text.size(), style.max());
1262 internal::StyleIterator style(empty_colors, baselines(), styles()); 1262 internal::StyleIterator style(empty_colors, baselines(), weights(), styles());
1263 1263
1264 for (size_t run_break = 0; run_break < text.length();) { 1264 for (size_t run_break = 0; run_break < text.length();) {
1265 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; 1265 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz;
1266 run->range.set_start(run_break); 1266 run->range.set_start(run_break);
1267 run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | 1267 run->font_style = (style.style(ITALIC) ? Font::ITALIC : 0);
msw 2016/03/22 01:53:44 nit: convert to bool flag for italic.
Mikus 2016/03/22 14:19:51 Done.
1268 (style.style(ITALIC) ? Font::ITALIC : 0);
1269 run->baseline_type = style.baseline(); 1268 run->baseline_type = style.baseline();
1270 run->strike = style.style(STRIKE); 1269 run->strike = style.style(STRIKE);
1271 run->diagonal_strike = style.style(DIAGONAL_STRIKE); 1270 run->diagonal_strike = style.style(DIAGONAL_STRIKE);
1272 run->underline = style.style(UNDERLINE); 1271 run->underline = style.style(UNDERLINE);
1272 run->weight = style.weight();
1273 int32_t script_item_break = 0; 1273 int32_t script_item_break = 0;
1274 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); 1274 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level);
1275 CHECK_GT(static_cast<size_t>(script_item_break), run_break); 1275 CHECK_GT(static_cast<size_t>(script_item_break), run_break);
1276 // Odd BiDi embedding levels correspond to RTL runs. 1276 // Odd BiDi embedding levels correspond to RTL runs.
1277 run->is_rtl = (run->level % 2) == 1; 1277 run->is_rtl = (run->level % 2) == 1;
1278 // Find the length and script of this script run. 1278 // Find the length and script of this script run.
1279 script_item_break = ScriptInterval(text, run_break, 1279 script_item_break = ScriptInterval(text, run_break,
1280 script_item_break - run_break, &run->script) + run_break; 1280 script_item_break - run_break, &run->script) + run_break;
1281 1281
1282 // Find the next break and advance the iterators as needed. 1282 // Find the next break and advance the iterators as needed.
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 1448
1449 run->glyph_count = 0; 1449 run->glyph_count = 0;
1450 run->width = 0.0f; 1450 run->width = 0.0f;
1451 } 1451 }
1452 1452
1453 bool RenderTextHarfBuzz::ShapeRunWithFont(const base::string16& text, 1453 bool RenderTextHarfBuzz::ShapeRunWithFont(const base::string16& text,
1454 const gfx::Font& font, 1454 const gfx::Font& font,
1455 const FontRenderParams& params, 1455 const FontRenderParams& params,
1456 internal::TextRunHarfBuzz* run) { 1456 internal::TextRunHarfBuzz* run) {
1457 skia::RefPtr<SkTypeface> skia_face = 1457 skia::RefPtr<SkTypeface> skia_face =
1458 internal::CreateSkiaTypeface(font, run->font_style); 1458 internal::CreateSkiaTypeface(font, run->font_style, run->weight);
1459 if (skia_face == NULL) 1459 if (skia_face == NULL)
1460 return false; 1460 return false;
1461 run->skia_face = skia_face; 1461 run->skia_face = skia_face;
1462 run->font = font; 1462 run->font = font;
1463 run->render_params = params; 1463 run->render_params = params;
1464 1464
1465 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( 1465 hb_font_t* harfbuzz_font = CreateHarfBuzzFont(
1466 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params, 1466 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params,
1467 subpixel_rendering_suppressed()); 1467 subpixel_rendering_suppressed());
1468 1468
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 DCHECK(!update_layout_run_list_); 1564 DCHECK(!update_layout_run_list_);
1565 DCHECK(!update_display_run_list_); 1565 DCHECK(!update_display_run_list_);
1566 return text_elided() ? display_run_list_.get() : &layout_run_list_; 1566 return text_elided() ? display_run_list_.get() : &layout_run_list_;
1567 } 1567 }
1568 1568
1569 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { 1569 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const {
1570 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); 1570 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList();
1571 } 1571 }
1572 1572
1573 } // namespace gfx 1573 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698