pub struct FontContext {Show 14 fields
system_font_service_proxy: Arc<SystemFontServiceProxy>,
resource_threads: Mutex<CoreResourceThread>,
paint_api: Mutex<CrossProcessPaintApi>,
fonts: RwLock<HashMap<FontCacheKey, Option<FontRef>>>,
resolved_font_groups: RwLock<HashMap<FontGroupCacheKey, Arc<FontGroup>>>,
web_fonts: CrossThreadFontStore,
webrender_font_keys: RwLock<HashMap<FontIdentifier, FontKey>>,
webrender_font_instance_keys: RwLock<HashMap<FontParameters, FontInstanceKey>>,
font_data: RwLock<HashMap<FontIdentifier, FontData>>,
have_removed_web_fonts: AtomicBool,
currently_downloading_fonts: Mutex<HashMap<ServoUrl, Vec<WebFontDownloadState>>>,
known_font_face_rules: Mutex<KnownFontFaceRules>,
font_feature_value_map: AtomicRefCell<Option<FontFeatureValueMap>>,
number_of_loading_web_fonts: AtomicUsize,
}Expand description
The FontContext represents the per-thread/thread state necessary for working with fonts. It is the public API used by the layout and paint code. It talks directly to the system font service where required.
Fields§
§system_font_service_proxy: Arc<SystemFontServiceProxy>§resource_threads: Mutex<CoreResourceThread>§paint_api: Mutex<CrossProcessPaintApi>A sender that can send messages and receive replies from Paint.
fonts: RwLock<HashMap<FontCacheKey, Option<FontRef>>>The actual instances of fonts ie a FontTemplate combined with a size and
other font properties, along with the font data and a platform font instance.
resolved_font_groups: RwLock<HashMap<FontGroupCacheKey, Arc<FontGroup>>>A caching map between the specification of a font in CSS style and
resolved FontGroup which contains information about all fonts that
can be selected with that style.
web_fonts: CrossThreadFontStore§webrender_font_keys: RwLock<HashMap<FontIdentifier, FontKey>>A collection of WebRender FontKeys generated for the web fonts that this
FontContext controls.
webrender_font_instance_keys: RwLock<HashMap<FontParameters, FontInstanceKey>>A collection of WebRender FontInstanceKeys generated for the web fonts that
this FontContext controls.
font_data: RwLock<HashMap<FontIdentifier, FontData>>The data for each web font FontIdentifier. This data might be used by more than one
FontTemplate as each identifier refers to a URL.
have_removed_web_fonts: AtomicBool§currently_downloading_fonts: Mutex<HashMap<ServoUrl, Vec<WebFontDownloadState>>>Maps from a URL to all the @font-face rules that are currently waiting for the load to
finish.
known_font_face_rules: Mutex<KnownFontFaceRules>The set of @font-face rules that are currently present in the CSS cascade. This is not necessarily
equivalent to the rules that actually apply to the page, because rules that are invalid or not
yet downloaded are also included.
font_feature_value_map: AtomicRefCell<Option<FontFeatureValueMap>>A lazily-computed map of feature names from @font-feature-value rules.
number_of_loading_web_fonts: AtomicUsizeThe number of fonts that are currently loading.
Implementations§
Source§impl FontContext
impl FontContext
pub fn new( system_font_service_proxy: Arc<SystemFontServiceProxy>, paint_api: CrossProcessPaintApi, resource_threads: ResourceThreads, ) -> Self
pub fn web_fonts_still_loading(&self) -> usize
fn get_font_data(&self, identifier: &FontIdentifier) -> Option<FontData>
Sourcepub fn font_group(&self, style: ServoArc<FontStyleStruct>) -> Arc<FontGroup>
pub fn font_group(&self, style: ServoArc<FontStyleStruct>) -> Arc<FontGroup>
Returns a FontGroup representing fonts which can be used for layout, given the style.
Font groups are cached, so subsequent calls with the same style will return a reference
to an existing FontGroup.
Sourcepub fn font_group_with_size(
&self,
style: ServoArc<FontStyleStruct>,
size: Au,
) -> Arc<FontGroup>
pub fn font_group_with_size( &self, style: ServoArc<FontStyleStruct>, size: Au, ) -> Arc<FontGroup>
Like Self::font_group, but overriding the size found in the FontStyleStruct with the given size
in pixels.
Sourcepub fn font(
&self,
font_template: FontTemplateRef,
font_descriptor: &FontDescriptor,
) -> Option<FontRef>
pub fn font( &self, font_template: FontTemplateRef, font_descriptor: &FontDescriptor, ) -> Option<FontRef>
Returns a font matching the parameters. Fonts are cached, so repeated calls will return a
reference to the same underlying Font.
fn get_font_maybe_synthesizing_small_caps( &self, font_template: FontTemplateRef, font_descriptor: &FontDescriptor, synthesize_small_caps: bool, ) -> Option<FontRef>
fn matching_web_font_templates( &self, descriptor_to_match: &FontDescriptor, family_descriptor: &FontFamilyDescriptor, ) -> Option<Vec<FontTemplateRef>>
Sourcepub fn matching_templates(
&self,
descriptor_to_match: &FontDescriptor,
family_descriptor: &FontFamilyDescriptor,
) -> Vec<FontTemplateRef>
pub fn matching_templates( &self, descriptor_to_match: &FontDescriptor, family_descriptor: &FontFamilyDescriptor, ) -> Vec<FontTemplateRef>
Try to find matching templates in this FontContext, first looking in the list of web fonts and
falling back to asking the super::SystemFontService for a matching system font.
Sourcefn create_font(
&self,
font_template: FontTemplateRef,
font_descriptor: FontDescriptor,
synthesized_small_caps: Option<FontRef>,
) -> Result<FontRef, &'static str>
fn create_font( &self, font_template: FontTemplateRef, font_descriptor: FontDescriptor, synthesized_small_caps: Option<FontRef>, ) -> Result<FontRef, &'static str>
Create a Font for use in layout calculations, from a FontTemplateData returned by the
cache thread and a FontDescriptor which contains the styling parameters.
pub(crate) fn create_font_instance_key( &self, font: &Font, painter_id: PainterId, ) -> FontInstanceKey
fn create_web_font_instance( &self, font_template: FontTemplateRef, pt_size: Au, flags: FontInstanceFlags, variations: Vec<FontVariation>, painter_id: PainterId, ) -> FontInstanceKey
fn invalidate_font_groups_after_web_font_load(&self)
pub fn is_supported_web_font_source(source: &&Source) -> bool
fn is_local_or_unknown_url_font( &self, family_name: &LowercaseFontFamilyName, source: &Source, ) -> bool
Sourcepub(crate) fn handle_web_font_request_started(
&self,
url: ServoUrl,
state: WebFontDownloadState,
) -> bool
pub(crate) fn handle_web_font_request_started( &self, url: ServoUrl, state: WebFontDownloadState, ) -> bool
Adds the provided new web font request to the list of pending downloads.
Returns a boolean indicating whether a new download should be started. If there is already a pending request for the same URL then there is no need to start a new one.
Sourcepub(crate) fn handle_web_font_request_succeeded(
&self,
font_data: FontData,
url: ServoUrl,
) -> bool
pub(crate) fn handle_web_font_request_succeeded( &self, font_data: FontData, url: ServoUrl, ) -> bool
Handle a web font load finishing, adding the new font to the FontStore. If the web font
load was canceled (for instance, if the stylesheet was removed), then do nothing and return
false.
All download states waiting for this entry to load will have their promise fulfilled.
Sourcepub fn decrement_count_of_loading_fonts_by_one(&self)
pub fn decrement_count_of_loading_fonts_by_one(&self)
Decrement the count of font loads blocking the document.fonts.ready promise by one.
Sourcepub(crate) fn is_font_face_rule_active(
&self,
target_rule: &ServoArc<LockedFontFaceRule>,
) -> bool
pub(crate) fn is_font_face_rule_active( &self, target_rule: &ServoArc<LockedFontFaceRule>, ) -> bool
Returns true iff a @font-face rule is part of the active set.
A font face rule might be removed from this set if its stylesheet is removed for example.
Source§impl FontContext
impl FontContext
pub fn collect_unused_webrender_resources( &self, all: bool, ) -> (Vec<FontKey>, Vec<FontInstanceKey>)
Sourcefn remove_single_font_face_rule(
&self,
font_face_rule: &FontFaceRuleDescriptors,
font_store: &mut FontStore,
) -> bool
fn remove_single_font_face_rule( &self, font_face_rule: &FontFaceRuleDescriptors, font_store: &mut FontStore, ) -> bool
Returns true if any font templates were removed.
pub fn add_template_to_font_context( &self, family_name: LowercaseFontFamilyName, new_template: FontTemplate, )
pub fn construct_web_font_from_data( &self, data: &[u8], descriptors: CSSFontFaceDescriptors, ) -> Option<(LowercaseFontFamilyName, FontTemplate)>
fn start_loading_one_web_font( self: &Arc<FontContext>, webview_id: Option<WebViewId>, source_list: &SourceList, css_font_face_descriptors: CSSFontFaceDescriptors, completion_handler: WebFontLoadInitiator, document_context: &WebFontDocumentContext, )
pub(crate) fn process_next_web_font_source( self: &Arc<FontContext>, state: WebFontDownloadState, )
Sourcepub fn resolve_font_variant_alternate_identifiers_for(
&self,
font: &FontRef,
alternates: &FontVariantAlternates,
stylist: &Stylist,
) -> ResolvedFontVariantAlternates
pub fn resolve_font_variant_alternate_identifiers_for( &self, font: &FontRef, alternates: &FontVariantAlternates, stylist: &Stylist, ) -> ResolvedFontVariantAlternates
Resolves the value of font-variant-alternates to a set of OpenType features to apply.
Sourcefn look_up_font_feature_alternate_name(
&self,
family_name: Atom,
kind: AlternateKindRequiringResolution,
name: Atom,
stylist: &Stylist,
) -> Option<FontFeatureValue>
fn look_up_font_feature_alternate_name( &self, family_name: Atom, kind: AlternateKindRequiringResolution, name: Atom, stylist: &Stylist, ) -> Option<FontFeatureValue>
Resolves a single component of font-variant-alternates, like stylistic(foobar) to a font-specific
set of OpenType features to apply.
If the map of @font-feature-values rules has not yet been computed then this method
will compute it.
pub fn invalidate_font_feature_values_map(&self)
Trait Implementations§
Source§impl MallocSizeOf for FontContext
impl MallocSizeOf for FontContext
Source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl !Freeze for FontContext
impl !RefUnwindSafe for FontContext
impl Send for FontContext
impl Sync for FontContext
impl Unpin for FontContext
impl UnsafeUnpin for FontContext
impl !UnwindSafe for FontContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more