Skip to content

Commit

Permalink
style: Make all keywords CamelCase for consistency.
Browse files Browse the repository at this point in the history
This prevents confusion and paves the ground for derive(Parse) of them.
  • Loading branch information
emilio committed Dec 6, 2017
1 parent 37cd870 commit af87952
Show file tree
Hide file tree
Showing 60 changed files with 921 additions and 836 deletions.
4 changes: 2 additions & 2 deletions components/gfx/font.rs
Expand Up @@ -261,8 +261,8 @@ impl Font {
#[inline]
pub fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
let codepoint = match self.variant {
font_variant_caps::T::small_caps => codepoint.to_uppercase().next().unwrap(), //FIXME: #5938
font_variant_caps::T::normal => codepoint,
font_variant_caps::T::SmallCaps => codepoint.to_uppercase().next().unwrap(), //FIXME: #5938
font_variant_caps::T::Normal => codepoint,
};
self.handle.glyph_index(codepoint)
}
Expand Down
13 changes: 7 additions & 6 deletions components/gfx/font_context.rs
Expand Up @@ -20,7 +20,8 @@ use std::hash::{BuildHasherDefault, Hash, Hasher};
use std::rc::Rc;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use style::computed_values::{font_style, font_variant_caps};
use style::computed_values::font_style::T as FontStyle;
use style::computed_values::font_variant_caps::T as FontVariantCaps;
use style::properties::style_structs;
use webrender_api;

