mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
Fix font-weight propery
Currently, hard coded value(FontWeight300) is used for font-weight property. To display it properly, use parsed CSS font-weight value.
This commit is contained in:
parent
2b487ed3e9
commit
5756680d90
8 changed files with 62 additions and 75 deletions
|
@ -15,7 +15,7 @@ use std::rc::RcMut;
|
||||||
use servo_util::cache::{Cache, HashCache};
|
use servo_util::cache::{Cache, HashCache};
|
||||||
use servo_util::range::Range;
|
use servo_util::range::Range;
|
||||||
use servo_util::time::ProfilerChan;
|
use servo_util::time::ProfilerChan;
|
||||||
use style::computed_values::text_decoration;
|
use style::computed_values::{text_decoration, font_weight};
|
||||||
|
|
||||||
use color::Color;
|
use color::Color;
|
||||||
use font_context::FontContext;
|
use font_context::FontContext;
|
||||||
|
@ -41,7 +41,7 @@ pub trait FontHandleMethods {
|
||||||
fn family_name(&self) -> ~str;
|
fn family_name(&self) -> ~str;
|
||||||
fn face_name(&self) -> ~str;
|
fn face_name(&self) -> ~str;
|
||||||
fn is_italic(&self) -> bool;
|
fn is_italic(&self) -> bool;
|
||||||
fn boldness(&self) -> CSSFontWeight;
|
fn boldness(&self) -> font_weight::T;
|
||||||
|
|
||||||
fn clone_with_style(&self, fctx: &FontContextHandle, style: &UsedFontStyle)
|
fn clone_with_style(&self, fctx: &FontContextHandle, style: &UsedFontStyle)
|
||||||
-> Result<FontHandle, ()>;
|
-> Result<FontHandle, ()>;
|
||||||
|
@ -90,29 +90,6 @@ pub struct FontMetrics {
|
||||||
max_advance: Au
|
max_advance: Au
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(Issue #200): use enum from CSS bindings for 'font-weight'
|
|
||||||
#[deriving(Clone, Eq)]
|
|
||||||
pub enum CSSFontWeight {
|
|
||||||
FontWeight100,
|
|
||||||
FontWeight200,
|
|
||||||
FontWeight300,
|
|
||||||
FontWeight400,
|
|
||||||
FontWeight500,
|
|
||||||
FontWeight600,
|
|
||||||
FontWeight700,
|
|
||||||
FontWeight800,
|
|
||||||
FontWeight900,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CSSFontWeight {
|
|
||||||
pub fn is_bold(self) -> bool {
|
|
||||||
match self {
|
|
||||||
FontWeight900 | FontWeight800 | FontWeight700 | FontWeight600 => true,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(Issue #179): eventually this will be split into the specified
|
// TODO(Issue #179): eventually this will be split into the specified
|
||||||
// and used font styles. specified contains uninterpreted CSS font
|
// and used font styles. specified contains uninterpreted CSS font
|
||||||
// property values, while 'used' is attached to gfx::Font to descript
|
// property values, while 'used' is attached to gfx::Font to descript
|
||||||
|
@ -122,7 +99,7 @@ impl CSSFontWeight {
|
||||||
#[deriving(Clone, Eq)]
|
#[deriving(Clone, Eq)]
|
||||||
pub struct FontStyle {
|
pub struct FontStyle {
|
||||||
pt_size: f64,
|
pt_size: f64,
|
||||||
weight: CSSFontWeight,
|
weight: font_weight::T,
|
||||||
italic: bool,
|
italic: bool,
|
||||||
oblique: bool,
|
oblique: bool,
|
||||||
families: ~str,
|
families: ~str,
|
||||||
|
|
|
@ -11,6 +11,7 @@ use servo_util::time::ProfilerChan;
|
||||||
|
|
||||||
use platform::font::FontHandle;
|
use platform::font::FontHandle;
|
||||||
use platform::font_context::FontContextHandle;
|
use platform::font_context::FontContextHandle;
|
||||||
|
use style::computed_values::font_weight;
|
||||||
|
|
||||||
use azure::azure_hl::BackendType;
|
use azure::azure_hl::BackendType;
|
||||||
use std::hashmap::HashMap;
|
use std::hashmap::HashMap;
|
||||||
|
@ -20,10 +21,9 @@ use std::rc::RcMut;
|
||||||
// TODO(Rust #3934): creating lots of new dummy styles is a workaround
|
// TODO(Rust #3934): creating lots of new dummy styles is a workaround
|
||||||
// for not being able to store symbolic enums in top-level constants.
|
// for not being able to store symbolic enums in top-level constants.
|
||||||
pub fn dummy_style() -> FontStyle {
|
pub fn dummy_style() -> FontStyle {
|
||||||
use font::FontWeight300;
|
|
||||||
return FontStyle {
|
return FontStyle {
|
||||||
pt_size: 20f64,
|
pt_size: 20f64,
|
||||||
weight: FontWeight300,
|
weight: font_weight::Weight300,
|
||||||
italic: false,
|
italic: false,
|
||||||
oblique: false,
|
oblique: false,
|
||||||
families: ~"serif, sans-serif",
|
families: ~"serif, sans-serif",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use font::{CSSFontWeight, SpecifiedFontStyle};
|
use font::SpecifiedFontStyle;
|
||||||
use gfx_font::FontHandleMethods;
|
use gfx_font::FontHandleMethods;
|
||||||
use platform::font::FontHandle;
|
use platform::font::FontHandle;
|
||||||
use platform::font_context::FontContextHandle;
|
use platform::font_context::FontContextHandle;
|
||||||
|
@ -10,6 +10,7 @@ use platform::font_list::FontListHandle;
|
||||||
use servo_util::time;
|
use servo_util::time;
|
||||||
use servo_util::time::profile;
|
use servo_util::time::profile;
|
||||||
use servo_util::time::ProfilerChan;
|
use servo_util::time::ProfilerChan;
|
||||||
|
use style::computed_values::font_weight;
|
||||||
|
|
||||||
use std::hashmap::HashMap;
|
use std::hashmap::HashMap;
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ impl<'self> FontFamily {
|
||||||
/// standard four faces: Normal, Bold, Italic, BoldItalic.
|
/// standard four faces: Normal, Bold, Italic, BoldItalic.
|
||||||
pub struct FontEntry {
|
pub struct FontEntry {
|
||||||
face_name: ~str,
|
face_name: ~str,
|
||||||
priv weight: CSSFontWeight,
|
priv weight: font_weight::T,
|
||||||
priv italic: bool,
|
priv italic: bool,
|
||||||
handle: FontHandle,
|
handle: FontHandle,
|
||||||
// TODO: array of OpenType features, etc.
|
// TODO: array of OpenType features, etc.
|
||||||
|
|
|
@ -4,15 +4,14 @@
|
||||||
|
|
||||||
extern mod freetype;
|
extern mod freetype;
|
||||||
|
|
||||||
use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
|
use font::{FontHandleMethods, FontMetrics, FontTableMethods};
|
||||||
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
|
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle};
|
||||||
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
|
|
||||||
use font::{FontWeight700, FontWeight800, FontWeight900};
|
|
||||||
use servo_util::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use servo_util::geometry;
|
use servo_util::geometry;
|
||||||
use platform::font_context::FontContextHandle;
|
use platform::font_context::FontContextHandle;
|
||||||
use text::glyph::GlyphIndex;
|
use text::glyph::GlyphIndex;
|
||||||
use text::util::{float_to_fixed, fixed_to_float};
|
use text::util::{float_to_fixed, fixed_to_float};
|
||||||
|
use style::computed_values::font_weight;
|
||||||
|
|
||||||
use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name};
|
use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name};
|
||||||
use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size};
|
use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size};
|
||||||
|
@ -140,8 +139,8 @@ impl FontHandleMethods for FontHandle {
|
||||||
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC != 0 }
|
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC != 0 }
|
||||||
}
|
}
|
||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
fn boldness(&self) -> CSSFontWeight {
|
fn boldness(&self) -> font_weight::T {
|
||||||
let default_weight = FontWeight400;
|
let default_weight = font_weight::Weight400;
|
||||||
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } {
|
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } {
|
||||||
default_weight
|
default_weight
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,15 +150,15 @@ impl FontHandleMethods for FontHandle {
|
||||||
if valid {
|
if valid {
|
||||||
let weight =(*os2).usWeightClass;
|
let weight =(*os2).usWeightClass;
|
||||||
match weight {
|
match weight {
|
||||||
1 | 100..199 => FontWeight100,
|
1 | 100..199 => font_weight::Weight100,
|
||||||
2 | 200..299 => FontWeight200,
|
2 | 200..299 => font_weight::Weight200,
|
||||||
3 | 300..399 => FontWeight300,
|
3 | 300..399 => font_weight::Weight300,
|
||||||
4 | 400..499 => FontWeight400,
|
4 | 400..499 => font_weight::Weight400,
|
||||||
5 | 500..599 => FontWeight500,
|
5 | 500..599 => font_weight::Weight500,
|
||||||
6 | 600..699 => FontWeight600,
|
6 | 600..699 => font_weight::Weight600,
|
||||||
7 | 700..799 => FontWeight700,
|
7 | 700..799 => font_weight::Weight700,
|
||||||
8 | 800..899 => FontWeight800,
|
8 | 800..899 => font_weight::Weight800,
|
||||||
9 | 900..999 => FontWeight900,
|
9 | 900..999 => font_weight::Weight900,
|
||||||
_ => default_weight
|
_ => default_weight
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,15 +4,14 @@
|
||||||
|
|
||||||
extern mod freetype;
|
extern mod freetype;
|
||||||
|
|
||||||
use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
|
use font::{FontHandleMethods, FontMetrics, FontTableMethods};
|
||||||
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
|
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle};
|
||||||
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
|
|
||||||
use font::{FontWeight700, FontWeight800, FontWeight900};
|
|
||||||
use servo_util::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use servo_util::geometry;
|
use servo_util::geometry;
|
||||||
use platform::font_context::FontContextHandle;
|
use platform::font_context::FontContextHandle;
|
||||||
use text::glyph::GlyphIndex;
|
use text::glyph::GlyphIndex;
|
||||||
use text::util::{float_to_fixed, fixed_to_float};
|
use text::util::{float_to_fixed, fixed_to_float};
|
||||||
|
use style::computed_values::font_weight;
|
||||||
|
|
||||||
use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name};
|
use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name};
|
||||||
use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size};
|
use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size};
|
||||||
|
@ -138,8 +137,8 @@ impl FontHandleMethods for FontHandle {
|
||||||
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC != 0 }
|
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC != 0 }
|
||||||
}
|
}
|
||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
fn boldness(&self) -> CSSFontWeight {
|
fn boldness(&self) -> font_weight::T {
|
||||||
let default_weight = FontWeight400;
|
let default_weight = font_weight::Weight400;
|
||||||
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } {
|
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } {
|
||||||
default_weight
|
default_weight
|
||||||
} else {
|
} else {
|
||||||
|
@ -149,15 +148,15 @@ impl FontHandleMethods for FontHandle {
|
||||||
if valid {
|
if valid {
|
||||||
let weight =(*os2).usWeightClass;
|
let weight =(*os2).usWeightClass;
|
||||||
match weight {
|
match weight {
|
||||||
1 | 100..199 => FontWeight100,
|
1 | 100..199 => font_weight::Weight100,
|
||||||
2 | 200..299 => FontWeight200,
|
2 | 200..299 => font_weight::Weight200,
|
||||||
3 | 300..399 => FontWeight300,
|
3 | 300..399 => font_weight::Weight300,
|
||||||
4 | 400..499 => FontWeight400,
|
4 | 400..499 => font_weight::Weight400,
|
||||||
5 | 500..599 => FontWeight500,
|
5 | 500..599 => font_weight::Weight500,
|
||||||
6 | 600..699 => FontWeight600,
|
6 | 600..699 => font_weight::Weight600,
|
||||||
7 | 700..799 => FontWeight700,
|
7 | 700..799 => font_weight::Weight700,
|
||||||
8 | 800..899 => FontWeight800,
|
8 | 800..899 => font_weight::Weight800,
|
||||||
9 | 900..999 => FontWeight900,
|
9 | 900..999 => font_weight::Weight900,
|
||||||
_ => default_weight
|
_ => default_weight
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -8,14 +8,14 @@ extern mod core_foundation;
|
||||||
extern mod core_graphics;
|
extern mod core_graphics;
|
||||||
extern mod core_text;
|
extern mod core_text;
|
||||||
|
|
||||||
use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
|
use font::{FontHandleMethods, FontMetrics, FontTableMethods};
|
||||||
use font::{FontTableTag, FontWeight100, FontWeight200, FontWeight300, FontWeight400};
|
use font::FontTableTag;
|
||||||
use font::{FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900};
|
|
||||||
use font::{FractionalPixel, SpecifiedFontStyle};
|
use font::{FractionalPixel, SpecifiedFontStyle};
|
||||||
use servo_util::geometry::{Au, px_to_pt};
|
use servo_util::geometry::{Au, px_to_pt};
|
||||||
use servo_util::geometry;
|
use servo_util::geometry;
|
||||||
use platform::macos::font_context::FontContextHandle;
|
use platform::macos::font_context::FontContextHandle;
|
||||||
use text::glyph::GlyphIndex;
|
use text::glyph::GlyphIndex;
|
||||||
|
use style::computed_values::font_weight;
|
||||||
|
|
||||||
use core_foundation::base::CFIndex;
|
use core_foundation::base::CFIndex;
|
||||||
use core_foundation::data::CFData;
|
use core_foundation::data::CFData;
|
||||||
|
@ -104,20 +104,20 @@ impl FontHandleMethods for FontHandle {
|
||||||
self.ctfont.symbolic_traits().is_italic()
|
self.ctfont.symbolic_traits().is_italic()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn boldness(&self) -> CSSFontWeight {
|
fn boldness(&self) -> font_weight::T {
|
||||||
// -1.0 to 1.0
|
// -1.0 to 1.0
|
||||||
let normalized = self.ctfont.all_traits().normalized_weight();
|
let normalized = self.ctfont.all_traits().normalized_weight();
|
||||||
// 0.0 to 9.0
|
// 0.0 to 9.0
|
||||||
let normalized = (normalized + 1.0) / 2.0 * 9.0;
|
let normalized = (normalized + 1.0) / 2.0 * 9.0;
|
||||||
if normalized < 1.0 { return FontWeight100; }
|
if normalized < 1.0 { return font_weight::Weight100; }
|
||||||
if normalized < 2.0 { return FontWeight200; }
|
if normalized < 2.0 { return font_weight::Weight200; }
|
||||||
if normalized < 3.0 { return FontWeight300; }
|
if normalized < 3.0 { return font_weight::Weight300; }
|
||||||
if normalized < 4.0 { return FontWeight400; }
|
if normalized < 4.0 { return font_weight::Weight400; }
|
||||||
if normalized < 5.0 { return FontWeight500; }
|
if normalized < 5.0 { return font_weight::Weight500; }
|
||||||
if normalized < 6.0 { return FontWeight600; }
|
if normalized < 6.0 { return font_weight::Weight600; }
|
||||||
if normalized < 7.0 { return FontWeight700; }
|
if normalized < 7.0 { return font_weight::Weight700; }
|
||||||
if normalized < 8.0 { return FontWeight800; }
|
if normalized < 8.0 { return font_weight::Weight800; }
|
||||||
return FontWeight900;
|
return font_weight::Weight900;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clone_with_style(&self, fctx: &FontContextHandle, style: &SpecifiedFontStyle)
|
fn clone_with_style(&self, fctx: &FontContextHandle, style: &SpecifiedFontStyle)
|
||||||
|
|
|
@ -13,7 +13,8 @@ use gfx::display_list::{DisplayList, ImageDisplayItem, ImageDisplayItemClass};
|
||||||
use gfx::display_list::{SolidColorDisplayItem, SolidColorDisplayItemClass, TextDisplayItem};
|
use gfx::display_list::{SolidColorDisplayItem, SolidColorDisplayItemClass, TextDisplayItem};
|
||||||
use gfx::display_list::{TextDisplayItemClass, TextDisplayItemFlags, ClipDisplayItem};
|
use gfx::display_list::{TextDisplayItemClass, TextDisplayItemFlags, ClipDisplayItem};
|
||||||
use gfx::display_list::{ClipDisplayItemClass};
|
use gfx::display_list::{ClipDisplayItemClass};
|
||||||
use gfx::font::{FontStyle, FontWeight300};
|
use gfx::font::FontStyle;
|
||||||
|
|
||||||
use gfx::text::text_run::TextRun;
|
use gfx::text::text_run::TextRun;
|
||||||
use servo_msg::constellation_msg::{FrameRectMsg, PipelineId, SubpageId};
|
use servo_msg::constellation_msg::{FrameRectMsg, PipelineId, SubpageId};
|
||||||
use servo_net::image::holder::ImageHolder;
|
use servo_net::image::holder::ImageHolder;
|
||||||
|
@ -415,9 +416,11 @@ impl Box {
|
||||||
font_style::oblique => (false, true),
|
font_style::oblique => (false, true),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let font_weight = my_style.Font.font_weight;
|
||||||
|
|
||||||
FontStyle {
|
FontStyle {
|
||||||
pt_size: font_size,
|
pt_size: font_size,
|
||||||
weight: FontWeight300,
|
weight: font_weight,
|
||||||
italic: italic,
|
italic: italic,
|
||||||
oblique: oblique,
|
oblique: oblique,
|
||||||
families: font_families,
|
families: font_families,
|
||||||
|
|
|
@ -554,6 +554,14 @@ pub mod longhands {
|
||||||
Weight${weight},
|
Weight${weight},
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
impl T {
|
||||||
|
pub fn is_bold(self) -> bool {
|
||||||
|
match self {
|
||||||
|
Weight900 | Weight800 | Weight700 | Weight600 => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T { Weight400 } // normal
|
#[inline] pub fn get_initial_value() -> computed_value::T { Weight400 } // normal
|
||||||
pub fn to_computed_value(value: SpecifiedValue, context: &computed::Context)
|
pub fn to_computed_value(value: SpecifiedValue, context: &computed::Context)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue