1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
Description: Better font validation
--- catdvi-0.14.orig/fontinfo.c
+++ catdvi-0.14/fontinfo.c
@@ -363,6 +363,10 @@ void font_def(sint32 k, uint32 c, uint32
* and axis_height happens to be the last one).
*/
tfm_tbl[k].axis_height = font_param(k, 22);
+ if(tfm_tbl[k].axis_height < 0) {
+ warning("Font has negative axis_height; substituting 0\n");
+ tfm_tbl[k].axis_height = 0;
+ }
}
else tfm_tbl[k].axis_height = 0;
@@ -417,9 +421,10 @@ fix_word_t font_scale_fw(sint32 font, fi
return fw_prod(fw, tfm_tbl[font].scale);
}
-uint32 font_char_width(sint32 font, sint32 glyph)
+sint32 font_char_width(sint32 font, sint32 glyph)
{
- uint32 wi, ugly, rv;
+ uint32 wi, ugly;
+ sint32 rv;
if (glyph < 0) {
warning("ignoring negative glyph index");
@@ -451,9 +456,10 @@ uint32 font_char_width(sint32 font, sint
}
-uint32 font_char_height(sint32 font, sint32 glyph)
+sint32 font_char_height(sint32 font, sint32 glyph)
{
- uint32 he, ugly, rv;
+ uint32 he, ugly;
+ sint32 rv;
if (glyph < 0) {
warning("ignoring negative glyph index");
@@ -485,9 +491,10 @@ uint32 font_char_height(sint32 font, sin
}
-uint32 font_char_depth(sint32 font, sint32 glyph)
+sint32 font_char_depth(sint32 font, sint32 glyph)
{
- uint32 de, ugly, rv;
+ uint32 de, ugly;
+ sint32 rv;
if (glyph < 0) {
warning("ignoring negative glyph index");
@@ -556,7 +563,7 @@ fix_word_t font_param(sint32 font, unsig
}
-uint32 font_axis_height(sint32 font)
+fix_word_t font_axis_height(sint32 font)
{
if (font < 0 || font >= LEN_TFM_TBL) {
warning("Font index out of range\n");
--- catdvi-0.14.orig/fontinfo.h
+++ catdvi-0.14/fontinfo.h
@@ -37,12 +37,12 @@ char const * font_family(sint32 k);
/* Return the width/height/depth of the refereced glyph in
* the referenced font.
*/
-uint32 font_char_width(sint32 font, sint32 glyph);
-uint32 font_char_height(sint32 font, sint32 glyph);
-uint32 font_char_depth(sint32 font, sint32 glyph);
+sint32 font_char_width(sint32 font, sint32 glyph);
+sint32 font_char_height(sint32 font, sint32 glyph);
+sint32 font_char_depth(sint32 font, sint32 glyph);
/* Return the unscaled(!) axis height, or 0 for fonts without this parameter */
-uint32 font_axis_height(sint32 font);
+fix_word_t font_axis_height(sint32 font);
/* scale a fixword in font units to DVI units */
fix_word_t font_scale_fw(sint32 font, fix_word_t fw);
--- catdvi-0.14.orig/layout.c
+++ catdvi-0.14/layout.c
@@ -603,7 +603,7 @@ void page_collect_statistics(void)
y = p->b.y;
width = p->b.width;
height = p->b.height;
- depth = p->b.depth;
+ depth = max(0, p->b.depth);
left_margin = min(left_margin, x);
right_margin = max(right_margin, x + width);
--- catdvi-0.14.orig/page.c
+++ catdvi-0.14/page.c
@@ -269,6 +269,44 @@ void page_set_glyph(
b.flags = 0;
b.axis = 0;
+ /* Make sure some fundamental assumptions are true */
+ if(b.width < 0) {
+ /* We can treat backspacing glyphs as empty boxes here, since
+ * advancing the DVI h register has already been taken care of.
+ */
+ pmesg(
+ 60,
+ "PAGE_SET_GLYPH: negative glyph width %li treated as 0\n",
+ b.width
+ );
+ b.width = 0;
+ }
+ if(b.height < 0) {
+ /* A submarine! This really should not happen. */
+ warning(
+ "Negative glyph height %li treated as 0.\n",
+ b.height
+ );
+ b.height = 0;
+ }
+ /* depth < 0 does occur from time to time. Main source are small
+ * glyphs with tight bounding box centered on the math axis.
+ * We leave this as it is to keep the math axis in the centre;
+ * so use max(0, b.depth) instead of b.depth for some calculations.
+ * We do however make an additional consistency check:
+ */
+ if(b.depth < -b.height) {
+ /* A glyph from Down Under! */
+ warning("Inconsistent font metrics, depth < -height. Fixed.\n");
+ pmesg(
+ 60,
+ "PAGE_SET_GLYPH: upside down glyph, depth=%li, height=%li\n",
+ b.depth,
+ b.height
+ );
+ b.depth = -b.height;
+ }
+
hint = glyph_get_hint(glyph);
if(hint & GH_DIACRITIC) {
|