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