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 #include "drawing.h" 22 23 #include "texgine_mask_filter.h" 24 #include "texgine_path_effect.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace TextEngine { 29 class TexginePaint { 30 public: 31 enum Style : uint8_t { 32 FILL, 33 STROKE, 34 STROKEANDFILL, 35 }; 36 37 enum TexgineBlendMode : uint8_t { 38 CLEAR, 39 SRC, 40 DST, 41 SRC_OVER, 42 DST_OVER, 43 SRC_IN, 44 DST_IN, 45 SRC_OUT, 46 DST_OUT, 47 SRC_ATOP, 48 DST_ATOP, 49 XOR, 50 PLUS, 51 MODULATE, 52 SCREEN, 53 OVERLAY, 54 DARKEN, 55 LIGHTEN, 56 COLOR_DODGE, 57 COLOR_BURN, 58 HARD_LIGHT, 59 SOFT_LIGHT, 60 DIFFERENCE, 61 EXCLUSION, 62 MULTIPLY, 63 HUE, 64 STATURATION, 65 COLOR, 66 LUMINOSITY, 67 }; 68 69 TexginePaint(); 70 71 /* 72 * @brief Gets Brush from TexginePaint 73 */ 74 RSBrush GetBrush() const; 75 76 /* 77 * @brief Gets Pen from TexginePaint 78 */ 79 RSPen GetPen() const; 80 81 /* 82 * @brief Gets Style from TexginePaint 83 */ 84 Style GetStyle() const; 85 86 /* 87 * @brief Sets Brush to TexginePaint 88 */ 89 void SetBrush(const RSBrush &brush); 90 91 /* 92 * @brief Sets Pen to TexginePaint 93 */ 94 void SetPen(const RSPen &pen); 95 96 /* 97 * @brief Sets alpha and RGB used when stroking and filling 98 */ 99 void SetColor(const uint32_t color); 100 101 /* 102 * @brief Replace alpha while keeping RGB unchanged. 103 */ 104 void SetAlphaf(const float alpha); 105 106 /* 107 * @brief Sets the thickness of the pen used by the paint to outline the shape 108 */ 109 void SetStrokeWidth(const double width); 110 111 /* 112 * @brief Sets edge pixels are drawn as opaque or partially transparent. 113 */ 114 void SetAntiAlias(const bool aa); 115 116 /* 117 * @brief Sets color used when drawing solid fills 118 * @param a The quantity, from completely transparent (0) to completely opaque (255) 119 * @param r Red, from no red (0) to full red (255) 120 * @param g Green, from no green (0) to full green (255) 121 * @param b blue, from no blue (0) to full blue (255) 122 */ 123 void SetARGB(const unsigned int a, const unsigned int r, 124 const unsigned int g, const unsigned int b); 125 126 /* 127 * @brief Sets whether the geometry is filled, stroked or filled and stroked 128 */ 129 void SetStyle(Style style); 130 131 /* 132 * @brief Sets TexginePathEffect to the paint 133 * @param pathEffect The path that replace SkPath when drawn 134 */ 135 void SetPathEffect(const std::shared_ptr<TexginePathEffect> pathEffect); 136 137 /* 138 * @brief Sets TexgineMaskFilter to the paint 139 * @param maskFilter Modifies clipping mask generated from drawn geometry 140 */ 141 void SetMaskFilter(const std::shared_ptr<TexgineMaskFilter> maskFilter); 142 143 /* 144 * @brief Replaces alpha, leaving RGB 145 * @param alpha Is from 0.0 to 1.0 146 * 0.0 makes color fully transparent 147 * 1.0 makes color fully opaque 148 */ 149 void SetAlpha(const unsigned int alpha); 150 151 /* 152 * @brief Sets blend mode to paint 153 */ 154 void SetBlendMode(TexgineBlendMode mode); 155 bool operator==(const TexginePaint &rhs) const; 156 157 private: 158 Style style_; 159 std::shared_ptr<RSBrush> brush_ = nullptr; 160 std::shared_ptr<RSPen> pen_ = nullptr; 161 }; 162 } // namespace TextEngine 163 } // namespace Rosen 164 } // namespace OHOS 165 166 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_PAINT_H 167