From 49bcd4b5c613ec0c748a222e570873feb2a340b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boluwatif=E1=BA=B9?= Date: Thu, 13 Jan 2022 19:49:44 +0100 Subject: [PATCH] Added support for "rem" units (#647) * Added tests for "support for rem units" * Added support for "rem" units --- lib/src/utilities/numbers.dart | 11 +++++++---- test/svg_parsers_test.dart | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/src/utilities/numbers.dart b/lib/src/utilities/numbers.dart index 9d88071a..077554f3 100644 --- a/lib/src/utilities/numbers.dart +++ b/lib/src/utilities/numbers.dart @@ -11,6 +11,7 @@ double? parseDouble(String? rawDouble, {bool tryParse = false}) { } rawDouble = rawDouble + .replaceFirst('rem', '') .replaceFirst('em', '') .replaceFirst('ex', '') .replaceFirst('px', '') @@ -46,12 +47,14 @@ double? parseDoubleWithUnits( }) { double unit = 1.0; + // 1 rem unit is equal to the root font size. // 1 em unit is equal to the current font size. - if (rawDouble?.contains('em') ?? false) { - unit = fontSize; - } // 1 ex unit is equal to the current x-height. - else if (rawDouble?.contains('ex') ?? false) { + if (rawDouble?.contains('rem') ?? false) { + unit = fontSize; + } else if (rawDouble?.contains('em') ?? false) { + unit = fontSize; + } else if (rawDouble?.contains('ex') ?? false) { unit = xHeight; } diff --git a/test/svg_parsers_test.dart b/test/svg_parsers_test.dart index 2e2dd4c8..b581df22 100644 --- a/test/svg_parsers_test.dart +++ b/test/svg_parsers_test.dart @@ -213,6 +213,16 @@ void main() { parseFontSize(' 2em ', fontSize: fontSize, xHeight: xHeight), equals(2 * fontSize), ); + + expect( + parseFontSize('4rem', fontSize: fontSize, xHeight: xHeight), + equals(4 * fontSize), + ); + + expect( + parseFontSize(' 2rem ', fontSize: fontSize, xHeight: xHeight), + equals(2 * fontSize), + ); expect( parseFontSize('4ex', fontSize: fontSize, xHeight: xHeight),