mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Enable textAlign, textBaseline and direction attributes for canvas
This commit is contained in:
parent
c21fde3751
commit
34d0c313dc
15 changed files with 486 additions and 64 deletions
|
@ -39,6 +39,7 @@ derive_more = "0.99"
|
|||
encoding_rs = { version = "0.8", optional = true }
|
||||
euclid = "0.20"
|
||||
fallible = { path = "../fallible" }
|
||||
font-kit = "0.7"
|
||||
fxhash = "0.2"
|
||||
hashglobe = { path = "../hashglobe" }
|
||||
html5ever = { version = "0.25", optional = true }
|
||||
|
|
|
@ -40,6 +40,8 @@ extern crate debug_unreachable;
|
|||
extern crate derive_more;
|
||||
extern crate euclid;
|
||||
extern crate fallible;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate font_kit;
|
||||
extern crate fxhash;
|
||||
#[cfg(feature = "gecko")]
|
||||
#[macro_use]
|
||||
|
|
|
@ -22,6 +22,12 @@ use crate::values::specified::length::{FontBaseSize, NoCalcLength};
|
|||
use crate::values::CSSFloat;
|
||||
use crate::Atom;
|
||||
use cssparser::{serialize_identifier, CssStringWriter, Parser};
|
||||
#[cfg(feature = "servo")]
|
||||
use font_kit::family_name::FamilyName as FontKitFamilyName;
|
||||
#[cfg(feature = "servo")]
|
||||
use font_kit::properties::{
|
||||
Stretch as FontKitFontStretch, Style as FontKitFontStyle, Weight as FontKitFontWeight,
|
||||
};
|
||||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use std::fmt::{self, Write};
|
||||
|
@ -69,6 +75,13 @@ impl ToAnimatedValue for FontWeight {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl From<FontWeight> for FontKitFontWeight {
|
||||
fn from(font_weight: FontWeight) -> Self {
|
||||
FontKitFontWeight(font_weight.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
|
@ -445,6 +458,26 @@ impl SingleFontFamily {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl From<&SingleFontFamily> for FontKitFamilyName {
|
||||
fn from(font_family: &SingleFontFamily) -> Self {
|
||||
match font_family {
|
||||
SingleFontFamily::FamilyName(family_name) => {
|
||||
FontKitFamilyName::Title(family_name.to_css_string())
|
||||
},
|
||||
SingleFontFamily::Generic(GenericFontFamily::Serif) => FontKitFamilyName::Serif,
|
||||
SingleFontFamily::Generic(GenericFontFamily::SansSerif) => FontKitFamilyName::SansSerif,
|
||||
SingleFontFamily::Generic(GenericFontFamily::Monospace) => FontKitFamilyName::Monospace,
|
||||
SingleFontFamily::Generic(GenericFontFamily::Fantasy) => FontKitFamilyName::Fantasy,
|
||||
SingleFontFamily::Generic(GenericFontFamily::Cursive) => FontKitFamilyName::Cursive,
|
||||
SingleFontFamily::Generic(family_name) => {
|
||||
warn!("unsupported font family name: {:?}", family_name);
|
||||
FontKitFamilyName::SansSerif
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
#[derive(
|
||||
Clone,
|
||||
|
@ -943,6 +976,17 @@ impl ToCss for FontStyle {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl From<FontStyle> for FontKitFontStyle {
|
||||
fn from(font_style: FontStyle) -> Self {
|
||||
match font_style {
|
||||
FontStyle::Normal => FontKitFontStyle::Normal,
|
||||
FontStyle::Italic => FontKitFontStyle::Italic,
|
||||
FontStyle::Oblique(_) => FontKitFontStyle::Oblique,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A value for the font-stretch property per:
|
||||
///
|
||||
/// https://drafts.csswg.org/css-fonts-4/#propdef-font-stretch
|
||||
|
@ -965,6 +1009,13 @@ impl FontStretch {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl From<FontStretch> for FontKitFontStretch {
|
||||
fn from(stretch: FontStretch) -> Self {
|
||||
FontKitFontStretch(stretch.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for FontStretch {
|
||||
type AnimatedValue = Percentage;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue