From: Joshua Simmons Date: Fri, 2 Dec 2022 21:13:34 +0000 (+0100) Subject: Expand stb_truetype wrapper X-Git-Url: https://git.nega.tv//gitweb.cgi?a=commitdiff_plain;h=7475d16e5b11e88d1d5bc00b3098c2f62b05725e;p=josh%2Fnarcissus Expand stb_truetype wrapper --- diff --git a/ffi/stb_truetype-sys/src/lib.rs b/ffi/stb_truetype-sys/src/lib.rs index e5fca1f..80923bf 100644 --- a/ffi/stb_truetype-sys/src/lib.rs +++ b/ffi/stb_truetype-sys/src/lib.rs @@ -1,7 +1,7 @@ use std::ffi::c_void; #[repr(C)] -pub struct stbtt_pack_context { +pub struct PackContext { user_allocator_context: *mut c_void, pack_info: *mut c_void, width: i32, @@ -16,31 +16,31 @@ pub struct stbtt_pack_context { } #[repr(C)] -pub struct stbtt_packedchar { +pub struct PackedChar { x0: u16, y0: u16, x1: u16, y1: u16, // coordinates of bbox in bitmap - xoff: f32, - yoff: f32, - xadvance: f32, - xoff2: f32, - yoff2: f32, + x_offset: f32, + y_offset: f32, + x_advance: f32, + x_off2: f32, + y_off2: f32, } #[repr(C)] -pub struct stbtt_pack_range { +pub struct PackRange { font_size: f32, first_unicode_codepoint_in_range: i32, // if non-zero, then the chars are continuous, and this is the first codepoint array_of_unicode_codepoints: *const i32, // if non-zero, then this is an array of unicode codepoints num_chars: i32, - chardata_for_range: *mut stbtt_packedchar, // output + chardata_for_range: *mut PackedChar, // output h_oversample: u32, v_oversample: u32, // don't set these, they're used internally } #[repr(C)] -pub struct stbtt_aligned_quad { +pub struct AlignedQuad { x0: f32, // top-left y0: f32, s0: f32, @@ -52,14 +52,14 @@ pub struct stbtt_aligned_quad { } #[repr(C)] -struct stbtt__buf { +struct Buf { data: *mut u8, cursor: i32, size: i32, } #[repr(C)] -pub struct stbtt_fontinfo { +pub struct FontInfo { userdata: *mut c_void, data: *mut u8, // pointer to .ttf file fontstart: i32, // offset of start of font @@ -77,17 +77,17 @@ pub struct stbtt_fontinfo { index_map: i32, // a cmap mapping for our chosen character encoding index_to_loc_format: i32, // format needed to map from glyph index to glyph - cff: stbtt__buf, // cff font data - charstrings: stbtt__buf, // the charstring index - gsubrs: stbtt__buf, // global charstring subroutines index - subrs: stbtt__buf, // private charstring subroutines index - fontdicts: stbtt__buf, // array of font dicts - fdselect: stbtt__buf, // map from glyph to fontdict + cff: Buf, // cff font data + charstrings: Buf, // the charstring index + gsubrs: Buf, // global charstring subroutines index + subrs: Buf, // private charstring subroutines index + fontdicts: Buf, // array of font dicts + fdselect: Buf, // map from glyph to fontdict } extern "C" { pub fn stbtt_PackBegin( - spc: *mut stbtt_pack_context, + spc: *mut PackContext, pixels: *const u8, width: i32, height: i32, @@ -96,105 +96,222 @@ extern "C" { alloc_context: *mut c_void, ) -> i32; - pub fn stbtt_PackSetOversampling( - spc: *mut stbtt_pack_context, - h_oversample: u32, - v_oversample: u32, - ); + pub fn stbtt_PackSetOversampling(spc: &mut PackContext, h_oversample: u32, v_oversample: u32); pub fn stbtt_PackFontRanges( - spc: *mut stbtt_pack_context, + spc: &mut PackContext, fontdata: *const u8, font_index: i32, - ranges: *const stbtt_pack_range, + ranges: *const PackRange, num_ranges: i32, ); - pub fn stbtt_PackEnd(spc: *mut stbtt_pack_context); + pub fn stbtt_PackEnd(spc: &mut PackContext); pub fn stbtt_GetPackedQuad( - chardata: *const stbtt_packedchar, + chardata: *const PackedChar, pw: i32, ph: i32, char_index: i32, // character to display - xpos: *mut f32, - ypos: *mut f32, // pointers to current position in screen pixel space - q: *mut stbtt_aligned_quad, // output: quad to draw + x: &mut f32, // current position in screen pixel space + y: &mut f32, + quad: &mut AlignedQuad, // output: quad to draw align_to_integer: i32, ); - pub fn stbtt_InitFont(info: *mut stbtt_fontinfo, data: *const u8, offset: i32) -> i32; + pub fn stbtt_InitFont(info: *mut FontInfo, data: *const u8, offset: i32) -> i32; + + pub fn stbtt_ScaleForPixelHeight(info: &FontInfo, height: f32) -> f32; pub fn stbtt_GetNumberOfFonts(data: *const u8) -> i32; pub fn stbtt_GetFontOffsetForIndex(data: *const u8, index: i32) -> i32; pub fn stbtt_GetCodepointBitmap( - info: &stbtt_fontinfo, + info: &FontInfo, scale_x: f32, scale_y: f32, codepoint: i32, width: &mut i32, height: &mut i32, - xoff: &mut i32, - yoff: &mut i32, + x_offset: &mut i32, + y_offset: &mut i32, ) -> *mut u8; pub fn stbtt_MakeCodepointBitmap( - info: &stbtt_fontinfo, + info: &FontInfo, + output: *mut u8, + out_w: i32, + out_h: i32, + out_stride: i32, + scale_x: f32, + scale_y: f32, + codepoint: i32, + ); + + pub fn stbtt_MakeCodepointBitmapSubpixel( + info: &FontInfo, + output: *mut u8, + out_w: i32, + out_h: i32, + out_stride: i32, + scale_x: f32, + scale_y: f32, + shift_x: f32, + shift_y: f32, + codepoint: i32, + ); + + pub fn stbtt_MakeCodepointBitmapSubpixelPrefilter( + info: &FontInfo, output: *mut u8, out_w: i32, out_h: i32, out_stride: i32, scale_x: f32, scale_y: f32, + shift_x: f32, + shift_y: f32, + oversample_x: i32, + oversample_y: i32, + sub_x: &mut f32, + sub_y: &mut f32, codepoint: i32, ); pub fn stbtt_GetCodepointBitmapBox( - info: &stbtt_fontinfo, + info: &FontInfo, codepoint: i32, scale_x: f32, scale_y: f32, - ix0: &mut i32, - iy0: &mut i32, - ix1: &mut i32, - iy1: &mut i32, + x0: &mut i32, + y0: &mut i32, + x1: &mut i32, + y1: &mut i32, ); pub fn stbtt_GetCodepointBitmapBoxSubpixel( - info: &stbtt_fontinfo, + info: &FontInfo, codepoint: i32, scale_x: f32, scale_y: f32, shift_x: f32, shift_y: f32, - ix0: &mut i32, - iy0: &mut i32, - ix1: &mut i32, - iy1: &mut i32, + x0: &mut i32, + y0: &mut i32, + x1: &mut i32, + y1: &mut i32, + ); + + pub fn stbtt_GetGlyphBitmap( + info: &FontInfo, + scale_x: f32, + scale_y: f32, + glyph: i32, + width: &mut i32, + height: &mut i32, + x_offset: &mut i32, + y_offset: &mut i32, + ) -> *mut u8; + + pub fn stbtt_GetGlyphBitmapSubpixel( + info: &FontInfo, + scale_x: f32, + scale_y: f32, + shift_x: f32, + shift_y: f32, + glyph: i32, + width: &mut i32, + height: &mut i32, + x_offset: &mut i32, + y_offset: &mut i32, + ) -> *mut u8; + + pub fn stbtt_MakeGlyphBitmap( + info: &FontInfo, + output: *mut u8, + out_w: i32, + out_h: i32, + out_stride: i32, + scale_x: f32, + scale_y: f32, + glyph: i32, + ); + + pub fn stbtt_MakeGlyphBitmapSubpixel( + info: &FontInfo, + output: *mut u8, + out_w: i32, + out_h: i32, + out_stride: i32, + scale_x: f32, + scale_y: f32, + shift_x: f32, + shift_y: f32, + glyph: i32, + ); + + pub fn stbtt_MakeGlyphBitmapSubpixelPrefilter( + info: &FontInfo, + output: *mut u8, + out_w: i32, + out_h: i32, + out_stride: i32, + scale_x: f32, + scale_y: f32, + shift_x: f32, + shift_y: f32, + oversample_x: i32, + oversample_y: i32, + sub_x: &mut f32, + sub_y: &mut f32, + glyph: i32, + ); + + pub fn stbtt_GetGlyphBitmapBox( + info: &FontInfo, + glyph: i32, + scale_x: f32, + scale_y: f32, + x0: &mut i32, + y0: &mut i32, + x1: &mut i32, + y1: &mut i32, + ); + + pub fn stbtt_GetGlyphBitmapBoxSubpixel( + info: &FontInfo, + glyph: i32, + scale_x: f32, + scale_y: f32, + shift_x: f32, + shift_y: f32, + x0: &mut i32, + y0: &mut i32, + x1: &mut i32, + y1: &mut i32, ); pub fn stbtt_GetCodepointHMetrics( - info: &stbtt_fontinfo, + info: &FontInfo, codepoint: i32, advance_width: &mut i32, left_side_bearing: &mut i32, ); pub fn stbtt_GetFontVMetrics( - info: &stbtt_fontinfo, + info: &FontInfo, ascent: &mut i32, descent: &mut i32, line_gap: &mut i32, ); pub fn stbtt_GetFontVMetricsOS2( - info: &stbtt_fontinfo, + info: &FontInfo, typo_ascent: &mut i32, typo_descent: &mut i32, typo_line_gap: &mut i32, ) -> i32; - pub fn stbtt_GetCodepointKernAdvance(info: &stbtt_fontinfo, ch1: i32, ch2: i32) -> i32; + pub fn stbtt_GetCodepointKernAdvance(info: &FontInfo, ch1: i32, ch2: i32) -> i32; }