aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/platform
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-02-22 10:49:52 -0500
committerGitHub <noreply@github.com>2018-02-22 10:49:52 -0500
commitf48dce120dddd8e3d585cfc8bc221faa2726bf6b (patch)
treee679c13ca398702a5b0be3a9d70a09ee8c2ff7ff /components/gfx/platform
parenta0e340d68f5a51d61a69b0bc16f543d3cef54597 (diff)
parente4acb3f77f12e0d42fb8084dafbf5de59f7a1c1b (diff)
downloadservo-f48dce120dddd8e3d585cfc8bc221faa2726bf6b.tar.gz
servo-f48dce120dddd8e3d585cfc8bc221faa2726bf6b.zip
Auto merge of #20021 - jonleighton:lazy-font-group, r=mbrubeck,glennw
Lazy load fonts in a FontGroup The first commit message explains this so I'll just copy it here: --- This is a step towards fixing #17267. To fix that, we need to be able to try various different fallback fonts in turn, which would become unweildy with the prior eager-loading strategy. Prior to this change, FontGroup loaded up all Font instances, including the fallback font, before any of them were checked for the presence of the glyphs we're trying to render. So for the following CSS: font-family: Helvetica, Arial; The FontGroup would contain a Font instance for Helvetica, and a Font instance for Arial, and a Font instance for the fallback font. It may be that Helvetica contains glyphs for every character in the document, and therefore Arial and the fallback font are not needed at all. This change makes the strategy lazy, so that we'll only create a Font for Arial if we cannot find a glyph within Helvetica. I've also substantially refactored the existing code in the process and added some documentation along the way. --- I've added some tests in the second commit, but it required quite a bit of gymnastics to make it possible to write such a test. I'm not sure if the added complexity to the production code is worth it? On the other hand, having this infrastructure in place may be useful for testing future changes in this area, and also possibly brings us a step closer to extracting a library as discussed in #4901. (What I mean by that is: it reduces coupling between `FontCacheThread` and `FontContext` -- the latter would have a place in such a library, the former wouldn't.) <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20021) <!-- Reviewable:end -->
Diffstat (limited to 'components/gfx/platform')
-rw-r--r--components/gfx/platform/freetype/font.rs5
-rw-r--r--components/gfx/platform/macos/font.rs5
-rw-r--r--components/gfx/platform/windows/font.rs5
3 files changed, 15 insertions, 0 deletions
diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs
index f0092b9a646..57b8861ed96 100644
--- a/components/gfx/platform/freetype/font.rs
+++ b/components/gfx/platform/freetype/font.rs
@@ -17,6 +17,7 @@ use freetype::freetype::FT_Sfnt_Tag;
use freetype::tt_os2::TT_OS2;
use platform::font_context::FontContextHandle;
use platform::font_template::FontTemplateData;
+use servo_atoms::Atom;
use std::{mem, ptr};
use std::os::raw::{c_char, c_long};
use std::sync::Arc;
@@ -306,6 +307,10 @@ impl FontHandleMethods for FontHandle {
Some(FontTable { buffer: buf })
}
}
+
+ fn identifier(&self) -> Atom {
+ self.font_data.identifier.clone()
+ }
}
impl<'a> FontHandle {
diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs
index b14d30e6cca..ca719ddf5b7 100644
--- a/components/gfx/platform/macos/font.rs
+++ b/components/gfx/platform/macos/font.rs
@@ -18,6 +18,7 @@ use font::{FontHandleMethods, FontMetrics, FontTableMethods, FontTableTag, Fract
use font::{GPOS, GSUB, KERN};
use platform::font_template::FontTemplateData;
use platform::macos::font_context::FontContextHandle;
+use servo_atoms::Atom;
use std::{fmt, ptr};
use std::ops::Range;
use std::sync::Arc;
@@ -318,4 +319,8 @@ impl FontHandleMethods for FontHandle {
Some(FontTable::wrap(data))
})
}
+
+ fn identifier(&self) -> Atom {
+ self.font_data.identifier.clone()
+ }
}
diff --git a/components/gfx/platform/windows/font.rs b/components/gfx/platform/windows/font.rs
index 5a7433d26f7..12df6d547d2 100644
--- a/components/gfx/platform/windows/font.rs
+++ b/components/gfx/platform/windows/font.rs
@@ -15,6 +15,7 @@ use font::{FontTableTag, FractionalPixel};
use platform::font_template::FontTemplateData;
use platform::windows::font_context::FontContextHandle;
use platform::windows::font_list::font_from_atom;
+use servo_atoms::Atom;
use std::sync::Arc;
use style::computed_values::font_stretch::T as StyleFontStretch;
use style::computed_values::font_weight::T as StyleFontWeight;
@@ -374,4 +375,8 @@ impl FontHandleMethods for FontHandle {
fn table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {
self.face.get_font_table(tag).map(|bytes| FontTable { data: bytes })
}
+
+ fn identifier(&self) -> Atom {
+ self.font_data.identifier.clone()
+ }
}