* include/freetype/config/ftoption.h, include/freetype/internal/ttypes.h, src/truetype/ttpload.c, src/truetype/ttpload.h, src/truetype/ttgload.c: added the temporary configuration FT_OPTIMIZE_MEMORY to control various optimizations used to reduce the heap footprint of memory-mapped TrueType files. * src/truetype/ttpload.c (tt_face_load_loca, tt_face_get_location, tt_face_done_loca): when FT_OPTIMIZE_MEMORY is set, the locations table is read directly from memory-mapped streams, instead of being decoded into the heap. * src/truetype/ttpload.c: only load the CVT and fpgm tables when the bytecode interpreter is compiled in.
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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
diff --git a/ChangeLog b/ChangeLog
index fb56e4f..cde05d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,20 @@
* include/freetype/internal/ftmemory.h: adding FT_ARRAY_ZERO, as a
convenience macro.
+ * include/freetype/config/ftoption.h, include/freetype/internal/ttypes.h,
+ src/truetype/ttpload.c, src/truetype/ttpload.h, src/truetype/ttgload.c:
+ added the temporary configuration FT_OPTIMIZE_MEMORY to control various
+ optimizations used to reduce the heap footprint of memory-mapped TrueType
+ files.
+
+ * src/truetype/ttpload.c (tt_face_load_loca, tt_face_get_location,
+ tt_face_done_loca): when FT_OPTIMIZE_MEMORY is set, the locations table
+ is read directly from memory-mapped streams, instead of being decoded
+ into the heap.
+
+ * src/truetype/ttpload.c: only load the CVT and fpgm tables when the
+ bytecode interpreter is compiled in.
+
2005-02-20 Werner Lemberg <wl@gnu.org>
diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index 1d9efe4..c3d06c4 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -568,6 +568,8 @@ FT_BEGIN_HEADER
#endif /* FT_CONFIG_OPTION_CHESTER_HINTS */
+#define FT_OPTIMIZE_MEMORY
+
FT_END_HEADER
diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h
index 4a3aab1..183beb8 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -361,6 +361,7 @@ FT_BEGIN_HEADER
} TT_HdmxRec, *TT_Hdmx;
+
/*************************************************************************/
/* */
/* <Struct> */
@@ -1263,9 +1264,14 @@ FT_BEGIN_HEADER
/* */
/***********************************************************************/
+#ifdef FT_OPTIMIZE_MEMORY
+ FT_UInt num_locations;
+ FT_Byte* glyph_locations;
+#else
/* the glyph locations */
FT_UShort num_locations;
FT_Long* glyph_locations;
+#endif
/* the font program, if any */
FT_ULong font_program_size;
@@ -1297,7 +1303,7 @@ FT_BEGIN_HEADER
FT_Bool doblend;
GX_Blend blend;
#endif
-
+
/***********************************************************************/
/* */
/* Other tables or fields. This is used by derivative formats like */
diff --git a/src/autohint/ahglyph.c b/src/autohint/ahglyph.c
index 5bf1988..7db7bb9 100644
--- a/src/autohint/ahglyph.c
+++ b/src/autohint/ahglyph.c
@@ -304,12 +304,15 @@
if ( FT_RENEW_ARRAY( outline->points, max, news ) ||
- FT_RENEW_ARRAY( outline->horz_edges, max * 2, news * 2 ) ||
- FT_RENEW_ARRAY( outline->horz_segments, max * 2, news * 2 ) )
+ FT_RENEW_ARRAY( outline->horz_edges, max * 2, news * 2 ) )
goto Exit;
- /* readjust some pointers */
outline->vert_edges = outline->horz_edges + news;
+
+ if ( FT_RENEW_ARRAY( outline->horz_segments, max * 2, news * 2 ) )
+ goto Exit;
+
+ /* readjust some pointers */
outline->vert_segments = outline->horz_segments + news;
outline->max_points = news;
}
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 145ac98..036a7d2 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -1019,13 +1019,7 @@
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
- {
- offset = face->glyph_locations[glyph_index];
- count = 0;
-
- if ( glyph_index < (FT_UInt)face->num_locations - 1 )
- count = (FT_UInt)( face->glyph_locations[glyph_index + 1] - offset );
- }
+ offset = tt_face_get_location( face, glyph_index, &count );
if ( count == 0 )
{
diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c
index b606ace..095292d 100644
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -218,8 +218,11 @@
if ( !face->root.internal->incremental_interface )
error = tt_face_load_loca( face, stream );
if ( !error )
- error = tt_face_load_cvt( face, stream ) ||
- tt_face_load_fpgm( face, stream );
+ {
+ error = tt_face_load_cvt( face, stream );
+ if ( !error )
+ error = tt_face_load_fpgm( face, stream );
+ }
#else
@@ -290,8 +293,7 @@
sfnt->done_face( face );
/* freeing the locations table */
- FT_FREE( face->glyph_locations );
- face->num_locations = 0;
+ tt_face_done_loca( face );
/* freeing the CVT */
FT_FREE( face->cvt );
diff --git a/src/truetype/ttpload.c b/src/truetype/ttpload.c
index 9cae477..cc2eb61 100644
--- a/src/truetype/ttpload.c
+++ b/src/truetype/ttpload.c
@@ -58,6 +58,118 @@
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
+#ifdef FT_OPTIMIZE_MEMORY
+
+ FT_LOCAL_DEF( FT_Error )
+ tt_face_load_loca( TT_Face face,
+ FT_Stream stream )
+ {
+ FT_Error error;
+ FT_Memory memory = stream->memory;
+ FT_ULong table_len;
+
+
+ FT_TRACE2(( "Locations " ));
+ error = face->goto_table( face, TTAG_loca, stream, &table_len );
+ if ( error )
+ {
+ error = TT_Err_Locations_Missing;
+ goto Exit;
+ }
+
+ if ( face->header.Index_To_Loc_Format != 0 )
+ {
+ if ( table_len >= 040000 )
+ {
+ FT_TRACE2(( "table too large !!\n" ));
+ error = TT_Err_Invalid_Table;
+ goto Exit;
+ }
+ face->num_locations = (FT_UInt)(table_len >> 2);
+ }
+ else
+ {
+ if ( table_len >= 0x20000 )
+ {
+ FT_TRACE2(( "table too large !!\n" ));
+ error = TT_Err_Invalid_Table;
+ goto Exit;
+ }
+ face->num_locations = (FT_UInt)(table_len >> 1);
+ }
+
+
+ /* extract the frame. We don't need to decompress it since
+ * we'll be able to parse it directly
+ */
+ if ( FT_FRAME_EXTRACT( table_len, face->glyph_locations ) )
+ goto Exit;
+
+ FT_TRACE2(( "loaded\n" ));
+
+ Exit:
+ return error;
+ }
+
+
+ FT_LOCAL_DEF( FT_ULong )
+ tt_face_get_location( TT_Face face,
+ FT_UInt gindex,
+ FT_UInt *asize )
+ {
+ FT_ULong pos1, pos2;
+ FT_Byte* p;
+ FT_Byte* p_limit;
+
+ pos1 = pos2 = 0;
+ if ( gindex < face->num_locations )
+ {
+ if ( face->header.Index_To_Loc_Format != 0 )
+ {
+ p = face->glyph_locations + gindex*4;
+ p_limit = face->glyph_locations + face->num_locations*4;
+
+ pos1 = FT_NEXT_ULONG(p);
+ pos2 = pos1;
+
+ if ( p+4 <= p_limit )
+ pos2 = FT_NEXT_ULONG(p);
+ }
+ else
+ {
+ p = face->glyph_locations + gindex*2;
+ p_limit = face->glyph_locations + face->num_locations*2;
+
+ pos1 = FT_NEXT_USHORT(p);
+ pos2 = pos1;
+
+ if ( p+2 <= p_limit )
+ pos2 = FT_NEXT_USHORT(p);
+
+ pos1 <<= 1;
+ pos2 <<= 1;
+ }
+ }
+
+ *asize = (FT_UInt)(pos2 - pos1);
+
+ return pos1;
+ }
+
+
+ FT_LOCAL_DEF( void )
+ tt_face_done_loca( TT_Face face )
+ {
+ FT_Stream stream = face->root.stream;
+
+ FT_FRAME_RELEASE( face->glyph_locations );
+ face->num_locations = 0;
+ }
+
+
+
+#else /* !FT_OPTIMIZE_MEMORY */
+
FT_LOCAL_DEF( FT_Error )
tt_face_load_loca( TT_Face face,
FT_Stream stream )
@@ -130,6 +242,39 @@
}
+ FT_LOCAL_DEF( FT_ULong )
+ tt_face_get_location( TT_Face face,
+ FT_UInt gindex,
+ FT_UInt *asize )
+ {
+ FT_ULong offset;
+ FT_UInt count;
+
+ offset = face->glyph_locations[gindex];
+ count = 0;
+
+ if ( gindex < (FT_UInt)face->num_locations - 1 )
+ count = (FT_UInt)( face->glyph_locations[gindex + 1] - offset );
+
+ *asize = count;
+ return offset;
+ }
+
+
+ FT_LOCAL_DEF( void )
+ tt_face_done_loca( TT_Face face )
+ {
+ FT_Memory memory = face->root.memory;
+
+ FT_FREE( face->glyph_locations );
+ face->num_locations = 0;
+ }
+
+
+
+#endif /* !FT_OPTIMIZE_MEMORY */
+
+
/*************************************************************************/
/* */
/* <Function> */
@@ -151,6 +296,8 @@
tt_face_load_cvt( TT_Face face,
FT_Stream stream )
{
+#ifdef FT_CONFIG_OPTION_BYTECODE_INTERPRETER
+
FT_Error error;
FT_Memory memory = stream->memory;
FT_ULong table_len;
@@ -197,6 +344,12 @@
Exit:
return error;
+
+#else /* !BYTECODE_INTERPRETER */
+ FT_UNUSED(face);
+ FT_UNUSED(stream);
+ return 0;
+#endif
}
@@ -221,6 +374,8 @@
tt_face_load_fpgm( TT_Face face,
FT_Stream stream )
{
+#ifdef FT_CONFIG_OPTION_BYTECODE_INTERPRETER
+
FT_Error error;
FT_ULong table_len;
@@ -267,6 +422,12 @@
Exit:
return error;
+
+#else /* !BYTECODE_INTERPRETER */
+ FT_UNUSED(face);
+ FT_UNUSED(stream);
+ return 0;
+#endif
}
diff --git a/src/truetype/ttpload.h b/src/truetype/ttpload.h
index 3f8cd64..1d14aec 100644
--- a/src/truetype/ttpload.h
+++ b/src/truetype/ttpload.h
@@ -31,6 +31,14 @@ FT_BEGIN_HEADER
tt_face_load_loca( TT_Face face,
FT_Stream stream );
+ FT_LOCAL( FT_ULong )
+ tt_face_get_location( TT_Face face,
+ FT_UInt gindex,
+ FT_UInt *asize );
+
+ FT_LOCAL( void )
+ tt_face_done_loca( TT_Face face );
+
FT_LOCAL( FT_Error )
tt_face_load_cvt( TT_Face face,
FT_Stream stream );