1 /* 2 * Copyright (c) 2024 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_ATTRIBUTES_PARSER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_ATTRIBUTES_PARSER_H 18 19 #include <string> 20 21 #include "base/memory/ace_type.h" 22 #include "base/utils/noncopyable.h" 23 #include "core/components/common/properties/color.h" 24 #include "core/components/common/properties/paint_state.h" 25 26 namespace OHOS::Ace::NG { 27 class SvgAttributesParser { 28 public: 29 static Color GetColor(const std::string& str); 30 static LineCapStyle GetLineCapStyle(const std::string& val); 31 static LineJoinStyle GetLineJoinStyle(const std::string& val); 32 static Dimension ParseDimension(const std::string& value, bool useVp = false); 33 static double ParseDouble(const std::string& value); 34 }; 35 36 enum class SvgFeColorMatrixType { 37 MATRIX, 38 SATURATE, 39 HUE_ROTATE, 40 LUMINACE_TO_ALPHA, 41 }; 42 43 enum class SvgColorInterpolationType { 44 LINEAR_RGB, 45 SRGB, 46 AUTO 47 }; 48 49 enum class SvgFeInType { 50 SOURCE_GRAPHIC, 51 SOURCE_ALPHA, 52 BACKGROUND_IMAGE, 53 BACKGROUND_ALPHA, 54 FILL_PAINT, 55 STROKE_PAINT, 56 PRIMITIVE 57 }; 58 59 enum class SvgFeEdgeMode { 60 EDGE_DUPLICATE, 61 EDGE_WRAP, 62 EDGE_NONE 63 }; 64 65 enum class SvgFeOperatorType { 66 FE_ARITHMETIC, 67 FE_ATOP, 68 FE_IN, 69 FE_LIGHTER, 70 FE_OUT, 71 FE_OVER, 72 FE_XOR 73 }; 74 75 enum class SvgFeBlendMode { 76 NORMAL, 77 MULTIPLY, 78 SCREEN, 79 DARKEN, 80 LIGHTEN 81 }; 82 83 struct SvgFeIn { 84 SvgFeInType in = SvgFeInType::PRIMITIVE; 85 std::string id; 86 }; 87 88 struct SvgAttributes { 89 Rect viewBox; 90 Dimension x; 91 Dimension y; 92 Dimension width = -1.0_px; 93 Dimension height = -1.0_px; 94 bool autoMirror = false; 95 }; 96 97 struct SvgAnimateAttribute { 98 std::string attributeName; 99 int32_t begin = 0; 100 int32_t dur = 0; 101 int32_t end = 0; 102 int32_t repeatCount = 1; 103 std::string fillMode; 104 std::string calcMode; 105 std::vector<std::string> values; 106 std::vector<double> keyTimes; 107 std::vector<std::string> keySplines; 108 std::string from; 109 std::string to; 110 std::vector<std::string> keyPoints; 111 std::string path; 112 std::string rotate; 113 std::string transformType; 114 }; 115 116 struct SvgStopAttribute { 117 GradientColor gradientColor; 118 }; 119 120 struct SvgRectAttribute { 121 Dimension x; 122 Dimension y; 123 Dimension rx = -1.0_px; 124 Dimension ry = -1.0_px; 125 Dimension width; 126 Dimension height; 127 }; 128 129 struct SvgMaskAttribute { 130 Dimension x = Dimension(-0.1, DimensionUnit::PERCENT); // x-axis default value 131 Dimension y = Dimension(-0.1, DimensionUnit::PERCENT); // y-axis default value 132 Dimension width = Dimension(1.2, DimensionUnit::PERCENT); // masking area width default value 133 Dimension height = Dimension(1.2, DimensionUnit::PERCENT); // masking area height default value 134 std::string maskContentUnits = "userSpaceOnUse"; 135 std::string maskUnits = "objectBoundingBox"; 136 }; 137 138 struct SvgCircleAttribute { 139 Dimension cx; 140 Dimension cy; 141 Dimension r; 142 }; 143 144 struct SvgPolygonAttribute { 145 std::string points; 146 }; 147 148 struct SvgEllipseAttribute { 149 Dimension cx; 150 Dimension cy; 151 Dimension rx = -1.0_px; 152 Dimension ry = -1.0_px; 153 }; 154 155 struct SvgLineAttribute { 156 Dimension x1; 157 Dimension y1; 158 Dimension x2; 159 Dimension y2; 160 }; 161 162 struct SvgPatternAttribute { 163 Dimension x; // x-axis default value 164 Dimension y; // y-axis default value 165 Dimension width; // pattern area width default value 166 Dimension height; // pattern area height default value 167 std::string patternUnits = "objectBoundingBox"; 168 std::string patternContentUnits = "userSpaceOnUse"; 169 std::string patternTransform; 170 Rect viewBox; 171 }; 172 173 struct SvgImageAttribute { 174 Dimension x = Dimension(0, DimensionUnit::PX); // x-axis default value 175 Dimension y = Dimension(0, DimensionUnit::PX); // y-axis default value 176 Dimension width = Dimension(0.0, DimensionUnit::PX); // image width default value 177 Dimension height = Dimension(0.0, DimensionUnit::PX); // image height default value 178 std::string href = ""; 179 }; 180 181 struct SvgFilterAttribute { 182 Dimension x = Dimension(-0.1, DimensionUnit::PERCENT); // x-axis default value 183 Dimension y = Dimension(-0.1, DimensionUnit::PERCENT); // y-axis default value 184 Dimension width = Dimension(1.2, DimensionUnit::PERCENT); // masking area width default value 185 Dimension height = Dimension(1.2, DimensionUnit::PERCENT); // masking area height default value 186 }; 187 188 struct SvgFeCommonAttribute { 189 Dimension x = Dimension(0.0, DimensionUnit::PERCENT); 190 Dimension y = Dimension(0.0, DimensionUnit::PERCENT); 191 Dimension height = Dimension(1.0, DimensionUnit::PERCENT); 192 Dimension width = Dimension(1.0, DimensionUnit::PERCENT); 193 std::string result; 194 SvgFeIn in; 195 SvgColorInterpolationType colorInterpolationType = SvgColorInterpolationType::SRGB; 196 }; 197 198 struct SvgFeFloodAttribute { 199 Color floodColor = Color::BLACK; 200 double floodOpacity = 1.0; 201 }; 202 203 struct SvgFeGaussianBlurAttribute { 204 float stdDeviationX = 0.0f; 205 float stdDeviationY = 0.0f; 206 SvgFeEdgeMode edgeMode = SvgFeEdgeMode::EDGE_DUPLICATE; 207 }; 208 209 struct SvgFeOffsetAttribute { 210 Dimension dx; 211 Dimension dy; 212 }; 213 214 struct SvgFeCompositeAttribute { 215 SvgFeIn in2; 216 SvgFeOperatorType operatorType = SvgFeOperatorType::FE_OVER; 217 float k1 = 0.0f; 218 float k2 = 0.0f; 219 float k3 = 0.0f; 220 float k4 = 0.0f; 221 }; 222 223 struct SvgFeBlendAttribute { 224 SvgFeIn in2; 225 SvgFeBlendMode blendMode = SvgFeBlendMode::NORMAL; 226 }; 227 228 struct SvgFeColorMatrixAttribute { 229 SvgFeColorMatrixType type = SvgFeColorMatrixType::MATRIX; 230 std::string values; 231 }; 232 233 struct SvgGradientAttribute { 234 Gradient gradient = Gradient(); 235 }; 236 237 } // namespace OHOS::Ace::NG 238 239 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_ATTRIBUTES_PARSER_H