4 * Copyright (C) 2011-2012 by Werner Lemberg.
6 * This file is part of the ttfautohint library, and may only be used,
7 * modified, and distributed under the terms given in `COPYING'. By
8 * continuing to use, modify, or distribute this file you indicate that you
9 * have read `COPYING' and understand and accept it fully.
11 * The file `COPYING' mentioned in the previous paragraph is distributed
12 * with the ttfautohint library.
20 TA_sfnt_build_loca_table(SFNT
* sfnt
,
23 SFNT_Table
* loca_table
= &font
->tables
[sfnt
->loca_idx
];
24 SFNT_Table
* glyf_table
= &font
->tables
[sfnt
->glyf_idx
];
25 SFNT_Table
* head_table
= &font
->tables
[sfnt
->head_idx
];
27 glyf_Data
* data
= (glyf_Data
*)glyf_table
->data
;
37 if (loca_table
->processed
)
40 /* get largest offset */
44 for (i
= 0; i
< data
->num_glyphs
; i
++, glyph
++)
46 /* glyph records should have offsets which are multiples of 4 */
47 offset
= (offset
+ 3) & ~3;
48 offset
+= glyph
->len1
+ glyph
->len2
+ glyph
->ins_len
;
49 /* add two bytes for the instructionLength field */
50 if (glyph
->len2
|| glyph
->ins_len
)
54 if (offset
> 0xFFFF * 2)
62 loca_table
->len
= (data
->num_glyphs
+ 1) * 4;
63 buf_new
= (FT_Byte
*)realloc(loca_table
->buf
, loca_table
->len
);
65 return FT_Err_Out_Of_Memory
;
67 loca_table
->buf
= buf_new
;
73 for (i
= 0; i
< data
->num_glyphs
; i
++, glyph
++)
75 offset
= (offset
+ 3) & ~3;
77 *(p
++) = BYTE1(offset
);
78 *(p
++) = BYTE2(offset
);
79 *(p
++) = BYTE3(offset
);
80 *(p
++) = BYTE4(offset
);
82 offset
+= glyph
->len1
+ glyph
->len2
+ glyph
->ins_len
;
83 if (glyph
->len2
|| glyph
->ins_len
)
87 /* last element holds the size of the `glyf' table */
88 *(p
++) = BYTE1(offset
);
89 *(p
++) = BYTE2(offset
);
90 *(p
++) = BYTE3(offset
);
91 *(p
++) = BYTE4(offset
);
95 loca_table
->len
= (data
->num_glyphs
+ 1) * 2;
96 buf_new
= (FT_Byte
*)realloc(loca_table
->buf
,
97 (loca_table
->len
+ 3) & ~3);
99 return FT_Err_Out_Of_Memory
;
101 loca_table
->buf
= buf_new
;
105 glyph
= data
->glyphs
;
107 for (i
= 0; i
< data
->num_glyphs
; i
++, glyph
++)
109 offset
= (offset
+ 1) & ~1;
111 *(p
++) = HIGH(offset
);
112 *(p
++) = LOW(offset
);
114 offset
+= (glyph
->len1
+ glyph
->len2
+ glyph
->ins_len
+ 1) >> 1;
115 if (glyph
->len2
|| glyph
->ins_len
)
119 /* last element holds the size of the `glyf' table */
120 *(p
++) = HIGH(offset
);
121 *(p
++) = LOW(offset
);
123 /* pad `loca' table to make its length a multiple of 4 */
124 if (loca_table
->len
% 4 == 2)
131 loca_table
->checksum
= TA_table_compute_checksum(loca_table
->buf
,
133 loca_table
->processed
= 1;
135 head_table
->buf
[LOCA_FORMAT_OFFSET
] = loca_format
;
140 /* end of taloca.c */