]> granicus.if.org Git - graphviz/commitdiff
- initial bits of a text_layout plugin - initially just the fontmetrics stuff - later...
authorellson <devnull@localhost>
Thu, 20 Jan 2005 17:22:51 +0000 (17:22 +0000)
committerellson <devnull@localhost>
Thu, 20 Jan 2005 17:22:51 +0000 (17:22 +0000)
- use new cairo includes

lib/common/fontmetrics.c
lib/common/types.h
lib/gvc/Makefile.am
lib/gvc/gvcint.h
lib/gvc/gvemit.c
lib/gvc/gvplugin.c
lib/gvc/gvplugin.h
lib/gvc/gvplugin_text.h [new file with mode: 0644]
lib/gvc/gvtext.c [new file with mode: 0644]

index d12088cabacb47616dbc66ac7c47a402b300f931..ff6e00516b7093417d615a476f90b2d9fc966b68 100644 (file)
@@ -124,6 +124,10 @@ static double courFontWidth[] = {
     0.5999, 0.5999, 0.5999, 0.5999, 0.5999, 0.5999, 0.5999, 0.5999,    /* øùúû     */
 };
 
+#ifdef CAIRO_HAS_FT_FONT
+#include <cairo-ft.h>
+#endif
+
 #if !defined(DISABLE_CODEGENS) && !defined(HAVE_GD_FREETYPE)
 extern codegen_t *Output_codegen;
 
