Skip to content

Commit

Permalink
Merge pull request #185 from harfbuzz/hb-paint
Browse files Browse the repository at this point in the history
Bind hb-paint API
  • Loading branch information
khaledhosny committed Feb 3, 2024
2 parents 6b14bb0 + ac261ba commit 737ff7c
Show file tree
Hide file tree
Showing 15 changed files with 1,308 additions and 46 deletions.
496 changes: 486 additions & 10 deletions src/uharfbuzz/_harfbuzz.pyx

Large diffs are not rendered by default.

291 changes: 285 additions & 6 deletions src/uharfbuzz/charfbuzz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cdef extern from "hb.h":
ctypedef long hb_position_t
ctypedef unsigned long hb_mask_t
ctypedef unsigned long hb_tag_t
ctypedef uint32_t hb_color_t

ctypedef enum hb_direction_t:
HB_DIRECTION_LTR
Expand Down Expand Up @@ -48,6 +49,13 @@ cdef extern from "hb.h":
hb_script_t hb_ot_tag_to_script(hb_tag_t tag)
const char* hb_version_string()

uint8_t hb_color_get_alpha(hb_color_t color)
uint8_t hb_color_get_red(hb_color_t color)
uint8_t hb_color_get_green(hb_color_t color)
uint8_t hb_color_get_blue(hb_color_t color)

hb_color_t HB_COLOR(uint8_t b, uint8_t g, uint8_t r, uint8_t a)

ctypedef struct hb_user_data_key_t:
pass

Expand Down Expand Up @@ -88,6 +96,7 @@ cdef extern from "hb.h":
hb_blob_t* hb_blob_create_from_file_or_fail(
const char *file_name)

hb_blob_t* hb_blob_reference(hb_blob_t* blob)
void hb_blob_destroy(hb_blob_t* blob)

