1 /*
2  * Copyright (c) 2024 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 #ifndef ROSEN_MODULES_SPTEXT_PARAGRAPH_BUILDER_H
17 #define ROSEN_MODULES_SPTEXT_PARAGRAPH_BUILDER_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "font_collection.h"
23 #include "paragraph.h"
24 #include "paragraph_style.h"
25 #include "placeholder_run.h"
26 #include "text_style.h"
27 #include "utils.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace SPText {
32 class ParagraphBuilder {
33 public:
34     static std::unique_ptr<ParagraphBuilder> Create(const ParagraphStyle& style,
35       std::shared_ptr<txt::FontCollection> fontCollection);
36 
37     virtual ~ParagraphBuilder() = default;
38 
39     virtual void PushStyle(const TextStyle& style) = 0;
40     virtual void Pop() = 0;
41     virtual void AddText(const std::u16string& text) = 0;
42     virtual void AddPlaceholder(PlaceholderRun& span) = 0;
43 
44     virtual std::unique_ptr<Paragraph> Build() = 0;
45 
46 protected:
47     ParagraphBuilder() = default;
48 
49 private:
50     DISALLOW_COPY_AND_ASSIGN(ParagraphBuilder);
51 };
52 } // namespace SPText
53 } // namespace Rosen
54 } // namespace OHOS
55 
56 #endif // ROSEN_MODULES_SPTEXT_PARAGRAPH_BUILDER_H
57