This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5871de
commit 81040d3
Showing
5 changed files
with
254 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::usvg::text::{AlignmentBaseline, BaselineShift, DominantBaseline, Font, LengthAdjust}; | ||
use ordered_float::OrderedFloat; | ||
use rust_lapper::Interval; | ||
|
||
// TODO: Make attribute partial? So that they can actually overlap in a useful manner. | ||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
pub struct Attribute { | ||
/// A font. | ||
pub font: Font, | ||
/// A font size. | ||
pub font_size: OrderedFloat<f32>, | ||
/// Indicates that small caps should be used. | ||
/// | ||
/// Set by `font-variant="small-caps"` | ||
pub small_caps: bool, | ||
/// Indicates that a kerning should be applied. | ||
/// | ||
/// Supports both `kerning` and `font-kerning` properties. | ||
pub apply_kerning: bool, | ||
/// A span dominant baseline. | ||
pub dominant_baseline: DominantBaseline, | ||
/// A span alignment baseline. | ||
pub alignment_baseline: AlignmentBaseline, | ||
/// A list of all baseline shift that should be applied to this span. | ||
/// | ||
/// Ordered from `text` element down to the actual `span` element. | ||
pub baseline_shift: Vec<BaselineShift>, | ||
/// A letter spacing property. | ||
pub letter_spacing: OrderedFloat<f32>, | ||
/// A word spacing property. | ||
pub word_spacing: OrderedFloat<f32>, | ||
/// A text length property. | ||
pub text_length: Option<OrderedFloat<f32>>, | ||
/// A length adjust property. | ||
pub length_adjust: LengthAdjust, | ||
} | ||
|
||
pub type AttributeInterval = Interval<usize, Attribute>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::usvg::{database::FontsCache, resolve_font, resolved_font::ResolvedFont, text::Font}; | ||
use std::sync::Arc; | ||
|
||
pub fn resolve_font_from_cache<'a>( | ||
font: &Font, | ||
fonts_cache: &'a mut FontsCache, | ||
fontdb: &fontdb::Database, | ||
) -> Option<&'a Arc<ResolvedFont>> { | ||
// Check if the font is already in the cache | ||
if !fonts_cache.contains_key(font) { | ||
if let Some(resolved_font) = resolve_font(font, fontdb) { | ||
fonts_cache.insert(font.clone(), Arc::new(resolved_font)); | ||
} else { | ||
return None; | ||
} | ||
} | ||
|
||
return fonts_cache.get(font); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.