Skip to content

Commit

Permalink
added dtx_baseline()
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsiomb committed Jul 3, 2018
1 parent 7b71866 commit 12794cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/drawtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ size_t dtx_utf8_from_string(const wchar_t *str, char *buf);

/* ---- metrics ---- */
float dtx_line_height(void);
float dtx_baseline(void);

/* rendered dimensions of a single glyph */
void dtx_glyph_box(int code, struct dtx_box *box);
Expand Down
1 change: 1 addition & 0 deletions src/drawtext_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct dtx_glyphmap {
int crange;

float line_advance;
float baseline;

struct glyph *glyphs;
struct dtx_glyphmap *next;
Expand Down
8 changes: 8 additions & 0 deletions src/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ struct dtx_glyphmap *dtx_create_glyphmap_range(struct dtx_font *fnt, int sz, int
gmap->cend = cend;
gmap->crange = cend - cstart;
gmap->line_advance = FTSZ_TO_PIXELS((float)face->size->metrics.height);
gmap->baseline = -FTSZ_TO_PIXELS((float)face->size->metrics.descender);

if(!(gmap->glyphs = malloc(gmap->crange * sizeof *gmap->glyphs))) {
free(gmap);
Expand Down Expand Up @@ -1081,6 +1082,13 @@ float dtx_line_height(void)
return gmap->line_advance;
}

float dtx_baseline(void)
{
struct dtx_glyphmap *gmap = dtx_get_glyphmap(dtx_font, 0);

return gmap->baseline;
}

void dtx_glyph_box(int code, struct dtx_box *box)
{
int cidx;
Expand Down

0 comments on commit 12794cb

Please sign in to comment.