1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.. All rights reserved.
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_SPTEXT_PAINT_RECORD_H
17 #define ROSEN_MODULES_SPTEXT_PAINT_RECORD_H
18 
19 #include <optional>
20 
21 #include "include/core/SkColor.h"
22 
23 #include "draw/brush.h"
24 #include "draw/pen.h"
25 #include "symbol_engine/hm_symbol_txt.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace SPText {
30 struct PaintRecord {
31     using RSBrush = OHOS::Rosen::Drawing::Brush;
32     using RSPen = OHOS::Rosen::Drawing::Pen;
33     using RSColor = OHOS::Rosen::Drawing::Color;
34 
35     RSColor color;
36     std::optional<RSBrush> brush;
37     std::optional<RSPen> pen;
38     // hm symbol feature
39     bool isSymbolGlyph = false;
40     HMSymbolTxt symbol;
41 
PaintRecordPaintRecord42     PaintRecord() {}
PaintRecordPaintRecord43     PaintRecord(RSBrush brush, RSPen pen) : brush(brush), pen(pen) {}
PaintRecordPaintRecord44     PaintRecord(std::optional<RSBrush> brush, std::optional<RSPen> pen) : brush(brush), pen(pen) {}
45 
SetColorPaintRecord46     void SetColor(const RSColor& c)
47     {
48         color = c;
49     }
50 
SetColorPaintRecord51     void SetColor(SkColor c)
52     {
53         SetColor(ToRSColor(c));
54     }
55 
56     bool operator==(const PaintRecord& rhs) const
57     {
58         return brush == rhs.brush && pen == rhs.pen;
59     }
60 
61     bool operator!=(const PaintRecord& rhs) const
62     {
63         return !(*this == rhs);
64     }
65 
ToRSColorPaintRecord66     static RSColor ToRSColor(SkColor c)
67     {
68         return RSColor(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), SkColorGetA(c));
69     }
70 };
71 } // namespace SPText
72 } // namespace Rosen
73 } // namespace OHOS
74 
75 #endif // ROSEN_MODULES_SPTEXT_PAINT_RECORD_H
76