FontSelectionValueInlines.h [plain text]
#pragma once
#include "CSSValueKeywords.h"
#include "FontSelectionAlgorithm.h"
namespace WebCore {
inline bool isCSS21Weight(FontSelectionValue weight)
{
return weight == FontSelectionValue(100)
|| weight == FontSelectionValue(200)
|| weight == FontSelectionValue(300)
|| weight == FontSelectionValue(400)
|| weight == FontSelectionValue(500)
|| weight == FontSelectionValue(600)
|| weight == FontSelectionValue(700)
|| weight == FontSelectionValue(800)
|| weight == FontSelectionValue(900);
}
inline bool isCSS21Weight(int weight)
{
return !((weight % 100) || weight < 100 || weight > 900);
}
inline std::optional<CSSValueID> fontWeightKeyword(FontSelectionValue weight)
{
if (weight == normalWeightValue())
return CSSValueNormal;
if (weight == boldWeightValue())
return CSSValueBold;
return std::nullopt;
}
inline std::optional<FontSelectionValue> fontWeightValue(CSSValueID value)
{
switch (value) {
case CSSValueNormal:
return normalWeightValue();
case CSSValueBold:
case CSSValueBolder:
return boldWeightValue();
case CSSValueLighter:
return lightWeightValue();
default:
return std::nullopt;
}
}
inline std::optional<CSSValueID> fontStretchKeyword(FontSelectionValue stretch)
{
if (stretch == ultraCondensedStretchValue())
return CSSValueUltraCondensed;
if (stretch == extraCondensedStretchValue())
return CSSValueExtraCondensed;
if (stretch == condensedStretchValue())
return CSSValueCondensed;
if (stretch == semiCondensedStretchValue())
return CSSValueSemiCondensed;
if (stretch == normalStretchValue())
return CSSValueNormal;
if (stretch == semiExpandedStretchValue())
return CSSValueSemiExpanded;
if (stretch == expandedStretchValue())
return CSSValueExpanded;
if (stretch == extraExpandedStretchValue())
return CSSValueExtraExpanded;
if (stretch == ultraExpandedStretchValue())
return CSSValueUltraExpanded;
return std::nullopt;
}
inline std::optional<FontSelectionValue> fontStretchValue(CSSValueID value)
{
switch (value) {
case CSSValueUltraCondensed:
return ultraCondensedStretchValue();
case CSSValueExtraCondensed:
return extraCondensedStretchValue();
case CSSValueCondensed:
return condensedStretchValue();
case CSSValueSemiCondensed:
return semiCondensedStretchValue();
case CSSValueNormal:
return normalStretchValue();
case CSSValueSemiExpanded:
return semiExpandedStretchValue();
case CSSValueExpanded:
return expandedStretchValue();
case CSSValueExtraExpanded:
return extraExpandedStretchValue();
case CSSValueUltraExpanded:
return ultraExpandedStretchValue();
default:
return std::nullopt;
}
}
inline std::optional<CSSValueID> fontStyleKeyword(FontSelectionValue style, FontStyleAxis axis)
{
if (style == normalItalicValue())
return CSSValueNormal;
if (style == italicValue())
return axis == FontStyleAxis::ital ? CSSValueItalic : CSSValueOblique;
return std::nullopt;
}
inline std::optional<FontSelectionValue> fontStyleValue(CSSValueID value)
{
switch (value) {
case CSSValueNormal:
return normalItalicValue();
case CSSValueOblique:
case CSSValueItalic:
return italicValue();
default:
return std::nullopt;
}
}
}