From: ellson Date: Thu, 20 Jan 2005 17:22:51 +0000 (+0000) Subject: - initial bits of a text_layout plugin - initially just the fontmetrics stuff - later... X-Git-Tag: LAST_LIBGRAPH~32^2~8062 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71b4c575e2b030e3c4127922910b53223f213dbf;p=graphviz - initial bits of a text_layout plugin - initially just the fontmetrics stuff - later pango - use new cairo includes --- diff --git a/lib/common/fontmetrics.c b/lib/common/fontmetrics.c index d12088cab..ff6e00516 100644 --- a/lib/common/fontmetrics.c +++ b/lib/common/fontmetrics.c @@ -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 +#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; diff --git a/lib/common/types.h b/lib/common/types.h index 7e84029af..a18bb869f 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -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; diff --git a/lib/gvc/Makefile.am b/lib/gvc/Makefile.am index d3fecd008..e0a343bef 100644 --- a/lib/gvc/Makefile.am +++ b/lib/gvc/Makefile.am @@ -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 diff --git a/lib/gvc/gvcint.h b/lib/gvc/gvcint.h index 1bc403020..10b151b38 100644 --- a/lib/gvc/gvcint.h +++ b/lib/gvc/gvcint.h @@ -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 */ diff --git a/lib/gvc/gvemit.c b/lib/gvc/gvemit.c index a3b67d9aa..bbea57702 100644 --- a/lib/gvc/gvemit.c +++ b/lib/gvc/gvemit.c @@ -19,6 +19,12 @@ #endif #include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif #include "const.h" #include "types.h" @@ -32,6 +38,9 @@ extern void emit_graph(GVC_t * gvc, graph_t * g, int flags); #include +#ifdef CAIRO_HAS_XLIB_SURFACE +#include + #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; diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index 816ef969e..1c04d526b 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -29,17 +29,16 @@ * 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) diff --git a/lib/gvc/gvplugin.h b/lib/gvc/gvplugin.h index 62579ba81..728aa43ee 100644 --- a/lib/gvc/gvplugin.h +++ b/lib/gvc/gvplugin.h @@ -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 index 000000000..b46b5c023 --- /dev/null +++ b/lib/gvc/gvplugin_text.h @@ -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 index 000000000..86dc362fe --- /dev/null +++ b/lib/gvc/gvtext.c @@ -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 + +#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; +}