Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 1 | /* |
| 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 Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 9 | #include "include/core/SkFontStyle.h" |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 10 | #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 Terkelsen | 10f019c | 2020-08-04 13:21:09 -0700 | [diff] [blame^] | 16 | #include "modules/skparagraph/include/TypefaceFontProvider.h" |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 17 | #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 Nifong | e5d3254 | 2020-03-26 09:27:48 -0400 | [diff] [blame] | 25 | #include "modules/canvaskit/WasmCommon.h" |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 26 | |
| 27 | using namespace emscripten; |
| 28 | |
| 29 | namespace para = skia::textlayout; |
| 30 | |
Nathaniel Nifong | 1bedbeb | 2020-05-04 16:46:17 -0400 | [diff] [blame] | 31 | SkColor4f toSkColor4f(uintptr_t /* float* */ cPtr) { |
| 32 | float* fourFloats = reinterpret_cast<float*>(cPtr); |
| 33 | SkColor4f color = { fourFloats[0], fourFloats[1], fourFloats[2], fourFloats[3] }; |
| 34 | return color; |
| 35 | } |
| 36 | |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 37 | struct SimpleFontStyle { |
| 38 | SkFontStyle::Slant slant; |
| 39 | SkFontStyle::Weight weight; |
| 40 | SkFontStyle::Width width; |
| 41 | }; |
| 42 | |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 43 | struct SimpleTextStyle { |
Nathaniel Nifong | 1bedbeb | 2020-05-04 16:46:17 -0400 | [diff] [blame] | 44 | uintptr_t /* float* */ colorPtr; |
| 45 | uintptr_t /* float* */ foregroundColorPtr; |
| 46 | uintptr_t /* float* */ backgroundColorPtr; |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 47 | uint8_t decoration; |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 48 | SkScalar decorationThickness; |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 49 | SkScalar fontSize; |
| 50 | SimpleFontStyle fontStyle; |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 51 | |
Kevin Lubick | 0c8884b | 2020-05-14 08:27:53 -0400 | [diff] [blame] | 52 | uintptr_t /* const char** */ fontFamiliesPtr; |
| 53 | int fontFamiliesLen; |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | para::TextStyle toTextStyle(const SimpleTextStyle& s) { |
| 57 | para::TextStyle ts; |
Nathaniel Nifong | e5d3254 | 2020-03-26 09:27:48 -0400 | [diff] [blame] | 58 | |
| 59 | // textstyle.color doesn't support a 4f color, however the foreground and background fields below do. |
Nathaniel Nifong | 1bedbeb | 2020-05-04 16:46:17 -0400 | [diff] [blame] | 60 | ts.setColor(toSkColor4f(s.colorPtr).toSkColor()); |
Nathaniel Nifong | e5d3254 | 2020-03-26 09:27:48 -0400 | [diff] [blame] | 61 | |
Nathaniel Nifong | e5d3254 | 2020-03-26 09:27:48 -0400 | [diff] [blame] | 62 | // It is functionally important that these paints be unset when no value was provided. |
Nathaniel Nifong | 1bedbeb | 2020-05-04 16:46:17 -0400 | [diff] [blame] | 63 | if (s.foregroundColorPtr) { |
Nathaniel Nifong | e5d3254 | 2020-03-26 09:27:48 -0400 | [diff] [blame] | 64 | SkPaint p1; |
Nathaniel Nifong | 1bedbeb | 2020-05-04 16:46:17 -0400 | [diff] [blame] | 65 | p1.setColor4f(toSkColor4f(s.foregroundColorPtr)); |
Nathaniel Nifong | e5d3254 | 2020-03-26 09:27:48 -0400 | [diff] [blame] | 66 | ts.setForegroundColor(p1); |
Robert Phillips | cb77eab | 2020-03-24 14:19:40 +0000 | [diff] [blame] | 67 | } |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 68 | |
Nathaniel Nifong | 1bedbeb | 2020-05-04 16:46:17 -0400 | [diff] [blame] | 69 | if (s.backgroundColorPtr) { |
Nathaniel Nifong | e5d3254 | 2020-03-26 09:27:48 -0400 | [diff] [blame] | 70 | SkPaint p2; |
Nathaniel Nifong | 1bedbeb | 2020-05-04 16:46:17 -0400 | [diff] [blame] | 71 | p2.setColor4f(toSkColor4f(s.backgroundColorPtr)); |
Nathaniel Nifong | e5d3254 | 2020-03-26 09:27:48 -0400 | [diff] [blame] | 72 | ts.setBackgroundColor(p2); |
Robert Phillips | cb77eab | 2020-03-24 14:19:40 +0000 | [diff] [blame] | 73 | } |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 74 | |
| 75 | if (s.fontSize != 0) { |
| 76 | ts.setFontSize(s.fontSize); |
| 77 | } |
| 78 | |
| 79 | ts.setDecoration(para::TextDecoration(s.decoration)); |
| 80 | if (s.decorationThickness != 0) { |
| 81 | ts.setDecorationThicknessMultiplier(s.decorationThickness); |
| 82 | } |
| 83 | |
Kevin Lubick | 0c8884b | 2020-05-14 08:27:53 -0400 | [diff] [blame] | 84 | const char** fontFamilies = reinterpret_cast<const char**>(s.fontFamiliesPtr); |
| 85 | if (s.fontFamiliesLen > 0 && fontFamilies != nullptr) { |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 86 | std::vector<SkString> ff; |
Kevin Lubick | 0c8884b | 2020-05-14 08:27:53 -0400 | [diff] [blame] | 87 | for (int i = 0; i < s.fontFamiliesLen; i++) { |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 88 | ff.emplace_back(fontFamilies[i]); |
| 89 | } |
| 90 | ts.setFontFamilies(ff); |
| 91 | } |
| 92 | |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 93 | SkFontStyle fs(s.fontStyle.weight, s.fontStyle.width, s.fontStyle.slant); |
| 94 | ts.setFontStyle(fs); |
| 95 | |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 96 | return ts; |
| 97 | } |
| 98 | |
| 99 | struct SimpleParagraphStyle { |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 100 | bool disableHinting; |
| 101 | uintptr_t /* const char* */ ellipsisPtr; |
| 102 | size_t ellipsisLen; |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 103 | SkScalar heightMultiplier; |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 104 | size_t maxLines; |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 105 | para::TextAlign textAlign; |
| 106 | para::TextDirection textDirection; |
| 107 | SimpleTextStyle textStyle; |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | para::ParagraphStyle toParagraphStyle(const SimpleParagraphStyle& s) { |
| 111 | para::ParagraphStyle ps; |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 112 | if (s.disableHinting) { |
| 113 | ps.turnHintingOff(); |
| 114 | } |
| 115 | |
| 116 | if (s.ellipsisLen > 0) { |
| 117 | const char* ellipsisPtr = reinterpret_cast<const char*>(s.ellipsisPtr); |
| 118 | SkString eStr(ellipsisPtr, s.ellipsisLen); |
| 119 | ps.setEllipsis(eStr); |
| 120 | } |
| 121 | ps.setTextAlign(s.textAlign); |
| 122 | ps.setTextDirection(s.textDirection); |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 123 | auto ts = toTextStyle(s.textStyle); |
| 124 | ps.setTextStyle(ts); |
| 125 | if (s.heightMultiplier != 0) { |
| 126 | ps.setHeight(s.heightMultiplier); |
| 127 | } |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 128 | if (s.maxLines != 0) { |
| 129 | ps.setMaxLines(s.maxLines); |
| 130 | } |
| 131 | return ps; |
| 132 | } |
| 133 | |
Kevin Lubick | 4a5f4f2 | 2019-11-20 08:27:10 -0500 | [diff] [blame] | 134 | struct SimpleTextBox { |
| 135 | SkRect rect; |
| 136 | // This isn't the most efficient way to represent this, but it is much easier to keep |
| 137 | // everything as floats when unpacking on the JS side. |
| 138 | // 0.0 = RTL, 1.0 = LTr |
| 139 | SkScalar direction; |
| 140 | }; |
| 141 | |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 142 | Float32Array GetRectsForRange(para::ParagraphImpl& self, unsigned start, unsigned end, |
| 143 | para::RectHeightStyle heightStyle, para::RectWidthStyle widthStyle) { |
| 144 | std::vector<para::TextBox> boxes = self.getRectsForRange(start, end, heightStyle, widthStyle); |
Kevin Lubick | 4a5f4f2 | 2019-11-20 08:27:10 -0500 | [diff] [blame] | 145 | // Pack these text boxes into an array of n groups of 5 SkScalar (floats) |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 146 | if (!boxes.size()) { |
| 147 | return emscripten::val::null(); |
| 148 | } |
Kevin Lubick | 4a5f4f2 | 2019-11-20 08:27:10 -0500 | [diff] [blame] | 149 | SimpleTextBox* rects = new SimpleTextBox[boxes.size()]; |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 150 | for (int i = 0; i< boxes.size(); i++) { |
Kevin Lubick | 4a5f4f2 | 2019-11-20 08:27:10 -0500 | [diff] [blame] | 151 | rects[i].rect = boxes[i].rect; |
| 152 | if (boxes[i].direction == para::TextDirection::kRtl) { |
| 153 | rects[i].direction = 0; |
| 154 | } else { |
| 155 | rects[i].direction = 1; |
| 156 | } |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 157 | } |
| 158 | float* fPtr = reinterpret_cast<float*>(rects); |
| 159 | // Of note: now that we have cast rects to float*, emscripten is smart enough to wrap this |
| 160 | // into a Float32Array for us. |
Kevin Lubick | 4a5f4f2 | 2019-11-20 08:27:10 -0500 | [diff] [blame] | 161 | return Float32Array(typed_memory_view(boxes.size()*5, fPtr)); |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | EMSCRIPTEN_BINDINGS(Paragraph) { |
| 165 | |
| 166 | class_<para::Paragraph>("Paragraph"); |
| 167 | |
| 168 | // This "base<>" tells Emscripten that ParagraphImpl is a Paragraph and can get substituted |
| 169 | // in properly in drawParagraph. However, Emscripten will not let us bind pure virtual methods |
Kevin Lubick | 0491267 | 2019-11-15 14:48:55 -0500 | [diff] [blame] | 170 | // so we have to "expose" the ParagraphImpl in those cases. |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 171 | class_<para::ParagraphImpl, base<para::Paragraph>>("ParagraphImpl") |
Kevin Lubick | 0491267 | 2019-11-15 14:48:55 -0500 | [diff] [blame] | 172 | .function("didExceedMaxLines", ¶::Paragraph::didExceedMaxLines) |
| 173 | .function("getAlphabeticBaseline", ¶::Paragraph::getAlphabeticBaseline) |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 174 | .function("getGlyphPositionAtCoordinate", ¶::ParagraphImpl::getGlyphPositionAtCoordinate) |
Kevin Lubick | 0491267 | 2019-11-15 14:48:55 -0500 | [diff] [blame] | 175 | .function("getHeight", ¶::Paragraph::getHeight) |
| 176 | .function("getIdeographicBaseline", ¶::Paragraph::getIdeographicBaseline) |
| 177 | .function("getLongestLine", ¶::Paragraph::getLongestLine) |
| 178 | .function("getMaxIntrinsicWidth", ¶::Paragraph::getMaxIntrinsicWidth) |
| 179 | .function("getMaxWidth", ¶::Paragraph::getMaxWidth) |
| 180 | .function("getMinIntrinsicWidth", ¶::Paragraph::getMinIntrinsicWidth) |
| 181 | .function("_getRectsForRange", &GetRectsForRange) |
| 182 | .function("getWordBoundary", ¶::ParagraphImpl::getWordBoundary) |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 183 | .function("layout", ¶::ParagraphImpl::layout); |
| 184 | |
| 185 | class_<para::ParagraphBuilderImpl>("ParagraphBuilder") |
Nathaniel Nifong | 1bedbeb | 2020-05-04 16:46:17 -0400 | [diff] [blame] | 186 | .class_function("_Make", optional_override([](SimpleParagraphStyle style, |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 187 | sk_sp<SkFontMgr> fontMgr)-> para::ParagraphBuilderImpl { |
| 188 | auto fc = sk_make_sp<para::FontCollection>(); |
| 189 | fc->setDefaultFontManager(fontMgr); |
| 190 | auto ps = toParagraphStyle(style); |
| 191 | para::ParagraphBuilderImpl pbi(ps, fc); |
| 192 | return pbi; |
| 193 | }), allow_raw_pointers()) |
Harry Terkelsen | 10f019c | 2020-08-04 13:21:09 -0700 | [diff] [blame^] | 194 | .class_function("_MakeFromFontProvider", optional_override([](SimpleParagraphStyle style, |
| 195 | sk_sp<para::TypefaceFontProvider> fontProvider)-> para::ParagraphBuilderImpl { |
| 196 | auto fc = sk_make_sp<para::FontCollection>(); |
| 197 | fc->setDefaultFontManager(fontProvider); |
| 198 | auto ps = toParagraphStyle(style); |
| 199 | para::ParagraphBuilderImpl pbi(ps, fc); |
| 200 | return pbi; |
| 201 | }), allow_raw_pointers()) |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 202 | .function("addText", optional_override([](para::ParagraphBuilderImpl& self, std::string text) { |
| 203 | return self.addText(text.c_str(), text.length()); |
| 204 | })) |
| 205 | .function("build", ¶::ParagraphBuilderImpl::Build, allow_raw_pointers()) |
| 206 | .function("pop", ¶::ParagraphBuilderImpl::pop) |
Nathaniel Nifong | 1bedbeb | 2020-05-04 16:46:17 -0400 | [diff] [blame] | 207 | .function("_pushStyle", optional_override([](para::ParagraphBuilderImpl& self, |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 208 | SimpleTextStyle textStyle) { |
| 209 | auto ts = toTextStyle(textStyle); |
| 210 | self.pushStyle(ts); |
Nathaniel Nifong | e09b314 | 2020-08-04 09:06:54 -0400 | [diff] [blame] | 211 | })) |
| 212 | // A method of pushing a textStyle with paints instead of colors for foreground and |
| 213 | // background. Since SimpleTextStyle is a value object, it cannot contain paints, which are not primitives. This binding is here to accept them. Any color that is specified in the textStyle is overridden. |
| 214 | .function("_pushPaintStyle", optional_override([](para::ParagraphBuilderImpl& self, |
| 215 | SimpleTextStyle textStyle, SkPaint foreground, SkPaint background) { |
| 216 | auto ts = toTextStyle(textStyle); |
| 217 | ts.setForegroundColor(foreground); |
| 218 | ts.setBackgroundColor(background); |
| 219 | self.pushStyle(ts); |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 220 | })); |
| 221 | |
Harry Terkelsen | 10f019c | 2020-08-04 13:21:09 -0700 | [diff] [blame^] | 222 | class_<para::TypefaceFontProvider, base<SkFontMgr>>("TypefaceFontProvider") |
| 223 | .smart_ptr<sk_sp<para::TypefaceFontProvider>>("sk_sp<TypefaceFontProvider>") |
| 224 | .class_function("Make", optional_override([]()-> sk_sp<para::TypefaceFontProvider> { |
| 225 | return sk_make_sp<para::TypefaceFontProvider>(); |
| 226 | })) |
| 227 | .function("_registerFont", optional_override([](para::TypefaceFontProvider& self, |
| 228 | sk_sp<SkTypeface> typeface, |
| 229 | uintptr_t familyPtr) { |
| 230 | const char* fPtr = reinterpret_cast<const char*>(familyPtr); |
| 231 | SkString fStr(fPtr); |
| 232 | self.registerTypeface(typeface, fStr); |
| 233 | }), allow_raw_pointers()); |
| 234 | |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 235 | |
| 236 | enum_<para::Affinity>("Affinity") |
| 237 | .value("Upstream", para::Affinity::kUpstream) |
| 238 | .value("Downstream", para::Affinity::kDownstream); |
| 239 | |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 240 | enum_<SkFontStyle::Slant>("FontSlant") |
| 241 | .value("Upright", SkFontStyle::Slant::kUpright_Slant) |
| 242 | .value("Italic", SkFontStyle::Slant::kItalic_Slant) |
| 243 | .value("Oblique", SkFontStyle::Slant::kOblique_Slant); |
| 244 | |
| 245 | enum_<SkFontStyle::Weight>("FontWeight") |
| 246 | .value("Invisible", SkFontStyle::Weight::kInvisible_Weight) |
| 247 | .value("Thin", SkFontStyle::Weight::kThin_Weight) |
| 248 | .value("ExtraLight", SkFontStyle::Weight::kExtraLight_Weight) |
| 249 | .value("Light", SkFontStyle::Weight::kLight_Weight) |
| 250 | .value("Normal", SkFontStyle::Weight::kNormal_Weight) |
| 251 | .value("Medium", SkFontStyle::Weight::kMedium_Weight) |
| 252 | .value("SemiBold", SkFontStyle::Weight::kSemiBold_Weight) |
| 253 | .value("Bold", SkFontStyle::Weight::kBold_Weight) |
| 254 | .value("ExtraBold", SkFontStyle::Weight::kExtraBold_Weight) |
| 255 | .value("Black" , SkFontStyle::Weight::kBlack_Weight) |
| 256 | .value("ExtraBlack", SkFontStyle::Weight::kExtraBlack_Weight); |
| 257 | |
| 258 | enum_<SkFontStyle::Width>("FontWidth") |
| 259 | .value("UltraCondensed", SkFontStyle::Width::kUltraCondensed_Width) |
| 260 | .value("ExtraCondensed", SkFontStyle::Width::kExtraCondensed_Width) |
| 261 | .value("Condensed", SkFontStyle::Width::kCondensed_Width) |
| 262 | .value("SemiCondensed", SkFontStyle::Width::kSemiCondensed_Width) |
| 263 | .value("Normal", SkFontStyle::Width::kNormal_Width) |
| 264 | .value("SemiExpanded", SkFontStyle::Width::kSemiExpanded_Width) |
| 265 | .value("Expanded", SkFontStyle::Width::kExpanded_Width) |
| 266 | .value("ExtraExpanded", SkFontStyle::Width::kExtraExpanded_Width) |
| 267 | .value("UltraExpanded", SkFontStyle::Width::kUltraExpanded_Width); |
| 268 | |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 269 | enum_<para::RectHeightStyle>("RectHeightStyle") |
Kevin Lubick | 4a5f4f2 | 2019-11-20 08:27:10 -0500 | [diff] [blame] | 270 | .value("Tight", para::RectHeightStyle::kTight) |
| 271 | .value("Max", para::RectHeightStyle::kMax) |
| 272 | .value("IncludeLineSpacingMiddle", para::RectHeightStyle::kIncludeLineSpacingMiddle) |
| 273 | .value("IncludeLineSpacingTop", para::RectHeightStyle::kIncludeLineSpacingTop) |
| 274 | .value("IncludeLineSpacingBottom", para::RectHeightStyle::kIncludeLineSpacingBottom); |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 275 | |
| 276 | enum_<para::RectWidthStyle>("RectWidthStyle") |
| 277 | .value("Tight", para::RectWidthStyle::kTight) |
| 278 | .value("Max", para::RectWidthStyle::kMax); |
| 279 | |
| 280 | enum_<para::TextAlign>("TextAlign") |
| 281 | .value("Left", para::TextAlign::kLeft) |
| 282 | .value("Right", para::TextAlign::kRight) |
| 283 | .value("Center", para::TextAlign::kCenter) |
| 284 | .value("Justify", para::TextAlign::kJustify) |
| 285 | .value("Start", para::TextAlign::kStart) |
| 286 | .value("End", para::TextAlign::kEnd); |
| 287 | |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 288 | enum_<para::TextDirection>("TextDirection") |
| 289 | .value("LTR", para::TextDirection::kLtr) |
| 290 | .value("RTL", para::TextDirection::kRtl); |
| 291 | |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 292 | |
| 293 | value_object<para::PositionWithAffinity>("PositionWithAffinity") |
| 294 | .field("pos", ¶::PositionWithAffinity::position) |
| 295 | .field("affinity", ¶::PositionWithAffinity::affinity); |
| 296 | |
Kevin Lubick | 0491267 | 2019-11-15 14:48:55 -0500 | [diff] [blame] | 297 | value_object<SimpleFontStyle>("FontStyle") |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 298 | .field("slant", &SimpleFontStyle::slant) |
| 299 | .field("weight", &SimpleFontStyle::weight) |
| 300 | .field("width", &SimpleFontStyle::width); |
| 301 | |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 302 | value_object<SimpleParagraphStyle>("ParagraphStyle") |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 303 | .field("disableHinting", &SimpleParagraphStyle::disableHinting) |
| 304 | .field("_ellipsisPtr", &SimpleParagraphStyle::ellipsisPtr) |
| 305 | .field("_ellipsisLen", &SimpleParagraphStyle::ellipsisLen) |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 306 | .field("heightMultiplier", &SimpleParagraphStyle::heightMultiplier) |
| 307 | .field("maxLines", &SimpleParagraphStyle::maxLines) |
| 308 | .field("textAlign", &SimpleParagraphStyle::textAlign) |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 309 | .field("textDirection", &SimpleParagraphStyle::textDirection) |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 310 | .field("textStyle", &SimpleParagraphStyle::textStyle); |
| 311 | |
| 312 | value_object<SimpleTextStyle>("TextStyle") |
Kevin Lubick | 0c8884b | 2020-05-14 08:27:53 -0400 | [diff] [blame] | 313 | .field("_colorPtr", &SimpleTextStyle::colorPtr) |
| 314 | .field("_foregroundColorPtr", &SimpleTextStyle::foregroundColorPtr) |
| 315 | .field("_backgroundColorPtr", &SimpleTextStyle::backgroundColorPtr) |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 316 | .field("decoration", &SimpleTextStyle::decoration) |
| 317 | .field("decorationThickness", &SimpleTextStyle::decorationThickness) |
Kevin Lubick | 0c8884b | 2020-05-14 08:27:53 -0400 | [diff] [blame] | 318 | .field("_fontFamiliesPtr", &SimpleTextStyle::fontFamiliesPtr) |
| 319 | .field("_fontFamiliesLen", &SimpleTextStyle::fontFamiliesLen) |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 320 | .field("fontSize", &SimpleTextStyle::fontSize) |
Kevin Lubick | 0c8884b | 2020-05-14 08:27:53 -0400 | [diff] [blame] | 321 | .field("fontStyle", &SimpleTextStyle::fontStyle); |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 322 | |
Kevin Lubick | 0491267 | 2019-11-15 14:48:55 -0500 | [diff] [blame] | 323 | // The U stands for unsigned - we can't bind a generic/template object, so we have to specify it |
| 324 | // with the type we are using. |
| 325 | value_object<para::SkRange<size_t>>("URange") |
| 326 | .field("start", ¶::SkRange<size_t>::start) |
| 327 | .field("end", ¶::SkRange<size_t>::end); |
| 328 | |
Kevin Lubick | 369f6a5 | 2019-10-03 11:22:08 -0400 | [diff] [blame] | 329 | // TextDecoration should be a const because they can be combined |
| 330 | constant("NoDecoration", int(para::TextDecoration::kNoDecoration)); |
| 331 | constant("UnderlineDecoration", int(para::TextDecoration::kUnderline)); |
| 332 | constant("OverlineDecoration", int(para::TextDecoration::kOverline)); |
| 333 | constant("LineThroughDecoration", int(para::TextDecoration::kLineThrough)); |
| 334 | } |