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

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

Issue 299313009: Revert of Merge HarfBuzz kerning support from Blink (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 // 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 <map> 7 #include <map>
8 8
9 #include "base/i18n/break_iterator.h" 9 #include "base/i18n/break_iterator.h"
10 #include "base/i18n/char_iterator.h" 10 #include "base/i18n/char_iterator.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 hb_bool_t GetGlyphHorizontalOrigin(hb_font_t* font, 119 hb_bool_t GetGlyphHorizontalOrigin(hb_font_t* font,
120 void* data, 120 void* data,
121 hb_codepoint_t glyph, 121 hb_codepoint_t glyph,
122 hb_position_t* x, 122 hb_position_t* x,
123 hb_position_t* y, 123 hb_position_t* y,
124 void* user_data) { 124 void* user_data) {
125 // Just return true, like the HarfBuzz-FreeType implementation. 125 // Just return true, like the HarfBuzz-FreeType implementation.
126 return true; 126 return true;
127 } 127 }
128 128
129 hb_position_t GetGlyphKerning(FontData* font_data,
130 hb_codepoint_t first_glyph,
131 hb_codepoint_t second_glyph) {
132 SkTypeface* typeface = font_data->paint_.getTypeface();
133 const uint16_t glyphs[2] = { first_glyph, second_glyph };
134 int32_t kerning_adjustments[1] = { 0 };
135
136 if (!typeface->getKerningPairAdjustments(glyphs, 2, kerning_adjustments))
137 return 0;
138
139 SkScalar upm = SkIntToScalar(typeface->getUnitsPerEm());
140 SkScalar size = font_data->paint_.getTextSize();
141 return SkiaScalarToHarfBuzzPosition(
142 SkScalarMulDiv(SkIntToScalar(kerning_adjustments[0]), size, upm));
143 }
144
145 hb_position_t GetGlyphHorizontalKerning(hb_font_t* font,
146 void* data,
147 hb_codepoint_t left_glyph,
148 hb_codepoint_t right_glyph,
149 void* user_data) {
150 FontData* font_data = reinterpret_cast<FontData*>(data);
151 if (font_data->paint_.isVerticalText()) {
152 // We don't support cross-stream kerning.
153 return 0;
154 }
155
156 return GetGlyphKerning(font_data, left_glyph, right_glyph);
157 }
158
159 hb_position_t GetGlyphVerticalKerning(hb_font_t* font,
160 void* data,
161 hb_codepoint_t top_glyph,
162 hb_codepoint_t bottom_glyph,
163 void* user_data) {
164 FontData* font_data = reinterpret_cast<FontData*>(data);
165 if (!font_data->paint_.isVerticalText()) {
166 // We don't support cross-stream kerning.
167 return 0;
168 }
169
170 return GetGlyphKerning(font_data, top_glyph, bottom_glyph);
171 }
172
173 // Writes the |extents| of |glyph|. 129 // Writes the |extents| of |glyph|.
174 hb_bool_t GetGlyphExtents(hb_font_t* font, 130 hb_bool_t GetGlyphExtents(hb_font_t* font,
175 void* data, 131 void* data,
176 hb_codepoint_t glyph, 132 hb_codepoint_t glyph,
177 hb_glyph_extents_t* extents, 133 hb_glyph_extents_t* extents,
178 void* user_data) { 134 void* user_data) {
179 FontData* font_data = reinterpret_cast<FontData*>(data); 135 FontData* font_data = reinterpret_cast<FontData*>(data);
180 136
181 GetGlyphWidthAndExtents(&font_data->paint_, glyph, 0, extents); 137 GetGlyphWidthAndExtents(&font_data->paint_, glyph, 0, extents);
182 return true; 138 return true;
183 } 139 }
184 140
185 // Returns a HarfBuzz font data provider that uses Skia. 141 // Returns a HarfBuzz font data provider that uses Skia.
186 hb_font_funcs_t* GetFontFuncs() { 142 hb_font_funcs_t* GetFontFuncs() {
187 static hb_font_funcs_t* font_funcs = 0; 143 static hb_font_funcs_t* font_funcs = 0;
188 144
189 // We don't set callback functions which we can't support. 145 // We don't set callback functions which we can't support.
190 // HarfBuzz will use the fallback implementation if they aren't set. 146 // HarfBuzz will use the fallback implementation if they aren't set.
147 // TODO(ckocagil): Merge Blink's kerning funcs.
191 if (!font_funcs) { 148 if (!font_funcs) {
192 // The object created by |hb_font_funcs_create()| below lives indefinitely 149 // The object created by |hb_font_funcs_create()| below lives indefinitely
193 // and is intentionally leaked. 150 // and is intentionally leaked.
194 font_funcs = hb_font_funcs_create(); 151 font_funcs = hb_font_funcs_create();
195 hb_font_funcs_set_glyph_func(font_funcs, GetGlyph, 0, 0); 152 hb_font_funcs_set_glyph_func(font_funcs, GetGlyph, 0, 0);
196 hb_font_funcs_set_glyph_h_advance_func( 153 hb_font_funcs_set_glyph_h_advance_func(
197 font_funcs, GetGlyphHorizontalAdvance, 0, 0); 154 font_funcs, GetGlyphHorizontalAdvance, 0, 0);
198 hb_font_funcs_set_glyph_h_kerning_func(
199 font_funcs, GetGlyphHorizontalKerning, 0, 0);
200 hb_font_funcs_set_glyph_h_origin_func( 155 hb_font_funcs_set_glyph_h_origin_func(
201 font_funcs, GetGlyphHorizontalOrigin, 0, 0); 156 font_funcs, GetGlyphHorizontalOrigin, 0, 0);
202 hb_font_funcs_set_glyph_v_kerning_func(
203 font_funcs, GetGlyphVerticalKerning, 0, 0);
204 hb_font_funcs_set_glyph_extents_func( 157 hb_font_funcs_set_glyph_extents_func(
205 font_funcs, GetGlyphExtents, 0, 0); 158 font_funcs, GetGlyphExtents, 0, 0);
206 hb_font_funcs_make_immutable(font_funcs); 159 hb_font_funcs_make_immutable(font_funcs);
207 } 160 }
208 return font_funcs; 161 return font_funcs;
209 } 162 }
210 163
211 // Returns the raw data of the font table |tag|. 164 // Returns the raw data of the font table |tag|.
212 hb_blob_t* GetFontTable(hb_face_t* face, hb_tag_t tag, void* user_data) { 165 hb_blob_t* GetFontTable(hb_face_t* face, hb_tag_t tag, void* user_data) {
213 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(user_data); 166 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(user_data);
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 run->positions[i].set(run->width + x_offset, y_offset); 943 run->positions[i].set(run->width + x_offset, y_offset);
991 run->width += 944 run->width +=
992 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); 945 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance));
993 } 946 }
994 947
995 hb_buffer_destroy(buffer); 948 hb_buffer_destroy(buffer);
996 hb_font_destroy(harfbuzz_font); 949 hb_font_destroy(harfbuzz_font);
997 } 950 }
998 951
999 } // namespace gfx 952 } // namespace gfx
OLDNEW
« 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