noinst_LTLIBRARIES = libcommon.la
if !DISABLE_CODEGENS
+if WITH_LIBGD
CODEGENS = diagen.c figgen.c hpglgen.c gdgen.c mapgen.c mifgen.c mpgen.c \
picgen.c psgen.c svggen.c vrmlgen.c vtxgen.c ps.txt xdgen.c color_names
+else
+CODEGENS = diagen.c figgen.c hpglgen.c mapgen.c mifgen.c mpgen.c \
+ picgen.c psgen.c svggen.c vtxgen.c ps.txt xdgen.c color_names
+endif
endif
dia_fputs(" </dia:attribute>\n");
dia_fputs(" <dia:attribute name=\"obj_bb\">\n");
dia_printf(" <dia:rectangle val=\"%g,%g;%g,%g\"/>\n",
- mp.x - (Scale * (line->width) / 2.), mp.y - 0.4,
- mp.x + (Scale * (line->width) / 2.), mp.y + 0.4);
+ mp.x - (Scale * (line->dimen.x) / 2.), mp.y - 0.4,
+ mp.x + (Scale * (line->dimen.x) / 2.), mp.y + 0.4);
dia_fputs(" </dia:attribute>\n");
dia_fputs(" </dia:object>\n");
}
0.5999, 0.5999, 0.5999, 0.5999, 0.5999, 0.5999, 0.5999, 0.5999, /* øùúû */
};
-#if !defined(DISABLE_CODEGENS) && !defined(HAVE_GD_FREETYPE)
-extern codegen_t *Output_codegen;
-
-double _dpi;
-void initDPI(graph_t * g)
-{
- _dpi = GD_drawing(g)->dpi;
-fprintf(stderr,"graph dpi = %g\n", _dpi);
-}
-
-extern codegen_t GD_CodeGen;
-
-double textheight(int nlines, double fontsz)
-{
- if (Output_codegen == &GD_CodeGen) {
- double fsize = (fontsz * _dpi) / POINTS_PER_INCH; /* in pixels */
- double fontsize = builtinFontHt(fsize);
- return (nlines * (int) (fontsize * LINESPACING) *
- POINTS_PER_INCH) / _dpi;
- } else
- return nlines * (int) (fontsz * LINESPACING);
-}
-#endif
-
/* estimate_textsize:
- * Estimate width of text, for given face and size, in points.
- * Value is stored textline->width.
+ * Estimate width and height of text, for given face and size, in points.
+ * Value is stored textline->size.
* NOTE: Tables are based on a font of size 1. Need to multiply by
* fontsize to get appropriate value.
*/
static void
-estimate_textsize(textline_t * textline, char *fontname, double fontsz,
- char **fontpath)
+estimate_textsize(graph_t *g, textline_t * textline, char *fontname, double fontsz, char **fontpath)
{
double *Fontwidth;
char c, *p;
- textline->width = 0.0;
- textline->height = fontsz;
+ textline->dimen.x = 0.0;
+ textline->dimen.y = fontsz;
textline->xshow = NULL;
textline->layout = NULL;
textline->free_layout = NULL;
-#if !defined(DISABLE_CODEGENS) && !defined(HAVE_GD_FREETYPE)
+#if !defined(DISABLE_CODEGENS) && !defined(HAVE_GD_FREETYPE) && defined(HAVE_LIBGD)
if (Output_codegen == &GD_CodeGen) {
- int cwidth;
- double fsize = (fontsz * _dpi) / POINTS_PER_INCH; /* in pixels */
+ double scale = GD_drawing(g)->dpi) / POINTS_PER_INCH;
+ double fsize = fontsz * scale; /* in pixels */
*fontpath = "[internal gd]";
- cwidth = builtinFontWd(fsize);
- if ((p = textline->str)) {
- textline->width = strlen(p) * cwidth * POINTS_PER_INCH / _dpi;
- }
+ if ((p = textline->str))
+ textline->dimen.x = strlen(p) * builtinFontWd(fsize) / scale;
+ textline->dimen.y = builtinFontHt(fsize) / scale;
return;
- } else if (!strncasecmp(fontname, "cour", 4)) {
-#else
- if (!strncasecmp(fontname, "cour", 4)) {
+ }
#endif
+ if (!strncasecmp(fontname, "cour", 4)) {
*fontpath = "[internal courier]";
Fontwidth = courFontWidth;
} else if (!strncasecmp(fontname, "arial", 5)
}
if ((p = textline->str)) {
while ((c = *p++))
- textline->width += Fontwidth[(unsigned char) c];
- textline->width *= fontsz;
+ textline->dimen.x += Fontwidth[(unsigned char) c];
+ textline->dimen.x *= fontsz;
}
}
-double textwidth(graph_t *g, textline_t * textline, char *fontname, double fontsize)
+pointf textsize(graph_t *g, textline_t * textline, char *fontname, double fontsize)
{
char *fontpath = NULL;
if (! gvtextlayout(GD_gvc(g), textline, fontname, fontsize, &fontpath))
- estimate_textsize(textline, fontname, fontsize, &fontpath);
+ estimate_textsize(g, textline, fontname, fontsize, &fontpath);
if (Verbose) {
if (emit_once(fontname)) {
fontname, fontpath);
}
}
- return textline->width;
+ return textline->dimen;
}
case 'l':
break;
case 'r':
- p.x -= line->width;
+ p.x -= line->dimen.x;
break;
default:
case 'n':
- p.x -= line->width / 2;
+ p.x -= line->dimen.x / 2;
break;
}
#include "htmltable.h"
#include "htmlparse.h"
#include "htmllex.h"
-#include "entities.h"
#include <ctype.h>
#ifdef HAVE_LIBEXPAT
return s;
}
-#define MAXENTLEN 8
-
-static int
-comp_entities(const void *e1, const void *e2) {
- struct entities_s *en1 = (struct entities_s *) e1;
- struct entities_s *en2 = (struct entities_s *) e2;
- return strcmp(en1->name, en2->name);
-}
-
-/* scanEntity:
- * Scan non-numeric entity, convert to &#...; form and store in xbuf.
- * t points to first char after '&'. Return after final semicolon.
- * If unknown, we return t and let libexpat flag the error.
- */
-static char*
-scanEntity (char* t, agxbuf* xb)
-{
- char* endp = strchr (t, ';');
- struct entities_s key, *res;
- int len;
- char buf[MAXENTLEN+1];
-
- agxbputc(xb, '&');
- if (!endp) return t;
- if (((len = endp-t) > MAXENTLEN) || (len < 2)) return t;
- strncpy (buf, t, len);
- buf[len] = '\0';
- key.name = buf;
- res = bsearch(&key, entities, NR_OF_ENTITIES,
- sizeof(entities[0]), comp_entities);
- if (!res) return t;
- sprintf (buf, "%d", res->value);
- agxbputc(xb, '#');
- agxbput(xb, buf);
- agxbputc(xb, ';');
- return (endp+1);
-}
-
/* findNext:
* Return next XML unit. This is either <..>, an HTML
* comment <!-- ... -->, or characters up to next <.
tl.str = ti->str;
tl.xshow = ti->xshow;
tl.layout = ti->layout;
- tl.width = lines[i].size;
+ tl.dimen.x = lines[i].size;
+ tl.dimen.y = lines[i].lfsize;
tl.just = lines[i].just;
gvrender_textline(job, p_, &tl);
{
double xsize = 0.0;
double fsize;
- int width;
char *fname;
char *news = NULL;
textline_t *lp = txt->line;
+ pointf size;
if (txt->font) {
if (txt->font->size > 0.0)
free(lp->str);
lp->str = news;
- width = textwidth(g, lp, fname, fsize);
+ size = textsize(g, lp, fname, fsize);
/* no margins are added since the containing node or cell will pad */
- if (width > xsize)
- xsize = width;
+ if (dimen.x > xsize)
+ xsize = size.x;
lp++;
}
txt->box.UR.x = xsize;
if (txt->nlines == 1)
- txt->box.UR.y = (int) (fsize);
+ txt->box.UR.y = (int) (size.y);
else
- txt->box.UR.y = txt->nlines * (int) (fsize * LINESPACING);
+ txt->box.UR.y = txt->nlines * (int) (size.y * LINESPACING);
return 0;
}
#endif
{
double xsize = 0.0, ysize = 0.0;
double fsize, lsize = 0.0;
+ pointf sz;
int i, j, w = 0, width = 0;
char *fname;
textline_t lp;
fsize = env->finfo.size;
fname = env->finfo.name;
}
- w = textwidth(g, &lp, fname, fsize);
+ sz = textsize(g, &lp, fname, fsize);
+ w = sz.x;
free (ftxt->lines[i].items[j].str);
ftxt->lines[i].items[j].str = lp.str;
- ftxt->lines[i].items[j].size = (double) w;
+ ftxt->lines[i].items[j].size = sz.x;
ftxt->lines[i].items[j].xshow = lp.xshow;
ftxt->lines[i].items[j].layout = lp.layout;
ftxt->lines[i].items[j].free_layout = lp.free_layout;
|| ((p = agget(g, "resolution")) && p[0]))
GD_drawing(g)->dpi = atof(p);
- /* The following two functions rely on dpi being set */
-#if !defined(DISABLE_CODEGENS) && !defined(HAVE_GD_FREETYPE)
+ /* The following functions relies on dpi being set */
if (GD_drawing(g)->dpi < 1.0) GD_drawing(g)->dpi = DEFAULT_DPI;
- initDPI(g);
-#endif
do_graph_label(g);
Initial_dist = MYHUGE;
#include "htmltable.h"
#include <limits.h>
-#ifndef DISABLE_CODEGENS
-extern codegen_t *Output_codegen;
-extern codegen_t *GD_CodeGen;
-#endif
-
static void storeline(graph_t *g, textlabel_t *lp, char *line, char terminator)
{
- double width = 0.0;
+ pointf size;
lp->u.txt.line =
ALLOC(lp->u.txt.nlines + 2, lp->u.txt.line, textline_t);
lp->u.txt.line[lp->u.txt.nlines].str = line;
- width = textwidth(g, &(lp->u.txt.line[lp->u.txt.nlines]),
+ size = textsize(g, &(lp->u.txt.line[lp->u.txt.nlines]),
lp->fontname, lp->fontsize);
lp->u.txt.line[lp->u.txt.nlines].just = terminator;
lp->u.txt.nlines++;
/* total width = max line width */
- if (lp->dimen.x < width)
- lp->dimen.x = width;
+ if (lp->dimen.x < size.x)
+ lp->dimen.x = size.x;
/* recalculate total height */
-#if !defined(DISABLE_CODEGENS) && !defined(HAVE_GD_FREETYPE)
- if (Output_codegen == &GD_CodeGen)
- lp->dimen.y = textheight(lp->u.txt.nlines, lp->fontsize);
- else
- lp->dimen.y =
- lp->u.txt.nlines * (int) (lp->fontsize * LINESPACING);
-#else
- lp->dimen.y = lp->u.txt.nlines * (int) (lp->fontsize * LINESPACING);
-#endif
-
+ lp->dimen.y = lp->u.txt.nlines * (int) (size.y * LINESPACING);
}
/* compiles <str> into a label <lp> and returns its bounding box size. */
p.x = p.x;
break;
case 'r':
- p.x = p.x - line->width;
+ p.x = p.x - line->dimen.x;
break;
default:
case 'n':
- p.x = p.x - line->width / 2;
+ p.x = p.x - line->dimen.x / 2;
break;
}
pf = cvt2ptf(p);
#endif
/* Why on earth would we do this either. But it works. SCN 2/26/2002 */
pf.y += fontsz / (3.0 * POINTS_PER_INCH);
- pf.x += line->width / (2.0 * POINTS_PER_INCH);
+ pf.x += line->dimen.x / (2.0 * POINTS_PER_INCH);
if (!(S[SP].size)) { /* size was never set in this or hierarchically higher context */
pic_set_font(S[SP].font, fontsz); /* primarily to output font and/or size directives */
for (flag = SP; ((S[flag].size = fontsz), flag); flag--) /* set size in contexts */
case 'l':
break;
case 'r':
- p.x -= line->width;
+ p.x -= line->dimen.x;
break;
default:
case 'n':
- p.x -= line->width / 2;
+ p.x -= line->dimen.x / 2;
break;
}
fprintf(Output_file, "%d %d moveto\n%s\n[%s]\nxshow\n",
break;
}
fprintf(Output_file, "%d %d moveto %.1f %.1f %s alignedtext\n",
- p.x, p.y, line->width, adj, ps_string(line->str,isLatin1));
+ p.x, p.y, line->dimen.x, adj, ps_string(line->str,isLatin1));
}
}
fprintf(Output_file, Stroke);
}
+#ifdef HAVE_LIBGD
static void writePSBitmap (gdImagePtr im, point p, point sz)
{
int x, y, px;
fprintf(Output_file, "grestore\n");
}
+#endif
static void ps_freeimage_gd (void *data)
{
+#ifdef HAVE_LIBGD
gdImageDestroy((gdImagePtr)data);
+#endif
+}
+
+static void ps_freeimage_ps (void *data)
+{
+#if 0
+ free (data);
+#endif
}
/* ps_usershape:
static void ps_usershape(usershape_t *us, boxf b, point *A, int n, bool filled)
{
int j;
+#ifdef HAVE_LIBGD
gdImagePtr gd_img = NULL;
+#endif
ps_image_t *ps_img = NULL;
point offset;
}
if (us->data) {
- if (us->datafree == ps_freeimage_gd)
+ if (us->datafree == ps_freeimage_gd) {
+#ifdef HAVE_LIBGD
gd_img = (gdImagePtr)(us->data); /* use cached data */
+#endif
+ }
+ else if (us->datafree == ps_freeimage_ps) {
#if 0
- else if (us->datafree == ps_freeimage_ps)
ps_img = (ps_image_t *)(us->data); /* use cached data */
#endif
+ }
else {
us->datafree(us->data); /* free incompatible cache data */
us->data = NULL;
}
}
- if (!gd_img && !ps_img) { /* read file into cache */
+#ifdef HAVE_LIBGD
+ if (!ps_img && !gd_img) { /* read file into cache */
+#else
+ if (!ps_img) { /* read file into cache */
+#endif
fseek(us->f, 0, SEEK_SET);
switch (us->type) {
+#ifdef HAVE_LIBGD
#ifdef HAVE_GD_PNG
case FT_PNG:
gd_img = gdImageCreateFromPng(us->f);
case FT_JPEG:
gd_img = gdImageCreateFromJpeg(us->f);
break;
+#endif
#endif
case FT_PS:
case FT_EPS:
default:
break;
}
+#ifdef HAVE_LIBGD
if (gd_img) {
us->data = (void*)gd_img;
us->datafree = ps_freeimage_gd;
}
+#endif
#if 0
if (ps_img) {
us->data = (void*)ps_img;
return;
}
+#ifdef HAVE_LIBGD
if (gd_img) {
point sz;
sz.x = A[0].x - A[2].x;
writePSBitmap (gd_img, A[2], sz);
return;
}
+#endif
/* some other type of image */
agerr(AGERR, "usershape %s is not supported in PostScript output\n", us->name);
#include "colorprocs.h" /* must collow color.h (in types.h) */
#include "geomprocs.h" /* must follow geom.h (in types.h) */
#include "graph.h" /* must follow types.h */
-#include "utils.h" /* must follow types.h */
+#include "agxbuf.h"
+#include "utils.h" /* must follow types.h and agxbuf.h */
#include "gvplugin.h" /* must follow gvcext.h (in types.h) */
#include "gvcint.h" /* must follow gvcext.h (in types.h) */
#include "gvcproc.h" /* must follow gvcext.h (in types.h) */
extern void shape_clip(node_t * n, point curve[4]);
extern void size_label (graph_t* g, textlabel_t* rv);
extern void start_timer(void);
- extern double textwidth(graph_t *g, textline_t * textline,
+ extern pointf textsize(graph_t *g, textline_t * textline,
char *fontname, double fontsz);
extern void translate_bb(Agraph_t *, int);
extern void use_library(char *);
typedef struct textline_t {
char *str; /* stored in utf-8 */
char *xshow;
- double width, height;
- char just;
void *layout;
void (*free_layout) (void *layout); /* FIXME - this is ugly */
+ pointf dimen;
+ char just;
} textline_t;
typedef struct textlabel_t {
#include "render.h"
#include "agxbuf.h"
#include "htmltable.h"
+#include "entities.h"
#ifndef MSWIN32
#include <unistd.h>
return a;
}
-#include "entities.h"
-
static int comp_entities(const void *e1, const void *e2) {
struct entities_s *en1 = (struct entities_s *) e1;
struct entities_s *en2 = (struct entities_s *) e2;
return strcmp(en1->name, en2->name);
}
+#define MAXENTLEN 8
+
+/* scanEntity:
+ * * Scan non-numeric entity, convert to &#...; form and store in xbuf.
+ * * t points to first char after '&'. Return after final semicolon.
+ * * If unknown, we return t and let libexpat flag the error.
+ * */
+char* scanEntity (char* t, agxbuf* xb)
+{
+ char* endp = strchr (t, ';');
+ struct entities_s key, *res;
+ int len;
+ char buf[MAXENTLEN+1];
+
+ agxbputc(xb, '&');
+ if (!endp) return t;
+ if (((len = endp-t) > MAXENTLEN) || (len < 2)) return t;
+ strncpy (buf, t, len);
+ buf[len] = '\0';
+ key.name = buf;
+ res = bsearch(&key, entities, NR_OF_ENTITIES,
+ sizeof(entities[0]), comp_entities);
+ if (!res) return t;
+ sprintf (buf, "%d", res->value);
+ agxbputc(xb, '#');
+ agxbput(xb, buf);
+ agxbputc(xb, ';');
+ return (endp+1);
+}
+
+
/* htmlEntity:
* Check for an HTML entity for a special character.
* Assume *s points to first byte after '&'.
extern char *latin1ToUTF8(char *);
extern char* utf8ToLatin1 (char* ins);
+ extern char* scanEntity (char* t, agxbuf* xb);
extern pointf Bezier(pointf *, int, double, pointf *, pointf *);
extern point dotneato_closest(splines * spl, point p);
j = 0;
break;
}
- sprintf(buf, "T %d %d %d %d ", p.x, YDIR(p.y), j, (int) line->width);
+ sprintf(buf, "T %d %d %d %d ", p.x, YDIR(p.y), j, (int) line->dimen.x);
agxbput(xbufs[gvc->emit_state], buf);
xd_str ("", line->str);
}
#endif
extern codegen_t FIG_CodeGen, HPGL_CodeGen, MAP_CodeGen,
MIF_CodeGen, XDot_CodeGen, MP_CodeGen, PIC_CodeGen,
- PS_CodeGen, DIA_CodeGen, SVG_CodeGen, VRML_CodeGen,
- VTX_CodeGen, GD_CodeGen, memGD_CodeGen;
+ PS_CodeGen, DIA_CodeGen, SVG_CodeGen, VTX_CodeGen;
+#ifdef HAVE_LIBGD
+ extern codegen_t GD_CodeGen, memGD_CodeGen, VRML_CodeGens;
+#endif
#endif
/*
{&MIF_CodeGen, "mif", MIF},
{&PIC_CodeGen, "pic", PIC_format},
+#ifdef HAVE_LIBGD
{&GD_CodeGen, "gd", GD},
#ifdef HAVE_LIBZ
{&GD_CodeGen, "gd2", GD2},
{&GD_CodeGen, "xbm", XBM},
{&GD_CodeGen, "xpm", XBM},
#endif
+#endif
#ifdef QUARTZ_RENDER
{&QPDF_CodeGen, "pdf", QPDF},
#include "types.h"
#include "graph.h"
+#include "agxbuf.h"
#include "utils.h"
static Dict_t *ImageDict;
*/
#include "neato.h"
+#include "agxbuf.h"
#include "utils.h"
#include "voronoi.h"
#include "info.h"