Enable textAlign, textBaseline and direction attributes for canvas

This commit is contained in:
Utsav Oza 2020-06-07 01:38:04 +05:30
parent c21fde3751
commit 34d0c313dc
15 changed files with 486 additions and 64 deletions

View file

@ -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;