X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=backend%2Fdvi%2Fmdvi-lib%2Fdviread.c;h=d01432056518ac6ae3518ed3eec5f5705159f02f;hb=33d9b680db507280f1d8fbb31c01d31de6531046;hp=3042951df5f9c7bb7be27b800cde1c974b474b6e;hpb=4ce480dd80453275c10c3b99f988667c2f1bdfff;p=evince.git diff --git a/backend/dvi/mdvi-lib/dviread.c b/backend/dvi/mdvi-lib/dviread.c index 3042951d..d0143205 100644 --- a/backend/dvi/mdvi-lib/dviread.c +++ b/backend/dvi/mdvi-lib/dviread.c @@ -13,9 +13,10 @@ * * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include #include @@ -237,7 +238,7 @@ static int get_bytes(DviContext *dvi, size_t n) newlen = fread(dvi->buffer.data + dvi->buffer.length, 1, dvi->buffer.size - dvi->buffer.length, dvi->in); if(newlen == -1) { - error("%s: %s\n", dvi->filename, strerror(errno)); + mdvi_error("%s: %s\n", dvi->filename, strerror(errno)); return -1; } dvi->buffer.length += newlen; @@ -358,7 +359,7 @@ static int sort_down(const void *p1, const void *p2) } static int sort_random(const void *p1, const void *p2) { - return (random() % 1) ? -1 : 1; + return (rand() % 1) ? -1 : 1; } static int sort_dvi_up(const void *p1, const void *p2) { @@ -426,7 +427,7 @@ static DviFontRef *define_font(DviContext *dvi, int op) hdpi, vdpi)); ref = font_reference(&dvi->params, arg, name, checksum, hdpi, vdpi, scale); if(ref == NULL) { - error(_("could not load font `%s'\n"), name); + mdvi_error(_("could not load font `%s'\n"), name); mdvi_free(name); return NULL; } @@ -480,7 +481,7 @@ int mdvi_reload(DviContext *dvi, DviParams *np) /* load it again */ newdvi = mdvi_init_context(pars, dvi->pagesel, dvi->filename); if(newdvi == NULL) { - warning(_("could not reload `%s'\n"), dvi->filename); + mdvi_warning(_("could not reload `%s'\n"), dvi->filename); return -1; } @@ -683,7 +684,7 @@ DviContext *mdvi_init_context(DviParams *par, DviPageSpec *spec, const char *fil perror(file); return NULL; } - p = fopen(filename, "r"); + p = fopen(filename, "rb"); if(p == NULL) { perror(file); mdvi_free(filename); @@ -707,8 +708,8 @@ DviContext *mdvi_init_context(DviParams *par, DviPageSpec *spec, const char *fil if(fuget1(p) != DVI_PRE) goto bad_dvi; if((arg = fuget1(p)) != DVI_ID) { - error(_("%s: unsupported DVI format (version %u)\n"), - file, arg); + mdvi_error(_("%s: unsupported DVI format (version %u)\n"), + file, arg); goto error; /* jump to the end of this routine, * where we handle errors */ } @@ -867,7 +868,7 @@ DviContext *mdvi_init_context(DviParams *par, DviPageSpec *spec, const char *fil } pagecount++; if(pagecount >= dvi->npages) { - error(_("no pages selected\n")); + mdvi_error(_("no pages selected\n")); goto error; } if(pagecount) { @@ -900,7 +901,7 @@ DviContext *mdvi_init_context(DviParams *par, DviPageSpec *spec, const char *fil return dvi; bad_dvi: - error(_("%s: File corrupted, or not a DVI file\n"), file); + mdvi_error(_("%s: File corrupted, or not a DVI file\n"), file); error: /* if we came from the font definitions, this will be non-trivial */ dreset(dvi); @@ -1007,11 +1008,11 @@ int mdvi_dopage(DviContext *dvi, int pageno) again: if(dvi->in == NULL) { /* try reopening the file */ - dvi->in = fopen(dvi->filename, "r"); + dvi->in = fopen(dvi->filename, "rb"); if(dvi->in == NULL) { - warning(_("%s: could not reopen file (%s)\n"), - dvi->filename, - strerror(errno)); + mdvi_warning(_("%s: could not reopen file (%s)\n"), + dvi->filename, + strerror(errno)); return -1; } DEBUG((DBG_FILES, "reopen(%s) -> Ok\n", dvi->filename)); @@ -1026,15 +1027,15 @@ again: } if(pageno < 0 || pageno > dvi->npages-1) { - error(_("%s: page %d out of range\n"), - dvi->filename, pageno); + mdvi_error(_("%s: page %d out of range\n"), + dvi->filename, pageno); return -1; } fseek(dvi->in, (long)dvi->pagemap[pageno][0], SEEK_SET); if((op = fuget1(dvi->in)) != DVI_BOP) { - error(_("%s: bad offset at page %d\n"), - dvi->filename, pageno+1); + mdvi_error(_("%s: bad offset at page %d\n"), + dvi->filename, pageno+1); return -1; } @@ -1165,43 +1166,13 @@ 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->curr_fg; bg = dvi->curr_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); @@ -1536,6 +1507,10 @@ int special(DviContext *dvi, int opcode) Int32 arg; arg = dugetn(dvi, opcode - DVI_XXX1 + 1); + if (arg <= 0) { + dvierr(dvi, _("malformed special length\n")); + return -1; + } s = mdvi_malloc(arg + 1); dread(dvi, s, arg); s[arg] = 0;