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