• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINIKIN_MINIKIN_PAINT_H
18 #define MINIKIN_MINIKIN_PAINT_H
19 
20 #include <memory>
21 #include <string>
22 
23 #include "minikin/FamilyVariant.h"
24 #include "minikin/FontCollection.h"
25 #include "minikin/FontFamily.h"
26 #include "minikin/FontFeature.h"
27 #include "minikin/Hasher.h"
28 
29 namespace minikin {
30 
31 class FontCollection;
32 
33 // These describe what is stored in MinikinPaint.fontFlags.
34 enum MinikinFontFlags {
35     Embolden_Shift = 0,
36     LinearMetrics_Shift = 1,
37     Subpixel_Shift = 2,
38     EmbeddedBitmaps_Shift = 3,
39     ForceAutoHinting_Shift = 4,
40 
41     Embolden_Flag = 1 << Embolden_Shift,
42     LinearMetrics_Flag = 1 << LinearMetrics_Shift,
43     Subpixel_Flag = 1 << Subpixel_Shift,
44     EmbeddedBitmaps_Flag = 1 << EmbeddedBitmaps_Shift,
45     ForceAutoHinting_Flag = 1 << ForceAutoHinting_Shift,
46 };
47 
48 // Possibly move into own .h file?
49 // Note: if you add a field here, either add it to LayoutCacheKey
50 struct MinikinPaint {
MinikinPaintMinikinPaint51     MinikinPaint(const std::shared_ptr<FontCollection>& font)
52             : size(0),
53               scaleX(0),
54               skewX(0),
55               letterSpacing(0),
56               wordSpacing(0),
57               fontFlags(0),
58               localeListId(0),
59               familyVariant(FamilyVariant::DEFAULT),
60               fontFeatureSettings(),
61               font(font) {}
62 
63     bool skipCache() const;
64 
65     float size;
66     float scaleX;
67     float skewX;
68     float letterSpacing;
69     float wordSpacing;
70     uint32_t fontFlags;
71     uint32_t localeListId;
72     FontStyle fontStyle;
73     FamilyVariant familyVariant;
74     std::vector<FontFeature> fontFeatureSettings;
75     std::shared_ptr<FontCollection> font;
76 
copyFromMinikinPaint77     void copyFrom(const MinikinPaint& paint) { *this = paint; }
78 
79     MinikinPaint(const MinikinPaint&) = default;
80     MinikinPaint& operator=(const MinikinPaint&) = default;
81 
82     MinikinPaint(MinikinPaint&&) = default;
83     MinikinPaint& operator=(MinikinPaint&&) = default;
84 
getLetterSpacingInPxMinikinPaint85     float getLetterSpacingInPx() const { return letterSpacing * size * scaleX; }
86 
87     inline bool operator==(const MinikinPaint& paint) const {
88         return size == paint.size && scaleX == paint.scaleX && skewX == paint.skewX &&
89                letterSpacing == paint.letterSpacing && wordSpacing == paint.wordSpacing &&
90                fontFlags == paint.fontFlags && localeListId == paint.localeListId &&
91                fontStyle == paint.fontStyle && familyVariant == paint.familyVariant &&
92                fontFeatureSettings == paint.fontFeatureSettings && font.get() == paint.font.get();
93     }
94 
hashMinikinPaint95     uint32_t hash() const {
96         return Hasher()
97                 .update(size)
98                 .update(scaleX)
99                 .update(skewX)
100                 .update(letterSpacing)
101                 .update(wordSpacing)
102                 .update(fontFlags)
103                 .update(localeListId)
104                 .update(fontStyle.identifier())
105                 .update(static_cast<uint8_t>(familyVariant))
106                 .update(fontFeatureSettings)
107                 .update(font->getId())
108                 .hash();
109     }
110 };
111 
112 }  // namespace minikin
113 
114 #endif  // MINIKIN_MINIKIN_PAINT_H
115