1 /*
2 * Copyright (c) 2022 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 #include "rosen_text/properties/typography_create_txt.h"
17
18 #include "rosen_text/properties/font_collection_txt.h"
19 #include "rosen_text/properties/rosen_converter_txt.h"
20 #include "rosen_text/ui/typography.h"
21 #include "txt/placeholder_run.h"
22 #include "txt/text_style.h"
23
24 namespace rosen {
TypographyCreateTxt(const TypographyStyle & style,std::shared_ptr<FontCollection> font_collection)25 TypographyCreateTxt::TypographyCreateTxt(const TypographyStyle& style,
26 std::shared_ptr<FontCollection> font_collection)
27 {
28 txt::ParagraphStyle txtParagraphStyle;
29 RosenConvertTypographyStyle(style, txtParagraphStyle);
30 const FontCollectionTxt* fontCollectionTxt = static_cast<const FontCollectionTxt*>(
31 font_collection->GetFontCollection().get());
32 paragraphBuilderTxt_ = std::make_shared<txt::ParagraphBuilderTxt>(
33 txtParagraphStyle, fontCollectionTxt->GetFontCollection());
34 }
35
~TypographyCreateTxt()36 TypographyCreateTxt::~TypographyCreateTxt()
37 {
38 }
39
PushStyle(const TextStyle & style)40 void TypographyCreateTxt::PushStyle(const TextStyle& style)
41 {
42 txt::TextStyle textStyle;
43 RosenConvertTxtStyle(style, textStyle);
44 paragraphBuilderTxt_->PushStyle(textStyle);
45 }
46
Pop()47 void TypographyCreateTxt::Pop()
48 {
49 paragraphBuilderTxt_->Pop();
50 }
51
AddText(const std::u16string & text)52 void TypographyCreateTxt::AddText(const std::u16string& text)
53 {
54 paragraphBuilderTxt_->AddText(text);
55 }
56
AddPlaceholder(PlaceholderRun & span)57 void TypographyCreateTxt::AddPlaceholder(PlaceholderRun& span)
58 {
59 txt::PlaceholderRun txtPlaceholderRun = RosenConvertPlaceholderRun(span);
60 paragraphBuilderTxt_->AddPlaceholder(txtPlaceholderRun);
61 }
62
Build()63 std::unique_ptr<Typography> TypographyCreateTxt::Build()
64 {
65 return std::make_unique<Typography>();
66 }
67 } // namespace rosen
68