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 "SkScalar.h"
|
2018-10-24 14:26:32 +00:00
|
|
|
#include "SkTypeface.h"
|
2014-04-08 15:04:29 +00:00
|
|
|
|
|
|
|
class SkPaint;
|
|
|
|
|
|
|
|
enum SkTextEncoding {
|
|
|
|
kUTF8_SkTextEncoding,
|
|
|
|
kUTF16_SkTextEncoding,
|
|
|
|
kUTF32_SkTextEncoding,
|
|
|
|
kGlyphID_SkTextEncoding,
|
|
|
|
};
|
|
|
|
|
2018-10-22 18:24:07 +00:00
|
|
|
class SkFont {
|
2014-04-08 15:04:29 +00:00
|
|
|
public:
|
|
|
|
enum Flags {
|
|
|
|
/**
|
|
|
|
* Use the system's automatic hinting mechanism to hint the typeface.
|
|
|
|
*/
|
2018-10-22 18:24:07 +00:00
|
|
|
kForceAutoHinting_Flag = 1 << 0,
|
2014-04-08 15:04:29 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2018-10-22 18:24:07 +00:00
|
|
|
kEmbeddedBitmaps_Flag = 1 << 1,
|
2014-08-19 20:18:58 +00:00
|
|
|
|
2018-10-22 18:24:07 +00:00
|
|
|
kSubpixel_Flag = 1 << 2,
|
|
|
|
kLinearMetrics_Flag = 1 << 3,
|
2018-10-23 16:05:47 +00:00
|
|
|
kEmbolden_Flag = 1 << 4,
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2018-10-24 17:34:11 +00:00
|
|
|
kDEPRECATED_Antialias_Flag = 1 << 5,
|
|
|
|
kDEPRECATED_LCDRender_Flag = 1 << 6,
|
|
|
|
};
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2018-10-24 17:34:11 +00:00
|
|
|
enum Hinting {
|
|
|
|
kNo_Hinting = 0, //!< glyph outlines unchanged
|
|
|
|
kSlight_Hinting = 1, //!< minimal modification to improve constrast
|
|
|
|
kNormal_Hinting = 2, //!< glyph outlines modified to improve constrast
|
|
|
|
kFull_Hinting = 3, //!< modifies glyph outlines for maximum constrast
|
2014-04-08 15:04:29 +00:00
|
|
|
};
|
|
|
|
|
2018-10-24 17:34:11 +00:00
|
|
|
SkFont();
|
2018-10-22 18:24:07 +00:00
|
|
|
SkFont(sk_sp<SkTypeface>, SkScalar size, uint32_t flags);
|
2018-10-24 14:26:32 +00:00
|
|
|
SkFont(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX, uint32_t flags,
|
|
|
|
int align = 0);
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2018-10-24 17:34:11 +00:00
|
|
|
bool isForceAutoHinting() const { return SkToBool(fFlags & kForceAutoHinting_Flag); }
|
|
|
|
bool isEmbeddedBitmaps() const { return SkToBool(fFlags & kEmbeddedBitmaps_Flag); }
|
|
|
|
bool isSubpixel() const { return SkToBool(fFlags & kSubpixel_Flag); }
|
|
|
|
bool isLinearMetrics() const { return SkToBool(fFlags & kLinearMetrics_Flag); }
|
|
|
|
bool isEmbolden() const { return SkToBool(fFlags & kEmbolden_Flag); }
|
|
|
|
Hinting getHinting() const { return (Hinting)fHinting; }
|
|
|
|
|
|
|
|
void setForceAutoHinting(bool);
|
|
|
|
void setEmbeddedBitmaps(bool);
|
|
|
|
void setSubpixel(bool);
|
|
|
|
void setLinearMetrics(bool);
|
|
|
|
void setEmbolden(bool);
|
|
|
|
void setHinting(Hinting);
|
|
|
|
|
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.
|
|
|
|
*/
|
2018-10-22 18:24:07 +00:00
|
|
|
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.
|
|
|
|
*/
|
2018-10-22 18:24:07 +00:00
|
|
|
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; }
|
|
|
|
|
2018-10-22 18:24:07 +00:00
|
|
|
sk_sp<SkTypeface> refTypeface() const { return fTypeface; }
|
|
|
|
|
2018-10-24 17:34:11 +00:00
|
|
|
void setTypeface(sk_sp<SkTypeface> tf) { fTypeface = tf; }
|
2018-10-22 18:24:07 +00:00
|
|
|
void setSize(SkScalar);
|
|
|
|
void setScaleX(SkScalar);
|
|
|
|
void setSkewX(SkScalar);
|
|
|
|
void setFlags(uint32_t);
|
2014-05-30 16:46:10 +00:00
|
|
|
|
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;
|
|
|
|
|
2018-10-22 18:24:07 +00:00
|
|
|
void LEGACY_applyToPaint(SkPaint*) const;
|
|
|
|
static SkFont LEGACY_ExtractFromPaint(const SkPaint&);
|
2014-04-08 15:04:29 +00:00
|
|
|
|
|
|
|
private:
|
2018-10-24 17:34:11 +00:00
|
|
|
static constexpr unsigned kAllFlags = 0x07F;
|
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;
|
2018-10-24 17:34:11 +00:00
|
|
|
uint8_t fFlags;
|
|
|
|
uint8_t fAlign;
|
|
|
|
uint8_t fHinting;
|
2014-04-08 15:04:29 +00:00
|
|
|
};
|
2014-05-30 16:46:10 +00:00
|
|
|
|
|
|
|
#endif
|