PdfDictionary font,
PdfDictionary cidFont
)
{
// CMap [PDF:1.6:5.6.4].
Buffer cmapBuffer = new Buffer();
cmapBuffer.append(
"%!PS-Adobe-3.0 Resource-CMap\n"
+ "%%DocumentNeededResources: ProcSet (CIDInit)\n"
+ "%%IncludeResource: ProcSet (CIDInit)\n"
+ "%%BeginResource: CMap (Adobe-Identity-UCS)\n"
+ "%%Title: (Adobe-Identity-UCS Adobe Identity 0)\n"
+ "%%Version: 1\n"
+ "%%EndComments\n"
+ "/CIDInit /ProcSet findresource begin\n"
+ "12 dict begin\n"
+ "begincmap\n"
+ "/CIDSystemInfo\n"
+ "3 dict dup begin\n"
+ "/Registry (Adobe) def\n"
+ "/Ordering (Identity) def\n"
+ "/Supplement 0 def\n"
+ "end def\n"
+ "/CMapName /Adobe-Identity-UCS def\n"
+ "/CMapVersion 1 def\n"
+ "/CMapType 0 def\n"
+ "/WMode 0 def\n"
+ "2 begincodespacerange\n"
+ "<20> <20>\n"
+ "<0000> <19FF>\n"
+ "endcodespacerange\n"
+ glyphIndexes.size() + " begincidchar\n"
);
// ToUnicode [PDF:1.6:5.9.2].
Buffer toUnicodeBuffer = new Buffer();
toUnicodeBuffer.append(
"/CIDInit /ProcSet findresource begin\n"
+ "12 dict begin\n"
+ "begincmap\n"
+ "/CIDSystemInfo\n"
+ "<< /Registry (Adobe)\n"
+ "/Ordering (UCS)\n"
+ "/Supplement 0\n"
+ ">> def\n"
+ "/CMapName /Adobe-Identity-UCS def\n"
+ "/CMapVersion 10.001 def\n"
+ "/CMapType 2 def\n"
+ "2 begincodespacerange\n"
+ "<20> <20>\n"
+ "<0000> <19FF>\n"
+ "endcodespacerange\n"
+ glyphIndexes.size() + " beginbfchar\n"
);
// CIDToGIDMap [PDF:1.6:5.6.3].
Buffer gIdBuffer = new Buffer();
gIdBuffer.append((byte)0);
gIdBuffer.append((byte)0);
int code = 0;
codes = new BiMap<ByteArray,Integer>(glyphIndexes.size());
PdfArray widthsObject = new PdfArray(glyphWidths.size());
for(Map.Entry<Integer,Integer> glyphIndexEntry : glyphIndexes.entrySet())
{
// Character code (codepoint to unicode) entry.
code++;
byte[] charCode = (glyphIndexEntry.getKey() == 32
? new byte[]{32}
: new byte[]
{
(byte)((code >> 8) & 0xFF),
(byte)(code & 0xFF)
});
codes.put(new ByteArray(charCode),glyphIndexEntry.getKey());
// CMap entry.
cmapBuffer.append("<");
toUnicodeBuffer.append("<");
for(int charCodeBytesIndex = 0,
charCodeBytesLength = charCode.length;
charCodeBytesIndex < charCodeBytesLength;
charCodeBytesIndex++
)
{
String hex = Integer.toHexString((int)charCode[charCodeBytesIndex]);
//TODO:improve hex padding!!!
if(hex.length() == 1)
{hex = "0" + hex;}
else
{hex = hex.substring(hex.length()-2,hex.length());}
cmapBuffer.append(hex);
toUnicodeBuffer.append(hex);
}
cmapBuffer.append("> " + code + "\n");
toUnicodeBuffer.append("> <" + getHex(glyphIndexEntry.getKey()) + ">\n");
// CID-to-GID entry.
int glyphIndex = glyphIndexEntry.getValue();
gIdBuffer.append((byte)((glyphIndex >> 8) & 0xFF));
gIdBuffer.append((byte)(glyphIndex & 0xFF));
// Width.
int width;
try
{width = glyphWidths.get(glyphIndex);if(width>1000){width=1000;}}