mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Add font-size absolute size keywords. Fix #3417.
Relative size keywords are still missing: https://github.com/servo/servo/issues/3423
This commit is contained in:
parent
010d87b93e
commit
4e71b215b8
7 changed files with 47 additions and 49 deletions
|
@ -904,8 +904,9 @@ pub mod longhands {
|
|||
use super::super::Au;
|
||||
pub type T = Au;
|
||||
}
|
||||
static MEDIUM_PX: int = 16;
|
||||
#[inline] pub fn get_initial_value() -> computed_value::T {
|
||||
Au::from_px(16) // medium
|
||||
Au::from_px(MEDIUM_PX)
|
||||
}
|
||||
#[inline]
|
||||
pub fn to_computed_value(_value: SpecifiedValue, context: &computed::Context)
|
||||
|
@ -913,16 +914,26 @@ pub mod longhands {
|
|||
// We already computed this element's font size; no need to compute it again.
|
||||
return context.font_size
|
||||
}
|
||||
/// <length> | <percentage>
|
||||
/// TODO: support <absolute-size> and <relative-size>
|
||||
/// <length> | <percentage> | <absolute-size>
|
||||
/// TODO: support <relative-size>
|
||||
pub fn from_component_value(input: &ComponentValue, _base_url: &Url)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
specified::LengthOrPercentage::parse_non_negative(input).map(|value| {
|
||||
match value {
|
||||
specified::LP_Length(value) => value,
|
||||
specified::LP_Percentage(value) => specified::Em(value),
|
||||
}
|
||||
})
|
||||
match specified::LengthOrPercentage::parse_non_negative(input) {
|
||||
Ok(specified::LP_Length(value)) => return Ok(value),
|
||||
Ok(specified::LP_Percentage(value)) => return Ok(specified::Em(value)),
|
||||
Err(()) => (),
|
||||
}
|
||||
let au = match try!(get_ident_lower(input)).as_slice() {
|
||||
"xx-small" => Au::from_px(MEDIUM_PX) * 3 / 5,
|
||||
"x-small" => Au::from_px(MEDIUM_PX) * 3 / 4,
|
||||
"small" => Au::from_px(MEDIUM_PX) * 8 / 9,
|
||||
"medium" => Au::from_px(MEDIUM_PX),
|
||||
"large" => Au::from_px(MEDIUM_PX) * 6 / 5,
|
||||
"x-large" => Au::from_px(MEDIUM_PX) * 3 / 2,
|
||||
"xx-large" => Au::from_px(MEDIUM_PX) * 2,
|
||||
_ => return Err(())
|
||||
};
|
||||
Ok(specified::Au_(au))
|
||||
}
|
||||
</%self:single_component_value>
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
== text_decoration_cached.html text_decoration_cached_ref.html
|
||||
# text_decoration_propagation_a.html text_decoration_propagation_b.html
|
||||
# inline_text_align_a.html inline_text_align_b.html
|
||||
== font_size_em.html font_size_em_ref.html
|
||||
== font_size_percentage.html font_size_em_ref.html
|
||||
== font_size.html font_size_ref.html
|
||||
== img_size_a.html img_size_b.html
|
||||
== img_dynamic_remove.html img_dynamic_remove_ref.html
|
||||
== upper_id_attr.html upper_id_attr_ref.html
|
||||
|
|
13
tests/ref/font_size.html
Normal file
13
tests/ref/font_size.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<title>font-size (issues #1435, #3417)</title>
|
||||
<body style="font-size: 20px">
|
||||
<p style="font-size: 24pt">24pt is 32px.
|
||||
<p style="font-size: 2em">2em is 40px.
|
||||
<p style="font-size: 200%">200% is 40px.
|
||||
<p style="font-size: xx-small">xx-small is 9.6px.
|
||||
<p style="font-size: x-small">x-small is 12px.
|
||||
<p style="font-size: small">small is 14.2222…px.
|
||||
<p style="font-size: medium">medium is 16px.
|
||||
<p style="font-size: large">large is 19.2px.
|
||||
<p style="font-size: x-large">x-large is 24px.
|
||||
<p style="font-size: xx-large">xx-large is 32px.
|
|
@ -1,13 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>font-size: 2em (Bug #1435)</title>
|
||||
<style type="text/css">
|
||||
body { font-size: 20px; }
|
||||
p { font-size: 2em; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>This text should be 40px high.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,12 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>font-size: 2em (Bug #1435)</title>
|
||||
<style type="text/css">
|
||||
p { font-size: 40px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>This text should be 40px high.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,13 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>font-size: 200% (Bug #1435)</title>
|
||||
<style type="text/css">
|
||||
body { font-size: 20px }
|
||||
p { font-size: 200%; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>This text should be 40px high.</p>
|
||||
</body>
|
||||
</html>
|
13
tests/ref/font_size_ref.html
Normal file
13
tests/ref/font_size_ref.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<title>font-size (issues #1435, #3417)</title>
|
||||
<body>
|
||||
<p style="font-size: 32px">24pt is 32px.
|
||||
<p style="font-size: 40px">2em is 40px.
|
||||
<p style="font-size: 40px">200% is 40px.
|
||||
<p style="font-size: 9.6px">xx-small is 9.6px.
|
||||
<p style="font-size: 12px">x-small is 12px.
|
||||
<p style="font-size: 14.2222222222222222222222222222px">small is 14.2222…px.
|
||||
<p style="font-size: 16px">medium is 16px.
|
||||
<p style="font-size: 19.2px">large is 19.2px.
|
||||
<p style="font-size: 24px">x-large is 24px.
|
||||
<p style="font-size: 32px">xx-large is 32px.
|
Loading…
Add table
Add a link
Reference in a new issue