resolveFontSize static method
Implementation
static CSSLengthValue resolveFontSize(String fontSize, RenderStyle renderStyle, String propertyName) {
switch (fontSize) {
case 'xx-small':
return CSSLengthValue(3 / 5 * 16, CSSLengthType.PX);
case 'x-small':
return CSSLengthValue(3 / 4 * 16, CSSLengthType.PX);
case 'small':
return CSSLengthValue(8 / 9 * 16, CSSLengthType.PX);
case 'medium':
return CSSLengthValue(16, CSSLengthType.PX);
case 'large':
return CSSLengthValue(6 / 5 * 16, CSSLengthType.PX);
case 'x-large':
return CSSLengthValue(3 / 2 * 16, CSSLengthType.PX);
case 'xx-large':
return CSSLengthValue(2 / 1 * 16, CSSLengthType.PX);
case 'xxx-large':
return CSSLengthValue(3 / 1 * 16, CSSLengthType.PX);
case 'smaller':
return CSSLengthValue(5 / 6, CSSLengthType.EM, renderStyle, propertyName);
case 'larger':
return CSSLengthValue(6 / 5, CSSLengthType.EM, renderStyle, propertyName);
default:
// Parse lengths/percentages/functions (e.g., calc()).
final CSSLengthValue parsed = CSSLength.parseLength(fontSize, renderStyle, propertyName);
// If parsing failed, treat as invalid (ignore declaration).
if (identical(parsed, CSSLengthValue.unknown)) {
// Keep previous value unchanged (ignore invalid declaration).
return renderStyle.fontSize;
}
// Preserve calc() results (including negative) for computed style queries.
// Some integration tests expect negative computed values from calc() for font-size
// (e.g., calc(30% - 40px) relative to a 40px parent resolves to -28px).
// Return the parsed value directly; any layout-time handling can clamp if needed.
return parsed;
}
}