const char* hb_blob_get_data(
Expand Down Expand Up @@ -231,6 +240,7 @@ cdef extern from "hb.h":
hb_bool_t replace)
void hb_face_destroy(hb_face_t* face)
hb_blob_t* hb_face_reference_blob(hb_face_t *face)
hb_face_t* hb_face_reference(hb_face_t *face)
hb_face_t* hb_face_get_empty()
unsigned int hb_face_get_table_tags(
const hb_face_t *face,
Expand Down Expand Up @@ -298,6 +308,13 @@ cdef extern from "hb.h":
hb_position_t reserved2
hb_position_t reserved1

hb_font_t* hb_font_create(hb_face_t* face)
hb_font_t* hb_font_create_sub_font(hb_font_t* parent)
hb_font_t* hb_font_get_empty()
hb_font_t* hb_font_reference(hb_font_t *font)
void hb_font_destroy(hb_font_t* font)

hb_face_t *hb_font_get_face(hb_font_t *font)
hb_font_funcs_t* hb_font_funcs_create()
void hb_font_funcs_set_glyph_h_advance_func(
hb_font_funcs_t* ffuncs,
Expand Down Expand Up @@ -333,8 +350,6 @@ cdef extern from "hb.h":
void *user_data, hb_destroy_func_t destroy)
void hb_font_funcs_destroy(hb_font_funcs_t* ffuncs)

hb_font_t* hb_font_create(hb_face_t* face)
hb_font_t* hb_font_create_sub_font(hb_font_t* parent)
void hb_font_set_funcs(
hb_font_t* font,
hb_font_funcs_t* klass,
Expand Down Expand Up @@ -431,8 +446,22 @@ cdef extern from "hb.h":
const char *s,
int len,
hb_codepoint_t *glyph)
void hb_font_destroy(hb_font_t* font)

void hb_font_draw_glyph(
hb_font_t *font,
hb_codepoint_t glyph,
const hb_draw_funcs_t *dfuncs,
void *draw_data)

void hb_font_paint_glyph(
hb_font_t *font,
hb_codepoint_t glyph,
hb_paint_funcs_t *pfuncs,
void *paint_data,
unsigned int palette_index,
hb_color_t foreground)

# hb-draw.h
ctypedef struct hb_draw_state_t:
hb_bool_t path_open
float path_start_x
Expand Down Expand Up @@ -528,11 +557,261 @@ cdef extern from "hb.h":

void hb_draw_funcs_destroy(hb_draw_funcs_t* funcs)

void hb_font_draw_glyph(
# hb-paint.h
ctypedef struct hb_paint_funcs_t:
pass

ctypedef struct hb_color_stop_t:
float offset
hb_bool_t is_foreground
hb_color_t color

ctypedef enum hb_paint_extend_t:
HB_PAINT_EXTEND_PAD
HB_PAINT_EXTEND_REPEAT
HB_PAINT_EXTEND_REFLECT

ctypedef struct hb_color_line_t:
pass

ctypedef enum hb_paint_composite_mode_t:
HB_PAINT_COMPOSITE_MODE_CLEAR
HB_PAINT_COMPOSITE_MODE_SRC
HB_PAINT_COMPOSITE_MODE_DEST
HB_PAINT_COMPOSITE_MODE_SRC_OVER
HB_PAINT_COMPOSITE_MODE_DEST_OVER
HB_PAINT_COMPOSITE_MODE_SRC_IN
HB_PAINT_COMPOSITE_MODE_DEST_IN
HB_PAINT_COMPOSITE_MODE_SRC_OUT
HB_PAINT_COMPOSITE_MODE_DEST_OUT
HB_PAINT_COMPOSITE_MODE_SRC_ATOP
HB_PAINT_COMPOSITE_MODE_DEST_ATOP
HB_PAINT_COMPOSITE_MODE_XOR
HB_PAINT_COMPOSITE_MODE_PLUS
HB_PAINT_COMPOSITE_MODE_SCREEN
HB_PAINT_COMPOSITE_MODE_OVERLAY
HB_PAINT_COMPOSITE_MODE_DARKEN
HB_PAINT_COMPOSITE_MODE_LIGHTEN
HB_PAINT_COMPOSITE_MODE_COLOR_DODGE
HB_PAINT_COMPOSITE_MODE_COLOR_BURN
HB_PAINT_COMPOSITE_MODE_HARD_LIGHT
HB_PAINT_COMPOSITE_MODE_SOFT_LIGHT
HB_PAINT_COMPOSITE_MODE_DIFFERENCE
HB_PAINT_COMPOSITE_MODE_EXCLUSION
HB_PAINT_COMPOSITE_MODE_MULTIPLY
HB_PAINT_COMPOSITE_MODE_HSL_HUE
HB_PAINT_COMPOSITE_MODE_HSL_SATURATION
HB_PAINT_COMPOSITE_MODE_HSL_COLOR
HB_PAINT_COMPOSITE_MODE_HSL_LUMINOSITY

hb_paint_funcs_t *hb_paint_funcs_create()
hb_paint_funcs_t *hb_paint_funcs_get_empty()
hb_paint_funcs_t *hb_paint_funcs_reference(hb_paint_funcs_t *funcs)
void hb_paint_funcs_destroy(hb_paint_funcs_t *funcs)
hb_bool_t hb_paint_funcs_set_user_data(
hb_paint_funcs_t *funcs,
hb_user_data_key_t *key,
void *data,
hb_destroy_func_t destroy,
hb_bool_t replace)
void *hb_paint_funcs_get_user_data(
const hb_paint_funcs_t *funcs,
hb_user_data_key_t *key)
void hb_paint_funcs_make_immutable(hb_paint_funcs_t *funcs)
hb_bool_t hb_paint_funcs_is_immutable(hb_paint_funcs_t *funcs)

unsigned int hb_color_line_get_color_stops(
hb_color_line_t *color_line,
unsigned int start,
unsigned int *count,
hb_color_stop_t *color_stops)

hb_paint_extend_t hb_color_line_get_extend(hb_color_line_t *color_line)

ctypedef void (*hb_paint_push_transform_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
float xx, float yx,
float xy, float yy,
float dx, float dy,
void *user_data)
ctypedef void (*hb_paint_pop_transform_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
void *user_data)
ctypedef hb_bool_t (*hb_paint_color_glyph_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
hb_codepoint_t glyph,
hb_font_t *font,
void *user_data)
ctypedef void (*hb_paint_push_clip_glyph_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
hb_codepoint_t glyph,
const hb_draw_funcs_t *dfuncs,
void *draw_data)
hb_font_t *font,
void *user_data)
ctypedef void (*hb_paint_push_clip_rectangle_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
float xmin, float ymin,
float xmax, float ymax,
void *user_data)
ctypedef void (*hb_paint_pop_clip_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
void *user_data)
ctypedef void (*hb_paint_color_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
hb_bool_t is_foreground,
hb_color_t color,
void *user_data)
ctypedef hb_bool_t (*hb_paint_image_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
hb_blob_t *image,
unsigned int width,
unsigned int height,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents,
void *user_data)
ctypedef unsigned int (*hb_color_line_get_color_stops_func_t) (
hb_color_line_t *color_line,
void *color_line_data,
unsigned int start,
unsigned int *count,
hb_color_stop_t *color_stops,
void *user_data)
ctypedef hb_paint_extend_t (*hb_color_line_get_extend_func_t) (
hb_color_line_t *color_line,
void *color_line_data,
void *user_data)
ctypedef struct hb_color_line_t:
void *data
hb_color_line_get_color_stops_func_t get_color_stops
void *get_color_stops_user_data
hb_color_line_get_extend_func_t get_extend
void *get_extend_user_data
void *reserved0
void *reserved1
void *reserved2
void *reserved3
void *reserved5
void *reserved6
void *reserved7
void *reserved8

ctypedef void (*hb_paint_linear_gradient_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
hb_color_line_t *color_line,
float x0, float y0,
float x1, float y1,
float x2, float y2,
void *user_data)
ctypedef void (*hb_paint_radial_gradient_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
hb_color_line_t *color_line,
float x0, float y0, float r0,
float x1, float y1, float r1,
void *user_data)
ctypedef void (*hb_paint_sweep_gradient_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
hb_color_line_t *color_line,
float x0, float y0,
float start_angle,
float end_angle,
void *user_data)
ctypedef void (*hb_paint_push_group_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
void *user_data)
ctypedef void (*hb_paint_pop_group_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
hb_paint_composite_mode_t mode,
void *user_data)
ctypedef hb_bool_t (*hb_paint_custom_palette_color_func_t) (
hb_paint_funcs_t *funcs,
void *paint_data,
unsigned int color_index,
hb_color_t *color,
void *user_data)

void hb_paint_funcs_set_push_transform_func(
hb_paint_funcs_t *funcs,
hb_paint_push_transform_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_pop_transform_func(
hb_paint_funcs_t *funcs,
hb_paint_pop_transform_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_color_glyph_func(
hb_paint_funcs_t *funcs,
hb_paint_color_glyph_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_push_clip_glyph_func(
hb_paint_funcs_t *funcs,
hb_paint_push_clip_glyph_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_push_clip_rectangle_func(
hb_paint_funcs_t *funcs,
hb_paint_push_clip_rectangle_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_pop_clip_func(
hb_paint_funcs_t *funcs,
hb_paint_pop_clip_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_color_func(
hb_paint_funcs_t *funcs,
hb_paint_color_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_image_func(
hb_paint_funcs_t *funcs,
hb_paint_image_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_linear_gradient_func (
hb_paint_funcs_t *funcs,
hb_paint_linear_gradient_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_radial_gradient_func(
hb_paint_funcs_t *funcs,
hb_paint_radial_gradient_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_sweep_gradient_func(
hb_paint_funcs_t *funcs,
hb_paint_sweep_gradient_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_push_group_func(
hb_paint_funcs_t *funcs,
hb_paint_push_group_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_pop_group_func(
hb_paint_funcs_t *funcs,
hb_paint_pop_group_func_t func,
void *user_data,
hb_destroy_func_t destroy)
void hb_paint_funcs_set_custom_palette_color_func(
hb_paint_funcs_t *funcs,
hb_paint_custom_palette_color_func_t func,
void *user_data,
hb_destroy_func_t destroy)

# hb-shape.h
void hb_shape(
Expand Down
Loading

0 comments on commit 737ff7c

Please sign in to comment.