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 ROSEN_TEXT_ADAPTER_TXT_TYPOGRAPHY_H 17 #define ROSEN_TEXT_ADAPTER_TXT_TYPOGRAPHY_H 18 19 #include <bitset> 20 #include <shared_mutex> 21 #include "rosen_text/typography.h" 22 #include "txt/paragraph.h" 23 #include "rosen_text/typography_style.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 namespace AdapterTxt { 28 class Typography : public ::OHOS::Rosen::Typography { 29 public: 30 explicit Typography(std::unique_ptr<SPText::Paragraph> paragraph); 31 32 double GetMaxWidth() const override; 33 double GetHeight() const override; 34 double GetActualWidth() const override; 35 double GetLongestLineWithIndent() const override; 36 double GetMinIntrinsicWidth() override; 37 double GetMaxIntrinsicWidth() override; 38 double GetAlphabeticBaseline() override; 39 double GetIdeographicBaseline() override; 40 double GetGlyphsBoundsTop() override; 41 double GetGlyphsBoundsBottom() override; 42 double GetGlyphsBoundsLeft() override; 43 double GetGlyphsBoundsRight() override; 44 bool DidExceedMaxLines() const override; 45 int GetLineCount() const override; 46 void MarkDirty() override; 47 int32_t GetUnresolvedGlyphsCount() override; 48 void UpdateFontSize(size_t from, size_t to, float fontSize) override; 49 50 void SetIndents(const std::vector<float>& indents) override; 51 float DetectIndents(size_t index) override; 52 void Layout(double width) override; 53 void Paint(SkCanvas* canvas, double x, double y) override; 54 void Paint(Drawing::Canvas* drawCanvas, double x, double y) override; 55 void Paint(Drawing::Canvas* drawCanvas, Drawing::Path* path, double hOffset, double vOffset) override; 56 57 std::vector<TextRect> GetTextRectsByBoundary(size_t left, size_t right, 58 TextRectHeightStyle heightStyle, TextRectWidthStyle widthStyle) override; 59 std::vector<TextRect> GetTextRectsOfPlaceholders() override; 60 IndexAndAffinity GetGlyphIndexByCoordinate(double x, double y) override; 61 Boundary GetWordBoundaryByIndex(size_t index) override; 62 Boundary GetActualTextRange(int lineNumber, bool includeSpaces) override; 63 Boundary GetEllipsisTextRange() override; 64 double GetLineHeight(int lineNumber) override; 65 double GetLineWidth(int lineNumber) override; 66 void SetAnimation( 67 std::function<bool(const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig>&)>& animationFunc 68 ) override; 69 std::function<bool(const std::shared_ptr<TextEngine::SymbolAnimationConfig>&)> GetAnimation() override; 70 void SetParagraghId(uint32_t id) override; 71 Drawing::FontMetrics MeasureText() override; 72 bool GetLineInfo(int lineNumber, bool oneLine, bool includeWhitespace, LineMetrics* lineMetrics) override; 73 std::vector<LineMetrics> GetLineMetrics() override; 74 bool GetLineMetricsAt(int lineNumber, LineMetrics* lineMetrics) override; 75 Drawing::FontMetrics GetFontMetrics(const OHOS::Rosen::TextStyle& textStyle) override; 76 bool GetLineFontMetrics(const size_t lineNumber, size_t& charNumber, 77 std::vector<Drawing::FontMetrics>& fontMetrics) override; 78 std::vector<std::unique_ptr<TextLineBase>> GetTextLines() const override; 79 std::unique_ptr<OHOS::Rosen::Typography> CloneSelf() override; 80 void UpdateColor(size_t from, size_t to, const Drawing::Color& color) override; GetParagraph()81 void* GetParagraph() override { return reinterpret_cast<void*>(paragraph_.get()); } 82 Drawing::RectI GeneratePaintRegion(double x, double y) const override; 83 void Relayout(double width, const TypographyStyle& typograhyStyle, 84 const std::vector<TextStyle>& textStyles) override; 85 void UpdateAllTextStyles(const TextStyle& textStyleTemplate) override; 86 void SetSkipTextBlobDrawing(bool state) override; 87 bool HasSkipTextBlobDrawing() const override; 88 std::vector<TextBlobRecordInfo> GetTextBlobRecordInfo() const override; SetTextEffectAssociation(bool association)89 void SetTextEffectAssociation(bool association) override { textEffectAssociation_ = association; } GetTextEffectAssociation()90 bool GetTextEffectAssociation() const override { return textEffectAssociation_; } 91 bool CanPaintAllText() const override; 92 std::string GetDumpInfo() const override; 93 private: 94 std::unique_ptr<SPText::Paragraph> paragraph_ = nullptr; 95 std::vector<TextStyle> lineMetricsStyles_; 96 std::optional<std::vector<LineMetrics>> lineMetrics_; 97 bool textEffectAssociation_{false}; 98 mutable std::shared_mutex mutex_; 99 }; 100 } // namespace AdapterTxt 101 } // namespace Rosen 102 } // namespace OHOS 103 104 #endif // ROSEN_TEXT_ADAPTER_TXT_TYPOGRAPHY_H 105