aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkFontArguments.h
blob: 473798fb8403217bd62ac6ccfa824cf9f530d799 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkFontAgruments_DEFINED
#define SkFontAgruments_DEFINED

#include "SkScalar.h"
#include "SkTypes.h"

/** Represents a set of actual arguments for a font. */
struct SkFontArguments {
    struct VariationPosition {
        struct Coordinate {
            SkFourByteTag axis;
            SkScalar value;
        };
        const Coordinate* coordinates;
        int coordinateCount;
    };
    // deprecated, use VariationCoordinate instead
    struct Axis {
       SkFourByteTag fTag;
       SkScalar fStyleValue;
    };

    SkFontArguments() : fCollectionIndex(0), fVariationDesignPosition{nullptr, 0} {}

    /** Specify the index of the desired font.
     *
     *  Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed
     *  collections of fonts.
     */
    SkFontArguments& setCollectionIndex(int collectionIndex) {
        fCollectionIndex = collectionIndex;
        return *this;
    }

    // deprecated, use setVariationDesignPosition instead.
    SkFontArguments& setAxes(const Axis* axes, int axisCount) {
        fVariationDesignPosition.coordinates =
                reinterpret_cast<const VariationPosition::Coordinate*>(axes);
        fVariationDesignPosition.coordinateCount = axisCount;
        return *this;
    }

    /** Specify a position in the variation design space.
     *
     *  Any axis not specified will use the default value.
     *  Any specified axis not actually present in the font will be ignored.
     *
     *  @param position not copied. The value must remain valid for life of SkFontArguments.
     */
    SkFontArguments& setVariationDesignPosition(VariationPosition position) {
        fVariationDesignPosition.coordinates = position.coordinates;
        fVariationDesignPosition.coordinateCount = position.coordinateCount;
        return *this;
    }

    int getCollectionIndex() const {
        return fCollectionIndex;
    }
    // deprecated, use getVariationDesignPosition instead.
    const Axis* getAxes(int* axisCount) const {
        *axisCount = fVariationDesignPosition.coordinateCount;
        return reinterpret_cast<const Axis*>(fVariationDesignPosition.coordinates);
    }
    VariationPosition getVariationDesignPosition() const {
        return fVariationDesignPosition;
    }
private:
    int fCollectionIndex;
    VariationPosition fVariationDesignPosition;
};

#endif