Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions lib/src/styled_element.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_html/src/css_parser.dart';
import 'package:flutter_html/style.dart';
import 'package:html/dom.dart' as dom;
//TODO(Sub6Resources): don't use the internal code of the html package as it may change unexpectedly.
Expand Down Expand Up @@ -179,6 +180,17 @@ StyledElement parseStyledElement(
display: Display.BLOCK,
);
break;
case "font":
styledElement.style = Style(
color: element.attributes['color'] != null ?
element.attributes['color']!.startsWith("#") ?
ExpressionMapping.stringToColor(element.attributes['color']!) :
ExpressionMapping.namedColorToColor(element.attributes['color']!) :
null,
fontFamily: element.attributes['face']?.split(",").first,
fontSize: numberToFontSize(element.attributes['size'] ?? ''),
);
break;
case "h1":
styledElement.style = Style(
fontSize: FontSize.xxLarge,
Expand Down Expand Up @@ -368,3 +380,31 @@ StyledElement parseStyledElement(
}

typedef ListCharacter = String Function(int i);

FontSize numberToFontSize(String num) {
switch (num) {
case "1":
return FontSize.xxSmall;
case "2":
return FontSize.xSmall;
case "3":
return FontSize.small;
case "4":
return FontSize.medium;
case "5":
return FontSize.large;
case "6":
return FontSize.xLarge;
case "7":
return FontSize.xxLarge;
}
if (num.startsWith("+")) {
final relativeNum = double.tryParse(num.substring(1)) ?? 0;
return numberToFontSize((3 + relativeNum).toString());
}
if (num.startsWith("-")) {
final relativeNum = double.tryParse(num.substring(1)) ?? 0;
return numberToFontSize((3 - relativeNum).toString());
}
return FontSize.medium;
}