OLD | NEW |
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
, hb_position_t* width, hb_glyph_extents_t* extents) | 139 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
, hb_position_t* width, hb_glyph_extents_t* extents) |
140 { | 140 { |
141 ASSERT(codepoint <= 0xFFFF); | 141 ASSERT(codepoint <= 0xFFFF); |
142 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 142 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
143 | 143 |
144 SkScalar skWidth; | 144 SkScalar skWidth; |
145 SkRect skBounds; | 145 SkRect skBounds; |
146 uint16_t glyph = codepoint; | 146 uint16_t glyph = codepoint; |
147 | 147 |
148 paint->getTextWidths(&glyph, sizeof(glyph), &skWidth, &skBounds); | 148 paint->getTextWidths(&glyph, sizeof(glyph), &skWidth, &skBounds); |
149 if (width) | 149 if (width) { |
| 150 if (!paint->isSubpixelText()) |
| 151 skWidth = SkScalarRoundToInt(skWidth); |
150 *width = SkiaScalarToHarfBuzzPosition(skWidth); | 152 *width = SkiaScalarToHarfBuzzPosition(skWidth); |
| 153 } |
151 if (extents) { | 154 if (extents) { |
| 155 if (!paint->isSubpixelText()) { |
| 156 // Use roundOut() rather than round() to avoid rendering glyphs |
| 157 // outside the visual overflow rect. crbug.com/452914. |
| 158 SkIRect ir; |
| 159 skBounds.roundOut(&ir); |
| 160 skBounds.set(ir); |
| 161 } |
152 // Invert y-axis because Skia is y-grows-down but we set up HarfBuzz to
be y-grows-up. | 162 // Invert y-axis because Skia is y-grows-down but we set up HarfBuzz to
be y-grows-up. |
153 extents->x_bearing = SkiaScalarToHarfBuzzPosition(skBounds.fLeft); | 163 extents->x_bearing = SkiaScalarToHarfBuzzPosition(skBounds.fLeft); |
154 extents->y_bearing = SkiaScalarToHarfBuzzPosition(-skBounds.fTop); | 164 extents->y_bearing = SkiaScalarToHarfBuzzPosition(-skBounds.fTop); |
155 extents->width = SkiaScalarToHarfBuzzPosition(skBounds.width()); | 165 extents->width = SkiaScalarToHarfBuzzPosition(skBounds.width()); |
156 extents->height = SkiaScalarToHarfBuzzPosition(-skBounds.height()); | 166 extents->height = SkiaScalarToHarfBuzzPosition(-skBounds.height()); |
157 } | 167 } |
158 } | 168 } |
159 | 169 |
160 #if !defined(HB_VERSION_ATLEAST) | 170 #if !defined(HB_VERSION_ATLEAST) |
161 #define HB_VERSION_ATLEAST(major, minor, micro) 0 | 171 #define HB_VERSION_ATLEAST(major, minor, micro) 0 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 hb_font_t* font = hb_font_create(m_face); | 347 hb_font_t* font = hb_font_create(m_face); |
338 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB
uzzFontData); | 348 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB
uzzFontData); |
339 float size = m_platformData->size(); | 349 float size = m_platformData->size(); |
340 int scale = SkiaScalarToHarfBuzzPosition(size); | 350 int scale = SkiaScalarToHarfBuzzPosition(size); |
341 hb_font_set_scale(font, scale, scale); | 351 hb_font_set_scale(font, scale, scale); |
342 hb_font_make_immutable(font); | 352 hb_font_make_immutable(font); |
343 return font; | 353 return font; |
344 } | 354 } |
345 | 355 |
346 } // namespace blink | 356 } // namespace blink |
OLD | NEW |