2014-04-08 15:04:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-05-30 16:46:10 +00:00
|
|
|
#ifndef SkFont_DEFINED
|
|
|
|
#define SkFont_DEFINED
|
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkScalar.h"
|
|
|
|
|
|
|
|
class SkPaint;
|
|
|
|
class SkTypeface;
|
|
|
|
|
|
|
|
enum SkTextEncoding {
|
|
|
|
kUTF8_SkTextEncoding,
|
|
|
|
kUTF16_SkTextEncoding,
|
|
|
|
kUTF32_SkTextEncoding,
|
|
|
|
kGlyphID_SkTextEncoding,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
1. The Hinting enum in SkPaint is gone entirely, absorbed into SkFont's flags.
|
2014-04-09 03:04:11 +00:00
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
2. SkPaint Flags look like this today
|
2014-04-09 03:04:11 +00:00
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
enum Flags {
|
|
|
|
kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing
|
|
|
|
kDither_Flag = 0x04, //!< mask to enable dithering
|
|
|
|
kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text
|
|
|
|
kLinearText_Flag = 0x40, //!< mask to enable linear-text
|
|
|
|
kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning
|
|
|
|
kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering
|
|
|
|
kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes
|
|
|
|
kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
|
|
|
|
kVerticalText_Flag = 0x1000,
|
|
|
|
};
|
|
|
|
|
|
|
|
SkFont would absorb these:
|
2014-04-09 03:04:11 +00:00
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text
|
|
|
|
kLinearText_Flag = 0x40, //!< mask to enable linear-text
|
|
|
|
kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning
|
|
|
|
kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering
|
|
|
|
kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes
|
|
|
|
kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
|
|
|
|
kVerticalText_Flag = 0x1000,
|
|
|
|
|
|
|
|
leaving these still in paint
|
|
|
|
|
|
|
|
kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing
|
|
|
|
kDither_Flag = 0x04, //!< mask to enable dithering
|
|
|
|
|
|
|
|
3. Antialiasing
|
2014-04-09 03:04:11 +00:00
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
SkFont has a mask-type: BW, AA, LCD
|
|
|
|
SkPaint has antialias boolean
|
2014-04-09 03:04:11 +00:00
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
What to do if the font's mask-type disagrees with the paint?
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SkFont : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
enum Flags {
|
|
|
|
/**
|
|
|
|
* Use the system's automatic hinting mechanism to hint the typeface.
|
2014-08-19 20:18:58 +00:00
|
|
|
* This is a last resort hinting method applied only if other hinting methods do not apply.
|
|
|
|
* TODO: where to put auto-normal vs auto-light?
|
2014-04-08 15:04:29 +00:00
|
|
|
*/
|
|
|
|
kEnableAutoHints_Flag = 1 << 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the typeface contains explicit bytecodes for hinting, use them.
|
|
|
|
* If both bytecode and auto hints are specified, attempt to use the bytecodes first;
|
|
|
|
* if that fails (e.g. there are no codes), then attempt to autohint.
|
|
|
|
*/
|
|
|
|
kEnableByteCodeHints_Flag = 1 << 1,
|
|
|
|
|
2014-08-19 20:18:58 +00:00
|
|
|
/**
|
|
|
|
* If the typeface contains explicit bitmaps for hinting, use them.
|
|
|
|
* If both bytecode and auto hints are also specified, attempt to use the bitmaps first;
|
|
|
|
* if that fails (e.g. there are no bitmaps), then attempt to bytecode or autohint.
|
|
|
|
*/
|
|
|
|
kEmbeddedBitmaps_Flag = 1 << 2,
|
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
/**
|
|
|
|
* Use rounded metric values (e.g. advance).
|
|
|
|
* If either auto or bytecode hinting was used, apply those results to the metrics of the
|
|
|
|
* glyphs as well. If no hinting was applied, the metrics will just be rounded to the
|
|
|
|
* nearest integer.
|
|
|
|
*
|
|
|
|
* This applies to calls that return metrics (e.g. measureText) and to drawing the glyphs
|
|
|
|
* (see SkCanvas drawText and drawPosText).
|
|
|
|
*/
|
2014-08-19 20:18:58 +00:00
|
|
|
kUseNonlinearMetrics_Flag = 1 << 3,
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2014-08-19 20:18:58 +00:00
|
|
|
kVertical_Flag = 1 << 4,
|
2018-04-13 19:50:01 +00:00
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
kEmbolden_Flag = 1 << 6,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum MaskType {
|
|
|
|
kBW_MaskType,
|
|
|
|
kA8_MaskType,
|
|
|
|
kLCD_MaskType,
|
|
|
|
};
|
|
|
|
|
2016-05-12 17:09:30 +00:00
|
|
|
static sk_sp<SkFont> Make(sk_sp<SkTypeface>, SkScalar size, MaskType, uint32_t flags);
|
|
|
|
static sk_sp<SkFont> Make(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX,
|
|
|
|
MaskType, uint32_t flags);
|
2014-04-08 15:04:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a font with the same attributes of this font, but with the specified size.
|
|
|
|
* If size is not supported (e.g. <= 0 or non-finite) NULL will be returned.
|
|
|
|
*/
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkFont> makeWithSize(SkScalar size) const;
|
2016-07-19 14:59:22 +00:00
|
|
|
/**
|
|
|
|
* Return a font with the same attributes of this font, but with the flags.
|
|
|
|
*/
|
|
|
|
sk_sp<SkFont> makeWithFlags(uint32_t newFlags) const;
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2016-05-12 17:09:30 +00:00
|
|
|
SkTypeface* getTypeface() const { return fTypeface.get(); }
|
2014-04-08 15:04:29 +00:00
|
|
|
SkScalar getSize() const { return fSize; }
|
|
|
|
SkScalar getScaleX() const { return fScaleX; }
|
|
|
|
SkScalar getSkewX() const { return fSkewX; }
|
|
|
|
uint32_t getFlags() const { return fFlags; }
|
|
|
|
MaskType getMaskType() const { return (MaskType)fMaskType; }
|
|
|
|
|
2014-05-30 16:46:10 +00:00
|
|
|
bool isVertical() const { return SkToBool(fFlags & kVertical_Flag); }
|
|
|
|
bool isEmbolden() const { return SkToBool(fFlags & kEmbolden_Flag); }
|
|
|
|
bool isEnableAutoHints() const { return SkToBool(fFlags & kEnableAutoHints_Flag); }
|
|
|
|
bool isEnableByteCodeHints() const { return SkToBool(fFlags & kEnableByteCodeHints_Flag); }
|
|
|
|
bool isUseNonLinearMetrics() const { return SkToBool(fFlags & kUseNonlinearMetrics_Flag); }
|
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
int textToGlyphs(const void* text, size_t byteLength, SkTextEncoding,
|
2016-07-25 14:18:12 +00:00
|
|
|
SkGlyphID glyphs[], int maxGlyphCount) const;
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2016-07-19 14:59:22 +00:00
|
|
|
int countText(const void* text, size_t byteLength, SkTextEncoding encoding) {
|
|
|
|
return this->textToGlyphs(text, byteLength, encoding, nullptr, 0);
|
|
|
|
}
|
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding) const;
|
|
|
|
|
2016-05-12 17:09:30 +00:00
|
|
|
static sk_sp<SkFont> Testing_CreateFromPaint(const SkPaint&);
|
2014-04-08 15:04:29 +00:00
|
|
|
|
|
|
|
private:
|
2018-04-26 12:32:37 +00:00
|
|
|
static constexpr int kAllFlags = 0xFF;
|
2014-04-09 03:04:11 +00:00
|
|
|
|
2016-05-12 17:09:30 +00:00
|
|
|
SkFont(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType,
|
|
|
|
uint32_t flags);
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> fTypeface;
|
2014-04-08 15:04:29 +00:00
|
|
|
SkScalar fSize;
|
|
|
|
SkScalar fScaleX;
|
|
|
|
SkScalar fSkewX;
|
|
|
|
uint16_t fFlags;
|
|
|
|
uint8_t fMaskType;
|
2014-04-08 15:29:10 +00:00
|
|
|
// uint8_t fPad;
|
2014-04-08 15:04:29 +00:00
|
|
|
};
|
2014-05-30 16:46:10 +00:00
|
|
|
|
|
|
|
#endif
|