mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[CanvasKit] Support all TextHeightStyles (flutter/engine#25741)
This commit is contained in:
parent
58897e0896
commit
1685f4a977
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user