[CanvasKit] Support all TextHeightStyles (flutter/engine#25741)

This commit is contained in:
Harry Terkelsen 2021-04-26 18:19:01 -07:00 committed by GitHub
parent 58897e0896
commit 1685f4a977
2 changed files with 49 additions and 3 deletions

View File

@ -320,9 +320,12 @@ SkTextHeightBehavior toSkTextHeightBehavior(ui.TextHeightBehavior behavior) {
@JS()
class SkRectHeightStyleEnum {
// TODO(yjbanov): support all styles
external SkRectHeightStyle get Tight;
external SkRectHeightStyle get Max;
external SkRectHeightStyle get IncludeLineSpacingMiddle;
external SkRectHeightStyle get IncludeLineSpacingTop;
external SkRectHeightStyle get IncludeLineSpacingBottom;
external SkRectHeightStyle get Strut;
}
@JS()
@ -333,11 +336,14 @@ class SkRectHeightStyle {
final List<SkRectHeightStyle> _skRectHeightStyles = <SkRectHeightStyle>[
canvasKit.RectHeightStyle.Tight,
canvasKit.RectHeightStyle.Max,
canvasKit.RectHeightStyle.IncludeLineSpacingMiddle,
canvasKit.RectHeightStyle.IncludeLineSpacingTop,
canvasKit.RectHeightStyle.IncludeLineSpacingBottom,
canvasKit.RectHeightStyle.Strut,
];
SkRectHeightStyle toSkRectHeightStyle(ui.BoxHeightStyle style) {
final int index = style.index;
return _skRectHeightStyles[index < 2 ? index : 0];
return _skRectHeightStyles[style.index];
}
@JS()

View File

@ -1390,6 +1390,46 @@ void _paragraphTests() {
paragraph.delete();
});
test('RectHeightStyle', () {
SkParagraphStyleProperties props = SkParagraphStyleProperties();
props.heightMultiplier = 3;
props.textAlign = canvasKit.TextAlign.Start;
props.textDirection = canvasKit.TextDirection.LTR;
props.textStyle = SkTextStyleProperties()
..fontSize = 25
..fontFamilies = <String>['Roboto']
..fontStyle = (SkFontStyle()..weight = canvasKit.FontWeight.Normal);
props.strutStyle = SkStrutStyleProperties()
..strutEnabled = true
..forceStrutHeight = true
..fontSize = 25
..fontFamilies = <String>['Roboto']
..heightMultiplier = 3
..fontStyle = (SkFontStyle()..weight = canvasKit.FontWeight.Normal);
final SkParagraphStyle paragraphStyle = canvasKit.ParagraphStyle(props);
final SkParagraphBuilder builder =
canvasKit.ParagraphBuilder.MakeFromFontProvider(
paragraphStyle,
skiaFontCollection.fontProvider,
);
builder.addText('hello');
final SkParagraph paragraph = builder.build();
paragraph.layout(500);
expect(
paragraph.getRectsForRange(
0,
1,
canvasKit.RectHeightStyle.Strut,
canvasKit.RectWidthStyle.Tight,
),
[
[0, 0, 13.770000457763672, 75],
],
);
});
test('TextHeightBehavior', () {
expect(
toSkTextHeightBehavior(ui.TextHeightBehavior(