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

Unified Diff: ui/gfx/render_text_harfbuzz.cc

Issue 290993011: Merge HarfBuzz kerning support from Blink (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_harfbuzz.cc
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc
index 10e7a1a5276931a44ad6e8ff6643d5a03bba9ed9..138b859f1e6298b8df76a7af601875b7a073e6b7 100644
--- a/ui/gfx/render_text_harfbuzz.cc
+++ b/ui/gfx/render_text_harfbuzz.cc
@@ -126,6 +126,56 @@ hb_bool_t GetGlyphHorizontalOrigin(hb_font_t* font,
return true;
}
+hb_position_t GetGlyphHorizontalKerning(hb_font_t*,
msw 2014/05/27 22:00:59 nit: give names to even unused parameters (this an
ckocagil 2014/05/28 01:07:10 Done.
+ void* data,
+ hb_codepoint_t left_glyph,
+ hb_codepoint_t right_glyph,
+ void*) {
+ FontData* font_data = reinterpret_cast<FontData*>(data);
+ if (font_data->paint_.isVerticalText()) {
+ // We don't support cross-stream kerning.
+ return 0;
+ }
+
+ SkTypeface* typeface = font_data->paint_.getTypeface();
+ const uint16_t glyphs[2] = { left_glyph, right_glyph };
+ int32_t kerningAdjustments[1] = { 0 };
msw 2014/05/27 22:00:59 nit: |kerning_adjustments|
ckocagil 2014/05/28 01:07:10 Done.
+
+ if (typeface->getKerningPairAdjustments(glyphs, 2, kerningAdjustments)) {
+ SkScalar upm = SkIntToScalar(typeface->getUnitsPerEm());
+ SkScalar size = font_data->paint_.getTextSize();
+ return SkiaScalarToHarfBuzzPosition(
+ SkScalarMulDiv(SkIntToScalar(kerningAdjustments[0]), size, upm));
+ }
+
+ return 0;
+}
+
+hb_position_t GetGlyphVerticalKerning(hb_font_t*,
+ void* data,
+ hb_codepoint_t top_glyph,
+ hb_codepoint_t bottom_glyph,
+ void*) {
+ FontData* font_data = reinterpret_cast<FontData*>(data);
+ if (!font_data->paint_.isVerticalText()) {
msw 2014/05/27 22:00:59 This is the only logical difference from the funct
ckocagil 2014/05/28 01:07:10 Done, added a common helper.
+ // We don't support cross-stream kerning.
+ return 0;
+ }
+
+ SkTypeface* typeface = font_data->paint_.getTypeface();
+ const uint16_t glyphs[2] = { top_glyph, bottom_glyph };
+ int32_t kerningAdjustments[1] = { 0 };
msw 2014/05/27 22:00:59 ditto nit: |kerning_adjustments|
ckocagil 2014/05/28 01:07:10 Done.
+
+ if (typeface->getKerningPairAdjustments(glyphs, 2, kerningAdjustments)) {
+ SkScalar upm = SkIntToScalar(typeface->getUnitsPerEm());
+ SkScalar size = font_data->paint_.getTextSize();
+ return SkiaScalarToHarfBuzzPosition(
+ SkScalarMulDiv(SkIntToScalar(kerningAdjustments[0]), size, upm));
+ }
+
+ return 0;
+}
+
// Writes the |extents| of |glyph|.
hb_bool_t GetGlyphExtents(hb_font_t* font,
void* data,
@@ -144,7 +194,6 @@ hb_font_funcs_t* GetFontFuncs() {
// We don't set callback functions which we can't support.
// HarfBuzz will use the fallback implementation if they aren't set.
- // TODO(ckocagil): Merge Blink's kerning funcs.
if (!font_funcs) {
// The object created by |hb_font_funcs_create()| below lives indefinitely
// and is intentionally leaked.
@@ -152,8 +201,12 @@ hb_font_funcs_t* GetFontFuncs() {
hb_font_funcs_set_glyph_func(font_funcs, GetGlyph, 0, 0);
hb_font_funcs_set_glyph_h_advance_func(
font_funcs, GetGlyphHorizontalAdvance, 0, 0);
+ hb_font_funcs_set_glyph_h_kerning_func(
+ font_funcs, GetGlyphHorizontalKerning, 0, 0);
hb_font_funcs_set_glyph_h_origin_func(
font_funcs, GetGlyphHorizontalOrigin, 0, 0);
+ hb_font_funcs_set_glyph_v_kerning_func(
+ font_funcs, GetGlyphVerticalKerning, 0, 0);
hb_font_funcs_set_glyph_extents_func(
font_funcs, GetGlyphExtents, 0, 0);
hb_font_funcs_make_immutable(font_funcs);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698