I have Cairo and Pango code to create an image:
#include<stdio.h>
#include<cairo.h>
#include<pango/pangocairo.h>
#define IMAGE_WIDTH 650
#define IMAGE_HEIGHT 150
#define TEXT "HELLO WORLD"
#define FONT "MizuFontAlphabet Normal 40"
int main(int argc , char** argv) {
cairo_surface_t *surface;
cairo_t *cr;
PangoLayout *layout;
PangoFontDescription *desc;
PangoRectangle extents;
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, IMAGE_WIDTH, IMAGE_HEIGHT);
cr = cairo_create(surface);
cairo_rectangle(cr, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_fill(cr);
cairo_stroke(cr);
layout = pango_cairo_create_layout(cr);
pango_layout_set_text(layout, TEXT, -1);
desc = pango_font_description_from_string(FONT);
pango_layout_set_font_description(layout, desc);
pango_font_description_free (desc);
pango_layout_get_pixel_extents(layout, NULL, &extents);
int x = (int) (IMAGE_WIDTH - extents.width) / 2;
int y = (int) (IMAGE_HEIGHT - extents.height) / 2;
cairo_set_source_rgb(cr, 0.33, 0.55, 0.88);
cairo_move_to(cr, x, y);
pango_cairo_show_layout(cr, layout);
g_object_unref(layout);
cairo_surface_write_to_png(surface, "image.png");
cairo_destroy(cr);
cairo_surface_destroy(surface);
return(0);
}
The font I'm using MizuFontAlphabetis a non-standard font, so it needs to be installed in the font directory so that I can use it with Pango:
desc = pango_font_description_from_string(FONT);
How can I download a font from a file if this font has not been installed?
user1129665
source
share