* src/sfnt/ttmtx.c, src/cff/cffload.c: speeding up the CFF font loader, with some large CFF fonts, FT_Open_Face is now 350% faster !
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/ChangeLog b/ChangeLog
index ac3167d..20b7bac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,10 @@
2006-10-23 David Turner <david@freetype.org>
- * src/pshinter/pshalgo.c: major speed improvements to the Postscript
- hinter, more than 100% speed increase on my machine
+ * src/sfnt/ttmtx.c, src/cff/cffload.c: speeding up the CFF font
+ loader, with some large CFF fonts, FT_Open_Face is now 350% faster !
+
+ * src/pshinter/pshalgo.c: major speed improvements to the Postscript
+ hinter, more than 100% speed increase on my machine
2006-10-15 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
@@ -115,6 +118,7 @@
* src/smooth/ftsmooth.c (ft_smooth_render_generic): Remove arguments
`hmul' and `vmul'.
+ 5A
Handle subpixel rendering.
Simplify function.
(ft_smooth_render_lcd): Use `FT_RENDER_MODE_LCD'.
diff --git a/src/cff/cffload.c b/src/cff/cffload.c
index ac5ed85..6abd9ea 100644
--- a/src/cff/cffload.c
+++ b/src/cff/cffload.c
@@ -1063,24 +1063,6 @@
#define FT_COMPONENT trace_cffload
- /* read a CFF offset from memory */
- static FT_ULong
- cff_get_offset( FT_Byte* p,
- FT_Byte off_size )
- {
- FT_ULong result;
-
-
- for ( result = 0; off_size > 0; off_size-- )
- {
- result <<= 8;
- result |= *p++;
- }
-
- return result;
- }
-
-
static FT_Error
cff_new_index( CFF_Index idx,
FT_Stream stream,
@@ -1101,6 +1083,7 @@
FT_Byte offsize;
FT_ULong data_size;
FT_ULong* poff;
+ FT_Byte* p_end;
/* there is at least one element; read the offset size, */
@@ -1108,6 +1091,12 @@
if ( FT_READ_BYTE( offsize ) )
goto Exit;
+ if ( offsize < 1 || offsize > 4 )
+ {
+ error = FT_Err_Invalid_Table;
+ goto Exit;
+ }
+
idx->stream = stream;
idx->count = count;
idx->off_size = offsize;
@@ -1117,14 +1106,30 @@
FT_FRAME_ENTER( data_size ) )
goto Exit;
- poff = idx->offsets;
- p = (FT_Byte*)stream->cursor;
+ poff = idx->offsets;
+ p = (FT_Byte*)stream->cursor;
+ p_end = p + data_size;
- for ( ; (FT_Short)count >= 0; count-- )
+ switch ( offsize )
{
- poff[0] = cff_get_offset( p, offsize );
- poff++;
- p += offsize;
+ case 1:
+ for ( ; p < p_end; p++, poff++ )
+ poff[0] = p[0];
+ break;
+
+ case 2:
+ for ( ; p < p_end; p += 2, poff++ )
+ poff[0] = FT_PEEK_USHORT(p);
+ break;
+
+ case 3:
+ for ( ; p < p_end; p += 3, poff++ )
+ poff[0] = FT_PEEK_OFF3(p);
+ break;
+
+ default:
+ for ( ; p < p_end; p += 4, poff++ )
+ poff[0] = FT_PEEK_ULONG(p);
}
FT_FRAME_EXIT();
@@ -1493,20 +1498,60 @@
/*************************************************************************/
/*************************************************************************/
+ static FT_Error
+ cff_charset_compute_cids( CFF_Charset charset,
+ FT_UInt num_glyphs,
+ FT_Memory memory )
+ {
+ FT_Error error = 0;
+ FT_UInt i;
+ FT_UShort max_cid = 0;
+
+ if ( charset->max_cid > 0 )
+ goto Exit;
+
+ for ( i = 0; i < num_glyphs; i++ )
+ if ( charset->sids[i] > max_cid )
+ max_cid = charset->sids[i];
+ max_cid++;
+
+ if ( FT_NEW_ARRAY( charset->cids, max_cid ) )
+ goto Exit;
+
+ for ( i = 0; i < num_glyphs; i++ )
+ charset->cids[charset->sids[i]] = (FT_UShort)i;
+
+ charset->max_cid = max_cid;
+
+ Exit:
+ return error;
+ }
+
+
+ static void
+ cff_charset_free_cids( CFF_Charset charset,
+ FT_Memory memory )
+ {
+ FT_FREE( charset->cids );
+ charset->max_cid = 0;
+ }
+
+
static void
cff_charset_done( CFF_Charset charset,
FT_Stream stream )
{
FT_Memory memory = stream->memory;
+ cff_charset_free_cids( charset, memory );
FT_FREE( charset->sids );
- FT_FREE( charset->cids );
charset->format = 0;
charset->offset = 0;
}
+
static FT_Error
cff_charset_load( CFF_Charset charset,
FT_UInt num_glyphs,
@@ -1672,25 +1717,7 @@
/* we have to invert the `sids' array for subsetted CID-keyed fonts */
if ( invert )
- {
- FT_UInt i;
- FT_UShort max_cid = 0;
-
-
- for ( i = 0; i < num_glyphs; i++ )
- if ( charset->sids[i] > max_cid )
- max_cid = charset->sids[i];
- max_cid++;
-
- if ( FT_NEW_ARRAY( charset->cids, max_cid ) )
- goto Exit;
- FT_MEM_ZERO( charset->cids, sizeof ( FT_UShort ) * max_cid );
-
- for ( i = 0; i < num_glyphs; i++ )
- charset->cids[charset->sids[i]] = (FT_UShort)i;
-
- charset->max_cid = max_cid;
- }
+ error = cff_charset_compute_cids( charset, num_glyphs, memory );
Exit:
/* Clean up if there was an error. */
@@ -1921,32 +1948,29 @@
encoding->count = 0;
+ error = cff_charset_compute_cids( charset, num_glyphs, stream->memory );
+ if (error)
+ goto Exit;
+
for ( j = 0; j < 256; j++ )
{
- /* If j is encoded, find the GID for it. */
- if ( encoding->sids[j] )
+ FT_UInt sid = encoding->sids[j];
+ FT_UInt gid = 0;
+
+ if ( sid )
+ gid = charset->cids[sid];
+
+ if ( gid != 0 )
{
- for ( i = 1; i < num_glyphs; i++ )
- /* We matched, so break. */
- if ( charset->sids[i] == encoding->sids[j] )
- break;
-
- /* i will be equal to num_glyphs if we exited the above */
- /* loop without a match. In this case, we also have to */
- /* fix the code to SID mapping. */
- if ( i == num_glyphs )
- {
- encoding->codes[j] = 0;
- encoding->sids [j] = 0;
- }
- else
- {
- encoding->codes[j] = (FT_UShort)i;
+ encoding->codes[j] = (FT_UShort)gid;
- /* update encoding count */
- if ( encoding->count < j + 1 )
- encoding->count = j + 1;
- }
+ if ( encoding->count < j+1 )
+ encoding->count = j+1;
+ }
+ else
+ {
+ encoding->codes[j] = 0;
+ encoding->sids [j] = 0;
}
}
break;
@@ -2013,7 +2037,7 @@
if ( error )
goto Exit;
-
+
/* if it is a CID font, we stop there */
if ( top->cid_registry != 0xFFFFU )
goto Exit;
diff --git a/src/sfnt/ttmtx.c b/src/sfnt/ttmtx.c
index d0140b3..2d4f02c 100644
--- a/src/sfnt/ttmtx.c
+++ b/src/sfnt/ttmtx.c
@@ -71,8 +71,8 @@
FT_ULong table_size;
FT_Byte** ptable;
FT_ULong* ptable_size;
-
-
+
+
if ( vertical )
{
error = face->goto_table( face, TTAG_vmtx, stream, &table_size );
@@ -91,10 +91,10 @@
ptable = &face->horz_metrics;
ptable_size = &face->horz_metrics_size;
}
-
+
if ( FT_FRAME_EXTRACT( table_size, *ptable ) )
goto Fail;
-
+
*ptable_size = table_size;
Fail:
@@ -116,6 +116,7 @@
TT_LongMetrics * longs;
TT_ShortMetrics** shorts;
+ FT_Byte* p;
if ( vertical )
@@ -175,6 +176,8 @@
if ( FT_FRAME_ENTER( table_len ) )
goto Fail;
+ p = stream->cursor;
+
{
TT_LongMetrics cur = *longs;
TT_LongMetrics limit = cur + num_longs;
@@ -182,8 +185,8 @@
for ( ; cur < limit; cur++ )
{
- cur->advance = FT_GET_USHORT();
- cur->bearing = FT_GET_SHORT();
+ cur->advance = FT_NEXT_USHORT(p);
+ cur->bearing = FT_NEXT_SHORT(p);
}
}
@@ -195,7 +198,7 @@
for ( ; cur < limit; cur++ )
- *cur = FT_GET_SHORT();
+ *cur = FT_NEXT_SHORT(p);
/* We fill up the missing left side bearings with the */
/* last valid value. Since this will occur for buggy CJK */
@@ -313,7 +316,7 @@
/*************************************************************************/
/* */
/* <Function> */
- /* tt_face_get_metrics */
+ /* tt_face_get_metrics */
/* */
/* <Description> */
/* Returns the horizontal or vertical metrics in font units for a */