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