Flutter Engine
paragraph_builder_txt.h
Go to the documentation of this file.
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_TXT_H_
18 #define LIB_TXT_SRC_PARAGRAPH_BUILDER_TXT_H_
19 
20 #include "paragraph_builder.h"
21 
22 #include "styled_runs.h"
23 
24 namespace txt {
25 
26 // Implementation of ParagraphBuilder that produces paragraphs backed by the
27 // Minikin text layout library.
29  public:
31  std::shared_ptr<FontCollection> font_collection);
32 
33  virtual ~ParagraphBuilderTxt();
34 
35  virtual void PushStyle(const TextStyle& style) override;
36  virtual void Pop() override;
37  virtual const TextStyle& PeekStyle() override;
38  virtual void AddText(const std::u16string& text) override;
39  virtual void AddPlaceholder(PlaceholderRun& span) override;
40  virtual std::unique_ptr<Paragraph> Build() override;
41 
42  private:
43  std::vector<uint16_t> text_;
44  // A vector of PlaceholderRuns, which detail the sizes, positioning and break
45  // behavior of the empty spaces to leave. Each placeholder span corresponds to
46  // a 0xFFFC (object replacement character) in text_, which indicates the
47  // position in the text where the placeholder will occur. There should be an
48  // equal number of 0xFFFC characters and elements in this vector.
49  std::vector<PlaceholderRun> inline_placeholders_;
50  // The indexes of the obj replacement characters added through
51  // ParagraphBuilder::addPlaceholder().
52  std::unordered_set<size_t> obj_replacement_char_indexes_;
53  std::vector<size_t> style_stack_;
54  std::shared_ptr<FontCollection> font_collection_;
55  StyledRuns runs_;
56  ParagraphStyle paragraph_style_;
57  size_t paragraph_style_index_;
58 
59  void SetParagraphStyle(const ParagraphStyle& style);
60 
61  size_t PeekStyleIndex() const;
62 };
63 
64 } // namespace txt
65 
66 #endif // LIB_TXT_SRC_PARAGRAPH_BUILDER_TXT_H_
ParagraphBuilderTxt(const ParagraphStyle &style, std::shared_ptr< FontCollection > font_collection)
virtual void Pop() override
virtual void AddPlaceholder(PlaceholderRun &span) override
virtual const TextStyle & PeekStyle() override
virtual void AddText(const std::u16string &text) override
virtual void PushStyle(const TextStyle &style) override
virtual std::unique_ptr< Paragraph > Build() override