11import 'package:flutter/material.dart' ;
2+ import 'package:flutter_html/src/css_parser.dart' ;
23import 'package:flutter_html/style.dart' ;
34import 'package:html/dom.dart' as dom;
45//TODO(Sub6Resources): don't use the internal code of the html package as it may change unexpectedly.
@@ -179,6 +180,17 @@ StyledElement parseStyledElement(
179180 display: Display .BLOCK ,
180181 );
181182 break ;
183+ case "font" :
184+ styledElement.style = Style (
185+ color: element.attributes['color' ] != null ?
186+ element.attributes['color' ]! .startsWith ("#" ) ?
187+ ExpressionMapping .stringToColor (element.attributes['color' ]! ) :
188+ ExpressionMapping .namedColorToColor (element.attributes['color' ]! ) :
189+ null ,
190+ fontFamily: element.attributes['face' ]? .split ("," ).first,
191+ fontSize: numberToFontSize (element.attributes['size' ] ?? '' ),
192+ );
193+ break ;
182194 case "h1" :
183195 styledElement.style = Style (
184196 fontSize: FontSize .xxLarge,
@@ -368,3 +380,31 @@ StyledElement parseStyledElement(
368380}
369381
370382typedef ListCharacter = String Function (int i);
383+
384+ FontSize numberToFontSize (String num ) {
385+ switch (num ) {
386+ case "1" :
387+ return FontSize .xxSmall;
388+ case "2" :
389+ return FontSize .xSmall;
390+ case "3" :
391+ return FontSize .small;
392+ case "4" :
393+ return FontSize .medium;
394+ case "5" :
395+ return FontSize .large;
396+ case "6" :
397+ return FontSize .xLarge;
398+ case "7" :
399+ return FontSize .xxLarge;
400+ }
401+ if (num .startsWith ("+" )) {
402+ final relativeNum = double .tryParse (num .substring (1 )) ?? 0 ;
403+ return numberToFontSize ((3 + relativeNum).toString ());
404+ }
405+ if (num .startsWith ("-" )) {
406+ final relativeNum = double .tryParse (num .substring (1 )) ?? 0 ;
407+ return numberToFontSize ((3 - relativeNum).toString ());
408+ }
409+ return FontSize .medium;
410+ }
0 commit comments