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 textContrast_(ProcessTextConstrast::Instance().GetTextContrast()) {}
29
MakeFromText(const void * text,size_t byteLength,const Font & font,TextEncoding encoding)30 std::shared_ptr<TextBlob> TextBlob::MakeFromText(const void* text, size_t byteLength,
31 const Font& font, TextEncoding encoding)
32 {
33 return StaticFactory::MakeFromText(text, byteLength, font, encoding);
34 }
35
MakeFromPosText(const void * text,size_t byteLength,const Point pos[],const Font & font,TextEncoding encoding)36 std::shared_ptr<TextBlob> TextBlob::MakeFromPosText(const void* text, size_t byteLength,
37 const Point pos[], const Font& font, TextEncoding encoding)
38 {
39 return StaticFactory::MakeFromPosText(text, byteLength, pos, font, encoding);
40 }
41
MakeFromString(const char * str,const Font & font,TextEncoding encoding)42 std::shared_ptr<TextBlob> TextBlob::MakeFromString(const char* str, const Font& font, TextEncoding encoding)
43 {
44 if (!str) {
45 return nullptr;
46 }
47 return MakeFromText(str, strlen(str), font, encoding);
48 }
49
MakeFromRSXform(const void * text,size_t byteLength,const RSXform xform[],const Font & font,TextEncoding encoding)50 std::shared_ptr<TextBlob> TextBlob::MakeFromRSXform(const void* text, size_t byteLength,
51 const RSXform xform[], const Font& font, TextEncoding encoding)
52 {
53 return StaticFactory::MakeFromRSXform(text, byteLength, xform, font, encoding);
54 }
55
GetIntercepts(const SkScalar bounds[],SkScalar intervals[],const Paint * paint)56 int TextBlob::GetIntercepts(const SkScalar bounds[], SkScalar intervals[], const Paint *paint)
57 {
58 if (textBlobImpl_) {
59 return textBlobImpl_->GetIntercepts(bounds, intervals, paint);
60 }
61 return 0;
62 }
Serialize(void * ctx) const63 std::shared_ptr<Data> TextBlob::Serialize(void* ctx) const
64 {
65 if (!textBlobImpl_) {
66 return nullptr;
67 }
68 return textBlobImpl_->Serialize(ctx);
69 }
70
Deserialize(const void * data,size_t size,void * ctx)71 std::shared_ptr<TextBlob> TextBlob::Deserialize(const void* data, size_t size, void* ctx)
72 {
73 return StaticFactory::DeserializeTextBlob(data, size, ctx);
74 }
75
GetDrawingGlyphIDforTextBlob(const TextBlob * blob,std::vector<uint16_t> & glyphIds)76 void TextBlob::GetDrawingGlyphIDforTextBlob(const TextBlob* blob, std::vector<uint16_t>& glyphIds)
77 {
78 StaticFactory::GetDrawingGlyphIDforTextBlob(blob, glyphIds);
79 }
80
GetDrawingPathforTextBlob(uint16_t glyphId,const TextBlob * blob)81 Path TextBlob::GetDrawingPathforTextBlob(uint16_t glyphId, const TextBlob* blob)
82 {
83 return StaticFactory::GetDrawingPathforTextBlob(glyphId, blob);
84 }
85
GetDrawingPointsForTextBlob(const TextBlob * blob,std::vector<Point> & points)86 void TextBlob::GetDrawingPointsForTextBlob(const TextBlob* blob, std::vector<Point>& points)
87 {
88 return StaticFactory::GetDrawingPointsForTextBlob(blob, points);
89 }
90
Bounds() const91 std::shared_ptr<Rect> TextBlob::Bounds() const
92 {
93 if (textBlobImpl_) {
94 return textBlobImpl_->Bounds();
95 }
96 return nullptr;
97 }
98
UniqueID() const99 uint32_t TextBlob::UniqueID() const
100 {
101 if (textBlobImpl_) {
102 return textBlobImpl_->UniqueID();
103 }
104 return 0;
105 }
106 } // namespace Drawing
107 } // namespace Rosen
108 } // namespace OHOS
109