Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 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 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_GRAPHICS_PAINT_H_ |
| 18 | #define ANDROID_GRAPHICS_PAINT_H_ |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 19 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 20 | #include <cutils/compiler.h> |
| 21 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 22 | #include <SkPaint.h> |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 23 | #include <string> |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 24 | |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 25 | #include <minikin/FontFamily.h> |
| 26 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 27 | namespace android { |
| 28 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 29 | class ANDROID_API Paint : public SkPaint { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 30 | public: |
Roozbeh Pournader | ca8a04a | 2017-06-06 18:30:29 -0700 | [diff] [blame] | 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 | |
Roozbeh Pournader | 1378a9d | 2017-07-13 12:45:20 -0700 | [diff] [blame^] | 40 | constexpr static float kStdStrikeThru_Thickness = kStdUnderline_Thickness; |
| 41 | constexpr static float kStdStrikeThru_Top = |
| 42 | kStdStrikeThru_Offset - 0.5f * kStdStrikeThru_Thickness; |
| 43 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 44 | Paint(); |
| 45 | Paint(const Paint& paint); |
Chih-Hung Hsieh | a619ec7 | 2016-08-29 14:52:43 -0700 | [diff] [blame] | 46 | Paint(const SkPaint& paint); // NOLINT(implicit) |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 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 | |
Behdad Esfahbod | fa80f74 | 2014-07-17 19:10:39 -0400 | [diff] [blame] | 56 | void setLetterSpacing(float letterSpacing) { |
| 57 | mLetterSpacing = letterSpacing; |
| 58 | } |
| 59 | |
| 60 | float getLetterSpacing() const { |
| 61 | return mLetterSpacing; |
| 62 | } |
| 63 | |
Seigo Nonaka | 219e2c79 | 2016-11-15 19:01:45 +0900 | [diff] [blame] | 64 | void setWordSpacing(float wordSpacing) { |
| 65 | mWordSpacing = wordSpacing; |
| 66 | } |
| 67 | |
| 68 | float getWordSpacing() const { |
| 69 | return mWordSpacing; |
| 70 | } |
| 71 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 72 | void setFontFeatureSettings(const std::string& fontFeatureSettings) { |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 73 | mFontFeatureSettings = fontFeatureSettings; |
| 74 | } |
| 75 | |
| 76 | std::string getFontFeatureSettings() const { |
| 77 | return mFontFeatureSettings; |
| 78 | } |
| 79 | |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 80 | void setMinikinLangListId(uint32_t minikinLangListId) { |
| 81 | mMinikinLangListId = minikinLangListId; |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 84 | uint32_t getMinikinLangListId() const { |
| 85 | return mMinikinLangListId; |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 88 | void setFontVariant(minikin::FontVariant variant) { |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 89 | mFontVariant = variant; |
| 90 | } |
| 91 | |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 92 | minikin::FontVariant getFontVariant() const { |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 93 | return mFontVariant; |
| 94 | } |
| 95 | |
Raph Levien | 210a189 | 2015-03-09 14:42:14 -0700 | [diff] [blame] | 96 | void setHyphenEdit(uint32_t hyphen) { |
| 97 | mHyphenEdit = hyphen; |
| 98 | } |
| 99 | |
| 100 | uint32_t getHyphenEdit() const { |
| 101 | return mHyphenEdit; |
| 102 | } |
| 103 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 104 | private: |
Raph Levien | 210a189 | 2015-03-09 14:42:14 -0700 | [diff] [blame] | 105 | float mLetterSpacing = 0; |
Seigo Nonaka | 219e2c79 | 2016-11-15 19:01:45 +0900 | [diff] [blame] | 106 | float mWordSpacing = 0; |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 107 | std::string mFontFeatureSettings; |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 108 | uint32_t mMinikinLangListId; |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 109 | minikin::FontVariant mFontVariant; |
Raph Levien | 210a189 | 2015-03-09 14:42:14 -0700 | [diff] [blame] | 110 | uint32_t mHyphenEdit = 0; |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | } // namespace android |
| 114 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 115 | #endif // ANDROID_GRAPHICS_PAINT_H_ |