• 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 #ifndef USE_SKIA_TXT
62     SkRect getImageBounds() const override;
63     std::vector<SkPoint> getPositions(int64_t start, int64_t length) const override;
64 #else
65     RSRect getImageBounds() const override;
66     std::vector<RSPoint> getPositions(int64_t start, int64_t length) const override;
67 #endif
68 #endif
69     void paint(ParagraphPainter* painter, SkScalar x, SkScalar y) override;
70 
71     size_t getVisitorPos() const;
72     size_t getVisitorSize() const;
73 
74 private:
75 
76 #ifdef OHOS_SUPPORT
77     float calculateTrailSpacesWidth() const;
78     uint64_t calculateActualLength(int64_t start, int64_t length) const;
79     SkRect getAllGlyphRectInfo(SkSpan<const SkGlyphID>& runGlyphIdSpan, size_t startNotWhiteSpaceIndex,
80         SkScalar startWhiteSpaceWidth, size_t endWhiteSpaceNum, SkScalar endAdvance) const;
81 #endif
82 #ifndef USE_SKIA_TXT
83     sk_sp<SkTextBlob> fBlob;
84     SkFont fFont;
85 #else
86     RSFont fFont;
87     std::shared_ptr<RSTextBlob> fBlob;
88 #endif
89     SkPoint fOffset = SkPoint::Make(0.0f, 0.0f);
90     ParagraphPainter::SkPaintOrID fPaint;
91     bool fClippingNeeded = false;
92     SkRect fClipRect = SkRect::MakeEmpty();
93 
94     const Run* fVisitorRun;
95     size_t     fVisitorPos;
96 #ifdef OHOS_SUPPORT
97     size_t     fVisitorGlobalPos = 0;
98     size_t     fTrailSpaces = 0;
99 #endif
100     size_t     fVisitorSize;
101 };
102 }  // namespace textlayout
103 }  // namespace skia
104 
105 #endif  // SKPARAGRAPH_SRC_RUN_BASE_IMPL_H