Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "SkRefCnt.h" | |
| 9 #include "SkScalar.h" | |
| 10 | |
| 11 class SkPaint; | |
| 12 class SkTypeface; | |
| 13 | |
| 14 enum SkTextEncoding { | |
| 15 kUTF8_SkTextEncoding, | |
| 16 kUTF16_SkTextEncoding, | |
| 17 kUTF32_SkTextEncoding, | |
| 18 kGlyphID_SkTextEncoding, | |
| 19 }; | |
| 20 | |
| 21 /* | |
| 22 1. The Hinting enum in SkPaint is gone entirely, absorbed into SkFont's flags. | |
| 23 | |
| 24 2. SkPaint Flags look like this today | |
| 25 | |
| 26 enum Flags { | |
| 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 positioni ng | |
| 34 kDevKernText_Flag = 0x100, //!< mask to enable device kerning text | |
| 35 kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderer ing | |
| 36 kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strik es | |
| 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 he lp it | |
| 40 }; | |
| 41 | |
| 42 SkFont would absorb these: | |
| 43 | |
| 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 positioni ng | |
| 47 kDevKernText_Flag = 0x100, //!< mask to enable device kerning text | |
| 48 kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderer ing | |
| 49 kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strik es | |
| 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 he lp it | |
| 53 | |
| 54 leaving these still in paint | |
| 55 | |
| 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 | |
| 60 | |
| 61 3. Antialiasing | |
| 62 | |
| 63 SkFont has a mask-type: BW, AA, LCD | |
| 64 SkPaint has antialias boolean | |
| 65 | |
| 66 What to do if the font's mask-type disagrees with the paint? | |
| 67 | |
| 68 */ | |
| 69 | |
| 70 class SkFont : public SkRefCnt { | |
| 71 public: | |
| 72 enum Flags { | |
| 73 /** | |
| 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 by tecodes first. | |
| 76 * If that fails (e.g. there are no codes), then attempt to autohint. | |
| 77 */ | |
| 78 kEnableAutoHints_Flag = 1 << 0, | |
| 79 | |
| 80 /** | |
| 81 * If the typeface contains explicit bytecodes for hinting, use them. | |
| 82 * If both bytecode and auto hints are specified, attempt to use the by tecodes first; | |
| 83 * if that fails (e.g. there are no codes), then attempt to autohint. | |
| 84 */ | |
| 85 kEnableByteCodeHints_Flag = 1 << 1, | |
| 86 | |
| 87 /** | |
| 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 | |
| 91 * nearest integer. | |
| 92 * | |
| 93 * This applies to calls that return metrics (e.g. measureText) and to drawing the glyphs | |
| 94 * (see SkCanvas drawText and drawPosText). | |
| 95 */ | |
| 96 kUseNonlinearMetrics_Flag = 1 << 2, | |
| 97 | |
| 98 kVertical_Flag = 1 << 3, | |
| 99 kEmbeddedBitmaps_Flag = 1 << 4, | |
|
bungeman-skia
2014/05/02 19:29:43
I was just working on this with relation to Direct
| |
| 100 kGenA8FromLCD_Flag = 1 << 5, | |
| 101 kEmbolden_Flag = 1 << 6, | |
| 102 kDevKern_Flag = 1 << 7, // ifdef ANDROID ? | |
| 103 }; | |
| 104 | |
| 105 enum MaskType { | |
| 106 kBW_MaskType, | |
| 107 kA8_MaskType, | |
| 108 kLCD_MaskType, | |
| 109 }; | |
| 110 | |
| 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); | |
| 114 | |
| 115 /** | |
| 116 * Return a font with the same attributes of this font, but with the specif ied size. | |
| 117 * If size is not supported (e.g. <= 0 or non-finite) NULL will be returned . | |
| 118 */ | |
| 119 SkFont* cloneWithSize(SkScalar size) const; | |
| 120 | |
| 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; } | |
| 127 | |
| 128 int textToGlyphs(const void* text, size_t byteLength, SkTextEncoding, | |
| 129 uint16_t glyphs[], int maxGlyphCount) const; | |
| 130 | |
| 131 SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding) co nst; | |
| 132 | |
| 133 static SkFont* Testing_CreateFromPaint(const SkPaint&); | |
| 134 | |
| 135 private: | |
| 136 enum { | |
| 137 kAllFlags = 0xFF, | |
| 138 }; | |
| 139 | |
| 140 SkFont(SkTypeface*, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType , uint32_t flags); | |
| 141 virtual ~SkFont(); | |
| 142 | |
| 143 SkTypeface* fTypeface; | |
| 144 SkScalar fSize; | |
| 145 SkScalar fScaleX; | |
| 146 SkScalar fSkewX; | |
| 147 uint16_t fFlags; | |
| 148 uint8_t fMaskType; | |
| 149 uint8_t fPad; | |
| 150 }; | |
| 151 | |
| OLD | NEW |