• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef ENABLE_TEXT_ENHANCE
17 
18 #include "modules/skparagraph/src/TextLineBaseImpl.h"
19 
20 namespace skia {
21 namespace textlayout {
TextLineBaseImpl(std::unique_ptr<TextLine> visitorTextLine)22 TextLineBaseImpl::TextLineBaseImpl(
23     std::unique_ptr<TextLine> visitorTextLine) : fVisitorTextLine(std::move(visitorTextLine))
24 {
25 }
26 
getGlyphCount() const27 size_t TextLineBaseImpl::getGlyphCount() const
28 {
29     if (!fVisitorTextLine) {
30         return 0;
31     }
32     fVisitorTextLine->ensureTextBlobCachePopulated();
33     return fVisitorTextLine->getGlyphCount();
34 }
35 
getGlyphRuns() const36 std::vector<std::unique_ptr<RunBase>> TextLineBaseImpl::getGlyphRuns() const
37 {
38     if (!fVisitorTextLine) {
39         return {};
40     }
41     fVisitorTextLine->ensureTextBlobCachePopulated();
42     return fVisitorTextLine->getGlyphRuns();
43 }
44 
getTextRange() const45 SkRange<size_t> TextLineBaseImpl::getTextRange() const
46 {
47     if (!fVisitorTextLine) {
48         return {};
49     }
50     return fVisitorTextLine->text();
51 }
52 
paint(ParagraphPainter * painter,SkScalar x,SkScalar y)53 void TextLineBaseImpl::paint(ParagraphPainter* painter, SkScalar x, SkScalar y)
54 {
55     if (!fVisitorTextLine || !painter) {
56         return;
57     }
58     return fVisitorTextLine->paint(painter, x, y);
59 }
60 
createTruncatedLine(double width,EllipsisModal ellipsisMode,const std::string & ellipsisStr)61 std::unique_ptr<TextLineBase> TextLineBaseImpl::createTruncatedLine(double width, EllipsisModal ellipsisMode,
62     const std::string& ellipsisStr)
63 {
64     if (!fVisitorTextLine) {
65         return nullptr;
66     }
67 
68     return fVisitorTextLine->createTruncatedLine(width, ellipsisMode, ellipsisStr);
69 }
70 
getTypographicBounds(double * ascent,double * descent,double * leading) const71 double TextLineBaseImpl::getTypographicBounds(double* ascent, double* descent, double* leading) const
72 {
73     if (!fVisitorTextLine) {
74         return 0.0;
75     }
76 
77     return fVisitorTextLine->getTypographicBounds(ascent, descent, leading);
78 }
79 
getImageBounds() const80 RSRect TextLineBaseImpl::getImageBounds() const
81 {
82     if (!fVisitorTextLine) {
83         return {};
84     }
85 
86     return fVisitorTextLine->getImageBounds();
87 }
88 
getTrailingSpaceWidth() const89 double TextLineBaseImpl::getTrailingSpaceWidth() const
90 {
91     if (!fVisitorTextLine) {
92         return 0.0;
93     }
94 
95     return fVisitorTextLine->getTrailingSpaceWidth();
96 }
97 
getStringIndexForPosition(SkPoint point) const98 int32_t TextLineBaseImpl::getStringIndexForPosition(SkPoint point) const
99 {
100     if (!fVisitorTextLine) {
101         return 0;
102     }
103 
104     return fVisitorTextLine->getStringIndexForPosition(point);
105 }
106 
getOffsetForStringIndex(int32_t index) const107 double TextLineBaseImpl::getOffsetForStringIndex(int32_t index) const
108 {
109     if (!fVisitorTextLine) {
110         return 0.0;
111     }
112 
113     return fVisitorTextLine->getOffsetForStringIndex(index);
114 }
115 
getIndexAndOffsets(bool & isHardBreak) const116 std::map<int32_t, double> TextLineBaseImpl::getIndexAndOffsets(bool& isHardBreak) const
117 {
118     if (!fVisitorTextLine) {
119         return {};
120     }
121 
122     return fVisitorTextLine->getIndexAndOffsets(isHardBreak);
123 }
124 
getAlignmentOffset(double alignmentFactor,double alignmentWidth) const125 double TextLineBaseImpl::getAlignmentOffset(double alignmentFactor, double alignmentWidth) const
126 {
127     if (!fVisitorTextLine) {
128         return 0.0;
129     }
130 
131     return fVisitorTextLine->getAlignmentOffset(alignmentFactor, alignmentWidth);
132 }
133 }  // namespace textlayout
134 }  // namespace skia
135 
136 #endif // ENABLE_TEXT_ENHANCE