From f944b0d22fcab9cf403d5e0e31661380204ef938 Mon Sep 17 00:00:00 2001 From: John Ellson Date: Thu, 7 Nov 2013 13:39:22 -0500 Subject: [PATCH] half way to dict of fonts using cdt --- lib/common/fontmetrics.c | 93 ++++++++++++++++++++++++++++++++++++++++ lib/common/htmllex.c | 23 +++++----- lib/common/htmllex.h | 2 +- lib/common/htmlparse.y | 4 +- lib/common/htmltable.c | 20 +++------ lib/common/htmltable.h | 12 +++++- tclpkg/Makefile.am | 11 ----- 7 files changed, 125 insertions(+), 40 deletions(-) diff --git a/lib/common/fontmetrics.c b/lib/common/fontmetrics.c index 9dc00200b..0ccb41383 100644 --- a/lib/common/fontmetrics.c +++ b/lib/common/fontmetrics.c @@ -11,6 +11,10 @@ * Contributors: See CVS logs. Details at http://www.graphviz.org/ *************************************************************************/ +#include +#include +#include +#include "cdt.h" #include "render.h" static double timesFontWidth[] = { @@ -244,3 +248,92 @@ void unref_textfont(textfont_t * tf) free(tf); } } + +#if 0 +typedef struct { + /* key */ + char *name; + char *color; + unsigned int flags; + /* non key */ + char *postscript_alias; +} font_t; + +Void_t* font_makef(Dt_t* dt, Void_t* obj, Dtdisc_t* disc) +{ + font_t *f1 = (font_t*)obj; + font_t *f2 = calloc(1,sizeof(font_t)); + + /* key */ + if (f1->name) f2->name = strdup(f1->name); + if (f1->color) f2->color = strdup(f1->color); + f2->flags = f1->flags; + + /* non key */ + f2->postscript_alias = f1->postscript_alias; + + return f2; +} + +void font_freef(Dt_t* dt, Void_t* obj, Dtdisc_t* disc) +{ + font_t *f = (font_t*)obj; + + if (f->name) free(f->name); + if (f->color) free(f->color); + free(f); +} + +int font_comparf (Dt_t* dt, Void_t* key1, Void_t* key2, Dtdisc_t* disc) +{ + int rc; + font_t *f1 = (font_t*)key1, *f2 = (font_t*)key2; + + rc = strcmp(f1->name, f2->name); + if (rc) return rc; + rc = strcmp(f1->color, f2->color); + if (rc) return rc; + return (f1->flags - f2->flags); +} + +Dtdisc_t fontdisc = { + 0,sizeof(font_t),-1,font_makef,font_freef,font_comparf,NULL,NULL,NULL +}; + +#define TEST 1 +#ifdef TEST + +font_t font1 = { "Times", "black", 0 }; +font_t font2 = { "Arial", "black", 0 }; +font_t font3 = { "Arial", "black", 4 }; +font_t font4 = { "Arial", "black", 0 }; /* dup of 2 */ +font_t font5 = { "Arial", "red", 0 }; +font_t font6 = { "Times", "black", 0 }; /* dup of 1 */ + +int main (void) +{ + Dt_t *fontname_dt; + font_t *f1 = &font1, *f2 = &font2, *f3 = &font3, *f4 = &font4, *f5 = &font5, *f6 = &font6; + + fprintf(stderr,"%p %p %p %p %p %p\n", f1, f2, f3, f4, f5, f6); + fprintf(stderr,"%s %s %s %s %s %s\n", f1->name, f2->name, f3->name, f4->name, f5->name, f6->name); + + fontname_dt = dtopen( &fontdisc, Dtoset); + + f1 = dtinsert(fontname_dt, f1); + f2 = dtinsert(fontname_dt, f2); + f3 = dtinsert(fontname_dt, f3); + f4 = dtinsert(fontname_dt, f4); + f5 = dtinsert(fontname_dt, f5); + f6 = dtinsert(fontname_dt, f6); + + fprintf(stderr,"%p %p %p %p %p %p\n", f1, f2, f3, f4, f5, f6); + fprintf(stderr,"%s %s %s %s %s %s\n", f1->name, f2->name, f3->name, f4->name, f5->name, f6->name); + + dtclose(fontname_dt); + + return 0; +} + +#endif +#endif diff --git a/lib/common/htmllex.c b/lib/common/htmllex.c index c9c09defe..b81924a08 100644 --- a/lib/common/htmllex.c +++ b/lib/common/htmllex.c @@ -563,7 +563,7 @@ static htmlimg_t *mkImg(char **atts) return img; } -static textfont_t *mkFont(char **atts, int flags, int ul) +static textfont_t *mkFont(GVC_t *gvc, char **atts, int flags, int ul) { textfont_t *font = new_textfont(); @@ -599,6 +599,8 @@ static htmltbl_t *mkTbl(char **atts) static void startElement(void *user, const char *name, char **atts) { + GVC_t *gvc = (GVC_t*)user; + if (strcasecmp(name, "TABLE") == 0) { htmllval.tbl = mkTbl(atts); state.inCell = 0; @@ -612,25 +614,25 @@ static void startElement(void *user, const char *name, char **atts) htmllval.cell = mkCell(atts); state.tok = T_cell; } else if (strcasecmp(name, "FONT") == 0) { - htmllval.font = mkFont(atts, 0, 0); + htmllval.font = mkFont(gvc, atts, 0, 0); state.tok = T_font; } else if (strcasecmp(name, "B") == 0) { - htmllval.font = mkFont(0, HTML_BF, 0); + htmllval.font = mkFont(gvc, 0, HTML_BF, 0); state.tok = T_bold; } else if (strcasecmp(name, "S") == 0) { - htmllval.font = mkFont(0, HTML_S, 0); + htmllval.font = mkFont(gvc, 0, HTML_S, 0); state.tok = T_s; } else if (strcasecmp(name, "U") == 0) { - htmllval.font = mkFont(0, HTML_UL, 1); + htmllval.font = mkFont(gvc, 0, HTML_UL, 1); state.tok = T_underline; } else if (strcasecmp(name, "I") == 0) { - htmllval.font = mkFont(0, HTML_IF, 0); + htmllval.font = mkFont(gvc, 0, HTML_IF, 0); state.tok = T_italic; } else if (strcasecmp(name, "SUP") == 0) { - htmllval.font = mkFont(0, HTML_SUP, 0); + htmllval.font = mkFont(gvc, 0, HTML_SUP, 0); state.tok = T_sup; } else if (strcasecmp(name, "SUB") == 0) { - htmllval.font = mkFont(0, HTML_SUB, 0); + htmllval.font = mkFont(gvc, 0, HTML_SUB, 0); state.tok = T_sub; } else if (strcasecmp(name, "BR") == 0) { mkBR(atts); @@ -726,7 +728,7 @@ static void characterData(void *user, const char *s, int length) } #endif -int initHTMLlexer(char *src, agxbuf * xb, int charset) +int initHTMLlexer(char *src, agxbuf * xb, htmlenv_t *env) { #ifdef HAVE_EXPAT state.xb = xb; @@ -738,7 +740,8 @@ int initHTMLlexer(char *src, agxbuf * xb, int charset) state.currtoklen = 0; state.prevtoklen = 0; state.inCell = 1; - state.parser = XML_ParserCreate(charsetToStr(charset)); + state.parser = XML_ParserCreate(charsetToStr(GD_charset(env->g))); + XML_SetUserData(state.parser, GD_gvc(env->g)); XML_SetElementHandler(state.parser, (XML_StartElementHandler) startElement, endElement); diff --git a/lib/common/htmllex.h b/lib/common/htmllex.h index 4216992d4..a4f95b077 100644 --- a/lib/common/htmllex.h +++ b/lib/common/htmllex.h @@ -20,7 +20,7 @@ extern "C" { #include - extern int initHTMLlexer(char *, agxbuf *, int); + extern int initHTMLlexer(char *, agxbuf *, htmlenv_t *); extern int htmllex(void); extern int htmllineno(void); extern int clearHTMLlexer(void); diff --git a/lib/common/htmlparse.y b/lib/common/htmlparse.y index e7bfa5185..ca6bcbbdd 100644 --- a/lib/common/htmlparse.y +++ b/lib/common/htmlparse.y @@ -600,7 +600,7 @@ VR : T_vr T_end_vr * Set warn to 0 on success; 1 for warning message; 2 if no expat. */ htmllabel_t* -parseHTML (char* txt, int* warn, int charset) +parseHTML (char* txt, int* warn, htmlenv_t *env) { unsigned char buf[SMALLBUF]; agxbuf str; @@ -618,7 +618,7 @@ parseHTML (char* txt, int* warn, int charset) agxbinit (&str, SMALLBUF, buf); HTMLstate.str = &str; - if (initHTMLlexer (txt, &str, charset)) {/* failed: no libexpat - give up */ + if (initHTMLlexer (txt, &str, env)) {/* failed: no libexpat - give up */ *warn = 2; l = NULL; } diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index 665928998..56e11bcf6 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -42,16 +42,6 @@ #define DEFAULT_CELLPADDING 2 #define DEFAULT_CELLSPACING 2 -typedef struct { - pointf pos; - textfont_t finfo; - void *obj; - graph_t *g; - char *imgscale; - char *objid; - boolean objid_set; -} htmlenv_t; - typedef struct { char *url; char *tooltip; @@ -957,7 +947,7 @@ int html_path(node_t * n, port * p, int side, boxf * rv, int *k) return 0; } -static int size_html_txt(graph_t * g, htmltxt_t * ftxt, htmlenv_t * env) +static int size_html_txt(GVC_t *gvc, htmltxt_t * ftxt, htmlenv_t * env) { double xsize = 0.0; /* width of text block */ double ysize = 0.0; /* height of text block */ @@ -1045,7 +1035,7 @@ static int size_html_txt(graph_t * g, htmltxt_t * ftxt, htmlenv_t * env) } lp.font->name = fname; lp.font->size = fsize; - sz = textspan_size(GD_gvc(g), &lp); + sz = textspan_size(gvc, &lp); free(ftxt->spans[i].items[j].str); ftxt->spans[i].items[j].str = lp.str; ftxt->spans[i].items[j].size.x = sz.x; @@ -1160,7 +1150,7 @@ size_html_cell(graph_t * g, htmlcell_t * cp, htmltbl_t * parent, rv = size_html_img(cp->child.u.img, env); child_sz = cp->child.u.img->box.UR; } else { - rv = size_html_txt(g, cp->child.u.txt, env); + rv = size_html_txt(GD_gvc(g), cp->child.u.txt, env); child_sz = cp->child.u.txt->box.UR; } @@ -2044,7 +2034,7 @@ int make_html_label(void *obj, textlabel_t * lp) env.finfo.name = lp->fontname; env.finfo.color = lp->fontcolor; env.finfo.flags = 0; - lbl = parseHTML(lp->text, &rv, GD_charset(env.g)); + lbl = parseHTML(lp->text, &rv, &env); if (!lbl) { /* Parse of label failed; revert to simple text label */ agxbuf xb; @@ -2078,7 +2068,7 @@ int make_html_label(void *obj, textlabel_t * lp) lp->dimen.x = box.UR.x - box.LL.x; lp->dimen.y = box.UR.y - box.LL.y; } else { - rv |= size_html_txt(g, lbl->u.txt, &env); + rv |= size_html_txt(GD_gvc(g), lbl->u.txt, &env); wd2 = lbl->u.txt->box.UR.x / 2; ht2 = lbl->u.txt->box.UR.y / 2; box = boxfof(-wd2, -ht2, wd2, ht2); diff --git a/lib/common/htmltable.h b/lib/common/htmltable.h index 5b4601f6d..aaacd1d46 100644 --- a/lib/common/htmltable.h +++ b/lib/common/htmltable.h @@ -148,7 +148,17 @@ extern "C" { unsigned char ruled; } pitem; - extern htmllabel_t *parseHTML(char *, int *, int); + typedef struct { + pointf pos; + textfont_t finfo; + void *obj; + graph_t *g; + char *imgscale; + char *objid; + boolean objid_set; + } htmlenv_t; + + extern htmllabel_t *parseHTML(char *, int *, htmlenv_t *); extern int make_html_label(void *obj, textlabel_t * lp); extern void emit_html_label(GVJ_t * job, htmllabel_t * lp, textlabel_t *); diff --git a/tclpkg/Makefile.am b/tclpkg/Makefile.am index a078ed730..6a9123a69 100644 --- a/tclpkg/Makefile.am +++ b/tclpkg/Makefile.am @@ -41,7 +41,6 @@ if WITH_LUA -mkdir -p $(DESTDIR)@LUA_INSTALL_DIR@; if test -w $(DESTDIR)@LUA_INSTALL_DIR@; then \ (cd $(DESTDIR)@LUA_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgluadir)/gv.so; \ mv -f $(DESTDIR)$(pkgluadir)/libgv_lua.so gv.so;) \ else \ echo "Warning: @LUA_INSTALL_DIR@ is not writable."; \ @@ -52,7 +51,6 @@ if WITH_PERL -mkdir -p $(DESTDIR)@PERL_INSTALL_DIR@; if test -w $(DESTDIR)@PERL_INSTALL_DIR@; then \ (cd $(DESTDIR)@PERL_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgperldir)/gv.so; \ mv -f $(DESTDIR)$(pkgperldir)/libgv_perl.so gv.so; \ mv -f $(DESTDIR)$(pkgperldir)/gv.pm gv.pm;) \ else \ @@ -64,7 +62,6 @@ if WITH_PHP -mkdir -p $(DESTDIR)@PHP_INSTALL_DIR@; if test -w $(DESTDIR)@PHP_INSTALL_DIR@; then \ (cd $(DESTDIR)@PHP_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgphpdir)/gv.so; \ mv -f $(DESTDIR)$(pkgphpdir)/libgv_php.so gv.so;) \ else \ echo "Warning: @PHP_INSTALL_DIR@ is not writable."; \ @@ -83,7 +80,6 @@ if WITH_PYTHON -mkdir -p $(DESTDIR)@PYTHON_INSTALL_DIR@; if test -w $(DESTDIR)@PYTHON_INSTALL_DIR@; then \ (cd $(DESTDIR)@PYTHON_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgpythondir)/_gv.so; \ mv -f $(DESTDIR)$(pkgpythondir)/libgv_python.so _gv.so; \ mv -f $(DESTDIR)$(pkgpythondir)/gv.py gv.py;) \ else \ @@ -95,7 +91,6 @@ if WITH_PYTHON23 -mkdir -p $(DESTDIR)@PYTHON23_INSTALL_DIR@; if test -w $(DESTDIR)@PYTHON23_INSTALL_DIR@; then \ (cd $(DESTDIR)@PYTHON23_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgpython23dir)/_gv.so; \ mv -f $(DESTDIR)$(pkgpython23dir)/libgv_python23.so _gv.so; \ mv -f $(DESTDIR)$(pkgpython23dir)/gv.py gv.py;) \ else \ @@ -107,7 +102,6 @@ if WITH_PYTHON24 -mkdir -p $(DESTDIR)@PYTHON24_INSTALL_DIR@; if test -w $(DESTDIR)@PYTHON24_INSTALL_DIR@; then \ (cd $(DESTDIR)@PYTHON24_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgpython24dir)/_gv.so; \ mv -f $(DESTDIR)$(pkgpython24dir)/libgv_python24.so _gv.so; \ mv -f $(DESTDIR)$(pkgpython24dir)/gv.py gv.py;) \ else \ @@ -119,7 +113,6 @@ if WITH_PYTHON25 -mkdir -p $(DESTDIR)@PYTHON25_INSTALL_DIR@; if test -w $(DESTDIR)@PYTHON25_INSTALL_DIR@; then \ (cd $(DESTDIR)@PYTHON25_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgpython25dir)/_gv.so; \ mv -f $(DESTDIR)$(pkgpython25dir)/libgv_python25.so _gv.so; \ mv -f $(DESTDIR)$(pkgpython25dir)/gv.py gv.py;) \ else \ @@ -131,7 +124,6 @@ if WITH_PYTHON26 -mkdir -p $(DESTDIR)@PYTHON26_INSTALL_DIR@; if test -w $(DESTDIR)@PYTHON26_INSTALL_DIR@; then \ (cd $(DESTDIR)@PYTHON26_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgpython26dir)/_gv.so; \ mv -f $(DESTDIR)$(pkgpython26dir)/libgv_python26.so _gv.so; \ mv -f $(DESTDIR)$(pkgpython26dir)/gv.py gv.py;) \ else \ @@ -143,7 +135,6 @@ if WITH_PYTHON27 -mkdir -p $(DESTDIR)@PYTHON27_INSTALL_DIR@; if test -w $(DESTDIR)@PYTHON27_INSTALL_DIR@; then \ (cd $(DESTDIR)@PYTHON27_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgpython27dir)/_gv.so; \ mv -f $(DESTDIR)$(pkgpython27dir)/libgv_python27.so _gv.so; \ mv -f $(DESTDIR)$(pkgpython27dir)/gv.py gv.py;) \ else \ @@ -155,7 +146,6 @@ if WITH_RUBY -mkdir -p $(DESTDIR)@RUBY_INSTALL_DIR@; if test -w $(DESTDIR)@RUBY_INSTALL_DIR@; then \ (cd $(DESTDIR)@RUBY_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgrubydir)/gv.so; \ mv -f $(DESTDIR)$(pkgrubydir)/libgv_ruby.so gv.so;) \ else \ echo "Warning: @RUBY_INSTALL_DIR@ is not writable."; \ @@ -166,7 +156,6 @@ if WITH_TCL -mkdir -p $(DESTDIR)@TCL_INSTALL_DIR@; if test -w $(DESTDIR)@TCL_INSTALL_DIR@/; then \ (cd $(DESTDIR)@TCL_INSTALL_DIR@; \ - rm -f $(DESTDIR)$(pkgtcldir)/*.so; \ mv -f $(DESTDIR)$(pkgtcldir) @PACKAGE_NAME@;) \ else \ echo "Warning: @TCL_INSTALL_DIR@ is not writable."; \ -- 2.40.0