Changed the file structure

This commit is contained in:
Eduardo Flores 2022-10-12 19:44:44 -07:00 committed by Michael Murphy
parent 7743d0d084
commit 420d3c3dfc
22 changed files with 409 additions and 395 deletions

View file

@ -66,7 +66,8 @@ impl<'a> FontLayoutLine<'a> {
// Compute the fractional offset-- you'll likely want to quantize this
// in a real renderer
let offset = Vector::new(cache_key.x_bin.as_float(), cache_key.y_bin.as_float());
let offset =
Vector::new(cache_key.x_bin.as_float(), cache_key.y_bin.as_float());
// Select our source order
Render::new(&[
@ -77,12 +78,12 @@ impl<'a> FontLayoutLine<'a> {
// Standard scalable outline
Source::Outline,
])
// Select a subpixel format
.format(Format::Alpha)
// Apply the fractional offset
.offset(offset)
// Render the image
.render(&mut scaler, cache_key.glyph_id)
// Select a subpixel format
.format(Format::Alpha)
// Apply the fractional offset
.offset(offset)
// Render the image
.render(&mut scaler, cache_key.glyph_id)
});
if let Some(ref image) = image_opt {
@ -96,28 +97,25 @@ impl<'a> FontLayoutLine<'a> {
let mut i = 0;
for off_y in 0..image.placement.height as i32 {
for off_x in 0..image.placement.width as i32 {
let color =
(image.data[i] as u32) << 24 |
base & 0xFFFFFF;
let color = (image.data[i] as u32) << 24 | base & 0xFFFFFF;
f(x + off_x, y + off_y, color);
i += 1;
}
}
},
}
Content::Color => {
let mut i = 0;
for off_y in 0..image.placement.height as i32 {
for off_x in 0..image.placement.width as i32 {
let color =
(image.data[i + 3] as u32) << 24 |
(image.data[i] as u32) << 16 |
(image.data[i + 1] as u32) << 8 |
(image.data[i + 2] as u32);
let color = (image.data[i + 3] as u32) << 24
| (image.data[i] as u32) << 16
| (image.data[i + 1] as u32) << 8
| (image.data[i + 2] as u32);
f(x + off_x, y + off_y, color);
i += 4;
}
}
},
}
Content::SubpixelMask => {
println!("TODO: SubpixelMask");
}

View file

