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/Hasher.h" 27 28 namespace minikin { 29 30 class FontCollection; 31 32 // These describe what is stored in MinikinPaint.fontFlags. 33 enum MinikinFontFlags { 34 Embolden_Shift = 0, 35 LinearMetrics_Shift = 1, 36 Subpixel_Shift = 2, 37 EmbeddedBitmaps_Shift = 3, 38 ForceAutoHinting_Shift = 4, 39 40 Embolden_Flag = 1 << Embolden_Shift, 41 LinearMetrics_Flag = 1 << LinearMetrics_Shift, 42 Subpixel_Flag = 1 << Subpixel_Shift, 43 EmbeddedBitmaps_Flag = 1 << EmbeddedBitmaps_Shift, 44 ForceAutoHinting_Flag = 1 << ForceAutoHinting_Shift, 45 }; 46 47 // Possibly move into own .h file? 48 // Note: if you add a field here, either add it to LayoutCacheKey or to skipCache() 49 struct MinikinPaint { MinikinPaintMinikinPaint50 MinikinPaint(const std::shared_ptr<FontCollection>& font) 51 : size(0), 52 scaleX(0), 53 skewX(0), 54 letterSpacing(0), 55 wordSpacing(0), 56 fontFlags(0), 57 localeListId(0), 58 familyVariant(FamilyVariant::DEFAULT), 59 fontFeatureSettings(), 60 font(font) {} 61 skipCacheMinikinPaint62 bool skipCache() const { return !fontFeatureSettings.empty(); } 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 std::string fontFeatureSettings; 74 std::shared_ptr<FontCollection> font; 75 copyFromMinikinPaint76 void copyFrom(const MinikinPaint& paint) { *this = paint; } 77 78 MinikinPaint(const MinikinPaint&) = default; 79 MinikinPaint& operator=(const MinikinPaint&) = default; 80 81 MinikinPaint(MinikinPaint&&) = default; 82 MinikinPaint& operator=(MinikinPaint&&) = default; 83 84 inline bool operator==(const MinikinPaint& paint) const { 85 return size == paint.size && scaleX == paint.scaleX && skewX == paint.skewX && 86 letterSpacing == paint.letterSpacing && wordSpacing == paint.wordSpacing && 87 fontFlags == paint.fontFlags && localeListId == paint.localeListId && 88 fontStyle == paint.fontStyle && familyVariant == paint.familyVariant && 89 fontFeatureSettings == paint.fontFeatureSettings && font.get() == paint.font.get(); 90 } 91 hashMinikinPaint92 uint32_t hash() const { 93 return Hasher() 94 .update(size) 95 .update(scaleX) 96 .update(skewX) 97 .update(letterSpacing) 98 .update(wordSpacing) 99 .update(fontFlags) 100 .update(localeListId) 101 .update(fontStyle.identifier()) 102 .update(static_cast<uint8_t>(familyVariant)) 103 .updateString(fontFeatureSettings) 104 .update(font->getId()) 105 .hash(); 106 } 107 }; 108 109 } // namespace minikin 110 111 #endif // MINIKIN_MINIKIN_PAINT_H 112