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 verticalText(false), 61 fontFeatureSettings(), 62 font(font) {} 63 64 float size; 65 float scaleX; 66 float skewX; 67 float letterSpacing; 68 float wordSpacing; 69 uint32_t fontFlags; 70 uint32_t localeListId; 71 FontStyle fontStyle; 72 FamilyVariant familyVariant; 73 bool verticalText; 74 std::vector<FontFeature> fontFeatureSettings; 75 std::shared_ptr<FontCollection> font; 76 VariationSettings fontVariationSettings; 77 copyFromMinikinPaint78 void copyFrom(const MinikinPaint& paint) { *this = paint; } 79 80 MinikinPaint(const MinikinPaint&) = default; 81 MinikinPaint& operator=(const MinikinPaint&) = default; 82 83 MinikinPaint(MinikinPaint&&) = default; 84 MinikinPaint& operator=(MinikinPaint&&) = default; 85 getLetterSpacingInPxMinikinPaint86 float getLetterSpacingInPx() const { return letterSpacing * size * scaleX; } 87 88 inline bool operator==(const MinikinPaint& paint) const { 89 return size == paint.size && scaleX == paint.scaleX && skewX == paint.skewX && 90 letterSpacing == paint.letterSpacing && wordSpacing == paint.wordSpacing && 91 fontFlags == paint.fontFlags && localeListId == paint.localeListId && 92 fontStyle == paint.fontStyle && familyVariant == paint.familyVariant && 93 fontFeatureSettings == paint.fontFeatureSettings && font.get() == paint.font.get() && 94 fontVariationSettings == paint.fontVariationSettings && 95 verticalText == paint.verticalText; 96 } 97 hashMinikinPaint98 uint32_t hash() const { 99 return Hasher() 100 .update(size) 101 .update(scaleX) 102 .update(skewX) 103 .update(letterSpacing) 104 .update(wordSpacing) 105 .update(fontFlags) 106 .update(localeListId) 107 .update(fontStyle.identifier()) 108 .update(static_cast<uint8_t>(familyVariant)) 109 .update(fontFeatureSettings) 110 .update(verticalText) 111 .update(font->getId()) 112 .update(fontVariationSettings) 113 .hash(); 114 } 115 }; 116 117 } // namespace minikin 118 119 #endif // MINIKIN_MINIKIN_PAINT_H 120