Re: [PATCH] Fix T1 font rendering in dvi backend



Hi Carlos!

On Sat, 2008-04-12 at 11:35 +0200, Carlos Garcia Campos wrote:
> So, how can we reproduce the problem? I don't understand why is only
> reproducible when testing against development tree. 

Ok, let me elaborate: The problem only shows up if evince actually
renders the characters directly using t1lib. This only happens if it can
find the font files. For locating these files, the mdvi-lib contained in
evince uses the kpathsea library. The search path that kpathsea will use
depends on where the program is installed, what paths are passed
to ./configure, environment variables etc. Now what happened here was
that I had passed a different --prefix to ./configure in order to
prevent make install from overwriting my system evince installation.
However, the kpathsea searchpath now didn't include the paths where my
t1 fonts (actually part of the texlive installation) are stored. This
resulted in kpathsea failing to locate the fonts, mdvi-lib falling back
to the bitmap versions of the fonts. Thus, the problem didn't show up. 

A good way to check what's going on is to set KPATHSEA_DEBUG=-1 in the
environment. Kpathsea will then print debug output on stderr listing all
the paths it considers. For example, the evince compiled from my
development tree outputs the line

...
kdebug:start search(files=[cmssbx10.pfa cmssbx10.pfb cmssbx10], must_exist=0, find_all=0, path=.:/home/mattias/.texmf-config/fonts/type1//:/home/mattias/.texmf-var/fonts/type1//:/home/mattias/texmf/fonts/type1//:!!/home/mattias/local/etc/texmf/fonts/type1//:!!/home/mattias/local/var/lib/texmf/fonts/type1//:!!/home/mattias/local/evince/share/texmf/fonts/type1//:!!/home/mattias/local/evince/local/share/texmf/fonts/type1//:!!/home/mattias/local/evince/share/texmf-site/fonts/type1//:!!/home/mattias/local/evince/share/texmf-dist/fonts/type1//:/please/set/osfontdir/in/the/environment//).
...

The cmssbx10 file cannot be found in any of these directories. However,
if I set OSFONTDIR=/usr/share/texmf/fonts/type1, the cmssbx10.pfb file
is found and evince will render the characters directly through t1lib.
This time, the bug strikes.

I hope this explanation gives you enough information to understand and
reproduce the bug.

> 
> The patch doesn't apply correctly to current svn trunk. Could you update
> the patch, please? Ah!, and please send it attached to the mail instead
> of inline, so that it's easier to save and apply :-)

I've just checked again, the patch applies without problems against rev
3004. I have now attached it for your convenience.

Mattias
Index: backend/dvi/mdvi-lib/bitmap.c
===================================================================
--- backend/dvi/mdvi-lib/bitmap.c	(revision 2998)
+++ backend/dvi/mdvi-lib/bitmap.c	(working copy)
@@ -125,7 +125,7 @@
  * hopelessly slow.
  */
 
-BITMAP	*bitmap_convert_lsb8(Uchar *bits, int w, int h)
+BITMAP	*bitmap_convert_lsb8(Uchar *bits, int w, int h, int stride)
 {
 	BITMAP	*bm;
 	int	i;
@@ -147,12 +147,13 @@
 	for(i = 0; i < h; i++) {
 #ifdef WORD_LITTLE_ENDIAN
 		memcpy(unit, curr, bytes);
-		curr += bytes;
+		curr += stride;
 #else
 		int	j;
 		
 		for(j = 0; j < bytes; curr++, j++)
 			unit[j] = bit_swap[*curr];
+		cur += stride - bytes;
 #endif
 		memzero(unit + bytes, bm->stride - bytes);
 		unit  += bm->stride;
@@ -162,7 +163,7 @@
 	return bm;
 }
 
-BITMAP	*bitmap_convert_msb8(Uchar *data, int w, int h)
+BITMAP	*bitmap_convert_msb8(Uchar *data, int w, int h, int stride)
 {
 	BITMAP	*bm;
 	Uchar	*unit;
@@ -180,9 +181,10 @@
 		
 		for(j = 0; j < bytes; curr++, j++)
 			unit[j] = bit_swap[*curr];
+		curr += stride - bytes;
 #else
 		memcpy(unit, curr, bytes);
-		curr += bytes;
+		curr += stride;
 #endif
 		memzero(unit + bytes, bm->stride - bytes);
 		unit += bm->stride;
Index: backend/dvi/mdvi-lib/bitmap.h
===================================================================
--- backend/dvi/mdvi-lib/bitmap.h	(revision 2998)
+++ backend/dvi/mdvi-lib/bitmap.h	(working copy)
@@ -136,8 +136,8 @@
 extern void bitmap_rotate_counter_clockwise __PROTO((BITMAP *));
 extern void bitmap_flip_rotate_clockwise __PROTO((BITMAP *));
 extern void bitmap_flip_rotate_counter_clockwise __PROTO((BITMAP *));
-extern BITMAP *bitmap_convert_lsb8 __PROTO((Uchar *, int, int));
-extern BITMAP *bitmap_convert_msb8 __PROTO((Uchar *, int, int));
+extern BITMAP *bitmap_convert_lsb8 __PROTO((Uchar *, int, int, int));
+extern BITMAP *bitmap_convert_msb8 __PROTO((Uchar *, int, int, int));
 
 #include <stdio.h>
 extern void	bitmap_print __PROTO((FILE *, BITMAP *));
Index: backend/dvi/mdvi-lib/t1.c
===================================================================
--- backend/dvi/mdvi-lib/t1.c	(revision 2998)
+++ backend/dvi/mdvi-lib/t1.c	(working copy)
@@ -437,25 +437,16 @@
 
 static inline BITMAP *t1_glyph_bitmap(GLYPH *glyph)
 {
-	BITMAP	*bm;
-	int	w, h;
+	int	w, h, pad;
 	
 	w = GLYPH_WIDTH(glyph);
 	h = GLYPH_HEIGHT(glyph);
 
 	if(!w || !h)
 		return MDVI_GLYPH_EMPTY;
-	switch(glyph->bpp << 3) {
-		case 8: 
-			bm = bitmap_convert_lsb8((unsigned char *)glyph->bits, w, h);
-			break;
-		default:
-			warning(_("(t1) unsupported bitmap pad size %d\n"),
-				glyph->bpp);
-			bm = MDVI_GLYPH_EMPTY;
-			break;
-	}
-	return bm;
+
+	pad = T1_GetBitmapPad();
+	return bitmap_convert_lsb8((unsigned char *)glyph->bits, w, h, ROUND(w, pad) * (pad >> 3));
 }
 
 static void t1_font_shrink_glyph(DviContext *dvi, DviFont *font, DviFontChar *ch, DviGlyph *dest)
Index: backend/dvi/mdvi-lib/tt.c
===================================================================
--- backend/dvi/mdvi-lib/tt.c	(revision 2998)
+++ backend/dvi/mdvi-lib/tt.c	(working copy)
@@ -382,7 +382,7 @@
 	
 	TT_Translate_Outline(&outline, -bbox.xMin, -bbox.yMin);
 	TT_Get_Outline_Bitmap(tt_handle, &outline, &raster);
-	glyph->data = bitmap_convert_msb8(raster.bitmap, w, h);
+	glyph->data = bitmap_convert_msb8(raster.bitmap, w, h, ROUND(w, 8));
 	TT_Done_Outline(&outline);
 	mdvi_free(raster.bitmap);
 	


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]