george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006-2012 The Android Open Source Project |
| 3 | * Copyright 2012 Mozilla Foundation |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #ifndef SKFONTHOST_FREETYPE_COMMON_H_ |
| 10 | #define SKFONTHOST_FREETYPE_COMMON_H_ |
| 11 | |
| 12 | #include "SkGlyph.h" |
| 13 | #include "SkScalerContext.h" |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 14 | #include "SkTypeface.h" |
bungeman | 14df833 | 2014-10-28 15:07:23 -0700 | [diff] [blame^] | 15 | #include "SkTypes.h" |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 16 | |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 17 | #include <ft2build.h> |
| 18 | #include FT_FREETYPE_H |
| 19 | |
| 20 | #ifdef SK_DEBUG |
| 21 | #define SkASSERT_CONTINUE(pred) \ |
| 22 | do { \ |
| 23 | if (!(pred)) \ |
| 24 | SkDebugf("file %s:%d: assert failed '" #pred "'\n", __FILE__, __LINE__); \ |
| 25 | } while (false) |
| 26 | #else |
| 27 | #define SkASSERT_CONTINUE(pred) |
| 28 | #endif |
| 29 | |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 30 | class SkScalerContext_FreeType_Base : public SkScalerContext { |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 31 | protected: |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 32 | // See http://freetype.sourceforge.net/freetype2/docs/reference/ft2-bitmap_handling.html#FT_Bitmap_Embolden |
| 33 | // This value was chosen by eyeballing the result in Firefox and trying to match it. |
| 34 | static const FT_Pos kBitmapEmboldenStrength = 1 << 6; |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 35 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 36 | SkScalerContext_FreeType_Base(SkTypeface* typeface, const SkDescriptor *desc) |
| 37 | : INHERITED(typeface, desc) |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 38 | {} |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 39 | |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 40 | void generateGlyphImage(FT_Face face, const SkGlyph& glyph); |
sugoi@google.com | 66a58ac | 2013-03-05 20:40:52 +0000 | [diff] [blame] | 41 | void generateGlyphPath(FT_Face face, SkPath* path); |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 42 | |
| 43 | private: |
| 44 | typedef SkScalerContext INHERITED; |
| 45 | }; |
| 46 | |
| 47 | class SkTypeface_FreeType : public SkTypeface { |
bungeman | 3a21d61 | 2014-07-11 08:52:26 -0700 | [diff] [blame] | 48 | public: |
| 49 | /** For SkFontMgrs to make use of our ability to extract |
| 50 | * name and style from a stream, using FreeType's API. |
| 51 | */ |
bungeman | 14df833 | 2014-10-28 15:07:23 -0700 | [diff] [blame^] | 52 | class Scanner : ::SkNoncopyable { |
| 53 | public: |
| 54 | Scanner(); |
| 55 | ~Scanner(); |
| 56 | bool recognizedFont(SkStream* stream, int* numFonts) const; |
| 57 | bool scanFont(SkStream* stream, int ttcIndex, |
| 58 | SkString* name, SkFontStyle* style, bool* isFixedPitch) const; |
| 59 | private: |
| 60 | FT_Face openFace(SkStream* stream, int ttcIndex, FT_Stream ftStream) const; |
| 61 | FT_Library fLibrary; |
| 62 | mutable SkMutex fLibraryMutex; |
| 63 | }; |
bungeman | 3a21d61 | 2014-07-11 08:52:26 -0700 | [diff] [blame] | 64 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 65 | protected: |
bungeman | a4c4a2d | 2014-10-20 13:33:19 -0700 | [diff] [blame] | 66 | SkTypeface_FreeType(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch) |
reed@google.com | b4162b1 | 2013-07-02 16:32:29 +0000 | [diff] [blame] | 67 | : INHERITED(style, uniqueID, isFixedPitch) |
| 68 | , fGlyphCount(-1) |
| 69 | {} |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 70 | |
| 71 | virtual SkScalerContext* onCreateScalerContext( |
| 72 | const SkDescriptor*) const SK_OVERRIDE; |
| 73 | virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
reed@google.com | 2689f61 | 2013-03-20 20:01:47 +0000 | [diff] [blame] | 74 | virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 75 | SkAdvancedTypefaceMetrics::PerGlyphInfo, |
| 76 | const uint32_t*, uint32_t) const SK_OVERRIDE; |
reed@google.com | 38c37dd | 2013-03-21 15:36:26 +0000 | [diff] [blame] | 77 | virtual int onGetUPEM() const SK_OVERRIDE; |
reed@google.com | 35fe737 | 2013-10-30 15:07:03 +0000 | [diff] [blame] | 78 | virtual bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count, |
| 79 | int32_t adjustments[]) const SK_OVERRIDE; |
reed@google.com | b4162b1 | 2013-07-02 16:32:29 +0000 | [diff] [blame] | 80 | virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], |
| 81 | int glyphCount) const SK_OVERRIDE; |
| 82 | virtual int onCountGlyphs() const SK_OVERRIDE; |
| 83 | |
bungeman@google.com | 839702b | 2013-08-07 17:09:22 +0000 | [diff] [blame] | 84 | virtual LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE; |
bungeman@google.com | a980269 | 2013-08-07 02:45:25 +0000 | [diff] [blame] | 85 | |
bungeman@google.com | ddc218e | 2013-08-01 22:29:43 +0000 | [diff] [blame] | 86 | virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; |
| 87 | virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
| 88 | size_t length, void* data) const SK_OVERRIDE; |
| 89 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 90 | private: |
reed@google.com | b4162b1 | 2013-07-02 16:32:29 +0000 | [diff] [blame] | 91 | mutable int fGlyphCount; |
| 92 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 93 | typedef SkTypeface INHERITED; |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | #endif // SKFONTHOST_FREETYPE_COMMON_H_ |