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

Side by Side Diff: Source/core/platform/graphics/harfbuzz/HarfBuzzFaceSkia.cpp

Issue 69513002: Implement TrueType kerning support for HarfBuzz text path. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: don't remove empty line at the end of TextExpectations Created 7 years, 1 month 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 /* 1 /*
2 * Copyright (c) 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
6 * met: 7 * met:
7 * 8 *
8 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 11 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 13 * in the documentation and/or other materials provided with the
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return advance; 111 return advance;
111 } 112 }
112 113
113 static hb_bool_t harfBuzzGetGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontD ata, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) 114 static hb_bool_t harfBuzzGetGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontD ata, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData)
114 { 115 {
115 // Just return true, following the way that HarfBuzz-FreeType 116 // Just return true, following the way that HarfBuzz-FreeType
116 // implementation does. 117 // implementation does.
117 return true; 118 return true;
118 } 119 }
119 120
121 static hb_position_t harfBuzzGetGlyphHorizontalKerning(hb_font_t*, void* fontDat a, hb_codepoint_t leftGlyph, hb_codepoint_t rightGlyph, void*)
122 {
123 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData) ;
124 if (hbFontData->m_paint.isVerticalText()) {
125 // We don't support cross-stream kerning
126 return 0;
127 }
128
129 SkTypeface* typeface = hbFontData->m_paint.getTypeface();
130
131 const uint16_t glyphs[2] = { leftGlyph, rightGlyph };
132 int32_t kerningAdjustments[1] = { 0 };
133
134 if (typeface->getKerningPairAdjustments(glyphs, 2, kerningAdjustments)) {
135 SkScalar upm = SkIntToScalar(typeface->getUnitsPerEm());
136 SkScalar size = hbFontData->m_paint.getTextSize();
137 return SkiaScalarToHarfBuzzPosition(SkScalarMulDiv(SkIntToScalar(kerning Adjustments[0]), size, upm));
138 }
139
140 return 0;
141 }
142
143 static hb_position_t harfBuzzGetGlyphVerticalKerning(hb_font_t*, void* fontData, hb_codepoint_t topGlyph, hb_codepoint_t bottomGlyph, void*)
144 {
145 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData) ;
146 if (!hbFontData->m_paint.isVerticalText()) {
147 // We don't support cross-stream kerning
148 return 0;
149 }
150
151 SkTypeface* typeface = hbFontData->m_paint.getTypeface();
152
153 const uint16_t glyphs[2] = { topGlyph, bottomGlyph };
154 int32_t kerningAdjustments[1] = { 0 };
155
156 if (typeface->getKerningPairAdjustments(glyphs, 2, kerningAdjustments)) {
157 SkScalar upm = SkIntToScalar(typeface->getUnitsPerEm());
158 SkScalar size = hbFontData->m_paint.getTextSize();
159 return SkiaScalarToHarfBuzzPosition(SkScalarMulDiv(SkIntToScalar(kerning Adjustments[0]), size, upm));
160 }
161
162 return 0;
163 }
164
120 static hb_bool_t harfBuzzGetGlyphExtents(hb_font_t* hbFont, void* fontData, hb_c odepoint_t glyph, hb_glyph_extents_t* extents, void* userData) 165 static hb_bool_t harfBuzzGetGlyphExtents(hb_font_t* hbFont, void* fontData, hb_c odepoint_t glyph, hb_glyph_extents_t* extents, void* userData)
121 { 166 {
122 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData) ; 167 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData) ;
123 168
124 SkiaGetGlyphWidthAndExtents(&hbFontData->m_paint, glyph, 0, extents); 169 SkiaGetGlyphWidthAndExtents(&hbFontData->m_paint, glyph, 0, extents);
125 return true; 170 return true;
126 } 171 }
127 172
128 static hb_font_funcs_t* harfBuzzSkiaGetFontFuncs() 173 static hb_font_funcs_t* harfBuzzSkiaGetFontFuncs(const TypesettingFeatures& feat ures)
129 { 174 {
130 static hb_font_funcs_t* harfBuzzSkiaFontFuncs = 0; 175 static hb_font_funcs_t* harfBuzzSkiaFontFuncs = 0;
176 static hb_font_funcs_t* harfBuzzSkiaFontFuncsWithKerning = 0; // includes Tr ueType ("kern" table) kerning
177
178 if (features & Kerning) {
179 if (!harfBuzzSkiaFontFuncsWithKerning) {
180 harfBuzzSkiaFontFuncsWithKerning = hb_font_funcs_create();
181 hb_font_funcs_set_glyph_func(harfBuzzSkiaFontFuncsWithKerning, harfB uzzGetGlyph, 0, 0);
182 hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncsWithKern ing, harfBuzzGetGlyphHorizontalAdvance, 0, 0);
183 hb_font_funcs_set_glyph_h_kerning_func(harfBuzzSkiaFontFuncsWithKern ing, harfBuzzGetGlyphHorizontalKerning, 0, 0);
184 hb_font_funcs_set_glyph_h_origin_func(harfBuzzSkiaFontFuncsWithKerni ng, harfBuzzGetGlyphHorizontalOrigin, 0, 0);
185 hb_font_funcs_set_glyph_v_kerning_func(harfBuzzSkiaFontFuncsWithKern ing, harfBuzzGetGlyphVerticalKerning, 0, 0);
186 hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncsWithKernin g, harfBuzzGetGlyphExtents, 0, 0);
187 hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncsWithKerning);
188 }
189 return harfBuzzSkiaFontFuncsWithKerning;
behdad_google 2013/11/15 16:26:35 This is the wrong approach to control kerning.
190 }
131 191
132 // We don't set callback functions which we can't support. 192 // We don't set callback functions which we can't support.
133 // HarfBuzz will use the fallback implementation if they aren't set. 193 // HarfBuzz will use the fallback implementation if they aren't set.
134 if (!harfBuzzSkiaFontFuncs) { 194 if (!harfBuzzSkiaFontFuncs) {
135 harfBuzzSkiaFontFuncs = hb_font_funcs_create(); 195 harfBuzzSkiaFontFuncs = hb_font_funcs_create();
136 hb_font_funcs_set_glyph_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyph, 0, 0); 196 hb_font_funcs_set_glyph_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyph, 0, 0);
137 hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphHorizontalAdvance, 0, 0); 197 hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphHorizontalAdvance, 0, 0);
138 hb_font_funcs_set_glyph_h_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGet GlyphHorizontalOrigin, 0, 0); 198 hb_font_funcs_set_glyph_h_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGet GlyphHorizontalOrigin, 0, 0);
139 hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncs, harfBuzzGetG lyphExtents, 0, 0); 199 hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncs, harfBuzzGetG lyphExtents, 0, 0);
140 hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncs); 200 hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncs);
(...skipping 27 matching lines...) Expand all
168 delete hbFontData; 228 delete hbFontData;
169 } 229 }
170 230
171 hb_face_t* HarfBuzzFace::createFace() 231 hb_face_t* HarfBuzzFace::createFace()
172 { 232 {
173 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0); 233 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0);
174 ASSERT(face); 234 ASSERT(face);
175 return face; 235 return face;
176 } 236 }
177 237
178 hb_font_t* HarfBuzzFace::createFont() 238 hb_font_t* HarfBuzzFace::createFont(const TypesettingFeatures& features)
179 { 239 {
180 HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCache Entry); 240 HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCache Entry);
181 m_platformData->setupPaint(&hbFontData->m_paint); 241 m_platformData->setupPaint(&hbFontData->m_paint);
182 hb_font_t* font = hb_font_create(m_face); 242 hb_font_t* font = hb_font_create(m_face);
183 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB uzzFontData); 243 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(features), hbFontData, dest royHarfBuzzFontData);
184 float size = m_platformData->size(); 244 float size = m_platformData->size();
185 int scale = SkiaScalarToHarfBuzzPosition(size); 245 int scale = SkiaScalarToHarfBuzzPosition(size);
186 hb_font_set_scale(font, scale, scale); 246 hb_font_set_scale(font, scale, scale);
187 hb_font_make_immutable(font); 247 hb_font_make_immutable(font);
188 return font; 248 return font;
189 } 249 }
190 250
191 GlyphBufferAdvance HarfBuzzShaper::createGlyphBufferAdvance(float width, float h eight) 251 GlyphBufferAdvance HarfBuzzShaper::createGlyphBufferAdvance(float width, float h eight)
192 { 252 {
193 return GlyphBufferAdvance(width, height); 253 return GlyphBufferAdvance(width, height);
194 } 254 }
195 255
196 } // namespace WebCore 256 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698