1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_PAINT_H 17 #define ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_PAINT_H 18 19 #include <memory> 20 21 #ifndef USE_ROSEN_DRAWING 22 #include <include/core/SkPaint.h> 23 #else 24 #include "drawing.h" 25 #endif 26 27 #include "texgine_mask_filter.h" 28 #include "texgine_path_effect.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 namespace TextEngine { 33 class TexginePaint { 34 public: 35 enum Style : uint8_t { 36 FILL, 37 STROKE, 38 STROKEANDFILL, 39 }; 40 41 enum TexgineBlendMode : uint8_t { 42 CLEAR, 43 SRC, 44 DST, 45 SRC_OVER, 46 DST_OVER, 47 SRC_IN, 48 DST_IN, 49 SRC_OUT, 50 DST_OUT, 51 SRC_ATOP, 52 DST_ATOP, 53 XOR, 54 PLUS, 55 MODULATE, 56 SCREEN, 57 OVERLAY, 58 DARKEN, 59 LIGHTEN, 60 COLOR_DODGE, 61 COLOR_BURN, 62 HARD_LIGHT, 63 SOFT_LIGHT, 64 DIFFERENCE, 65 EXCLUSION, 66 MULTIPLY, 67 HUE, 68 STATURATION, 69 COLOR, 70 LUMINOSITY, 71 }; 72 73 TexginePaint(); 74 75 #ifndef USE_ROSEN_DRAWING 76 /* 77 * @brief Gets SkPaint from TexginePaint 78 */ 79 SkPaint GetPaint() const; 80 #else 81 /* 82 * @brief Gets Brush from TexginePaint 83 */ 84 RSBrush GetBrush() const; 85 86 /* 87 * @brief Gets Pen from TexginePaint 88 */ 89 RSPen GetPen() const; 90 91 /* 92 * @brief Gets Style from TexginePaint 93 */ 94 Style GetStyle() const; 95 #endif 96 97 #ifndef USE_ROSEN_DRAWING 98 /* 99 * @brief Sets SkPaint to TexginePaint 100 */ 101 void SetPaint(const SkPaint &paint); 102 #else 103 /* 104 * @brief Sets Brush to TexginePaint 105 */ 106 void SetBrush(const RSBrush &brush); 107 108 /* 109 * @brief Sets Pen to TexginePaint 110 */ 111 void SetPen(const RSPen &pen); 112 #endif 113 114 /* 115 * @brief Sets alpha and RGB used when stroking and filling 116 */ 117 void SetColor(const uint32_t color); 118 119 /* 120 * @brief Replace alpha while keeping RGB unchanged. 121 */ 122 void SetAlphaf(const float alpha); 123 124 /* 125 * @brief Sets the thickness of the pen used by the paint to outline the shape 126 */ 127 void SetStrokeWidth(const double width); 128 129 /* 130 * @brief Sets edge pixels are drawn as opaque or partially transparent. 131 */ 132 void SetAntiAlias(const bool aa); 133 134 /* 135 * @brief Sets color used when drawing solid fills 136 * @param a The quantity, from completely transparent (0) to completely opaque (255) 137 * @param r Red, from no red (0) to full red (255) 138 * @param g Green, from no green (0) to full green (255) 139 * @param b blue, from no blue (0) to full blue (255) 140 */ 141 void SetARGB(const unsigned int a, const unsigned int r, 142 const unsigned int g, const unsigned int b); 143 144 /* 145 * @brief Sets whether the geometry is filled, stroked or filled and stroked 146 */ 147 void SetStyle(Style style); 148 149 /* 150 * @brief Sets TexginePathEffect to the paint 151 * @param pathEffect The path that replace SkPath when drawn 152 */ 153 void SetPathEffect(const std::shared_ptr<TexginePathEffect> pathEffect); 154 155 /* 156 * @brief Sets TexgineMaskFilter to the paint 157 * @param maskFilter Modifies clipping mask generated from drawn geometry 158 */ 159 void SetMaskFilter(const std::shared_ptr<TexgineMaskFilter> maskFilter); 160 161 /* 162 * @brief Replaces alpha, leaving RGB 163 * @param alpha Is from 0.0 to 1.0 164 * 0.0 makes color fully transparent 165 * 1.0 makes color fully opaque 166 */ 167 void SetAlpha(const unsigned int alpha); 168 169 /* 170 * @brief Sets blend mode to paint 171 */ 172 void SetBlendMode(TexgineBlendMode mode); 173 bool operator==(const TexginePaint &rhs) const; 174 175 private: 176 #ifndef USE_ROSEN_DRAWING 177 std::shared_ptr<SkPaint> paint_ = nullptr; 178 #else 179 Style style_; 180 std::shared_ptr<RSBrush> brush_ = nullptr; 181 std::shared_ptr<RSPen> pen_ = nullptr; 182 #endif 183 }; 184 } // namespace TextEngine 185 } // namespace Rosen 186 } // namespace OHOS 187 188 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_PAINT_H 189