[cairo] print text to a PostScript (PS) file using Cairo
rush ta
anjutagtk at gmail.com
Tue Oct 25 11:19:01 PDT 2005
hi guys...
I m trying to print text to a PostScript (PS) file using Cairo...
I get the prog to complie and run with out errors...
But the PS file obtained doesnot contain any text ...
Here goes the code tell me where i m going wrong...
//----------------------------
Basket.c----------------------------------------------
#include <cairo.h>
#include <cairo-ps.h>
#include <math.h>
void
draw (cairo_t *cr);
#define X_INCHES 8
#define Y_INCHES 3
#define FILENAME "basket.ps <http://basket.ps>"
int
main (void)
{
cairo_surface_t *surface;
cairo_t *cr;
FILE *file;
file = fopen (FILENAME, "w");
if (file == NULL) {
fprintf (stderr, "Failed to open file %s for writing.\n", FILENAME);
return 1;
}
surface = cairo_ps_surface_create (FILENAME,
X_INCHES * 72.0,
Y_INCHES * 72.0);
cr = cairo_create (surface);
cairo_surface_destroy(surface);
draw (cr);
cairo_show_page (cr);
cairo_destroy (cr);
fclose (file);
return 0;
}
void
draw (cairo_t *cr)
{
cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr,72) ;
cairo_set_source_rgb(cr,0,0,0) ;
cairo_move_to(cr,20,100) ;
cairo_show_text(cr,"Hello world !") ;
}
//-------------------------------------------------end of
basket.c-----------------------------------------
Just in case , if someone wants to know.....
The Makefile I use to compile looks like....
EXAMPLES=basket
# I'd like to put a bunch of compiler-specific warning flags here, but
# I don't know a good way to choose the right flags based on the
# compiler in use.
#
# So, for now, if you want more warnings, set them in CFLAGS before
# calling make. For example, for gcc:
#
# CFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes
-Wmissing-declarations -Wnested-externs -fno-strict-aliasing" make
MYCFLAGS=`pkg-config --cflags cairo libpng12`
MYLDFLAGS=`pkg-config --libs cairo libpng12`
all: ${EXAMPLES}
%.o: %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) ${MYCFLAGS} $< -o $@
%: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) ${MYCFLAGS} ${MYLDFLAGS} $^ -o $@
clean:
rm -f ${EXAMPLES} *.o
pls reply ...
regards
rush
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/cairo/attachments/20051025/3a085298/attachment.html
More information about the cairo
mailing list