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_IMPL_H
17 #define ROSEN_MODULES_SPTEXT_PARAGRAPH_BUILDER_IMPL_H
18 
19 #include <pthread.h>
20 
21 #include "modules/skparagraph/include/ParagraphBuilder.h"
22 #include "paragraph_impl.h"
23 #include "txt/paragraph_builder.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace SPText {
28 class ParagraphBuilderImpl : public ParagraphBuilder {
29 public:
30     ParagraphBuilderImpl(const ParagraphStyle& style, std::shared_ptr<txt::FontCollection> fontCollection);
31 
32     virtual ~ParagraphBuilderImpl();
33 
34     void PushStyle(const TextStyle& style) override;
35     void Pop() override;
36     void AddText(const std::u16string& text) override;
37     void AddPlaceholder(PlaceholderRun& span) override;
38     std::unique_ptr<Paragraph> Build() override;
39 
40     static skia::textlayout::TextStyle ConvertTextStyleToSkStyle(const TextStyle& txt);
41 
42 private:
43     void RecordDifferentPthreadCall(const char* caller) const;
44     skia::textlayout::ParagraphPainter::PaintID AllocPaintID(const PaintRecord& paint);
45     skia::textlayout::ParagraphStyle TextStyleToSkStyle(const ParagraphStyle& txt);
46     skia::textlayout::TextStyle TextStyleToSkStyle(const TextStyle& txt);
47     void CopyTextStylePaint(const TextStyle& txt, skia::textlayout::TextStyle& skStyle);
48 
49     std::shared_ptr<skia::textlayout::ParagraphBuilder> builder_;
50     TextStyle baseStyle_;
51 
52     std::vector<PaintRecord> paints_;
53     mutable pthread_t threadId_;
54 };
55 } // namespace SPText
56 } // namespace Rosen
57 } // namespace OHOS
58 
59 #endif // ROSEN_MODULES_SPTEXT_PARAGRAPH_BUILDER_IMPL_H
60