Use DPI=96 + add absolute and relative sizes + add missing value units

This commit is contained in:
Artem Pavlenko 2021-04-12 14:16:39 +01:00
parent 4f783f61ed
commit ff8c411749

View file

@ -33,18 +33,45 @@ namespace x3 = boost::spirit::x3;
// units // units
struct css_unit_value : x3::symbols<double> struct css_unit_value : x3::symbols<double>
{ {
const double DPI = 90; constexpr static double DPI = 96;
css_unit_value() css_unit_value()
{ {
add add
("px", 1.0) ("px", 1.0) // pixels
("pt", DPI/72.0) ("pt", DPI/72.0) // points
("pc", DPI/6.0) ("pc", DPI/6.0) // picas
("mm", DPI/25.4) ("mm", DPI/25.4) // milimeters
("cm", DPI/2.54) ("Q" , DPI/101.6)// quarter-milimeters
("in", static_cast<double>(DPI)) ("cm", DPI/2.54) // centimeters
//("em", 1.0/16.0) // default pixel size for body (usually 16px) ("in", static_cast<double>(DPI)) // inches
// ^^ this doesn't work currently as 'e' in 'em' interpreted as part of scientific notation. ;
}
};
struct css_absolute_size : x3::symbols<double>
{
constexpr static double EM = 10.0; // 1em == 10px
css_absolute_size()
{
add
("xx-small", 0.6 * EM)
("x-small", 0.75 * EM)
("small", 0.88 * EM)
("medium", 1.0 * EM)
("large", 1.2 * EM)
("x-large", 1.5 * EM)
("xx-large", 2.0 * EM)
;
}
};
struct css_relative_size : x3::symbols<double>
{
css_relative_size()
{
add
("larger", 1.2)
("smaller", 0.8)
; ;
} }
}; };