[canvaskit] Implement TextHeightBehavior (flutter/engine#25734)
* Add TextHeightBehavior * Remove TODO * Update goldens lock * Update goldens_lock
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
repository: https://github.com/flutter/goldens.git
|
||||
revision: 449cb88e9ffed446e4e7df9beb73814e5fb11ead
|
||||
revision: 8d866a84b7ceb67412ce6767ea0c1eec2eb3fa3f
|
||||
|
||||
@@ -42,6 +42,7 @@ class CanvasKit {
|
||||
external SkRectWidthStyleEnum get RectWidthStyle;
|
||||
external SkAffinityEnum get Affinity;
|
||||
external SkTextAlignEnum get TextAlign;
|
||||
external SkTextHeightBehaviorEnum get TextHeightBehavior;
|
||||
external SkTextDirectionEnum get TextDirection;
|
||||
external SkFontWeightEnum get FontWeight;
|
||||
external SkFontSlantEnum get FontSlant;
|
||||
@@ -290,6 +291,33 @@ SkTextAlign toSkTextAlign(ui.TextAlign align) {
|
||||
return _skTextAligns[align.index];
|
||||
}
|
||||
|
||||
@JS()
|
||||
class SkTextHeightBehaviorEnum {
|
||||
external SkTextHeightBehavior get All;
|
||||
external SkTextHeightBehavior get DisableFirstAscent;
|
||||
external SkTextHeightBehavior get DisableLastDescent;
|
||||
external SkTextHeightBehavior get DisableAll;
|
||||
}
|
||||
|
||||
@JS()
|
||||
class SkTextHeightBehavior {
|
||||
external int get value;
|
||||
}
|
||||
|
||||
final List<SkTextHeightBehavior> _skTextHeightBehaviors =
|
||||
<SkTextHeightBehavior>[
|
||||
canvasKit.TextHeightBehavior.All,
|
||||
canvasKit.TextHeightBehavior.DisableFirstAscent,
|
||||
canvasKit.TextHeightBehavior.DisableLastDescent,
|
||||
canvasKit.TextHeightBehavior.DisableAll,
|
||||
];
|
||||
|
||||
SkTextHeightBehavior toSkTextHeightBehavior(ui.TextHeightBehavior behavior) {
|
||||
int index = (behavior.applyHeightToFirstAscent ? 0 : 1 << 0) |
|
||||
(behavior.applyHeightToLastDescent ? 0 : 1 << 1);
|
||||
return _skTextHeightBehaviors[index];
|
||||
}
|
||||
|
||||
@JS()
|
||||
class SkRectHeightStyleEnum {
|
||||
// TODO(yjbanov): support all styles
|
||||
@@ -1531,7 +1559,7 @@ class SkParagraphStyleProperties {
|
||||
external set textAlign(SkTextAlign? value);
|
||||
external set textDirection(SkTextDirection? value);
|
||||
external set heightMultiplier(double? value);
|
||||
external set textHeightBehavior(int? value);
|
||||
external set textHeightBehavior(SkTextHeightBehavior? value);
|
||||
external set maxLines(int? value);
|
||||
external set ellipsis(String? value);
|
||||
external set textStyle(SkTextStyleProperties? value);
|
||||
|
||||
@@ -139,8 +139,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
|
||||
|
||||
if (textHeightBehavior != null) {
|
||||
properties.textHeightBehavior =
|
||||
(textHeightBehavior.applyHeightToFirstAscent ? 0 : 1 << 0) |
|
||||
(textHeightBehavior.applyHeightToLastDescent ? 0 : 1 << 1);
|
||||
toSkTextHeightBehavior(textHeightBehavior);
|
||||
}
|
||||
|
||||
if (ellipsis != null) {
|
||||
@@ -151,8 +150,8 @@ class CkParagraphStyle implements ui.ParagraphStyle {
|
||||
properties.strutStyle = toSkStrutStyleProperties(strutStyle);
|
||||
}
|
||||
|
||||
properties.textStyle =
|
||||
toSkTextStyleProperties(fontFamily, fontSize, height, fontWeight, fontStyle);
|
||||
properties.textStyle = toSkTextStyleProperties(
|
||||
fontFamily, fontSize, height, fontWeight, fontStyle);
|
||||
|
||||
return canvasKit.ParagraphStyle(properties);
|
||||
}
|
||||
|
||||
@@ -262,8 +262,6 @@ void testMain() {
|
||||
await testTextStyle('paragraph height', layoutWidth: 50, paragraphHeight: 1.5);
|
||||
});
|
||||
|
||||
// TODO(yjbanov): paragraphTextHeightBehavior seems to have no effect. Unsure how to use it.
|
||||
// https://github.com/flutter/flutter/issues/74337
|
||||
test('text styles - paragraph text height behavior', () async {
|
||||
await testTextStyle('paragraph text height behavior', layoutWidth: 50, paragraphHeight: 1.5, paragraphTextHeightBehavior: ui.TextHeightBehavior(
|
||||
applyHeightToFirstAscent: false,
|
||||
|
||||
@@ -996,7 +996,7 @@ void _canvasTests() {
|
||||
|
||||
test('drawImageCubic', () {
|
||||
final SkAnimatedImage image =
|
||||
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage);
|
||||
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage);
|
||||
canvas.drawImageCubic(
|
||||
image.getCurrentFrame(),
|
||||
10,
|
||||
@@ -1009,7 +1009,7 @@ void _canvasTests() {
|
||||
|
||||
test('drawImageRectOptions', () {
|
||||
final SkAnimatedImage image =
|
||||
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage);
|
||||
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage);
|
||||
canvas.drawImageRectOptions(
|
||||
image.getCurrentFrame(),
|
||||
Float32List.fromList([0, 0, 1, 1]),
|
||||
@@ -1022,7 +1022,7 @@ void _canvasTests() {
|
||||
|
||||
test('drawImageRectCubic', () {
|
||||
final SkAnimatedImage image =
|
||||
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage);
|
||||
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage);
|
||||
canvas.drawImageRectCubic(
|
||||
image.getCurrentFrame(),
|
||||
Float32List.fromList([0, 0, 1, 1]),
|
||||
@@ -1273,7 +1273,7 @@ void _paragraphTests() {
|
||||
props.textAlign = canvasKit.TextAlign.Center;
|
||||
props.textDirection = canvasKit.TextDirection.RTL;
|
||||
props.heightMultiplier = 3;
|
||||
props.textHeightBehavior = 0;
|
||||
props.textHeightBehavior = canvasKit.TextHeightBehavior.All;
|
||||
props.maxLines = 4;
|
||||
props.ellipsis = '___';
|
||||
props.textStyle = SkTextStyleProperties()
|
||||
@@ -1389,4 +1389,35 @@ void _paragraphTests() {
|
||||
|
||||
paragraph.delete();
|
||||
});
|
||||
|
||||
test('TextHeightBehavior', () {
|
||||
expect(
|
||||
toSkTextHeightBehavior(ui.TextHeightBehavior(
|
||||
applyHeightToFirstAscent: true,
|
||||
applyHeightToLastDescent: true,
|
||||
)),
|
||||
canvasKit.TextHeightBehavior.All,
|
||||
);
|
||||
expect(
|
||||
toSkTextHeightBehavior(ui.TextHeightBehavior(
|
||||
applyHeightToFirstAscent: false,
|
||||
applyHeightToLastDescent: true,
|
||||
)),
|
||||
canvasKit.TextHeightBehavior.DisableFirstAscent,
|
||||
);
|
||||
expect(
|
||||
toSkTextHeightBehavior(ui.TextHeightBehavior(
|
||||
applyHeightToFirstAscent: true,
|
||||
applyHeightToLastDescent: false,
|
||||
)),
|
||||
canvasKit.TextHeightBehavior.DisableLastDescent,
|
||||
);
|
||||
expect(
|
||||
toSkTextHeightBehavior(ui.TextHeightBehavior(
|
||||
applyHeightToFirstAscent: false,
|
||||
applyHeightToLastDescent: false,
|
||||
)),
|
||||
canvasKit.TextHeightBehavior.DisableAll,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user