@ -5,7 +5,15 @@ pub struct FontMatches<'a> {
}
impl<'a> FontMatches<'a> {
fn shape_fallback(&self, font_i: usize, line: &str, start_word: usize, end_word: usize, span_rtl: bool, blank: bool) -> (Vec<FontShapeGlyph>, Vec<usize>) {
fn shape_fallback(
&self,
font_i: usize,
line: &str,
start_word: usize,
end_word: usize,
span_rtl: bool,
blank: bool,
) -> (Vec<FontShapeGlyph>, Vec<usize>) {
let word = &line[start_word..end_word];
let font_scale = self.fonts[font_i].rustybuzz.units_per_em() as f32;
@ -101,15 +109,24 @@ impl<'a> FontMatches<'a> {
(glyphs, missing)
}
fn shape_word(&self, line: &str, start_word: usize, end_word: usize, span_rtl: bool, blank: bool) -> FontShapeWord {
fn shape_word(
&self,
line: &str,
start_word: usize,
end_word: usize,
span_rtl: bool,
blank: bool,
) -> FontShapeWord {
let mut font_i = 0;
let (mut glyphs, mut missing) = self.shape_fallback(font_i, line, start_word, end_word, span_rtl, blank);
let (mut glyphs, mut missing) =
self.shape_fallback(font_i, line, start_word, end_word, span_rtl, blank);
//TODO: improve performance!
font_i += 1;
while !missing.is_empty() && font_i < self.fonts.len() {
// println!("Evaluating fallback with font {}", font_i);
let (mut fb_glyphs, fb_missing) = self.shape_fallback(font_i, line, start_word, end_word, span_rtl, blank);
let (mut fb_glyphs, fb_missing) =
self.shape_fallback(font_i, line, start_word, end_word, span_rtl, blank);
// Insert all matching glyphs
let mut fb_i = 0;
@ -187,7 +204,11 @@ impl<'a> FontMatches<'a> {
) -> FontShapeSpan {
let span = &line[start_span..end_span];
log::debug!(" Span {}: '{}'", if span_rtl { "RTL" } else { "LTR" }, span);
log::debug!(
" Span {}: '{}'",
if span_rtl { "RTL" } else { "LTR" },
span
);
let mut words = Vec::new();
@ -202,10 +223,22 @@ impl<'a> FontMatches<'a> {
}
}
if start_word < start_lb {
words.push(self.shape_word(line, start_span + start_word, start_span + start_lb, span_rtl, false));
words.push(self.shape_word(
line,
start_span + start_word,
start_span + start_lb,
span_rtl,
false,
));
}
if start_lb < end_lb {
words.push(self.shape_word(line, start_span + start_lb, start_span + end_lb, span_rtl, true));
words.push(self.shape_word(
line,
start_span + start_lb,
start_span + end_lb,
span_rtl,
true,
));
}
start_word = end_lb;
}

View file

@ -1,7 +1,4 @@
use std::{
collections::HashMap,
sync::Mutex,
};
use std::{collections::HashMap, sync::Mutex};
pub use self::cache::*;
mod cache;
@ -21,7 +18,6 @@ mod system;
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct FontCacheKey {
glyph_id: u16,
}
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]

View file

@ -26,27 +26,24 @@ impl<'a> FontShapeGlyph<'a> {
let x_advance = font_size as f32 * self.x_advance;
#[cfg(feature = "ab_glyph")]
let inner = self.font.ab_glyph.outline_glyph(
self.inner.with_scale_and_position(
let inner = self
.font
.ab_glyph
.outline_glyph(self.inner.with_scale_and_position(
font_size as f32,
ab_glyph::point(
x + x_offset,
y - y_offset,
)
)
);
ab_glyph::point(x + x_offset, y - y_offset),
));
#[cfg(feature = "rusttype")]
let inner = self.font.rusttype.glyph(self.inner)
let inner = self
.font
.rusttype
.glyph(self.inner)
.scaled(rusttype::Scale::uniform(font_size as f32))
.positioned(rusttype::point(x + x_offset, y - y_offset));
#[cfg(feature = "swash")]
let inner = CacheKey::new(
self.inner,
font_size,
(x + x_offset, y - y_offset),
);
let inner = CacheKey::new(self.inner, font_size, (x + x_offset, y - y_offset));
FontLayoutGlyph {
start: self.start,

View file

@ -30,31 +30,28 @@ impl FontSystem {
}
}
Self {
db,
}
Self { db }
}
pub fn matches<'a, F: Fn(&fontdb::FaceInfo) -> bool>(&'a self, f: F) -> Option<FontMatches<'a>> {
pub fn matches<'a, F: Fn(&fontdb::FaceInfo) -> bool>(
&'a self,
f: F,
) -> Option<FontMatches<'a>> {
let mut fonts = Vec::new();
for face in self.db.faces() {
if ! f(face) {
if !f(face) {
continue;
}
let font_opt = Font::new(
&face.post_script_name,
match &face.source {
fontdb::Source::Binary(data) => {
data.deref().as_ref()
},
fontdb::Source::Binary(data) => data.deref().as_ref(),
fontdb::Source::File(path) => {
println!("Unsupported fontdb Source::File('{}')", path.display());
continue;
},
fontdb::Source::SharedFile(_path, data) => {
data.deref().as_ref()
},
}
fontdb::Source::SharedFile(_path, data) => data.deref().as_ref(),
},
face.index,
);
@ -67,10 +64,8 @@ impl FontSystem {
}
}
if ! fonts.is_empty() {
Some(FontMatches {
fonts
})
if !fonts.is_empty() {
Some(FontMatches { fonts })
} else {
None
}