未验证 提交 5ec4dd8f 编写于 作者: H Harry Terkelsen 提交者: GitHub

[CanvasKit] Support all TextHeightStyles (#25741)

上级 0bc55490
......@@ -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()
......
......@@ -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(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册