mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Always include the last-resort font
This is used as a fallback for any characters that don't have glyphs in the specified font.
This commit is contained in:
parent
2d5dc8fa6d
commit
e588943b4f
258 changed files with 127 additions and 905 deletions
|
@ -223,38 +223,35 @@ impl FontContext {
|
|||
}
|
||||
}
|
||||
|
||||
// If unable to create any of the specified fonts, create one from the
|
||||
// list of last resort fonts for this platform.
|
||||
if fonts.is_empty() {
|
||||
let mut cache_hit = false;
|
||||
for cached_font_entry in &self.fallback_font_cache {
|
||||
let cached_font = cached_font_entry.font.borrow();
|
||||
if cached_font.descriptor == desc &&
|
||||
cached_font.requested_pt_size == style.font_size &&
|
||||
cached_font.variant == style.font_variant {
|
||||
fonts.push(cached_font_entry.font.clone());
|
||||
cache_hit = true;
|
||||
break;
|
||||
}
|
||||
// Add a last resort font as a fallback option.
|
||||
let mut cache_hit = false;
|
||||
for cached_font_entry in &self.fallback_font_cache {
|
||||
let cached_font = cached_font_entry.font.borrow();
|
||||
if cached_font.descriptor == desc &&
|
||||
cached_font.requested_pt_size == style.font_size &&
|
||||
cached_font.variant == style.font_variant {
|
||||
fonts.push(cached_font_entry.font.clone());
|
||||
cache_hit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if !cache_hit {
|
||||
let template_info = self.font_cache_thread.last_resort_font_template(desc.clone());
|
||||
let layout_font = self.create_layout_font(template_info.font_template,
|
||||
desc.clone(),
|
||||
style.font_size,
|
||||
style.font_variant,
|
||||
template_info.font_key);
|
||||
match layout_font {
|
||||
Ok(layout_font) => {
|
||||
let layout_font = Rc::new(RefCell::new(layout_font));
|
||||
self.fallback_font_cache.push(FallbackFontCacheEntry {
|
||||
font: layout_font.clone(),
|
||||
});
|
||||
fonts.push(layout_font);
|
||||
}
|
||||
Err(_) => debug!("Failed to create fallback layout font!")
|
||||
if !cache_hit {
|
||||
let template_info = self.font_cache_thread.last_resort_font_template(desc.clone());
|
||||
let layout_font = self.create_layout_font(template_info.font_template,
|
||||
desc.clone(),
|
||||
style.font_size,
|
||||
style.font_variant,
|
||||
template_info.font_key);
|
||||
match layout_font {
|
||||
Ok(layout_font) => {
|
||||
let layout_font = Rc::new(RefCell::new(layout_font));
|
||||
self.fallback_font_cache.push(FallbackFontCacheEntry {
|
||||
font: layout_font.clone(),
|
||||
});
|
||||
fonts.push(layout_font);
|
||||
}
|
||||
Err(_) => debug!("Failed to create fallback layout font!")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1971,6 +1971,11 @@ impl Fragment {
|
|||
}
|
||||
}
|
||||
SpecificFragmentInfo::ScannedText(ref text_fragment) => {
|
||||
// Fragments with no glyphs don't contribute any inline metrics.
|
||||
// TODO: Filter out these fragments during flow construction?
|
||||
if text_fragment.content_size.inline == Au(0) {
|
||||
return InlineMetrics::new(Au(0), Au(0), Au(0));
|
||||
}
|
||||
// See CSS 2.1 § 10.8.1.
|
||||
let line_height = self.calculate_line_height(layout_context);
|
||||
let font_derived_metrics =
|
||||
|
|
|
@ -197,17 +197,12 @@ impl TextRunScanner {
|
|||
for (byte_index, character) in text.char_indices() {
|
||||
// Search for the first font in this font group that contains a glyph for this
|
||||
// character.
|
||||
let mut font_index = 0;
|
||||
let font_index = fontgroup.fonts.iter().position(|font| {
|
||||
font.borrow().glyph_index(character).is_some()
|
||||
}).unwrap_or(0);
|
||||
|
||||
// The following code panics one way or another if this condition isn't met.
|
||||
assert!(fontgroup.fonts.len() > 0);
|
||||
while font_index < fontgroup.fonts.len() - 1 {
|
||||
if fontgroup.fonts.get(font_index).unwrap().borrow()
|
||||
.glyph_index(character)
|
||||
.is_some() {
|
||||
break
|
||||
}
|
||||
font_index += 1;
|
||||
}
|
||||
|
||||
let bidi_level = match bidi_levels {
|
||||
Some(levels) => levels[*paragraph_bytes_processed],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue