mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-04 21:15:06 +00:00
[fontations] Start building a libharfbuzz-fontations
This commit is contained in:
parent
ca3cd48fa3
commit
ad8e4a29b9
7 changed files with 237 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
project('harfbuzz', 'c', 'cpp',
|
||||
project('harfbuzz', ['c', 'cpp', 'rust'],
|
||||
meson_version: '>= 0.55.0',
|
||||
version: '10.4.0',
|
||||
default_options: [
|
||||
|
|
|
@ -15,6 +15,8 @@ option('graphite2', type: 'feature', value: 'disabled',
|
|||
description: 'Enable Graphite2 complementary shaper')
|
||||
option('freetype', type: 'feature', value: 'auto',
|
||||
description: 'Enable freetype interop helpers')
|
||||
option('fontations', type: 'feature', value: 'disabled',
|
||||
description: 'Enabled fontations font functions')
|
||||
option('gdi', type: 'feature', value: 'disabled',
|
||||
description: 'Enable GDI helpers and Uniscribe shaper backend (Windows only)')
|
||||
option('directwrite', type: 'feature', value: 'disabled',
|
||||
|
|
13
src/fontations/Cargo.toml
Normal file
13
src/fontations/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "harfbuzz_fontations"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "harfbuzz_fontations"
|
||||
crate-type = ["rlib"]
|
||||
|
||||
[dependencies]
|
||||
read-fonts = "0.20"
|
||||
skrifa = "0.20"
|
||||
libc = "0.2"
|
124
src/fontations/lib.rs
Normal file
124
src/fontations/lib.rs
Normal file
|
@ -0,0 +1,124 @@
|
|||
//
|
||||
// lib.rs — Rust code that sets up HarfBuzz font funcs
|
||||
//
|
||||
|
||||
use std::os::raw::{c_void, c_char};
|
||||
use std::ptr::{null_mut};
|
||||
|
||||
// If you want to parse TTF/OTF with read-fonts, etc. import them:
|
||||
// use read_fonts::FontRef;
|
||||
// use skrifa::{...};
|
||||
|
||||
// Minimal HarfBuzz FFI
|
||||
// Typically you'd generate these with bindgen from <hb.h>, but we'll do a small subset:
|
||||
|
||||
pub type hb_bool_t = i32;
|
||||
pub type hb_position_t = i32;
|
||||
pub type hb_codepoint_t = u32;
|
||||
pub type hb_destroy_func_t = Option<extern "C" fn(user_data: *mut c_void)>;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct hb_font_t { _unused: [u8; 0], }
|
||||
|
||||
#[repr(C)]
|
||||
pub struct hb_font_funcs_t { _unused: [u8; 0], }
|
||||
|
||||
extern "C" {
|
||||
fn hb_font_funcs_create() -> *mut hb_font_funcs_t;
|
||||
|
||||
fn hb_font_funcs_set_glyph_h_advance_func(
|
||||
ffuncs: *mut hb_font_funcs_t,
|
||||
func: Option<hb_font_get_glyph_advance_func_t>,
|
||||
user_data: *mut c_void,
|
||||
destroy: hb_destroy_func_t
|
||||
);
|
||||
|
||||
fn hb_font_set_funcs(
|
||||
font: *mut hb_font_t,
|
||||
klass: *mut hb_font_funcs_t,
|
||||
font_data: *mut c_void,
|
||||
destroy: hb_destroy_func_t
|
||||
);
|
||||
|
||||
fn hb_font_funcs_destroy (
|
||||
ffuncs: *mut hb_font_funcs_t
|
||||
);
|
||||
|
||||
// If you need more sets or functions, declare them here
|
||||
}
|
||||
|
||||
// Callback type: e.g. horizontal advance
|
||||
pub type hb_font_get_glyph_advance_func_t = extern "C" fn(
|
||||
font: *mut hb_font_t,
|
||||
font_data: *mut c_void,
|
||||
glyph: hb_codepoint_t,
|
||||
user_data: *mut c_void
|
||||
) -> hb_position_t;
|
||||
|
||||
// A struct for storing your “fontations” data
|
||||
#[repr(C)]
|
||||
pub struct FontationsData {
|
||||
// e.g. storing an owned font buffer, or read-fonts handles:
|
||||
// font_bytes: Vec<u8>,
|
||||
// font_ref: Option<FontRef<'static>>,
|
||||
pub offset: i32,
|
||||
}
|
||||
|
||||
// A destructor for the user_data
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fontations_data_destroy(ptr: *mut c_void) {
|
||||
if !ptr.is_null() {
|
||||
unsafe { Box::from_raw(ptr as *mut FontationsData); }
|
||||
}
|
||||
}
|
||||
|
||||
// Our callback: get glyph horizontal advance
|
||||
#[no_mangle]
|
||||
pub extern "C" fn hb_fontations_get_glyph_h_advance(
|
||||
_font: *mut hb_font_t,
|
||||
font_data: *mut c_void,
|
||||
glyph: hb_codepoint_t,
|
||||
_user_data: *mut c_void
|
||||
) -> hb_position_t {
|
||||
let data = unsafe {
|
||||
assert!(!font_data.is_null());
|
||||
&*(font_data as *const FontationsData)
|
||||
};
|
||||
// Just a dummy formula:
|
||||
let advance = (glyph as i32) + data.offset;
|
||||
advance
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _hb_fontations_font_funcs_create() -> *mut hb_font_funcs_t {
|
||||
let ffuncs = unsafe { hb_font_funcs_create() };
|
||||
|
||||
unsafe {
|
||||
hb_font_funcs_set_glyph_h_advance_func(
|
||||
ffuncs,
|
||||
Some(hb_fontations_get_glyph_h_advance),
|
||||
null_mut(),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
ffuncs
|
||||
}
|
||||
|
||||
// A helper to attach these funcs to a hb_font_t
|
||||
#[no_mangle]
|
||||
pub extern "C" fn hb_fontations_font_set_funcs(
|
||||
font: *mut hb_font_t,
|
||||
) {
|
||||
let ffuncs = _hb_fontations_font_funcs_create ();
|
||||
|
||||
// Set up some data for the callbacks to use:
|
||||
let data = FontationsData { offset: 100 };
|
||||
let data_ptr = Box::into_raw(Box::new(data)) as *mut c_void;
|
||||
|
||||
unsafe {
|
||||
hb_font_set_funcs (font, ffuncs, data_ptr, Some(fontations_data_destroy));
|
||||
}
|
||||
|
||||
unsafe { hb_font_funcs_destroy (ffuncs); }
|
||||
}
|
9
src/fontations/meson.build
Normal file
9
src/fontations/meson.build
Normal file
|
@ -0,0 +1,9 @@
|
|||
harfbuzz_dep = dependency('harfbuzz', required: true)
|
||||
|
||||
harfbuzz_fontations_rust = static_library(
|
||||
'harfbuzz_fontations_rust',
|
||||
'lib.rs',
|
||||
dependencies: [harfbuzz_dep],
|
||||
rust_abi: 'c',
|
||||
install: true,
|
||||
)
|
37
src/hb-fontations.h
Normal file
37
src/hb-fontations.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* This is part of HarfBuzz, a text shaping library.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose, provided that the
|
||||
* above copyright notice and the following two paragraphs appear in
|
||||
* all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||||
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*
|
||||
* Author(s): Behdad Esfahbod
|
||||
*/
|
||||
|
||||
#ifndef HB_FONTATIONS_H
|
||||
#define HB_FONTATIONS_H
|
||||
|
||||
#include "hb.h"
|
||||
|
||||
HB_BEGIN_DECLS
|
||||
|
||||
HB_EXTERN void
|
||||
hb_fontations_font_set_funcs (hb_font_t *font);
|
||||
|
||||
HB_END_DECLS
|
||||
|
||||
#endif /* HB_CAIRO_H */
|
|
@ -693,6 +693,57 @@ if conf.get('HAVE_CAIRO', 0) == 1
|
|||
)
|
||||
endif
|
||||
|
||||
libharfbuzz_fontations_dep = null_dep
|
||||
if get_option('fontations').enabled()
|
||||
|
||||
subdir('fontations')
|
||||
|
||||
hb_fontations_sources = [
|
||||
]
|
||||
|
||||
hb_fontations_headers = [
|
||||
'hb-fontations.h',
|
||||
]
|
||||
|
||||
harfbuzz_fontations_rust_dep = declare_dependency(
|
||||
link_with: harfbuzz_fontations_rust,
|
||||
dependencies: [harfbuzz_dep], # XXX
|
||||
)
|
||||
|
||||
libharfbuzz_fontations = library('harfbuzz-fontations', hb_fontations_sources,
|
||||
include_directories: incconfig,
|
||||
dependencies: [harfbuzz_fontations_rust_dep],
|
||||
link_with: [libharfbuzz],
|
||||
cpp_args: cpp_args + extra_hb_cpp_args,
|
||||
soversion: hb_so_version,
|
||||
version: version,
|
||||
install: true,
|
||||
darwin_versions: darwin_versions,
|
||||
link_language: chosen_linker,
|
||||
)
|
||||
|
||||
install_headers(hb_fontations_headers, subdir: meson.project_name())
|
||||
|
||||
libharfbuzz_fontations_dep = declare_dependency(
|
||||
link_with: libharfbuzz_fontations,
|
||||
include_directories: incsrc,
|
||||
dependencies: [])
|
||||
meson.override_dependency('harfbuzz-fontations', libharfbuzz_fontations_dep)
|
||||
|
||||
harfbuzz_fontations_def = custom_target('harfbuzz-fontations.def',
|
||||
command: gen_def_cmd,
|
||||
input: hb_fontations_headers,
|
||||
output: 'harfbuzz-fontations.def')
|
||||
defs_list += [harfbuzz_fontations_def]
|
||||
|
||||
pkgmod.generate(libharfbuzz_fontations,
|
||||
description: 'HarfBuzz fontations support',
|
||||
requires: ['harfbuzz = @0@'.format(meson.project_version())],
|
||||
subdirs: [meson.project_name()],
|
||||
version: meson.project_version(),
|
||||
)
|
||||
endif
|
||||
|
||||
if get_option('tests').enabled()
|
||||
# TODO: Microsoft LINK gives the following because extern, non dllexport
|
||||
# symbols can only be used when linking against a static library
|
||||
|
|
Loading…
Add table
Reference in a new issue