1 /*
2  * Copyright (c) 2023-2024 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 SKIA_TEXT_BLOB_H
17 #define SKIA_TEXT_BLOB_H
18 
19 #include <cstdint>
20 #include <memory>
21 
22 #include "include/core/SkTextBlob.h"
23 
24 #include "impl_interface/text_blob_impl.h"
25 #include "text/text_blob.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class DRAWING_API SkiaTextBlob : public TextBlobImpl {
31 public:
32     static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
33 
34     explicit SkiaTextBlob(sk_sp<SkTextBlob> skTextBlob);
35     ~SkiaTextBlob() override = default;
36 
GetType()37     AdapterType GetType() const override
38     {
39         return AdapterType::SKIA_ADAPTER;
40     }
41 
42     static std::shared_ptr<TextBlob> MakeFromText(const void* text, size_t byteLength,
43         const Font& font, TextEncoding encoding);
44     static std::shared_ptr<TextBlob> MakeFromPosText(const void* text, size_t byteLength,
45         const Point pos[], const Font& font, TextEncoding encoding);
46     static std::shared_ptr<TextBlob> MakeFromRSXform(const void* text, size_t byteLength,
47         const RSXform xform[], const Font& font, TextEncoding encoding);
48 
49     sk_sp<SkTextBlob> GetTextBlob() const;
50 
51     std::shared_ptr<Data> Serialize(void* ctx) const override;
52 
53     static std::shared_ptr<TextBlob> Deserialize(const void* data, size_t size, void* ctx);
54     static void GetDrawingGlyphIDforTextBlob(const TextBlob* blob, std::vector<uint16_t>& glyphIds);
55     static Path GetDrawingPathforTextBlob(uint16_t glyphId, const TextBlob* blob);
56     static void GetDrawingPointsForTextBlob(const TextBlob* blob, std::vector<Point>& points);
57     int GetIntercepts(const float bounds[], float intervals[], const Paint* paint) const override;
58 
59     std::shared_ptr<Rect> Bounds() const override;
60 
61     uint32_t UniqueID() const override;
62 
63 private:
64     sk_sp<SkTextBlob> skTextBlob_;
65 };
66 } // namespace Drawing
67 } // namespace Rosen
68 } // namespace OHOS
69 #endif