[ot-glyph] Improve API names

This commit is contained in:
Ebrahim Byagowi 2019-10-21 13:52:48 +03:30
parent af08f388ab
commit 0b559d750f
4 changed files with 38 additions and 19 deletions

View File

@ -520,6 +520,18 @@ hb_ot_color_palette_get_name_id
hb_ot_font_set_funcs
</SECTION>
<SECTION>
<FILE>hb-ot-glyph</FILE>
hb_ot_glyph_path_t
hb_ot_glyph_path_create
hb_ot_glyph_path_create_from_font
hb_ot_glyph_path_destroy
hb_ot_glyph_path_empty
hb_ot_glyph_path_get_commands
hb_ot_glyph_path_get_coords
hb_ot_glyph_path_reference
</SECTION>
<SECTION>
<FILE>hb-ot-name</FILE>
hb_ot_name_id_t

View File

@ -52,7 +52,7 @@ hb_ot_glyph_path_empty ()
}
hb_ot_glyph_path_t *
hb_ot_glyph_create_path (hb_position_t *coords,
hb_ot_glyph_path_create (hb_position_t *coords,
unsigned int coords_count,
uint8_t *commands,
unsigned int commands_count,
@ -133,14 +133,14 @@ struct _hb_ot_glyph_path_vectors
};
static void
_hb_ot_glyph_free_path_vectors (void *user_data)
_hb_ot_glyph_path_free_vectors (void *user_data)
{
((_hb_ot_glyph_path_vectors *) user_data)->fini ();
free (user_data);
}
hb_ot_glyph_path_t *
hb_ot_glyph_create_path_from_font (hb_font_t *font, hb_codepoint_t glyph)
hb_ot_glyph_path_create_from_font (hb_font_t *font, hb_codepoint_t glyph)
{
_hb_ot_glyph_path_vectors *user_data = (_hb_ot_glyph_path_vectors *)
malloc (sizeof (_hb_ot_glyph_path_vectors));
@ -161,8 +161,8 @@ hb_ot_glyph_create_path_from_font (hb_font_t *font, hb_codepoint_t glyph)
if (unlikely (!ret)) return hb_ot_glyph_path_empty ();
return hb_ot_glyph_create_path (coords.arrayZ, coords.length, commands.arrayZ, commands.length,
user_data, (hb_destroy_func_t) _hb_ot_glyph_free_path_vectors);
return hb_ot_glyph_path_create (coords.arrayZ, coords.length, commands.arrayZ, commands.length,
user_data, (hb_destroy_func_t) _hb_ot_glyph_path_free_vectors);
}
#endif

View File

@ -36,30 +36,31 @@ HB_BEGIN_DECLS
typedef struct hb_ot_glyph_path_t hb_ot_glyph_path_t;
HB_EXTERN hb_ot_glyph_path_t *
hb_ot_glyph_path_empty (void);
HB_EXTERN hb_ot_glyph_path_t *
hb_ot_glyph_create_path (hb_position_t *coords,
hb_ot_glyph_path_create (hb_position_t *coords,
unsigned int coords_count,
uint8_t *commands,
unsigned int commands_count,
void *user_data,
hb_destroy_func_t destroy);
HB_EXTERN const hb_position_t *
hb_ot_glyph_path_get_coords (hb_ot_glyph_path_t *path, unsigned int *count);
HB_EXTERN const uint8_t *
hb_ot_glyph_path_get_commands (hb_ot_glyph_path_t *path, unsigned int *count);
HB_EXTERN hb_ot_glyph_path_t *
hb_ot_glyph_path_reference (hb_ot_glyph_path_t *path);
hb_ot_glyph_path_create_from_font (hb_font_t *font, hb_codepoint_t glyph);
HB_EXTERN void
hb_ot_glyph_path_destroy (hb_ot_glyph_path_t *path);
HB_EXTERN hb_ot_glyph_path_t *
hb_ot_glyph_create_path_from_font (hb_font_t *font, hb_codepoint_t glyph);
hb_ot_glyph_path_empty (void);
HB_EXTERN const uint8_t *
hb_ot_glyph_path_get_commands (hb_ot_glyph_path_t *path, unsigned int *count);
HB_EXTERN const hb_position_t *
hb_ot_glyph_path_get_coords (hb_ot_glyph_path_t *path, unsigned int *count);
HB_EXTERN hb_ot_glyph_path_t *
hb_ot_glyph_path_reference (hb_ot_glyph_path_t *path);
HB_END_DECLS

View File

@ -30,6 +30,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
int
main (int argc, char **argv)
@ -66,30 +67,35 @@ main (int argc, char **argv)
" viewBox=\"%d %d %d %d\"><path d=\"",
extents.x_bearing, 0,
extents.x_bearing + extents.width, font_extents.ascender - font_extents.descender); //-extents.height);
hb_ot_glyph_path_t *path = hb_ot_glyph_create_path_from_font (font, gid);
hb_ot_glyph_path_t *path = hb_ot_glyph_path_create_from_font (font, gid);
unsigned int commands_count;
const uint8_t *commands = hb_ot_glyph_path_get_commands (path, &commands_count);
unsigned int coords_count;
const hb_position_t *coords = hb_ot_glyph_path_get_coords (path, &coords_count);
for (unsigned i = 0, j = 0; i < commands_count && j < coords_count; ++i)
unsigned j = 0;
for (unsigned i = 0; i < commands_count && j < coords_count; ++i)
{
fprintf (f, "%c", commands[i]);
if (commands[i] == 'Z') continue;
assert (coords_count >= j + 2);
fprintf (f, "%d,%d", coords[j], font_extents.ascender - coords[j + 1]); //extents.y_bearing - points[i].y);
j += 2;
if (commands[i] == 'Q')
{
assert (coords_count >= j + 2);
fprintf (f, " %d,%d", coords[j], font_extents.ascender - coords[j + 1]); //extents.y_bearing - points[i].y);
j += 2;
}
if (commands[i] == 'C')
{
assert (coords_count >= j + 4);
fprintf (f, " %d,%d", coords[j], font_extents.ascender - coords[j + 1]); //extents.y_bearing - points[i].y);
j += 2;
fprintf (f, " %d,%d", coords[j], font_extents.ascender - coords[j + 1]); //extents.y_bearing - points[i].y);
j += 2;
}
}
assert (coords_count == j);
fprintf (f, "\"/></svg>");
fclose (f);
hb_ot_glyph_path_destroy (path);