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 | |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 20 | #include "Typeface.h" |
| 21 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 22 | #include <cutils/compiler.h> |
| 23 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 24 | #include <SkPaint.h> |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 25 | #include <string> |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 26 | |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 27 | #include <minikin/FontFamily.h> |
| 28 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 29 | namespace android { |
| 30 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 31 | class ANDROID_API Paint : public SkPaint { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 32 | public: |
Roozbeh Pournader | ca8a04a | 2017-06-06 18:30:29 -0700 | [diff] [blame] | 33 | // Default values for underlined and strikethrough text, |
| 34 | // as defined by Skia in SkTextFormatParams.h. |
| 35 | constexpr static float kStdStrikeThru_Offset = (-6.0f / 21.0f); |
| 36 | constexpr static float kStdUnderline_Offset = (1.0f / 9.0f); |
| 37 | constexpr static float kStdUnderline_Thickness = (1.0f / 18.0f); |
| 38 | |
| 39 | constexpr static float kStdUnderline_Top = |
| 40 | kStdUnderline_Offset - 0.5f * kStdUnderline_Thickness; |
| 41 | |
Roozbeh Pournader | 1378a9d | 2017-07-13 12:45:20 -0700 | [diff] [blame] | 42 | constexpr static float kStdStrikeThru_Thickness = kStdUnderline_Thickness; |
| 43 | constexpr static float kStdStrikeThru_Top = |
| 44 | kStdStrikeThru_Offset - 0.5f * kStdStrikeThru_Thickness; |
| 45 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 46 | Paint(); |
| 47 | Paint(const Paint& paint); |
Chih-Hung Hsieh | a619ec7 | 2016-08-29 14:52:43 -0700 | [diff] [blame] | 48 | Paint(const SkPaint& paint); // NOLINT(implicit) |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 49 | ~Paint(); |
| 50 | |
| 51 | Paint& operator=(const Paint& other); |
| 52 | |
| 53 | friend bool operator==(const Paint& a, const Paint& b); |
| 54 | friend bool operator!=(const Paint& a, const Paint& b) { |
| 55 | return !(a == b); |
| 56 | } |
| 57 | |
Behdad Esfahbod | fa80f74 | 2014-07-17 19:10:39 -0400 | [diff] [blame] | 58 | void setLetterSpacing(float letterSpacing) { |
| 59 | mLetterSpacing = letterSpacing; |
| 60 | } |
| 61 | |
| 62 | float getLetterSpacing() const { |
| 63 | return mLetterSpacing; |
| 64 | } |
| 65 | |
Seigo Nonaka | 219e2c79 | 2016-11-15 19:01:45 +0900 | [diff] [blame] | 66 | void setWordSpacing(float wordSpacing) { |
| 67 | mWordSpacing = wordSpacing; |
| 68 | } |
| 69 | |
| 70 | float getWordSpacing() const { |
| 71 | return mWordSpacing; |
| 72 | } |
| 73 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 74 | void setFontFeatureSettings(const std::string& fontFeatureSettings) { |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 75 | mFontFeatureSettings = fontFeatureSettings; |
| 76 | } |
| 77 | |
| 78 | std::string getFontFeatureSettings() const { |
| 79 | return mFontFeatureSettings; |
| 80 | } |
| 81 | |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 82 | void setMinikinLangListId(uint32_t minikinLangListId) { |
| 83 | mMinikinLangListId = minikinLangListId; |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 86 | uint32_t getMinikinLangListId() const { |
| 87 | return mMinikinLangListId; |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 88 | } |
| 89 | |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 90 | void setFontVariant(minikin::FontVariant variant) { |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 91 | mFontVariant = variant; |
| 92 | } |
| 93 | |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 94 | minikin::FontVariant getFontVariant() const { |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 95 | return mFontVariant; |
| 96 | } |
| 97 | |
Raph Levien | 210a189 | 2015-03-09 14:42:14 -0700 | [diff] [blame] | 98 | void setHyphenEdit(uint32_t hyphen) { |
| 99 | mHyphenEdit = hyphen; |
| 100 | } |
| 101 | |
| 102 | uint32_t getHyphenEdit() const { |
| 103 | return mHyphenEdit; |
| 104 | } |
| 105 | |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 106 | void setAndroidTypeface(Typeface* typeface) { |
| 107 | mTypeface = typeface; |
| 108 | } |
| 109 | |
| 110 | const Typeface* getAndroidTypeface() const { |
| 111 | return mTypeface; |
| 112 | } |
| 113 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 114 | private: |
Raph Levien | 210a189 | 2015-03-09 14:42:14 -0700 | [diff] [blame] | 115 | float mLetterSpacing = 0; |
Seigo Nonaka | 219e2c79 | 2016-11-15 19:01:45 +0900 | [diff] [blame] | 116 | float mWordSpacing = 0; |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 117 | std::string mFontFeatureSettings; |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 118 | uint32_t mMinikinLangListId; |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 119 | minikin::FontVariant mFontVariant; |
Raph Levien | 210a189 | 2015-03-09 14:42:14 -0700 | [diff] [blame] | 120 | uint32_t mHyphenEdit = 0; |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 121 | // The native Typeface object has the same lifetime of the Java Typeface object. The Java Paint |
| 122 | // object holds a strong reference to the Java Typeface object. Thus, following pointer can |
| 123 | // never be a dangling pointer. Note that nullptr is valid: it means the default typeface. |
| 124 | const Typeface* mTypeface = nullptr; |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | } // namespace android |
| 128 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 129 | #endif // ANDROID_GRAPHICS_PAINT_H_ |