Table of Contents

Method GetTextFontWeight

Namespace
SharpVectors.Renderers.Texts
Assembly
SharpVectors.Rendering.Wpf.dll

GetTextFontWeight(string)

Resolves a CSS font-weight string to a WPF FontWeight.

protected FontWeight GetTextFontWeight(string fontWeight)

Parameters

fontWeight string

A CSS font-weight string (e.g., "bold", "700", "650").

Returns

FontWeight

A WPF FontWeight corresponding to the input; defaults to Normal if parsing fails.

Remarks

Supported Input Formats:

  • CSS Keywords: "normal", "bold"
  • Numeric Values: "100", "200", ..., "900", "950"
  • Non-standard Numeric: Any integer; rounded to nearest standard weight via MapNumericFontWeightToStandard(int).
  • Null/Empty: Defaults to "normal" (400).

Non-Standard Numeric Behavior:

When a numeric font-weight is provided that does not correspond to a standard CSS weight (e.g., 650, 475, 550), the value is rounded to the nearest standard weight. This ensures compatibility with WPF's standard FontWeight values while preserving the user's intent. See MapNumericFontWeightToStandard(int) for detailed rounding examples.

GetTextFontWeight(SvgTextContentElement)

Resolves the font-weight property of an SVG text element, with support for relative keywords and parent-relative adjustments.

protected FontWeight GetTextFontWeight(SvgTextContentElement element)

Parameters

element SvgTextContentElement

The SVG text element from which to extract the font-weight property.

Returns

FontWeight

The resolved FontWeight; defaults to Normal if no value is specified or parsing fails.

Remarks

Priority Order:

  1. Direct CSS keywords: "normal", "bold"
  2. Direct numeric values: "100"–"950"
  3. Relative keywords with parent lookup: "bolder", "lighter"
  4. Fallback: "normal" (400) if no valid value is found

Relative Keywords:

  • "bolder": Looks up the parent element's font-weight and applies one step heavier (via GetBolderFontWeight(string)). If no parent or parent weight unavailable, defaults to ExtraBold (800).
  • "lighter": Looks up the parent element's font-weight and applies one step lighter (via GetLighterFontWeight(string)). If no parent or parent weight unavailable, defaults to Light (300).

Non-Standard Numeric Handling:

Non-standard numeric values are automatically rounded via MapNumericFontWeightToStandard(int). This ensures smooth rendering across both CSS and WPF specifications.