Unverified Commit 8cd892b3 authored by Gary Qian's avatar Gary Qian Committed by GitHub

Use alphabetic baselines for layout of InputDecorator (#44029)

parent 2110dfe0
......@@ -907,7 +907,13 @@ class _RenderDecoration extends RenderBox {
return 0.0;
}
box.layout(constraints, parentUsesSize: true);
final double baseline = box.getDistanceToBaseline(textBaseline);
// Since internally, all layout is performed against the alphabetic baseline,
// (eg, ascents/descents are all relative to alphabetic, even if the font is
// an ideographic or hanging font), we should always obtain the reference
// baseline from the alphabetic baseline. The ideographic baseline is for
// use post-layout and is derived from the alphabetic baseline combined with
// the font metrics.
final double baseline = box.getDistanceToBaseline(TextBaseline.alphabetic);
assert(baseline != null && baseline >= 0.0);
return baseline;
}
......
......@@ -3551,4 +3551,47 @@ void main() {
'alignLabelWithHint: true',
]);
});
testWidgets('uses alphabetic baseline for CJK layout', (WidgetTester tester) async {
await tester.binding.setLocale('zh', 'CN');
final Typography typography = Typography();
final FocusNode focusNode = FocusNode();
final TextEditingController controller = TextEditingController();
// The dense theme uses ideographic baselines
Widget buildFrame(bool alignLabelWithHint) {
return MaterialApp(
theme: ThemeData(
textTheme: typography.dense,
),
home: Material(
child: Directionality(
textDirection: TextDirection.ltr,
child: TextField(
controller: controller,
focusNode: focusNode,
decoration: InputDecoration(
labelText: 'label',
alignLabelWithHint: alignLabelWithHint,
hintText: 'hint',
hintStyle: const TextStyle(
fontFamily: 'Cough',
),
),
),
),
),
);
}
await tester.pumpWidget(buildFrame(true));
await tester.pumpAndSettle();
// These numbers should be the values from using alphabetic baselines:
// Ideographic (incorrect) value is 31.299999713897705
expect(tester.getTopLeft(find.text('hint')).dy, 28.75);
// Ideographic (incorrect) value is 50.299999713897705
expect(tester.getBottomLeft(find.text('hint')).dy, 47.75);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment