Coverage Report

Created: 2025-06-24 08:20

/src/skia/include/core/SkFontArguments.h
Line
Count
Source
1
/*
2
 * Copyright 2017 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
#ifndef SkFontArguments_DEFINED
9
#define SkFontArguments_DEFINED
10
11
#include "include/core/SkColor.h"
12
#include "include/core/SkFourByteTag.h"
13
#include "include/core/SkTypes.h"
14
15
#include <cstdint>
16
17
/** Represents a set of actual arguments for a font. */
18
struct SkFontArguments {
19
    struct VariationPosition {
20
        struct Coordinate {
21
            SkFourByteTag axis;
22
            float value;
23
        };
24
        const Coordinate* coordinates;
25
        int coordinateCount;
26
    };
27
28
    /** Specify a palette to use and overrides for palette entries.
29
     *
30
     *  `overrides` is a list of pairs of palette entry index and color.
31
     *  The overriden palette entries will use the associated color.
32
     *  Override pairs with palette entry indices out of range will not be applied.
33
     *  Later override entries override earlier ones.
34
     */
35
    struct Palette {
36
        struct Override {
37
            uint16_t index;
38
            SkColor color;
39
        };
40
        int index;
41
        const Override* overrides;
42
        int overrideCount;
43
    };
44
45
    SkFontArguments()
46
327k
            : fCollectionIndex(0)
47
327k
            , fVariationDesignPosition{nullptr, 0}
48
327k
            , fPalette{0, nullptr, 0} {}
49
50
    /** Specify the index of the desired font.
51
     *
52
     *  Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed
53
     *  collections of fonts.
54
     */
55
327k
    SkFontArguments& setCollectionIndex(int collectionIndex) {
56
327k
        fCollectionIndex = collectionIndex;
57
327k
        return *this;
58
327k
    }
59
60
    /** Specify a position in the variation design space.
61
     *
62
     *  Any axis not specified will use the default value.
63
     *  Any specified axis not actually present in the font will be ignored.
64
     *
65
     *  @param position not copied. The value must remain valid for life of SkFontArguments.
66
     */
67
296k
    SkFontArguments& setVariationDesignPosition(VariationPosition position) {
68
296k
        fVariationDesignPosition.coordinates = position.coordinates;
69
296k
        fVariationDesignPosition.coordinateCount = position.coordinateCount;
70
296k
        return *this;
71
296k
    }
72
73
364k
    int getCollectionIndex() const {
74
364k
        return fCollectionIndex;
75
364k
    }
76
77
59.5k
    VariationPosition getVariationDesignPosition() const {
78
59.5k
        return fVariationDesignPosition;
79
59.5k
    }
80
81
296k
    SkFontArguments& setPalette(Palette palette) {
82
296k
        fPalette.index = palette.index;
83
296k
        fPalette.overrides = palette.overrides;
84
296k
        fPalette.overrideCount = palette.overrideCount;
85
296k
        return *this;
86
296k
    }
87
88
178k
    Palette getPalette() const { return fPalette; }
89
90
private:
91
    int fCollectionIndex;
92
    VariationPosition fVariationDesignPosition;
93
    Palette fPalette;
94
};
95
96
#endif