Skip to content

Commit

Permalink
More.
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon committed Feb 17, 2024
1 parent b54e2e0 commit 4aa25ae
Show file tree
Hide file tree
Showing 32 changed files with 1,215 additions and 778 deletions.
5 changes: 3 additions & 2 deletions src/aat/extended_kerning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use ttf_parser::{ankr, apple_layout, kerx, FromData, GlyphId};
use crate::buffer::{hb_buffer_t, BufferScratchFlags};
use crate::hb_font_t;
use crate::ot::matching::SkippyIter;
use crate::ot::{attach_type, lookup_flags, ApplyContext, TableIndex};
use crate::plan::hb_ot_shape_plan_t;
use crate::ot::{attach_type, lookup_flags, ApplyContext};
use crate::ot_layout::TableIndex;
use crate::shape_plan::hb_ot_shape_plan_t;

trait ExtendedStateTableExt<T: FromData + Copy> {
fn class(&self, glyph_id: GlyphId) -> Option<u16>;
Expand Down
2 changes: 1 addition & 1 deletion src/aat/metamorphosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ttf_parser::{apple_layout, morx, FromData, GlyphId, LazyArray32};
use crate::aat::feature_selector;
use crate::aat::{FeatureType, Map, MapBuilder};
use crate::buffer::hb_buffer_t;
use crate::plan::hb_ot_shape_plan_t;
use crate::shape_plan::hb_ot_shape_plan_t;
use crate::{hb_font_t, GlyphInfo};

pub fn compile_flags(face: &hb_font_t, builder: &MapBuilder) -> Option<Map> {
Expand Down
2 changes: 1 addition & 1 deletion src/aat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use map::*;

use crate::buffer::hb_buffer_t;
use crate::hb_font_t;
use crate::plan::hb_ot_shape_plan_t;
use crate::shape_plan::hb_ot_shape_plan_t;

pub fn substitute(plan: &hb_ot_shape_plan_t, face: &hb_font_t, buffer: &mut hb_buffer_t) {
metamorphosis::apply(plan, face, buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/aat/tracking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::buffer::hb_buffer_t;
use crate::hb_font_t;
use crate::plan::hb_ot_shape_plan_t;
use crate::shape_plan::hb_ot_shape_plan_t;

pub fn apply(plan: &hb_ot_shape_plan_t, face: &hb_font_t, buffer: &mut hb_buffer_t) -> Option<()> {
let trak_mask = plan.trak_mask;
Expand Down
57 changes: 6 additions & 51 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use ttf_parser::GlyphId;

use crate::buffer::glyph_flag::{UNSAFE_TO_BREAK, UNSAFE_TO_CONCAT};
use crate::face::GlyphExtents;
use crate::ot::_hb_glyph_info_get_modified_combining_class;
use crate::unicode::{CharExt, GeneralCategory, GeneralCategoryExt, Space};
use crate::ot_layout::_hb_glyph_info_get_general_category;
use crate::unicode::{hb_unicode_general_category_t, CharExt, GeneralCategoryExt};
use crate::{hb_font_t, script, Direction, Language, Mask, Script};

const CONTEXT_LENGTH: usize = 5;
Expand Down Expand Up @@ -230,7 +230,7 @@ impl hb_glyph_info_t {
}

#[inline]
fn set_unicode_props(&mut self, n: u16) {
pub(crate) fn set_unicode_props(&mut self, n: u16) {
let v: &mut [u16; 2] = bytemuck::cast_mut(&mut self.var2);
v[0] = n;
}
Expand Down Expand Up @@ -284,68 +284,23 @@ impl hb_glyph_info_t {
self.set_unicode_props(props);
}

#[inline]
pub(crate) fn general_category(&self) -> GeneralCategory {
let n = self.unicode_props() & UnicodeProps::GENERAL_CATEGORY.bits();
GeneralCategory::from_rb(n as u32)
}

#[inline]
pub(crate) fn set_general_category(&mut self, gc: GeneralCategory) {
let gc = gc.to_rb();
let n =
(gc as u16) | (self.unicode_props() & (0xFF & !UnicodeProps::GENERAL_CATEGORY.bits()));
self.set_unicode_props(n);
}

#[inline]
pub(crate) fn space_fallback(&self) -> Option<Space> {
if self.general_category() == GeneralCategory::SpaceSeparator {
let n = (self.unicode_props() >> 8) as u8;
Some(n)
} else {
None
}
}

#[inline]
pub(crate) fn set_space_fallback(&mut self, space: Space) {
if self.general_category() == GeneralCategory::SpaceSeparator {
let n = ((space as u16) << 8) | (self.unicode_props() & 0xFF);
self.set_unicode_props(n);
}
}

#[inline]
pub(crate) fn is_unicode_mark(&self) -> bool {
self.general_category().is_mark()
_hb_glyph_info_get_general_category(self).is_mark()
}

#[inline]
pub(crate) fn is_zwnj(&self) -> bool {
self.general_category() == GeneralCategory::Format
_hb_glyph_info_get_general_category(self) == hb_unicode_general_category_t::Format
&& (self.unicode_props() & UnicodeProps::CF_ZWNJ.bits() != 0)
}

#[inline]
pub(crate) fn is_zwj(&self) -> bool {
self.general_category() == GeneralCategory::Format
_hb_glyph_info_get_general_category(self) == hb_unicode_general_category_t::Format
&& (self.unicode_props() & UnicodeProps::CF_ZWJ.bits() != 0)
}

#[inline]
pub(crate) fn modified_combining_class(&self) -> u8 {
_hb_glyph_info_get_modified_combining_class(self)
}

#[inline]
pub(crate) fn set_modified_combining_class(&mut self, mcc: u8) {
if self.is_unicode_mark() {
let n = ((mcc as u16) << 8) | (self.unicode_props() & 0xFF);
self.set_unicode_props(n);
}
}

#[inline]
pub(crate) fn is_hidden(&self) -> bool {
self.unicode_props() & UnicodeProps::HIDDEN.bits() != 0
Expand Down
31 changes: 17 additions & 14 deletions src/complex/arabic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use alloc::boxed::Box;

use super::*;
use crate::buffer::{hb_buffer_t, BufferScratchFlags};
use crate::ot::{feature, FeatureFlags};
use crate::ot::*;
use crate::ot_layout::*;
use crate::ot_shape_normalize::HB_OT_SHAPE_NORMALIZATION_MODE_AUTO;
use crate::plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::unicode::{
hb_gc, modified_combining_class, CharExt, GeneralCategory, GeneralCategoryExt,
};
use crate::shape_plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::unicode::*;
use crate::{hb_font_t, hb_glyph_info_t, script, Mask, Script, Tag};

pub const ARABIC_SHAPER: ComplexShaper = ComplexShaper {
Expand Down Expand Up @@ -377,7 +376,9 @@ fn apply_stch(face: &hb_font_t, buffer: &mut hb_buffer_t) {
while context != 0
&& !action::is_stch(buffer.info[context - 1].arabic_shaping_action())
&& (buffer.info[context - 1].is_default_ignorable()
|| is_word_category(buffer.info[context - 1].general_category()))
|| is_word_category(_hb_glyph_info_get_general_category(
&buffer.info[context - 1],
)))
{
context -= 1;
w_total += buffer.pos[context].x_advance;
Expand Down Expand Up @@ -447,7 +448,7 @@ fn apply_stch(face: &hb_font_t, buffer: &mut hb_buffer_t) {

// See:
// https://github.com/harfbuzz/harfbuzz/commit/6e6f82b6f3dde0fc6c3c7d991d9ec6cfff57823d#commitcomment-14248516
fn is_word_category(gc: GeneralCategory) -> bool {
fn is_word_category(gc: hb_unicode_general_category_t) -> bool {
(rb_flag_unsafe(gc.to_rb())
& (rb_flag(hb_gc::RB_UNICODE_GENERAL_CATEGORY_UNASSIGNED)
| rb_flag(hb_gc::RB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE)
Expand Down Expand Up @@ -503,8 +504,10 @@ fn arabic_joining(buffer: &mut hb_buffer_t) {
}

for i in 0..buffer.len {
let this_type =
get_joining_type(buffer.info[i].as_char(), buffer.info[i].general_category());
let this_type = get_joining_type(
buffer.info[i].as_char(),
_hb_glyph_info_get_general_category(&buffer.info[i]),
);
if this_type == JoiningType::T {
buffer.info[i].set_arabic_shaping_action(action::NONE);
continue;
Expand Down Expand Up @@ -573,7 +576,7 @@ fn mongolian_variation_selectors(buffer: &mut hb_buffer_t) {
}
}

fn get_joining_type(u: char, gc: GeneralCategory) -> JoiningType {
fn get_joining_type(u: char, gc: hb_unicode_general_category_t) -> JoiningType {
let j_type = super::arabic_table::joining_type(u);
if j_type != JoiningType::X {
return j_type;
Expand Down Expand Up @@ -612,21 +615,21 @@ const MODIFIER_COMBINING_MARKS: &[u32] = &[
fn reorder_marks(_: &hb_ot_shape_plan_t, buffer: &mut hb_buffer_t, mut start: usize, end: usize) {
let mut i = start;
for cc in [220u8, 230].iter().cloned() {
while i < end && buffer.info[i].modified_combining_class() < cc {
while i < end && _hb_glyph_info_get_modified_combining_class(&buffer.info[i]) < cc {
i += 1;
}

if i == end {
break;
}

if buffer.info[i].modified_combining_class() > cc {
if _hb_glyph_info_get_modified_combining_class(&buffer.info[i]) > cc {
continue;
}

let mut j = i;
while j < end
&& buffer.info[j].modified_combining_class() == cc
&& _hb_glyph_info_get_modified_combining_class(&buffer.info[j]) == cc
&& MODIFIER_COMBINING_MARKS.contains(&buffer.info[j].glyph_id)
{
j += 1;
Expand Down Expand Up @@ -668,7 +671,7 @@ fn reorder_marks(_: &hb_ot_shape_plan_t, buffer: &mut hb_buffer_t, mut start: us
};

while start < new_start {
buffer.info[start].set_modified_combining_class(new_cc);
_hb_glyph_info_set_modified_combining_class(&mut buffer.info[start], new_cc);
start += 1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/complex/hangul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
use crate::buffer::{hb_buffer_t, BufferClusterLevel, BufferFlags};
use crate::ot::{feature, FeatureFlags, Map};
use crate::ot_shape_normalize::HB_OT_SHAPE_NORMALIZATION_MODE_NONE;
use crate::plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::shape_plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::{hb_font_t, hb_glyph_info_t, Mask};

pub const HANGUL_SHAPER: ComplexShaper = ComplexShaper {
Expand Down Expand Up @@ -336,7 +336,7 @@ fn is_hangul_tone(u: u32) -> bool {
}

fn is_zero_width_char(face: &hb_font_t, c: char) -> bool {
if let Some(glyph) = face.glyph_index(c as u32) {
if let Some(glyph) = face.get_nominal_glyph(c as u32) {
face.glyph_h_advance(glyph) == 0
} else {
false
Expand Down
27 changes: 13 additions & 14 deletions src/complex/indic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use ttf_parser::GlyphId;

use super::*;
use crate::buffer::hb_buffer_t;
use crate::ot::{
feature, FeatureFlags, LayoutTable, Map, TableIndex, WouldApply, WouldApplyContext,
};
use crate::ot::{feature, FeatureFlags, Map, WouldApply, WouldApplyContext};
use crate::ot_layout::*;
use crate::ot_shape_normalize::HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT;
use crate::plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::shape_plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::unicode::{hb_gc, CharExt, GeneralCategoryExt};
use crate::{hb_font_t, hb_glyph_info_t, script, Mask, Script, Tag};

Expand Down Expand Up @@ -673,7 +672,7 @@ fn collect_features(planner: &mut ShapePlanner) {
planner.ot_map.add_gsub_pause(Some(final_reordering));
planner
.ot_map
.add_gsub_pause(Some(crate::ot::clear_syllables));
.add_gsub_pause(Some(crate::ot_layout::_hb_clear_syllables));

for feature in INDIC_FEATURES.iter().skip(10) {
planner.ot_map.add_feature(feature.0, feature.1, 1);
Expand Down Expand Up @@ -725,7 +724,7 @@ fn decompose(ctx: &hb_ot_shape_normalize_context_t, ab: char) -> Option<(char, c
// https://docs.microsoft.com/en-us/typography/script-development/sinhala#shaping

let mut ok = false;
if let Some(g) = ctx.face.glyph_index(u32::from(ab)) {
if let Some(g) = ctx.face.get_nominal_glyph(u32::from(ab)) {
let indic_plan = ctx.plan.data::<IndicShapePlan>();
ok = indic_plan
.pstf
Expand Down Expand Up @@ -811,7 +810,7 @@ fn update_consonant_positions(

let mut virama_glyph = None;
if indic_plan.config.virama != 0 {
virama_glyph = face.glyph_index(indic_plan.config.virama);
virama_glyph = face.get_nominal_glyph(indic_plan.config.virama);
}

if let Some(virama) = virama_glyph {
Expand Down Expand Up @@ -1472,7 +1471,7 @@ fn final_reordering(plan: &hb_ot_shape_plan_t, face: &hb_font_t, buffer: &mut hb

let mut virama_glyph = None;
if indic_plan.config.virama != 0 {
if let Some(g) = face.glyph_index(indic_plan.config.virama) {
if let Some(g) = face.get_nominal_glyph(indic_plan.config.virama) {
virama_glyph = Some(g.0 as u32);
}
}
Expand Down Expand Up @@ -1941,12 +1940,12 @@ fn final_reordering_impl(
// Apply 'init' to the Left Matra if it's a word start.
if buffer.info[start].indic_position() == position::PRE_M {
if start == 0
|| (rb_flag_unsafe(buffer.info[start - 1].general_category().to_rb())
& rb_flag_range(
hb_gc::RB_UNICODE_GENERAL_CATEGORY_FORMAT,
hb_gc::RB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK,
))
== 0
|| (rb_flag_unsafe(
_hb_glyph_info_get_general_category(&buffer.info[start - 1]).to_rb(),
) & rb_flag_range(
hb_gc::RB_UNICODE_GENERAL_CATEGORY_FORMAT,
hb_gc::RB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK,
)) == 0
{
buffer.info[start].mask |= plan.mask_array[indic_feature::INIT];
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/complex/khmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use crate::buffer::hb_buffer_t;
use crate::ot::{feature, FeatureFlags};
use crate::ot_shape_normalize::HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT;
use crate::plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::shape_plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::unicode::{CharExt, GeneralCategoryExt};
use crate::{hb_font_t, hb_glyph_info_t, Mask, Tag};

Expand Down Expand Up @@ -148,7 +148,7 @@ fn collect_features(planner: &mut ShapePlanner) {

planner
.ot_map
.add_gsub_pause(Some(crate::ot::clear_syllables));
.add_gsub_pause(Some(crate::ot_layout::_hb_clear_syllables));

for feature in KHMER_FEATURES.iter().skip(5) {
planner.ot_map.add_feature(feature.0, feature.1, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/complex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::ot_shape_normalize::{
hb_ot_shape_normalization_mode_t, hb_ot_shape_normalize_context_t,
HB_OT_SHAPE_NORMALIZATION_MODE_AUTO,
};
use crate::plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::shape_plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::{hb_font_t, script, Direction, Script, Tag};

pub const MAX_COMBINING_MARKS: usize = 32;
Expand Down
4 changes: 2 additions & 2 deletions src/complex/myanmar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::ot_shape_normalize::{
HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
HB_OT_SHAPE_NORMALIZATION_MODE_NONE,
};
use crate::plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::shape_plan::{hb_ot_shape_plan_t, ShapePlanner};
use crate::{hb_font_t, hb_glyph_info_t, Tag};

pub const MYANMAR_SHAPER: ComplexShaper = ComplexShaper {
Expand Down Expand Up @@ -165,7 +165,7 @@ fn collect_features(planner: &mut ShapePlanner) {

planner
.ot_map
.add_gsub_pause(Some(crate::ot::clear_syllables));
.add_gsub_pause(Some(crate::ot_layout::_hb_clear_syllables));

for feature in MYANMAR_FEATURES.iter().skip(4) {
planner
Expand Down
2 changes: 1 addition & 1 deletion src/complex/syllabic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn insert_dotted_circles(
return;
}

let dottedcircle_glyph = match face.glyph_index(0x25CC) {
let dottedcircle_glyph = match face.get_nominal_glyph(0x25CC) {
Some(g) => g.0 as u32,
None => return,
};
Expand Down
Loading

0 comments on commit 4aa25ae

Please sign in to comment.