Created
January 25, 2020 17:48
-
-
Save ebraminio/864e6db65abe79467fb912796b962e81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include "src/hb.h" | |
#include "src/hb-ot.h" | |
struct hb_rasterizer_t | |
{ | |
hb_ot_glyph_decompose_funcs_t *funcs; | |
unsigned width, height; | |
unsigned starting_stride; | |
float *a; | |
hb_rasterizer_t (unsigned char *memory, unsigned width_, unsigned height_) | |
{ | |
width = width_; height = height_; starting_stride = 0; | |
a = (float *) calloc (width * height, sizeof (float)); | |
/* Can be cached */ | |
funcs = hb_ot_glyph_decompose_funcs_create (); | |
hb_ot_glyph_decompose_funcs_set_move_to_func (funcs, (hb_ot_glyph_decompose_move_to_func_t) move_to_); | |
hb_ot_glyph_decompose_funcs_set_line_to_func (funcs, (hb_ot_glyph_decompose_line_to_func_t) line_to_); | |
hb_ot_glyph_decompose_funcs_set_conic_to_func (funcs, (hb_ot_glyph_decompose_conic_to_func_t) conic_to_); | |
hb_ot_glyph_decompose_funcs_set_cubic_to_func (funcs, (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to_); | |
hb_ot_glyph_decompose_funcs_set_close_path_func (funcs, (hb_ot_glyph_decompose_close_path_func_t) close_path_); | |
} | |
~hb_rasterizer_t () { free (a); hb_ot_glyph_decompose_funcs_destroy (funcs); } | |
void set_starting_stride (unsigned starting_stride_) { starting_stride = starting_stride_; } | |
void draw_glyph (hb_font_t *font, hb_codepoint_t gid, unsigned *w/*OUT*/, unsigned *h/*OUT*/, unsigned *stride/*OUT*/) | |
{ draw_glyphs (font, 1, &gid, &starting_stride, &width, &height, w, h, stride); } | |
void draw_glyphs (hb_font_t *font, unsigned glyph_count, | |
hb_codepoint_t *gids/*IN*/, unsigned *starting_stride/*IN*/, | |
unsigned *width/*IN*/, unsigned *height/*IN*/, | |
unsigned *w/*OUT*/, unsigned *h/*OUT*/, unsigned *stride/*OUT*/) | |
{ | |
// fill w and h out array from hb_get_glyph_extents | |
for (unsigned int i = 0; i < glyph_count; ++i) | |
hb_ot_glyph_decompose (font, gids[i], funcs, this); | |
accumulate (); | |
} | |
void move_to (hb_position_t to_x, hb_position_t to_y) {} | |
void line_to (hb_position_t to_x, hb_position_t to_y) {} | |
void conic_to (hb_position_t control_x, hb_position_t control_y, | |
hb_position_t to_x, hb_position_t to_y) {} | |
void cubic_to (hb_position_t control1_x, hb_position_t control1_y, | |
hb_position_t control2_x, hb_position_t control2_y, | |
hb_position_t to_x, hb_position_t to_y) {} | |
void close_path () {} | |
void accumulate () | |
{ | |
// accumulate https://github.com/raphlinus/font-rs/blob/master/src/accumulate.rs#L70 | |
// and return https://github.com/raphlinus/font-rs/blob/master/src/raster.rs#L137 | |
} | |
static void move_to_ (hb_position_t to_x, hb_position_t to_y, hb_rasterizer_t &self) | |
{ self.move_to (to_x, to_y); } | |
static void line_to_ (hb_position_t to_x, hb_position_t to_y, hb_rasterizer_t &self) | |
{ self.line_to (to_x, to_y); } | |
static void conic_to_ (hb_position_t control_x, hb_position_t control_y, | |
hb_position_t to_x, hb_position_t to_y, | |
hb_rasterizer_t &self) | |
{ self.conic_to (control_x, control_y, to_x, to_y); } | |
static void cubic_to_ (hb_position_t control1_x, hb_position_t control1_y, | |
hb_position_t control2_x, hb_position_t control2_y, | |
hb_position_t to_x, hb_position_t to_y, | |
hb_rasterizer_t &self) | |
{ self.cubic_to (control1_x, control1_y, control2_x, control2_y, to_x, to_y); } | |
static void close_path_ (hb_rasterizer_t &self) { self.close_path (); } | |
}; | |
int main () | |
{ | |
printf ("asdasd"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment