mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Auto merge of #26697 - utsavoza:ugo/issue-11681/22-05-2020, r=jdm
Implement CanvasRenderingContext2d.fillText The PR consists of broadly two main changes: - Implementation of Canvas2dRenderingContext.font - Basic implementation of Canvas2dRenderingContext.fillText Although I am not fully sure about the long term goals for the canvas backend in Servo, I assumed limited scope for font and text handling (should support simple text drawing with font selection) in the current implementation as I believe a more complete implementation would eventually be brought in as a part of #22957. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #11681 - [x] There are tests for these changes
This commit is contained in:
commit
721271dcd3
57 changed files with 928 additions and 183 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]
|
||||
|
|
|
@ -2602,6 +2602,7 @@ pub mod style_structs {
|
|||
% for style_struct in data.active_style_structs():
|
||||
% if style_struct.name == "Font":
|
||||
#[derive(Clone, Debug, MallocSizeOf)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))]
|
||||
% else:
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
% endif
|
||||
|
|
|
@ -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,
|
||||
|
@ -81,6 +94,7 @@ impl ToAnimatedValue for FontWeight {
|
|||
ToCss,
|
||||
ToResolvedValue,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))]
|
||||
/// The computed value of font-size
|
||||
pub struct FontSize {
|
||||
/// The size.
|
||||
|
@ -179,7 +193,7 @@ impl ToAnimatedValue for FontSize {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToResolvedValue)]
|
||||
#[cfg_attr(feature = "servo", derive(Hash, MallocSizeOf))]
|
||||
#[cfg_attr(feature = "servo", derive(Hash, MallocSizeOf, Serialize, Deserialize))]
|
||||
/// Specifies a prioritized list of font family names or generic family names.
|
||||
pub struct FontFamily {
|
||||
/// The actual list of family names.
|
||||
|
@ -444,9 +458,29 @@ 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
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))]
|
||||
/// A list of SingleFontFamily
|
||||
pub struct FontFamilyList(Box<[SingleFontFamily]>);
|
||||
|
||||
|
@ -931,6 +965,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
|
||||
|
@ -953,6 +998,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;
|
||||
|
||||
|
|
|
@ -497,6 +497,7 @@ impl ToComputedValue for FontStretch {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum KeywordSize {
|
||||
#[css(keyword = "xx-small")]
|
||||
|
@ -541,6 +542,7 @@ impl Default for KeywordSize {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))]
|
||||
/// Additional information for keyword-derived font sizes.
|
||||
pub struct KeywordInfo {
|
||||
/// The keyword used
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue