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_MODULES_TEXGINE_SRC_TYPOGRAPHY_BUILDER_IMPL_H 17 #define ROSEN_MODULES_TEXGINE_SRC_TYPOGRAPHY_BUILDER_IMPL_H 18 19 #include <stack> 20 21 #include "texgine/typography_builder.h" 22 #include "variant_span.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 namespace TextEngine { 27 class TypographyBuilderImpl : public TypographyBuilder { 28 public: 29 TypographyBuilderImpl(const TypographyStyle& ys, std::shared_ptr<FontProviders> fontProviders); 30 void PushStyle(const TextStyle &style) override; 31 void PopStyle() override; 32 void AppendSpan(const std::shared_ptr<AnySpan> &as) override; 33 void AppendSpan(const std::shared_ptr<TextSpan> &ts); 34 void AppendSpan(const std::string &text) override; 35 void AppendSpan(const std::u16string &text) override; 36 void AppendSpan(const std::u32string &text) override; 37 void AppendSpan(const std::vector<uint16_t> &text) override; 38 void AppendSpan(const std::vector<uint32_t> &text) override; 39 std::shared_ptr<Typography> Build() override; 40 41 private: 42 TypographyStyle ys_; 43 std::shared_ptr<FontProviders> fontProviders_ = nullptr; 44 std::stack<TextStyle> styleStack_; 45 std::vector<VariantSpan> spans_; 46 std::shared_ptr<TextSpan> lastTextSpan_ = nullptr; 47 }; 48 } // namespace OHOS 49 } // namespace Rosen 50 } // namespace TextEngine 51 52 #endif // ROSEN_MODULES_TEXGINE_SRC_TYPOGRAPHY_BUILDER_IMPL_H 53