start of simple font viewer program. Doesn't correctl display the text yet
2002-12-04 James Henstridge <james@daa.com.au> * src/font-view.c (main): start of simple font viewer program. Doesn't correctl display the text yet though :( * src/ftstream-vfs.c (FT_New_Face_From_URI): rename function to match naming scheme used elsewhere.
This commit is contained in:
parent
a5d6209b4f
commit
2f4b9395dc
5 changed files with 134 additions and 12 deletions
|
@ -1,3 +1,11 @@
|
|||
2002-12-04 James Henstridge <james@daa.com.au>
|
||||
|
||||
* src/font-view.c (main): start of simple font viewer program.
|
||||
Doesn't correctl display the text yet though :(
|
||||
|
||||
* src/ftstream-vfs.c (FT_New_Face_From_URI): rename function to
|
||||
match naming scheme used elsewhere.
|
||||
|
||||
2002-12-02 James Henstridge <james@daa.com.au>
|
||||
|
||||
* src/thumbnailer.c (draw_char): split code for drawing character
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
INCLUDES = $(FONT_METHOD_CFLAGS) $(THUMBNAILER_CFLAGS) \
|
||||
-DDIRECTORY_DIR=\"$(vfsdirectorydir)\"
|
||||
INCLUDES = $(FONT_METHOD_CFLAGS) $(THUMBNAILER_CFLAGS) $(FONT_VIEW_CFLAGS) \
|
||||
-DDIRECTORY_DIR=\"$(vfsdirectorydir)\"
|
||||
|
||||
vfsmoduledir = $(libdir)/gnome-vfs-2.0/modules
|
||||
vfsmodule_LTLIBRARIES = libfont-method.la
|
||||
|
||||
noinst_PROGRAMS = thumbnailer
|
||||
noinst_PROGRAMS = thumbnailer font-view
|
||||
|
||||
libfont_method_la_LDFLAGS = -module -avoid-version
|
||||
libfont_method_la_LIBADD = $(FONT_METHOD_LIBS)
|
||||
|
@ -20,6 +20,9 @@ vfsdirectory_DATA = font-method.directory
|
|||
thumbnailer_LDADD = $(THUMBNAILER_LIBS)
|
||||
thumbnailer_SOURCES = ftstream-vfs.c thumbnailer.c
|
||||
|
||||
font_view_LDADD = $(FONT_VIEW_LIBS)
|
||||
font_view_SOURCES = ftstream-vfs.c font-view.c
|
||||
|
||||
EXTRA_DIST = \
|
||||
font-method.conf \
|
||||
font-method.directory
|
||||
|
|
111
vfs-methods/fontilus/font-view.c
Normal file
111
vfs-methods/fontilus/font-view.c
Normal file
|
@ -0,0 +1,111 @@
|
|||
/* -*- mode: C; c-basic-offset: 4 -*- */
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
static XftFont *font;
|
||||
static XftDraw *draw = NULL;
|
||||
static XftColor colour;
|
||||
|
||||
FT_Error FT_New_Face_From_URI(FT_Library library,
|
||||
const gchar *uri,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface);
|
||||
|
||||
static void
|
||||
realize(GtkWidget *widget)
|
||||
{
|
||||
Display *xdisplay;
|
||||
Drawable xdrawable;
|
||||
Visual *xvisual;
|
||||
Colormap xcolormap;
|
||||
|
||||
xdisplay = GDK_WINDOW_XDISPLAY(widget->window);
|
||||
xdrawable = GDK_DRAWABLE_XID(widget->window);
|
||||
xvisual = GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(widget->window));
|
||||
xcolormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(widget->window));
|
||||
|
||||
draw = XftDrawCreate(xdisplay, xdrawable, xvisual, xcolormap);
|
||||
if (!draw) {
|
||||
g_warning("could not create Xft drawable");
|
||||
return;
|
||||
}
|
||||
XftColorAllocName(xdisplay, xvisual, xcolormap, "black", &colour);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
expose_event(GtkWidget *widget, GdkEventExpose *event)
|
||||
{
|
||||
XftDrawString8(draw, &colour, font, 50, 50, "Foo bar", 7);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
FT_Error error;
|
||||
FT_Library library;
|
||||
FT_Face face;
|
||||
FcPattern *pattern;
|
||||
GtkWidget *window;
|
||||
GtkWidget *drawing_area;
|
||||
GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
g_printerr("usage: foo fontfile\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!gnome_vfs_init()) {
|
||||
g_printerr("could not initialise gnome-vfs\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = FT_Init_FreeType(&library);
|
||||
if (error) {
|
||||
g_printerr("could not initialise freetype\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = FT_New_Face_From_URI(library, argv[1], 0, &face);
|
||||
if (error) {
|
||||
g_printerr("could not load face '%s'\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
pattern = FcPatternBuild(NULL,
|
||||
FC_FT_FACE, FcTypeFTFace, face,
|
||||
FC_PIXEL_SIZE, FcTypeDouble, 48.0,
|
||||
NULL);
|
||||
font = XftFontOpenPattern(GDK_DISPLAY(), pattern);
|
||||
if (!font) {
|
||||
g_printerr("could not load face\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_message("ascent=%d, descent=%d, height=%d",
|
||||
font->ascent, font->descent, font->height);
|
||||
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title(GTK_WINDOW(window), "Foo");
|
||||
|
||||
drawing_area = gtk_drawing_area_new();
|
||||
gtk_widget_modify_bg(drawing_area, GTK_STATE_NORMAL, &white);
|
||||
gtk_widget_set_double_buffered(drawing_area, FALSE);
|
||||
gtk_widget_set_size_request(drawing_area, 300, 300);
|
||||
gtk_container_add(GTK_CONTAINER(window), drawing_area);
|
||||
|
||||
g_signal_connect_after(drawing_area, "realize",
|
||||
G_CALLBACK(realize), NULL);
|
||||
g_signal_connect(drawing_area, "expose_event",
|
||||
G_CALLBACK(expose_event), NULL);
|
||||
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||
|
||||
gtk_widget_show_all(window);
|
||||
|
||||
gtk_main();
|
||||
return 0;
|
||||
}
|
|
@ -81,10 +81,10 @@ vfs_stream_open(FT_Stream stream,
|
|||
|
||||
/* load a typeface from a URI */
|
||||
FT_Error
|
||||
FT_New_URI_Face(FT_Library library,
|
||||
const gchar* uri,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface)
|
||||
FT_New_Face_From_URI(FT_Library library,
|
||||
const gchar* uri,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface)
|
||||
{
|
||||
FT_Open_Args args;
|
||||
FT_Stream stream;
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
#define FONT_SIZE 64
|
||||
#define PAD_PIXELS 4
|
||||
|
||||
FT_Error FT_New_URI_Face(FT_Library library,
|
||||
const gchar *uri,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface);
|
||||
FT_Error FT_New_Face_From_URI(FT_Library library,
|
||||
const gchar *uri,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface);
|
||||
|
||||
static void
|
||||
draw_bitmap(GdkPixbuf *pixbuf, FT_Bitmap *bitmap, gint off_x, gint off_y)
|
||||
|
@ -196,7 +196,7 @@ main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
error = FT_New_URI_Face(library, argv[1], 0, &face);
|
||||
error = FT_New_Face_From_URI(library, argv[1], 0, &face);
|
||||
if (error) {
|
||||
g_printerr("could not load face '%s'\n", argv[1]);
|
||||
return 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue