Exemplo n.º 1
0
void glf_get_string_bb(gl_tex_font_p glf, const char *text, int n, GLfloat *x0, GLfloat *y0, GLfloat *x1, GLfloat *y1)
{
    *x0 = 0.0;
    *x1 = 0.0;
    *y0 = 0.0;
    *y1 = 0.0;

    if((glf != nullptr) && (glf->ft_face != nullptr))
    {
        uint8_t *nch;
        uint8_t *nch2;
        uint8_t *ch = (uint8_t*)text;
        float x = 0.0;
        float y = 0.0;
        float xx0, xx1, yy0, yy1;
        int i;
        uint32_t curr_utf32, next_utf32;

        nch = utf8_to_utf32(ch, &curr_utf32);
        curr_utf32 = FT_Get_Char_Index(glf->ft_face, curr_utf32);

        for(i = 0; (*ch != 0) && !((n >= 0) && (i >= n)); i++)
        {
            FT_Vector kern;
            char_info_p g = glf->glyphs + curr_utf32;

            nch2 = utf8_to_utf32(nch, &next_utf32);

            next_utf32 = FT_Get_Char_Index(glf->ft_face, next_utf32);
            ch = nch;
            nch = nch2;

            FT_Get_Kerning(glf->ft_face, curr_utf32, next_utf32, FT_KERNING_UNSCALED, &kern);   // kern in 1/64 pixel
            curr_utf32 = next_utf32;

            xx0 = x + g->left;
            xx1 = xx0 + g->width;
            yy0 = y + g->top;
            yy1 = yy0 - g->height;
            bbox_add(&xx0, &xx1, &yy0, &yy1, x0, x1, y0, y1);

            x += static_cast<GLfloat>(kern.x + g->advance_x) / 64.0;
            y += static_cast<GLfloat>(kern.y + g->advance_y) / 64.0;
        }
    }
}
Exemplo n.º 2
0
void glf_get_string_bb(gl_tex_font_p glf, const char *text, int n, int32_t *x0, int32_t *y0, int32_t *x1, int32_t *y1)
{
    uint8_t *ch = (uint8_t*)text;
    *x0 = 0;
    *x1 = 0;
    *y0 = 0;
    *y1 = 0;

    if(glf && glf->ft_face && *ch)
    {
        FT_Vector kern;
        int32_t x_pt = 0;
        int32_t y_pt = 0;
        int32_t xx0, xx1, yy0, yy1;
        uint32_t curr_utf32, next_utf32;

        ch = utf8_to_utf32(ch, &curr_utf32);
        curr_utf32 = FT_Get_Char_Index(glf->ft_face, curr_utf32);
        for(int i = 0; (n < 0) || (i < n); i++)
        {
            char_info_p g = glf->glyphs + curr_utf32;
            n = (*ch) ? (n) : (0);

            ch = utf8_to_utf32(ch, &next_utf32);
            next_utf32 = FT_Get_Char_Index(glf->ft_face, next_utf32);
            FT_Get_Kerning(glf->ft_face, curr_utf32, next_utf32, FT_KERNING_UNSCALED, &kern);   // kern in 1/64 pixel
            curr_utf32 = next_utf32;

            xx0 = x_pt + g->left * 64;
            xx1 = xx0 + g->width * 64;
            yy0 = y_pt + g->top * 64;
            yy1 = yy0 - g->height * 64;
            bbox_add(&xx0, &xx1, &yy0, &yy1, x0, x1, y0, y1);

            x_pt += kern.x + g->advance_x_pt;
            y_pt += kern.y + g->advance_y_pt;
        }
    }
}