Skip to content
Myr

stb_truetype: allow getting font metrics without explicitly opening file

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent 9f1ef73 · Browse files · 1 file+22 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+22 added−1 removed

  • other:+22 added−1 removed

1 file+22 added−1 removed

modified:stb_truetype.h+22 added-1 removed
554 unmodified lines
555// see discussion of "BASELINE" above.556//557// It's inefficient; you might want to c&p it and optimize it.558559STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap);560// Query the font vertical metrics without having to create a font first.561562563//////////////////////////////////////////////////////////////////////////////564//
2596 unmodified lines
3161 while (e->y0 <= scan_y_bottom) {3162 if (e->y0 != e->y1) {3163 stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);3164 if (z != NULL) {3163 STBTT_assert(z->ey >= scan_y_top);3165 if (j == 0 && off_y != 0) {3166 if (z->ey < scan_y_top) {3167 // this can happen due to subpixel positioning and some kind of fp rounding error i think3168 z->ey = scan_y_top;3169 }3170 }3171 STBTT_assert(z->ey >= scan_y_top); // if we get really unlucky a tiny bit of an edge can be out of bounds3172 // insert at front3173 z->next = active;3174 active = z;3175 }
971 unmodified lines
4147 range.font_size = font_size;4148 return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);4149}41504151STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap)4152{4153 int i_ascent, i_descent, i_lineGap;4154 float scale;4155 stbtt_fontinfo info;4156 stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata, index));4157 scale = size > 0 ? stbtt_ScaleForPixelHeight(&info, size) : stbtt_ScaleForMappingEmToPixels(&info, -size);4158 stbtt_GetFontVMetrics(&info, &i_ascent, &i_descent, &i_lineGap);4159 *ascent = (float) i_ascent * scale;4160 *descent = (float) i_descent * scale;4161 *lineGap = (float) i_lineGap * scale;4162}41634164STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)4165{4166 float ipw = 1.0f / pw, iph = 1.0f / ph;4167 const stbtt_packedchar *b = chardata + char_index;
707 unmodified lines