]> granicus.if.org Git - graphviz/commitdiff
provide a support for a single "times" font in -Tswf
authorellson <devnull@localhost>
Tue, 17 Oct 2006 22:01:17 +0000 (22:01 +0000)
committerellson <devnull@localhost>
Tue, 17 Oct 2006 22:01:17 +0000 (22:01 +0000)
plugin/ming/Makefile.am
plugin/ming/gvrender_ming.c

index 434c8f8be2e7df0c4a79969d49d78b901b13d5d9..38dd63bcdb64f991fa3f521ee52351cf938e83ac 100644 (file)
@@ -13,6 +13,7 @@ AM_CPPFLAGS = \
 if WITH_LIBMING
 noinst_LTLIBRARIES = libgvplugin_ming_C.la
 pkglib_LTLIBRARIES = libgvplugin_ming.la
+pkglib_DATA = Bitstream_Vera_Sans.fdb  Bitstream_Vera_Serif.fdb
 endif
 
 libgvplugin_ming_C_la_SOURCES = \
@@ -23,5 +24,4 @@ libgvplugin_ming_la_LDFLAGS = -version-info @VERSION_INFO@ -no-undefined
 libgvplugin_ming_la_SOURCES = $(libgvplugin_ming_C_la_SOURCES)
 libgvplugin_ming_la_LIBADD = @LIBMING_LIBS@ @MATH_LIBS@
 
-EXTRA_DIST = Makefile.old
-
+EXTRA_DIST = Makefile.old Bitstream_Vera_Sans.fdb Bitstream_Vera_Serif.fdb
index 0513600e54f3f2786371fec927fd711b9195e314..cbf7af991f491a78914e3140c87d8398342147d2 100644 (file)
@@ -25,8 +25,9 @@
 #ifdef HAVE_LIBMING
 #include <ming.h>
 
-#define DEFSWFVERSION 6
-#define DEFSWFCOMPRESSION 9
+#define SWFVERSION 6
+#define SWFCOMPRESSION 9
+#define SWFFRAMERATE .5
 
 typedef enum { FORMAT_SWF } format_type; 
 
@@ -35,10 +36,10 @@ static void ming_begin_job(GVJ_t * job)
     SWFMovie movie;
 
     Ming_init();
-    Ming_useSWFVersion(DEFSWFVERSION);
-    Ming_setSWFCompression(DEFSWFCOMPRESSION);
+    Ming_useSWFVersion(SWFVERSION);
+    Ming_setSWFCompression(SWFCOMPRESSION);
     movie = newSWFMovie();
-    SWFMovie_setRate(movie, .5);
+    SWFMovie_setRate(movie, SWFFRAMERATE);
     SWFMovie_setDimension(movie, job->width, job->height);
 
     job->surface = (void*) movie;
@@ -73,41 +74,68 @@ static void ming_end_page(GVJ_t * job)
     SWFMovie_nextFrame(movie);
 }
 
+extern char* gvconfig_libdir(void);
+#define FONT "Bitstream_Vera_Serif.fdb"
+
 static void ming_textpara(GVJ_t * job, pointf p, textpara_t * para)
 {
     SWFMovie movie = (SWFMovie)(job->surface);
-    SWFText text;
+    SWFTextField textfield;
+    SWFDisplayItem item;
     obj_state_t *obj = job->obj;
     gvcolor_t pencolor = obj->pencolor;
     pointf offset;
+    char *font_file_name;
+    FILE *font_file;
+    char *libdir;
+    static SWFFont font;
+
+/* FIXME - hardcoded to a Times-like font */
+    if (font == NULL) {
+       libdir=gvconfig_libdir();
+       font_file_name = malloc(strlen(libdir)+strlen(FONT)+2);
+       strcpy(font_file_name, libdir);
+       strcat(font_file_name, "/");
+       strcat(font_file_name, FONT);
+       font_file = fopen(font_file_name, "r");
+       if (font_file == NULL ) {
+           perror(font_file_name);
+           free(font_file_name);
+           exit(1);
+       }
+       font = loadSWFFontFromFile(font_file);
+       fclose(font_file);
+       free(font_file_name);
+    }
 
-    text = newSWFText2();
-    SWFText_setFont(text, para->fontname);
-    SWFText_setHeight(text, para->fontsize * 20.);
-    SWFText_setColor(text,
+    textfield = newSWFTextField();
+    SWFTextField_setFont(textfield, (SWFBlock)font);
+    SWFTextField_addChars(textfield, para->str);
+    SWFTextField_addUTF8String(textfield, para->str);
+    SWFTextField_setColor(textfield,
         pencolor.u.rgba[0],
         pencolor.u.rgba[1],
         pencolor.u.rgba[2],
         pencolor.u.rgba[3]);
+    SWFTextField_setHeight(textfield, para->fontsize);
 
     switch (para->just) {
     case 'r':
-       offset.x = para->width;
+       offset.x = 0.;
        break;
     case 'l':
-       offset.x = 0.0;
+       offset.x = -para->width;
        break;
     case 'n':
     default:
-       offset.x = para->width / 2.0;
+       offset.x = -para->width/2.;
        break;
     }
     /* offset to baseline */
-    offset.y = 0.;
+    offset.y = -para->height + para->fontsize*.4;  /* empirically determined */
 
-    SWFText_moveTo(text, p.x + offset.x, p.y + offset.y);
-    SWFText_addUTF8String(text, para->str, 0);
-//    SWFMovie_add(movie, (SWFBlock)text);  /* FIXME - causes crash */
+    item = SWFMovie_add(movie, (SWFBlock)textfield);
+    SWFDisplayItem_moveTo(item, p.x + offset.x, p.y + offset.y);
 }
 
 static void ming_ellipse(GVJ_t * job, pointf * A, int filled)