Beispiel #1
0
static bool font_fromfont(sui_font *font, sui_library *l, char **error, FT_Face face)
{
    (void)l, (void)error;
    font->hb_font = hb_ft_font_create(face, NULL);
    font->hb_face = hb_ft_face_create(face, NULL);
    return true;
}
Beispiel #2
0
ilA_img *ilG_gui_textlayout_render(ilG_gui_textlayout *self, float col[4], enum ilG_gui_textoptions opts)
{
    (void)opts;
    unsigned w = 0, h = 0;
    unsigned x = 0, y = 0;
    int bx = 0, by = 0;
    int scale = 64;
    unsigned i;

    self->cairo_ft_face = cairo_ft_font_face_create_for_ft_face(self->ft_face, 0);
    self->hb_ft_face = hb_ft_face_create(self->ft_face, NULL);

    x *= scale;
    y *= scale;
    self->cairo_glyphs = calloc(self->glyph_count, sizeof(cairo_glyph_t));
    for (i = 0; i < self->glyph_count; i++) {
        self->cairo_glyphs[i].index = self->glyph_info[i].codepoint;
        self->cairo_glyphs[i].x = (x + self->glyph_pos[i].x_offset)/scale;
        self->cairo_glyphs[i].y = (y + self->glyph_pos[i].y_offset)/scale;
        x += self->glyph_pos[i].x_advance;
        y += self->glyph_pos[i].y_advance;
    }

    ilG_gui_textlayout_getExtents(self, &w, &h, &bx, &by, NULL, NULL);
    self->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
    self->cr = cairo_create(self->surface);

    cairo_translate(self->cr, -bx, 1-by);
    cairo_set_source_rgba(self->cr, col[0], col[1], col[2], col[3]);
    cairo_set_font_face(self->cr, self->cairo_ft_face);
    cairo_set_font_size(self->cr, self->pt);
    cairo_show_glyphs(self->cr, self->cairo_glyphs, self->glyph_count);
    cairo_surface_flush(self->surface);

    ilA_img *preswizzle = ilA_img_fromdata(cairo_image_surface_get_data(self->surface), w, h, 8, ILA_IMG_RGBA);
    /*   R G B A | 0x
     * B 0 0 1 0 | 2
     * G 0 1 0 0 | 4
     * R 1 0 0 0 | 8
     * A 0 0 0 1 | 1
    */
    ilA_img *img = ilA_img_bgra_to_rgba(preswizzle);//ilA_img_swizzle(preswizzle, 0x2481);
    ilA_img_free(preswizzle);
    return img;
}