Ejemplo n.º 1
0
static cairo_font_face_t *
font_face_create(gchar *fontfile){
    FT_Error error;
    FT_Library library;
    FT_Face face;
    GFile *file;
    gchar *font_file;

    error = FT_Init_FreeType (&library);
    if (error) {
        g_printerr("Could not initialise freetype\n");
        exit(1);
    }

    file = g_file_new_for_commandline_arg (fontfile);
    font_file = g_file_get_uri (file);
    g_object_unref (file);

    if (!font_file) {
        g_printerr("Could not parse argument into a URI\n");
        exit(1);
    }
    error = FT_New_Face_From_URI (library, font_file, 0, &face);
    if (error) {
        g_printerr("Could not load face '%s'\n", font_file);
        exit(1);
    }
    return cairo_ft_font_face_create_for_ft_face (face, 0);
}
Ejemplo n.º 2
0
int
main(int argc, char **argv)
{
    FT_Error error;
    FT_Library library;
    FT_Face face;
    GFile *file;
    gchar *font_file, *title;
    gint row;
    GtkWidget *window, *hbox, *table, *swin, *drawing_area;
    GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
    GtkWidget *button, *align;

    bindtextdomain(GETTEXT_PACKAGE, MATELOCALEDIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
    textdomain(GETTEXT_PACKAGE);

    gtk_init(&argc, &argv);

    if (argc != 2) {
	g_printerr(_("usage: %s fontfile\n"), argv[0]);
	return 1;
    }

    if (!XftInitFtLibrary()) {
	g_printerr("could not initialise freetype library\n");
	return 1;
    }

    error = FT_Init_FreeType(&library);
    if (error) {
	g_printerr("could not initialise freetype\n");
	return 1;
    }

    file = g_file_new_for_commandline_arg (argv[1]);
    font_file = g_file_get_uri (file);
    g_object_unref (file);

    if (!font_file) {
	g_printerr("could not parse argument into a URI\n");
	return 1;
    }

    error = FT_New_Face_From_URI(library, font_file, 0, &face);
    if (error) {
	g_printerr("could not load face '%s'\n", font_file);
	return 1;
    }

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    title = g_strconcat(face->family_name,
			face->style_name ? ", " : "",
			face->style_name, NULL);
    gtk_window_set_title(GTK_WINDOW(window), title);
    set_icon(GTK_WINDOW(window), font_file);
    g_free(title);
    gtk_window_set_resizable(GTK_WINDOW(window), TRUE);

    hbox = gtk_hbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), hbox);

    swin = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
				   GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
    gtk_box_pack_start(GTK_BOX(hbox), swin, TRUE, TRUE, 0);

    drawing_area = gtk_drawing_area_new();
    gtk_widget_modify_bg(drawing_area, GTK_STATE_NORMAL, &white);
    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin),
					  drawing_area);
#if !GTK_CHECK_VERSION (3, 0, 0)
    g_signal_connect (drawing_area, "realize", G_CALLBACK(create_text_pixmap), face);
#endif

    /* set the minimum size on the scrolled window to prevent
     * unnecessary scrolling */
    gtk_widget_set_size_request(swin, 500, -1);

    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    table = gtk_table_new(1, 2, FALSE);
    gtk_container_set_border_width(GTK_CONTAINER(table), 5);
    gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, TRUE, 0);

    row = 0;
    add_face_info(table, &row, font_file, face);

    /* add install button */
    align = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
    gtk_table_attach (GTK_TABLE (table), align, 0, 2, row, row + 1,
                      GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);

    button = gtk_button_new_with_mnemonic (_("I_nstall Font"));
    g_signal_connect (button, "clicked",
                      G_CALLBACK (install_button_clicked_cb), font_file);
    gtk_container_add (GTK_CONTAINER (align), button);


    gtk_table_set_col_spacings(GTK_TABLE(table), 8);
    gtk_table_set_row_spacings(GTK_TABLE(table), 2);
    gtk_widget_show_all(window);

    gtk_main();
    return 0;
}