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

Side by Side Diff: Source/platform/fonts/harfbuzz/HarfBuzzFaceCoreText.mm

Issue 617103003: Replace ENABLE_OPENTYPE_VERTICAL implementation with HarfBuzz (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@removeOpenTypeVertical
Patch Set: Created 6 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 static hb_position_t getGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData , hb_codepoint_t glyph, void* userData) 99 static hb_position_t getGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData , hb_codepoint_t glyph, void* userData)
100 { 100 {
101 CGSize advance; 101 CGSize advance;
102 FontPlatformData* platformData = reinterpret_cast<FontPlatformData*>(fontDat a); 102 FontPlatformData* platformData = reinterpret_cast<FontPlatformData*>(fontDat a);
103 advanceForGlyph(glyph, *platformData, &advance); 103 advanceForGlyph(glyph, *platformData, &advance);
104 float syntheticBoldOffset = platformData->m_syntheticBold ? 1.0f : 0.0f; 104 float syntheticBoldOffset = platformData->m_syntheticBold ? 1.0f : 0.0f;
105 return floatToHarfBuzzPosition(advance.width + syntheticBoldOffset); 105 return floatToHarfBuzzPosition(advance.width + syntheticBoldOffset);
106 } 106 }
107 107
108 static hb_bool_t harfBuzzGetGlyphVerticalOrigin(hb_font_t* hbFont, void* fontDat a, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData)
109 {
110 FontPlatformData* fontPlatformData = reinterpret_cast<FontPlatformData*>(fon tData);
111
112 OpenTypeVerticalData* verticalData = fontPlatformData->verticalData().get();
113 if (!verticalData)
114 return false;
115
116 // FIXME: This should be using the existing SimpleFontData or SkFontMetrics.
117 RefPtr<SimpleFontData> simpleFontData = SimpleFontData::create(*fontPlatform Data);
118 float result[] = { 0, 0 };
119
120 Glyph theGlyph = glyph;
121 verticalData->getVerticalTranslationsForGlyphs(simpleFontData.get(), &theGly ph, 1, result);
122 *x = floatToHarfBuzzPosition(-result[0]);
123 *y = floatToHarfBuzzPosition(-result[1]);
124
125 return true;
126 }
127
128 static hb_position_t harfBuzzGetGlyphVerticalAdvance(hb_font_t* hbFont, void* fo ntData, hb_codepoint_t glyph, void* userData)
129 {
130 FontPlatformData* fontPlatformData = reinterpret_cast<FontPlatformData*>(fon tData);
131
132 RefPtr<SimpleFontData> simpleFontData = SimpleFontData::create(*fontPlatform Data);
133 OpenTypeVerticalData* verticalData = fontPlatformData->verticalData().get();
134
135 if (!verticalData)
136 return floatToHarfBuzzPosition(simpleFontData->fontMetrics().height());
137
138 // FIXME: This should be using the existing SimpleFontData or SkFontMetrics.
139 Glyph theGlyph = glyph;
140 float advanceHeight = verticalData->advanceHeight(simpleFontData.get(), theG lyph);
141
142 return floatToHarfBuzzPosition(advanceHeight);
143 }
144
108 static hb_bool_t getGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontData, hb_ codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) 145 static hb_bool_t getGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontData, hb_ codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData)
109 { 146 {
110 return true; 147 return true;
111 } 148 }
112 149
113 static hb_bool_t getGlyphExtents(hb_font_t* hbFont, void* fontData, hb_codepoint _t glyph, hb_glyph_extents_t* extents, void* userData) 150 static hb_bool_t getGlyphExtents(hb_font_t* hbFont, void* fontData, hb_codepoint _t glyph, hb_glyph_extents_t* extents, void* userData)
114 { 151 {
115 CTFontRef ctFont = reinterpret_cast<FontPlatformData*>(fontData)->ctFont(); 152 CTFontRef ctFont = reinterpret_cast<FontPlatformData*>(fontData)->ctFont();
116 CGRect cgRect; 153 CGRect cgRect;
117 CGGlyph cgGlyph = glyph; 154 CGGlyph cgGlyph = glyph;
118 if (CTFontGetBoundingRectsForGlyphs(ctFont, kCTFontDefaultOrientation, &cgGl yph, &cgRect, 1) == CGRectNull) 155 if (CTFontGetBoundingRectsForGlyphs(ctFont, kCTFontDefaultOrientation, &cgGl yph, &cgRect, 1) == CGRectNull)
119 return false; 156 return false;
120 extents->x_bearing = floatToHarfBuzzPosition(cgRect.origin.x); 157 extents->x_bearing = floatToHarfBuzzPosition(cgRect.origin.x);
121 extents->y_bearing = -floatToHarfBuzzPosition(cgRect.origin.y); 158 extents->y_bearing = -floatToHarfBuzzPosition(cgRect.origin.y);
122 extents->width = floatToHarfBuzzPosition(cgRect.size.width); 159 extents->width = floatToHarfBuzzPosition(cgRect.size.width);
123 extents->height = floatToHarfBuzzPosition(cgRect.size.height); 160 extents->height = floatToHarfBuzzPosition(cgRect.size.height);
124 return true; 161 return true;
125 } 162 }
126 163
127 static hb_font_funcs_t* harfBuzzCoreTextGetFontFuncs() 164 static hb_font_funcs_t* harfBuzzCoreTextGetFontFuncs()
128 { 165 {
129 static hb_font_funcs_t* harfBuzzCoreTextFontFuncs = 0; 166 static hb_font_funcs_t* harfBuzzCoreTextFontFuncs = 0;
130 167
131 if (!harfBuzzCoreTextFontFuncs) { 168 if (!harfBuzzCoreTextFontFuncs) {
132 harfBuzzCoreTextFontFuncs = hb_font_funcs_create(); 169 harfBuzzCoreTextFontFuncs = hb_font_funcs_create();
133 hb_font_funcs_set_glyph_func(harfBuzzCoreTextFontFuncs, getGlyph, 0, 0); 170 hb_font_funcs_set_glyph_func(harfBuzzCoreTextFontFuncs, getGlyph, 0, 0);
134 hb_font_funcs_set_glyph_h_advance_func(harfBuzzCoreTextFontFuncs, getGly phHorizontalAdvance, 0, 0); 171 hb_font_funcs_set_glyph_h_advance_func(harfBuzzCoreTextFontFuncs, getGly phHorizontalAdvance, 0, 0);
135 hb_font_funcs_set_glyph_h_origin_func(harfBuzzCoreTextFontFuncs, getGlyp hHorizontalOrigin, 0, 0); 172 hb_font_funcs_set_glyph_h_origin_func(harfBuzzCoreTextFontFuncs, getGlyp hHorizontalOrigin, 0, 0);
173 hb_font_funcs_set_glyph_v_advance_func(harfBuzzCoreTextFontFuncs, harfBu zzGetGlyphVerticalAdvance, 0, 0);
174 hb_font_funcs_set_glyph_v_origin_func(harfBuzzCoreTextFontFuncs, harfBuz zGetGlyphVerticalOrigin, 0, 0);
136 hb_font_funcs_set_glyph_extents_func(harfBuzzCoreTextFontFuncs, getGlyph Extents, 0, 0); 175 hb_font_funcs_set_glyph_extents_func(harfBuzzCoreTextFontFuncs, getGlyph Extents, 0, 0);
137 hb_font_funcs_make_immutable(harfBuzzCoreTextFontFuncs); 176 hb_font_funcs_make_immutable(harfBuzzCoreTextFontFuncs);
138 } 177 }
139 return harfBuzzCoreTextFontFuncs; 178 return harfBuzzCoreTextFontFuncs;
140 } 179 }
141 180
142 hb_face_t* HarfBuzzFace::createFace() 181 hb_face_t* HarfBuzzFace::createFace()
143 { 182 {
144 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); 183 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont());
145 ASSERT(face); 184 ASSERT(face);
146 return face; 185 return face;
147 } 186 }
148 187
149 hb_font_t* HarfBuzzFace::createFont() 188 hb_font_t* HarfBuzzFace::createFont()
150 { 189 {
151 hb_font_t* font = hb_font_create(m_face); 190 hb_font_t* font = hb_font_create(m_face);
152 hb_font_set_funcs(font, harfBuzzCoreTextGetFontFuncs(), m_platformData, 0); 191 hb_font_set_funcs(font, harfBuzzCoreTextGetFontFuncs(), m_platformData, 0);
153 const float size = m_platformData->m_textSize; 192 const float size = m_platformData->m_textSize;
154 hb_font_set_ppem(font, size, size); 193 hb_font_set_ppem(font, size, size);
155 const int scale = (1 << 16) * static_cast<int>(size); 194 const int scale = (1 << 16) * static_cast<int>(size);
156 hb_font_set_scale(font, scale, scale); 195 hb_font_set_scale(font, scale, scale);
157 hb_font_make_immutable(font); 196 hb_font_make_immutable(font);
158 return font; 197 return font;
159 } 198 }
160 199
161 } // namespace blink 200 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698