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