Skip to content

Commit

Permalink
removal of font mod
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Feb 16, 2024
1 parent 3132205 commit aa1c229
Show file tree
Hide file tree
Showing 20 changed files with 23 additions and 2,602 deletions.
23 changes: 12 additions & 11 deletions sugarloaf/src/font/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ use fnv::FnvHashMap;
use std::ops::Index;
use std::ops::IndexMut;
use swash::proxy::CharmapProxy;
use swash::text::cluster::{Char, CharCluster, Status};
use swash::Attributes;
use swash::CacheKey;
use swash::Charmap;
use swash::FontRef;
use swash::Synthesis;
use swash::text::cluster::{CharCluster, Status};
use swash::{Attributes, CacheKey, Charmap, FontRef, Synthesis};

pub use swash::{Style, Weight};

#[derive(Default)]
pub struct FontLibrary {
Expand Down Expand Up @@ -58,6 +56,11 @@ impl FontLibrary {
self.inner.is_empty()
}

#[inline]
pub fn font_by_id(&self, font_id: usize) -> FontRef {
self.inner[font_id].as_ref()
}

#[inline]
pub fn lookup_for_best_font(
&mut self,
Expand Down Expand Up @@ -88,10 +91,8 @@ impl FontLibrary {
let mut font_id = FONT_ID_REGULAR;
if let Some(cached_font_id) = self.cache.get(&chars[0].ch) {
font_id = *cached_font_id;
} else {
if cluster.info().is_emoji() {
font_id = FONT_ID_EMOJIS_NATIVE;
}
} else if cluster.info().is_emoji() {
font_id = FONT_ID_EMOJIS_NATIVE;
}

let charmap = self.inner[font_id]
Expand Down Expand Up @@ -184,7 +185,7 @@ impl FontData {

#[inline]
pub fn from_slice(data: &[u8]) -> Result<Self, Box<dyn std::error::Error>> {
let font = FontRef::from_index(&data, 0).unwrap();
let font = FontRef::from_index(data, 0).unwrap();
let (offset, key) = (font.offset, font.key);
// Return our struct with the original file data and copies of the
// offset and key from the font reference
Expand Down
6 changes: 3 additions & 3 deletions sugarloaf/src/layout/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::builder_data::*;
use super::span_style::*;
use super::Paragraph;
use super::{SpanId, MAX_ID};
use crate::font::{FontData, FontLibrary};
use crate::font::FontLibrary;
use core::borrow::Borrow;
use swash::shape::{self, ShapeContext};
use swash::text::cluster::{CharCluster, CharInfo, Parser, Token};
Expand Down Expand Up @@ -583,9 +583,9 @@ where
}

let current_font_id = state.font_id.unwrap();
let font = fcx[current_font_id].clone();
let font = fcx.inner[current_font_id].clone();
let mut shaper = scx
.builder(font.as_ref())
.builder(&font)
.script(state.script)
.language(state.span.lang)
.direction(dir)
Expand Down
3 changes: 1 addition & 2 deletions sugarloaf/src/layout/builder_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use super::span_style::*;
use super::{SpanId, MAX_ID};
use crate::font::FontLibrary;
use crate::sugarloaf::primitives::SugarCursor;
use core::borrow::Borrow;
use swash::text::{cluster::CharInfo, Script};
Expand Down Expand Up @@ -204,7 +203,7 @@ impl BuilderState {
}
let parent_id = *self.span_stack.last()?;
let parent = self.spans.get_mut(parent_id.to_usize())?;
let mut span = parent.clone();
let mut span = parent.to_owned();
let last_child = if let Some(last_child) = parent.last_child {
parent.last_child = Some(next_id);
Some(last_child)
Expand Down
Loading

0 comments on commit aa1c229

Please sign in to comment.