mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
auto merge of #723 : recrack/servo/add_cm, r=metajack
Related to https://github.com/mozilla-servo/rust-css/pull/28
This commit is contained in:
commit
488972e817
7 changed files with 80 additions and 27 deletions
|
@ -85,8 +85,8 @@ impl Au {
|
|||
Au(((*self as float) * factor) as i32)
|
||||
}
|
||||
|
||||
pub fn from_px(i: int) -> Au {
|
||||
NumCast::from(i * 60)
|
||||
pub fn from_px(px: int) -> Au {
|
||||
NumCast::from(px * 60)
|
||||
}
|
||||
|
||||
pub fn to_px(&self) -> int {
|
||||
|
@ -108,12 +108,12 @@ impl Au {
|
|||
Rect(Point2D(z, z), Size2D(z, z))
|
||||
}
|
||||
|
||||
pub fn from_pt(f: float) -> Au {
|
||||
from_px(pt_to_px(f) as int)
|
||||
pub fn from_pt(pt: float) -> Au {
|
||||
from_px(pt_to_px(pt) as int)
|
||||
}
|
||||
|
||||
pub fn from_frac_px(f: float) -> Au {
|
||||
Au((f * 60f) as i32)
|
||||
pub fn from_frac_px(px: float) -> Au {
|
||||
Au((px * 60f) as i32)
|
||||
}
|
||||
|
||||
pub fn min(x: Au, y: Au) -> Au { if *x < *y { x } else { y } }
|
||||
|
@ -121,13 +121,13 @@ impl Au {
|
|||
}
|
||||
|
||||
// assumes 72 points per inch, and 96 px per inch
|
||||
pub fn pt_to_px(f: float) -> float {
|
||||
f / 72f * 96f
|
||||
pub fn pt_to_px(pt: float) -> float {
|
||||
pt / 72f * 96f
|
||||
}
|
||||
|
||||
// assumes 72 points per inch, and 96 px per inch
|
||||
pub fn px_to_pt(f: float) -> float {
|
||||
f / 96f * 72f
|
||||
pub fn px_to_pt(px: float) -> float {
|
||||
px / 96f * 72f
|
||||
}
|
||||
|
||||
pub fn zero_rect() -> Rect<Au> {
|
||||
|
@ -143,12 +143,12 @@ pub fn zero_size() -> Size2D<Au> {
|
|||
Size2D(Au(0), Au(0))
|
||||
}
|
||||
|
||||
pub fn from_frac_px(f: float) -> Au {
|
||||
Au((f * 60f) as i32)
|
||||
pub fn from_frac_px(px: float) -> Au {
|
||||
Au((px * 60f) as i32)
|
||||
}
|
||||
|
||||
pub fn from_px(i: int) -> Au {
|
||||
NumCast::from(i * 60)
|
||||
pub fn from_px(px: int) -> Au {
|
||||
NumCast::from(px * 60)
|
||||
}
|
||||
|
||||
pub fn to_px(au: Au) -> int {
|
||||
|
@ -160,6 +160,6 @@ pub fn to_frac_px(au: Au) -> float {
|
|||
}
|
||||
|
||||
// assumes 72 points per inch, and 96 px per inch
|
||||
pub fn from_pt(f: float) -> Au {
|
||||
from_px((f / 72f * 96f) as int)
|
||||
pub fn from_pt(pt: float) -> Au {
|
||||
from_px((pt / 72f * 96f) as int)
|
||||
}
|
||||
|
|
|
@ -22,11 +22,12 @@ use gfx::display_list::{DisplayList, ImageDisplayItem, ImageDisplayItemClass};
|
|||
use gfx::display_list::{SolidColorDisplayItem, SolidColorDisplayItemClass, TextDisplayItem};
|
||||
use gfx::display_list::{TextDisplayItemClass};
|
||||
use gfx::font::{FontStyle, FontWeight300};
|
||||
use gfx::geometry::{Au, pt_to_px};
|
||||
use gfx::geometry::Au;
|
||||
use gfx::text::text_run::TextRun;
|
||||
use newcss::color::rgb;
|
||||
use newcss::complete::CompleteStyle;
|
||||
use newcss::units::{Cursive, Em, Fantasy, Monospace, Pt, Px, SansSerif, Serif};
|
||||
use newcss::units::{Em, Px};
|
||||
use newcss::units::{Cursive, Fantasy, Monospace, SansSerif, Serif};
|
||||
use newcss::values::{CSSClearNone, CSSClearLeft, CSSClearRight, CSSClearBoth};
|
||||
use newcss::values::{CSSFontFamilyFamilyName, CSSFontFamilyGenericFamily};
|
||||
use newcss::values::{CSSFontSizeLength, CSSFontStyleItalic, CSSFontStyleNormal};
|
||||
|
@ -790,7 +791,6 @@ impl RenderBox {
|
|||
|
||||
let font_size = match my_style.font_size() {
|
||||
CSSFontSizeLength(Px(length)) => length,
|
||||
CSSFontSizeLength(Pt(length)) => pt_to_px(length),
|
||||
// todo: this is based on a hard coded font size, should be the parent element's font size
|
||||
CSSFontSizeLength(Em(length)) => length * 16f,
|
||||
_ => 16f // px units
|
||||
|
|
|
@ -18,7 +18,7 @@ use geom::{Point2D, Rect, Size2D};
|
|||
use gfx::display_list::DisplayList;
|
||||
use gfx::geometry::Au;
|
||||
use newcss::values::{CSSTextAlignLeft, CSSTextAlignCenter, CSSTextAlignRight, CSSTextAlignJustify};
|
||||
use newcss::units::{Em, Px, Pt};
|
||||
use newcss::units::{Em, Px};
|
||||
use newcss::values::{CSSLineHeightNormal, CSSLineHeightNumber, CSSLineHeightLength, CSSLineHeightPercentage};
|
||||
use servo_util::range::Range;
|
||||
use servo_util::tree::TreeNodeRef;
|
||||
|
@ -194,7 +194,6 @@ impl LineboxScanner {
|
|||
CSSLineHeightNumber(l) => em_size.scale_by(l),
|
||||
CSSLineHeightLength(Em(l)) => em_size.scale_by(l),
|
||||
CSSLineHeightLength(Px(l)) => Au::from_frac_px(l),
|
||||
CSSLineHeightLength(Pt(l)) => Au::from_pt(l),
|
||||
CSSLineHeightPercentage(p) => em_size.scale_by(p / 100.0f)
|
||||
};
|
||||
|
||||
|
@ -690,7 +689,6 @@ impl InlineFlowData {
|
|||
CSSLineHeightNumber(l) => em_size.scale_by(l),
|
||||
CSSLineHeightLength(Em(l)) => em_size.scale_by(l),
|
||||
CSSLineHeightLength(Px(l)) => Au::from_frac_px(l),
|
||||
CSSLineHeightLength(Pt(l)) => Au::from_pt(l),
|
||||
CSSLineHeightPercentage(p) => em_size.scale_by(p / 100.0f)
|
||||
};
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::num::Zero;
|
|||
use geom::side_offsets::SideOffsets2D;
|
||||
use gfx::geometry::Au;
|
||||
use newcss::complete::CompleteStyle;
|
||||
use newcss::units::{Length, Em, Pt, Px};
|
||||
use newcss::units::{Length, Em, Px};
|
||||
use newcss::values::{CSSBorderWidth, CSSBorderWidthLength, CSSBorderWidthMedium};
|
||||
use newcss::values::{CSSBorderWidthThick, CSSBorderWidthThin, CSSFontSize, CSSFontSizeLength};
|
||||
use newcss::values::{CSSWidth, CSSWidthLength, CSSWidthPercentage, CSSWidthAuto};
|
||||
|
@ -27,11 +27,9 @@ pub struct BoxModel {
|
|||
fn from_length(length: Length, font_size: CSSFontSize) -> Au {
|
||||
match length {
|
||||
Px(v) => Au::from_frac_px(v),
|
||||
Pt(v) => Au::from_pt(v),
|
||||
Em(em) => {
|
||||
match font_size {
|
||||
CSSFontSizeLength(Px(v)) => Au::from_frac_px(em * v),
|
||||
CSSFontSizeLength(Pt(v)) => Au::from_pt(em * v),
|
||||
_ => fail!("expected non-relative font size")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9ed02f7f0c4b704adb3ae60426bbc1b124e1a995
|
||||
Subproject commit d6bec7942ab07857dd65569dacc1a704dc3514df
|
|
@ -1 +1 @@
|
|||
Subproject commit be68b4032793167f714deebaf438e89301db9871
|
||||
Subproject commit a55ab9e2834b1cc898e68a02795ab68861f95f73
|
57
src/test/html/test_cssunit_length.html
Normal file
57
src/test/html/test_cssunit_length.html
Normal file
|
@ -0,0 +1,57 @@
|
|||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
html {
|
||||
background: white;
|
||||
color: black;
|
||||
}
|
||||
#test_em {
|
||||
border:1em solid;
|
||||
border-color:green;
|
||||
background-color:red;
|
||||
}
|
||||
#test_pt {
|
||||
border:1pt solid;
|
||||
border-color:green;
|
||||
background-color:red;
|
||||
}
|
||||
#test_px {
|
||||
border:1px solid;
|
||||
border-color:pink;
|
||||
background-color:green;
|
||||
}
|
||||
#test_mm {
|
||||
border:1mm solid;
|
||||
border-color:red;
|
||||
background-color:gray;
|
||||
}
|
||||
#test_pc {
|
||||
border:1pc solid;
|
||||
border-color:yellow;
|
||||
background-color:gray;
|
||||
}
|
||||
#test_cm {
|
||||
border:1cm solid;
|
||||
border-color:pink;
|
||||
background-color:gray;
|
||||
}
|
||||
#test_in {
|
||||
border:1in solid;
|
||||
border-color:red;
|
||||
background-color:gray;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="test_em"> Hello, 1em </div>
|
||||
<div id="test_pt"> Hello, 1pt </div>
|
||||
<div id="test_px"> Hello, 1px </div>
|
||||
<div id="test_mm"> Hello, 1mm </div>
|
||||
<div id="test_pc"> Hello, 1pc </div>
|
||||
<div id="test_cm"> Hello, 1cm </div>
|
||||
<div id="test_in"> Hello, 1in </div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue