+ int cur_chunk_idx = 0;
+ for (size_t j = 0; j < s; j++)
+ {
+ if (l >= chunks[cur_chunk_idx])
+ {
+ lily_cookie_fprintf (out, "\n"
+ " 00>\n"
+ " <");
+ l = 0;
+ cur_chunk_idx++;
+ }
+
+ if (l % 31 == 0)
+ lily_cookie_fprintf (out, "\n"
+ " ");
+
+ /* lily_cookie_fprintf (out,"%02X",(int)buffer[j]) is too slow */
+ lily_cookie_putc (xdigits[(buffer[j] & 0xF0) >> 4], out);
+ lily_cookie_putc (xdigits[buffer[j] & 0x0F], out);
+
+ l++;
+ }
+
+ /* pad to four-byte boundary */
+ while ((s++) % 4 != 0)
+ lily_cookie_fprintf (out, "00");
+
+ lily_cookie_fprintf (out, "\n"
+ " 00\n"
+ " >");
+}
+
+static void
+print_body (void *out, FT_Face face)
+{
+ FT_UInt idx = 0;
+ FT_ULong head_length = 0, loca_length = 0;
+ FT_ULong tag, length;
+ vector<FT_ULong> lengths, tags;
+
+ /*
+ we must build our own TTF header -- the original font
+ might be a TTC where tables are not contiguous, or the font
+ contains tables which aren't indexed at all
+ */
+ while (FT_Sfnt_Table_Info (face, idx, &tag, &length)
+ != FT_Err_Table_Missing)
+ {
+ lengths.push_back (length);
+ tags.push_back (tag);
+ if (tag == head_tag)
+ head_length = length;
+ else if (tag == loca_tag)
+ loca_length = length;
+ idx++;
+ }
+
+ FT_ULong hlength = 12 + 16 * idx;
+
+ unsigned char *hbuf = new unsigned char[hlength];
+ unsigned char *p;
+
+ hbuf[0] = 0x00; /* version */
+ hbuf[1] = 0x01;
+ hbuf[2] = 0x00;
+ hbuf[3] = 0x00;
+ hbuf[4] = (unsigned char) ((idx & 0xFF00) >> 8); /* numTables */
+ hbuf[5] = idx & 0x00FF;
+
+ FT_UInt searchRange, entrySelector, rangeShift;
+ FT_UInt i, j;
+ for (i = 1, j = 2; j <= idx; i++, j <<= 1)
+ ;
+ entrySelector = i - 1;
+ searchRange = 0x10 << entrySelector;
+ rangeShift = (idx << 4) - searchRange;
+
+ hbuf[6] = (unsigned char) ((searchRange & 0xFF00) >> 8);
+ hbuf[7] = searchRange & 0x00FF;
+ hbuf[8] = (unsigned char) ((entrySelector & 0xFF00) >> 8);
+ hbuf[9] = entrySelector & 0x00FF;
+ hbuf[10] = (unsigned char) ((rangeShift & 0xFF00) >> 8);
+ hbuf[11] = rangeShift & 0x00FF;
+
+ p = &hbuf[12];
+
+ FT_ULong checksum, font_checksum = 0;
+
+ FT_ULong offset = hlength; /* first table offset */