Debian Codegraph @

src/ports/SkFontHost_FreeType_common.h

raw
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 "include/core/SkColor.h"
13 #include "include/core/SkSpan.h"
14 #include "include/core/SkTypes.h"
15 #include "src/core/SkGlyph.h"
16 #include "src/core/SkScalerContext.h"
17
18 class SkCanvas;
19 class SkPathBuilder;
20
21 // These are forward declared to avoid pimpl but also hide the FreeType implementation.
22 typedef struct FT_FaceRec_* FT_Face;
23 typedef signed long FT_Pos;
24
25
26 #ifdef SK_DEBUG
27 const char* SkTraceFtrGetError(int);
28 #define SK_TRACEFTR(ERR, MSG, ...) \
29 SkDebugf("%s:%d:1: error: 0x%x '%s' " MSG "\n", __FILE__, __LINE__, (uint32_t)ERR, \
30 SkTraceFtrGetError((int)(ERR)), __VA_ARGS__)
31 #else
32 #define SK_TRACEFTR(ERR, ...) do { sk_ignore_unused_variable(ERR); } while (false)
33 #endif
34
35 struct SkScalerContextFTUtils {
36 SkColor fForegroundColor;
37 SkScalerContext::Flags fFlags;
38
39 using LoadGlyphFlags = uint32_t;
40
41 void init(SkColor fgColor, SkScalerContext::Flags);
42
43 bool isSubpixel() const {
44 return SkToBool(fFlags & SkScalerContext::kSubpixelPositioning_Flag);
45 }
46
47 bool isLinearMetrics() const {
48 return SkToBool(fFlags & SkScalerContext::kLinearMetrics_Flag);
49 }
50
51 bool drawCOLRv0Glyph(FT_Face, const SkGlyph&, LoadGlyphFlags,
52 SkSpan<SkColor> palette, SkCanvas*) const;
53 bool drawCOLRv1Glyph(FT_Face, const SkGlyph&, LoadGlyphFlags,
54 SkSpan<SkColor> palette, SkCanvas*) const;
55 bool drawSVGGlyph(FT_Face, const SkGlyph&, LoadGlyphFlags,
56 SkSpan<SkColor> palette, SkCanvas*) const;
57 void generateGlyphImage(FT_Face, const SkGlyph&, void*, const SkMatrix& bitmapTransform,
58 const SkMaskGamma::PreBlend&) const;
59 bool generateGlyphPath(FT_Face, SkPathBuilder*) const;
60
61 /** Computes a bounding box for a COLRv1 glyph.
62 *
63 * This method may change the configured size and transforms on FT_Face. Make sure to
64 * configure size, matrix and load glyphs as needed after using this function to restore the
65 * state of FT_Face.
66 */
67 static bool computeColrV1GlyphBoundingBox(FT_Face, SkGlyphID, SkRect* bounds);
68
69 private:
70 bool generateFacePath(FT_Face, SkGlyphID, LoadGlyphFlags, SkPathBuilder*) const;
71 };
72
73 #endif // SKFONTHOST_FREETYPE_COMMON_H_