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 #include "paragraph_line_fetcher_impl.h"
17 #include "paragraph_impl.h"
18 namespace OHOS {
19 namespace Rosen {
20 namespace SPText {
ParagraphLineFetcherImpl(std::unique_ptr<skia::textlayout::ParagraphLineFetcher> lineFetcher,std::vector<PaintRecord> && paints)21 ParagraphLineFetcherImpl::ParagraphLineFetcherImpl(
22 std::unique_ptr<skia::textlayout::ParagraphLineFetcher> lineFetcher, std::vector<PaintRecord>&& paints)
23 : lineFetcher_(std::move(lineFetcher)), paints_(std::move(paints))
24 {}
GetLineBreak(size_t startIndex,SkScalar width) const25 size_t ParagraphLineFetcherImpl::GetLineBreak(size_t startIndex, SkScalar width) const
26 {
27 if (lineFetcher_ == nullptr) {
28 return 0;
29 }
30 return lineFetcher_->getLineBreak(startIndex, width);
31 }
CreateLine(size_t startIndex,size_t count)32 std::unique_ptr<TextLineBase> ParagraphLineFetcherImpl::CreateLine(size_t startIndex, size_t count)
33 {
34 if (lineFetcher_ == nullptr) {
35 return nullptr;
36 }
37 return std::make_unique<TextLineImpl>(lineFetcher_->createLine(startIndex, count), paints_);
38 }
GetTempParagraph()39 std::unique_ptr<Paragraph> ParagraphLineFetcherImpl::GetTempParagraph()
40 {
41 if (lineFetcher_ == nullptr) {
42 return nullptr;
43 }
44 std::vector<PaintRecord> paints = paints_;
45 return std::make_unique<ParagraphImpl>(lineFetcher_->getTempParagraph(), std::move(paints));
46 }
47 } // namespace SPText
48 } // namespace Rosen
49 } // namespace OHOS
50