Rasterizer uses DPI from Glutin

This commit is contained in:
Joe Wilm 2016-02-27 20:26:31 -08:00
parent 1bf7bb8e12
commit c8b69412b2
4 changed files with 24 additions and 10 deletions

12
Cargo.lock generated
View File

@ -6,7 +6,7 @@ dependencies = [
"euclid 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gl 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.4.9 (git+https://github.com/jwilm/glutin?rev=c95e6973ace3cbf321123a64588b27f032675be9)",
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-fontconfig 0.2.0 (git+https://github.com/jwilm/rust-fontconfig)",
]
@ -205,8 +205,8 @@ dependencies = [
[[package]]
name = "glutin"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
version = "0.4.9"
source = "git+https://github.com/jwilm/glutin?rev=c95e6973ace3cbf321123a64588b27f032675be9#c95e6973ace3cbf321123a64588b27f032675be9"
dependencies = [
"android_glue 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cgl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -229,7 +229,7 @@ dependencies = [
"wayland-kbd 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wayland-window 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"x11-dl 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"x11-dl 2.4.0 (git+https://github.com/jwilm/x11-rs?rev=40f08df7b4408980b922b3c6e258c9c6765c2c24)",
]
[[package]]
@ -481,8 +481,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "x11-dl"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
version = "2.4.0"
source = "git+https://github.com/jwilm/x11-rs?rev=40f08df7b4408980b922b3c6e258c9c6765c2c24#40f08df7b4408980b922b3c6e258c9c6765c2c24"
dependencies = [
"dylib 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -8,7 +8,12 @@ license = "Apache-2.0"
servo-fontconfig = { git = "https://github.com/jwilm/rust-fontconfig" }
freetype-rs = "0.5.0"
libc = "*"
glutin = "*"
gl = "*"
cgmath = "0.7"
euclid = "0.6"
[dependencies.glutin]
git = "https://github.com/jwilm/glutin"
rev = "c95e6973ace3cbf321123a64588b27f032675be9"
# version = "*"
# path = "../glutin"

View File

@ -26,8 +26,11 @@ fn main() {
gl::Viewport(0, 0, width as i32, height as i32);
}
let (dpi_x, dpi_y) = window.get_dpi().unwrap();
let dpr = window.hidpi_factor();
let desc = FontDesc::new("Ubuntu Mono", "Regular");
let mut rasterizer = text::Rasterizer::new();
let mut rasterizer = text::Rasterizer::new(dpi_x, dpi_y, dpr);
let glyph_r = Glyph::new(&rasterizer.get_glyph(&desc, 180., 'R'));
let glyph_u = Glyph::new(&rasterizer.get_glyph(&desc, 180., 'u'));

View File

@ -10,6 +10,9 @@ pub struct Rasterizer {
faces: HashMap<FontDesc, Face<'static>>,
library: Library,
system_fonts: HashMap<String, ::list_fonts::Family>,
dpi_x: u32,
dpi_y: u32,
dpr: f32,
}
#[inline]
@ -35,13 +38,16 @@ impl FontDesc {
}
impl Rasterizer {
pub fn new() -> Rasterizer {
pub fn new(dpi_x: f32, dpi_y: f32, device_pixel_ratio: f32) -> Rasterizer {
let library = Library::init().unwrap();
Rasterizer {
system_fonts: get_font_families(),
faces: HashMap::new(),
library: library,
dpi_x: dpi_x as u32,
dpi_y: dpi_y as u32,
dpr: device_pixel_ratio,
}
}
@ -66,7 +72,7 @@ impl Rasterizer {
pub fn get_glyph(&mut self, desc: &FontDesc, size: f32, c: char) -> RasterizedGlyph {
let face = self.get_face(desc).expect("TODO handle get_face error");
// TODO DPI
face.set_char_size(to_freetype_26_6(size), 0, 96, 0).unwrap();
face.set_char_size(to_freetype_26_6(size * self.dpr), 0, self.dpi_x, self.dpi_y).unwrap();
face.load_char(c as usize, freetype::face::RENDER).unwrap();
let glyph = face.glyph();