]> www.fi.muni.cz Git - evince.git/blobdiff - backend/dvi/mdvi-lib/dviread.c
dvi: Fix drawing glyphs with transparency
[evince.git] / backend / dvi / mdvi-lib / dviread.c
index 8d8799190de429fa1044ad3bee840936551d2dad..cd8cfa916113e821e87c344de300ba998a8b95a5 100644 (file)
@@ -13,7 +13,7 @@
  *
  * 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 <config.h>
@@ -238,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;
@@ -359,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)
 {
@@ -427,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;
        }
@@ -481,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;
        }
 
@@ -684,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);
@@ -708,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 */
        }
@@ -868,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) {
@@ -901,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);
@@ -1008,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));
@@ -1027,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;
        }
        
@@ -1166,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);