From a04ff22dd37c854be4576048e9ab17e8f57ad32d Mon Sep 17 00:00:00 2001 From: John Ellson Date: Thu, 7 Nov 2013 16:17:57 -0500 Subject: [PATCH] font dict open and close --- lib/common/render.h | 2 ++ lib/common/textfont.c | 81 ++++++++++++++++++++++--------------------- lib/gvc/gvcint.h | 2 +- lib/gvc/gvconfig.c | 1 + lib/gvc/gvcontext.c | 1 + 5 files changed, 46 insertions(+), 41 deletions(-) diff --git a/lib/common/render.h b/lib/common/render.h index 467f75edb..1b9f8ca79 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -159,6 +159,8 @@ extern "C" { extern stroke_t* taper0 (bezier* bez, double initwid); extern pointf textspan_size(GVC_t * gvc, textspan_t * span); extern textfont_t * new_textfont(void); + extern Dt_t * textfont_dict_open(GVC_t *gvc); + extern void textfont_dict_close(GVC_t *gvc); extern void ref_textfont(textfont_t *tf); extern void unref_textfont(textfont_t *tf); extern void translate_bb(Agraph_t *, int); diff --git a/lib/common/textfont.c b/lib/common/textfont.c index 0ccb41383..cbb06ce5d 100644 --- a/lib/common/textfont.c +++ b/lib/common/textfont.c @@ -249,25 +249,16 @@ void unref_textfont(textfont_t * 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) +static Void_t* textfont_makef(Dt_t* dt, Void_t* obj, Dtdisc_t* disc) { - font_t *f1 = (font_t*)obj; - font_t *f2 = calloc(1,sizeof(font_t)); + textfont_t *f1 = (textfont_t*)obj; + textfont_t *f2 = calloc(1,sizeof(textfont_t)); /* key */ if (f1->name) f2->name = strdup(f1->name); if (f1->color) f2->color = strdup(f1->color); f2->flags = f1->flags; + f2->size = f1->size; /* non key */ f2->postscript_alias = f1->postscript_alias; @@ -275,65 +266,75 @@ Void_t* font_makef(Dt_t* dt, Void_t* obj, Dtdisc_t* disc) return f2; } -void font_freef(Dt_t* dt, Void_t* obj, Dtdisc_t* disc) +static void textfont_freef(Dt_t* dt, Void_t* obj, Dtdisc_t* disc) { - font_t *f = (font_t*)obj; + textfont_t *f = (textfont_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) +static int textfont_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; + textfont_t *f1 = (textfont_t*)key1, *f2 = (textfont_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); + rc = (f1->flags - f2->flags); + if (rc) return rc; + if (f1->size > f2->size) return 1; + if (f1->size < f2->size) return -1; + return 0; } -Dtdisc_t fontdisc = { - 0,sizeof(font_t),-1,font_makef,font_freef,font_comparf,NULL,NULL,NULL -}; +Dt_t * textfont_dict_open(GVC_t *gvc) +{ + DTDISC(&(gvc->textfont_disc),0,sizeof(textfont_t),-1,textfont_makef,textfont_freef,textfont_comparf,NULL,NULL,NULL); + gvc->textfont_dt = dtopen(&(gvc->textfont_disc), Dtoset); + return gvc->textfont_dt; +} + +void textfont_dict_close(GVC_t *gvc) +{ + dtclose(gvc->textfont_dt); +} + -#define TEST 1 -#ifdef TEST +#if 0 -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 */ +textfont_t font1 = { "Times", "black", 0 }; +textfont_t font2 = { "Arial", "black", 0 }; +textfont_t font3 = { "Arial", "black", 4 }; +textfont_t font4 = { "Arial", "black", 0 }; /* dup of 2 */ +textfont_t font5 = { "Arial", "red", 0 }; +textfont_t font6 = { "Times", "black", 0 }; /* dup of 1 */ int main (void) { - Dt_t *fontname_dt; + Dt_t *textfont_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); + textfont_dt = dtopen( &textfont_disc, 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); + f1 = dtinsert(textfont_dt, f1); + f2 = dtinsert(textfont_dt, f2); + f3 = dtinsert(textfont_dt, f3); + f4 = dtinsert(textfont_dt, f4); + f5 = dtinsert(textfont_dt, f5); + f6 = dtinsert(textfont_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); + dtclose(textfont_dt); return 0; } - -#endif #endif diff --git a/lib/gvc/gvcint.h b/lib/gvc/gvcint.h index 3688f8ff7..e4d1eec2b 100644 --- a/lib/gvc/gvcint.h +++ b/lib/gvc/gvcint.h @@ -93,7 +93,7 @@ extern "C" { /* fonts and textlayout */ Dtdisc_t textfont_disc; - Dt_t *textfont_dict; + Dt_t *textfont_dt; gvplugin_active_textlayout_t textlayout; /* always use best avail for all jobs */ // void (*free_layout) (void *layout); /* function for freeing layouts (mostly used by pango) */ diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index faa9221ea..821825977 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -564,6 +564,7 @@ void gvconfig(GVC_t * gvc, boolean rescan) } #endif gvtextlayout_select(gvc); /* choose best available textlayout plugin immediately */ + textfont_dict_open(gvc); /* initialize font dict */ } #ifdef ENABLE_LTDL diff --git a/lib/gvc/gvcontext.c b/lib/gvc/gvcontext.c index 66eee9c14..b29667bae 100644 --- a/lib/gvc/gvcontext.c +++ b/lib/gvc/gvcontext.c @@ -91,6 +91,7 @@ int gvFreeContext(GVC_t * gvc) free(gvc->config_path); if (gvc->input_filenames) free(gvc->input_filenames); + textfont_dict_close(gvc); free(gvc); return (graphviz_errors + agerrors()); } -- 2.40.0