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 #include "text/text_blob.h"
17
18 #include <cstring>
19
20 #include "impl_interface/text_blob_impl.h"
21 #include "static_factory.h"
22 #include "utils/log.h"
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
TextBlob(std::shared_ptr<TextBlobImpl> textBlobImpl)27 TextBlob::TextBlob(std::shared_ptr<TextBlobImpl> textBlobImpl) noexcept : textBlobImpl_(textBlobImpl) {}
28
MakeFromText(const void * text,size_t byteLength,const Font & font,TextEncoding encoding)29 std::shared_ptr<TextBlob> TextBlob::MakeFromText(const void* text, size_t byteLength,
30 const Font& font, TextEncoding encoding)
31 {
32 return StaticFactory::MakeFromText(text, byteLength, font, encoding);
33 }
34
MakeFromPosText(const void * text,size_t byteLength,const Point pos[],const Font & font,TextEncoding encoding)35 std::shared_ptr<TextBlob> TextBlob::MakeFromPosText(const void* text, size_t byteLength,
36 const Point pos[], const Font& font, TextEncoding encoding)
37 {
38 return StaticFactory::MakeFromPosText(text, byteLength, pos, font, encoding);
39 }
40
MakeFromString(const char * str,const Font & font,TextEncoding encoding)41 std::shared_ptr<TextBlob> TextBlob::MakeFromString(const char* str, const Font& font, TextEncoding encoding)
42 {
43 if (!str) {
44 return nullptr;
45 }
46 return MakeFromText(str, strlen(str), font, encoding);
47 }
48
MakeFromRSXform(const void * text,size_t byteLength,const RSXform xform[],const Font & font,TextEncoding encoding)49 std::shared_ptr<TextBlob> TextBlob::MakeFromRSXform(const void* text, size_t byteLength,
50 const RSXform xform[], const Font& font, TextEncoding encoding)
51 {
52 return StaticFactory::MakeFromRSXform(text, byteLength, xform, font, encoding);
53 }
54
GetIntercepts(const SkScalar bounds[],SkScalar intervals[],const Paint * paint)55 int TextBlob::GetIntercepts(const SkScalar bounds[], SkScalar intervals[], const Paint *paint)
56 {
57 if (textBlobImpl_) {
58 return textBlobImpl_->GetIntercepts(bounds, intervals, paint);
59 }
60 return 0;
61 }
Serialize(void * ctx) const62 std::shared_ptr<Data> TextBlob::Serialize(void* ctx) const
63 {
64 if (!textBlobImpl_) {
65 return nullptr;
66 }
67 return textBlobImpl_->Serialize(ctx);
68 }
69
Deserialize(const void * data,size_t size,void * ctx)70 std::shared_ptr<TextBlob> TextBlob::Deserialize(const void* data, size_t size, void* ctx)
71 {
72 return StaticFactory::DeserializeTextBlob(data, size, ctx);
73 }
74
GetDrawingGlyphIDforTextBlob(const TextBlob * blob,std::vector<uint16_t> & glyphIds)75 void TextBlob::GetDrawingGlyphIDforTextBlob(const TextBlob* blob, std::vector<uint16_t>& glyphIds)
76 {
77 StaticFactory::GetDrawingGlyphIDforTextBlob(blob, glyphIds);
78 }
79
GetDrawingPathforTextBlob(uint16_t glyphId,const TextBlob * blob)80 Path TextBlob::GetDrawingPathforTextBlob(uint16_t glyphId, const TextBlob* blob)
81 {
82 return StaticFactory::GetDrawingPathforTextBlob(glyphId, blob);
83 }
84
GetDrawingPointsForTextBlob(const TextBlob * blob,std::vector<Point> & points)85 void TextBlob::GetDrawingPointsForTextBlob(const TextBlob* blob, std::vector<Point>& points)
86 {
87 return StaticFactory::GetDrawingPointsForTextBlob(blob, points);
88 }
89
Bounds() const90 std::shared_ptr<Rect> TextBlob::Bounds() const
91 {
92 if (textBlobImpl_) {
93 return textBlobImpl_->Bounds();
94 }
95 return nullptr;
96 }
97
UniqueID() const98 uint32_t TextBlob::UniqueID() const
99 {
100 if (textBlobImpl_) {
101 return textBlobImpl_->UniqueID();
102 }
103 return 0;
104 }
105 } // namespace Drawing
106 } // namespace Rosen
107 } // namespace OHOS
108