createTextStyle static method

TextStyle createTextStyle(
  1. CSSRenderStyle renderStyle, {
  2. double? height,
  3. Color? color,
})

Implementation

static TextStyle createTextStyle(CSSRenderStyle renderStyle, {double? height, Color? color}) {
  // Creates a new TextStyle object.
  //   color: The color to use when painting the text. If this is specified, foreground must be null.
  //   decoration: The decorations to paint near the text (e.g., an underline).
  //   decorationColor: The color in which to paint the text decorations.
  //   decorationStyle: The style in which to paint the text decorations (e.g., dashed).
  //   fontWeight: The typeface thickness to use when painting the text (e.g., bold).
  //   fontStyle: The typeface variant to use when drawing the letters (e.g., italics).
  //   fontSize: The size of glyphs (in logical pixels) to use when painting the text.
  //   letterSpacing: The amount of space (in logical pixels) to add between each letter.
  //   wordSpacing: The amount of space (in logical pixels) to add at each sequence of white-space (i.e. between /// each word).
  //   textBaseline: The common baseline that should be aligned between this text span and its parent text span, /// or, for the root text spans, with the line box.
  //   height: The height of this text span, as a multiple of the font size.
  //   locale: The locale used to select region-specific glyphs.
  //   background: The paint drawn as a background for the text.
  //   foreground: The paint used to draw the text. If this is specified, color must be null.
  // Respect visibility:hidden: do not paint text or its decorations but keep layout.
  final bool hidden = renderStyle.isVisibilityHidden;
  final Color? effectiveColor = hidden
      ? const Color(0x00000000)
      : (renderStyle.backgroundClip != CSSBackgroundBoundary.text ? color ?? renderStyle.color.value : null);

  TextStyle textStyle = TextStyle(
      color: effectiveColor,
      decoration: hidden ? TextDecoration.none : renderStyle.textDecorationLine,
      decorationColor: hidden ? const Color(0x00000000) : renderStyle.textDecorationColor?.value,
      decorationStyle: renderStyle.textDecorationStyle,
      fontWeight: renderStyle.fontWeight,
      fontStyle: renderStyle.fontStyle,
      fontFamily: (renderStyle.fontFamily != null && renderStyle.fontFamily!.isNotEmpty)
          ? renderStyle.fontFamily!.first
          : null,
      fontFamilyFallback: renderStyle.fontFamily,
      fontSize: renderStyle.fontSize.computedValue,
      letterSpacing: renderStyle.letterSpacing?.computedValue,
      wordSpacing: renderStyle.wordSpacing?.computedValue,
      shadows: renderStyle.textShadow,
      textBaseline: CSSText.getTextBaseLine(),
      package: CSSText.getFontPackage(),
      locale: CSSText.getLocale(),
      background: CSSText.getBackground(),
      foreground: CSSText.getForeground(),
      height: height);
  return textStyle;
}