paragraph_builder.h 2.1 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_H_
#define FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_H_
7

8
#include "flutter/lib/ui/text/paragraph.h"
9 10 11
#include "flutter/sky/engine/core/rendering/RenderObject.h"
#include "flutter/sky/engine/wtf/OwnPtr.h"
#include "flutter/third_party/txt/src/txt/paragraph_builder.h"
12
#include "lib/tonic/dart_wrappable.h"
13
#include "lib/tonic/typed_data/int32_list.h"
14

15
namespace tonic {
A
Adam Barth 已提交
16
class DartLibraryNatives;
17 18 19
}  // namespace tonic

namespace blink {
20

21 22
class Paragraph;

23 24
class ParagraphBuilder : public ftl::RefCountedThreadSafe<ParagraphBuilder>,
                         public tonic::DartWrappable {
25
  DEFINE_WRAPPERTYPEINFO();
26
  FRIEND_MAKE_REF_COUNTED(ParagraphBuilder);
27

28
 public:
29 30 31 32 33
  static ftl::RefPtr<ParagraphBuilder> create(tonic::Int32List& encoded,
                                              const std::string& fontFamily,
                                              double fontSize,
                                              double lineHeight,
                                              const std::string& ellipsis);
34

35
  ~ParagraphBuilder() override;
36

37 38 39 40 41 42
  void pushStyle(tonic::Int32List& encoded,
                 const std::string& fontFamily,
                 double fontSize,
                 double letterSpacing,
                 double wordSpacing,
                 double height);
43

44
  void pop();
45

46
  void addText(const std::string& text);
47

48
  ftl::RefPtr<Paragraph> build();
A
Adam Barth 已提交
49

50
  static void RegisterNatives(tonic::DartLibraryNatives* natives);
51

52
 private:
53 54 55 56 57
  explicit ParagraphBuilder(tonic::Int32List& encoded,
                            const std::string& fontFamily,
                            double fontSize,
                            double lineHeight,
                            const std::string& ellipsis);
58

59 60 61 62 63
  void createRenderView();

  OwnPtr<RenderView> m_renderView;
  RenderObject* m_renderParagraph;
  RenderObject* m_currentRenderObject;
64
  txt::ParagraphBuilder m_paragraphBuilder;
65 66
};

67
}  // namespace blink
68

69
#endif  // FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_H_