Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 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.
| |
| 130 void* data, | |
| 131 hb_codepoint_t left_glyph, | |
| 132 hb_codepoint_t right_glyph, | |
| 133 void*) { | |
| 134 FontData* font_data = reinterpret_cast<FontData*>(data); | |
| 135 if (font_data->paint_.isVerticalText()) { | |
| 136 // We don't support cross-stream kerning. | |
| 137 return 0; | |
| 138 } | |
| 139 | |
| 140 SkTypeface* typeface = font_data->paint_.getTypeface(); | |
| 141 const uint16_t glyphs[2] = { left_glyph, right_glyph }; | |
| 142 int32_t kerningAdjustments[1] = { 0 }; | |
|
msw
2014/05/27 22:00:59
nit: |kerning_adjustments|
ckocagil
2014/05/28 01:07:10
Done.
| |
| 143 | |
| 144 if (typeface->getKerningPairAdjustments(glyphs, 2, kerningAdjustments)) { | |
| 145 SkScalar upm = SkIntToScalar(typeface->getUnitsPerEm()); | |
| 146 SkScalar size = font_data->paint_.getTextSize(); | |
| 147 return SkiaScalarToHarfBuzzPosition( | |
| 148 SkScalarMulDiv(SkIntToScalar(kerningAdjustments[0]), size, upm)); | |
| 149 } | |
| 150 | |
| 151 return 0; | |
| 152 } | |
| 153 | |
| 154 hb_position_t GetGlyphVerticalKerning(hb_font_t*, | |
| 155 void* data, | |
| 156 hb_codepoint_t top_glyph, | |
| 157 hb_codepoint_t bottom_glyph, | |
| 158 void*) { | |
| 159 FontData* font_data = reinterpret_cast<FontData*>(data); | |
| 160 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.
| |
| 161 // We don't support cross-stream kerning. | |
| 162 return 0; | |
| 163 } | |
| 164 | |
| 165 SkTypeface* typeface = font_data->paint_.getTypeface(); | |
| 166 const uint16_t glyphs[2] = { top_glyph, bottom_glyph }; | |
| 167 int32_t kerningAdjustments[1] = { 0 }; | |
|
msw
2014/05/27 22:00:59
ditto nit: |kerning_adjustments|
ckocagil
2014/05/28 01:07:10
Done.
| |
| 168 | |
| 169 if (typeface->getKerningPairAdjustments(glyphs, 2, kerningAdjustments)) { | |
| 170 SkScalar upm = SkIntToScalar(typeface->getUnitsPerEm()); | |
| 171 SkScalar size = font_data->paint_.getTextSize(); | |
| 172 return SkiaScalarToHarfBuzzPosition( | |
| 173 SkScalarMulDiv(SkIntToScalar(kerningAdjustments[0]), size, upm)); | |
| 174 } | |
| 175 | |
| 176 return 0; | |
| 177 } | |
| 178 | |
| 129 // Writes the |extents| of |glyph|. | 179 // Writes the |extents| of |glyph|. |
| 130 hb_bool_t GetGlyphExtents(hb_font_t* font, | 180 hb_bool_t GetGlyphExtents(hb_font_t* font, |
| 131 void* data, | 181 void* data, |
| 132 hb_codepoint_t glyph, | 182 hb_codepoint_t glyph, |
| 133 hb_glyph_extents_t* extents, | 183 hb_glyph_extents_t* extents, |
| 134 void* user_data) { | 184 void* user_data) { |
| 135 FontData* font_data = reinterpret_cast<FontData*>(data); | 185 FontData* font_data = reinterpret_cast<FontData*>(data); |
| 136 | 186 |
| 137 GetGlyphWidthAndExtents(&font_data->paint_, glyph, 0, extents); | 187 GetGlyphWidthAndExtents(&font_data->paint_, glyph, 0, extents); |
| 138 return true; | 188 return true; |
| 139 } | 189 } |
| 140 | 190 |
| 141 // Returns a HarfBuzz font data provider that uses Skia. | 191 // Returns a HarfBuzz font data provider that uses Skia. |
| 142 hb_font_funcs_t* GetFontFuncs() { | 192 hb_font_funcs_t* GetFontFuncs() { |
| 143 static hb_font_funcs_t* font_funcs = 0; | 193 static hb_font_funcs_t* font_funcs = 0; |
| 144 | 194 |
| 145 // We don't set callback functions which we can't support. | 195 // We don't set callback functions which we can't support. |
| 146 // HarfBuzz will use the fallback implementation if they aren't set. | 196 // HarfBuzz will use the fallback implementation if they aren't set. |
| 147 // TODO(ckocagil): Merge Blink's kerning funcs. | |
| 148 if (!font_funcs) { | 197 if (!font_funcs) { |
| 149 // The object created by |hb_font_funcs_create()| below lives indefinitely | 198 // The object created by |hb_font_funcs_create()| below lives indefinitely |
| 150 // and is intentionally leaked. | 199 // and is intentionally leaked. |
| 151 font_funcs = hb_font_funcs_create(); | 200 font_funcs = hb_font_funcs_create(); |
| 152 hb_font_funcs_set_glyph_func(font_funcs, GetGlyph, 0, 0); | 201 hb_font_funcs_set_glyph_func(font_funcs, GetGlyph, 0, 0); |
| 153 hb_font_funcs_set_glyph_h_advance_func( | 202 hb_font_funcs_set_glyph_h_advance_func( |
| 154 font_funcs, GetGlyphHorizontalAdvance, 0, 0); | 203 font_funcs, GetGlyphHorizontalAdvance, 0, 0); |
| 204 hb_font_funcs_set_glyph_h_kerning_func( | |
| 205 font_funcs, GetGlyphHorizontalKerning, 0, 0); | |
| 155 hb_font_funcs_set_glyph_h_origin_func( | 206 hb_font_funcs_set_glyph_h_origin_func( |
| 156 font_funcs, GetGlyphHorizontalOrigin, 0, 0); | 207 font_funcs, GetGlyphHorizontalOrigin, 0, 0); |
| 208 hb_font_funcs_set_glyph_v_kerning_func( | |
| 209 font_funcs, GetGlyphVerticalKerning, 0, 0); | |
| 157 hb_font_funcs_set_glyph_extents_func( | 210 hb_font_funcs_set_glyph_extents_func( |
| 158 font_funcs, GetGlyphExtents, 0, 0); | 211 font_funcs, GetGlyphExtents, 0, 0); |
| 159 hb_font_funcs_make_immutable(font_funcs); | 212 hb_font_funcs_make_immutable(font_funcs); |
| 160 } | 213 } |
| 161 return font_funcs; | 214 return font_funcs; |
| 162 } | 215 } |
| 163 | 216 |
| 164 // Returns the raw data of the font table |tag|. | 217 // Returns the raw data of the font table |tag|. |
| 165 hb_blob_t* GetFontTable(hb_face_t* face, hb_tag_t tag, void* user_data) { | 218 hb_blob_t* GetFontTable(hb_face_t* face, hb_tag_t tag, void* user_data) { |
| 166 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(user_data); | 219 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(user_data); |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 943 run->positions[i].set(run->width + x_offset, y_offset); | 996 run->positions[i].set(run->width + x_offset, y_offset); |
| 944 run->width += | 997 run->width += |
| 945 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); | 998 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); |
| 946 } | 999 } |
| 947 | 1000 |
| 948 hb_buffer_destroy(buffer); | 1001 hb_buffer_destroy(buffer); |
| 949 hb_font_destroy(harfbuzz_font); | 1002 hb_font_destroy(harfbuzz_font); |
| 950 } | 1003 } |
| 951 | 1004 |
| 952 } // namespace gfx | 1005 } // namespace gfx |
| OLD | NEW |