r22142 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Thu Aug 24 19:28:57 UTC 2017
Author: jghali
Date: Thu Aug 24 19:28:57 2017
New Revision: 22142
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22142
Log:
#14960 related: generate PDF ToUnicode map also for Type3 fonts
Modified:
trunk/Scribus/scribus/pdflib_core.cpp
Modified: trunk/Scribus/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22142&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp (original)
+++ trunk/Scribus/scribus/pdflib_core.cpp Thu Aug 24 19:28:57 2017
@@ -1459,13 +1459,20 @@
double miny = std::numeric_limits<double>::max();
double maxx = -std::numeric_limits<double>::max();
double maxy = -std::numeric_limits<double>::max();
+
QList<uint> glyphWidths;
QList<QByteArray> charProcs;
+ QStringList toUnicodeMaps;
+ QList<int> toUnicodeMapsCount;
+ QString toUnicodeMap = "";
+ int toUnicodeMapCounter = 0;
QByteArray encoding = "<< /Type /Encoding\n/Differences [ 0\n";
QByteArray fon;
QMap<uint, uint> glyphMapping;
+
ScFace::FaceEncoding gl;
face.glyphNames(gl);
+
QMap<uint,FPointArray>::ConstIterator ig;
for (ig = RealGlyphs.cbegin(); ig != RealGlyphs.cend(); ++ig)
{
@@ -1517,6 +1524,7 @@
maxx = qMax(maxx, np1.x());
maxy = qMax(maxy, np1.y());
glyphWidths.append(qRound(np1.x()));
+
PdfId charProcObject = writer.newObject();
charProcs.append(Pdf::toName(gl[ig.key()].second)+" "+Pdf::toPdf(charProcObject)+" 0 R\n");
encoding += Pdf::toName(gl[ig.key()].second)+" ";
@@ -1529,6 +1537,20 @@
PutDoc("\n/Filter /FlateDecode");
PutDoc("\n>>\nstream\n"+EncStream(fon, charProcObject)+"\nendstream");
writer.endObj(charProcObject);
+
+ QString tmp, tmp2;
+ tmp.sprintf("%02X", glyphCount);
+ tmp2.sprintf("%04X", gl[ig.key()].first);
+ toUnicodeMap += "<" + Pdf::toAscii(tmp) + "> <" + Pdf::toAscii(tmp2) + ">\n";
+ toUnicodeMapCounter++;
+ if (toUnicodeMapCounter == 100)
+ {
+ toUnicodeMaps.append(toUnicodeMap);
+ toUnicodeMapsCount.append(toUnicodeMapCounter);
+ toUnicodeMap = "";
+ toUnicodeMapCounter = 0;
+ }
+
glyphCount++;
int glyphsLeft = RealGlyphs.count() - SubFonts * 256;
if ((glyphCount > 255) || (glyphCount == glyphsLeft))
@@ -1557,6 +1579,40 @@
PutDoc("]\n");
PutDoc(">>");
writer.endObj(fontEncoding);
+
+ if (toUnicodeMapCounter != 0)
+ {
+ toUnicodeMaps.append(toUnicodeMap);
+ toUnicodeMapsCount.append(toUnicodeMapCounter);
+ }
+
+ QByteArray toUnicodeMapStream = "";
+ toUnicodeMapStream += "/CIDInit /ProcSet findresource begin\n";
+ toUnicodeMapStream += "12 dict begin\n";
+ toUnicodeMapStream += "begincmap\n";
+ toUnicodeMapStream += "/CIDSystemInfo <<\n";
+ toUnicodeMapStream += "/Registry (Adobe)\n";
+ toUnicodeMapStream += "/Ordering (UCS)\n";
+ toUnicodeMapStream += "/Supplement 0\n";
+ toUnicodeMapStream += ">> def\n";
+ toUnicodeMapStream += "/CMapName /Adobe-Identity-UCS def\n";
+ toUnicodeMapStream += "/CMapType 2 def\n";
+ toUnicodeMapStream += "1 begincodespacerange\n";
+ toUnicodeMapStream += "<0000> <FFFF>\n";
+ toUnicodeMapStream += "endcodespacerange\n";
+ for (int uniC = 0; uniC < toUnicodeMaps.count(); uniC++)
+ {
+ toUnicodeMapStream += Pdf::toPdf(toUnicodeMapsCount[uniC]);
+ toUnicodeMapStream += " beginbfchar\n";
+ toUnicodeMapStream += toUnicodeMaps[uniC];
+ toUnicodeMapStream += "endbfchar\n";
+ }
+ toUnicodeMapStream += "endcmap\n";
+ toUnicodeMapStream += "CMapName currentdict /CMap defineresource pop\n";
+ toUnicodeMapStream += "end\n";
+ toUnicodeMapStream += "end\n";
+ PdfId fontToUnicode = WritePDFStream(toUnicodeMapStream);
+
PdfId font3Object = writer.newObject();
writer.startObj(font3Object);
PutDoc("<<\n/Type /Font\n/Subtype /Type3\n");
@@ -1568,12 +1624,16 @@
PutDoc("/FontBBox ["+Pdf::toPdf(qRound(minx))+" "+Pdf::toPdf(qRound(miny))+" "+Pdf::toPdf(qRound(maxx))+ " "+Pdf::toPdf(qRound(maxy))+"]\n");
PutDoc("/FontMatrix [0.001 0 0 0.001 0 0]\n");
PutDoc("/Encoding "+Pdf::toPdf(fontEncoding)+" 0 R\n");
+ PutDoc("/ToUnicode " + Pdf::toPdf(fontToUnicode) + " 0 R\n");
PutDoc(">>");
writer.endObj(font3Object);
pageData.FObjects[name+"S"+Pdf::toPdf(SubFonts)] = font3Object;
charProcs.clear();
glyphWidths.clear();
- // glyphMapping.clear();
+ toUnicodeMaps.clear();
+ toUnicodeMapsCount.clear();
+ toUnicodeMap.clear();
+ toUnicodeMapCounter = 0;
glyphCount = 0;
++SubFonts;
minx = std::numeric_limits<double>::max();
More information about the scribus-commit
mailing list