getTextStyle static method

TextStyle getTextStyle(
  1. Map<String, dynamic> props,
  2. ChantContext ctxt,
  3. double? resize
)

Computes the effective TextStyle for given CSS-ish styling props.

Implementation

static TextStyle getTextStyle(
  Map<String, dynamic> props,
  ChantContext ctxt,
  double? resize,
) {
  final fontSize = _parseCssFontSize(
    props['font-size'],
    props['base-font-size'],
  );
  final fontFamily = (props['font-family'] ?? props['base-font-family'])
      .toString()
      .split(RegExp(", ?"))
      .map((f) => f.replaceAll(RegExp(r"^'|'$"), ''))
      .toList();
  return TextStyle(
    color: _colorFromCss(props['fill'], ctxt.theme.textColor),
    fontFamilyFallback: fontFamily,
    fontSize: fontSize * (resize ?? 1),
    height: props['line-height'],
    fontStyle: props['font-style'] == 'italic'
        ? FontStyle.italic
        : FontStyle.normal,
    fontWeight: props['font-weight'] == 'bold'
        ? FontWeight.bold
        : FontWeight.normal,
    fontFeatures: [
      if (props['font-variant'] == 'small-caps') FontFeature.enable('smcp'),
    ],
  );
}