@@ -195,7 +199,7 @@ estimate_textsize(textline_t * textline, char *fontname, double fontsz,
 double textwidth(textline_t * textline, char *fontname, double fontsize)
 {
     char *fontpath = NULL;
-#ifdef HAVE_CAIRO
+#ifdef CAIRO_HAS_FT_FONT
     cairo_t *cr;
     cairo_text_extents_t extents;
 
index 7e84029aff8586f70d6f787b6ed792fc874215ac..a18bb869f52f50396d09a0d07983b48724ded5f2 100644 (file)
@@ -37,6 +37,7 @@ extern "C" {
     typedef struct gvrender_engine_s gvrender_engine_t;
     typedef struct gvlayout_engine_s gvlayout_engine_t;
     typedef struct gvdisplay_engine_s gvdisplay_engine_t;
+    typedef struct gvtext_engine_s gvtext_engine_t;
 
     typedef struct htmllabel_t htmllabel_t;
 
index d3fecd008e5b85e1620c61efcfd2f372507c41e9..e0a343befbd113f873d6cf3a61384b962d3548ce 100644 (file)
@@ -15,12 +15,13 @@ AM_CPPFLAGS = \
 
 #LIBS = @LIBLTDL@
 
-pkginclude_HEADERS = gvc.h gvcint.h gvplugin_render.h \
-       gvplugin_layout.h gvplugin_display.h gvplugin.h
+pkginclude_HEADERS = gvc.h gvcint.h gvplugin.h \
+       gvplugin_render.h gvplugin_layout.h \
+       gvplugin_text.h gvplugin_display.h
 pkglib_LTLIBRARIES = libgvc.la
 pkgconfig_DATA = libgvc.pc
 
-libgvc_la_SOURCES = gvrender.c gvlayout.c gvcontext.c gvjobs.c \
+libgvc_la_SOURCES = gvrender.c gvlayout.c gvtext.c gvcontext.c gvjobs.c \
        gvemit.c gvplugin.c gvconfig.c
 
 EXTRA_DIST = Makefile.old
index 1bc40302003c6324ae9f3205b3b8e6dbc8f83fa3..10b151b384edb4afa3efb46826005a610dfd7db1 100644 (file)
@@ -154,6 +154,7 @@ extern "C" {
        gv_plugin_t *api[NUM_APIS];     /* array of current plugins for each api */
 
        void *display; /* window display data for gvdisplay plugin */
+       gvtext_engine_t *text_engine;   /* current text layout engine */
 
        /* gvrender_begin_job() */
        char *layout_type;      /* string name of layout type */
index a3b67d9aaf86ca189c5b19f5fa4a3e656c7329bc..bbea577026cf5aeab94fffa1951b0e56bb83d884 100644 (file)
 #endif
 
 #include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
 
 #include "const.h"
 #include "types.h"
@@ -32,6 +38,9 @@ extern void emit_graph(GVC_t * gvc, graph_t * g, int flags);
 
 #include <cairo.h>
 
+#ifdef CAIRO_HAS_XLIB_SURFACE
+#include <cairo-xlib.h>
+
 #define PANFACTOR 10
 #define ZOOMFACTOR 1.1
 #define EPSILON .0001
@@ -502,6 +511,7 @@ static int toggle_fit_cb(gvrender_job_t * job)
     }
     return 0;
 }
+#endif /* CAIRO_HAS_XLIB_SURFACE */
 #endif /* X_DISPLAY_MISSING */
 
 void gvemit_graph(GVC_t * gvc, graph_t * g, int flags)
@@ -513,7 +523,7 @@ void gvemit_graph(GVC_t * gvc, graph_t * g, int flags)
     job->flags = flags;
 
    if (flags & GVRENDER_X11_EVENTS) {
-#if !defined(X_DISPLAY_MISSING) && !defined(DISABLE_GVRENDER) && defined(HAVE_CAIRO)
+#ifdef CAIRO_HAS_XLIB_SURFACE
 
        const char *display=NULL;
        int argb=0;
index 816ef969edb5aea41a8e3f19031ce826908b4548..1c04d526bd2a2ced18282411bea60f460881cc14 100644 (file)
  * The enumerated type is defined gvplugin.h.  The apis array is
  * inititialized here by redefining ELEM and reinvoking APIS.
  *
- * The last enum is NUM_APIS which is the size of the array.
+ * The NUM_APIS is the size of the array.
  */
 #define ELEM(x) #x,
-static char *apis[] = { APIS };        /* "renderer", "scripter", ... */
-
+static char *apis[] = { APIS };        /* "render", "layout", ... */
 #undef ELEM
 
 /* translate a string api name to its type, or -1 on error */
 api_t gvplugin_api(char *str)
 {
-    api_t api;
+    int api;
 
     for (api = 0; api < NUM_APIS; api++) {
        if (strcmp(str, apis[api]) == 0)
index 62579ba81911302b0836fc2936530a74877d645a..728aa43eedc2dd115efd335c2ac68b4ce9377f4d 100644 (file)
@@ -32,13 +32,13 @@ extern "C" {
  * The enumerated type is defined here.  The apis array is
  * inititialized in gvplugin.c by redefining ELEM and reinvoking APIS.
  *
- * The last enum is NUM_APIS which is the size of the array.
+ * NUM_APIS is the size of the array.
  */
-// #define APIS ELEM(render) ELEM(layout) ELEM(parser) ELEM(scripter) ...
-#define APIS ELEM(render) ELEM(layout) ELEM(display)
+#define APIS ELEM(render) ELEM(layout) ELEM(display) ELEM(text)
+#define NUM_APIS 4
 
 #define ELEM(x) API_##x,
-    typedef enum { APIS NUM_APIS } api_t;      /* API_render, API_layout, ... */
+    typedef enum { APIS } api_t; /* API_render, API_layout, ... */
 #undef ELEM
 
     typedef struct {
@@ -55,7 +55,8 @@ extern "C" {
     } gvplugin_api_t;
 
     typedef struct {
-       char *name;             /* used instead of a file pathname when this plugin is builtin */
+       char *name;             /* used instead of a file pathname
+                                       when this plugin is builtin */
        gvplugin_api_t *apis;
     } gvplugin_t;
 
diff --git a/lib/gvc/gvplugin_text.h b/lib/gvc/gvplugin_text.h
new file mode 100644 (file)
index 0000000..b46b5c0
--- /dev/null
@@ -0,0 +1,34 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/**********************************************************
+*      This software is part of the graphviz package      *
+*                http://www.graphviz.org/                 *
+*                                                         *
+*            Copyright (c) 1994-2004 AT&T Corp.           *
+*                and is licensed under the                *
+*            Common Public License, Version 1.0           *
+*                      by AT&T Corp.                      *
+*                                                         *
+*        Information and Software Systems Research        *
+*              AT&T Research, Florham Park NJ             *
+**********************************************************/
+
+#ifndef GVTEXT_PLUGIN_H
+#define GVTEXT_PLUGIN_H
+
+#include "gvplugin.h"
+#include "gvcint.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    struct gvtext_engine_s {
+       int (*width) (textline_t *textline, char *fontname, double fontsize, char* fontpath);
+    };
+
+#ifdef __cplusplus
+}
+#endif
+#endif                         /* GVTEXT_PLUGIN_H */
diff --git a/lib/gvc/gvtext.c b/lib/gvc/gvtext.c
new file mode 100644 (file)
index 0000000..86dc362
--- /dev/null
@@ -0,0 +1,61 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/**********************************************************
+*      This software is part of the graphviz package      *
+*                http://www.graphviz.org/                 *
+*                                                         *
+*            Copyright (c) 1994-2004 AT&T Corp.           *
+*                and is licensed under the                *
+*            Common Public License, Version 1.0           *
+*                      by AT&T Corp.                      *
+*                                                         *
+*        Information and Software Systems Research        *
+*              AT&T Research, Florham Park NJ             *
+**********************************************************/
+
+/*
+ *  text_layout engine wrapper
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include "const.h"
+#include "types.h"
+#include "macros.h"
+
+#include "gvplugin_text.h"
+#include "gvc.h"
+
+#if 0
+int gvlayout_select(GVC_t * gvc, char *layout)
+{
+    gv_plugin_t *plugin;
+    gvplugin_type_t *typeptr;
+
+    plugin = gvplugin_load(gvc, API_layout, layout);
+    if (plugin) {
+       typeptr = plugin->typeptr;
+       gvc->layout_type = typeptr->type;
+       gvc->layout_engine = (gvlayout_engine_t *) (typeptr->engine);
+       gvc->layout_id = typeptr->id;
+       return GVRENDER_PLUGIN;
+    }
+    return NO_SUPPORT;
+}
+#endif
+
+double gvtext_width(GVC_t *gvc, textline_t *textline, char *fontname, double fontsize, char *fontpath)
+{
+    gvtext_engine_t *gvte = gvc->text_engine;
+    int rc;
+
+    if (gvte && gvte->width) {
+       rc = gvte->width(textline, fontname, fontsize, fontpath);
+    }
+    return textline->width;
+}