From e88d645e01f3bfbdbeb965f49a091887ead04ab1 Mon Sep 17 00:00:00 2001 From: "Nickolay V. Shmyrev" Date: Sat, 9 Apr 2005 19:30:47 +0000 Subject: [PATCH] Dvi thumbnails and improved antialiasing of dvi rules. Fix compilation warnings. --- ChangeLog | 31 +++++++++ dvi/dvi-document.c | 68 +++++++++++++++++--- dvi/mdvi-lib/Makefile.am | 7 +- dvi/mdvi-lib/assoc.c | 99 ---------------------------- dvi/mdvi-lib/assoc.h | 14 ---- dvi/mdvi-lib/bitmap.c | 76 +--------------------- dvi/mdvi-lib/color.c | 135 +++++++++++++++++++++++++++++++++++++++ dvi/mdvi-lib/color.h | 34 ++++++++++ dvi/mdvi-lib/common.h | 6 -- dvi/mdvi-lib/dviread.c | 66 ++++++++++++++----- dvi/mdvi-lib/files.c | 71 -------------------- dvi/mdvi-lib/fontmap.c | 13 ++-- dvi/mdvi-lib/mdvi.h | 12 +--- dvi/mdvi-lib/sp-epsf.c | 2 +- dvi/mdvi-lib/tfmfile.c | 1 - dvi/mdvi-lib/util.c | 13 ---- dvi/pixbuf-device.c | 32 +++++++--- 17 files changed, 345 insertions(+), 335 deletions(-) delete mode 100644 dvi/mdvi-lib/assoc.c delete mode 100644 dvi/mdvi-lib/assoc.h create mode 100644 dvi/mdvi-lib/color.c create mode 100644 dvi/mdvi-lib/color.h diff --git a/ChangeLog b/ChangeLog index e14a3c6b..aa84c474 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2005-04-09 Nickolay V. Shmyrev + + + * dvi/mdvi-lib/assoc.c: + * dvi/mdvi-lib/assoc.h: Removed garbage files + + * dvi/mdvi-lib/bitmap.c: + * dvi/mdvi-lib/color.c: (mdvi_set_color), (mdvi_push_color), + (mdvi_pop_color), (mdvi_reset_color), (get_color_table): + * dvi/mdvi-lib/color.h: Antialias of rules + + * dvi/mdvi-lib/common.h: + * dvi/mdvi-lib/dviread.c: (mdvi_configure), (mdvi_init_context), + (mdvi_destroy_context), (draw_shrink_rule), (draw_box), (set_rule): + * dvi/mdvi-lib/files.c: + * dvi/mdvi-lib/fontmap.c: (ps_init_default_paths): + * dvi/mdvi-lib/mdvi.h: + * dvi/mdvi-lib/sp-epsf.c: (epsf_special): + * dvi/mdvi-lib/tfmfile.c: (ofm_load_file): + * dvi/mdvi-lib/util.c: Fix compile warnings + + * dvi/dvi-document.c: + (dvi_document_load), (dvi_document_thumbnails_get_dimensions), + (dvi_document_thumbnails_get_thumbnail), + (dvi_document_document_thumbnails_iface_init): + * dvi/mdvi-lib/Makefile.am: + * dvi/pixbuf-device.c: (dvi_pixbuf_draw_rule), + (dvi_pixbuf_set_color), (mdvi_pixbuf_device_render): + + Dvi backend now renders thumbnails + 2005-04-09 Christian Persch * shell/main.c: (main): diff --git a/dvi/dvi-document.c b/dvi/dvi-document.c index 5bbe8f17..f827ff40 100644 --- a/dvi/dvi-document.c +++ b/dvi/dvi-document.c @@ -21,6 +21,7 @@ #include "dvi-document.h" #include "ev-document-thumbnails.h" +#include "ev-document-misc.h" #include "mdvi.h" #include "fonts.h" @@ -57,9 +58,7 @@ struct _DviDocument typedef struct _DviDocumentClass DviDocumentClass; static void dvi_document_document_iface_init (EvDocumentIface *iface); -#if 0 static void dvi_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface); -#endif static void dvi_document_get_page_size (EvDocument *document, int page, double *width, @@ -69,9 +68,7 @@ G_DEFINE_TYPE_WITH_CODE (DviDocument, dvi_document, G_TYPE_OBJECT, { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, dvi_document_document_iface_init); -#if 0 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, dvi_document_document_thumbnails_iface_init) -#endif }); static gboolean @@ -102,6 +99,7 @@ dvi_document_load (EvDocument *document, dvi_context_mutex = g_mutex_new (); + return TRUE; } @@ -259,24 +257,75 @@ dvi_document_document_iface_init (EvDocumentIface *iface) iface->render_pixbuf = dvi_document_render_pixbuf; } -#if 0 static void dvi_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, gint page, gint suggested_width, gint *width, gint *height) -{ +{ + DviDocument *dvi_document = DVI_DOCUMENT (document); + gdouble page_ratio; + + page_ratio = dvi_document->base_height / dvi_document->base_width; + *width = suggested_width; + *height = (gint) (suggested_width * page_ratio); + return; } static GdkPixbuf * dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint width) + gint page, + gint width, + gboolean border) { + DviDocument *dvi_document = DVI_DOCUMENT (document); + GdkPixbuf *pixbuf; + GdkPixbuf *border_pixbuf; + gint thumb_width, thumb_height; + gint proposed_width, proposed_height; + + dvi_document_thumbnails_get_dimensions (document, page, width, &thumb_width, &thumb_height); - return NULL; + g_mutex_lock (dvi_context_mutex); + + mdvi_setpage(dvi_document->context, page); + + mdvi_set_shrink (dvi_document->context, + (int)dvi_document->base_width * dvi_document->params->hshrink / thumb_width, + (int)dvi_document->base_width * dvi_document->params->vshrink / thumb_height); + + proposed_width = dvi_document->context->dvi_page_w * dvi_document->context->params.conv; + proposed_height = dvi_document->context->dvi_page_h * dvi_document->context->params.vconv; + + if (border) { + mdvi_pixbuf_device_set_margins (&dvi_document->context->device, + MAX (thumb_width - proposed_width, 0) / 2, + MAX (thumb_height - proposed_height, 0) / 2); + } else { + mdvi_pixbuf_device_set_margins (&dvi_document->context->device, + MAX (thumb_width - proposed_width - 2, 0) / 2, + MAX (thumb_height - proposed_height - 2, 0) / 2); + } + + + mdvi_pixbuf_device_render (dvi_document->context); + pixbuf = mdvi_pixbuf_device_get_pixbuf (&dvi_document->context->device); + + g_mutex_unlock (dvi_context_mutex); + + if (border) { + border_pixbuf = ev_document_misc_get_thumbnail_frame (thumb_width, thumb_height, NULL); + gdk_pixbuf_copy_area (pixbuf, 0, 0, + thumb_width - 2, thumb_height - 2, + border_pixbuf, 2, 2); + g_object_unref (pixbuf); + pixbuf = border_pixbuf; + } + + + return pixbuf; } static void @@ -285,7 +334,6 @@ dvi_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface) iface->get_thumbnail = dvi_document_thumbnails_get_thumbnail; iface->get_dimensions = dvi_document_thumbnails_get_dimensions; } -#endif static void diff --git a/dvi/mdvi-lib/Makefile.am b/dvi/mdvi-lib/Makefile.am index fd88f7fc..aa9ef947 100644 --- a/dvi/mdvi-lib/Makefile.am +++ b/dvi/mdvi-lib/Makefile.am @@ -3,14 +3,13 @@ noinst_LTLIBRARIES = libmdvi.la libmdvi_la_SOURCES = \ afmparse.c \ afmparse.h \ - assoc.c \ - assoc.h \ bitmap.c \ bitmap.h \ + color.c \ + color.h \ common.c \ common.h \ defaults.h \ - dvimisc.c \ dviopcodes.h \ dviread.c \ files.c \ @@ -38,3 +37,5 @@ libmdvi_la_SOURCES = \ tt.c \ util.c \ vf.c + + diff --git a/dvi/mdvi-lib/assoc.c b/dvi/mdvi-lib/assoc.c deleted file mode 100644 index e3ba1136..00000000 --- a/dvi/mdvi-lib/assoc.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2000, Matias Atria - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mdvi.h" -#include "assoc.h" -#include "hash.h" - -typedef struct { - void *data; - DviFree2Func free_func; -} DviAssoc; - -#define MDVI_ASSOC_SIZE 31 - -static void assoc_free(DviHashKey key, void *ptr) -{ - DviAssoc *assoc = (DviAssoc *)ptr; - - DEBUG((4, "Destroying association `%s'\n", (char *)key)); - if(assoc->free_func) - assoc->free_func(key, assoc->data); - xfree(assoc); -} - -int mdvi_assoc_put(DviContext *dvi, char *key, void *data, DviFree2Func f) -{ - DviAssoc *assoc; - int ok; - - if(dvi->assoc.buckets == NULL) { - mdvi_hash_create(&dvi->assoc, MDVI_ASSOC_SIZE); - dvi->assoc.hash_free = assoc_free; - } - assoc = xalloc(DviAssoc); - assoc->data = data; - assoc->free_func = f; - - ok = mdvi_hash_add(&dvi->assoc, MDVI_KEY(key), - assoc, MDVI_HASH_UNIQUE); - if(ok < 0) { - xfree(assoc); - return -1; - } - return 0; -} - -void *mdvi_assoc_get(DviContext *dvi, char *key) -{ - DviAssoc *assoc; - - if(dvi->assoc.buckets == NULL) - return NULL; - assoc = (DviAssoc *)mdvi_hash_lookup(&dvi->assoc, MDVI_KEY(key)); - return assoc ? assoc->data : NULL; -} - -void *mdvi_assoc_del(DviContext *dvi, char *key) -{ - DviAssoc *assoc; - void *ptr; - - if(dvi->assoc.buckets == NULL) - return NULL; - assoc = mdvi_hash_remove(&dvi->assoc, MDVI_KEY(key)); - if(assoc == NULL) - return NULL; - ptr = assoc->data; - xfree(assoc); - return ptr; -} - -void mdvi_assoc_free(DviContext *dvi, char *key) -{ - if(dvi->assoc.buckets) { - /* this will call `assoc_free' */ - mdvi_hash_destroy_key(&dvi->assoc, MDVI_KEY(key)); - } -} - -void mdvi_assoc_flush(DviContext *dvi) -{ - if(dvi->assoc.buckets) - mdvi_hash_reset(&dvi->assoc, 0); -} diff --git a/dvi/mdvi-lib/assoc.h b/dvi/mdvi-lib/assoc.h deleted file mode 100644 index f5b7035a..00000000 --- a/dvi/mdvi-lib/assoc.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef MDVI_ASSOC_H -#define MDVI_ASSOC_H - -/* Associations */ -extern int mdvi_assoc_put - __PROTO((DviContext *, char *, void *, DviFree2Func)); -extern void * mdvi_assoc_get __PROTO((DviContext *, char *)); -extern void * mdvi_assoc_del __PROTO((DviContext *, char *)); -extern void mdvi_assoc_free __PROTO((DviContext *, char *)); -extern void mdvi_assoc_flush __PROTO((DviContext *)); - - -#endif - diff --git a/dvi/mdvi-lib/bitmap.c b/dvi/mdvi-lib/bitmap.c index b30369f4..a48e6e05 100644 --- a/dvi/mdvi-lib/bitmap.c +++ b/dvi/mdvi-lib/bitmap.c @@ -21,6 +21,7 @@ #include #include "mdvi.h" +#include "color.h" /* bit_masks[n] contains a BmUnit with `n' contiguous bits */ @@ -46,17 +47,6 @@ static BmUnit bit_masks[] = { #define SHOW_OP_DATA (DEBUGGING(BITMAP_OPS) && DEBUGGING(BITMAP_DATA)) #endif -/* cache for color tables, to avoid creating them for every glyph */ -typedef struct { - Ulong fg; - Ulong bg; - Uint nlevels; - Ulong *pixels; - int density; - double gamma; - Uint hits; -} ColorCache; - /* * Some useful macros to manipulate bitmap data * SEGMENT(m,n) = bit mask for a segment of `m' contiguous bits @@ -126,70 +116,6 @@ static Uchar bit_swap[] = { 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff }; -#define CCSIZE 256 -static ColorCache color_cache[CCSIZE]; -static int cc_entries; - -#define GAMMA_DIFF 0.005 - -static Ulong *get_color_table(DviDevice *dev, - int nlevels, Ulong fg, Ulong bg, double gamma, int density); - - -/* create a color table */ -static Ulong *get_color_table(DviDevice *dev, - int nlevels, Ulong fg, Ulong bg, double gamma, int density) -{ - ColorCache *cc, *tofree; - int lohits; - Ulong *pixels; - int status; - - lohits = color_cache[0].hits; - tofree = &color_cache[0]; - /* look in the cache and see if we have one that matches this request */ - for(cc = &color_cache[0]; cc < &color_cache[cc_entries]; cc++) { - if(cc->hits < lohits) { - lohits = cc->hits; - tofree = cc; - } - if(cc->fg == fg && cc->bg == bg && cc->density == density && - cc->nlevels == nlevels && fabs(cc->gamma - gamma) <= GAMMA_DIFF) - break; - } - - if(cc < &color_cache[cc_entries]) { - cc->hits++; - return cc->pixels; - } - - DEBUG((DBG_DEVICE, "Adding color table to cache (fg=%lu, bg=%lu, n=%d)\n", - fg, bg, nlevels)); - - /* no entry was found in the cache, create a new one */ - if(cc_entries < CCSIZE) { - cc = &color_cache[cc_entries++]; - cc->pixels = NULL; - } else { - cc = tofree; - xfree(cc->pixels); - } - pixels = xnalloc(Ulong, nlevels); - status = dev->alloc_colors(dev->device_data, - pixels, nlevels, fg, bg, gamma, density); - if(status < 0) { - xfree(pixels); - return NULL; - } - cc->fg = fg; - cc->bg = bg; - cc->gamma = gamma; - cc->density = density; - cc->nlevels = nlevels; - cc->pixels = pixels; - cc->hits = 1; - return pixels; -} /* * next we have three bitmap functions to convert bitmaps in LSB bit order diff --git a/dvi/mdvi-lib/color.c b/dvi/mdvi-lib/color.c new file mode 100644 index 00000000..ae63a873 --- /dev/null +++ b/dvi/mdvi-lib/color.c @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2000, Matias Atria + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mdvi.h" +#include "color.h" + +void mdvi_set_color(DviContext *dvi, Ulong fg, Ulong bg) +{ + if(dvi->curr_fg != fg || dvi->curr_bg != bg) { + DEBUG((DBG_DEVICE, "setting color to (%lu,%lu)\n", fg, bg)); + if(dvi->device.set_color) + dvi->device.set_color(dvi->device.device_data, fg, bg); + dvi->curr_fg = fg; + dvi->curr_bg = bg; + } +} + +void mdvi_push_color(DviContext *dvi, Ulong fg, Ulong bg) +{ + if(dvi->color_top == dvi->color_size) { + dvi->color_size += 32; + dvi->color_stack = xrealloc(dvi->color_stack, + dvi->color_size * sizeof(DviColorPair)); + } + dvi->color_stack[dvi->color_top].fg = dvi->curr_fg; + dvi->color_stack[dvi->color_top].bg = dvi->curr_bg; + dvi->color_top++; + mdvi_set_color(dvi, fg, bg); +} + +void mdvi_pop_color(DviContext *dvi) +{ + Ulong fg, bg; + + if(dvi->color_top == 0) + return; + dvi->color_top--; + fg = dvi->color_stack[dvi->color_top].fg; + bg = dvi->color_stack[dvi->color_top].bg; + mdvi_set_color(dvi, fg, bg); +} + +void mdvi_reset_color(DviContext *dvi) +{ + dvi->color_top = 0; + mdvi_set_color(dvi, dvi->params.fg, dvi->params.bg); +} + +/* cache for color tables, to avoid creating them for every glyph */ +typedef struct { + Ulong fg; + Ulong bg; + Uint nlevels; + Ulong *pixels; + int density; + double gamma; + Uint hits; +} ColorCache; + +#define CCSIZE 256 +static ColorCache color_cache[CCSIZE]; +static int cc_entries; + +#define GAMMA_DIFF 0.005 + + +/* create a color table */ +Ulong *get_color_table(DviDevice *dev, + int nlevels, Ulong fg, Ulong bg, double gamma, int density) +{ + ColorCache *cc, *tofree; + int lohits; + Ulong *pixels; + int status; + + lohits = color_cache[0].hits; + tofree = &color_cache[0]; + /* look in the cache and see if we have one that matches this request */ + for(cc = &color_cache[0]; cc < &color_cache[cc_entries]; cc++) { + if(cc->hits < lohits) { + lohits = cc->hits; + tofree = cc; + } + if(cc->fg == fg && cc->bg == bg && cc->density == density && + cc->nlevels == nlevels && fabs(cc->gamma - gamma) <= GAMMA_DIFF) + break; + } + + if(cc < &color_cache[cc_entries]) { + cc->hits++; + return cc->pixels; + } + + DEBUG((DBG_DEVICE, "Adding color table to cache (fg=%lu, bg=%lu, n=%d)\n", + fg, bg, nlevels)); + + /* no entry was found in the cache, create a new one */ + if(cc_entries < CCSIZE) { + cc = &color_cache[cc_entries++]; + cc->pixels = NULL; + } else { + cc = tofree; + xfree(cc->pixels); + } + pixels = xnalloc(Ulong, nlevels); + status = dev->alloc_colors(dev->device_data, + pixels, nlevels, fg, bg, gamma, density); + if(status < 0) { + xfree(pixels); + return NULL; + } + cc->fg = fg; + cc->bg = bg; + cc->gamma = gamma; + cc->density = density; + cc->nlevels = nlevels; + cc->pixels = pixels; + cc->hits = 1; + return pixels; +} diff --git a/dvi/mdvi-lib/color.h b/dvi/mdvi-lib/color.h new file mode 100644 index 00000000..363776e6 --- /dev/null +++ b/dvi/mdvi-lib/color.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2000, Matias Atria + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _COLOR_H_ +#define _COLOR_H_ + +#include "common.h" + +extern Ulong *get_color_table(DviDevice *dev, + int nlevels, Ulong fg, Ulong bg, double gamma, int density); + +extern void mdvi_set_color __PROTO((DviContext *, Ulong, Ulong)); +extern void mdvi_push_color __PROTO((DviContext *, Ulong, Ulong)); +extern void mdvi_pop_color __PROTO((DviContext *)); +extern void mdvi_reset_color __PROTO((DviContext *)); + +#endif /* _COLOR_H_ */ + diff --git a/dvi/mdvi-lib/common.h b/dvi/mdvi-lib/common.h index 67130feb..e9c007ed 100644 --- a/dvi/mdvi-lib/common.h +++ b/dvi/mdvi-lib/common.h @@ -216,10 +216,6 @@ extern void *xmemdup __PROTO((const void *, size_t)); #define xnalloc(t,n) (t *)xcalloc((n), sizeof(t)) #define xresize(p,t,n) (t *)xrealloc((p), (n) * sizeof(t)) -extern int get_number __PROTO((const char *, long *)); -/* return paper dimensions (in cm) */ -extern int paper_dimensions __PROTO((const char *, double *, double *)); - extern char *xstradd __PROTO((char *, size_t *, size_t, const char *, size_t)); extern Ulong get_mtime __PROTO((int)); @@ -255,10 +251,8 @@ extern void dstring_reset __PROTO((Dstring *)); extern char *dgets __PROTO((Dstring *, FILE *)); extern int file_readable __PROTO((const char *)); extern int file_exists __PROTO((const char *)); -extern char *find_in_path __PROTO((const char *path, const char *file)); extern const char *file_basename __PROTO((const char *)); extern const char *file_extension __PROTO((const char *)); -extern char *read_into_core __PROTO((const char *, size_t *)); /* * Miscellaneous macros diff --git a/dvi/mdvi-lib/dviread.c b/dvi/mdvi-lib/dviread.c index e2ca6c73..2f9b5cd4 100644 --- a/dvi/mdvi-lib/dviread.c +++ b/dvi/mdvi-lib/dviread.c @@ -27,6 +27,7 @@ #include "mdvi.h" #include "private.h" +#include "color.h" typedef int (*DviCommand) __PROTO((DviContext *, int)); @@ -578,11 +579,6 @@ int mdvi_configure(DviContext *dvi, DviParamCode option, ...) break; case MDVI_SET_GAMMA: np.gamma = va_arg(ap, double); - if(np.pixels) { - xfree(np.pixels); - np.pixels = 0; - np.npixels = 0; - } reset_font = MDVI_FONTSEL_GREY; break; case MDVI_SET_DENSITY: @@ -745,8 +741,6 @@ DviContext *mdvi_init_context(DviParams *par, DviPageSpec *spec, const char *fil dvi->params.orientation = par->orientation; dvi->params.fg = par->fg; dvi->params.bg = par->bg; - dvi->params.pixels = NULL; - dvi->params.npixels = 0; /* initialize colors */ dvi->curr_fg = par->fg; @@ -902,9 +896,6 @@ DviContext *mdvi_init_context(DviParams *par, DviPageSpec *spec, const char *fil dvi->device.set_color = dummy_dev_set_color; dvi->device.device_data = NULL; - /* initialize associations */ - mdvi_hash_init(&dvi->assoc); - DEBUG((DBG_DVI, "%s read successfully\n", filename)); return dvi; @@ -942,7 +933,6 @@ void mdvi_destroy_context(DviContext *dvi) xfree(dvi->buffer.data); if(dvi->color_stack) xfree(dvi->color_stack); - mdvi_assoc_flush(dvi); xfree(dvi); } @@ -1175,6 +1165,50 @@ static void inline fix_after_horizontal(DviContext *dvi) (a), (b) > 0 ? '+' : '-', \ (b) > 0 ? (b) : -(b), (c) +/* + * Draw rules with some sort of antialias support. Usefult for high-rate + * scale factors. + */ + +static void draw_shrink_rule (DviContext *dvi, int x, int y, Uint w, Uint h, int f) +{ + int hs, vs, npixels; + Ulong fg, bg; + Ulong *pixels; + + hs = dvi->params.hshrink; + vs = dvi->params.vshrink; + fg = dvi->params.fg; + bg = dvi->params.bg; + + if (MDVI_ENABLED(dvi, MDVI_PARAM_ANTIALIASED)) { + npixels = vs * hs + 1; + pixels = get_color_table(&dvi->device, npixels, bg, fg, + dvi->params.gamma, dvi->params.density); + + if (pixels) { + int color; + + /* Lines with width 1 should be perfectly visible + * in shrink about 15. That is the reason of constant + */ + + color = (pow (vs / h * hs, 2) + pow (hs / w * vs, 2)) / 225; + if (color < npixels) { + fg = pixels[color]; + } else { + fg = pixels[npixels - 1]; + } + } + } + + mdvi_push_color (dvi, fg, bg); + dvi->device.draw_rule(dvi, x, y, w, h, f); + mdvi_pop_color (dvi); + + return; +} + /* * The only commands that actually draw something are: * set_char, set_rule @@ -1233,8 +1267,7 @@ static void draw_box(DviContext *dvi, DviFontChar *ch) break; } - dvi->device.draw_rule(dvi, - dvi->pos.hh - x, dvi->pos.vv - y, w, h, 1); + draw_shrink_rule(dvi, dvi->pos.hh - x, dvi->pos.vv - y, w, h, 1); } int set_char(DviContext *dvi, int opcode) @@ -1306,9 +1339,10 @@ int set_rule(DviContext *dvi, int opcode) b, a, w, h)); /* the `draw' functions expect the origin to be at the top left * corner of the rule, not the bottom left, as in DVI files */ - if(dvi->curr_layer <= dvi->params.layer) - dvi->device.draw_rule(dvi, - dvi->pos.hh, dvi->pos.vv - h + 1, w, h, 1); + if(dvi->curr_layer <= dvi->params.layer) { + draw_shrink_rule(dvi, + dvi->pos.hh, dvi->pos.vv - h + 1, w, h, 1); + } } else { SHOWCMD((dvi, opcode == DVI_SET_RULE ? "setrule" : "putrule", -1, "(moving left only, by %d)\n", b)); diff --git a/dvi/mdvi-lib/files.c b/dvi/mdvi-lib/files.c index d3dbcfed..0ed893b6 100644 --- a/dvi/mdvi-lib/files.c +++ b/dvi/mdvi-lib/files.c @@ -77,74 +77,3 @@ int file_exists(const char *filename) return status; } -static char *xstrchre(const char *string, int c) -{ - const char *ptr; - - for(ptr = string; *ptr && *ptr != c; ptr++); - return (char *)ptr; -} - -char *find_in_path(const char *filename, const char *path) -{ - const char *p, *q; - char *try; - int len; - - /* if the file is readable as given, return it */ - if(file_readable(filename)) - return xstrdup(filename); - - /* worst case scenario */ - try = xmalloc(strlen(path) + strlen(filename) + 2); - try[0] = 0; - - for(p = path; *p; p = q) { - q = xstrchre(p, ':'); - len = q - p; - xstrncpy(try, p, len); - try[len] = '/'; - strcpy(try + len + 1, filename); - if(file_readable(try)) - break; - if(*q) q++; - } - - if(*p) - return try; - else { - xfree(try); - return NULL; - } -} - -char *read_into_core(const char *file, size_t *size) -{ - FILE *in; - struct stat st; - char *ptr; - - in = fopen(file, "r"); - if(in == NULL) - return NULL; - if(fstat(fileno(in), &st) < 0) { - /* I don't think this is possible, but who knows */ - fclose(in); - return NULL; - } - if(st.st_size == 0) { - warning("%s: file is empty\n", file); - fclose(in); - return NULL; - } - ptr = xmalloc(st.st_size + 1); - if(fread(ptr, st.st_size, 1, in) != 1) { - fclose(in); - xfree(ptr); - return NULL; - } - fclose(in); - ptr[st.st_size] = 0; - if(size) *size = st.st_size; - return ptr; -} diff --git a/dvi/mdvi-lib/fontmap.c b/dvi/mdvi-lib/fontmap.c index 0837b237..26b33afc 100644 --- a/dvi/mdvi-lib/fontmap.c +++ b/dvi/mdvi-lib/fontmap.c @@ -872,18 +872,19 @@ void mdvi_flush_fontmaps(void) void ps_init_default_paths(void) { - char *kppath = mdvi_getenv("MDVI_PS_LIBPATH"); - char *kfpath = mdvi_getenv("MDVI_PS_FONTPATH"); + char *kppath; + char *kfpath; ASSERT(psinitialized == 0); - if(kppath == NULL) - kppath = getenv("GS_LIB"); - if(kfpath == NULL) - kfpath = getenv("GS_FONTPATH"); + + kppath = getenv("GS_LIB"); + kfpath = getenv("GS_FONTPATH"); + if(kppath != NULL) pslibdir = kpse_path_expand(kppath); if(kfpath != NULL) psfontdir = kpse_path_expand(kfpath); + listh_init(&psfonts); mdvi_hash_create(&pstable, PSMAP_HASH_SIZE); psinitialized = 1; diff --git a/dvi/mdvi-lib/mdvi.h b/dvi/mdvi-lib/mdvi.h index fbbab5bc..961689a0 100644 --- a/dvi/mdvi-lib/mdvi.h +++ b/dvi/mdvi-lib/mdvi.h @@ -65,7 +65,6 @@ typedef enum { TRUE = 1 } DviBool; -#include "assoc.h" #include "hash.h" #include "paper.h" @@ -307,8 +306,6 @@ struct _DviParams { DviOrientation orientation; /* page orientation */ int base_x; int base_y; - Ulong *pixels; /* colors used for antialiasing */ - int npixels; /* number of entries in `pixels' */ }; typedef enum { @@ -387,10 +384,11 @@ struct _DviContext { DviDevice device; /* device-specific routines */ Ulong curr_fg; /* rendering color */ Ulong curr_bg; + DviColorPair *color_stack; - DviHashTable assoc; int color_top; int color_size; + DviFontRef *(*findref) __PROTO((DviContext *, Int32)); void *user_data; /* client data attached to this context */ }; @@ -523,12 +521,6 @@ extern int mdvi_in_range __PROTO((DviRange *, int, int)); extern int mdvi_range_length __PROTO((DviRange *, int)); extern int mdvi_page_selected __PROTO((DviPageSpec *, PageNum, int)); -/* Color support */ -extern void mdvi_set_color __PROTO((DviContext *, Ulong, Ulong)); -extern void mdvi_push_color __PROTO((DviContext *, Ulong, Ulong)); -extern void mdvi_pop_color __PROTO((DviContext *)); -extern void mdvi_reset_color __PROTO((DviContext *)); - /* Specials */ extern int mdvi_register_special __PROTO(( const char *label, diff --git a/dvi/mdvi-lib/sp-epsf.c b/dvi/mdvi-lib/sp-epsf.c index de08482a..9a07fc79 100644 --- a/dvi/mdvi-lib/sp-epsf.c +++ b/dvi/mdvi-lib/sp-epsf.c @@ -235,7 +235,7 @@ void epsf_special(DviContext *dvi, char *prefix, char *arg) { char *file; char *special; - EpsfBox box; + EpsfBox box = {0, 0, 0, 0}; int x, y; int w, h; double xf, vf; diff --git a/dvi/mdvi-lib/tfmfile.c b/dvi/mdvi-lib/tfmfile.c index abab259d..45b78506 100644 --- a/dvi/mdvi-lib/tfmfile.c +++ b/dvi/mdvi-lib/tfmfile.c @@ -514,7 +514,6 @@ static int ofm_load_file(const char *filename, TFMInfo *info) } fread(info->coding, 39, 1, in); info->coding[n] = 0; - ptr += i; } else strcpy(info->coding, "FontSpecific"); /* get the font family */ diff --git a/dvi/mdvi-lib/util.c b/dvi/mdvi-lib/util.c index 8062733a..e7c73261 100644 --- a/dvi/mdvi-lib/util.c +++ b/dvi/mdvi-lib/util.c @@ -360,19 +360,6 @@ char *xstradd(char *dest, size_t *size, size_t n, const char *src, size_t m) return dest; } -int get_number(const char *string, long *val) -{ - long x; - char *end; - - errno = 0; - x = strtol(string, &end, 10); - if(errno || *end) - return -1; - *val = x; - return 0; -} - char *getword(char *string, const char *delim, char **end) { char *ptr; diff --git a/dvi/pixbuf-device.c b/dvi/pixbuf-device.c index 9ce93192..fbb05928 100644 --- a/dvi/pixbuf-device.c +++ b/dvi/pixbuf-device.c @@ -9,6 +9,10 @@ typedef struct _DviPixbufDevice gint xmargin; gint ymargin; + + Ulong fg; + Ulong bg; + } DviPixbufDevice; static void dvi_pixbuf_draw_rule(DviContext *dvi, int x, int y, Uint w, Uint h, int fill); @@ -52,6 +56,11 @@ static void dvi_pixbuf_draw_rule(DviContext *dvi, int x, int y, Uint w, Uint h, gint rowstride; gchar *p; gint i, j; + gint red, green, blue; + + red = (c_device->fg >> 16) & 0xff; + green = (c_device->fg >> 8) & 0xff; + blue = c_device->fg & 0xff; x += c_device->xmargin; y += c_device->ymargin; @@ -66,19 +75,19 @@ static void dvi_pixbuf_draw_rule(DviContext *dvi, int x, int y, Uint w, Uint h, for (i = 0; i < h; i++) { if (i == 0 || i == h - 1 || fill) { for (j = 0; j < w; j++) { - p[j * 4] = 0x00; - p[j * 4 + 1] = 0x00; - p[j * 4 + 2] = 0x00; + p[j * 4] = red; + p[j * 4 + 1] = green; + p[j * 4 + 2] = blue; p[j * 4 + 3] = 0xff; } } else { - p[0] = 0x00; - p[1] = 0x00; - p[2] = 0x00; + p[0] = red; + p[1] = green; + p[2] = blue; p[3] = 0xff; - p[(w - 1) * 4] = 0x00; - p[(w - 1) * 4 + 1] = 0x00; - p[(w - 1) * 4 + 2] = 0x00; + p[(w - 1) * 4] = red; + p[(w - 1) * 4 + 1] = green; + p[(w - 1) * 4 + 2] = blue; p[(w - 1) * 4 + 3] = 0xff; } p += rowstride; @@ -143,7 +152,10 @@ static void dvi_pixbuf_put_pixel(void *image, int x, int y, Ulong color) static void dvi_pixbuf_set_color(void *device_data, Ulong fg, Ulong bg) { + DviPixbufDevice *c_device = (DviPixbufDevice *) device_data; + c_device->fg = fg; + return; } @@ -194,7 +206,7 @@ mdvi_pixbuf_device_render (DviContext * dvi) page_width = dvi->dvi_page_w * dvi->params.conv + 2 * c_device->xmargin; page_height = dvi->dvi_page_h * dvi->params.vconv + 2 * c_device->ymargin; - + c_device->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, page_width, page_height); gdk_pixbuf_fill (c_device->pixbuf, 0xffffffff); -- 2.43.5