• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_SVG_SVGTRANSFORM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_SVGTRANSFORM_H
18 
19 #include <map>
20 #include <vector>
21 
22 #include "base/geometry/matrix4.h"
23 
24 namespace OHOS::Ace {
25 
26 struct TransformInfo {
27     Matrix4 matrix4;
28     Offset rotateCenter;
29     bool hasRotateCenter = false;
30 };
31 
32 class SvgTransform final {
33 public:
34     SvgTransform() = default;
35     ~SvgTransform() = default;
36 
37     // input: "rotate(-10, 50, 100) translate(-36, 45.5) skewX(40) skewY(40) scale(1, 0.5) matrix(1, 2, 3, 4, 5, 6)"
38     static Matrix4 CreateMatrix4(const std::string& transform);
39     static TransformInfo CreateInfoFromString(const std::string& transform);
40 
41     // input: "rotate(-10, 50, 100) translate(-36, 45.5) skewX(40) skewY(40) scale(1, 0.5) matrix(1, 2, 3, 4, 5, 6)"
42     // output: "{ { "rotate" : {-10, 50, 100} }, { "translate" : {-36, 45.5} }, { "skew" : {40, 50} },
43     //            { "scale", {1, 0.5} }, { "matrix", {1, 2, 3, 4, 5, 6} } }"
44     static std::map<std::string, std::vector<float>> CreateMap(const std::string& transform);
45 
46     static TransformInfo CreateInfoFromMap(const std::map<std::string, std::vector<float>>& transform);
47 
48     static bool SetProperty(const std::string& type, const std::vector<float>& from, const std::vector<float>& to,
49         double value, std::map<std::string, std::vector<float>>& transformAttrs);
50 
51     static bool AlignmentValues(const std::string& type, std::vector<float>& from, std::vector<float>& to);
52 
53     static bool AlignmentFrame(const std::string& type, std::vector<float>& frame);
54 };
55 
56 } // namespace OHOS::Ace
57 
58 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_SVGTRANSFORM_H
59