simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -152,22 +152,15 @@ class _PmRichTextState extends State<PmRichText> {
|
||||
|
||||
double? _fontSize(dynamic raw, double base) {
|
||||
if (raw is! String) return null;
|
||||
final match = RegExp(r'^(\d+(?:\.\d+)?)(px|rem|em|%)$').firstMatch(raw);
|
||||
if (match == null) return null;
|
||||
final value = double.parse(match.group(1)!);
|
||||
final double size;
|
||||
switch (match.group(2)) {
|
||||
case 'px':
|
||||
size = value;
|
||||
case 'rem':
|
||||
size = value * 16;
|
||||
case 'em':
|
||||
size = base * value;
|
||||
case '%':
|
||||
size = base * value / 100;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
final length = parsePmCssLength(raw);
|
||||
if (length == null) return null;
|
||||
final value = length.value;
|
||||
final size = switch (length.unit) {
|
||||
'px' => value,
|
||||
'rem' => value * 16,
|
||||
'em' => base * value,
|
||||
_ => base * value / 100,
|
||||
};
|
||||
return size.clamp(8, 72);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user