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 TEXT_BLOB_BUILDER_H
17 #define TEXT_BLOB_BUILDER_H
18 
19 #include <memory>
20 #include <cstdint>
21 
22 #include "text/font.h"
23 #include "text/text_blob.h"
24 #include "utils/point.h"
25 #include "utils/rect.h"
26 #include "utils/scalar.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 namespace Drawing {
31 class TextBlobBuilderImpl;
32 
33 class DRAWING_API TextBlobBuilder {
34 public:
35     TextBlobBuilder();
36     TextBlobBuilder(const TextBlobBuilder& other) = delete;
37     TextBlobBuilder& operator=(const TextBlobBuilder& other) = delete;
38     virtual ~TextBlobBuilder() = default;
39 
40     struct RunBuffer {
41         uint16_t*  glyphs;
42         scalar*    pos;
43         char*      utf8text;
44         uint32_t*  clusters;
45     };
46 
47     /**
48      * @brief   Make textBlob by textBlobBuilder.
49      * @return  A shared point to textBlob.
50      */
51     std::shared_ptr<TextBlob> Make();
52 
53     /**
54      * @brief         Alloc run with storage for glyphs and point positions.
55      * @param font    Font used for this run
56      * @param count   Number of glyphs
57      * @param bounds  Optional run bounding box
58      * @return        Run with storage for glyphs and point positions.
59      */
60     const RunBuffer& AllocRunPos(const Font& font, int count,
61                                  const Rect* bounds = nullptr);
62 
63     /**
64      * @brief         Alloc run with storage for glyphs and affine matrix.
65      * @param font    Font used for this run
66      * @param count   Number of glyphs
67      * @return        Run with storage for glyphs and affine matrix.
68      */
69     const RunBuffer& AllocRunRSXform(const Font& font, int count);
70 
71 private:
72     std::shared_ptr<TextBlobBuilderImpl> textBlobBuilderImpl_;
73 };
74 } // namespace Drawing
75 } // namespace Rosen
76 } // namespace OHOS
77 #endif