• 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 #ifndef SKPARAGRAPH_SRC_RUN_BASE_IMPL_H
17 #define SKPARAGRAPH_SRC_RUN_BASE_IMPL_H
18 
19 #include "modules/skparagraph/include/RunBase.h"
20 #include "modules/skparagraph/src/Run.h"
21 
22 namespace skia {
23 namespace textlayout {
24 class RunBaseImpl : public RunBase {
25 public:
26     RunBaseImpl(
27 #ifndef USE_SKIA_TXT
28         sk_sp<SkTextBlob> blob,
29 #else
30         std::shared_ptr<RSTextBlob> blob,
31 #endif
32         SkPoint offset,
33         ParagraphPainter::SkPaintOrID paint,
34         bool clippingNeeded,
35         SkRect clipRect,
36         const Run* visitorRun,
37         size_t visitorPos,
38 #ifdef OHOS_SUPPORT
39         size_t visitorGlobalPos,
40         size_t trailSpaces,
41 #endif
42         size_t visitorSize
43     );
44 
45 #ifndef USE_SKIA_TXT
46     const SkFont& font() const override;
47 #else
48     const RSFont& font() const override;
49 #endif
50 
51     size_t size() const override;
52     std::vector<uint16_t> getGlyphs() const override;
53     std::vector<RSPoint> getPositions() const override;
54     std::vector<RSPoint> getOffsets() const override;
55 
56 #ifdef OHOS_SUPPORT
57     std::vector<uint16_t> getGlyphs(int64_t start, int64_t length) const override;
58     void getStringRange(uint64_t* location, uint64_t* length) const override;
59     std::vector<uint64_t> getStringIndices(int64_t start, int64_t length) const override;
60     float getTypographicBounds(float* ascent, float* descent, float* leading) const override;
61     std::vector<RSPoint> getAdvances(uint32_t start, uint32_t length) const override;
62     TextDirection getTextDirection() const override;
63 #ifndef USE_SKIA_TXT
64     SkRect getImageBounds() const override;
65     std::vector<SkPoint> getPositions(int64_t start, int64_t length) const override;
66 #else
67     RSRect getImageBounds() const override;
68     std::vector<RSPoint> getPositions(int64_t start, int64_t length) const override;
69 #endif
70 #endif
71     void paint(ParagraphPainter* painter, SkScalar x, SkScalar y) override;
72 
73     size_t getVisitorPos() const;
74     size_t getVisitorSize() const;
75 
76 private:
77 
78 #ifdef OHOS_SUPPORT
79     float calculateTrailSpacesWidth() const;
80     uint64_t calculateActualLength(int64_t start, int64_t length) const;
81     SkRect getAllGlyphRectInfo(SkSpan<const SkGlyphID>& runGlyphIdSpan, size_t startNotWhiteSpaceIndex,
82         SkScalar startWhiteSpaceWidth, size_t endWhiteSpaceNum, SkScalar endAdvance) const;
83 #endif
84 #ifndef USE_SKIA_TXT
85     sk_sp<SkTextBlob> fBlob;
86     SkFont fFont;
87 #else
88     RSFont fFont;
89     std::shared_ptr<RSTextBlob> fBlob;
90 #endif
91     SkPoint fOffset = SkPoint::Make(0.0f, 0.0f);
92     ParagraphPainter::SkPaintOrID fPaint;
93     bool fClippingNeeded = false;
94     SkRect fClipRect = SkRect::MakeEmpty();
95 
96     const Run* fVisitorRun;
97     size_t     fVisitorPos;
98 #ifdef OHOS_SUPPORT
99     size_t     fVisitorGlobalPos = 0;
100     size_t     fTrailSpaces = 0;
101 #endif
102     size_t     fVisitorSize;
103 };
104 }  // namespace textlayout
105 }  // namespace skia
106 
107 #endif  // SKPARAGRAPH_SRC_RUN_BASE_IMPL_H