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_TEXT_LINE_BASE_H 17 #define ROSEN_TEXT_ADAPTER_TXT_TEXT_LINE_BASE_H 18 19 #include <memory> 20 #include <utility> 21 22 #include "draw/canvas.h" // Drawing 23 #include "rosen_text/text_line_base.h" 24 #include "rosen_text/typography.h" 25 #include "txt/text_line_base.h" 26 27 namespace OHOS { 28 namespace Rosen { 29 namespace AdapterTxt { 30 class TextLineBaseImpl : public ::OHOS::Rosen::TextLineBase { 31 public: 32 explicit TextLineBaseImpl(std::unique_ptr<SPText::TextLineBase> textlinebase); 33 size_t GetGlyphCount() const override; 34 std::vector<std::unique_ptr<Run>> GetGlyphRuns() const override; 35 Boundary GetTextRange() const override; 36 void Paint(Drawing::Canvas *canvas, double x, double y) override; 37 38 std::unique_ptr<TextLineBase> CreateTruncatedLine(double width, EllipsisModal ellipsisMode, 39 const std::string& ellipsisStr) const override; 40 double GetTypographicBounds(double* ascent, double* descent, double* leading) const override; 41 Drawing::Rect GetImageBounds() const override; 42 double GetTrailingSpaceWidth() const override; 43 int32_t GetStringIndexForPosition(SkPoint point) const override; 44 double GetOffsetForStringIndex(int32_t index) const override; 45 std::map<int32_t, double> GetIndexAndOffsets(bool& isHardBreak) const override; 46 double GetAlignmentOffset(double alignmentFactor, double alignmentWidth) const override; GetSpTextLineBase()47 void* GetSpTextLineBase() { return reinterpret_cast<void*>(textlinebase_.get()); } 48 49 private: 50 std::unique_ptr<SPText::TextLineBase> textlinebase_ = nullptr; 51 }; 52 } // namespace AdapterTxt 53 } // namespace Rosen 54 } // namespace OHOS 55 56 #endif // ROSEN_TEXT_ADAPTER_TXT_TEXT_LINE_BASE_H