55 CanvasKit ,
66 Paragraph ,
77 PathCommand ,
8+ PositionWithAffinity ,
89 PosTan ,
910 ShapedText ,
1011 SkAnimatedImage ,
@@ -31,6 +32,7 @@ import {
3132 SkVertices ,
3233 TonalColorsOutput ,
3334 TypedArray ,
35+ URange ,
3436 Vector3 ,
3537 VectorN ,
3638} from "canvaskit-wasm" ;
@@ -51,6 +53,8 @@ CanvasKitInit({locateFile: (file: string) => '/node_modules/canvaskit/bin/' + fi
5153 maskFilterTests ( CK ) ;
5254 matrixTests ( CK ) ;
5355 paintTests ( CK ) ;
56+ paragraphBuilderTests ( CK ) ;
57+ paragraphTests ( CK ) ;
5458 pathEffectTests ( CK ) ;
5559 pathTests ( CK ) ;
5660 pictureTests ( CK ) ;
@@ -445,6 +449,72 @@ function pathTests(CK: CanvasKit) {
445449 path . trim ( 0.1 , 0.7 , false ) ;
446450}
447451
452+ function paragraphTests ( CK : CanvasKit , p ?: Paragraph ) {
453+ if ( ! p ) return ;
454+ const a = p . didExceedMaxLines ( ) ; // $ExpectType boolean
455+ const b = p . getAlphabeticBaseline ( ) ; // $ExpectType number
456+ const c = p . getGlyphPositionAtCoordinate ( 10 , 3 ) ; // $ExpectType PositionWithAffinity
457+ const d = p . getHeight ( ) ; // $ExpectType number
458+ const e = p . getIdeographicBaseline ( ) ; // $ExpectType number
459+ const f = p . getLongestLine ( ) ; // $ExpectType number
460+ const g = p . getMaxIntrinsicWidth ( ) ; // $ExpectType number
461+ const h = p . getMaxWidth ( ) ; // $ExpectType number
462+ const i = p . getMinIntrinsicWidth ( ) ; // $ExpectType number
463+ const j = p . getRectsForPlaceholders ( ) ; // $ExpectType Float32Array
464+ const k = p . getRectsForRange ( 2 , 10 , CK . RectHeightStyle . Max , // $ExpectType Float32Array
465+ CK . RectWidthStyle . Tight ) ;
466+ const l = p . getWordBoundary ( 10 ) ; // $ExpectType URange
467+ p . layout ( 300 ) ;
468+ }
469+
470+ function paragraphBuilderTests ( CK : CanvasKit , fontMgr ?: SkFontMgr , paint ?: SkPaint ) {
471+ if ( ! fontMgr || ! paint ) return ;
472+ const paraStyle = new CK . ParagraphStyle ( { // $ExpectType ParagraphStyle
473+ textStyle : {
474+ color : CK . BLACK ,
475+ fontFamilies : [ 'Noto Serif' ] ,
476+ fontSize : 20 ,
477+ } ,
478+ textAlign : CK . TextAlign . Center ,
479+ maxLines : 8 ,
480+ ellipsis : '.._.' ,
481+ strutStyle : {
482+ strutEnabled : true ,
483+ fontFamilies : [ 'Roboto' ] ,
484+ fontSize : 28 ,
485+ heightMultiplier : 1.5 ,
486+ forceStrutHeight : true ,
487+ } ,
488+ } ) ;
489+ const blueText = new CK . TextStyle ( { // $ExpectType TextStyle
490+ backgroundColor : CK . Color ( 234 , 208 , 232 ) , // light pink
491+ color : CK . Color ( 48 , 37 , 199 ) ,
492+ fontFamilies : [ 'Noto Serif' ] ,
493+ decoration : CK . LineThroughDecoration ,
494+ decorationThickness : 1.5 , // multiplier based on font size
495+ fontSize : 24 ,
496+ fontFeatures : [ { name : 'smcp' , value : 1 } ] ,
497+ shadows : [ { color : CK . BLACK , blurRadius : 15 } ,
498+ { color : CK . RED , blurRadius : 5 , offset : [ 10 , 10 ] } ] ,
499+ } ) ;
500+
501+ const builder = CK . ParagraphBuilder . Make ( paraStyle , fontMgr ) ; // $ExpectType ParagraphBuilder
502+
503+ builder . pushStyle ( blueText ) ;
504+ builder . addText ( 'VAVAVAVAVAVAVA\nVAVA\n' ) ;
505+ builder . pop ( ) ;
506+ const paragraph = builder . build ( ) ; // $ExpectType Paragraph
507+
508+ const buf = new ArrayBuffer ( 10 ) ;
509+ const fontSrc = CK . TypefaceFontProvider . Make ( ) ; // $ExpectType TypefaceFontProvider
510+ fontSrc . registerFont ( buf , 'sans-serif' ) ;
511+ const builder2 = CK . ParagraphBuilder . MakeFromFontProvider ( // $ExpectType ParagraphBuilder
512+ paraStyle , fontSrc ) ;
513+ builder2 . pushPaintStyle ( blueText , paint , paint ) ;
514+ builder2 . addPlaceholder ( ) ;
515+ builder2 . addPlaceholder ( 10 , 20 , CK . PlaceholderAlignment . Top , CK . TextBaseline . Ideographic , 3 ) ;
516+ }
517+
448518function pathEffectTests ( CK : CanvasKit ) {
449519 const pe1 = CK . SkPathEffect . MakeCorner ( 2 ) ; // $ExpectType SkPathEffect | null
450520 const pe2 = CK . SkPathEffect . MakeDash ( [ 2 , 4 ] ) ; // $ExpectType SkPathEffect
0 commit comments