• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "texgine/any_span.h"
17 
18 namespace OHOS {
19 namespace Rosen {
20 namespace TextEngine {
21 class MyAnySpan : public AnySpan {
22 public:
23     MyAnySpan(double width, double height,
24               AnySpanAlignment align = AnySpanAlignment::ABOVE_BASELINE,
25               TextBaseline baseline = TextBaseline::ALPHABETIC,
26               double offset = 0.0,
27               uint32_t color = SK_ColorGRAY)
28     {
29         width_ = width;
30         height_ = height;
31         align_ = align;
32         baseline_ = baseline;
33         offset_ = offset;
34         color_ = color;
35     }
36 
37     ~MyAnySpan() = default;
38 
GetWidth()39     double GetWidth() const override
40     {
41         return width_;
42     }
43 
GetHeight()44     double GetHeight() const override
45     {
46         return height_;
47     }
48 
GetAlignment()49     AnySpanAlignment GetAlignment() const override
50     {
51         return align_;
52     }
53 
GetBaseline()54     TextBaseline GetBaseline() const override
55     {
56         return baseline_;
57     }
58 
GetLineOffset()59     double GetLineOffset() const override
60     {
61         return offset_;
62     }
63 
Paint(TexgineCanvas & canvas,double offsetx,double offsety)64     void Paint(TexgineCanvas &canvas, double offsetx, double offsety) override
65     {
66         TexginePaint paint;
67         paint.SetColor(color_);
68         paint.SetStyle(TexginePaint::FILL);
69         auto rect = TexgineRect::MakeXYWH(offsetx, offsety, width_, height_);
70         canvas.DrawRect(rect, paint);
71     }
72 
73 private:
74     double width_ = 0.0;
75     double height_ = 0.0;
76     AnySpanAlignment align_ = AnySpanAlignment::ABOVE_BASELINE;
77     TextBaseline baseline_ = TextBaseline::ALPHABETIC;
78     double offset_ = 0.0;
79     uint32_t color_ = SK_ColorGRAY;
80 };
81 } // namespace TextEngine
82 } // namespace Rosen
83 } // namespace OHOS
84