+ objtext(cmap, "<</Type/CMap\n/CMapName/");
+ objtext(cmap, fe->name);
+ objtext(cmap, "\n/CIDSystemInfo<</Registry(Adobe)"
+ "/Ordering(Identity)/Supplement 0>>\n");
+ objstream(cmap, "%!PS-Adobe-3.0 Resource-CMap\n"
+ "%%DocumentNeededResources: procset CIDInit\n"
+ "%%IncludeResource: procset CIDInit\n"
+ "%%BeginResource: CMap ");
+ objstream(cmap, fe->name);
+ objstream(cmap, "\n%%Title (");
+ objstream(cmap, fe->name);
+ objstream(cmap, " Adobe Identity 0)\n%%Version: 1\n%%EndComments\n");
+ objstream(cmap, "/CIDInit/ProcSet findresource begin\n");
+ objstream(cmap, "12 dict begin begincmap\n");
+ objstream(cmap, "/CIDSystemInfo 3 dict dup begin\n"
+ "/Registry(Adobe)def/Ordering(Identity)def"
+ "/Supplement 0 def end def\n");
+ objstream(cmap, "/CMapName/");
+ objstream(cmap, fe->name);
+ objstream(cmap, " def/CMapType 0 def/WMode 0 def\n");
+ objstream(cmap, "1 begincodespacerange<00><FF>"
+ "endcodespacerange\n");
+ start = -1; nranges = nchars = 0;
+ for (i = 0; i < 256; i++) {
+ unsigned idx;
+
+ ranges[i] = 0;
+ if (fe->vector[i] == NOGLYPH)
+ continue;
+ idx = sfnt_glyphtoindex(fe->font->info->fontfile,
+ fe->vector[i]);
+ if (start >= 0 && idx - startidx == (unsigned)(i - start)) {
+ if (ranges[start] == 1) {
+ nranges++; nchars--;
+ }
+ ranges[start] = i - start + 1;
+ } else {
+ ranges[i] = 1;
+ start = i;
+ startidx = idx;
+ nchars++;
+ }
+ }
+ i = 0;
+ while (nranges) {
+ unsigned blk = nranges > 100 ? 100 : nranges;
+ nranges -= blk;
+ sprintf(buf, "%u ", blk);
+ objstream(cmap, buf);
+ objstream(cmap, "begincidrange\n");
+ while (blk) {
+ if (ranges[i] > 1) {
+ sprintf(buf, "<%02X>", i);
+ objstream(cmap, buf);
+ sprintf(buf, "<%02X>", i + ranges[i] - 1);
+ objstream(cmap, buf);
+ sprintf(buf, "%hu\n",
+ sfnt_glyphtoindex(fe->font->info->fontfile,
+ fe->vector[i]));
+ objstream(cmap, buf);
+ blk--;
+ }
+ i++;
+ }
+ objstream(cmap, "endcidrange\n");
+ }
+ i = 0;
+ while (nchars) {
+ unsigned blk = nchars > 100 ? 100 : nchars;
+ nchars -= blk;
+ sprintf(buf, "%u ", blk);
+ objstream(cmap, buf);
+ objstream(cmap, "begincidchar\n");
+ while (blk) {
+ if (ranges[i] == 1) {
+ sprintf(buf, "<%02X>", i);
+ objstream(cmap, buf);
+ sprintf(buf, "%hu\n",
+ sfnt_glyphtoindex(fe->font->info->fontfile,
+ fe->vector[i]));
+ objstream(cmap, buf);
+ blk--;
+ }
+ i++;
+ }
+ objstream(cmap, "endcidchar\n");
+ }
+ objstream(cmap, "endcmap CMapName currentdict /CMap "
+ "defineresource pop end end\n%%EndResource\n%%EOF\n");
+