static float ui_draw_glyph(fz_font *font, int gid, float x, float y) { struct glyph *glyph; float s0, t0, s1, t1, xc, yc; glyph = lookup_glyph(font, gid, &x, &y); if (!glyph) return 0; s0 = (float) glyph->s / g_cache_w; t0 = (float) glyph->t / g_cache_h; s1 = (float) (glyph->s + glyph->w) / g_cache_w; t1 = (float) (glyph->t + glyph->h) / g_cache_h; xc = floorf(x) + glyph->lsb; yc = floorf(y) - glyph->top + glyph->h; glTexCoord2f(s0, t0); glVertex2f(xc, yc - glyph->h); glTexCoord2f(s1, t0); glVertex2f(xc + glyph->w, yc - glyph->h); glTexCoord2f(s1, t1); glVertex2f(xc + glyph->w, yc); glTexCoord2f(s0, t1); glVertex2f(xc, yc); return fz_advance_glyph(ctx, font, gid, 0) * g_font_size; }
static float add_glyph(int gid, float x, float y) { struct glyph *glyph; int subx = (x - floor(x)) * XPRECISION; int suby = (y - floor(y)) * YPRECISION; glyph = lookup_glyph(text_font, text_scale, gid, subx, suby); if (!glyph) return 0; float s0 = (float) glyph->s / CACHESIZE; float t0 = (float) glyph->t / CACHESIZE; float s1 = (float) (glyph->s + glyph->w) / CACHESIZE; float t1 = (float) (glyph->t + glyph->h) / CACHESIZE; float xc = floor(x) + glyph->x; float yc = floor(y) + glyph->y; add_rect(xc, yc, xc + glyph->w, yc + glyph->h, s0, t0, s1, t1); return glyph->advance; }