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