[PATCH] Fix T1 font rendering in dvi backend
- From: Mattias Nissler <mattias nissler gmx de>
- To: evince-list gnome org
- Subject: [PATCH] Fix T1 font rendering in dvi backend
- Date: Thu, 10 Apr 2008 01:10:41 +0200
Hi,
below patch fixes the problem of T1 font characters being rendered
incorrectly. I've made two screenshots illustrating this. In the broken
rendering [1], the characters are messed up. [2] shows the result after
applying the patch.
The problem turned out to be code using an incorrect row increment when
copying the bitmap. Note that the patch also affects the truetype font
loader. I haven't tested this part, but the patched code should be
functionally equivalent to the old code.
Also note that bug 354434 [3] seems to report the same problem. However,
the bug was closed without taking any action, probably because it is
likely to not show up when testing against a development tree. This was
the case during my tests, the reason was that the loader couldn't find
the T1 font and was falling back to bitmap fonts which are rendered
correctly.
Please CC me on replies, I'm not subscribed to the list.
Cheers,
Mattias
[1] http://www-user.rhrk.uni-kl.de/~nissler/tmp/evince_broken.png
[2] http://www-user.rhrk.uni-kl.de/~nissler/tmp/evince_ok.png#
[3] http://bugzilla.gnome.org/show_bug.cgi?id=354434
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]