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" |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame^] | 13 | #include "SkMutex.h" |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 14 | #include "SkScalerContext.h" |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 15 | #include "SkTypeface.h" |
bungeman | 14df833 | 2014-10-28 15:07:23 -0700 | [diff] [blame] | 16 | #include "SkTypes.h" |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 17 | |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 18 | #include <ft2build.h> |
| 19 | #include FT_FREETYPE_H |
| 20 | |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 21 | class SkScalerContext_FreeType_Base : public SkScalerContext { |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 22 | protected: |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 23 | // See http://freetype.sourceforge.net/freetype2/docs/reference/ft2-bitmap_handling.html#FT_Bitmap_Embolden |
| 24 | // This value was chosen by eyeballing the result in Firefox and trying to match it. |
| 25 | static const FT_Pos kBitmapEmboldenStrength = 1 << 6; |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 26 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 27 | SkScalerContext_FreeType_Base(SkTypeface* typeface, const SkDescriptor *desc) |
| 28 | : INHERITED(typeface, desc) |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 29 | {} |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 30 | |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 31 | void generateGlyphImage(FT_Face face, const SkGlyph& glyph); |
sugoi@google.com | 66a58ac | 2013-03-05 20:40:52 +0000 | [diff] [blame] | 32 | void generateGlyphPath(FT_Face face, SkPath* path); |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 33 | |
| 34 | private: |
| 35 | typedef SkScalerContext INHERITED; |
| 36 | }; |
| 37 | |
| 38 | class SkTypeface_FreeType : public SkTypeface { |
bungeman | 3a21d61 | 2014-07-11 08:52:26 -0700 | [diff] [blame] | 39 | public: |
| 40 | /** For SkFontMgrs to make use of our ability to extract |
| 41 | * name and style from a stream, using FreeType's API. |
| 42 | */ |
bungeman | 14df833 | 2014-10-28 15:07:23 -0700 | [diff] [blame] | 43 | class Scanner : ::SkNoncopyable { |
| 44 | public: |
| 45 | Scanner(); |
| 46 | ~Scanner(); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 47 | struct AxisDefinition { |
| 48 | SkFourByteTag fTag; |
| 49 | SkFixed fMinimum; |
| 50 | SkFixed fDefault; |
| 51 | SkFixed fMaximum; |
| 52 | }; |
| 53 | using AxisDefinitions = SkSTArray<4, AxisDefinition, true>; |
bungeman | 14df833 | 2014-10-28 15:07:23 -0700 | [diff] [blame] | 54 | bool recognizedFont(SkStream* stream, int* numFonts) const; |
| 55 | bool scanFont(SkStream* stream, int ttcIndex, |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 56 | SkString* name, SkFontStyle* style, bool* isFixedPitch, |
| 57 | AxisDefinitions* axes) const; |
bungeman | 14df833 | 2014-10-28 15:07:23 -0700 | [diff] [blame] | 58 | private: |
| 59 | FT_Face openFace(SkStream* stream, int ttcIndex, FT_Stream ftStream) const; |
| 60 | FT_Library fLibrary; |
| 61 | mutable SkMutex fLibraryMutex; |
| 62 | }; |
bungeman | 3a21d61 | 2014-07-11 08:52:26 -0700 | [diff] [blame] | 63 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 64 | protected: |
bungeman | a4c4a2d | 2014-10-20 13:33:19 -0700 | [diff] [blame] | 65 | SkTypeface_FreeType(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch) |
reed@google.com | b4162b1 | 2013-07-02 16:32:29 +0000 | [diff] [blame] | 66 | : INHERITED(style, uniqueID, isFixedPitch) |
| 67 | , fGlyphCount(-1) |
| 68 | {} |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 69 | |
| 70 | virtual SkScalerContext* onCreateScalerContext( |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 71 | const SkDescriptor*) const override; |
| 72 | void onFilterRec(SkScalerContextRec*) const override; |
reed | 39a9a50 | 2015-05-12 09:50:04 -0700 | [diff] [blame] | 73 | SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 74 | PerGlyphInfo, const uint32_t*, uint32_t) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 75 | int onGetUPEM() const override; |
reed@google.com | 35fe737 | 2013-10-30 15:07:03 +0000 | [diff] [blame] | 76 | virtual bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 77 | int32_t adjustments[]) const override; |
reed@google.com | b4162b1 | 2013-07-02 16:32:29 +0000 | [diff] [blame] | 78 | virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 79 | int glyphCount) const override; |
| 80 | int onCountGlyphs() const override; |
reed@google.com | b4162b1 | 2013-07-02 16:32:29 +0000 | [diff] [blame] | 81 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 82 | LocalizedStrings* onCreateFamilyNameIterator() const override; |
bungeman@google.com | a980269 | 2013-08-07 02:45:25 +0000 | [diff] [blame] | 83 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 84 | int onGetTableTags(SkFontTableTag tags[]) const override; |
bungeman@google.com | ddc218e | 2013-08-01 22:29:43 +0000 | [diff] [blame] | 85 | virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 86 | size_t length, void* data) const override; |
bungeman@google.com | ddc218e | 2013-08-01 22:29:43 +0000 | [diff] [blame] | 87 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 88 | private: |
reed@google.com | b4162b1 | 2013-07-02 16:32:29 +0000 | [diff] [blame] | 89 | mutable int fGlyphCount; |
| 90 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 91 | typedef SkTypeface INHERITED; |
george@mozilla.com | c59b5da | 2012-08-23 00:39:08 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | #endif // SKFONTHOST_FREETYPE_COMMON_H_ |