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

Side by Side Diff: Source/platform/fonts/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: rebase again Created 6 years, 10 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
« no previous file with comments | « LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2012 Google Inc. All rights reserved.
3 * Copyright (c) 2014 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()
129 { 174 {
130 static hb_font_funcs_t* harfBuzzSkiaFontFuncs = 0; 175 static hb_font_funcs_t* harfBuzzSkiaFontFuncs = 0;
131 176
132 // We don't set callback functions which we can't support. 177 // We don't set callback functions which we can't support.
133 // HarfBuzz will use the fallback implementation if they aren't set. 178 // HarfBuzz will use the fallback implementation if they aren't set.
134 if (!harfBuzzSkiaFontFuncs) { 179 if (!harfBuzzSkiaFontFuncs) {
135 harfBuzzSkiaFontFuncs = hb_font_funcs_create(); 180 harfBuzzSkiaFontFuncs = hb_font_funcs_create();
136 hb_font_funcs_set_glyph_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyph, 0, 0); 181 hb_font_funcs_set_glyph_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyph, 0, 0);
137 hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphHorizontalAdvance, 0, 0); 182 hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphHorizontalAdvance, 0, 0);
183 hb_font_funcs_set_glyph_h_kerning_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphHorizontalKerning, 0, 0);
138 hb_font_funcs_set_glyph_h_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGet GlyphHorizontalOrigin, 0, 0); 184 hb_font_funcs_set_glyph_h_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGet GlyphHorizontalOrigin, 0, 0);
185 hb_font_funcs_set_glyph_v_kerning_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphVerticalKerning, 0, 0);
139 hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncs, harfBuzzGetG lyphExtents, 0, 0); 186 hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncs, harfBuzzGetG lyphExtents, 0, 0);
140 hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncs); 187 hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncs);
141 } 188 }
142 return harfBuzzSkiaFontFuncs; 189 return harfBuzzSkiaFontFuncs;
143 } 190 }
144 191
145 static hb_blob_t* harfBuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* user Data) 192 static hb_blob_t* harfBuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* user Data)
146 { 193 {
147 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(userData); 194 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(userData);
148 195
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 hb_font_make_immutable(font); 234 hb_font_make_immutable(font);
188 return font; 235 return font;
189 } 236 }
190 237
191 GlyphBufferAdvance HarfBuzzShaper::createGlyphBufferAdvance(float width, float h eight) 238 GlyphBufferAdvance HarfBuzzShaper::createGlyphBufferAdvance(float width, float h eight)
192 { 239 {
193 return GlyphBufferAdvance(width, height); 240 return GlyphBufferAdvance(width, height);
194 } 241 }
195 242
196 } // namespace WebCore 243 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698