Flutter Engine
The Flutter Engine
paragraph_builder.cpp
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "../export.h"
6#include "../wrappers.h"
9
10using namespace skia::textlayout;
11using namespace Skwasm;
12
14 ParagraphStyle* style,
15 FlutterFontCollection* collection) {
16 return ParagraphBuilder::make(*style, collection->collection, nullptr)
17 .release();
18}
19
21 delete builder;
22}
23
28 PlaceholderAlignment alignment,
29 SkScalar baselineOffset,
30 TextBaseline baseline) {
31 builder->addPlaceholder(
32 PlaceholderStyle(width, height, alignment, baseline, baselineOffset));
33}
34
36 std::u16string* text) {
37 builder->addText(*text);
38}
39
41 uint32_t* outLength) {
42 auto span = builder->getText();
43 *outLength = span.size();
44 return span.data();
45}
46
48 TextStyle* style) {
49 builder->pushStyle(*style);
50}
51
53 builder->pop();
54}
55
57 auto [words, graphemeBreaks, lineBreaks] = builder->getClientICUData();
58 auto text = builder->getText();
59 sk_sp<SkUnicode> clientICU =
60 SkUnicodes::Client::Make(text, words, graphemeBreaks, lineBreaks);
61 builder->SetUnicode(clientICU);
62 return builder->Build().release();
63}
64
65SKWASM_EXPORT std::vector<SkUnicode::Position>* unicodePositionBuffer_create(
66 size_t length) {
67 return new std::vector<SkUnicode::Position>(length);
68}
69
71 std::vector<SkUnicode::Position>* buffer) {
72 return buffer->data();
73}
74
76 std::vector<SkUnicode::Position>* buffer) {
77 delete buffer;
78}
79
80SKWASM_EXPORT std::vector<SkUnicode::LineBreakBefore>* lineBreakBuffer_create(
81 size_t length) {
82 return new std::vector<SkUnicode::LineBreakBefore>(
84}
85
87 std::vector<SkUnicode::LineBreakBefore>* buffer) {
88 return buffer->data();
89}
90
92 std::vector<SkUnicode::LineBreakBefore>* buffer) {
93 delete buffer;
94}
95
98 std::vector<SkUnicode::Position>* breaks) {
99 builder->setGraphemeBreaksUtf16(std::move(*breaks));
100}
101
104 std::vector<SkUnicode::Position>* breaks) {
105 builder->setWordsUtf16(std::move(*breaks));
106}
107
110 std::vector<SkUnicode::LineBreakBefore>* breaks) {
111 builder->setLineBreaksUtf16(std::move(*breaks));
112}
size_t Position
Definition: SkUnicode.h:98
float SkScalar
Definition: extension.cpp:12
size_t length
std::u16string text
SKUNICODE_API sk_sp< SkUnicode > Make(SkSpan< char > text, std::vector< SkUnicode::Position > words, std::vector< SkUnicode::Position > graphemeBreaks, std::vector< SkUnicode::LineBreakBefore > lineBreaks)
Definition: helpers.h:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
PlaceholderAlignment
Where to vertically align the placeholder relative to the surrounding text.
Definition: TextStyle.h:87
static void make(SkBitmap *bitmap, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace)
Definition: encode_srgb.cpp:35
SKWASM_EXPORT SkUnicode::Position * unicodePositionBuffer_getDataPointer(std::vector< SkUnicode::Position > *buffer)
SKWASM_EXPORT std::vector< SkUnicode::Position > * unicodePositionBuffer_create(size_t length)
SKWASM_EXPORT SkUnicode::LineBreakBefore * lineBreakBuffer_getDataPointer(std::vector< SkUnicode::LineBreakBefore > *buffer)
SKWASM_EXPORT ParagraphBuilder * paragraphBuilder_create(ParagraphStyle *style, FlutterFontCollection *collection)
SKWASM_EXPORT void lineBreakBuffer_free(std::vector< SkUnicode::LineBreakBefore > *buffer)
SKWASM_EXPORT void paragraphBuilder_setGraphemeBreaksUtf16(ParagraphBuilder *builder, std::vector< SkUnicode::Position > *breaks)
SKWASM_EXPORT void paragraphBuilder_pop(ParagraphBuilder *builder)
SKWASM_EXPORT void paragraphBuilder_setWordBreaksUtf16(ParagraphBuilder *builder, std::vector< SkUnicode::Position > *breaks)
SKWASM_EXPORT void paragraphBuilder_pushStyle(ParagraphBuilder *builder, TextStyle *style)
SKWASM_EXPORT char * paragraphBuilder_getUtf8Text(ParagraphBuilder *builder, uint32_t *outLength)
SKWASM_EXPORT void paragraphBuilder_dispose(ParagraphBuilder *builder)
SKWASM_EXPORT void unicodePositionBuffer_free(std::vector< SkUnicode::Position > *buffer)
SKWASM_EXPORT Paragraph * paragraphBuilder_build(ParagraphBuilder *builder)
SKWASM_EXPORT std::vector< SkUnicode::LineBreakBefore > * lineBreakBuffer_create(size_t length)
SKWASM_EXPORT void paragraphBuilder_addText(ParagraphBuilder *builder, std::u16string *text)
SKWASM_EXPORT void paragraphBuilder_addPlaceholder(ParagraphBuilder *builder, SkScalar width, SkScalar height, PlaceholderAlignment alignment, SkScalar baselineOffset, TextBaseline baseline)
SKWASM_EXPORT void paragraphBuilder_setLineBreaksUtf16(ParagraphBuilder *builder, std::vector< SkUnicode::LineBreakBefore > *breaks)
int32_t height
int32_t width
sk_sp< skia::textlayout::FontCollection > collection
Definition: wrappers.h:33
#define SKWASM_EXPORT
Definition: export.h:10