mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 06:21:16 +01:00
[harfruzz] Update to new API
From https://github.com/harfbuzz/harfruzz/pull/57
This commit is contained in:
1 parent
4d7d54e380
commit
f92809fcdc
4 files changed
+71
-73
No files matched your search
+6
-2
@@ -81,6 +81,7 @@ _hb_harfruzz_shaper_font_data_destroy (hb_harfruzz_font_data_t *data)
|
||||
|
||||
extern "C" void *
|
||||
_hb_harfruzz_shape_plan_create_rs (const void *font_data,
|
||||
const void *face_data,
|
||||
hb_script_t script,
|
||||
hb_language_t language,
|
||||
hb_direction_t direction);
|
||||
@@ -94,7 +95,8 @@ _hb_harfruzz_shape_plan_destroy_rs (void *data);
|
||||
*/
|
||||
|
||||
extern "C" hb_bool_t
|
||||
_hb_harfruzz_shape_rs (const void *face_data,
|
||||
_hb_harfruzz_shape_rs (const void *font_data,
|
||||
const void *face_data,
|
||||
const void *rs_shape_plan,
|
||||
hb_font_t *font,
|
||||
hb_buffer_t *buffer,
|
||||
@@ -111,6 +113,7 @@ _hb_harfruzz_shape (hb_shape_plan_t *shape_plan,
|
||||
unsigned int num_features)
|
||||
{
|
||||
const hb_harfruzz_font_data_t *font_data = font->data.harfruzz;
|
||||
const hb_harfruzz_face_data_t *face_data = font->face->data.harfruzz;
|
||||
|
||||
void *hr_shape_plan = nullptr;
|
||||
|
||||
@@ -121,7 +124,7 @@ _hb_harfruzz_shape (hb_shape_plan_t *shape_plan,
|
||||
&hr_shape_plan_key);
|
||||
if (unlikely (!hr_shape_plan))
|
||||
{
|
||||
hr_shape_plan = _hb_harfruzz_shape_plan_create_rs (font_data,
|
||||
hr_shape_plan = _hb_harfruzz_shape_plan_create_rs (font_data, face_data,
|
||||
shape_plan->key.props.script,
|
||||
shape_plan->key.props.language,
|
||||
shape_plan->key.props.direction);
|
||||
@@ -139,6 +142,7 @@ _hb_harfruzz_shape (hb_shape_plan_t *shape_plan,
|
||||
}
|
||||
|
||||
return _hb_harfruzz_shape_rs (font_data,
|
||||
face_data,
|
||||
hr_shape_plan,
|
||||
font,
|
||||
buffer,
|
||||
|
||||
Generated
+7
-24
@@ -57,15 +57,13 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "harfruzz"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/harfbuzz/harfruzz#966d38a4b7b2f23b77a0ce4c356542e9395102e8"
|
||||
source = "git+https://github.com/harfbuzz/harfruzz?branch=instance-api#4964a851fee309a899831c544cff738f65ac1ff3"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bytemuck",
|
||||
"core_maths",
|
||||
"log",
|
||||
"read-fonts",
|
||||
"smallvec",
|
||||
"ttf-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -74,12 +72,6 @@ version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.95"
|
||||
@@ -100,9 +92,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "read-fonts"
|
||||
version = "0.29.1"
|
||||
version = "0.29.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e85935612710191461ec9df47b4b5880dd6359d4fad3b2f2ed696215f6f3146"
|
||||
checksum = "04ca636dac446b5664bd16c069c00a9621806895b8bb02c2dc68542b23b8f25d"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"core_maths",
|
||||
@@ -111,9 +103,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "skrifa"
|
||||
version = "0.31.1"
|
||||
version = "0.31.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9c3bb8cab5196b98d70c866ce1ea81ab516104d5b396f84ae80f8766b5d5b4e"
|
||||
checksum = "dbeb4ca4399663735553a09dd17ce7e49a0a0203f03b706b39628c4d913a8607"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"read-fonts",
|
||||
@@ -121,9 +113,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.15.0"
|
||||
version = "1.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9"
|
||||
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
@@ -136,15 +128,6 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ttf-parser"
|
||||
version = "0.25.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
||||
dependencies = [
|
||||
"core_maths",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
skrifa = { version = "0.*", optional = true }
|
||||
harfruzz = { git = "https://github.com/harfbuzz/harfruzz", optional = true }
|
||||
harfruzz = { git = "https://github.com/harfbuzz/harfruzz", branch="instance-api", optional = true }
|
||||
|
||||
[lib]
|
||||
name = "harfbuzz_rust"
|
||||
|
||||
+57
-46
@@ -6,12 +6,12 @@ use std::ffi::c_void;
|
||||
use std::ptr::null_mut;
|
||||
use std::str::FromStr;
|
||||
|
||||
use harfruzz::{F2Dot14, Face, FontRef, ShaperFont, Tag};
|
||||
use harfruzz::{FontRef, NormalizedCoord, ShaperData, ShaperInstance, Tag};
|
||||
|
||||
pub struct HBHarfRuzzFaceData<'a> {
|
||||
face_blob: *mut hb_blob_t,
|
||||
font_ref: FontRef<'a>,
|
||||
shaper_font: ShaperFont,
|
||||
shaper_data: ShaperData,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -31,12 +31,12 @@ pub unsafe extern "C" fn _hb_harfruzz_shaper_face_data_create_rs(
|
||||
Ok(f) => f,
|
||||
Err(_) => return null_mut(),
|
||||
};
|
||||
let shaper_font = ShaperFont::new(&font_ref);
|
||||
let shaper_data = ShaperData::new(&font_ref);
|
||||
|
||||
let hr_face_data = Box::new(HBHarfRuzzFaceData {
|
||||
face_blob,
|
||||
font_ref,
|
||||
shaper_font,
|
||||
shaper_data,
|
||||
});
|
||||
|
||||
Box::into_raw(hr_face_data) as *mut c_void
|
||||
@@ -50,12 +50,11 @@ pub unsafe extern "C" fn _hb_harfruzz_shaper_face_data_destroy_rs(data: *mut c_v
|
||||
hb_blob_destroy(blob);
|
||||
}
|
||||
|
||||
pub struct HBHarfRuzzFontData<'a> {
|
||||
coords: Vec<F2Dot14>,
|
||||
face: Option<Face<'a>>,
|
||||
pub struct HBHarfRuzzFontData {
|
||||
shaper_instance: ShaperInstance,
|
||||
}
|
||||
|
||||
fn font_coords_to_f2dot14(font: *mut hb_font_t) -> Vec<F2Dot14> {
|
||||
fn font_coords_to_f2dot14(font: *mut hb_font_t) -> Vec<NormalizedCoord> {
|
||||
let mut num_coords: u32 = 0;
|
||||
let coords = unsafe { hb_font_get_var_coords_normalized(font, &mut num_coords) };
|
||||
let coords = if coords.is_null() {
|
||||
@@ -65,7 +64,7 @@ fn font_coords_to_f2dot14(font: *mut hb_font_t) -> Vec<F2Dot14> {
|
||||
};
|
||||
coords
|
||||
.iter()
|
||||
.map(|&v| F2Dot14::from_bits(v as i16))
|
||||
.map(|&v| NormalizedCoord::from_bits(v as i16))
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
@@ -76,15 +75,13 @@ pub unsafe extern "C" fn _hb_harfruzz_shaper_font_data_create_rs(
|
||||
) -> *mut c_void {
|
||||
let face_data = face_data as *const HBHarfRuzzFaceData;
|
||||
|
||||
let font_ref = &(*face_data).font_ref;
|
||||
let coords = font_coords_to_f2dot14(font);
|
||||
|
||||
let hr_font_data = Box::new(HBHarfRuzzFontData { coords, face: None });
|
||||
let shaper_instance = ShaperInstance::from_coords(font_ref, coords);
|
||||
|
||||
let hr_font_data = Box::new(HBHarfRuzzFontData { shaper_instance });
|
||||
let hr_font_data_ptr = Box::into_raw(hr_font_data);
|
||||
(*hr_font_data_ptr).face = Some(
|
||||
(*face_data)
|
||||
.shaper_font
|
||||
.shaper(&(*face_data).font_ref, &(*hr_font_data_ptr).coords),
|
||||
);
|
||||
|
||||
hr_font_data_ptr as *mut c_void
|
||||
}
|
||||
@@ -108,11 +105,15 @@ fn hb_language_to_hr_language(language: hb_language_t) -> Option<harfruzz::Langu
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn _hb_harfruzz_shape_plan_create_rs(
|
||||
font_data: *const c_void,
|
||||
face_data: *const c_void,
|
||||
script: hb_script_t,
|
||||
language: hb_language_t,
|
||||
direction: hb_direction_t,
|
||||
) -> *mut c_void {
|
||||
let font_data = font_data as *const HBHarfRuzzFontData;
|
||||
let face_data = face_data as *const HBHarfRuzzFaceData;
|
||||
|
||||
let font_ref = &(*face_data).font_ref;
|
||||
|
||||
let script = harfruzz::Script::from_iso15924_tag(Tag::from_u32(script));
|
||||
let language = hb_language_to_hr_language(language);
|
||||
@@ -124,13 +125,14 @@ pub unsafe extern "C" fn _hb_harfruzz_shape_plan_create_rs(
|
||||
_ => harfruzz::Direction::Invalid,
|
||||
};
|
||||
|
||||
let hr_shape_plan = harfruzz::ShapePlan::new(
|
||||
(*font_data).face.as_ref().unwrap(),
|
||||
direction,
|
||||
script,
|
||||
language.as_ref(),
|
||||
&[],
|
||||
);
|
||||
let shaper = (*face_data)
|
||||
.shaper_data
|
||||
.shaper(font_ref)
|
||||
.instance(Some(&(*font_data).shaper_instance))
|
||||
.build();
|
||||
|
||||
let hr_shape_plan =
|
||||
harfruzz::ShapePlan::new(&shaper, direction, script, language.as_ref(), &[]);
|
||||
let hr_shape_plan = Box::new(hr_shape_plan);
|
||||
Box::into_raw(hr_shape_plan) as *mut c_void
|
||||
}
|
||||
@@ -144,6 +146,7 @@ pub unsafe extern "C" fn _hb_harfruzz_shape_plan_destroy_rs(data: *mut c_void) {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn _hb_harfruzz_shape_rs(
|
||||
font_data: *const c_void,
|
||||
face_data: *const c_void,
|
||||
shape_plan: *const c_void,
|
||||
font: *mut hb_font_t,
|
||||
buffer: *mut hb_buffer_t,
|
||||
@@ -151,6 +154,9 @@ pub unsafe extern "C" fn _hb_harfruzz_shape_rs(
|
||||
num_features: u32,
|
||||
) -> hb_bool_t {
|
||||
let font_data = font_data as *const HBHarfRuzzFontData;
|
||||
let face_data = face_data as *const HBHarfRuzzFaceData;
|
||||
|
||||
let font_ref = &(*face_data).font_ref;
|
||||
|
||||
let mut hr_buffer = harfruzz::UnicodeBuffer::new();
|
||||
|
||||
@@ -215,33 +221,38 @@ pub unsafe extern "C" fn _hb_harfruzz_shape_rs(
|
||||
hr_buffer.add(char::from_u32_unchecked(unicode), cluster);
|
||||
}
|
||||
|
||||
let face = &(*font_data).face.as_ref().unwrap();
|
||||
let shaper = (*face_data)
|
||||
.shaper_data
|
||||
.shaper(font_ref)
|
||||
.instance(Some(&(*font_data).shaper_instance))
|
||||
.build();
|
||||
|
||||
let features = if features.is_null() {
|
||||
Vec::new()
|
||||
} else {
|
||||
let features = std::slice::from_raw_parts(features, num_features as usize);
|
||||
features
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let tag = f.tag;
|
||||
let value = f.value;
|
||||
let start = f.start;
|
||||
let end = f.end;
|
||||
harfruzz::Feature {
|
||||
tag: Tag::from_u32(tag),
|
||||
value,
|
||||
start,
|
||||
end,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
let glyphs = if shape_plan.is_null() {
|
||||
let features = if features.is_null() {
|
||||
Vec::new()
|
||||
} else {
|
||||
let features = std::slice::from_raw_parts(features, num_features as usize);
|
||||
features
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let tag = f.tag;
|
||||
let value = f.value;
|
||||
let start = f.start;
|
||||
let end = f.end;
|
||||
harfruzz::Feature {
|
||||
tag: Tag::from_u32(tag),
|
||||
value,
|
||||
start,
|
||||
end,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
harfruzz::shape(face, &features, hr_buffer)
|
||||
shaper.shape(hr_buffer, &features)
|
||||
} else {
|
||||
let shape_plan = shape_plan as *const harfruzz::ShapePlan;
|
||||
harfruzz::shape_with_plan(face, shape_plan.as_ref().unwrap(), hr_buffer)
|
||||
shaper.shape_with_plan(shape_plan.as_ref().unwrap(), hr_buffer, &features)
|
||||
};
|
||||
|
||||
let count = glyphs.len();
|
||||
@@ -260,7 +271,7 @@ pub unsafe extern "C" fn _hb_harfruzz_shape_rs(
|
||||
let mut x_scale: i32 = 0;
|
||||
let mut y_scale: i32 = 0;
|
||||
hb_font_get_scale(font, &mut x_scale, &mut y_scale);
|
||||
let upem = face.units_per_em();
|
||||
let upem = shaper.units_per_em();
|
||||
let x_scale = x_scale as f32 / upem as f32;
|
||||
let y_scale = y_scale as f32 / upem as f32;
|
||||
|
||||
|
||||
Reference in new issue
Block a user