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 ANDROID_GRAPHICS_PAINT_H_ 18 #define ANDROID_GRAPHICS_PAINT_H_ 19 20 #include <cutils/compiler.h> 21 22 #include <SkPaint.h> 23 #include <string> 24 25 #include <minikin/FontFamily.h> 26 27 namespace android { 28 29 class ANDROID_API Paint : public SkPaint { 30 public: 31 // Default values for underlined and strikethrough text, 32 // as defined by Skia in SkTextFormatParams.h. 33 constexpr static float kStdStrikeThru_Offset = (-6.0f / 21.0f); 34 constexpr static float kStdUnderline_Offset = (1.0f / 9.0f); 35 constexpr static float kStdUnderline_Thickness = (1.0f / 18.0f); 36 37 constexpr static float kStdUnderline_Top = 38 kStdUnderline_Offset - 0.5f * kStdUnderline_Thickness; 39 40 constexpr static float kStdStrikeThru_Thickness = kStdUnderline_Thickness; 41 constexpr static float kStdStrikeThru_Top = 42 kStdStrikeThru_Offset - 0.5f * kStdStrikeThru_Thickness; 43 44 Paint(); 45 Paint(const Paint& paint); 46 Paint(const SkPaint& paint); // NOLINT(implicit) 47 ~Paint(); 48 49 Paint& operator=(const Paint& other); 50 51 friend bool operator==(const Paint& a, const Paint& b); 52 friend bool operator!=(const Paint& a, const Paint& b) { 53 return !(a == b); 54 } 55 setLetterSpacing(float letterSpacing)56 void setLetterSpacing(float letterSpacing) { 57 mLetterSpacing = letterSpacing; 58 } 59 getLetterSpacing()60 float getLetterSpacing() const { 61 return mLetterSpacing; 62 } 63 setWordSpacing(float wordSpacing)64 void setWordSpacing(float wordSpacing) { 65 mWordSpacing = wordSpacing; 66 } 67 getWordSpacing()68 float getWordSpacing() const { 69 return mWordSpacing; 70 } 71 setFontFeatureSettings(const std::string & fontFeatureSettings)72 void setFontFeatureSettings(const std::string& fontFeatureSettings) { 73 mFontFeatureSettings = fontFeatureSettings; 74 } 75 getFontFeatureSettings()76 std::string getFontFeatureSettings() const { 77 return mFontFeatureSettings; 78 } 79 setMinikinLangListId(uint32_t minikinLangListId)80 void setMinikinLangListId(uint32_t minikinLangListId) { 81 mMinikinLangListId = minikinLangListId; 82 } 83 getMinikinLangListId()84 uint32_t getMinikinLangListId() const { 85 return mMinikinLangListId; 86 } 87 setFontVariant(minikin::FontVariant variant)88 void setFontVariant(minikin::FontVariant variant) { 89 mFontVariant = variant; 90 } 91 getFontVariant()92 minikin::FontVariant getFontVariant() const { 93 return mFontVariant; 94 } 95 setHyphenEdit(uint32_t hyphen)96 void setHyphenEdit(uint32_t hyphen) { 97 mHyphenEdit = hyphen; 98 } 99 getHyphenEdit()100 uint32_t getHyphenEdit() const { 101 return mHyphenEdit; 102 } 103 104 private: 105 float mLetterSpacing = 0; 106 float mWordSpacing = 0; 107 std::string mFontFeatureSettings; 108 uint32_t mMinikinLangListId; 109 minikin::FontVariant mFontVariant; 110 uint32_t mHyphenEdit = 0; 111 }; 112 113 } // namespace android 114 115 #endif // ANDROID_GRAPHICS_PAINT_H_ 116