1 /* 2 * Copyright 2019 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef LIB_TXT_SRC_PARAGRAPH_BUILDER_SKIA_H_ 18 #define LIB_TXT_SRC_PARAGRAPH_BUILDER_SKIA_H_ 19 20 #include "txt/paragraph_builder.h" 21 22 #include "third_party/skia/modules/skparagraph/include/ParagraphBuilder.h" 23 24 namespace txt { 25 26 // Implementation of ParagraphBuilder based on Skia's text layout module. 27 class ParagraphBuilderSkia : public ParagraphBuilder { 28 public: 29 ParagraphBuilderSkia(const ParagraphStyle& style, 30 std::shared_ptr<FontCollection> font_collection); 31 32 virtual ~ParagraphBuilderSkia(); 33 34 virtual void PushStyle(const TextStyle& style) override; 35 virtual void Pop() override; 36 virtual const TextStyle& PeekStyle() override; 37 virtual void AddText(const std::u16string& text) override; 38 virtual void AddPlaceholder(PlaceholderRun& span) override; 39 virtual std::unique_ptr<Paragraph> Build() override; 40 41 private: 42 std::shared_ptr<skia::textlayout::ParagraphBuilder> builder_; 43 TextStyle base_style_; 44 std::stack<TextStyle> txt_style_stack_; 45 }; 46 47 } // namespace txt 48 49 #endif // LIB_TXT_SRC_PARAGRAPH_BUILDER_SKIA_H_ 50