Expand Down Expand Up @@ -78,14 +79,14 @@ impl FontContext {
template: Arc<FontTemplateData>,
descriptor: FontTemplateDescriptor,
pt_size: Au,
variant: font_variant_caps::T,
variant: FontVariantCaps,
font_key: webrender_api::FontKey) -> Result<Font, ()> {
// TODO: (Bug #3463): Currently we only support fake small-caps
// painting. We should also support true small-caps (where the
// font supports it) in the future.
let actual_pt_size = match variant {
font_variant_caps::T::small_caps => pt_size.scale_by(SMALL_CAPS_SCALE_FACTOR),
font_variant_caps::T::normal => pt_size,
FontVariantCaps::SmallCaps => pt_size.scale_by(SMALL_CAPS_SCALE_FACTOR),
FontVariantCaps::Normal => pt_size,
};

let handle = FontHandle::new_from_template(&self.platform_handle,
Expand Down Expand Up @@ -130,8 +131,8 @@ impl FontContext {

let desc = FontTemplateDescriptor::new(style.font_weight,
style.font_stretch,
style.font_style == font_style::T::italic ||
style.font_style == font_style::T::oblique);
style.font_style == FontStyle::Italic ||
style.font_style == FontStyle::Oblique);

let mut fonts: SmallVec<[Rc<RefCell<Font>>; 8]> = SmallVec::new();

Expand Down
15 changes: 8 additions & 7 deletions components/gfx/platform/freetype/font.rs
Expand Up @@ -20,7 +20,8 @@ use platform::font_template::FontTemplateData;
use std::{mem, ptr};
use std::os::raw::{c_char, c_long};
use std::sync::Arc;
use style::computed_values::{font_stretch, font_weight};
use style::computed_values::font_stretch::T as FontStretch;
use style::computed_values::font_weight::T as FontWeight;
use super::c_str_to_string;
use text::glyph::GlyphId;
use text::util::fixed_to_float;
Expand Down Expand Up @@ -134,8 +135,8 @@ impl FontHandleMethods for FontHandle {
fn is_italic(&self) -> bool {
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC as c_long != 0 }
}
fn boldness(&self) -> font_weight::T {
let default_weight = font_weight::T::normal();
fn boldness(&self) -> FontWeight {
let default_weight = FontWeight::normal();
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD as c_long == 0 } {
default_weight
} else {
Expand All @@ -145,9 +146,9 @@ impl FontHandleMethods for FontHandle {
if valid {
let weight =(*os2).usWeightClass as i32;
if weight < 10 {
font_weight::T::from_int(weight * 100).unwrap()
FontWeight::from_int(weight * 100).unwrap()
} else if weight >= 100 && weight < 1000 {
font_weight::T::from_int(weight / 100 * 100).unwrap()
FontWeight::from_int(weight / 100 * 100).unwrap()
} else {
default_weight
}
Expand All @@ -157,9 +158,9 @@ impl FontHandleMethods for FontHandle {
}
}
}
fn stretchiness(&self) -> font_stretch::T {
fn stretchiness(&self) -> FontStretch {
// TODO(pcwalton): Implement this.
font_stretch::T::normal
FontStretch::Normal
}

fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
Expand Down
27 changes: 14 additions & 13 deletions components/gfx/platform/macos/font.rs
Expand Up @@ -21,7 +21,8 @@ use platform::macos::font_context::FontContextHandle;
use std::{fmt, ptr};
use std::ops::Range;
use std::sync::Arc;
use style::computed_values::{font_stretch, font_weight};
use style::computed_values::font_stretch::T as FontStretch;
use style::computed_values::font_weight::T as FontWeight;
use text::glyph::GlyphId;

const KERN_PAIR_LEN: usize = 6;
Expand Down Expand Up @@ -210,29 +211,29 @@ impl FontHandleMethods for FontHandle {
self.ctfont.symbolic_traits().is_italic()
}

fn boldness(&self) -> font_weight::T {
fn boldness(&self) -> FontWeight {
let normalized = self.ctfont.all_traits().normalized_weight(); // [-1.0, 1.0]
let normalized = if normalized <= 0.0 {
4.0 + normalized * 3.0 // [1.0, 4.0]
} else {
4.0 + normalized * 5.0 // [4.0, 9.0]
}; // [1.0, 9.0], centered on 4.0
font_weight::T::from_int(normalized.round() as i32 * 100).unwrap()
FontWeight::from_int(normalized.round() as i32 * 100).unwrap()
}

fn stretchiness(&self) -> font_stretch::T {
fn stretchiness(&self) -> FontStretch {
let normalized = self.ctfont.all_traits().normalized_width(); // [-1.0, 1.0]
let normalized = (normalized + 1.0) / 2.0 * 9.0; // [0.0, 9.0]
match normalized {
v if v < 1.0 => font_stretch::T::ultra_condensed,
v if v < 2.0 => font_stretch::T::extra_condensed,
v if v < 3.0 => font_stretch::T::condensed,
v if v < 4.0 => font_stretch::T::semi_condensed,
v if v < 5.0 => font_stretch::T::normal,
v if v < 6.0 => font_stretch::T::semi_expanded,
v if v < 7.0 => font_stretch::T::expanded,
v if v < 8.0 => font_stretch::T::extra_expanded,
_ => font_stretch::T::ultra_expanded,
v if v < 1.0 => FontStretch::UltraCondensed,
v if v < 2.0 => FontStretch::ExtraCondensed,
v if v < 3.0 => FontStretch::Condensed,
v if v < 4.0 => FontStretch::SemiCondensed,
v if v < 5.0 => FontStretch::Normal,
v if v < 6.0 => FontStretch::SemiExpanded,
v if v < 7.0 => FontStretch::Expanded,
v if v < 8.0 => FontStretch::ExtraExpanded,
_ => FontStretch::UltraExpanded,
}
}

Expand Down
57 changes: 30 additions & 27 deletions components/gfx/platform/windows/font.rs
Expand Up @@ -16,7 +16,8 @@ use platform::font_template::FontTemplateData;
use platform::windows::font_context::FontContextHandle;
use platform::windows::font_list::font_from_atom;
use std::sync::Arc;
use style::computed_values::{font_stretch, font_weight};
use style::computed_values::font_stretch::T as StyleFontStretch;
use style::computed_values::font_weight::T as StyleFontWeight;
use text::glyph::GlyphId;
use truetype;

Expand Down Expand Up @@ -94,8 +95,8 @@ fn get_family_face_indices(records: &[truetype::naming_table::Record]) -> Option
struct FontInfo {
family_name: String,
face_name: String,
weight: font_weight::T,
stretch: font_stretch::T,
weight: StyleFontWeight,
stretch: StyleFontStretch,
style: FontStyle,
}

Expand Down Expand Up @@ -155,19 +156,21 @@ impl FontInfo {
},
};

let weight = font_weight::T::
from_int(min(9, max(1, weight_val as i32 / 100)) * 100).unwrap();
let weight =
StyleFontWeight::from_int(
min(9, max(1, weight_val as i32 / 100)) * 100
).unwrap();

let stretch = match min(9, max(1, width_val)) {
1 => font_stretch::T::ultra_condensed,
2 => font_stretch::T::extra_condensed,
3 => font_stretch::T::condensed,
4 => font_stretch::T::semi_condensed,
5 => font_stretch::T::normal,
6 => font_stretch::T::semi_expanded,
7 => font_stretch::T::expanded,
8 => font_stretch::T::extra_expanded,
9 => font_stretch::T::ultra_expanded,
1 => StyleFontStretch::UltraCondensed,
2 => StyleFontStretch::ExtraCondensed,
3 => StyleFontStretch::Condensed,
4 => StyleFontStretch::SemiCondensed,
5 => StyleFontStretch::Normal,
6 => StyleFontStretch::SemiExpanded,
7 => StyleFontStretch::Expanded,
8 => StyleFontStretch::ExtraExpanded,
9 => StyleFontStretch::UltraExpanded,
_ => return Err(()),
};

Expand All @@ -188,7 +191,7 @@ impl FontInfo {

fn new_from_font(font: &Font) -> Result<FontInfo, ()> {
let style = font.style();
let weight = font_weight::T(match font.weight() {
let weight = StyleFontWeight(match font.weight() {
FontWeight::Thin => 100,
FontWeight::ExtraLight => 200,
FontWeight::Light => 300,
Expand All @@ -204,16 +207,16 @@ impl FontInfo {
FontWeight::ExtraBlack => 900,
});
let stretch = match font.stretch() {
FontStretch::Undefined => font_stretch::T::normal,
FontStretch::UltraCondensed => font_stretch::T::ultra_condensed,
FontStretch::ExtraCondensed => font_stretch::T::extra_condensed,
FontStretch::Condensed => font_stretch::T::condensed,
FontStretch::SemiCondensed => font_stretch::T::semi_condensed,
FontStretch::Normal => font_stretch::T::normal,
FontStretch::SemiExpanded => font_stretch::T::semi_expanded,
FontStretch::Expanded => font_stretch::T::expanded,
FontStretch::ExtraExpanded => font_stretch::T::extra_expanded,
FontStretch::UltraExpanded => font_stretch::T::ultra_expanded,
FontStretch::Undefined => StyleFontStretch::Normal,
FontStretch::UltraCondensed => StyleFontStretch::UltraCondensed,
FontStretch::ExtraCondensed => StyleFontStretch::ExtraCondensed,
FontStretch::Condensed => StyleFontStretch::Condensed,
FontStretch::SemiCondensed => StyleFontStretch::SemiCondensed,
FontStretch::Normal => StyleFontStretch::Normal,
FontStretch::SemiExpanded => StyleFontStretch::SemiExpanded,
FontStretch::Expanded => StyleFontStretch::Expanded,
FontStretch::ExtraExpanded => StyleFontStretch::ExtraExpanded,
FontStretch::UltraExpanded => StyleFontStretch::UltraExpanded,
};

Ok(FontInfo {
Expand Down Expand Up @@ -300,11 +303,11 @@ impl FontHandleMethods for FontHandle {
}
}

fn boldness(&self) -> font_weight::T {
fn boldness(&self) -> StyleFontWeight {
self.info.weight
}

fn stretchiness(&self) -> font_stretch::T {
fn stretchiness(&self) -> StyleFontStretch {
self.info.stretch
}

Expand Down

0 comments on commit af87952

Please sign in to comment.