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