blob: a5d83a0ca018d57bc91623ebda4fe6945d69a8a3 [file] [log] [blame]
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -04001/*
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 Gampeed6b9df2014-11-20 22:02:20 -080017#ifndef ANDROID_GRAPHICS_PAINT_H_
18#define ANDROID_GRAPHICS_PAINT_H_
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040019
sergeyvdccca442016-03-21 15:38:21 -070020#include <cutils/compiler.h>
21
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040022#include <SkPaint.h>
Behdad Esfahbod805f6eb2014-07-29 18:43:03 -040023#include <string>
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040024
Derek Sollenberger6f030232014-08-07 08:10:39 -040025#include <minikin/FontFamily.h>
26
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040027namespace android {
28
sergeyvdccca442016-03-21 15:38:21 -070029class ANDROID_API Paint : public SkPaint {
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040030public:
Roozbeh Pournaderca8a04a2017-06-06 18:30:29 -070031 // 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 Pournader1378a9d2017-07-13 12:45:20 -070040 constexpr static float kStdStrikeThru_Thickness = kStdUnderline_Thickness;
41 constexpr static float kStdStrikeThru_Top =
42 kStdStrikeThru_Offset - 0.5f * kStdStrikeThru_Thickness;
43
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040044 Paint();
45 Paint(const Paint& paint);
Chih-Hung Hsieha619ec72016-08-29 14:52:43 -070046 Paint(const SkPaint& paint); // NOLINT(implicit)
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040047 ~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 Esfahbodfa80f742014-07-17 19:10:39 -040056 void setLetterSpacing(float letterSpacing) {
57 mLetterSpacing = letterSpacing;
58 }
59
60 float getLetterSpacing() const {
61 return mLetterSpacing;
62 }
63
Seigo Nonaka219e2c792016-11-15 19:01:45 +090064 void setWordSpacing(float wordSpacing) {
65 mWordSpacing = wordSpacing;
66 }
67
68 float getWordSpacing() const {
69 return mWordSpacing;
70 }
71
sergeyvdccca442016-03-21 15:38:21 -070072 void setFontFeatureSettings(const std::string& fontFeatureSettings) {
Behdad Esfahbod805f6eb2014-07-29 18:43:03 -040073 mFontFeatureSettings = fontFeatureSettings;
74 }
75
76 std::string getFontFeatureSettings() const {
77 return mFontFeatureSettings;
78 }
79
Seigo Nonakacfc607c2015-12-02 10:53:18 +090080 void setMinikinLangListId(uint32_t minikinLangListId) {
81 mMinikinLangListId = minikinLangListId;
Derek Sollenberger6f030232014-08-07 08:10:39 -040082 }
83
Seigo Nonakacfc607c2015-12-02 10:53:18 +090084 uint32_t getMinikinLangListId() const {
85 return mMinikinLangListId;
Derek Sollenberger6f030232014-08-07 08:10:39 -040086 }
87
Seigo Nonakaae1aa852016-06-09 19:42:51 +090088 void setFontVariant(minikin::FontVariant variant) {
Derek Sollenberger6f030232014-08-07 08:10:39 -040089 mFontVariant = variant;
90 }
91
Seigo Nonakaae1aa852016-06-09 19:42:51 +090092 minikin::FontVariant getFontVariant() const {
Derek Sollenberger6f030232014-08-07 08:10:39 -040093 return mFontVariant;
94 }
95
Raph Levien210a1892015-03-09 14:42:14 -070096 void setHyphenEdit(uint32_t hyphen) {
97 mHyphenEdit = hyphen;
98 }
99
100 uint32_t getHyphenEdit() const {
101 return mHyphenEdit;
102 }
103
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400104private:
Raph Levien210a1892015-03-09 14:42:14 -0700105 float mLetterSpacing = 0;
Seigo Nonaka219e2c792016-11-15 19:01:45 +0900106 float mWordSpacing = 0;
Behdad Esfahbod805f6eb2014-07-29 18:43:03 -0400107 std::string mFontFeatureSettings;
Seigo Nonakacfc607c2015-12-02 10:53:18 +0900108 uint32_t mMinikinLangListId;
Seigo Nonakaae1aa852016-06-09 19:42:51 +0900109 minikin::FontVariant mFontVariant;
Raph Levien210a1892015-03-09 14:42:14 -0700110 uint32_t mHyphenEdit = 0;
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400111};
112
113} // namespace android
114
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800115#endif // ANDROID_GRAPHICS_PAINT_H_