blob: f3779fddb620425009a80ce09e614b79731da08e [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
Seigo Nonaka318ca042017-08-01 16:36:18 -070020#include "Typeface.h"
21
sergeyvdccca442016-03-21 15:38:21 -070022#include <cutils/compiler.h>
23
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040024#include <SkPaint.h>
Behdad Esfahbod805f6eb2014-07-29 18:43:03 -040025#include <string>
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040026
Derek Sollenberger6f030232014-08-07 08:10:39 -040027#include <minikin/FontFamily.h>
28
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040029namespace android {
30
sergeyvdccca442016-03-21 15:38:21 -070031class ANDROID_API Paint : public SkPaint {
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040032public:
Roozbeh Pournaderca8a04a2017-06-06 18:30:29 -070033 // 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 Pournader1378a9d2017-07-13 12:45:20 -070042 constexpr static float kStdStrikeThru_Thickness = kStdUnderline_Thickness;
43 constexpr static float kStdStrikeThru_Top =
44 kStdStrikeThru_Offset - 0.5f * kStdStrikeThru_Thickness;
45
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040046 Paint();
47 Paint(const Paint& paint);
Chih-Hung Hsieha619ec72016-08-29 14:52:43 -070048 Paint(const SkPaint& paint); // NOLINT(implicit)
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040049 ~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 Esfahbodfa80f742014-07-17 19:10:39 -040058 void setLetterSpacing(float letterSpacing) {
59 mLetterSpacing = letterSpacing;
60 }
61
62 float getLetterSpacing() const {
63 return mLetterSpacing;
64 }
65
Seigo Nonaka219e2c792016-11-15 19:01:45 +090066 void setWordSpacing(float wordSpacing) {
67 mWordSpacing = wordSpacing;
68 }
69
70 float getWordSpacing() const {
71 return mWordSpacing;
72 }
73
sergeyvdccca442016-03-21 15:38:21 -070074 void setFontFeatureSettings(const std::string& fontFeatureSettings) {
Behdad Esfahbod805f6eb2014-07-29 18:43:03 -040075 mFontFeatureSettings = fontFeatureSettings;
76 }
77
78 std::string getFontFeatureSettings() const {
79 return mFontFeatureSettings;
80 }
81
Seigo Nonakacfc607c2015-12-02 10:53:18 +090082 void setMinikinLangListId(uint32_t minikinLangListId) {
83 mMinikinLangListId = minikinLangListId;
Derek Sollenberger6f030232014-08-07 08:10:39 -040084 }
85
Seigo Nonakacfc607c2015-12-02 10:53:18 +090086 uint32_t getMinikinLangListId() const {
87 return mMinikinLangListId;
Derek Sollenberger6f030232014-08-07 08:10:39 -040088 }
89
Seigo Nonakaae1aa852016-06-09 19:42:51 +090090 void setFontVariant(minikin::FontVariant variant) {
Derek Sollenberger6f030232014-08-07 08:10:39 -040091 mFontVariant = variant;
92 }
93
Seigo Nonakaae1aa852016-06-09 19:42:51 +090094 minikin::FontVariant getFontVariant() const {
Derek Sollenberger6f030232014-08-07 08:10:39 -040095 return mFontVariant;
96 }
97
Raph Levien210a1892015-03-09 14:42:14 -070098 void setHyphenEdit(uint32_t hyphen) {
99 mHyphenEdit = hyphen;
100 }
101
102 uint32_t getHyphenEdit() const {
103 return mHyphenEdit;
104 }
105
Seigo Nonaka318ca042017-08-01 16:36:18 -0700106 void setAndroidTypeface(Typeface* typeface) {
107 mTypeface = typeface;
108 }
109
110 const Typeface* getAndroidTypeface() const {
111 return mTypeface;
112 }
113
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400114private:
Raph Levien210a1892015-03-09 14:42:14 -0700115 float mLetterSpacing = 0;
Seigo Nonaka219e2c792016-11-15 19:01:45 +0900116 float mWordSpacing = 0;
Behdad Esfahbod805f6eb2014-07-29 18:43:03 -0400117 std::string mFontFeatureSettings;
Seigo Nonakacfc607c2015-12-02 10:53:18 +0900118 uint32_t mMinikinLangListId;
Seigo Nonakaae1aa852016-06-09 19:42:51 +0900119 minikin::FontVariant mFontVariant;
Raph Levien210a1892015-03-09 14:42:14 -0700120 uint32_t mHyphenEdit = 0;
Seigo Nonaka318ca042017-08-01 16:36:18 -0700121 // 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 Esfahbod6ba30b82014-07-15 16:22:32 -0400125};
126
127} // namespace android
128
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800129#endif // ANDROID_GRAPHICS_PAINT_H_