blob: c81c43ad472ec0fa2aacf15c5a1bfdebfc7be575 [file] [log] [blame]
Kevin Lubick369f6a52019-10-03 11:22:08 -04001/*
2 * Copyright 2019 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "include/core/SkColor.h"
Kevin Lubickd3b1fe62019-10-21 10:50:26 -04009#include "include/core/SkFontStyle.h"
Kevin Lubick369f6a52019-10-03 11:22:08 -040010#include "include/core/SkString.h"
11
12#include "modules/skparagraph/include/DartTypes.h"
13#include "modules/skparagraph/include/Paragraph.h"
14#include "modules/skparagraph/include/ParagraphBuilder.h"
15#include "modules/skparagraph/include/TextStyle.h"
Harry Terkelsen10f019c2020-08-04 13:21:09 -070016#include "modules/skparagraph/include/TypefaceFontProvider.h"
Kevin Lubick369f6a52019-10-03 11:22:08 -040017#include "modules/skparagraph/src/ParagraphBuilderImpl.h"
18#include "modules/skparagraph/src/ParagraphImpl.h"
19
20#include <string>
21#include <vector>
22
23#include <emscripten.h>
24#include <emscripten/bind.h>
Nathaniel Nifonge5d32542020-03-26 09:27:48 -040025#include "modules/canvaskit/WasmCommon.h"
Kevin Lubick369f6a52019-10-03 11:22:08 -040026
27using namespace emscripten;
28
29namespace para = skia::textlayout;
30
Nathaniel Nifong1bedbeb2020-05-04 16:46:17 -040031SkColor4f toSkColor4f(uintptr_t /* float* */ cPtr) {
32 float* fourFloats = reinterpret_cast<float*>(cPtr);
Harry Terkelsen223ffcd2020-10-02 15:24:13 -070033 SkColor4f color = {fourFloats[0], fourFloats[1], fourFloats[2], fourFloats[3]};
Nathaniel Nifong1bedbeb2020-05-04 16:46:17 -040034 return color;
35}
36
Kevin Lubickd3b1fe62019-10-21 10:50:26 -040037struct SimpleFontStyle {
Harry Terkelsen223ffcd2020-10-02 15:24:13 -070038 SkFontStyle::Slant slant;
Kevin Lubickd3b1fe62019-10-21 10:50:26 -040039 SkFontStyle::Weight weight;
Harry Terkelsen223ffcd2020-10-02 15:24:13 -070040 SkFontStyle::Width width;
Kevin Lubickd3b1fe62019-10-21 10:50:26 -040041};
42
Kevin Lubick369f6a52019-10-03 11:22:08 -040043struct SimpleTextStyle {
Nathaniel Nifong1bedbeb2020-05-04 16:46:17 -040044 uintptr_t /* float* */ colorPtr;
45 uintptr_t /* float* */ foregroundColorPtr;
46 uintptr_t /* float* */ backgroundColorPtr;
Kevin Lubick369f6a52019-10-03 11:22:08 -040047 uint8_t decoration;
Kevin Lubick369f6a52019-10-03 11:22:08 -040048 SkScalar decorationThickness;
Harry Terkelsen223ffcd2020-10-02 15:24:13 -070049 uintptr_t /* float* */ decorationColorPtr;
50 para::TextDecorationStyle decorationStyle;
51 para::TextBaseline textBaseline;
Kevin Lubickd3b1fe62019-10-21 10:50:26 -040052 SkScalar fontSize;
Harry Terkelsen223ffcd2020-10-02 15:24:13 -070053 SkScalar letterSpacing;
54 SkScalar wordSpacing;
55 SkScalar heightMultiplier;
56 uintptr_t /* const char* */ localePtr;
57 int localeLen;
Kevin Lubickd3b1fe62019-10-21 10:50:26 -040058 SimpleFontStyle fontStyle;
Kevin Lubickd3b1fe62019-10-21 10:50:26 -040059
Kevin Lubick0c8884b2020-05-14 08:27:53 -040060 uintptr_t /* const char** */ fontFamiliesPtr;
61 int fontFamiliesLen;
Harry Terkelsen223ffcd2020-10-02 15:24:13 -070062
63 int shadowLen;
64 uintptr_t /* SkColor4f* */ shadowColorsPtr;
65 uintptr_t /* SkPoint* */ shadowOffsetsPtr;
66 uintptr_t /* float* */ shadowBlurRadiiPtr;
67
68 int fontFeatureLen;
69 uintptr_t /* float* */ fontFeatureNamesPtr;
70 uintptr_t /* float* */ fontFeatureValuesPtr;
Kevin Lubick369f6a52019-10-03 11:22:08 -040071};
72
Harry Terkelsen223ffcd2020-10-02 15:24:13 -070073struct SimpleStrutStyle {
74 uintptr_t /* const char** */ fontFamiliesPtr;
75 int fontFamiliesLen;
76 SimpleFontStyle fontStyle;
77 SkScalar fontSize;
78 SkScalar heightMultiplier;
79 SkScalar leading;
80 bool strutEnabled;
81 bool forceStrutHeight;
82};
83
84para::StrutStyle toStrutStyle(const SimpleStrutStyle& s) {
85 para::StrutStyle ss;
86
87 const char** fontFamilies = reinterpret_cast<const char**>(s.fontFamiliesPtr);
88 if (fontFamilies != nullptr) {
89 std::vector<SkString> ff;
90 for (int i = 0; i < s.fontFamiliesLen; i++) {
91 ff.emplace_back(fontFamilies[i]);
92 }
93 ss.setFontFamilies(ff);
94 }
95
96 SkFontStyle fs(s.fontStyle.weight, s.fontStyle.width, s.fontStyle.slant);
97 ss.setFontStyle(fs);
98
99 if (s.fontSize != 0) {
100 ss.setFontSize(s.fontSize);
101 }
102 if (s.heightMultiplier != 0) {
103 ss.setHeight(s.heightMultiplier);
104 ss.setHeightOverride(true);
105 }
106 if (s.leading != 0) {
107 ss.setLeading(s.leading);
108 }
109
110 ss.setStrutEnabled(s.strutEnabled);
111 ss.setForceStrutHeight(s.forceStrutHeight);
112
113 return ss;
114}
115
Kevin Lubick369f6a52019-10-03 11:22:08 -0400116para::TextStyle toTextStyle(const SimpleTextStyle& s) {
117 para::TextStyle ts;
Nathaniel Nifonge5d32542020-03-26 09:27:48 -0400118
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700119 // textstyle.color doesn't support a 4f color, however the foreground and background fields
120 // below do.
Nathaniel Nifong1bedbeb2020-05-04 16:46:17 -0400121 ts.setColor(toSkColor4f(s.colorPtr).toSkColor());
Nathaniel Nifonge5d32542020-03-26 09:27:48 -0400122
Nathaniel Nifonge5d32542020-03-26 09:27:48 -0400123 // It is functionally important that these paints be unset when no value was provided.
Nathaniel Nifong1bedbeb2020-05-04 16:46:17 -0400124 if (s.foregroundColorPtr) {
Nathaniel Nifonge5d32542020-03-26 09:27:48 -0400125 SkPaint p1;
Nathaniel Nifong1bedbeb2020-05-04 16:46:17 -0400126 p1.setColor4f(toSkColor4f(s.foregroundColorPtr));
Nathaniel Nifonge5d32542020-03-26 09:27:48 -0400127 ts.setForegroundColor(p1);
Robert Phillipscb77eab2020-03-24 14:19:40 +0000128 }
Kevin Lubick369f6a52019-10-03 11:22:08 -0400129
Nathaniel Nifong1bedbeb2020-05-04 16:46:17 -0400130 if (s.backgroundColorPtr) {
Nathaniel Nifonge5d32542020-03-26 09:27:48 -0400131 SkPaint p2;
Nathaniel Nifong1bedbeb2020-05-04 16:46:17 -0400132 p2.setColor4f(toSkColor4f(s.backgroundColorPtr));
Nathaniel Nifonge5d32542020-03-26 09:27:48 -0400133 ts.setBackgroundColor(p2);
Robert Phillipscb77eab2020-03-24 14:19:40 +0000134 }
Kevin Lubick369f6a52019-10-03 11:22:08 -0400135
136 if (s.fontSize != 0) {
137 ts.setFontSize(s.fontSize);
138 }
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700139 if (s.letterSpacing != 0) {
140 ts.setLetterSpacing(s.letterSpacing);
141 }
142 if (s.wordSpacing != 0) {
143 ts.setWordSpacing(s.wordSpacing);
144 }
145
146 if (s.heightMultiplier != 0) {
147 ts.setHeight(s.heightMultiplier);
148 ts.setHeightOverride(true);
149 }
Kevin Lubick369f6a52019-10-03 11:22:08 -0400150
151 ts.setDecoration(para::TextDecoration(s.decoration));
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700152 ts.setDecorationStyle(s.decorationStyle);
Kevin Lubick369f6a52019-10-03 11:22:08 -0400153 if (s.decorationThickness != 0) {
154 ts.setDecorationThicknessMultiplier(s.decorationThickness);
155 }
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700156 if (s.decorationColorPtr) {
157 ts.setDecorationColor(toSkColor4f(s.decorationColorPtr).toSkColor());
158 }
159
160 if (s.localeLen > 0) {
161 const char* localePtr = reinterpret_cast<const char*>(s.localePtr);
162 SkString lStr(localePtr, s.localeLen);
163 ts.setLocale(lStr);
164 }
Kevin Lubick369f6a52019-10-03 11:22:08 -0400165
Kevin Lubick0c8884b2020-05-14 08:27:53 -0400166 const char** fontFamilies = reinterpret_cast<const char**>(s.fontFamiliesPtr);
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700167 if (fontFamilies != nullptr) {
Kevin Lubick369f6a52019-10-03 11:22:08 -0400168 std::vector<SkString> ff;
Kevin Lubick0c8884b2020-05-14 08:27:53 -0400169 for (int i = 0; i < s.fontFamiliesLen; i++) {
Kevin Lubick369f6a52019-10-03 11:22:08 -0400170 ff.emplace_back(fontFamilies[i]);
171 }
172 ts.setFontFamilies(ff);
173 }
174
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700175 ts.setTextBaseline(s.textBaseline);
176
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400177 SkFontStyle fs(s.fontStyle.weight, s.fontStyle.width, s.fontStyle.slant);
178 ts.setFontStyle(fs);
179
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700180 if (s.shadowLen > 0) {
181 const SkColor4f* colors = reinterpret_cast<const SkColor4f*>(s.shadowColorsPtr);
182 const SkPoint* offsets = reinterpret_cast<const SkPoint*>(s.shadowOffsetsPtr);
183 const float* blurRadii = reinterpret_cast<const float*>(s.shadowBlurRadiiPtr);
184 for (int i = 0; i < s.shadowLen; i++) {
185 para::TextShadow shadow(colors[i].toSkColor(), offsets[i], blurRadii[i]);
186 ts.addShadow(shadow);
187 }
188 }
189
190
191 if (s.fontFeatureLen > 0) {
192 const char** fontFeatureNames = reinterpret_cast<const char**>(s.fontFeatureNamesPtr);
193 const int* fontFeatureValues = reinterpret_cast<const int*>(s.fontFeatureValuesPtr);
194 for (int i = 0; i < s.fontFeatureLen; i++) {
195 // Font features names are 4-character simple strings.
196 SkString name(fontFeatureNames[i], 4);
197 ts.addFontFeature(name, fontFeatureValues[i]);
198 }
199 }
200
Kevin Lubick369f6a52019-10-03 11:22:08 -0400201 return ts;
202}
203
204struct SimpleParagraphStyle {
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400205 bool disableHinting;
206 uintptr_t /* const char* */ ellipsisPtr;
207 size_t ellipsisLen;
Kevin Lubick369f6a52019-10-03 11:22:08 -0400208 SkScalar heightMultiplier;
Kevin Lubick369f6a52019-10-03 11:22:08 -0400209 size_t maxLines;
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400210 para::TextAlign textAlign;
211 para::TextDirection textDirection;
212 SimpleTextStyle textStyle;
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700213 SimpleStrutStyle strutStyle;
Kevin Lubick369f6a52019-10-03 11:22:08 -0400214};
215
216para::ParagraphStyle toParagraphStyle(const SimpleParagraphStyle& s) {
217 para::ParagraphStyle ps;
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400218 if (s.disableHinting) {
219 ps.turnHintingOff();
220 }
221
222 if (s.ellipsisLen > 0) {
223 const char* ellipsisPtr = reinterpret_cast<const char*>(s.ellipsisPtr);
224 SkString eStr(ellipsisPtr, s.ellipsisLen);
225 ps.setEllipsis(eStr);
226 }
227 ps.setTextAlign(s.textAlign);
228 ps.setTextDirection(s.textDirection);
Kevin Lubick369f6a52019-10-03 11:22:08 -0400229 auto ts = toTextStyle(s.textStyle);
230 ps.setTextStyle(ts);
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700231 auto ss = toStrutStyle(s.strutStyle);
232 ps.setStrutStyle(ss);
Kevin Lubick369f6a52019-10-03 11:22:08 -0400233 if (s.heightMultiplier != 0) {
234 ps.setHeight(s.heightMultiplier);
235 }
Kevin Lubick369f6a52019-10-03 11:22:08 -0400236 if (s.maxLines != 0) {
237 ps.setMaxLines(s.maxLines);
238 }
239 return ps;
240}
241
Kevin Lubick4a5f4f22019-11-20 08:27:10 -0500242struct SimpleTextBox {
243 SkRect rect;
244 // This isn't the most efficient way to represent this, but it is much easier to keep
245 // everything as floats when unpacking on the JS side.
246 // 0.0 = RTL, 1.0 = LTr
247 SkScalar direction;
248};
249
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700250Float32Array TextBoxesToFloat32Array(std::vector<para::TextBox> boxes) {
Kevin Lubick4a5f4f22019-11-20 08:27:10 -0500251 // Pack these text boxes into an array of n groups of 5 SkScalar (floats)
Kevin Lubick369f6a52019-10-03 11:22:08 -0400252 if (!boxes.size()) {
253 return emscripten::val::null();
254 }
Kevin Lubick4a5f4f22019-11-20 08:27:10 -0500255 SimpleTextBox* rects = new SimpleTextBox[boxes.size()];
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700256 for (int i = 0; i < boxes.size(); i++) {
Kevin Lubick4a5f4f22019-11-20 08:27:10 -0500257 rects[i].rect = boxes[i].rect;
258 if (boxes[i].direction == para::TextDirection::kRtl) {
259 rects[i].direction = 0;
260 } else {
261 rects[i].direction = 1;
262 }
Kevin Lubick369f6a52019-10-03 11:22:08 -0400263 }
264 float* fPtr = reinterpret_cast<float*>(rects);
265 // Of note: now that we have cast rects to float*, emscripten is smart enough to wrap this
266 // into a Float32Array for us.
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700267 return Float32Array(typed_memory_view(boxes.size() * 5, fPtr));
268}
269
270Float32Array GetRectsForRange(para::ParagraphImpl& self,
271 unsigned start,
272 unsigned end,
273 para::RectHeightStyle heightStyle,
274 para::RectWidthStyle widthStyle) {
275 std::vector<para::TextBox> boxes = self.getRectsForRange(start, end, heightStyle, widthStyle);
276 return TextBoxesToFloat32Array(boxes);
277}
278
279Float32Array GetRectsForPlaceholders(para::ParagraphImpl& self) {
280 std::vector<para::TextBox> boxes = self.getRectsForPlaceholders();
281 return TextBoxesToFloat32Array(boxes);
Kevin Lubick369f6a52019-10-03 11:22:08 -0400282}
283
284EMSCRIPTEN_BINDINGS(Paragraph) {
285
286 class_<para::Paragraph>("Paragraph");
287
288 // This "base<>" tells Emscripten that ParagraphImpl is a Paragraph and can get substituted
289 // in properly in drawParagraph. However, Emscripten will not let us bind pure virtual methods
Kevin Lubick04912672019-11-15 14:48:55 -0500290 // so we have to "expose" the ParagraphImpl in those cases.
Kevin Lubick369f6a52019-10-03 11:22:08 -0400291 class_<para::ParagraphImpl, base<para::Paragraph>>("ParagraphImpl")
Kevin Lubick04912672019-11-15 14:48:55 -0500292 .function("didExceedMaxLines", &para::Paragraph::didExceedMaxLines)
293 .function("getAlphabeticBaseline", &para::Paragraph::getAlphabeticBaseline)
Kevin Lubick369f6a52019-10-03 11:22:08 -0400294 .function("getGlyphPositionAtCoordinate", &para::ParagraphImpl::getGlyphPositionAtCoordinate)
Kevin Lubick04912672019-11-15 14:48:55 -0500295 .function("getHeight", &para::Paragraph::getHeight)
296 .function("getIdeographicBaseline", &para::Paragraph::getIdeographicBaseline)
297 .function("getLongestLine", &para::Paragraph::getLongestLine)
298 .function("getMaxIntrinsicWidth", &para::Paragraph::getMaxIntrinsicWidth)
299 .function("getMaxWidth", &para::Paragraph::getMaxWidth)
300 .function("getMinIntrinsicWidth", &para::Paragraph::getMinIntrinsicWidth)
301 .function("_getRectsForRange", &GetRectsForRange)
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700302 .function("_getRectsForPlaceholders", &GetRectsForPlaceholders)
Kevin Lubick04912672019-11-15 14:48:55 -0500303 .function("getWordBoundary", &para::ParagraphImpl::getWordBoundary)
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700304 .function("layout", &para::ParagraphImpl::layout)
305 .function("getLineMetrics", &para::ParagraphImpl::getLineMetrics);
Kevin Lubick369f6a52019-10-03 11:22:08 -0400306
307 class_<para::ParagraphBuilderImpl>("ParagraphBuilder")
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700308 .class_function(
309 "_Make",
310 optional_override([](SimpleParagraphStyle style, sk_sp<SkFontMgr> fontMgr)
311 -> std::unique_ptr<para::ParagraphBuilderImpl> {
312 auto fc = sk_make_sp<para::FontCollection>();
313 fc->setDefaultFontManager(fontMgr);
314 fc->enableFontFallback();
315 auto ps = toParagraphStyle(style);
316 auto pb = para::ParagraphBuilderImpl::make(ps, fc);
317 return std::unique_ptr<para::ParagraphBuilderImpl>(
318 static_cast<para::ParagraphBuilderImpl*>(pb.release()));
319 }),
320 allow_raw_pointers())
321 .class_function(
322 "_MakeFromFontProvider",
323 optional_override([](SimpleParagraphStyle style,
324 sk_sp<para::TypefaceFontProvider> fontProvider)
325 -> std::unique_ptr<para::ParagraphBuilderImpl> {
326 auto fc = sk_make_sp<para::FontCollection>();
327 fc->setDefaultFontManager(fontProvider);
328 fc->enableFontFallback();
329 auto ps = toParagraphStyle(style);
330 auto pb = para::ParagraphBuilderImpl::make(ps, fc);
331 return std::unique_ptr<para::ParagraphBuilderImpl>(
332 static_cast<para::ParagraphBuilderImpl*>(pb.release()));
333 }),
334 allow_raw_pointers())
335 .function("addText",
336 optional_override([](para::ParagraphBuilderImpl& self, std::string text) {
337 return self.addText(text.c_str(), text.length());
338 }))
339 .function("build", &para::ParagraphBuilderImpl::Build, allow_raw_pointers())
340 .function("pop", &para::ParagraphBuilderImpl::pop)
341 .function("_pushStyle", optional_override([](para::ParagraphBuilderImpl& self,
342 SimpleTextStyle textStyle) {
343 auto ts = toTextStyle(textStyle);
344 self.pushStyle(ts);
345 }))
346 // A method of pushing a textStyle with paints instead of colors for foreground and
347 // background. Since SimpleTextStyle is a value object, it cannot contain paints, which
348 // are not primitives. This binding is here to accept them. Any color that is specified
349 // in the textStyle is overridden.
350 .function("_pushPaintStyle",
351 optional_override([](para::ParagraphBuilderImpl& self,
352 SimpleTextStyle textStyle, SkPaint foreground,
353 SkPaint background) {
354 auto ts = toTextStyle(textStyle);
355 ts.setForegroundColor(foreground);
356 ts.setBackgroundColor(background);
357 self.pushStyle(ts);
358 }))
359 .function("_addPlaceholder", optional_override([](para::ParagraphBuilderImpl& self,
360 SkScalar width,
361 SkScalar height,
362 para::PlaceholderAlignment alignment,
363 para::TextBaseline baseline,
364 SkScalar offset) {
365 para::PlaceholderStyle ps(width, height, alignment, baseline, offset);
366 self.addPlaceholder(ps);
367 }));
Kevin Lubick369f6a52019-10-03 11:22:08 -0400368
Harry Terkelsen10f019c2020-08-04 13:21:09 -0700369 class_<para::TypefaceFontProvider, base<SkFontMgr>>("TypefaceFontProvider")
370 .smart_ptr<sk_sp<para::TypefaceFontProvider>>("sk_sp<TypefaceFontProvider>")
371 .class_function("Make", optional_override([]()-> sk_sp<para::TypefaceFontProvider> {
372 return sk_make_sp<para::TypefaceFontProvider>();
373 }))
374 .function("_registerFont", optional_override([](para::TypefaceFontProvider& self,
375 sk_sp<SkTypeface> typeface,
376 uintptr_t familyPtr) {
377 const char* fPtr = reinterpret_cast<const char*>(familyPtr);
378 SkString fStr(fPtr);
379 self.registerTypeface(typeface, fStr);
380 }), allow_raw_pointers());
381
Kevin Lubick369f6a52019-10-03 11:22:08 -0400382
383 enum_<para::Affinity>("Affinity")
384 .value("Upstream", para::Affinity::kUpstream)
385 .value("Downstream", para::Affinity::kDownstream);
386
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400387 enum_<SkFontStyle::Slant>("FontSlant")
388 .value("Upright", SkFontStyle::Slant::kUpright_Slant)
389 .value("Italic", SkFontStyle::Slant::kItalic_Slant)
390 .value("Oblique", SkFontStyle::Slant::kOblique_Slant);
391
392 enum_<SkFontStyle::Weight>("FontWeight")
393 .value("Invisible", SkFontStyle::Weight::kInvisible_Weight)
394 .value("Thin", SkFontStyle::Weight::kThin_Weight)
395 .value("ExtraLight", SkFontStyle::Weight::kExtraLight_Weight)
396 .value("Light", SkFontStyle::Weight::kLight_Weight)
397 .value("Normal", SkFontStyle::Weight::kNormal_Weight)
398 .value("Medium", SkFontStyle::Weight::kMedium_Weight)
399 .value("SemiBold", SkFontStyle::Weight::kSemiBold_Weight)
400 .value("Bold", SkFontStyle::Weight::kBold_Weight)
401 .value("ExtraBold", SkFontStyle::Weight::kExtraBold_Weight)
402 .value("Black" , SkFontStyle::Weight::kBlack_Weight)
403 .value("ExtraBlack", SkFontStyle::Weight::kExtraBlack_Weight);
404
405 enum_<SkFontStyle::Width>("FontWidth")
406 .value("UltraCondensed", SkFontStyle::Width::kUltraCondensed_Width)
407 .value("ExtraCondensed", SkFontStyle::Width::kExtraCondensed_Width)
408 .value("Condensed", SkFontStyle::Width::kCondensed_Width)
409 .value("SemiCondensed", SkFontStyle::Width::kSemiCondensed_Width)
410 .value("Normal", SkFontStyle::Width::kNormal_Width)
411 .value("SemiExpanded", SkFontStyle::Width::kSemiExpanded_Width)
412 .value("Expanded", SkFontStyle::Width::kExpanded_Width)
413 .value("ExtraExpanded", SkFontStyle::Width::kExtraExpanded_Width)
414 .value("UltraExpanded", SkFontStyle::Width::kUltraExpanded_Width);
415
Kevin Lubick369f6a52019-10-03 11:22:08 -0400416 enum_<para::RectHeightStyle>("RectHeightStyle")
Kevin Lubick4a5f4f22019-11-20 08:27:10 -0500417 .value("Tight", para::RectHeightStyle::kTight)
418 .value("Max", para::RectHeightStyle::kMax)
419 .value("IncludeLineSpacingMiddle", para::RectHeightStyle::kIncludeLineSpacingMiddle)
420 .value("IncludeLineSpacingTop", para::RectHeightStyle::kIncludeLineSpacingTop)
421 .value("IncludeLineSpacingBottom", para::RectHeightStyle::kIncludeLineSpacingBottom);
Kevin Lubick369f6a52019-10-03 11:22:08 -0400422
423 enum_<para::RectWidthStyle>("RectWidthStyle")
424 .value("Tight", para::RectWidthStyle::kTight)
425 .value("Max", para::RectWidthStyle::kMax);
426
427 enum_<para::TextAlign>("TextAlign")
428 .value("Left", para::TextAlign::kLeft)
429 .value("Right", para::TextAlign::kRight)
430 .value("Center", para::TextAlign::kCenter)
431 .value("Justify", para::TextAlign::kJustify)
432 .value("Start", para::TextAlign::kStart)
433 .value("End", para::TextAlign::kEnd);
434
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400435 enum_<para::TextDirection>("TextDirection")
436 .value("LTR", para::TextDirection::kLtr)
437 .value("RTL", para::TextDirection::kRtl);
438
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700439 enum_<para::TextDecorationStyle>("DecorationStyle")
440 .value("Solid", para::TextDecorationStyle::kSolid)
441 .value("Double", para::TextDecorationStyle::kDouble)
442 .value("Dotted", para::TextDecorationStyle::kDotted)
443 .value("Dashed", para::TextDecorationStyle::kDashed)
444 .value("Wavy", para::TextDecorationStyle::kWavy);
445
446 enum_<para::PlaceholderAlignment>("PlaceholderAlignment")
447 .value("Baseline", para::PlaceholderAlignment::kBaseline)
448 .value("AboveBaseline", para::PlaceholderAlignment::kAboveBaseline)
449 .value("BelowBaseline", para::PlaceholderAlignment::kBelowBaseline)
450 .value("Top", para::PlaceholderAlignment::kTop)
451 .value("Bottom", para::PlaceholderAlignment::kBottom)
452 .value("Middle", para::PlaceholderAlignment::kMiddle);
453
454 enum_<para::TextBaseline>("TextBaseline")
455 .value("Alphabetic", para::TextBaseline::kAlphabetic)
456 .value("Ideographic", para::TextBaseline::kIdeographic);
Kevin Lubick369f6a52019-10-03 11:22:08 -0400457
458 value_object<para::PositionWithAffinity>("PositionWithAffinity")
459 .field("pos", &para::PositionWithAffinity::position)
460 .field("affinity", &para::PositionWithAffinity::affinity);
461
Kevin Lubick04912672019-11-15 14:48:55 -0500462 value_object<SimpleFontStyle>("FontStyle")
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400463 .field("slant", &SimpleFontStyle::slant)
464 .field("weight", &SimpleFontStyle::weight)
465 .field("width", &SimpleFontStyle::width);
466
Kevin Lubick369f6a52019-10-03 11:22:08 -0400467 value_object<SimpleParagraphStyle>("ParagraphStyle")
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400468 .field("disableHinting", &SimpleParagraphStyle::disableHinting)
469 .field("_ellipsisPtr", &SimpleParagraphStyle::ellipsisPtr)
470 .field("_ellipsisLen", &SimpleParagraphStyle::ellipsisLen)
Kevin Lubick369f6a52019-10-03 11:22:08 -0400471 .field("heightMultiplier", &SimpleParagraphStyle::heightMultiplier)
472 .field("maxLines", &SimpleParagraphStyle::maxLines)
473 .field("textAlign", &SimpleParagraphStyle::textAlign)
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400474 .field("textDirection", &SimpleParagraphStyle::textDirection)
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700475 .field("textStyle", &SimpleParagraphStyle::textStyle)
476 .field("strutStyle", &SimpleParagraphStyle::strutStyle);
477
478 value_object<SimpleStrutStyle>("StrutStyle")
479 .field("_fontFamiliesPtr", &SimpleStrutStyle::fontFamiliesPtr)
480 .field("_fontFamiliesLen", &SimpleStrutStyle::fontFamiliesLen)
481 .field("strutEnabled", &SimpleStrutStyle::strutEnabled)
482 .field("fontSize", &SimpleStrutStyle::fontSize)
483 .field("fontStyle", &SimpleStrutStyle::fontStyle)
484 .field("heightMultiplier", &SimpleStrutStyle::heightMultiplier)
485 .field("leading", &SimpleStrutStyle::leading)
486 .field("forceStrutHeight", &SimpleStrutStyle::forceStrutHeight);
Kevin Lubick369f6a52019-10-03 11:22:08 -0400487
488 value_object<SimpleTextStyle>("TextStyle")
Harry Terkelsen223ffcd2020-10-02 15:24:13 -0700489 .field("_colorPtr", &SimpleTextStyle::colorPtr)
490 .field("_foregroundColorPtr", &SimpleTextStyle::foregroundColorPtr)
491 .field("_backgroundColorPtr", &SimpleTextStyle::backgroundColorPtr)
492 .field("decoration", &SimpleTextStyle::decoration)
493 .field("decorationThickness", &SimpleTextStyle::decorationThickness)
494 .field("_decorationColorPtr", &SimpleTextStyle::decorationColorPtr)
495 .field("decorationStyle", &SimpleTextStyle::decorationStyle)
496 .field("_fontFamiliesPtr", &SimpleTextStyle::fontFamiliesPtr)
497 .field("_fontFamiliesLen", &SimpleTextStyle::fontFamiliesLen)
498 .field("fontSize", &SimpleTextStyle::fontSize)
499 .field("letterSpacing", &SimpleTextStyle::letterSpacing)
500 .field("wordSpacing", &SimpleTextStyle::wordSpacing)
501 .field("heightMultiplier", &SimpleTextStyle::heightMultiplier)
502 .field("_localePtr", &SimpleTextStyle::localePtr)
503 .field("_localeLen", &SimpleTextStyle::localeLen)
504 .field("fontStyle", &SimpleTextStyle::fontStyle)
505 .field("_shadowLen", &SimpleTextStyle::shadowLen)
506 .field("_shadowColorsPtr", &SimpleTextStyle::shadowColorsPtr)
507 .field("_shadowOffsetsPtr", &SimpleTextStyle::shadowOffsetsPtr)
508 .field("_shadowBlurRadiiPtr", &SimpleTextStyle::shadowBlurRadiiPtr)
509 .field("_fontFeatureLen", &SimpleTextStyle::fontFeatureLen)
510 .field("_fontFeatureNamesPtr", &SimpleTextStyle::fontFeatureNamesPtr)
511 .field("_fontFeatureValuesPtr", &SimpleTextStyle::fontFeatureValuesPtr);
Kevin Lubick369f6a52019-10-03 11:22:08 -0400512
Kevin Lubick04912672019-11-15 14:48:55 -0500513 // The U stands for unsigned - we can't bind a generic/template object, so we have to specify it
514 // with the type we are using.
515 value_object<para::SkRange<size_t>>("URange")
516 .field("start", &para::SkRange<size_t>::start)
517 .field("end", &para::SkRange<size_t>::end);
518
Kevin Lubick369f6a52019-10-03 11:22:08 -0400519 // TextDecoration should be a const because they can be combined
520 constant("NoDecoration", int(para::TextDecoration::kNoDecoration));
521 constant("UnderlineDecoration", int(para::TextDecoration::kUnderline));
522 constant("OverlineDecoration", int(para::TextDecoration::kOverline));
523 constant("LineThroughDecoration", int(para::TextDecoration::kLineThrough));
524}