525 {
526
527 class_<para::Paragraph>("Paragraph")
549
550 class_<para::ParagraphBuilderImpl>("ParagraphBuilder")
551 .class_function(
552 "_Make",
554 -> std::unique_ptr<para::ParagraphBuilderImpl> {
555 auto fc = sk_make_sp<para::FontCollection>();
556 fc->setDefaultFontManager(
fontMgr);
557 fc->enableFontFallback();
560 return std::unique_ptr<para::ParagraphBuilderImpl>(
562 }),
563 allow_raw_pointers())
564 .class_function(
565 "_MakeFromFontProvider",
568 -> std::unique_ptr<para::ParagraphBuilderImpl> {
569 auto fc = sk_make_sp<para::FontCollection>();
570 fc->setDefaultFontManager(fontProvider);
571 fc->enableFontFallback();
574 return std::unique_ptr<para::ParagraphBuilderImpl>(
576 }),
577 allow_raw_pointers())
578 .class_function(
579 "_MakeFromFontCollection",
582 -> std::unique_ptr<para::ParagraphBuilderImpl> {
585 return std::unique_ptr<para::ParagraphBuilderImpl>(
587 }),
588 allow_raw_pointers())
589 .class_function(
590 "_ShapeText",
592 std::string textStorage = jtext.as<std::string>();
593 const char*
text = textStorage.data();
594 size_t textCount = textStorage.size();
595
596 auto fc = sk_make_sp<para::FontCollection>();
598 fc->enableFontFallback();
599
601 {
602
603
608 }
609
611
612
613 size_t runCount = jruns["length"].as<size_t>();
614 for (
size_t i = 0;
i < runCount; ++
i) {
615 emscripten::val r = jruns[
i];
616
620
621 const size_t subTextCount = r["length"].as<size_t>();
622 if (subTextCount > textCount) {
623 return emscripten::val("block runs exceed text length!");
624 }
625
626 pb->pushStyle(style);
627 pb->addText(
text, subTextCount);
628 pb->pop();
629
630 text += subTextCount;
631 textCount -= subTextCount;
632 }
633 if (textCount != 0) {
634 return emscripten::val("Didn't have enough block runs to cover text");
635 }
636
637 auto pa = pb->Build();
639
640
641 {
644 }
646 }),
647 allow_raw_pointers())
649 .function("addText",
652 }))
655#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
656 auto [words, graphemeBreaks, lineBreaks] =
self.getClientICUData();
659 self.SetUnicode(clientICU);
660#endif
662 }), allow_raw_pointers())
669 }))
670
671
672
673
674 .function("_pushPaintStyle",
679 ts.setForegroundColor(foreground);
680 ts.setBackgroundColor(background);
682 }))
690 self.addPlaceholder(ps);
691 }))
692 .function("getText",
695 return emscripten::val(std::string(
text.data(),
text.size()).c_str());
696 }))
697 .function("_setWordsUtf8",
700#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
702#endif
703 }))
704 .function("_setWordsUtf16",
707#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
709#endif
710 }))
711 .function("_setGraphemeBreaksUtf8",
714#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
716#endif
717 }))
718 .function("_setGraphemeBreaksUtf16",
721#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
723#endif
724 }))
725 .function("_setLineBreaksUtf8",
728#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
730 std::vector<SkUnicode::LineBreakBefore> lineBreaks;
731 for (
size_t i = 0;
i < lineBreaksNum;
i += 2) {
732 auto pos = lineBreakData[
i];
733 auto breakType = lineBreakData[
i+1];
734 if (breakType == 0) {
736 } else {
738 }
739 }
740 self.setLineBreaksUtf8(std::move(lineBreaks));
741#endif
742 }))
743 .function("_setLineBreaksUtf16",
746#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
748 std::vector<SkUnicode::LineBreakBefore> lineBreaks;
749 for (
size_t i = 0;
i < lineBreaksNum;
i += 2) {
750 auto pos = lineBreakData[
i];
751 auto breakType = lineBreakData[
i+1];
752 if (breakType == 0) {
754 } else {
756 }
757 }
758 self.setLineBreaksUtf16(std::move(lineBreaks));
759#endif
760 }));
761
762 class_<para::TypefaceFontProvider, base<SkFontMgr>>("TypefaceFontProvider")
765 return sk_make_sp<para::TypefaceFontProvider>();
766 }))
770 const char* fPtr = reinterpret_cast<const char*>(familyPtr);
772 self.registerTypeface(typeface,
fStr);
773 }), allow_raw_pointers());
774
775 class_<para::FontCollection>("FontCollection")
778 return sk_make_sp<para::FontCollection>();
779 }))
782 self.setDefaultFontManager(fontManager);
783 }), allow_raw_pointers())
785
786
787 value_object<para::PositionWithAffinity>("PositionWithAffinity")
790
791 value_object<SimpleFontStyle>("FontStyle")
795
796 value_object<SimpleParagraphStyle>("ParagraphStyle")
809
810 value_object<SimpleStrutStyle>("StrutStyle")
820
821 value_object<SimpleTextStyle>("TextStyle")
849
850
851
852
853 value_object<para::SkRange<size_t>>("URange")
856
857
862}
static sk_sp< SkFontMgr > RefEmpty()
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
void enableFontFallback()
static bool RequiresClientICU()
static std::unique_ptr< ParagraphBuilder > make(const ParagraphStyle &style, sk_sp< FontCollection > fontCollection, sk_sp< SkUnicode > unicode)
std::unique_ptr< Paragraph > Build() override
static std::unique_ptr< ParagraphBuilder > make(const ParagraphStyle &style, sk_sp< FontCollection > fontCollection, sk_sp< SkUnicode > unicode)
virtual SkRange< size_t > getWordBoundary(unsigned offset)=0
SkScalar getAlphabeticBaseline()
virtual int getLineNumberAt(TextIndex codeUnitIndex) const =0
virtual size_t lineNumber()=0
virtual PositionWithAffinity getGlyphPositionAtCoordinate(SkScalar dx, SkScalar dy)=0
SkScalar getMinIntrinsicWidth()
SkScalar getIdeographicBaseline()
virtual void layout(SkScalar width)=0
SkScalar getLongestLine()
SkScalar getMaxIntrinsicWidth()
void setTypeface(sk_sp< SkTypeface > typeface)
void setFontFamilies(std::vector< SkString > families)
void setFontSize(SkScalar size)
sk_sp< SkFontMgr > fontMgr
Dart_NativeFunction function
SKUNICODE_API sk_sp< SkUnicode > Make(SkSpan< char > text, std::vector< SkUnicode::Position > words, std::vector< SkUnicode::Position > graphemeBreaks, std::vector< SkUnicode::LineBreakBefore > lineBreaks)
PlaceholderAlignment
Where to vertically align the placeholder relative to the surrounding text.
JSArray UnresolvedCodepoints(para::Paragraph &self)
JSObject GetClosestGlyphInfoAtCoordinate(para::Paragraph &self, SkScalar dx, SkScalar dy)
JSArray GetLineMetrics(para::Paragraph &self)
para::TextStyle toTextStyle(const SimpleTextStyle &s)
JSObject GetLineMetricsAt(para::Paragraph &self, size_t lineNumber)
Float32Array GetRectsForRange(para::Paragraph &self, unsigned start, unsigned end, para::RectHeightStyle heightStyle, para::RectWidthStyle widthStyle)
JSArray GetShapedLines(para::Paragraph &self)
JSObject GetGlyphInfoAt(para::Paragraph &self, size_t index)
Float32Array GetRectsForPlaceholders(para::Paragraph &self)
para::ParagraphStyle toParagraphStyle(const SimpleParagraphStyle &s)
static sk_sp< SkUnicode > get_unicode()
std::vector< SkUnicode::Position > convertArrayU32(WASMPointerU32 array, size_t count)
SkFontStyle::Weight weight
SkScalar heightMultiplier
para::TextDirection textDirection
SimpleStrutStyle strutStyle
SimpleTextStyle textStyle
bool replaceTabCharacters
para::TextAlign textAlign
WASMPointerU8 ellipsisPtr
para::TextHeightBehavior textHeightBehavior
SimpleFontStyle fontStyle
SkScalar heightMultiplier
WASMPointerU32 fontFamiliesPtr
SkScalar decorationThickness
WASMPointerF32 fontVariationValuesPtr
WASMPointerF32 shadowOffsetsPtr
WASMPointerF32 fontFeatureNamesPtr
WASMPointerU8 fontFamiliesPtr
SkScalar heightMultiplier
WASMPointerF32 shadowBlurRadiiPtr
WASMPointerF32 decorationColorPtr
WASMPointerF32 backgroundColorPtr
WASMPointerF32 fontFeatureValuesPtr
WASMPointerF32 foregroundColorPtr
SimpleFontStyle fontStyle
WASMPointerF32 shadowColorsPtr
para::TextDecorationStyle decorationStyle
WASMPointerF32 fontVariationAxesPtr
void setTextStyle(const TextStyle &textStyle)