2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
16 kUTF16_SkTextEncoding,
17 kUTF32_SkTextEncoding,
18 kGlyphID_SkTextEncoding,
22 1. The Hinting enum in SkPaint is gone entirely, absorbed into SkFont's flags.
24 2. SkPaint Flags look like this today
27 kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing
28 kDither_Flag = 0x04, //!< mask to enable dithering
29 kUnderlineText_Flag = 0x08, //!< mask to enable underline text
30 kStrikeThruText_Flag = 0x10, //!< mask to enable strike-thru text
31 kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text
32 kLinearText_Flag = 0x40, //!< mask to enable linear-text
33 kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning
34 kDevKernText_Flag = 0x100, //!< mask to enable device kerning text
35 kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering
36 kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes
37 kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
38 kVerticalText_Flag = 0x1000,
39 kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it
42 SkFont would absorb these:
44 kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text
45 kLinearText_Flag = 0x40, //!< mask to enable linear-text
46 kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning
47 kDevKernText_Flag = 0x100, //!< mask to enable device kerning text
48 kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering
49 kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes
50 kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
51 kVerticalText_Flag = 0x1000,
52 kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it
54 leaving these still in paint
56 kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing
57 kDither_Flag = 0x04, //!< mask to enable dithering
58 kUnderlineText_Flag = 0x08, //!< mask to enable underline text
59 kStrikeThruText_Flag = 0x10, //!< mask to enable strike-thru text
63 SkFont has a mask-type: BW, AA, LCD
64 SkPaint has antialias boolean
66 What to do if the font's mask-type disagrees with the paint?
70 class SkFont : public SkRefCnt {
74 * Use the system's automatic hinting mechanism to hint the typeface.
75 * If both bytecode and auto hints are specified, attempt to use the bytecodes first.
76 * If that fails (e.g. there are no codes), then attempt to autohint.
78 kEnableAutoHints_Flag = 1 << 0,
81 * If the typeface contains explicit bytecodes for hinting, use them.
82 * If both bytecode and auto hints are specified, attempt to use the bytecodes first;
83 * if that fails (e.g. there are no codes), then attempt to autohint.
85 kEnableByteCodeHints_Flag = 1 << 1,
88 * Use rounded metric values (e.g. advance).
89 * If either auto or bytecode hinting was used, apply those results to the metrics of the
90 * glyphs as well. If no hinting was applied, the metrics will just be rounded to the
93 * This applies to calls that return metrics (e.g. measureText) and to drawing the glyphs
94 * (see SkCanvas drawText and drawPosText).
96 kUseNonlinearMetrics_Flag = 1 << 2,
98 kVertical_Flag = 1 << 3,
99 kEmbeddedBitmaps_Flag = 1 << 4,
100 kGenA8FromLCD_Flag = 1 << 5,
101 kEmbolden_Flag = 1 << 6,
102 kDevKern_Flag = 1 << 7, // ifdef ANDROID ?
111 static SkFont* Create(SkTypeface*, SkScalar size, MaskType, uint32_t flags);
112 static SkFont* Create(SkTypeface*, SkScalar size, SkScalar scaleX, SkScalar skewX,
113 MaskType, uint32_t flags);
116 * Return a font with the same attributes of this font, but with the specified size.
117 * If size is not supported (e.g. <= 0 or non-finite) NULL will be returned.
119 SkFont* cloneWithSize(SkScalar size) const;
121 SkTypeface* getTypeface() const { return fTypeface; }
122 SkScalar getSize() const { return fSize; }
123 SkScalar getScaleX() const { return fScaleX; }
124 SkScalar getSkewX() const { return fSkewX; }
125 uint32_t getFlags() const { return fFlags; }
126 MaskType getMaskType() const { return (MaskType)fMaskType; }
128 int textToGlyphs(const void* text, size_t byteLength, SkTextEncoding,
129 uint16_t glyphs[], int maxGlyphCount) const;
131 SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding) const;
133 static SkFont* Testing_CreateFromPaint(const SkPaint&);
140 SkFont(SkTypeface*, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType, uint32_t flags);
143 SkTypeface* fTypeface;