Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions fontique/src/collection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,19 @@ impl Inner {
/// Returns the family object for the given family identifier.
pub fn family(&mut self, id: FamilyId) -> Option<FamilyInfo> {
self.sync_shared();

if let Some(family) = self.data.families.get(&id) {
family.as_ref().cloned()
} else {
#[cfg(feature = "system")]
if let Some(system) = &self.system {
let family = system.fonts.lock().unwrap().family(id);
self.data.families.insert(id, family.clone());
family
} else {
None
}
#[cfg(not(feature = "system"))]
{
None
}
return family.as_ref().cloned();
}

#[cfg(feature = "system")]
if let Some(system) = &self.system {
let family = system.fonts.lock().unwrap().family(id);
self.data.families.insert(id, family.clone());
return family;
}

None
}

/// Returns the family object for the given name.
Expand Down
32 changes: 20 additions & 12 deletions parley/src/analysis/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
use alloc::vec::Vec;
use icu_normalizer::properties::Decomposed;

use crate::analysis::AnalysisDataSources;
use crate::{analysis::AnalysisDataSources, emoji::EmojiPresentationStyle};

/// The maximum number of characters in a single cluster.
const MAX_CLUSTER_SIZE: usize = 32;

#[derive(Debug, Default)]
pub(crate) struct CharCluster {
pub chars: Vec<Char>,
pub is_emoji: bool,
pub map_len: u8,
pub start: u32,
pub end: u32,
pub force_normalize: bool,
pub emoji_presentation_style: EmojiPresentationStyle,
comp: Form,
decomp: Form,
form: FormKind,
Expand Down Expand Up @@ -52,6 +52,8 @@ pub(crate) struct Char {
/// Indexes into the list of styles for the containing text run, to find the style applicable
/// to this character.
pub style_index: u16,
/// Whether the emoji presentation selector
pub is_emoji_presentation_selector: bool,
}

pub(crate) type GlyphId = u16;
Expand Down Expand Up @@ -93,7 +95,6 @@ pub(crate) enum Status {
impl CharCluster {
pub(crate) fn clear(&mut self) {
self.chars.clear();
self.is_emoji = false;
self.map_len = 0;
self.start = 0;
self.end = 0;
Expand All @@ -102,6 +103,7 @@ impl CharCluster {
self.decomp.clear();
self.form = FormKind::Original;
self.best_ratio = 0.;
self.emoji_presentation_style = EmojiPresentationStyle::Default;
}

#[inline(always)]
Expand Down Expand Up @@ -351,17 +353,23 @@ impl<'a> Mapper<'a> {
}
let mut mapped = 0;
for (c, g) in self.chars.iter().zip(glyphs.iter_mut()) {
if !c.contributes_to_shaping {
*g = f(c.ch);
if self.map_len == 1 {
mapped += 1;
}
} else {
let gid = f(c.ch);
*g = gid;
if gid != 0 {
*g = f(c.ch);

// If the color emoji has a presentation style, ignore the variation selector.
if c.is_emoji_presentation_selector {
mapped += 1;
continue;
}

if c.contributes_to_shaping {
if *g != 0 {
mapped += 1;
}
continue;
}

if self.map_len == 1 {
mapped += 1;
}
}
let ratio = mapped as f32 / self.map_len as f32;
Expand Down
23 changes: 21 additions & 2 deletions parley/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ use icu_normalizer::properties::{
CanonicalComposition, CanonicalCompositionBorrowed, CanonicalDecomposition,
CanonicalDecompositionBorrowed,
};
use icu_properties::props::{BidiMirroringGlyph, GeneralCategory, GraphemeClusterBreak, Script};
use icu_properties::props::{
BidiMirroringGlyph, EmojiModifier, EmojiModifierBase, EmojiPresentation, GeneralCategory,
GraphemeClusterBreak, Script,
};
use icu_properties::{
CodePointMapData, CodePointMapDataBorrowed, PropertyNamesShort, PropertyNamesShortBorrowed,
CodePointMapData, CodePointMapDataBorrowed, CodePointSetData, CodePointSetDataBorrowed,
PropertyNamesShort, PropertyNamesShortBorrowed,
};
use icu_segmenter::options::{LineBreakOptions, LineBreakWordOption, WordBreakInvariantOptions};
use icu_segmenter::{
Expand Down Expand Up @@ -92,6 +96,21 @@ impl AnalysisDataSources {
fn brackets(&self) -> CodePointMapDataBorrowed<'_, BidiMirroringGlyph> {
const { CodePointMapData::new() }
}

#[inline(always)]
pub(crate) fn emoji_modifier(&self) -> CodePointSetDataBorrowed<'_> {
const { CodePointSetData::new::<EmojiModifier>() }
}

#[inline(always)]
pub(crate) fn emoji_modifier_base(&self) -> CodePointSetDataBorrowed<'_> {
const { CodePointSetData::new::<EmojiModifierBase>() }
}

#[inline(always)]
pub(crate) fn emoji_presentation(&self) -> CodePointSetDataBorrowed<'_> {
const { CodePointSetData::new::<EmojiPresentation>() }
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
Loading
Loading