| 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 27 matching lines...) Expand all Loading... |
| 38 #include "SkPaint.h" | 38 #include "SkPaint.h" |
| 39 #include "SkPath.h" | 39 #include "SkPath.h" |
| 40 #include "SkPoint.h" | 40 #include "SkPoint.h" |
| 41 #include "SkRect.h" | 41 #include "SkRect.h" |
| 42 #include "SkTypeface.h" | 42 #include "SkTypeface.h" |
| 43 #include "platform/fonts/FontCache.h" | 43 #include "platform/fonts/FontCache.h" |
| 44 #include "platform/fonts/FontPlatformData.h" | 44 #include "platform/fonts/FontPlatformData.h" |
| 45 #include "platform/fonts/SimpleFontData.h" | 45 #include "platform/fonts/SimpleFontData.h" |
| 46 #include "platform/fonts/shaping/HarfBuzzShaper.h" | 46 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
| 47 #include "wtf/HashMap.h" | 47 #include "wtf/HashMap.h" |
| 48 #include "wtf/MathExtras.h" |
| 48 | 49 |
| 49 namespace blink { | 50 namespace blink { |
| 50 | 51 |
| 51 const hb_tag_t HarfBuzzFace::vertTag = HB_TAG('v', 'e', 'r', 't'); | 52 const hb_tag_t HarfBuzzFace::vertTag = HB_TAG('v', 'e', 'r', 't'); |
| 52 | 53 |
| 53 // Though we have FontCache class, which provides the cache mechanism for | 54 // Though we have FontCache class, which provides the cache mechanism for |
| 54 // WebKit's font objects, we also need additional caching layer for HarfBuzz | 55 // WebKit's font objects, we also need additional caching layer for HarfBuzz |
| 55 // to reduce the memory consumption because hb_face_t should be associated with | 56 // to reduce the memory consumption because hb_face_t should be associated with |
| 56 // underling font data (e.g. CTFontRef, FTFace). | 57 // underling font data (e.g. CTFontRef, FTFace). |
| 57 | 58 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 RefPtr<SimpleFontData> m_simpleFontData; | 132 RefPtr<SimpleFontData> m_simpleFontData; |
| 132 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry; | 133 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry; |
| 133 hb_face_t* m_face; | 134 hb_face_t* m_face; |
| 134 hb_font_t* m_hbOpenTypeFont; | 135 hb_font_t* m_hbOpenTypeFont; |
| 135 unsigned m_rangeFrom; | 136 unsigned m_rangeFrom; |
| 136 unsigned m_rangeTo; | 137 unsigned m_rangeTo; |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) | 140 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) |
| 140 { | 141 { |
| 141 return SkScalarToFixed(value); | 142 // We treat HarfBuzz hb_position_t as 16.16 fixed-point. |
| 143 static const int kHbPosition1 = 1 << 16; |
| 144 return clampTo<int>(value * kHbPosition1); |
| 142 } | 145 } |
| 143 | 146 |
| 144 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
, hb_position_t* width, hb_glyph_extents_t* extents) | 147 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
, hb_position_t* width, hb_glyph_extents_t* extents) |
| 145 { | 148 { |
| 146 ASSERT(codepoint <= 0xFFFF); | 149 ASSERT(codepoint <= 0xFFFF); |
| 147 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 150 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 148 | 151 |
| 149 SkScalar skWidth; | 152 SkScalar skWidth; |
| 150 SkRect skBounds; | 153 SkRect skBounds; |
| 151 uint16_t glyph = codepoint; | 154 uint16_t glyph = codepoint; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 hb_font_t* font = hb_font_create(m_face); | 359 hb_font_t* font = hb_font_create(m_face); |
| 357 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB
uzzFontData); | 360 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB
uzzFontData); |
| 358 float size = m_platformData->size(); | 361 float size = m_platformData->size(); |
| 359 int scale = SkiaScalarToHarfBuzzPosition(size); | 362 int scale = SkiaScalarToHarfBuzzPosition(size); |
| 360 hb_font_set_scale(font, scale, scale); | 363 hb_font_set_scale(font, scale, scale); |
| 361 hb_font_make_immutable(font); | 364 hb_font_make_immutable(font); |
| 362 return font; | 365 return font; |
| 363 } | 366 } |
| 364 | 367 |
| 365 } // namespace blink | 368 } // namespace blink |
| OLD | NEW |