1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 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_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_TEXT_BLOB_BUILDER_H 17 #define ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_TEXT_BLOB_BUILDER_H 18 19 #include <memory> 20 21 #include <include/core/SkTextBlob.h> 22 23 #include "texgine_font.h" 24 #include "texgine_text_blob.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace TextEngine { 29 class TexgineTextBlobBuilder { 30 public: 31 struct RunBuffer { 32 uint16_t* glyphs; 33 float* pos; 34 char* utf8Text; 35 uint32_t* clusters; 36 }; 37 38 /* 39 * @brief Get the SkTextBlobBuilder. 40 * SkTextBlobBuilder is helper class for constructing SkTextBlob 41 */ 42 std::shared_ptr<SkTextBlobBuilder> GetTextBlobBuilder() const; 43 44 /* 45 * @brief Returns run with storage for glyphs and SkPoint positions 46 * @param font SkFont used for this run 47 * @param The count The number of glyphs 48 * @return Writable glyph buffer and SkPoint buffer 49 */ 50 std::shared_ptr<RunBuffer> AllocRunPos(const TexgineFont &font, int count); 51 52 /* 53 * @brief Create TexgineTextBlob 54 */ 55 std::shared_ptr<TexgineTextBlob> Make(); 56 57 private: 58 std::shared_ptr<SkTextBlobBuilder> textBlobBuilder_ = std::make_shared<SkTextBlobBuilder>(); 59 std::shared_ptr<RunBuffer> buffer_ = std::make_shared<RunBuffer>(); 60 }; 61 } // namespace TextEngine 62 } // namespace Rosen 63 } // namespace OHOS 64 65 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_TEXT_BLOB_BUILDER_H 66