Home | History | Annotate | Download | only in hwui
      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 "Typeface.h"
     21 
     22 #include <cutils/compiler.h>
     23 
     24 #include <SkPaint.h>
     25 #include <string>
     26 
     27 #include <minikin/FontFamily.h>
     28 
     29 namespace android {
     30 
     31 class ANDROID_API Paint : public SkPaint {
     32 public:
     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 
     42     constexpr static float kStdStrikeThru_Thickness = kStdUnderline_Thickness;
     43     constexpr static float kStdStrikeThru_Top =
     44             kStdStrikeThru_Offset - 0.5f * kStdStrikeThru_Thickness;
     45 
     46     Paint();
     47     Paint(const Paint& paint);
     48     Paint(const SkPaint& paint);  // NOLINT(implicit)
     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) { return !(a == b); }
     55 
     56     void setLetterSpacing(float letterSpacing) { mLetterSpacing = letterSpacing; }
     57 
     58     float getLetterSpacing() const { return mLetterSpacing; }
     59 
     60     void setWordSpacing(float wordSpacing) { mWordSpacing = wordSpacing; }
     61 
     62     float getWordSpacing() const { return mWordSpacing; }
     63 
     64     void setFontFeatureSettings(const std::string& fontFeatureSettings) {
     65         mFontFeatureSettings = fontFeatureSettings;
     66     }
     67 
     68     std::string getFontFeatureSettings() const { return mFontFeatureSettings; }
     69 
     70     void setMinikinLocaleListId(uint32_t minikinLocaleListId) {
     71         mMinikinLocaleListId = minikinLocaleListId;
     72     }
     73 
     74     uint32_t getMinikinLocaleListId() const { return mMinikinLocaleListId; }
     75 
     76     void setFamilyVariant(minikin::FontFamily::Variant variant) { mFamilyVariant = variant; }
     77 
     78     minikin::FontFamily::Variant getFamilyVariant() const { return mFamilyVariant; }
     79 
     80     void setHyphenEdit(uint32_t hyphen) { mHyphenEdit = hyphen; }
     81 
     82     uint32_t getHyphenEdit() const { return mHyphenEdit; }
     83 
     84     void setAndroidTypeface(Typeface* typeface) { mTypeface = typeface; }
     85 
     86     const Typeface* getAndroidTypeface() const { return mTypeface; }
     87 
     88 private:
     89     float mLetterSpacing = 0;
     90     float mWordSpacing = 0;
     91     std::string mFontFeatureSettings;
     92     uint32_t mMinikinLocaleListId;
     93     minikin::FontFamily::Variant mFamilyVariant;
     94     uint32_t mHyphenEdit = 0;
     95     // The native Typeface object has the same lifetime of the Java Typeface
     96     // object. The Java Paint object holds a strong reference to the Java Typeface
     97     // object. Thus, following pointer can never be a dangling pointer. Note that
     98     // nullptr is valid: it means the default typeface.
     99     const Typeface* mTypeface = nullptr;
    100 };
    101 
    102 }  // namespace android
    103 
    104 #endif  // ANDROID_GRAPHICS_PAINT_H_
    105