fixed the sbit loader (src/base/sfnt/ttsbit.c) introduced a new load flag (FT_LOAD_CROP_BITMAP) used to indicate that we want embedded bitmaps to be cropped.. Thanks a lot to Yamano-uchi, Hidetoshi
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
diff --git a/CHANGES b/CHANGES
index 665c6a8..20c1c07 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,10 @@
LATEST_CHANGES
+ - fixed some bugs in the sbit loader (src/base/sfnt/ttsbit.c) + added
+ a new flag, FT_LOAD_CROP_BITMAP to query that bitmaps be cropped when
+ loaded from a file (maybe I should move the bitmap cropper to the
+ base layer ??).
+
- changed the default number of gray levels of the smooth renderer to
256 (instead of the previous 128). Of course, the human eye can't
see any difference ;-)
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 5a6fcab..164a4a0 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -1532,6 +1532,20 @@
/*************************************************************************/
/* */
/* <Constant> */
+ /* FT_LOAD_CROP_BITMAP */
+ /* */
+ /* <Description> */
+ /* A bit-field constant, used with FT_Load_Glyph() to indicate that */
+ /* the font driver should try to crop the bitmap (i.e. remove all */
+ /* space around its black bits) when loading it. For now, this */
+ /* really only works with Embedded Bitmaps in TrueType fonts.. */
+ /* */
+ /* */
+#define FT_LOAD_CROP_BITMAP 64
+
+ /*************************************************************************/
+ /* */
+ /* <Constant> */
/* FT_LOAD_PEDANTIC */
/* */
/* <Description> */
diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h
index 9e6eb11..5775667 100644
--- a/include/freetype/internal/sfnt.h
+++ b/include/freetype/internal/sfnt.h
@@ -166,6 +166,7 @@
TT_Int x_ppem,
TT_Int y_ppem,
TT_UInt glyph_index,
+ TT_UInt load_flags,
FT_Stream stream,
FT_Bitmap* map,
TT_SBit_Metrics* metrics );
diff --git a/src/sfnt/ttsbit.c b/src/sfnt/ttsbit.c
index 57cf6a5..7303af4 100644
--- a/src/sfnt/ttsbit.c
+++ b/src/sfnt/ttsbit.c
@@ -58,7 +58,7 @@
/* */
static
void blit_sbit( FT_Bitmap* target,
- char* source,
+ FT_Byte* source,
FT_Int line_bits,
FT_Bool byte_padded,
FT_Int x_offset,
@@ -115,19 +115,19 @@
/* ensure that there are at least 8 bits in the accumulator */
if ( loaded < 8 )
{
- acc |= ((FT_UShort)*source++) << (8 - loaded);
+ acc |= (FT_UShort)*source++ << (8 - loaded);
loaded += 8;
}
/* now write one byte */
- val = (FT_Byte)(acc >> 8);
+ val = (FT_Byte)(acc >> 8);
if (shift)
{
cur[0] |= val >> shift;
cur[1] |= val << space;
}
else
- cur[0] = val;
+ cur[0] |= val;
cur++;
acc <<= 8; /* remove bits from accumulator */
@@ -150,7 +150,7 @@
/* ensure that there are at least `count' bits in the accumulator */
if ( loaded < count )
{
- acc |= ((FT_UShort)*source++) << (8 - loaded);
+ acc |= (FT_UShort)*source++ << (8 - loaded);
loaded += 8;
}
@@ -464,6 +464,7 @@
TT_ULong num_strikes;
TT_ULong table_base;
+ face->num_sbit_strikes = 0;
/* this table is optional */
error = face->goto_table( face, TTAG_EBLC, stream, 0 );
@@ -724,7 +725,7 @@
else
*aglyph_offset = range->image_offset +
n * range->image_size;
- break;
+ goto Found;
}
}
}
@@ -734,9 +735,9 @@
goto Fail;
}
+ Found:
/* return successfully! */
*arange = range;
-
return 0;
}
}
@@ -851,54 +852,55 @@
TT_Error error = TT_Err_Ok;
- switch ( range->index_format )
+ switch ( range->image_format )
{
- case 1: /* variable metrics */
- case 3:
- case 4:
- {
- switch ( range->image_format )
+ case 1:
+ case 2:
+ case 8:
+ /* variable small metrics */
{
- case 1: /* small metrics */
- case 2:
- case 8:
- {
- TT_SBit_Small_Metrics smetrics;
-
-
- /* read small metrics */
- if ( ACCESS_Frame( 5L ) )
- goto Exit;
- TT_Load_Small_SBit_Metrics( &smetrics, stream );
- FORGET_Frame();
-
- /* convert it to a big metrics */
- metrics->height = smetrics.height;
- metrics->width = smetrics.width;
- metrics->horiBearingX = smetrics.bearingX;
- metrics->horiBearingY = smetrics.bearingY;
- metrics->horiAdvance = smetrics.advance;
-
- /* these metrics are made up at a higher level when */
- /* needed. */
- metrics->vertBearingX = 0;
- metrics->vertBearingY = 0;
- metrics->vertAdvance = 0;
- }
- break;
+ TT_SBit_Small_Metrics smetrics;
- default: /* big metrics */
- if ( ACCESS_Frame( 8L ) )
+ /* read small metrics */
+ if ( ACCESS_Frame( 5L ) )
goto Exit;
- TT_Load_SBit_Metrics( metrics, stream );
+ TT_Load_Small_SBit_Metrics( &smetrics, stream );
FORGET_Frame();
+
+ /* convert it to a big metrics */
+ metrics->height = smetrics.height;
+ metrics->width = smetrics.width;
+ metrics->horiBearingX = smetrics.bearingX;
+ metrics->horiBearingY = smetrics.bearingY;
+ metrics->horiAdvance = smetrics.advance;
+
+ /* these metrics are made up at a higher level when */
+ /* needed. */
+ metrics->vertBearingX = 0;
+ metrics->vertBearingY = 0;
+ metrics->vertAdvance = 0;
}
+ break;
+
+ case 6:
+ case 7:
+ case 9:
+ /* variable big metrics */
+ {
+ if ( ACCESS_Frame( 8L ) )
+ goto Exit;
+ TT_Load_SBit_Metrics( metrics, stream );
+ FORGET_Frame();
}
break;
- default: /* constant metrics */
- *metrics = range->metrics;
- }
+ case 5:
+ default: /* constant metrics */
+ if ( range->index_format == 2 || range->index_format == 5 )
+ *metrics = range->metrics;
+ else
+ return FT_Err_Invalid_File_Format;
+ }
Exit:
return error;
@@ -1177,7 +1179,7 @@
/* don't forget to multiply `x_offset' by `map->pix_bits' as */
/* the sbit blitter doesn't make a difference between pixmap */
/* depths. */
- blit_sbit( map, stream->cursor, line_bits, pad_bytes,
+ blit_sbit( map, (FT_Byte*)stream->cursor, line_bits, pad_bytes,
x_offset * pix_bits, y_offset );
FORGET_Frame();
@@ -1267,6 +1269,9 @@
range->image_format, metrics, stream );
case 8: /* compound format */
+ FT_Skip_Stream( stream, 1L );
+ /* fallthrough */
+
case 9:
break;
@@ -1377,6 +1382,7 @@
TT_Int x_ppem,
TT_Int y_ppem,
TT_UInt glyph_index,
+ TT_UInt load_flags,
FT_Stream stream,
FT_Bitmap* map,
TT_SBit_Metrics* metrics )
@@ -1432,8 +1438,9 @@
metrics->vertAdvance = advance * 12 / 10;
}
- /* Crop the bitmap now */
- Crop_Bitmap( map, metrics );
+ /* Crop the bitmap now, unless specified otherwise */
+ if (load_flags & FT_LOAD_CROP_BITMAP)
+ Crop_Bitmap( map, metrics );
Exit:
return error;
diff --git a/src/sfnt/ttsbit.h b/src/sfnt/ttsbit.h
index 414ceae..944dc3e 100644
--- a/src/sfnt/ttsbit.h
+++ b/src/sfnt/ttsbit.h
@@ -93,6 +93,7 @@
TT_Int x_ppem,
TT_Int y_ppem,
TT_UInt glyph_index,
+ TT_UInt load_flags,
FT_Stream stream,
FT_Bitmap* map,
TT_SBit_Metrics* metrics );
diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c
index 9137758..33b4123 100644
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -239,8 +239,30 @@
root->charmaps[n] = (FT_CharMap)charmap;
}
- root->num_fixed_sizes = 0;
- root->available_sizes = 0;
+#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
+ if ( face->num_sbit_strikes )
+ {
+ face->root.num_fixed_sizes = face->num_sbit_strikes;
+ if ( ALLOC_ARRAY( face->root.available_sizes,
+ face->num_sbit_strikes,
+ FT_Bitmap_Size ) )
+ return error;
+
+ for ( n = 0 ; n < face->num_sbit_strikes ; n++ )
+ {
+ face->root.available_sizes[n].width =
+ face->sbit_strikes[n].x_ppem;
+ face->root.available_sizes[n].height =
+ face->sbit_strikes[n].y_ppem;
+ }
+ }
+ else
+#else
+ {
+ root->num_fixed_sizes = 0;
+ root->available_sizes = 0;
+ }
+#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
/*****************************************************************/
/* */
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index c388a6c..f7be829 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -1231,6 +1231,7 @@
size->root.metrics.x_ppem,
size->root.metrics.y_ppem,
glyph_index,
+ load_flags,
stream,
&glyph->bitmap,
&metrics );
diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c
index 089227a..faccdc3 100644
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -373,6 +373,11 @@
FREE( face->root.family_name );
FREE( face->root.style_name );
+ /* freeing sbit size table */
+ face->root.num_fixed_sizes = 0;
+ if ( face->root.available_sizes )
+ FREE( face->root.available_sizes );
+
face->sfnt = 0;
}