r20112 by jghali - fix use of space instead of tabs for indentation
scribus-commit
scribus-commit at lists.scribus.net
Wed May 20 22:39:10 UTC 2015
Author: jghali
Date: Wed May 20 22:39:10 2015
New Revision: 20112
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20112
Log:
fix use of space instead of tabs for indentation
Modified:
trunk/Scribus/scribus/pdflib_core.cpp
trunk/Scribus/scribus/pdflib_core.h
trunk/Scribus/scribus/pdfwriter.cpp
trunk/Scribus/scribus/pdfwriter.h
Modified: trunk/Scribus/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20112&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp (original)
+++ trunk/Scribus/scribus/pdflib_core.cpp Wed May 20 22:39:10 2015
@@ -175,7 +175,7 @@
double v = c;
if (fabs(c) < 0.0000001)
v = 0.0;
- return QByteArray::number(v, 'f', 5);
+ return QByteArray::number(v, 'f', 5);
};
bool PDFLibCore::PDF_IsPDFX()
@@ -417,15 +417,15 @@
return QByteArray();
else if (!Options.Encrypt)
return in;
- else
- return writer.encryptBytes(in, ObjNum);
+ else
+ return writer.encryptBytes(in, ObjNum);
// rc4_context_t rc4;
// QByteArray tmp(in);
// QByteArray us(tmp.length(), ' ');
// QByteArray ou(tmp.length(), ' ');
// for (int a = 0; a < tmp.length(); ++a)
-// us[a] = (tmp.at(a));
-// QByteArray step1 = writer.ComputeRC4Key(ObjNum);
+// us[a] = (tmp.at(a));
+// QByteArray step1 = writer.ComputeRC4Key(ObjNum);
// rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16));
// rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), reinterpret_cast<uchar*>(ou.data()), tmp.length());
// QString uk = "";
@@ -442,9 +442,9 @@
if (!Options.Encrypt)
{
//tmp = "(" + PDFEncode(in) + ")";
- return Pdf::toLiteralString(in);
- }
-
+ return Pdf::toLiteralString(in);
+ }
+
// rc4_context_t rc4;
// QByteArray us(in.length(), ' ');
// QByteArray ou(in.length(), ' ');
@@ -456,8 +456,8 @@
// QString uk = "";
// for (int cl = 0; cl < in.length(); ++cl)
// uk += QChar(ou[cl]);
-
- return Pdf::toHexString(writer.encryptBytes(in, ObjNum));
+
+ return Pdf::toHexString(writer.encryptBytes(in, ObjNum));
}
QByteArray PDFLibCore::EncStringUTF16(const QString & in, PdfId ObjNum)
@@ -466,14 +466,14 @@
return "<>";
if (!Options.Encrypt)
{
- QByteArray us = Pdf::toUTF16(in);
+ QByteArray us = Pdf::toUTF16(in);
// QString uk = "";
// for (int cl = 0; cl < us.size(); ++cl)
// uk += QChar(us[cl]);
return Pdf::toHexString(us);
}
// rc4_context_t rc4;
- QByteArray us = Pdf::toUTF16(in);
+ QByteArray us = Pdf::toUTF16(in);
// QByteArray ou(us.size(), ' ');
// QByteArray step1 = writer.ComputeRC4Key(ObjNum);
// rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16));
@@ -498,7 +498,7 @@
succeed = rc4Encode->writeData(in.data(), in.size());
succeed &= rc4Encode->closeFilter();
}
- delete rc4Encode;
+ delete rc4Encode;
}
else
writer.write(in);
@@ -510,25 +510,25 @@
bool fromCmyk, succeed = false;
int bytesWritten = 0;
- ScStreamFilter* rc4Encode = writer.openStreamFilter(Options.Encrypt, ObjNum);
- if (rc4Encode->openFilter())
- {
- switch (format)
- {
- case ColorSpaceMonochrome :
- fromCmyk = !Options.UseRGB && !Options.isGrayscale && !(doc.HasCMS && Options.UseProfiles2);
- succeed = image.writeMonochromeDataToFilter(rc4Encode, fromCmyk); break;
- case ColorSpaceGray :
- succeed = image.writeGrayDataToFilter(rc4Encode, precal); break;
- case ColorSpaceCMYK :
- succeed = image.writeCMYKDataToFilter(rc4Encode); break;
- default :
- succeed = image.writeRGBDataToFilter(rc4Encode); break;
- }
- succeed &= rc4Encode->closeFilter();
- bytesWritten = rc4Encode->writtenToStream();
- delete rc4Encode;
- }
+ ScStreamFilter* rc4Encode = writer.openStreamFilter(Options.Encrypt, ObjNum);
+ if (rc4Encode->openFilter())
+ {
+ switch (format)
+ {
+ case ColorSpaceMonochrome :
+ fromCmyk = !Options.UseRGB && !Options.isGrayscale && !(doc.HasCMS && Options.UseProfiles2);
+ succeed = image.writeMonochromeDataToFilter(rc4Encode, fromCmyk); break;
+ case ColorSpaceGray :
+ succeed = image.writeGrayDataToFilter(rc4Encode, precal); break;
+ case ColorSpaceCMYK :
+ succeed = image.writeCMYKDataToFilter(rc4Encode); break;
+ default :
+ succeed = image.writeRGBDataToFilter(rc4Encode); break;
+ }
+ succeed &= rc4Encode->closeFilter();
+ bytesWritten = rc4Encode->writtenToStream();
+ delete rc4Encode;
+ }
return (succeed ? bytesWritten : 0);
}
@@ -555,14 +555,14 @@
if (Options.Encrypt)
{
succeed = false;
- ScStreamFilter* rc4Encode = writer.openStreamFilter(true, ObjNum);
- if (rc4Encode->openFilter())
+ ScStreamFilter* rc4Encode = writer.openStreamFilter(true, ObjNum);
+ if (rc4Encode->openFilter())
{
succeed = copyFileToFilter(jpgFileName, *rc4Encode);
succeed &= rc4Encode->closeFilter();
bytesWritten = rc4Encode->writtenToStream();
}
- delete rc4Encode;
+ delete rc4Encode;
}
else
{
@@ -577,40 +577,40 @@
int PDFLibCore::WriteFlateImageToStream(ScImage& image, PdfId ObjNum, ColorSpaceEnum format, bool precal)
{
- bool fromCmyk, succeed = false;
- int bytesWritten = 0;
- ScStreamFilter* rc4Encode = writer.openStreamFilter(Options.Encrypt, ObjNum);
- ScFlateEncodeFilter flateEncode(rc4Encode);
- if (flateEncode.openFilter())
- {
- switch (format)
- {
- case ColorSpaceMonochrome :
- fromCmyk = !Options.UseRGB && !Options.isGrayscale && !(doc.HasCMS && Options.UseProfiles2);
- succeed = image.writeMonochromeDataToFilter(&flateEncode, fromCmyk); break;
- case ColorSpaceGray :
- succeed = image.writeGrayDataToFilter(&flateEncode, precal); break;
- case ColorSpaceCMYK :
- succeed = image.writeCMYKDataToFilter(&flateEncode); break;
- default :
- succeed = image.writeRGBDataToFilter(&flateEncode); break;
- }
- succeed &= flateEncode.closeFilter();
- bytesWritten = flateEncode.writtenToStream();
- }
- delete rc4Encode;
- return (succeed ? bytesWritten : 0);
+ bool fromCmyk, succeed = false;
+ int bytesWritten = 0;
+ ScStreamFilter* rc4Encode = writer.openStreamFilter(Options.Encrypt, ObjNum);
+ ScFlateEncodeFilter flateEncode(rc4Encode);
+ if (flateEncode.openFilter())
+ {
+ switch (format)
+ {
+ case ColorSpaceMonochrome :
+ fromCmyk = !Options.UseRGB && !Options.isGrayscale && !(doc.HasCMS && Options.UseProfiles2);
+ succeed = image.writeMonochromeDataToFilter(&flateEncode, fromCmyk); break;
+ case ColorSpaceGray :
+ succeed = image.writeGrayDataToFilter(&flateEncode, precal); break;
+ case ColorSpaceCMYK :
+ succeed = image.writeCMYKDataToFilter(&flateEncode); break;
+ default :
+ succeed = image.writeRGBDataToFilter(&flateEncode); break;
+ }
+ succeed &= flateEncode.closeFilter();
+ bytesWritten = flateEncode.writtenToStream();
+ }
+ delete rc4Encode;
+ return (succeed ? bytesWritten : 0);
}
bool PDFLibCore::PDF_Begin_Doc(const QString& fn, SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts, BookMView* vi)
{
- if (!writer.open(fn))
- return false;
-
- QFileInfo fiBase(fn);
- QString baseDir = fiBase.absolutePath();
+ if (!writer.open(fn))
+ return false;
+
+ QFileInfo fiBase(fn);
+ QString baseDir = fiBase.absolutePath();
// QString tmp;
// QFileInfo fd;
@@ -620,9 +620,9 @@
BookMinUse = false;
UsedFontsP.clear();
UsedFontsF.clear();
-
- writer.writeHeader(Options.Version);
-
+
+ writer.writeHeader(Options.Version);
+
// if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers))
// ObjCounter = 10;
// else
@@ -646,39 +646,39 @@
// ObjCounter++;
// PutDoc("%\xc7\xec\x8f\xa2\n");
- PDF_Begin_Catalog();
- PDF_Begin_MetadataAndEncrypt();
- PDF_Begin_WriteUsedFonts(AllFonts, PDF_Begin_FindUsedFonts(AllFonts, DocFonts));
- PDF_Begin_Colors();
- PDF_Begin_Layers();
-
- return true;
+ PDF_Begin_Catalog();
+ PDF_Begin_MetadataAndEncrypt();
+ PDF_Begin_WriteUsedFonts(AllFonts, PDF_Begin_FindUsedFonts(AllFonts, DocFonts));
+ PDF_Begin_Colors();
+ PDF_Begin_Layers();
+
+ return true;
}
void PDFLibCore::PDF_Begin_Catalog()
{
- writer.startObj(writer.CatalogObj);
- PutDoc("<<\n/Type /Catalog");
- PutDoc("\n/Outlines " + Pdf::toObjRef(writer.OutlinesObj) +
- "\n/Pages " + Pdf::toObjRef(writer.PagesObj) +
- "\n/Dests " + Pdf::toObjRef(writer.DestsObj) +
- "\n/AcroForm " + Pdf::toObjRef(writer.AcroFormObj) +
- "\n/Names "+ Pdf::toObjRef(writer.NamesObj) +
- "\n/Threads " + Pdf::toObjRef(writer.ThreadsObj) +
- "\n");
+ writer.startObj(writer.CatalogObj);
+ PutDoc("<<\n/Type /Catalog");
+ PutDoc("\n/Outlines " + Pdf::toObjRef(writer.OutlinesObj) +
+ "\n/Pages " + Pdf::toObjRef(writer.PagesObj) +
+ "\n/Dests " + Pdf::toObjRef(writer.DestsObj) +
+ "\n/AcroForm " + Pdf::toObjRef(writer.AcroFormObj) +
+ "\n/Names "+ Pdf::toObjRef(writer.NamesObj) +
+ "\n/Threads " + Pdf::toObjRef(writer.ThreadsObj) +
+ "\n");
if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers))
- {
- writer.OCPropertiesObj = writer.newObject();
+ {
+ writer.OCPropertiesObj = writer.newObject();
PutDoc("/OCProperties " + Pdf::toObjRef(writer.OCPropertiesObj) + "\n");
- }
- if (PDF_IsPDFX())
- {
- writer.OutputIntentObj = writer.newObject();
- PutDoc("/OutputIntents [ " + Pdf::toObjRef(writer.OutputIntentObj) + " ]\n");
- }
- if ((Options.Version == PDFOptions::PDFVersion_X4))
- {
- writer.MetaDataObj = writer.newObject();
+ }
+ if (PDF_IsPDFX())
+ {
+ writer.OutputIntentObj = writer.newObject();
+ PutDoc("/OutputIntents [ " + Pdf::toObjRef(writer.OutputIntentObj) + " ]\n");
+ }
+ if ((Options.Version == PDFOptions::PDFVersion_X4))
+ {
+ writer.MetaDataObj = writer.newObject();
PutDoc("/Metadata "+ Pdf::toObjRef(writer.MetaDataObj) + "\n");
}
PutDoc("/PageLayout ");
@@ -707,11 +707,11 @@
PutDoc("/PageMode /UseOC\n");
if (!Options.openAction.isEmpty())
{
- PutDoc("/OpenAction << /S /JavaScript /JS (this."+Pdf::toPdfDocEncoding(Options.openAction)+"\\(\\)) >>\n");
- }
- QString tmp;
+ PutDoc("/OpenAction << /S /JavaScript /JS (this."+Pdf::toPdfDocEncoding(Options.openAction)+"\\(\\)) >>\n");
+ }
+ QString tmp;
QDateTime dt = QDateTime::currentDateTime().toUTC();
- Datum = Pdf::toDateString(dt);
+ Datum = Pdf::toDateString(dt);
// "D:";
// tmp.sprintf("%4d", d.year());
// tmp.replace(QRegExp(" "), "0");
@@ -767,8 +767,8 @@
PutDoc("/HideMenubar true\n");
if (Options.fitWindow)
PutDoc("/FitWindow true\n");
- PutDoc(" >>\n>>");
- writer.endObj(writer.CatalogObj);
+ PutDoc(" >>\n>>");
+ writer.endObj(writer.CatalogObj);
}
void PDFLibCore::PDF_Begin_MetadataAndEncrypt()
@@ -780,13 +780,13 @@
IDg += doc.documentInfo().title();
IDg += doc.documentInfo().author();
IDg += "/False";
- writer.setFileId(Pdf::toPdfDocEncoding(IDg));
+ writer.setFileId(Pdf::toPdfDocEncoding(IDg));
if (Options.Encrypt)
{
- writer.setEncryption((Options.Version == PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_15), Pdf::toPdfDocEncoding(Options.PassOwner), Pdf::toPdfDocEncoding(Options.PassUser), Options.Permissions);
+ writer.setEncryption((Options.Version == PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_15), Pdf::toPdfDocEncoding(Options.PassOwner), Pdf::toPdfDocEncoding(Options.PassUser), Options.Permissions);
}
writer.startObj(writer.InfoObj);
- PutDoc("<<\n/Creator " + EncString(QByteArray("Scribus ") + VERSION, writer.InfoObj) + "\n");
+ PutDoc("<<\n/Creator " + EncString(QByteArray("Scribus ") + VERSION, writer.InfoObj) + "\n");
PutDoc("/Producer " + EncString(QByteArray("Scribus PDF Library ") + VERSION, writer.InfoObj) + "\n");
QString docTitle = doc.documentInfo().title();
if ((PDF_IsPDFX()) && (docTitle.isEmpty()))
@@ -807,12 +807,12 @@
PutDoc("/GTS_PDFXVersion (PDF/X-3:2002)\n");
if (Options.Version == PDFOptions::PDFVersion_X4)
PutDoc("/GTS_PDFXVersion (PDF/X-4)\n");
- PutDoc("/Trapped /False\n>>");
- writer.endObj(writer.InfoObj);
-
- // Encrypt
-
-// for (int t = 0; t < 6; ++t)
+ PutDoc("/Trapped /False\n>>");
+ writer.endObj(writer.InfoObj);
+
+ // Encrypt
+
+// for (int t = 0; t < 6; ++t)
// XRef.append(bytesWritten());
// if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers))
// XRef.append(bytesWritten());
@@ -828,8 +828,8 @@
// PutDoc( KeyLen > 5 ? "/R 3\n/V 2\n/Length 128\n" : "/R 2\n/V 1\n");
// PutDoc("/O "+Pdf::toHexString(ok)+"\n");
// PutDoc("/U "+Pdf::toHexString(uk)+"\n");
-// PutDoc("/P "+Pdf::toPdf(Options.Permissions)+"\n>>");
-// writer.endObj(writer.EncryptObj);
+// PutDoc("/P "+Pdf::toPdf(Options.Permissions)+"\n>>");
+// writer.endObj(writer.EncryptObj);
}
}
@@ -1063,942 +1063,942 @@
}
}
}
- return ReallyUsed;
+ return ReallyUsed;
}
static QByteArray sanitizeFontName(QString fn)
{
- return Pdf::toPdfDocEncoding(fn.replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ));
+ return Pdf::toPdfDocEncoding(fn.replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ));
}
static QList<Pdf::Resource> asColorSpace(QList<PdfICCD> iccCSlist)
{
- QList<Pdf::Resource> result;
- foreach (Pdf::Resource r, iccCSlist)
- {
- result.append(r);
- }
- return result;
+ QList<Pdf::Resource> result;
+ foreach (Pdf::Resource r, iccCSlist)
+ {
+ result.append(r);
+ }
+ return result;
}
static QList<Pdf::Resource> asColorSpace(QList<PdfSpotC> spotMapValues)
{
- QList<Pdf::Resource> result;
- foreach (Pdf::Resource r, spotMapValues)
- {
- result.append(r);
- }
- return result;
+ QList<Pdf::Resource> result;
+ foreach (Pdf::Resource r, spotMapValues)
+ {
+ result.append(r);
+ }
+ return result;
}
void PDFLibCore::PDF_WriteStandardFonts()
{
- int a = 0;
- QMap<QString, QString>::Iterator itStd;
- for (itStd = StdFonts.begin(); itStd != StdFonts.end(); ++itStd)
- {
- PdfId fontObject = writer.newObject();
- writer.startObj(fontObject);
- PutDoc("<<\n/Type /Font\n/Subtype /Type1\n");
- PutDoc("/Name /FoStd"+Pdf::toPdf(a)+"\n");
- PutDoc("/BaseFont "+Pdf::toPdfDocEncoding(itStd.key())+"\n");
- if (itStd.key() != "/ZapfDingbats")
- {
- PutDoc("/Encoding << \n");
- PutDoc("/Differences [ \n");
- PutDoc("24 /breve /caron /circumflex /dotaccent /hungarumlaut /ogonek /ring /tilde\n");
- PutDoc("39 /quotesingle 96 /grave 128 /bullet /dagger /daggerdbl /ellipsis /emdash /endash /florin /fraction /guilsinglleft /guilsinglright\n");
- PutDoc("/minus /perthousand /quotedblbase /quotedblleft /quotedblright /quoteleft /quoteright /quotesinglbase /trademark /fi /fl /Lslash /OE /Scaron\n");
- PutDoc("/Ydieresis /Zcaron /dotlessi /lslash /oe /scaron /zcaron 164 /currency 166 /brokenbar 168 /dieresis /copyright /ordfeminine 172 /logicalnot\n");
- PutDoc("/.notdef /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu 183 /periodcentered /cedilla /onesuperior /ordmasculine\n");
- PutDoc("188 /onequarter /onehalf /threequarters 192 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex\n");
- PutDoc("/Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash\n");
- PutDoc("/Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla\n");
- PutDoc("/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis\n");
- PutDoc("/divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis\n");
- PutDoc("] >>\n");
- }
- PutDoc(">>");
- writer.endObj(fontObject);
- pageData.FObjects["FoStd"+Pdf::toPdf(a)] = fontObject;
- itStd.value() = "FoStd"+Pdf::toPdf(a);
- a++;
- }
+ int a = 0;
+ QMap<QString, QString>::Iterator itStd;
+ for (itStd = StdFonts.begin(); itStd != StdFonts.end(); ++itStd)
+ {
+ PdfId fontObject = writer.newObject();
+ writer.startObj(fontObject);
+ PutDoc("<<\n/Type /Font\n/Subtype /Type1\n");
+ PutDoc("/Name /FoStd"+Pdf::toPdf(a)+"\n");
+ PutDoc("/BaseFont "+Pdf::toPdfDocEncoding(itStd.key())+"\n");
+ if (itStd.key() != "/ZapfDingbats")
+ {
+ PutDoc("/Encoding << \n");
+ PutDoc("/Differences [ \n");
+ PutDoc("24 /breve /caron /circumflex /dotaccent /hungarumlaut /ogonek /ring /tilde\n");
+ PutDoc("39 /quotesingle 96 /grave 128 /bullet /dagger /daggerdbl /ellipsis /emdash /endash /florin /fraction /guilsinglleft /guilsinglright\n");
+ PutDoc("/minus /perthousand /quotedblbase /quotedblleft /quotedblright /quoteleft /quoteright /quotesinglbase /trademark /fi /fl /Lslash /OE /Scaron\n");
+ PutDoc("/Ydieresis /Zcaron /dotlessi /lslash /oe /scaron /zcaron 164 /currency 166 /brokenbar 168 /dieresis /copyright /ordfeminine 172 /logicalnot\n");
+ PutDoc("/.notdef /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu 183 /periodcentered /cedilla /onesuperior /ordmasculine\n");
+ PutDoc("188 /onequarter /onehalf /threequarters 192 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex\n");
+ PutDoc("/Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash\n");
+ PutDoc("/Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla\n");
+ PutDoc("/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis\n");
+ PutDoc("/divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis\n");
+ PutDoc("] >>\n");
+ }
+ PutDoc(">>");
+ writer.endObj(fontObject);
+ pageData.FObjects["FoStd"+Pdf::toPdf(a)] = fontObject;
+ itStd.value() = "FoStd"+Pdf::toPdf(a);
+ a++;
+ }
}
PdfFont PDFLibCore::PDF_WriteType3Font(const QByteArray& name, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs)
{
- PdfFont result;
- result.name = Pdf::toName(name);
- result.method = Use_Type3;
- result.encoding = Encode_256;
-
- uint SubFonts = 0;
- int glyphCount = 0;
- double minx = std::numeric_limits<double>::max();
- 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;
- 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)
- {
- FPoint np, np1, np2;
- bool nPath = true;
- fon.resize(0);
- if (ig.value().size() > 3)
- {
- FPointArray gly = ig.value();
- QTransform mat;
- mat.scale(100.0, -100.0);
- gly.map(mat);
- gly.translate(0, 1000);
- for (int poi = 0; poi < gly.size()-3; poi += 4)
- {
- if (gly.isMarker(poi))
- {
- fon += "h\n";
- nPath = true;
- continue;
- }
- if (nPath)
- {
- np = gly.point(poi);
- fon += FToStr(np.x())+" "+FToStr(np.y())+" m\n";
- nPath = false;
- }
- np = gly.point(poi+1);
- np1 = gly.point(poi+3);
- np2 = gly.point(poi+2);
- fon += FToStr(np.x()) + " " + FToStr(np.y()) + " " + FToStr(np1.x()) + " " + FToStr(np1.y()) + " " + FToStr(np2.x()) + " " + FToStr(np2.y()) + " c\n";
- }
- fon += "h f*\n";
- np = getMinClipF(&gly);
- np1 = getMaxClipF(&gly);
- }
- else
- {
- fon = "h";
- np = FPoint(0, 0);
- np1 = FPoint(0, 0);
- }
- fon.prepend(Pdf::toPdf(qRound(np1.x())) + " 0 "+Pdf::toPdf(qRound(np.x()))+" "+Pdf::toPdf(qRound(np.y()))+" "+Pdf::toPdf(qRound(np1.x()))+ " "+Pdf::toPdf(qRound(np1.y()))+" d1\n");
- minx = qMin(minx, np.x());
- miny = qMin(miny, np.y());
- 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)+" ";
- glyphMapping.insert(ig.key(), glyphCount + SubFonts * 256);
- writer.startObj(charProcObject);
- if (Options.Compress)
- fon = CompressArray(fon);
- PutDoc("<< /Length "+Pdf::toPdf(fon.length()+1));
- if (Options.Compress)
- PutDoc("\n/Filter /FlateDecode");
- PutDoc("\n>>\nstream\n"+EncStream(fon, charProcObject)+"\nendstream");
- writer.endObj(charProcObject);
- glyphCount++;
- int glyphsLeft = RealGlyphs.count() - SubFonts * 256;
- if ((glyphCount > 255) || (glyphCount == glyphsLeft))
- {
- PdfId fontWidths = writer.newObject();
- writer.startObj(fontWidths);
- PutDoc("[ ");
- for (int ww = 0; ww < glyphWidths.count(); ++ww)
- {
- PutDoc(Pdf::toPdf(glyphWidths[ww])+" ");
- }
- PutDoc("]");
- writer.endObj(fontWidths);
- PdfId fontCharProcs = writer.newObject();
- writer.startObj(fontCharProcs);
- PutDoc("<<\n");
- for (int ww = 0; ww < charProcs.count(); ++ww)
- {
- PutDoc(charProcs[ww]);
- }
- PutDoc(">>");
- writer.endObj(fontCharProcs);
- PdfId fontEncoding = writer.newObject();
- writer.startObj(fontEncoding);
- PutDoc(encoding);
- PutDoc("]\n");
- PutDoc(">>");
- writer.endObj(fontEncoding);
- PdfId font3Object = writer.newObject();
- writer.startObj(font3Object);
- PutDoc("<<\n/Type /Font\n/Subtype /Type3\n");
- PutDoc("/Name /"+name+"S"+Pdf::toPdf(SubFonts)+"\n");
- PutDoc("/FirstChar 0\n");
- PutDoc("/LastChar "+Pdf::toPdf(glyphCount-1)+"\n");
- PutDoc("/Widths "+Pdf::toPdf(fontWidths)+" 0 R\n");
- PutDoc("/CharProcs "+Pdf::toPdf(fontCharProcs)+" 0 R\n");
- 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(">>");
- writer.endObj(font3Object);
- pageData.FObjects[name+"S"+Pdf::toPdf(SubFonts)] = font3Object;
- charProcs.clear();
- glyphWidths.clear();
- // glyphMapping.clear();
- glyphCount = 0;
- ++SubFonts;
- minx = std::numeric_limits<double>::max();
- miny = std::numeric_limits<double>::max();
- maxx = -std::numeric_limits<double>::max();
- maxy = -std::numeric_limits<double>::max();
- encoding = "<< /Type /Encoding\n/Differences [ 0\n";
- }
- }
- result.glyphmap = glyphMapping;
- return result;
+ PdfFont result;
+ result.name = Pdf::toName(name);
+ result.method = Use_Type3;
+ result.encoding = Encode_256;
+
+ uint SubFonts = 0;
+ int glyphCount = 0;
+ double minx = std::numeric_limits<double>::max();
+ 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;
+ 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)
+ {
+ FPoint np, np1, np2;
+ bool nPath = true;
+ fon.resize(0);
+ if (ig.value().size() > 3)
+ {
+ FPointArray gly = ig.value();
+ QTransform mat;
+ mat.scale(100.0, -100.0);
+ gly.map(mat);
+ gly.translate(0, 1000);
+ for (int poi = 0; poi < gly.size()-3; poi += 4)
+ {
+ if (gly.isMarker(poi))
+ {
+ fon += "h\n";
+ nPath = true;
+ continue;
+ }
+ if (nPath)
+ {
+ np = gly.point(poi);
+ fon += FToStr(np.x())+" "+FToStr(np.y())+" m\n";
+ nPath = false;
+ }
+ np = gly.point(poi+1);
+ np1 = gly.point(poi+3);
+ np2 = gly.point(poi+2);
+ fon += FToStr(np.x()) + " " + FToStr(np.y()) + " " + FToStr(np1.x()) + " " + FToStr(np1.y()) + " " + FToStr(np2.x()) + " " + FToStr(np2.y()) + " c\n";
+ }
+ fon += "h f*\n";
+ np = getMinClipF(&gly);
+ np1 = getMaxClipF(&gly);
+ }
+ else
+ {
+ fon = "h";
+ np = FPoint(0, 0);
+ np1 = FPoint(0, 0);
+ }
+ fon.prepend(Pdf::toPdf(qRound(np1.x())) + " 0 "+Pdf::toPdf(qRound(np.x()))+" "+Pdf::toPdf(qRound(np.y()))+" "+Pdf::toPdf(qRound(np1.x()))+ " "+Pdf::toPdf(qRound(np1.y()))+" d1\n");
+ minx = qMin(minx, np.x());
+ miny = qMin(miny, np.y());
+ 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)+" ";
+ glyphMapping.insert(ig.key(), glyphCount + SubFonts * 256);
+ writer.startObj(charProcObject);
+ if (Options.Compress)
+ fon = CompressArray(fon);
+ PutDoc("<< /Length "+Pdf::toPdf(fon.length()+1));
+ if (Options.Compress)
+ PutDoc("\n/Filter /FlateDecode");
+ PutDoc("\n>>\nstream\n"+EncStream(fon, charProcObject)+"\nendstream");
+ writer.endObj(charProcObject);
+ glyphCount++;
+ int glyphsLeft = RealGlyphs.count() - SubFonts * 256;
+ if ((glyphCount > 255) || (glyphCount == glyphsLeft))
+ {
+ PdfId fontWidths = writer.newObject();
+ writer.startObj(fontWidths);
+ PutDoc("[ ");
+ for (int ww = 0; ww < glyphWidths.count(); ++ww)
+ {
+ PutDoc(Pdf::toPdf(glyphWidths[ww])+" ");
+ }
+ PutDoc("]");
+ writer.endObj(fontWidths);
+ PdfId fontCharProcs = writer.newObject();
+ writer.startObj(fontCharProcs);
+ PutDoc("<<\n");
+ for (int ww = 0; ww < charProcs.count(); ++ww)
+ {
+ PutDoc(charProcs[ww]);
+ }
+ PutDoc(">>");
+ writer.endObj(fontCharProcs);
+ PdfId fontEncoding = writer.newObject();
+ writer.startObj(fontEncoding);
+ PutDoc(encoding);
+ PutDoc("]\n");
+ PutDoc(">>");
+ writer.endObj(fontEncoding);
+ PdfId font3Object = writer.newObject();
+ writer.startObj(font3Object);
+ PutDoc("<<\n/Type /Font\n/Subtype /Type3\n");
+ PutDoc("/Name /"+name+"S"+Pdf::toPdf(SubFonts)+"\n");
+ PutDoc("/FirstChar 0\n");
+ PutDoc("/LastChar "+Pdf::toPdf(glyphCount-1)+"\n");
+ PutDoc("/Widths "+Pdf::toPdf(fontWidths)+" 0 R\n");
+ PutDoc("/CharProcs "+Pdf::toPdf(fontCharProcs)+" 0 R\n");
+ 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(">>");
+ writer.endObj(font3Object);
+ pageData.FObjects[name+"S"+Pdf::toPdf(SubFonts)] = font3Object;
+ charProcs.clear();
+ glyphWidths.clear();
+ // glyphMapping.clear();
+ glyphCount = 0;
+ ++SubFonts;
+ minx = std::numeric_limits<double>::max();
+ miny = std::numeric_limits<double>::max();
+ maxx = -std::numeric_limits<double>::max();
+ maxy = -std::numeric_limits<double>::max();
+ encoding = "<< /Type /Encoding\n/Differences [ 0\n";
+ }
+ }
+ result.glyphmap = glyphMapping;
+ return result;
}
PdfFont PDFLibCore::PDF_WriteGlyphsAsXForms(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs)
{
- PdfFont result;
- result.name = Pdf::toName(fontName);
- result.method = Use_XForm;
- result.encoding = Encode_224;
-
- QByteArray fon;
- QMap<uint,FPointArray>::ConstIterator ig;
- for (ig = RealGlyphs.cbegin(); ig != RealGlyphs.cend(); ++ig)
- {
- FPoint np, np1, np2;
- bool nPath = true;
- fon.resize(0);
- if (ig.value().size() > 3)
- {
- FPointArray gly = ig.value();
- QTransform mat;
- mat.scale(0.1, 0.1);
- gly.map(mat);
- for (int poi = 0; poi < gly.size()-3; poi += 4)
- {
- if (gly.isMarker(poi))
- {
- fon += "h\n";
- nPath = true;
- continue;
- }
- if (nPath)
- {
- np = gly.point(poi);
- fon += FToStr(np.x())+" "+FToStr(-np.y())+" m\n";
- nPath = false;
- }
- np = gly.point(poi+1);
- np1 = gly.point(poi+3);
- np2 = gly.point(poi+2);
- fon += FToStr(np.x()) + " " + FToStr(-np.y()) + " " +
- FToStr(np1.x()) + " " + FToStr(-np1.y()) + " " +
- FToStr(np2.x()) + " " + FToStr(-np2.y()) + " c\n";
- }
- fon += "h f*\n";
- np = getMinClipF(&gly);
- np1 = getMaxClipF(&gly);
- }
- else
- {
- fon = "h";
- np = FPoint(0, 0);
- np1 = FPoint(0, 0);
- }
- PdfId fontGlyphXForm = writer.newObject();
- writer.startObj(fontGlyphXForm);
- PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1\n");
- PutDoc("/BBox [ "+FToStr(np.x())+" "+FToStr(-np.y())+" "+FToStr(np1.x())+ " "+FToStr(-np1.y())+" ]\n");
- PutDoc("/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n");
- PutDoc(">>\n");
- if (Options.Compress)
- fon = CompressArray(fon);
- PutDoc("/Length "+Pdf::toPdf(fon.length()+1));
- if (Options.Compress)
- PutDoc("\n/Filter /FlateDecode");
- PutDoc(" >>\nstream\n"+EncStream(fon, fontGlyphXForm)+"\nendstream");
- writer.endObj(fontGlyphXForm);
- pageData.XObjects[fontName + Pdf::toPdf(ig.key())] = fontGlyphXForm;
- }
- return result;
+ PdfFont result;
+ result.name = Pdf::toName(fontName);
+ result.method = Use_XForm;
+ result.encoding = Encode_224;
+
+ QByteArray fon;
+ QMap<uint,FPointArray>::ConstIterator ig;
+ for (ig = RealGlyphs.cbegin(); ig != RealGlyphs.cend(); ++ig)
+ {
+ FPoint np, np1, np2;
+ bool nPath = true;
+ fon.resize(0);
+ if (ig.value().size() > 3)
+ {
+ FPointArray gly = ig.value();
+ QTransform mat;
+ mat.scale(0.1, 0.1);
+ gly.map(mat);
+ for (int poi = 0; poi < gly.size()-3; poi += 4)
+ {
+ if (gly.isMarker(poi))
+ {
+ fon += "h\n";
+ nPath = true;
+ continue;
+ }
+ if (nPath)
+ {
+ np = gly.point(poi);
+ fon += FToStr(np.x())+" "+FToStr(-np.y())+" m\n";
+ nPath = false;
+ }
+ np = gly.point(poi+1);
+ np1 = gly.point(poi+3);
+ np2 = gly.point(poi+2);
+ fon += FToStr(np.x()) + " " + FToStr(-np.y()) + " " +
+ FToStr(np1.x()) + " " + FToStr(-np1.y()) + " " +
+ FToStr(np2.x()) + " " + FToStr(-np2.y()) + " c\n";
+ }
+ fon += "h f*\n";
+ np = getMinClipF(&gly);
+ np1 = getMaxClipF(&gly);
+ }
+ else
+ {
+ fon = "h";
+ np = FPoint(0, 0);
+ np1 = FPoint(0, 0);
+ }
+ PdfId fontGlyphXForm = writer.newObject();
+ writer.startObj(fontGlyphXForm);
+ PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1\n");
+ PutDoc("/BBox [ "+FToStr(np.x())+" "+FToStr(-np.y())+" "+FToStr(np1.x())+ " "+FToStr(-np1.y())+" ]\n");
+ PutDoc("/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n");
+ PutDoc(">>\n");
+ if (Options.Compress)
+ fon = CompressArray(fon);
+ PutDoc("/Length "+Pdf::toPdf(fon.length()+1));
+ if (Options.Compress)
+ PutDoc("\n/Filter /FlateDecode");
+ PutDoc(" >>\nstream\n"+EncStream(fon, fontGlyphXForm)+"\nendstream");
+ writer.endObj(fontGlyphXForm);
+ pageData.XObjects[fontName + Pdf::toPdf(ig.key())] = fontGlyphXForm;
+ }
+ return result;
}
PdfId PDFLibCore::PDF_EmbedFontObject(const QByteArray& font, const QByteArray& subtype)
{
- PdfId embeddedFontObject = writer.newObject();
- writer.startObj(embeddedFontObject);
- int len = font.length();
- QByteArray ttf = (Options.Compress? CompressArray(font) : font);
- //qDebug() << QString("sfnt data: size=%1 compressed=%2").arg(len).arg(bb.length());
- PutDoc("<<\n/Length " + Pdf::toPdf(ttf.length() + 1) + "\n");
- PutDoc("/Length1 " + Pdf::toPdf(len) + "\n");
- if (subtype.size() > 0)
- PutDoc("/Subtype " + subtype);
- if (Options.Compress)
- PutDoc("/Filter /FlateDecode\n");
- PutDoc(">>\nstream\n");
- EncodeArrayToStream(ttf, embeddedFontObject);
- PutDoc("\nendstream");
- writer.endObj(embeddedFontObject);
- return embeddedFontObject;
+ PdfId embeddedFontObject = writer.newObject();
+ writer.startObj(embeddedFontObject);
+ int len = font.length();
+ QByteArray ttf = (Options.Compress? CompressArray(font) : font);
+ //qDebug() << QString("sfnt data: size=%1 compressed=%2").arg(len).arg(bb.length());
+ PutDoc("<<\n/Length " + Pdf::toPdf(ttf.length() + 1) + "\n");
+ PutDoc("/Length1 " + Pdf::toPdf(len) + "\n");
+ if (subtype.size() > 0)
+ PutDoc("/Subtype " + subtype);
+ if (Options.Compress)
+ PutDoc("/Filter /FlateDecode\n");
+ PutDoc(">>\nstream\n");
+ EncodeArrayToStream(ttf, embeddedFontObject);
+ PutDoc("\nendstream");
+ writer.endObj(embeddedFontObject);
+ return embeddedFontObject;
}
PdfId PDFLibCore::PDF_WriteFontDescriptor(const QByteArray& fontName, ScFace& face, ScFace::FontFormat fformat, PdfId embeddedFontObject)
{
- PdfId fontDescriptor = writer.newObject();
- writer.startObj(fontDescriptor);
- // TODO: think about QByteArray ScFace::getFontDescriptor() -- AV
- PutDoc("<<\n/Type /FontDescriptor\n");
- PutDoc("/FontName " + Pdf::toName(fontName) + "\n");
- PutDoc("/FontBBox [ " + Pdf::toAscii(face.pdfFontBBoxAsString()) + " ]\n");
- PutDoc("/Flags ");
- //FIXME: isItalic() should be queried from ScFace, not from Qt -- AV
- //QFontInfo fo = QFontInfo(it.data());
- int pfl = 0;
- if (face.isFixedPitch())
- pfl = pfl ^ 1;
- //if (fo.italic())
- if (face.italicAngleAsString() != "0")
- pfl = pfl ^ 64;
- // pfl = pfl ^ 4;
- pfl = pfl ^ 32;
- PutDoc(Pdf::toPdf(pfl)+"\n");
- PutDoc("/Ascent " + Pdf::toAscii(face.pdfAscentAsString())+"\n");
- PutDoc("/Descent " + Pdf::toAscii(face.pdfDescentAsString())+"\n");
- PutDoc("/CapHeight " + Pdf::toAscii(face.pdfCapHeightAsString())+"\n");
- PutDoc("/ItalicAngle " + Pdf::toAscii(face.italicAngleAsString())+"\n");
- PutDoc("/StemV 1\n");
- if (embeddedFontObject != 0)
- {
- if (fformat == ScFace::SFNT || fformat == ScFace::TTCF)
- {
- if (face.type() == ScFace::OTF)
- {
- PutDoc("/FontFile3 "+Pdf::toPdf(embeddedFontObject)+" 0 R\n");
- }
- else
- {
- PutDoc("/FontFile2 "+Pdf::toPdf(embeddedFontObject)+" 0 R\n");
- }
- }
- else if (fformat == ScFace::PFB)
- PutDoc("/FontFile "+Pdf::toPdf(embeddedFontObject)+" 0 R\n");
- else if (fformat == ScFace::PFA)
- PutDoc("/FontFile "+Pdf::toPdf(embeddedFontObject)+" 0 R\n");
- }
- PutDoc(">>");
- writer.endObj(fontDescriptor);
- return fontDescriptor;
+ PdfId fontDescriptor = writer.newObject();
+ writer.startObj(fontDescriptor);
+ // TODO: think about QByteArray ScFace::getFontDescriptor() -- AV
+ PutDoc("<<\n/Type /FontDescriptor\n");
+ PutDoc("/FontName " + Pdf::toName(fontName) + "\n");
+ PutDoc("/FontBBox [ " + Pdf::toAscii(face.pdfFontBBoxAsString()) + " ]\n");
+ PutDoc("/Flags ");
+ //FIXME: isItalic() should be queried from ScFace, not from Qt -- AV
+ //QFontInfo fo = QFontInfo(it.data());
+ int pfl = 0;
+ if (face.isFixedPitch())
+ pfl = pfl ^ 1;
+ //if (fo.italic())
+ if (face.italicAngleAsString() != "0")
+ pfl = pfl ^ 64;
+ // pfl = pfl ^ 4;
+ pfl = pfl ^ 32;
+ PutDoc(Pdf::toPdf(pfl)+"\n");
+ PutDoc("/Ascent " + Pdf::toAscii(face.pdfAscentAsString())+"\n");
+ PutDoc("/Descent " + Pdf::toAscii(face.pdfDescentAsString())+"\n");
+ PutDoc("/CapHeight " + Pdf::toAscii(face.pdfCapHeightAsString())+"\n");
+ PutDoc("/ItalicAngle " + Pdf::toAscii(face.italicAngleAsString())+"\n");
+ PutDoc("/StemV 1\n");
+ if (embeddedFontObject != 0)
+ {
+ if (fformat == ScFace::SFNT || fformat == ScFace::TTCF)
+ {
+ if (face.type() == ScFace::OTF)
+ {
+ PutDoc("/FontFile3 "+Pdf::toPdf(embeddedFontObject)+" 0 R\n");
+ }
+ else
+ {
+ PutDoc("/FontFile2 "+Pdf::toPdf(embeddedFontObject)+" 0 R\n");
+ }
+ }
+ else if (fformat == ScFace::PFB)
+ PutDoc("/FontFile "+Pdf::toPdf(embeddedFontObject)+" 0 R\n");
+ else if (fformat == ScFace::PFA)
+ PutDoc("/FontFile "+Pdf::toPdf(embeddedFontObject)+" 0 R\n");
+ }
+ PutDoc(">>");
+ writer.endObj(fontDescriptor);
+ return fontDescriptor;
}
PdfFont PDFLibCore::PDF_EncodeCidFont(const QByteArray& fontName, ScFace& face, const QByteArray& baseFont, PdfId fontDes, const ScFace::FaceEncoding& gl, const QMap<uint,uint> glyphmap )
{
- PdfFont result;
- result.name = Pdf::toName(fontName);
- result.method = glyphmap.isEmpty()? Use_Embedded : Use_Subset;
- result.encoding = glyphmap.isEmpty()? Encode_IdentityH : Encode_Subset;
- result.glyphmap = glyphmap;
-
- PdfId fontWidths2 = writer.newObject();
- writer.startObj(fontWidths2);
- QList<QByteArray> toUnicodeMaps;
- QList<int> toUnicodeMapsCount;
- QByteArray toUnicodeMap = "";
- int toUnicodeMapCounter = 0;
-
- PutDoc("[ ");
- QList<uint> keys = gl.uniqueKeys();
- QList<uint>::iterator git;
- bool seenNotDef = false;
- for (git = keys.begin(); git != keys.end(); ++git)
- {
- uint gid = result.encoding == Encode_Subset? glyphmap[*git] : *git;
- if (gid > 0 || !seenNotDef)
- {
- seenNotDef |= (gid == 0);
- PutDoc(Pdf::toPdf(gid)+" ["+Pdf::toPdf(static_cast<int>(face.glyphWidth(*git)* 1000))+"] " );
- QString tmp, tmp2;
- tmp.sprintf("%04X", gid);
- tmp2.sprintf("%04X", gl.value(*git).first);
- toUnicodeMap += "<" + Pdf::toAscii(tmp)+ "> <" + Pdf::toAscii(tmp2) + ">\n";
- toUnicodeMapCounter++;
- if (toUnicodeMapCounter == 100)
- {
- toUnicodeMaps.append(toUnicodeMap);
- toUnicodeMapsCount.append(toUnicodeMapCounter);
- toUnicodeMap = "";
- toUnicodeMapCounter = 0;
- }
- }
- }
- PutDoc("]");
- writer.endObj(fontWidths2);
- 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 fontToUnicode2 = WritePDFStream(toUnicodeMapStream);
- PdfId fontObject2 = writer.newObject();
- writer.startObj(fontObject2);
- PutDoc("<<\n/Type /Font\n/Subtype /Type0\n");
- PutDoc("/Name " + Pdf::toName(fontName) + "\n");
- PutDoc("/BaseFont "+ baseFont +"\n");
- PutDoc("/Encoding /Identity-H\n");
- PutDoc("/ToUnicode "+Pdf::toPdf(fontToUnicode2)+" 0 R\n");
- PutDoc("/DescendantFonts [");
- PutDoc("<</Type /Font");
- if (face.type() == ScFace::OTF)
- PutDoc("/Subtype /CIDFontType0");
- else
- PutDoc("/Subtype /CIDFontType2");
- PutDoc("/BaseFont " + baseFont);
- PutDoc("/FontDescriptor " + Pdf::toPdf(fontDes)+ " 0 R");
- PutDoc("/CIDSystemInfo <</Ordering(Identity)/Registry(Adobe)/Supplement 0>>");
- PutDoc("/DW 1000");
- PutDoc("/W "+Pdf::toPdf(fontWidths2)+" 0 R");
- PutDoc("/CIDToGIDMap /Identity");
- PutDoc(">>"); // close CIDFont dictionary
- PutDoc("]\n"); // close DescendantFonts array
- PutDoc(">>");
- writer.endObj(fontObject2);
- pageData.FObjects[fontName] = fontObject2;
- return result;
+ PdfFont result;
+ result.name = Pdf::toName(fontName);
+ result.method = glyphmap.isEmpty()? Use_Embedded : Use_Subset;
+ result.encoding = glyphmap.isEmpty()? Encode_IdentityH : Encode_Subset;
+ result.glyphmap = glyphmap;
+
+ PdfId fontWidths2 = writer.newObject();
+ writer.startObj(fontWidths2);
+ QList<QByteArray> toUnicodeMaps;
+ QList<int> toUnicodeMapsCount;
+ QByteArray toUnicodeMap = "";
+ int toUnicodeMapCounter = 0;
+
+ PutDoc("[ ");
+ QList<uint> keys = gl.uniqueKeys();
+ QList<uint>::iterator git;
+ bool seenNotDef = false;
+ for (git = keys.begin(); git != keys.end(); ++git)
+ {
+ uint gid = result.encoding == Encode_Subset? glyphmap[*git] : *git;
+ if (gid > 0 || !seenNotDef)
+ {
+ seenNotDef |= (gid == 0);
+ PutDoc(Pdf::toPdf(gid)+" ["+Pdf::toPdf(static_cast<int>(face.glyphWidth(*git)* 1000))+"] " );
+ QString tmp, tmp2;
+ tmp.sprintf("%04X", gid);
+ tmp2.sprintf("%04X", gl.value(*git).first);
+ toUnicodeMap += "<" + Pdf::toAscii(tmp)+ "> <" + Pdf::toAscii(tmp2) + ">\n";
+ toUnicodeMapCounter++;
+ if (toUnicodeMapCounter == 100)
+ {
+ toUnicodeMaps.append(toUnicodeMap);
+ toUnicodeMapsCount.append(toUnicodeMapCounter);
+ toUnicodeMap = "";
+ toUnicodeMapCounter = 0;
+ }
+ }
+ }
+ PutDoc("]");
+ writer.endObj(fontWidths2);
+ 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 fontToUnicode2 = WritePDFStream(toUnicodeMapStream);
+ PdfId fontObject2 = writer.newObject();
+ writer.startObj(fontObject2);
+ PutDoc("<<\n/Type /Font\n/Subtype /Type0\n");
+ PutDoc("/Name " + Pdf::toName(fontName) + "\n");
+ PutDoc("/BaseFont "+ baseFont +"\n");
+ PutDoc("/Encoding /Identity-H\n");
+ PutDoc("/ToUnicode "+Pdf::toPdf(fontToUnicode2)+" 0 R\n");
+ PutDoc("/DescendantFonts [");
+ PutDoc("<</Type /Font");
+ if (face.type() == ScFace::OTF)
+ PutDoc("/Subtype /CIDFontType0");
+ else
+ PutDoc("/Subtype /CIDFontType2");
+ PutDoc("/BaseFont " + baseFont);
+ PutDoc("/FontDescriptor " + Pdf::toPdf(fontDes)+ " 0 R");
+ PutDoc("/CIDSystemInfo <</Ordering(Identity)/Registry(Adobe)/Supplement 0>>");
+ PutDoc("/DW 1000");
+ PutDoc("/W "+Pdf::toPdf(fontWidths2)+" 0 R");
+ PutDoc("/CIDToGIDMap /Identity");
+ PutDoc(">>"); // close CIDFont dictionary
+ PutDoc("]\n"); // close DescendantFonts array
+ PutDoc(">>");
+ writer.endObj(fontObject2);
+ pageData.FObjects[fontName] = fontObject2;
+ return result;
}
PdfFont PDFLibCore::PDF_EncodeSimpleFont(const QByteArray& fontName, ScFace& face, const QByteArray& baseFont, const QByteArray& subtype, bool isEmbedded, PdfId fontDes, const ScFace::FaceEncoding& gl)
{
- PdfFont result;
- result.name = Pdf::toName(fontName);
- result.method = isEmbedded? Use_Embedded : Use_System;
- result.encoding = Encode_224;
-
- int nglyphs = 0;
- ScFace::FaceEncoding::ConstIterator gli;
- for (gli = gl.cbegin(); gli != gl.cend(); ++gli)
- {
- if (gli.key() > static_cast<uint>(nglyphs))
- nglyphs = gli.key();
- }
- ++nglyphs;
- // qDebug() << QString("pdflib: nglyphs %1 max %2").arg(nglyphs).arg(face.maxGlyph());
-
- uint Fcc = nglyphs / 224;
- if ((nglyphs % 224) != 0)
- Fcc += 1;
- for (uint Fc = 0; Fc < Fcc; ++Fc)
- {
- PdfId fontWidths2 = writer.newObject();
- writer.startObj(fontWidths2);
- int chCount = 32;
- PutDoc("[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ");
- for (int ww = 32; ww < 256; ++ww)
- {
- uint glyph = 224 * Fc + ww - 32;
- if (gl.contains(glyph))
- PutDoc(Pdf::toPdf(static_cast<int>(face.glyphWidth(glyph)* 1000))+" ");
- else
- PutDoc("0 ");
- chCount++;
- if (signed(glyph) == nglyphs-1)
- break;
- }
- PutDoc("]");
- writer.endObj(fontWidths2);
- PdfId fontEncoding2 = writer.newObject();
- writer.startObj(fontEncoding2);
- QStringList toUnicodeMaps;
- QList<int> toUnicodeMapsCount;
- QString toUnicodeMap = "";
- int toUnicodeMapCounter = 0;
- PutDoc("<< /Type /Encoding\n");
- PutDoc("/Differences [ \n");
- int crc = 0;
- bool startOfSeq = true;
- for (int ww2 = 32; ww2 < 256; ++ww2)
- {
- uint glyph = 224 * Fc + ww2 - 32;
- ScFace::FaceEncoding::ConstIterator glIt = gl.find(glyph);
- if (glIt != gl.cend() && !glIt.value().second.isEmpty())
- {
- if (startOfSeq)
- {
- PutDoc(Pdf::toPdf(ww2)+" ");
- startOfSeq = false;
- }
- PutDoc(Pdf::toName(glIt.value().second)+" ");
- QString tmp, tmp2;
- tmp.sprintf("%02X", ww2);
- tmp2.sprintf("%04X", glIt.value().first);
- toUnicodeMap += "<" + Pdf::toAscii(tmp) + "> <" + Pdf::toAscii(tmp2) + ">\n";
- //QString("<%1> <%2>\n").arg(tmp).arg((tmp2));
- toUnicodeMapCounter++;
- if (toUnicodeMapCounter == 100)
- {
- toUnicodeMaps.append(toUnicodeMap);
- toUnicodeMapsCount.append(toUnicodeMapCounter);
- toUnicodeMap = "";
- toUnicodeMapCounter = 0;
- }
- crc++;
- }
- else
- {
- startOfSeq = true;
- }
- if (signed(glyph) == nglyphs-1)
- break;
- if (crc > 8)
- {
- PutDoc("\n");
- crc = 0;
- }
- }
- if (toUnicodeMapCounter != 0)
- {
- toUnicodeMaps.append(toUnicodeMap);
- toUnicodeMapsCount.append(toUnicodeMapCounter);
- }
- PutDoc("]\n");
- PutDoc(">>");
- writer.endObj(fontEncoding2);
- 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 fontToUnicode2 = WritePDFStream(toUnicodeMapStream);
- PdfId fontObject2 = writer.newObject();
- writer.startObj(fontObject2);
- PutDoc("<<\n/Type /Font\n/Subtype ");
- PutDoc(subtype + "\n");
- PutDoc("/Name "+Pdf::toName(fontName)+"S"+Pdf::toPdf(Fc)+"\n");
- PutDoc("/BaseFont "+baseFont+"\n");
- PutDoc("/FirstChar 0\n");
- PutDoc("/LastChar "+Pdf::toPdf(chCount-1)+"\n");
- PutDoc("/Widths "+Pdf::toPdf(fontWidths2)+" 0 R\n");
- PutDoc("/Encoding "+Pdf::toPdf(fontEncoding2)+" 0 R\n");
- PutDoc("/ToUnicode "+Pdf::toPdf(fontToUnicode2)+" 0 R\n");
- PutDoc("/FontDescriptor "+Pdf::toPdf(fontDes)+" 0 R\n");
- PutDoc(">>");
- writer.endObj(fontObject2);
- pageData.FObjects[fontName + "S"+Pdf::toPdf(Fc)] = fontObject2;
- } // for(Fc)
- PdfId fontWidthsForm = writer.newObject();
- writer.startObj(fontWidthsForm);
- PutDoc("[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ");
- for (int ww = 32; ww < 256; ++ww)
- {
- uint glyph = face.char2CMap(QChar(ww));
- if (gl.contains(glyph))
- PutDoc(Pdf::toPdf(static_cast<int>(face.glyphWidth(glyph)* 1000))+" ");
- else
- PutDoc("0 ");
- }
- PutDoc("]");
- writer.endObj(fontWidthsForm);
- PdfId fontObjectForm = writer.newObject();
- PdfFont formFont;
- formFont.name = Pdf::toName(fontName) + "Form";
- formFont.usage = Used_in_Forms;
- writer.startObj(fontObjectForm);
- PutDoc("<<\n/Type /Font\n/Subtype ");
- PutDoc(subtype + "\n");
- // if (fformat == ScFace::SFNT || fformat == ScFace::TTCF)
- // {
- // PutDoc("/TrueType\n");
- PutDoc("/Name " + formFont.name+ "\n");
- pageData.FObjects[formFont.name] = fontObjectForm;
- UsedFontsF.insert(fontName, formFont);
- /* }
- else
- {
- PutDoc("/Type1\n");
- PutDoc("/Name /"+face.psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+"\n");
- pageData.FObjects[face.psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )] = ObjCounter;
- UsedFontsF.insert(it.key(), "/"+face.psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ));
- } */
- PutDoc("/BaseFont "+Pdf::toName(sanitizeFontName(face.psName()))+"\n");
- PutDoc("/Encoding << \n");
- PutDoc("/Differences [ \n");
- PutDoc("24 /breve /caron /circumflex /dotaccent /hungarumlaut /ogonek /ring /tilde\n");
- PutDoc("39 /quotesingle 96 /grave 128 /bullet /dagger /daggerdbl /ellipsis /emdash /endash /florin /fraction /guilsinglleft /guilsinglright\n");
- PutDoc("/minus /perthousand /quotedblbase /quotedblleft /quotedblright /quoteleft /quoteright /quotesinglbase /trademark /fi /fl /Lslash /OE /Scaron\n");
- PutDoc("/Ydieresis /Zcaron /dotlessi /lslash /oe /scaron /zcaron 164 /currency 166 /brokenbar 168 /dieresis /copyright /ordfeminine 172 /logicalnot\n");
- PutDoc("/.notdef /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu 183 /periodcentered /cedilla /onesuperior /ordmasculine\n");
- PutDoc("188 /onequarter /onehalf /threequarters 192 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex\n");
- PutDoc("/Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash\n");
- PutDoc("/Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla\n");
- PutDoc("/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis\n");
- PutDoc("/divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis\n");
- PutDoc("] >>\n");
- PutDoc("/FirstChar 0\n");
- PutDoc("/LastChar 255\n");
- PutDoc("/Widths "+Pdf::toPdf(fontWidthsForm)+" 0 R\n");
- PutDoc("/FontDescriptor "+Pdf::toPdf(fontDes)+" 0 R\n");
- PutDoc(">>");
- writer.endObj(fontObjectForm);
-
- return result;
+ PdfFont result;
+ result.name = Pdf::toName(fontName);
+ result.method = isEmbedded? Use_Embedded : Use_System;
+ result.encoding = Encode_224;
+
+ int nglyphs = 0;
+ ScFace::FaceEncoding::ConstIterator gli;
+ for (gli = gl.cbegin(); gli != gl.cend(); ++gli)
+ {
+ if (gli.key() > static_cast<uint>(nglyphs))
+ nglyphs = gli.key();
+ }
+ ++nglyphs;
+ // qDebug() << QString("pdflib: nglyphs %1 max %2").arg(nglyphs).arg(face.maxGlyph());
+
+ uint Fcc = nglyphs / 224;
+ if ((nglyphs % 224) != 0)
+ Fcc += 1;
+ for (uint Fc = 0; Fc < Fcc; ++Fc)
+ {
+ PdfId fontWidths2 = writer.newObject();
+ writer.startObj(fontWidths2);
+ int chCount = 32;
+ PutDoc("[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ");
+ for (int ww = 32; ww < 256; ++ww)
+ {
+ uint glyph = 224 * Fc + ww - 32;
+ if (gl.contains(glyph))
+ PutDoc(Pdf::toPdf(static_cast<int>(face.glyphWidth(glyph)* 1000))+" ");
+ else
+ PutDoc("0 ");
+ chCount++;
+ if (signed(glyph) == nglyphs-1)
+ break;
+ }
+ PutDoc("]");
+ writer.endObj(fontWidths2);
+ PdfId fontEncoding2 = writer.newObject();
+ writer.startObj(fontEncoding2);
+ QStringList toUnicodeMaps;
+ QList<int> toUnicodeMapsCount;
+ QString toUnicodeMap = "";
+ int toUnicodeMapCounter = 0;
+ PutDoc("<< /Type /Encoding\n");
+ PutDoc("/Differences [ \n");
+ int crc = 0;
+ bool startOfSeq = true;
+ for (int ww2 = 32; ww2 < 256; ++ww2)
+ {
+ uint glyph = 224 * Fc + ww2 - 32;
+ ScFace::FaceEncoding::ConstIterator glIt = gl.find(glyph);
+ if (glIt != gl.cend() && !glIt.value().second.isEmpty())
+ {
+ if (startOfSeq)
+ {
+ PutDoc(Pdf::toPdf(ww2)+" ");
+ startOfSeq = false;
+ }
+ PutDoc(Pdf::toName(glIt.value().second)+" ");
+ QString tmp, tmp2;
+ tmp.sprintf("%02X", ww2);
+ tmp2.sprintf("%04X", glIt.value().first);
+ toUnicodeMap += "<" + Pdf::toAscii(tmp) + "> <" + Pdf::toAscii(tmp2) + ">\n";
+ //QString("<%1> <%2>\n").arg(tmp).arg((tmp2));
+ toUnicodeMapCounter++;
+ if (toUnicodeMapCounter == 100)
+ {
+ toUnicodeMaps.append(toUnicodeMap);
+ toUnicodeMapsCount.append(toUnicodeMapCounter);
+ toUnicodeMap = "";
+ toUnicodeMapCounter = 0;
+ }
+ crc++;
+ }
+ else
+ {
+ startOfSeq = true;
+ }
+ if (signed(glyph) == nglyphs-1)
+ break;
+ if (crc > 8)
+ {
+ PutDoc("\n");
+ crc = 0;
+ }
+ }
+ if (toUnicodeMapCounter != 0)
+ {
+ toUnicodeMaps.append(toUnicodeMap);
+ toUnicodeMapsCount.append(toUnicodeMapCounter);
+ }
+ PutDoc("]\n");
+ PutDoc(">>");
+ writer.endObj(fontEncoding2);
+ 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 fontToUnicode2 = WritePDFStream(toUnicodeMapStream);
+ PdfId fontObject2 = writer.newObject();
+ writer.startObj(fontObject2);
+ PutDoc("<<\n/Type /Font\n/Subtype ");
+ PutDoc(subtype + "\n");
+ PutDoc("/Name "+Pdf::toName(fontName)+"S"+Pdf::toPdf(Fc)+"\n");
+ PutDoc("/BaseFont "+baseFont+"\n");
+ PutDoc("/FirstChar 0\n");
+ PutDoc("/LastChar "+Pdf::toPdf(chCount-1)+"\n");
+ PutDoc("/Widths "+Pdf::toPdf(fontWidths2)+" 0 R\n");
+ PutDoc("/Encoding "+Pdf::toPdf(fontEncoding2)+" 0 R\n");
+ PutDoc("/ToUnicode "+Pdf::toPdf(fontToUnicode2)+" 0 R\n");
+ PutDoc("/FontDescriptor "+Pdf::toPdf(fontDes)+" 0 R\n");
+ PutDoc(">>");
+ writer.endObj(fontObject2);
+ pageData.FObjects[fontName + "S"+Pdf::toPdf(Fc)] = fontObject2;
+ } // for(Fc)
+ PdfId fontWidthsForm = writer.newObject();
+ writer.startObj(fontWidthsForm);
+ PutDoc("[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ");
+ for (int ww = 32; ww < 256; ++ww)
+ {
+ uint glyph = face.char2CMap(QChar(ww));
+ if (gl.contains(glyph))
+ PutDoc(Pdf::toPdf(static_cast<int>(face.glyphWidth(glyph)* 1000))+" ");
+ else
+ PutDoc("0 ");
+ }
+ PutDoc("]");
+ writer.endObj(fontWidthsForm);
+ PdfId fontObjectForm = writer.newObject();
+ PdfFont formFont;
+ formFont.name = Pdf::toName(fontName) + "Form";
+ formFont.usage = Used_in_Forms;
+ writer.startObj(fontObjectForm);
+ PutDoc("<<\n/Type /Font\n/Subtype ");
+ PutDoc(subtype + "\n");
+ // if (fformat == ScFace::SFNT || fformat == ScFace::TTCF)
+ // {
+ // PutDoc("/TrueType\n");
+ PutDoc("/Name " + formFont.name+ "\n");
+ pageData.FObjects[formFont.name] = fontObjectForm;
+ UsedFontsF.insert(fontName, formFont);
+ /* }
+ else
+ {
+ PutDoc("/Type1\n");
+ PutDoc("/Name /"+face.psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+"\n");
+ pageData.FObjects[face.psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )] = ObjCounter;
+ UsedFontsF.insert(it.key(), "/"+face.psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ));
+ } */
+ PutDoc("/BaseFont "+Pdf::toName(sanitizeFontName(face.psName()))+"\n");
+ PutDoc("/Encoding << \n");
+ PutDoc("/Differences [ \n");
+ PutDoc("24 /breve /caron /circumflex /dotaccent /hungarumlaut /ogonek /ring /tilde\n");
+ PutDoc("39 /quotesingle 96 /grave 128 /bullet /dagger /daggerdbl /ellipsis /emdash /endash /florin /fraction /guilsinglleft /guilsinglright\n");
+ PutDoc("/minus /perthousand /quotedblbase /quotedblleft /quotedblright /quoteleft /quoteright /quotesinglbase /trademark /fi /fl /Lslash /OE /Scaron\n");
+ PutDoc("/Ydieresis /Zcaron /dotlessi /lslash /oe /scaron /zcaron 164 /currency 166 /brokenbar 168 /dieresis /copyright /ordfeminine 172 /logicalnot\n");
+ PutDoc("/.notdef /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu 183 /periodcentered /cedilla /onesuperior /ordmasculine\n");
+ PutDoc("188 /onequarter /onehalf /threequarters 192 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex\n");
+ PutDoc("/Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash\n");
+ PutDoc("/Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla\n");
+ PutDoc("/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis\n");
+ PutDoc("/divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis\n");
+ PutDoc("] >>\n");
+ PutDoc("/FirstChar 0\n");
+ PutDoc("/LastChar 255\n");
+ PutDoc("/Widths "+Pdf::toPdf(fontWidthsForm)+" 0 R\n");
+ PutDoc("/FontDescriptor "+Pdf::toPdf(fontDes)+" 0 R\n");
+ PutDoc(">>");
+ writer.endObj(fontObjectForm);
+
+ return result;
}
static void dumpFont(QString name, QByteArray data)
{
- QFile file(name);
- file.open(QIODevice::WriteOnly);
- QDataStream out(&file);
- out.writeRawData(data.data(), data.length());
+ QFile file(name);
+ file.open(QIODevice::WriteOnly);
+ QDataStream out(&file);
+ out.writeRawData(data.data(), data.length());
}
static void dumpCFF(QString name, cff::CFF font)
{
- QFile file(name);
- file.open(QIODevice::WriteOnly);
- QDataStream out(&file);
- font.dump(out);
+ QFile file(name);
+ file.open(QIODevice::WriteOnly);
+ QDataStream out(&file);
+ font.dump(out);
}
PdfFont PDFLibCore::PDF_WriteTtfSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs)
{
- QByteArray font;
- face.RawData(font);
+ QByteArray font;
+ face.RawData(font);
dumpFont(face.psName() + ".ttf", font);
- QList<ScFace::gid_type> glyphs = RealGlyphs.uniqueKeys();
- glyphs.removeAll(0);
- glyphs.prepend(0);
- QByteArray subset = sfnt::subsetFace(font, glyphs);
+ QList<ScFace::gid_type> glyphs = RealGlyphs.uniqueKeys();
+ glyphs.removeAll(0);
+ glyphs.prepend(0);
+ QByteArray subset = sfnt::subsetFace(font, glyphs);
dumpFont(face.psName()+"subs.ttf", subset);
- PdfId embeddedFontObj = PDF_EmbedFontObject(subset, QByteArray());
- PdfId fontDes = PDF_WriteFontDescriptor(fontName, face, face.format(), embeddedFontObj);
- QByteArray baseFont = Pdf::toName(sanitizeFontName(face.psName()));
- ScFace::FaceEncoding fullEncoding, subEncoding;
- QMap<uint,uint> glyphmap;
- face.glyphNames(fullEncoding);
- for (int i = 0; i < glyphs.length(); ++i)
- {
- glyphmap[glyphs[i]] = i;
- qDebug() << glyphs[i] << " --> " << i << QChar(fullEncoding[glyphs[i]].first);
- }
-
- PdfFont result = PDF_EncodeCidFont(fontName, face, baseFont, fontDes, fullEncoding, glyphmap);
- return result;
+ PdfId embeddedFontObj = PDF_EmbedFontObject(subset, QByteArray());
+ PdfId fontDes = PDF_WriteFontDescriptor(fontName, face, face.format(), embeddedFontObj);
+ QByteArray baseFont = Pdf::toName(sanitizeFontName(face.psName()));
+ ScFace::FaceEncoding fullEncoding, subEncoding;
+ QMap<uint,uint> glyphmap;
+ face.glyphNames(fullEncoding);
+ for (int i = 0; i < glyphs.length(); ++i)
+ {
+ glyphmap[glyphs[i]] = i;
+ qDebug() << glyphs[i] << " --> " << i << QChar(fullEncoding[glyphs[i]].first);
+ }
+
+ PdfFont result = PDF_EncodeCidFont(fontName, face, baseFont, fontDes, fullEncoding, glyphmap);
+ return result;
}
PdfFont PDFLibCore::PDF_WriteCffSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs)
{
-// QByteArray sfnt; //TEST
-// face.RawData(sfnt);
-// QByteArray cff = sfnt::getTable(sfnt, "CFF ");
-// dumpFont(fontName, cff);
-// cff::CFF cfffont(cff);
-// cfffont.dump();
-// QByteArray subsetfont = cff::subsetFace(cff, it.value().keys());
-// dumpFont(it.key() + "subs.cff", subsetfont);
-// cff::CFF subset(subsetfont);
-// subset.dump();
-// PDF_WriteFontDescriptor(fontName, face, fformat, 0);
-// // END
-
- QByteArray font;
- face.RawData(font);
- font = sfnt::getTable(font, "CFF ");
- dumpFont(face.psName() + ".cff", font);
- QList<ScFace::gid_type> glyphs = RealGlyphs.uniqueKeys();
- glyphs.removeAll(0);
- glyphs.prepend(0);
- QByteArray subset = cff::subsetFace(font, glyphs);
- dumpFont(face.psName()+"subs.cff", subset);
- PdfId embeddedFontObj = PDF_EmbedFontObject(subset, "/CIDFontType0C");
- PdfId fontDes = PDF_WriteFontDescriptor(fontName, face, face.format(), embeddedFontObj);
- QByteArray baseFont = Pdf::toName(sanitizeFontName(face.psName()));
- ScFace::FaceEncoding fullEncoding, subEncoding;
- QMap<uint,uint> glyphmap;
- face.glyphNames(fullEncoding);
- for (int i = 0; i < glyphs.length(); ++i)
- {
- glyphmap[glyphs[i]] = i;
- qDebug() << glyphs[i] << " --> " << i << QChar(fullEncoding[glyphs[i]].first);
- }
-
- PdfFont result = PDF_EncodeCidFont(fontName, face, baseFont, fontDes, fullEncoding, glyphmap);
- return result;
+// QByteArray sfnt; //TEST
+// face.RawData(sfnt);
+// QByteArray cff = sfnt::getTable(sfnt, "CFF ");
+// dumpFont(fontName, cff);
+// cff::CFF cfffont(cff);
+// cfffont.dump();
+// QByteArray subsetfont = cff::subsetFace(cff, it.value().keys());
+// dumpFont(it.key() + "subs.cff", subsetfont);
+// cff::CFF subset(subsetfont);
+// subset.dump();
+// PDF_WriteFontDescriptor(fontName, face, fformat, 0);
+// // END
+
+ QByteArray font;
+ face.RawData(font);
+ font = sfnt::getTable(font, "CFF ");
+ dumpFont(face.psName() + ".cff", font);
+ QList<ScFace::gid_type> glyphs = RealGlyphs.uniqueKeys();
+ glyphs.removeAll(0);
+ glyphs.prepend(0);
+ QByteArray subset = cff::subsetFace(font, glyphs);
+ dumpFont(face.psName()+"subs.cff", subset);
+ PdfId embeddedFontObj = PDF_EmbedFontObject(subset, "/CIDFontType0C");
+ PdfId fontDes = PDF_WriteFontDescriptor(fontName, face, face.format(), embeddedFontObj);
+ QByteArray baseFont = Pdf::toName(sanitizeFontName(face.psName()));
+ ScFace::FaceEncoding fullEncoding, subEncoding;
+ QMap<uint,uint> glyphmap;
+ face.glyphNames(fullEncoding);
+ for (int i = 0; i < glyphs.length(); ++i)
+ {
+ glyphmap[glyphs[i]] = i;
+ qDebug() << glyphs[i] << " --> " << i << QChar(fullEncoding[glyphs[i]].first);
+ }
+
+ PdfFont result = PDF_EncodeCidFont(fontName, face, baseFont, fontDes, fullEncoding, glyphmap);
+ return result;
}
PdfId PDFLibCore::PDF_EmbedType1AsciiFontObject(const QByteArray& fon)
{
- QByteArray fon2;
- PdfId embeddedFontObject = writer.newObject();
- writer.startObj(embeddedFontObject);
- int len1 = fon.indexOf("eexec")+5;
- fon2 = fon.left(len1) + "\n";
- int len2 = fon.indexOf("0000000000000000000000000");
- if (len2 == -1)
- len2 = fon.length()+1;
- // QString tm;
- // uint value;
- // bool ok = true;
- // int count = 0;
- // for (int xx = len1; xx < len2-1; ++xx)
- // {
- // tm = fon.at(xx);
- // if ((tm == QChar(13)) || (tm == QChar(10)))
- // continue;
- // xx++;
- // count++;
- // tm += fon.at(xx);
- // value = tm.toUInt(&ok, 16);
- // fon2 += char(value);
- // }
- QByteArray hexData = QByteArray::fromHex(fon.mid(len1, len2-len1));
- fon2 += hexData;
- fon2 += fon.mid(len2);
- if (Options.Compress)
- fon2 = CompressArray(fon2);
- PutDoc("<<\n/Length "+Pdf::toPdf(fon2.length()+1)+"\n");
- PutDoc("/Length1 "+Pdf::toPdf(len1+1)+"\n");
- PutDoc("/Length2 "+Pdf::toPdf(hexData.length())+"\n");
- if(static_cast<int>(fon.length()-len2) == -1)
- PutDoc("/Length3 0\n");
- else
- PutDoc("/Length3 "+Pdf::toPdf(fon.length()-len2)+"\n");
- if (Options.Compress)
- PutDoc("/Filter /FlateDecode\n");
- PutDoc(">>\nstream\n"+EncStream(fon2, embeddedFontObject)+"\nendstream");
- writer.endObj(embeddedFontObject);
- return embeddedFontObject;
+ QByteArray fon2;
+ PdfId embeddedFontObject = writer.newObject();
+ writer.startObj(embeddedFontObject);
+ int len1 = fon.indexOf("eexec")+5;
+ fon2 = fon.left(len1) + "\n";
+ int len2 = fon.indexOf("0000000000000000000000000");
+ if (len2 == -1)
+ len2 = fon.length()+1;
+ // QString tm;
+ // uint value;
+ // bool ok = true;
+ // int count = 0;
+ // for (int xx = len1; xx < len2-1; ++xx)
+ // {
+ // tm = fon.at(xx);
+ // if ((tm == QChar(13)) || (tm == QChar(10)))
+ // continue;
+ // xx++;
+ // count++;
+ // tm += fon.at(xx);
+ // value = tm.toUInt(&ok, 16);
+ // fon2 += char(value);
+ // }
+ QByteArray hexData = QByteArray::fromHex(fon.mid(len1, len2-len1));
+ fon2 += hexData;
+ fon2 += fon.mid(len2);
+ if (Options.Compress)
+ fon2 = CompressArray(fon2);
+ PutDoc("<<\n/Length "+Pdf::toPdf(fon2.length()+1)+"\n");
+ PutDoc("/Length1 "+Pdf::toPdf(len1+1)+"\n");
+ PutDoc("/Length2 "+Pdf::toPdf(hexData.length())+"\n");
+ if(static_cast<int>(fon.length()-len2) == -1)
+ PutDoc("/Length3 0\n");
+ else
+ PutDoc("/Length3 "+Pdf::toPdf(fon.length()-len2)+"\n");
+ if (Options.Compress)
+ PutDoc("/Filter /FlateDecode\n");
+ PutDoc(">>\nstream\n"+EncStream(fon2, embeddedFontObject)+"\nendstream");
+ writer.endObj(embeddedFontObject);
+ return embeddedFontObject;
}
PdfId PDFLibCore::PDF_EmbedType1BinaryFontObject(const QByteArray& bb)
{
- PdfId embeddedFontObject = writer.newObject();
- QByteArray fon;
- writer.startObj(embeddedFontObject);
- int posi;
- for (posi = 6; posi < bb.size(); ++posi)
- {
- if ((bb[posi] == static_cast<char>(0x80)) && (static_cast<int>(bb[posi+1]) == 2))
- break;
- fon += bb[posi];
- }
- int len1 = fon.length();
- int ulen;
- ulen = bb[posi+2] & 0xff;
- ulen |= (bb[posi+3] << 8) & 0xff00;
- ulen |= (bb[posi+4] << 16) & 0xff0000;
- ulen |= (bb[posi+5] << 24) & 0xff000000;
- if (ulen > bb.size())
- ulen = bb.size()-7;
- posi += 6;
- for (int j = 0; j < ulen; ++j)
- fon += bb[posi++];
- posi += 6;
- int len2 = fon.length()-len1;
- for (int j = posi; j < bb.size(); ++j)
- {
- if ((bb[j] == static_cast<char>(0x80)) && (static_cast<int>(bb[j+1]) == 3))
- break;
- if (bb[j] == '\r')
- fon += "\n";
- else
- fon += bb[j];
- }
- int len3 = fon.length()-len2-len1;
- if (Options.Compress)
- fon = CompressArray(fon);
- PutDoc("<<\n/Length "+Pdf::toPdf(fon.length()+1)+"\n");
- PutDoc("/Length1 "+Pdf::toPdf(len1)+"\n");
- PutDoc("/Length2 "+Pdf::toPdf(len2)+"\n");
- PutDoc("/Length3 "+Pdf::toPdf(len3)+"\n");
- if (Options.Compress)
- PutDoc("/Filter /FlateDecode\n");
- PutDoc(">>\nstream\n"+EncStream(fon,embeddedFontObject)+"\nendstream");
- writer.endObj(embeddedFontObject);
- return embeddedFontObject;
+ PdfId embeddedFontObject = writer.newObject();
+ QByteArray fon;
+ writer.startObj(embeddedFontObject);
+ int posi;
+ for (posi = 6; posi < bb.size(); ++posi)
+ {
+ if ((bb[posi] == static_cast<char>(0x80)) && (static_cast<int>(bb[posi+1]) == 2))
+ break;
+ fon += bb[posi];
+ }
+ int len1 = fon.length();
+ int ulen;
+ ulen = bb[posi+2] & 0xff;
+ ulen |= (bb[posi+3] << 8) & 0xff00;
+ ulen |= (bb[posi+4] << 16) & 0xff0000;
+ ulen |= (bb[posi+5] << 24) & 0xff000000;
+ if (ulen > bb.size())
+ ulen = bb.size()-7;
+ posi += 6;
+ for (int j = 0; j < ulen; ++j)
+ fon += bb[posi++];
+ posi += 6;
+ int len2 = fon.length()-len1;
+ for (int j = posi; j < bb.size(); ++j)
+ {
+ if ((bb[j] == static_cast<char>(0x80)) && (static_cast<int>(bb[j+1]) == 3))
+ break;
+ if (bb[j] == '\r')
+ fon += "\n";
+ else
+ fon += bb[j];
+ }
+ int len3 = fon.length()-len2-len1;
+ if (Options.Compress)
+ fon = CompressArray(fon);
+ PutDoc("<<\n/Length "+Pdf::toPdf(fon.length()+1)+"\n");
+ PutDoc("/Length1 "+Pdf::toPdf(len1)+"\n");
+ PutDoc("/Length2 "+Pdf::toPdf(len2)+"\n");
+ PutDoc("/Length3 "+Pdf::toPdf(len3)+"\n");
+ if (Options.Compress)
+ PutDoc("/Filter /FlateDecode\n");
+ PutDoc(">>\nstream\n"+EncStream(fon,embeddedFontObject)+"\nendstream");
+ writer.endObj(embeddedFontObject);
+ return embeddedFontObject;
}
PdfId PDFLibCore::PDF_EmbedFontObject(const QString& name, ScFace& face)
{
- PdfId embeddedFontObject = 0;
- if (Options.EmbedList.contains(name))
- {
- ScFace::FontFormat fformat = face.format();
- QByteArray bb;
- face.RawData(bb);
- if (fformat == ScFace::PFB)
- {
- embeddedFontObject = PDF_EmbedType1BinaryFontObject(bb);
- }
- if (fformat == ScFace::PFA)
- {
- embeddedFontObject = PDF_EmbedType1AsciiFontObject(bb);
- }
- if (fformat == ScFace::SFNT || fformat == ScFace::TTCF)
- {
- QByteArray subtype;
- if (face.type() == ScFace::OTF)
- {
- subtype = "/CIDFontType0C";
- bb = sfnt::getTable(bb, "CFF ");
- dumpCFF(face.psName() + ".cff", cff::CFF(bb));
- bb = cff::extractFace(bb, 0);
- dumpCFF(face.psName() + "full.cff", cff::CFF(bb));
- }
- embeddedFontObject = PDF_EmbedFontObject(bb, subtype);
- }
- }
- return embeddedFontObject;
+ PdfId embeddedFontObject = 0;
+ if (Options.EmbedList.contains(name))
+ {
+ ScFace::FontFormat fformat = face.format();
+ QByteArray bb;
+ face.RawData(bb);
+ if (fformat == ScFace::PFB)
+ {
+ embeddedFontObject = PDF_EmbedType1BinaryFontObject(bb);
+ }
+ if (fformat == ScFace::PFA)
+ {
+ embeddedFontObject = PDF_EmbedType1AsciiFontObject(bb);
+ }
+ if (fformat == ScFace::SFNT || fformat == ScFace::TTCF)
+ {
+ QByteArray subtype;
+ if (face.type() == ScFace::OTF)
+ {
+ subtype = "/CIDFontType0C";
+ bb = sfnt::getTable(bb, "CFF ");
+ dumpCFF(face.psName() + ".cff", cff::CFF(bb));
+ bb = cff::extractFace(bb, 0);
+ dumpCFF(face.psName() + "full.cff", cff::CFF(bb));
+ }
+ embeddedFontObject = PDF_EmbedFontObject(bb, subtype);
+ }
+ }
+ return embeddedFontObject;
}
void PDFLibCore::PDF_Begin_WriteUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& ReallyUsed)
{
- qDebug() << "embed list:" << QStringList(Options.EmbedList).join(", ");
- qDebug() << "subset list:" << QStringList(Options.SubsetList).join(", ");
- qDebug() << "outline list:" << QStringList(Options.OutlineList).join(", ");
- QMap<QString,QMap<uint, FPointArray> >::ConstIterator it;
- int a = 0;
- for (it = ReallyUsed.cbegin(); it != ReallyUsed.cend(); ++it)
- {
- ScFace& face(AllFonts[it.key()]);
- ScFace::FontFormat fformat = face.format();
- PdfFont pdfFont;
- QByteArray fontName = QByteArray("Fo") + Pdf::toPdf(a);
-
- qDebug() << "pdf font" << it.key();
- if (Options.OutlineList.contains(it.key()))
- {
- pdfFont = PDF_WriteGlyphsAsXForms(fontName, face, it.value());
- }
- else
- {
- if (Options.SubsetList.contains(it.key()))
- {
- if (fformat == ScFace::SFNT || fformat == ScFace::TTCF)
- {
- if (face.type() == ScFace::TTF)
- {
- pdfFont = PDF_WriteTtfSubsetFont(fontName, face, it.value());
- }
- else
- {
- pdfFont = PDF_WriteCffSubsetFont(fontName, face, it.value());
- }
- }
- else
- {
- pdfFont = PDF_WriteType3Font(fontName, face, it.value());
- }
- }
- else
- {
- PdfId embeddedFontObject = PDF_EmbedFontObject(it.key(), face);
-
- PdfId fontDescriptor = PDF_WriteFontDescriptor(fontName, face, fformat, embeddedFontObject);
-
- ScFace::FaceEncoding gl;
- face.glyphNames(gl);
-
- QByteArray baseFont = Pdf::toName(sanitizeFontName(face.psName()));
-
- if ((face.isSymbolic() || !face.hasNames() || Options.Version == PDFOptions::PDFVersion_X4 || face.type() == ScFace::OTF) &&
- (fformat == ScFace::SFNT || fformat == ScFace::TTCF))
- {
- pdfFont = PDF_EncodeCidFont(fontName, face, baseFont, fontDescriptor, gl, QMap<uint,uint>());
- }
- else
- {
- QByteArray subtype = (fformat == ScFace::SFNT || fformat == ScFace::TTCF) ? "/TrueType" : "/Type1";
- pdfFont = PDF_EncodeSimpleFont(fontName, face, baseFont, subtype, embeddedFontObject != 0, fontDescriptor, gl);
- }
- }
- pdfFont.usage = Used_in_Content;
- QString meth;
- switch (pdfFont.method)
- {
- case Use_System:
- meth = "Systemfont (no embedding)"; break;
- case Use_Embedded:
- meth = "Embed"; break;
- case Use_Subset:
- meth = "Subset"; break;
- case Use_Type3:
- meth = "Subset as Type3 font"; break;
- case Use_XForm:
- meth = "Outline (PDF XForm)"; break;
- default:
- meth = "?"; break;
- }
- qDebug() << pdfFont.name << "uses method" << meth << "and encoding" << pdfFont.encoding;
- UsedFontsP.insert(it.key(), pdfFont);
- a++;
- }
- }
+ qDebug() << "embed list:" << QStringList(Options.EmbedList).join(", ");
+ qDebug() << "subset list:" << QStringList(Options.SubsetList).join(", ");
+ qDebug() << "outline list:" << QStringList(Options.OutlineList).join(", ");
+ QMap<QString,QMap<uint, FPointArray> >::ConstIterator it;
+ int a = 0;
+ for (it = ReallyUsed.cbegin(); it != ReallyUsed.cend(); ++it)
+ {
+ ScFace& face(AllFonts[it.key()]);
+ ScFace::FontFormat fformat = face.format();
+ PdfFont pdfFont;
+ QByteArray fontName = QByteArray("Fo") + Pdf::toPdf(a);
+
+ qDebug() << "pdf font" << it.key();
+ if (Options.OutlineList.contains(it.key()))
+ {
+ pdfFont = PDF_WriteGlyphsAsXForms(fontName, face, it.value());
+ }
+ else
+ {
+ if (Options.SubsetList.contains(it.key()))
+ {
+ if (fformat == ScFace::SFNT || fformat == ScFace::TTCF)
+ {
+ if (face.type() == ScFace::TTF)
+ {
+ pdfFont = PDF_WriteTtfSubsetFont(fontName, face, it.value());
+ }
+ else
+ {
+ pdfFont = PDF_WriteCffSubsetFont(fontName, face, it.value());
+ }
+ }
+ else
+ {
+ pdfFont = PDF_WriteType3Font(fontName, face, it.value());
+ }
+ }
+ else
+ {
+ PdfId embeddedFontObject = PDF_EmbedFontObject(it.key(), face);
+
+ PdfId fontDescriptor = PDF_WriteFontDescriptor(fontName, face, fformat, embeddedFontObject);
+
+ ScFace::FaceEncoding gl;
+ face.glyphNames(gl);
+
+ QByteArray baseFont = Pdf::toName(sanitizeFontName(face.psName()));
+
+ if ((face.isSymbolic() || !face.hasNames() || Options.Version == PDFOptions::PDFVersion_X4 || face.type() == ScFace::OTF) &&
+ (fformat == ScFace::SFNT || fformat == ScFace::TTCF))
+ {
+ pdfFont = PDF_EncodeCidFont(fontName, face, baseFont, fontDescriptor, gl, QMap<uint,uint>());
+ }
+ else
+ {
+ QByteArray subtype = (fformat == ScFace::SFNT || fformat == ScFace::TTCF) ? "/TrueType" : "/Type1";
+ pdfFont = PDF_EncodeSimpleFont(fontName, face, baseFont, subtype, embeddedFontObject != 0, fontDescriptor, gl);
+ }
+ }
+ pdfFont.usage = Used_in_Content;
+ QString meth;
+ switch (pdfFont.method)
+ {
+ case Use_System:
+ meth = "Systemfont (no embedding)"; break;
+ case Use_Embedded:
+ meth = "Embed"; break;
+ case Use_Subset:
+ meth = "Subset"; break;
+ case Use_Type3:
+ meth = "Subset as Type3 font"; break;
+ case Use_XForm:
+ meth = "Outline (PDF XForm)"; break;
+ default:
+ meth = "?"; break;
+ }
+ qDebug() << pdfFont.name << "uses method" << meth << "and encoding" << pdfFont.encoding;
+ UsedFontsP.insert(it.key(), pdfFont);
+ a++;
+ }
+ }
}
void PDFLibCore::PDF_Begin_Colors()
@@ -2011,7 +2011,7 @@
QMap<QString,LPIData>::const_iterator itlp;
for (itlp = Options.LPISettings.constBegin(); itlp != Options.LPISettings.constEnd(); ++itlp)
{
- PutDoc(Pdf::toName(itlp.key()) + "\n<<\n/Type /Halftone\n/HalftoneType 1\n/Frequency ");
+ PutDoc(Pdf::toName(itlp.key()) + "\n<<\n/Type /Halftone\n/HalftoneType 1\n/Frequency ");
PutDoc(Pdf::toPdf(itlp.value().Frequency)+"\n/Angle "+Pdf::toPdf(itlp.value().Angle)+"\n/SpotFunction ");
QByteArray func ("");
switch (itlp.value().SpotFunc)
@@ -2035,8 +2035,8 @@
PutDoc(func + "\n>>\n");
}
PutDoc("/Default\n<<\n/Type /Halftone\n/HalftoneType 1\n/Frequency 50\n/Angle 45\n/SpotFunction /Round\n>>\n");
- PutDoc(">>");
- writer.endObj(halftones);
+ PutDoc(">>");
+ writer.endObj(halftones);
HTName = ResNam+Pdf::toPdf(ResCount);
Transpar[HTName] = writeGState("/HT "+Pdf::toPdf(halftones)+" 0 R\n");
ResCount++;
@@ -2062,8 +2062,8 @@
PutDoc("/N "+Pdf::toPdf(Options.SComp)+"\n");
PutDoc(">>\nstream\n");
EncodeArrayToStream(dataP, iccProfileObject);
- PutDoc("\nendstream");
- writer.endObj(iccProfileObject);
+ PutDoc("\nendstream");
+ writer.endObj(iccProfileObject);
PdfId iccColorspace = writer.newObject();
writer.startObj(iccColorspace);
dataD.ResName = ResNam+Pdf::toPdf(ResCount);
@@ -2098,17 +2098,17 @@
PutDoc("/Domain [0.0 1.0]\n");
PutDoc("/Range [0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0]\n");
PutDoc("/Length "+Pdf::toPdf(colorDesc.length()+1)+"\n");
- PutDoc(">>\nstream\n"+EncStream(colorDesc, separationFunction)+"\nendstream");
- writer.endObj(separationFunction);
+ PutDoc(">>\nstream\n"+EncStream(colorDesc, separationFunction)+"\nendstream");
+ writer.endObj(separationFunction);
PdfId separationColorspace= writer.newObject();
writer.startObj(separationColorspace);
PutDoc("[ /Separation ");
if (colorsToUse[itf.key()].isRegistrationColor())
PutDoc("/All");
else
- PutDoc(Pdf::toName(itf.key().simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" )));
- PutDoc(" /DeviceCMYK "+Pdf::toObjRef(separationFunction)+" ]");
- writer.endObj(separationColorspace);
+ PutDoc(Pdf::toName(itf.key().simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" )));
+ PutDoc(" /DeviceCMYK "+Pdf::toObjRef(separationFunction)+" ]");
+ writer.endObj(separationColorspace);
spotD.ResName = spotNam+Pdf::toPdf(spotCount);
spotD.ResNum = separationColorspace;
spotMap.insert(itf.key(), spotD);
@@ -2128,8 +2128,8 @@
PutDoc("/C0 [0 0 0 0] \n");
PutDoc("/C1 [1 1 1 1] \n");
PutDoc("/N 1\n");
- PutDoc(">>\n]");
- writer.endObj(registrationColorspace);
+ PutDoc(">>\n]");
+ writer.endObj(registrationColorspace);
spotD.ResName = spotNam+Pdf::toPdf(spotCount);
spotD.ResNum = registrationColorspace;
spotMapReg.insert("Register", spotD);
@@ -2152,7 +2152,7 @@
{
PdfId optionalContent = writer.newObject();
doc.Layers.levelToLayer(ll, Lnr);
- ocg.Name = ocgNam + Pdf::toPdf(ll.ID);
+ ocg.Name = ocgNam + Pdf::toPdf(ll.ID);
ocg.ObjNum = optionalContent;
ocg.visible = ll.isViewable;
OCGEntries.insert(ll.Name, ocg);
@@ -2174,8 +2174,8 @@
PutDoc("/OFF");
PutDoc(">>>>");
PutDoc("\n");
- PutDoc(">>");
- writer.endObj(optionalContent);
+ PutDoc(">>");
+ writer.endObj(optionalContent);
Lnr++;
}
}
@@ -2198,14 +2198,14 @@
pageData.AObjects.clear();
- for (int la = 0; la < doc.Layers.count(); ++la)
+ for (int la = 0; la < doc.Layers.count(); ++la)
{
doc.Layers.levelToLayer(ll, Lnr);
PItems = doc.MasterItems;
if ((ll.isPrintable) || (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers)))
{
if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers))
- PutPage("/OC /" + OCGEntries[ll.Name].Name + " BDC\n");
+ PutPage("/OC /" + OCGEntries[ll.Name].Name + " BDC\n");
for (int a = 0; a < PItems.count(); ++a)
{
Content = "";
@@ -2265,7 +2265,7 @@
PutPage("] " + Pdf::toPdf(ite->DashOffset)+" d\n");
}
else
- PutPage("[" + Pdf::toAscii(getDashString(ite->PLineArt, ite->lineWidth())) + "] 0 d\n");
+ PutPage("[" + Pdf::toAscii(getDashString(ite->PLineArt, ite->lineWidth())) + "] 0 d\n");
switch (ite->PLineEnd)
{
case Qt::FlatCap:
@@ -2820,31 +2820,31 @@
PutDoc("/BBox [ "+FToStr(-bleedLeft)+" "+FToStr(-Options.bleeds.bottom())+" "+FToStr(maxBoxX)+" "+FToStr(maxBoxY)+" ]\n");
// PutDoc("/BBox [ 0 0 "+FToStr(ActPageP->width())+" "+FToStr(ActPageP->height())+" ]\n");
- Pdf::ResourceDictionary dict;
- dict.XObject.unite(pageData.ImgObjects);
- dict.XObject.unite(pageData.XObjects);
- dict.Font = pageData.FObjects;
- dict.Shading = Shadings;
- dict.Pattern = Patterns;
- dict.ExtGState = Transpar;
- dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
- dict.ColorSpace.append(asColorSpace(spotMap.values()));
- writer.write("/Resources ");
- writer.write(dict);
-
+ Pdf::ResourceDictionary dict;
+ dict.XObject.unite(pageData.ImgObjects);
+ dict.XObject.unite(pageData.XObjects);
+ dict.Font = pageData.FObjects;
+ dict.Shading = Shadings;
+ dict.Pattern = Patterns;
+ dict.ExtGState = Transpar;
+ dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
+ dict.ColorSpace.append(asColorSpace(spotMap.values()));
+ writer.write("/Resources ");
+ writer.write(dict);
+
if (Options.Compress)
Content = CompressArray(Content);
PutDoc("/Length "+Pdf::toPdf(Content.length()+1));
if (Options.Compress)
PutDoc("\n/Filter /FlateDecode");
- PutDoc(" >>\nstream\n"+EncStream(Content, templateObject)+"\nendstream");
- writer.endObj(templateObject);
-
- int pIndex = doc.MasterPages.indexOf((ScPage* const) pag) + 1;
- QByteArray name = QByteArray("master_page_obj_%1_%2")
- .replace("%1", Pdf::toPdf(pIndex))
- .replace("%2", Pdf::toPdf(qHash(ite)));
- pageData.XObjects[name] = templateObject;
+ PutDoc(" >>\nstream\n"+EncStream(Content, templateObject)+"\nendstream");
+ writer.endObj(templateObject);
+
+ int pIndex = doc.MasterPages.indexOf((ScPage* const) pag) + 1;
+ QByteArray name = QByteArray("master_page_obj_%1_%2")
+ .replace("%1", Pdf::toPdf(pIndex))
+ .replace("%2", Pdf::toPdf(qHash(ite)));
+ pageData.XObjects[name] = templateObject;
}
if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers))
PutPage("EMC\n");
@@ -2887,8 +2887,8 @@
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n");
EncodeArrayToStream(array, thumbnail);
- PutDoc("\nendstream");
- writer.endObj(thumbnail);
+ PutDoc("\nendstream");
+ writer.endObj(thumbnail);
pageData.Thumb = thumbnail;
}
}
@@ -3103,13 +3103,13 @@
else
{
if ((doc.HasCMS) && (Options.UseProfiles))
- PutDoc("/CS " + ICCProfiles[Options.SolidProf].ICCArray + "\n");
+ PutDoc("/CS " + ICCProfiles[Options.SolidProf].ICCArray + "\n");
else
PutDoc("/CS /DeviceCMYK\n");
}
}
- PutDoc(">>");
- writer.endObj(Gobj);
+ PutDoc(">>");
+ writer.endObj(Gobj);
}
uint pageObject = writer.newObject();
writer.startObj(pageObject);
@@ -3278,8 +3278,8 @@
PutDoc(">>\n");
}
}
- PutDoc(">>");
- writer.endObj(pageObject);
+ PutDoc(">>");
+ writer.endObj(pageObject);
PageTree.Count++;
PageTree.Kids[physPage] = pageObject;
}
@@ -3292,8 +3292,8 @@
PutDoc(dictionary);
PutDoc(">>\nstream\n");
EncodeArrayToStream(stream, objNr);
- PutDoc("\nendstream");
- writer.endObj(objNr);
+ PutDoc("\nendstream");
+ writer.endObj(objNr);
}
@@ -3305,9 +3305,9 @@
if (!type.isEmpty())
PutDoc("/Type " + type + "\n");
PutDoc(dictionary);
- PutDoc(">>");
- writer.endObj(result);
- return result;
+ PutDoc(">>");
+ writer.endObj(result);
+ return result;
}
@@ -3343,9 +3343,9 @@
{
double bbWidth = ActPageP->width() + bleedLeft + bleedRight;
double bbHeight = ActPageP->height() + bleedBottom + bleedTop;
- const char* B = " ";
- PutPage(FToStr(-bleedLeft) +B+ FToStr(-bleedBottom) +B+
- FToStr(bbWidth) +B+ FToStr(bbHeight) + " re W n\n");
+ const char* B = " ";
+ PutPage(FToStr(-bleedLeft) +B+ FToStr(-bleedBottom) +B+
+ FToStr(bbWidth) +B+ FToStr(bbHeight) + " re W n\n");
}
if ( (Options.MirrorH) && (!pag->MPageNam.isEmpty()) )
PutPage("-1 0 0 1 "+FToStr(ActPageP->width())+" 0 cm\n");
@@ -3402,9 +3402,9 @@
continue;
if ((!pag->pageName().isEmpty()) && (ite->OwnPage != static_cast<int>(pag->pageNr())) && (ite->OwnPage != -1))
continue;
- QByteArray name = QByteArray("/master_page_obj_%1_%2")
- .replace("%1", Pdf::toPdf(mPageIndex))
- .replace("%2", Pdf::toPdf(qHash(ite)));
+ QByteArray name = QByteArray("/master_page_obj_%1_%2")
+ .replace("%1", Pdf::toPdf(mPageIndex))
+ .replace("%2", Pdf::toPdf(qHash(ite)));
if ((!ite->asTextFrame()) && (!ite->asPathText()) && (!ite->asTable()))
{
if (((layer.transparency != 1) || (layer.blendMode != 0)) && ((Options.Version >= PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_X4)))
@@ -3440,8 +3440,8 @@
PutDoc("/S /Transparency\n");
PutDoc("/I false\n");
PutDoc("/K false\n");
- PutDoc(">>");
- writer.endObj(Gobj);
+ PutDoc(">>");
+ writer.endObj(Gobj);
QByteArray ShName = ResNam+QByteArray::number(ResCount);
ResCount++;
Transpar[ShName] = writeGState("/CA "+FToStr(layer.transparency)+"\n"
@@ -3463,9 +3463,9 @@
PutDoc("/Length "+QByteArray::number(content.length()+1));
if (Options.Compress)
PutDoc("\n/Filter /FlateDecode");
- PutDoc(" >>\nstream\n"+EncStream(content, formObject)+"\nendstream");
- writer.endObj(formObject);
- QByteArray name = ResNam+QByteArray::number(ResCount);
+ PutDoc(" >>\nstream\n"+EncStream(content, formObject)+"\nendstream");
+ writer.endObj(formObject);
+ QByteArray name = ResNam+QByteArray::number(ResCount);
ResCount++;
pageData.XObjects[name] = formObject;
PutPage("q\n");
@@ -3518,8 +3518,8 @@
PutDoc("/S /Transparency\n");
PutDoc("/I false\n");
PutDoc("/K false\n");
- PutDoc(">>");
- writer.endObj(Gobj);
+ PutDoc(">>");
+ writer.endObj(Gobj);
QByteArray ShName = ResNam+Pdf::toPdf(ResCount);
ResCount++;
Transpar[ShName] = writeGState("/CA "+FToStr(layer.transparency)+"\n"
@@ -3541,13 +3541,13 @@
PutDoc("/Length "+Pdf::toPdf(inh.length()+1));
if (Options.Compress)
PutDoc("\n/Filter /FlateDecode");
- PutDoc(" >>\nstream\n"+EncStream(inh, formObject)+"\nendstream");
- writer.endObj(formObject);
- QByteArray name = Pdf::toPdfDocEncoding(layer.Name.simplified().replace(QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_")) + Pdf::toPdf(layer.ID) + Pdf::toPdf(PNr);
+ PutDoc(" >>\nstream\n"+EncStream(inh, formObject)+"\nendstream");
+ writer.endObj(formObject);
+ QByteArray name = Pdf::toPdfDocEncoding(layer.Name.simplified().replace(QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_")) + Pdf::toPdf(layer.ID) + Pdf::toPdf(PNr);
pageData.XObjects[name] = formObject;
PutPage("q\n");
PutPage(Pdf::toName(ShName) + " gs\n");
- PutPage(Pdf::toName(name) + " Do\n");
+ PutPage(Pdf::toName(name) + " Do\n");
PutPage("Q\n");
}
if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers))
@@ -3599,17 +3599,17 @@
}
else
PutDoc("/BBox [ "+FToStr(-bleedLeft)+" "+FToStr(-Options.bleeds.bottom())+" "+FToStr(maxBoxX)+" "+FToStr(maxBoxY)+" ]\n");
- PutDoc("/Resources ");
- Pdf::ResourceDictionary dict;
- dict.XObject.unite(pageData.ImgObjects);
- dict.XObject.unite(pageData.XObjects);
- dict.Font = pageData.FObjects;
- dict.Shading = Shadings;
- dict.Pattern = Patterns;
- dict.ExtGState = Transpar;
- dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
- dict.ColorSpace.append(asColorSpace(spotMap.values()));
- writer.write(dict);
+ PutDoc("/Resources ");
+ Pdf::ResourceDictionary dict;
+ dict.XObject.unite(pageData.ImgObjects);
+ dict.XObject.unite(pageData.XObjects);
+ dict.Font = pageData.FObjects;
+ dict.Shading = Shadings;
+ dict.Pattern = Patterns;
+ dict.ExtGState = Transpar;
+ dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
+ dict.ColorSpace.append(asColorSpace(spotMap.values()));
+ writer.write(dict);
PutDoc(">>\n");
if (Options.Compress)
@@ -3617,8 +3617,8 @@
PutDoc("/Length "+QByteArray::number(data.length()+1));
if (Options.Compress)
PutDoc("\n/Filter /FlateDecode");
- PutDoc(" >>\nstream\n"+EncStream(data, formObject)+"\nendstream");
- writer.endObj(formObject);
+ PutDoc(" >>\nstream\n"+EncStream(data, formObject)+"\nendstream");
+ writer.endObj(formObject);
QByteArray name = ResNam+QByteArray::number(ResCount);
ResCount++;
pageData.XObjects[name] = formObject;
@@ -3641,8 +3641,8 @@
else
PutDoc("/I false\n");
PutDoc("/K false\n");
- PutDoc(">>");
- writer.endObj(Gobj);
+ PutDoc(">>");
+ writer.endObj(Gobj);
if (controlItem != NULL)
{
retString += "q\n";
@@ -3657,7 +3657,7 @@
+ "/SMask /None\n/AIS false\n/OPM 1\n"
+ "/BM /" + blendMode(blend) + "\n");
retString += "q\n";
- retString += Pdf::toName(ShName) + " gs\n";
+ retString += Pdf::toName(ShName) + " gs\n";
}
PdfId formObject = writer.newObject();
writer.startObj(formObject);
@@ -3700,29 +3700,29 @@
else
PutDoc("/BBox [ "+FToStr(-bleedLeft)+" "+FToStr(-Options.bleeds.bottom())+" "+FToStr(maxBoxX)+" "+FToStr(maxBoxY)+" ]\n");
PutDoc("/Group "+Pdf::toObjRef(Gobj)+"\n");
- PutDoc("/Resources ");
- Pdf::ResourceDictionary dict;
- dict.XObject.unite(pageData.ImgObjects);
- dict.XObject.unite(pageData.XObjects);
- dict.Font = pageData.FObjects;
- dict.Shading = Shadings;
- dict.Pattern = Patterns;
- dict.ExtGState = Transpar;
- dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
- dict.ColorSpace.append(asColorSpace(spotMap.values()));
- writer.write(dict);
-
- if (Options.Compress)
+ PutDoc("/Resources ");
+ Pdf::ResourceDictionary dict;
+ dict.XObject.unite(pageData.ImgObjects);
+ dict.XObject.unite(pageData.XObjects);
+ dict.Font = pageData.FObjects;
+ dict.Shading = Shadings;
+ dict.Pattern = Patterns;
+ dict.ExtGState = Transpar;
+ dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
+ dict.ColorSpace.append(asColorSpace(spotMap.values()));
+ writer.write(dict);
+
+ if (Options.Compress)
data = CompressArray(data);
PutDoc("/Length "+Pdf::toPdf(data.length()+1));
if (Options.Compress)
PutDoc("\n/Filter /FlateDecode");
- PutDoc(" >>\nstream\n" + EncStream(data, formObject) + "\nendstream");
- writer.endObj(formObject);
+ PutDoc(" >>\nstream\n" + EncStream(data, formObject) + "\nendstream");
+ writer.endObj(formObject);
QByteArray name = ResNam+Pdf::toPdf(ResCount);
ResCount++;
pageData.XObjects[name] = formObject;
- retString += Pdf::toName(name) + " Do\n";
+ retString += Pdf::toName(name) + " Do\n";
retString += "Q\n";
return retString;
}
@@ -3786,10 +3786,10 @@
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n");
int bytesWritten = WriteFlateImageToStream(img, maskObj, ColorSpaceGray, false);
- PutDoc("\nendstream");
- writer.endObj(maskObj);
+ PutDoc("\nendstream");
+ writer.endObj(maskObj);
writer.startObj(lengthObj);
- PutDoc(" " + Pdf::toPdf(bytesWritten));
+ PutDoc(" " + Pdf::toPdf(bytesWritten));
writer.endObj(lengthObj);
PdfId colObj = writer.newObject();
@@ -3849,7 +3849,7 @@
WriteImageToStream(col, colObj, ColorSpaceCMYK, false);
PutDoc("\nendstream");
}
- writer.endObj(colObj);
+ writer.endObj(colObj);
QByteArray colRes = ResNam+Pdf::toPdf(ResCount);
pageData.ImgObjects[colRes] = colObj;
ResCount++;
@@ -3868,7 +3868,7 @@
+ "/AIS false\n/OPM 1\n"
+ "/BM /" + blendMode(ite->softShadowBlendMode()) + "\n");
}
- tmp += Pdf::toName(ShName) + " gs\n";
+ tmp += Pdf::toName(ShName) + " gs\n";
tmp += Pdf::toName(colRes) + " Do Q\n";
return tmp;
@@ -5676,7 +5676,7 @@
return true;
}
- PdfFont pdfFont = UsedFontsP[style.font().replacementName()];
+ PdfFont pdfFont = UsedFontsP[style.font().replacementName()];
uint glyph = glyphs->glyph;
if (glyph == (ScFace::CONTROL_GLYPHS + SpecialChars::NBSPACE.unicode()) ||
@@ -5757,7 +5757,7 @@
}
tmp2 += "S\n";
}
-
+
if (pdfFont.method == Use_XForm)
{
if (glyph != style.font().char2CMap(QChar(' ')))
@@ -5808,8 +5808,8 @@
tmp2 += "1 0 0 1 0 "+FToStr( (((tsz / 10.0) - (tsz / 10.0) * (glyphs->scaleV)) / (tsz / 10.0)) * -1)+" cm\n";
tmp2 += FToStr(qMax(glyphs->scaleH, 0.1))+" 0 0 "+FToStr(qMax(glyphs->scaleV, 0.1))+" 0 0 cm\n";
if (style.fillColor() != CommonStrings::None)
- tmp2 += pdfFont.name + Pdf::toPdf(glyph)+" Do\n";
-
+ tmp2 += pdfFont.name + Pdf::toPdf(glyph)+" Do\n";
+
if (style.effects() & ScStyle_Outline)
{
FPointArray gly = style.font().glyphOutline(glyph);
@@ -5863,23 +5863,23 @@
{
uint gid = glyphs->glyph;
uint fontNr = 65535;
- switch (pdfFont.encoding)
- {
- case Encode_256:
- gid = pdfFont.glyphmap[gid];
- fontNr = gid / 256;
- gid = gid % 256;
- break;
- case Encode_224:
- fontNr = gid / 224;
- gid = gid % 224 + 32;
- break;
- case Encode_Subset:
- gid = pdfFont.glyphmap[gid];
- break;
- case Encode_IdentityH:
- break;
- }
+ switch (pdfFont.encoding)
+ {
+ case Encode_256:
+ gid = pdfFont.glyphmap[gid];
+ fontNr = gid / 256;
+ gid = gid % 256;
+ break;
+ case Encode_224:
+ fontNr = gid / 224;
+ gid = gid % 224 + 32;
+ break;
+ case Encode_Subset:
+ gid = pdfFont.glyphmap[gid];
+ break;
+ case Encode_IdentityH:
+ break;
+ }
if (fontNr == 65535)
tmp+= pdfFont.name + " " + FToStr(tsz / 10.0)+" Tf\n";
else
@@ -5927,7 +5927,7 @@
if (glyphs->scaleV != 1.0)
tmp2 += "1 0 0 1 0 "+FToStr( (((tsz / 10.0) - (tsz / 10.0) * (glyphs->scaleV)) / (tsz / 10.0)) * -1)+" cm\n";
tmp2 += FToStr(qMax(glyphs->scaleH, 0.1))+" 0 0 "+FToStr(qMax(glyphs->scaleV, 0.1))+" 0 0 cm\n";
- /* paint outline */
+ /* paint outline */
FPointArray gly = style.font().glyphOutline(glyph);
QTransform mat;
mat.scale(0.1, 0.1);
@@ -5979,23 +5979,23 @@
tmp += FToStr(qMax(glyphs->scaleH, 0.1))+" 0 0 "+FToStr(qMax(glyphs->scaleV, 0.1))+" "+FToStr(x+ glyphs->xoffset)+" "+FToStr(-y- glyphs->yoffset+(style.fontSize() / 10.0) * (style.baselineOffset() / 1000.0))+" Tm\n";
}
else
- {
- tmp += FToStr(qMax(glyphs->scaleH, 0.1))+" 0 0 "+FToStr(qMax(glyphs->scaleV, 0.1))+" 0 0 Tm\n";
- }
- if (pdfFont.method != Use_Type3 || style.fillColor() != CommonStrings::None)
- {
- switch (pdfFont.encoding)
- {
- case Encode_224:
- case Encode_256:
- tmp += Pdf::toHexString8(gid) + " Tj\n";
- break;
- case Encode_IdentityH:
- default:
- tmp += Pdf::toHexString16(gid) + " Tj\n";
- break;
- }
- }
+ {
+ tmp += FToStr(qMax(glyphs->scaleH, 0.1))+" 0 0 "+FToStr(qMax(glyphs->scaleV, 0.1))+" 0 0 Tm\n";
+ }
+ if (pdfFont.method != Use_Type3 || style.fillColor() != CommonStrings::None)
+ {
+ switch (pdfFont.encoding)
+ {
+ case Encode_224:
+ case Encode_256:
+ tmp += Pdf::toHexString8(gid) + " Tj\n";
+ break;
+ case Encode_IdentityH:
+ default:
+ tmp += Pdf::toHexString16(gid) + " Tj\n";
+ break;
+ }
+ }
}
}
if ((style.effects() & ScStyle_Strikethrough) && (chstr != SpecialChars::PARSEP))
@@ -6533,9 +6533,9 @@
PutDoc(">>\n");
PutDoc(">>\n");
PutDoc(">>\n");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
-
+
PdfId formObject = writer.newObject();
writer.startObj(formObject);
PutDoc("<<\n/Type /XObject\n/Subtype /Form\n");
@@ -6546,15 +6546,15 @@
PutDoc("/BBox [0 0 "+FToStr(ActPageP->width())+" "+FToStr(ActPageP->height())+" ]\n");
else
PutDoc("/BBox ["+FToStr(-lw / 2.0)+" "+FToStr(lw / 2.0)+" "+FToStr(currItem->width()+lw)+" "+FToStr(-(currItem->height()+lw))+" ]\n");
- PutDoc("/Resources ");
- Pdf::ResourceDictionary dict;
- dict.Pattern = Patterns;
- dict.XObject.unite(pageData.ImgObjects);
- dict.XObject.unite(pageData.XObjects);
- writer.write(dict);
+ PutDoc("/Resources ");
+ Pdf::ResourceDictionary dict;
+ dict.Pattern = Patterns;
+ dict.XObject.unite(pageData.ImgObjects);
+ dict.XObject.unite(pageData.XObjects);
+ writer.write(dict);
PutDoc("\n");
- QByteArray stre = "q\n";
+ QByteArray stre = "q\n";
if (currItem->isGroup())
{
QTransform mpa;
@@ -6579,8 +6579,8 @@
PutDoc("/Length "+Pdf::toPdf(stre.length())+"\n");
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
- PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
- writer.endObj(formObject);
+ PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
+ writer.endObj(formObject);
pageData.XObjects[ResNam+Pdf::toPdf(ResCount)] = formObject;
ResCount++;
GXName = ResNam+Pdf::toPdf(ResCount);
@@ -6616,14 +6616,14 @@
PutDoc("/BBox [0 0 "+FToStr(ActPageP->width())+" "+FToStr(ActPageP->height())+" ]\n");
else
PutDoc("/BBox [0 0 "+FToStr(currItem->width())+" "+FToStr(-(currItem->height()))+" ]\n");
- PutDoc("/Resources ");
- Pdf::ResourceDictionary dict;
- dict.Pattern = Patterns;
- dict.XObject.unite(pageData.ImgObjects);
- dict.XObject.unite(pageData.XObjects);
- writer.write(dict);
+ PutDoc("/Resources ");
+ Pdf::ResourceDictionary dict;
+ dict.Pattern = Patterns;
+ dict.XObject.unite(pageData.ImgObjects);
+ dict.XObject.unite(pageData.XObjects);
+ writer.write(dict);
PutDoc("\n");
-
+
QByteArray stre = "q\n";
if ((currItem->isGroup()) || (currItem->itemType() == PageItem::Symbol))
{
@@ -6642,8 +6642,8 @@
PutDoc("/Length "+Pdf::toPdf(stre.length())+"\n");
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
- PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
- writer.endObj(formObject);
+ PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
+ writer.endObj(formObject);
pageData.XObjects[ResNam+Pdf::toPdf(ResCount)] = formObject;
ResCount++;
GXName = ResNam+Pdf::toPdf(ResCount);
@@ -6869,24 +6869,24 @@
PutDoc("/Matrix ["+FToStr(mpa.m11())+" "+FToStr(mpa.m12())+" "+FToStr(mpa.m21())+" "+FToStr(mpa.m22())+" "+FToStr(mpa.dx())+" "+FToStr(mpa.dy())+"]\n");
PutDoc("/XStep "+FToStr(pat->width)+"\n");
PutDoc("/YStep "+FToStr(pat->height)+"\n");
- PutDoc("/Resources ");
-
- Pdf::ResourceDictionary dict;
- dict.XObject.unite(pageData.ImgObjects);
- dict.XObject.unite(pageData.XObjects);
- dict.Font = pageData.FObjects;
- dict.Shading = Shadings;
- dict.Pattern = Patterns;
- dict.ExtGState = Transpar;
- dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
- dict.ColorSpace.append(asColorSpace(spotMap.values()));
- writer.write(dict);
-
+ PutDoc("/Resources ");
+
+ Pdf::ResourceDictionary dict;
+ dict.XObject.unite(pageData.ImgObjects);
+ dict.XObject.unite(pageData.XObjects);
+ dict.Font = pageData.FObjects;
+ dict.Shading = Shadings;
+ dict.Pattern = Patterns;
+ dict.ExtGState = Transpar;
+ dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
+ dict.ColorSpace.append(asColorSpace(spotMap.values()));
+ writer.write(dict);
+
PutDoc("/Length "+Pdf::toPdf(tmp2.length()));
if (Options.Compress)
PutDoc("\n/Filter /FlateDecode");
- PutDoc(" >>\nstream\n"+EncStream(tmp2, patObject)+"\nendstream");
- writer.endObj(patObject);
+ PutDoc(" >>\nstream\n"+EncStream(tmp2, patObject)+"\nendstream");
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
QByteArray tmp;
if ((forArrow) || (kind != 1))
@@ -7051,16 +7051,16 @@
PutDoc("/Length "+Pdf::toPdf(dat.length())+"\n");
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
- PutDoc(">>\nstream\n"+EncStream(dat, shadeObjectT)+"\nendstream");
- writer.endObj(shadeObjectT);
-
+ PutDoc(">>\nstream\n"+EncStream(dat, shadeObjectT)+"\nendstream");
+ writer.endObj(shadeObjectT);
+
PdfId patObject = writer.newObject();
writer.startObj(patObject);
PutDoc("<<\n/Type /Pattern\n");
PutDoc("/PatternType 2\n");
PutDoc("/Shading "+Pdf::toPdf(shadeObjectT)+" 0 R\n");
PutDoc(">>");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
PdfId formObject = writer.newObject();
writer.startObj(formObject);
@@ -7069,13 +7069,13 @@
PutDoc("/Group << /S /Transparency /CS /DeviceGray >>\n");
double lw = c->lineWidth();
PutDoc("/BBox ["+FToStr(-lw / 2.0)+" "+FToStr(lw / 2.0)+" "+FToStr(c->width()+lw)+" "+FToStr(-(c->height()+lw))+" ]\n");
- PutDoc("/Resources ");
-
- Pdf::ResourceDictionary dict;
- dict.Pattern = Patterns;
- writer.write(dict);
-
- QByteArray stre = "q\n"+SetClipPath(c)+"h\n";
+ PutDoc("/Resources ");
+
+ Pdf::ResourceDictionary dict;
+ dict.Pattern = Patterns;
+ writer.write(dict);
+
+ QByteArray stre = "q\n"+SetClipPath(c)+"h\n";
stre += FToStr(fabs(c->lineWidth()))+" w\n";
stre += "/Pattern cs\n";
stre += "/Pattern"+Pdf::toPdf(patObject)+" scn\nf*\n";
@@ -7085,8 +7085,8 @@
PutDoc("/Length "+Pdf::toPdf(stre.length())+"\n");
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
- PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
- writer.endObj(shadeObjectT);
+ PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
+ writer.endObj(shadeObjectT);
pageData.XObjects[ResNam+Pdf::toPdf(ResCount)] = formObject;
ResCount++;
QByteArray GXName = ResNam+Pdf::toPdf(ResCount);
@@ -7124,8 +7124,8 @@
PutDoc("/ColorSpace [ /DeviceN [ /Cyan /Magenta /Yellow /Black");
for (int sc = 0; sc < spotColorSet.count(); sc++)
{
- PutDoc(" " + Pdf::toName(spotColorSet.at(sc).simplified()));
- // " /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
+ PutDoc(" " + Pdf::toName(spotColorSet.at(sc).simplified()));
+ // " /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
entx += " 0 1";
}
PutDoc(" ]\n");
@@ -7182,9 +7182,9 @@
PutDoc("/Length "+Pdf::toPdf(dat.length())+"\n");
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
- PutDoc(">>\nstream\n"+EncStream(dat, shadeObject)+"\nendstream");
- writer.endObj(shadeObject);
-
+ PutDoc(">>\nstream\n"+EncStream(dat, shadeObject)+"\nendstream");
+ writer.endObj(shadeObject);
+
PdfId patObject = writer.newObject();
writer.startObj(patObject);
PutDoc("<<\n/Type /Pattern\n");
@@ -7210,8 +7210,8 @@
}
PutDoc("/Matrix ["+FToStr(mpa.m11())+" "+FToStr(mpa.m12())+" "+FToStr(mpa.m21())+" "+FToStr(mpa.m22())+" "+FToStr(mpa.dx())+" "+FToStr(mpa.dy())+"]\n");
PutDoc("/Shading "+Pdf::toPdf(shadeObject)+" 0 R\n");
- PutDoc(">>");
- writer.endObj(patObject);
+ PutDoc(">>");
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
if (spotMode)
{
@@ -7250,8 +7250,8 @@
colorDesc += "}\n";
PutDoc("/Range [0 1 0 1 0 1 0 1]\n");
PutDoc("/Length "+Pdf::toPdf(colorDesc.length()+1)+"\n");
- PutDoc(">>\nstream\n"+EncStream(colorDesc, spotObject)+"\nendstream");
- writer.endObj(spotObject);
+ PutDoc(">>\nstream\n"+EncStream(colorDesc, spotObject)+"\nendstream");
+ writer.endObj(spotObject);
}
QByteArray tmp;
if (((Options.Version >= PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_X4)) && (transparencyFound))
@@ -7385,14 +7385,14 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(dat, shadeObjectT)+"\nendstream");
- writer.endObj(shadeObjectT);
+ writer.endObj(shadeObjectT);
PdfId patObject = writer.newObject();
writer.startObj(patObject);
PutDoc("<<\n/Type /Pattern\n");
PutDoc("/PatternType 2\n");
PutDoc("/Shading "+Pdf::toPdf(shadeObjectT)+" 0 R\n");
PutDoc(">>");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
PdfId formObject = writer.newObject();
writer.startObj(formObject);
@@ -7402,12 +7402,12 @@
double lw = c->lineWidth();
PutDoc("/BBox ["+FToStr(-lw / 2.0)+" "+FToStr(lw / 2.0)+" "+FToStr(c->width()+lw)+" "+FToStr(-(c->height()+lw))+" ]\n");
PutDoc("/Resources ");
-
- Pdf::ResourceDictionary dict;
- dict.Pattern = Patterns;
- writer.write(dict);
-
- QByteArray stre = "q\n"+SetClipPath(c)+"h\n";
+
+ Pdf::ResourceDictionary dict;
+ dict.Pattern = Patterns;
+ writer.write(dict);
+
+ QByteArray stre = "q\n"+SetClipPath(c)+"h\n";
stre += FToStr(fabs(c->lineWidth()))+" w\n";
stre += "/Pattern cs\n";
stre += "/Pattern"+Pdf::toPdf(patObject)+" scn\nf*\n";
@@ -7418,7 +7418,7 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
- writer.endObj(formObject);
+ writer.endObj(formObject);
pageData.XObjects[ResNam+Pdf::toPdf(ResCount)] = formObject;
ResCount++;
QByteArray GXName = ResNam+Pdf::toPdf(ResCount);
@@ -7456,8 +7456,8 @@
PutDoc("/ColorSpace [ /DeviceN [ /Cyan /Magenta /Yellow /Black");
for (int sc = 0; sc < spotColorSet.count(); sc++)
{
- PutDoc(" " + Pdf::toName(spotColorSet.at(sc).simplified()));
- //" /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
+ PutDoc(" " + Pdf::toName(spotColorSet.at(sc).simplified()));
+ //" /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
entx += " 0 1";
}
PutDoc(" ]\n");
@@ -7513,7 +7513,7 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(dat, shadeObject)+"\nendstream");
- writer.endObj(shadeObject);
+ writer.endObj(shadeObject);
PdfId patObject = writer.newObject();
writer.startObj(patObject);
PutDoc("<<\n/Type /Pattern\n");
@@ -7540,7 +7540,7 @@
PutDoc("/Matrix ["+FToStr(mpa.m11())+" "+FToStr(mpa.m12())+" "+FToStr(mpa.m21())+" "+FToStr(mpa.m22())+" "+FToStr(mpa.dx())+" "+FToStr(mpa.dy())+"]\n");
PutDoc("/Shading "+Pdf::toPdf(shadeObject)+" 0 R\n");
PutDoc(">>");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
if (spotMode)
{
@@ -7580,7 +7580,7 @@
PutDoc("/Range [0 1 0 1 0 1 0 1]\n");
PutDoc("/Length "+Pdf::toPdf(colorDesc.length()+1)+"\n");
PutDoc(">>\nstream\n"+EncStream(colorDesc, spotObject)+"\nendstream");
- writer.endObj(spotObject);
+ writer.endObj(spotObject);
}
QByteArray tmp;
if (((Options.Version >= PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_X4)) && (transparencyFound))
@@ -7734,14 +7734,14 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(dat, shadeObjectT)+"\nendstream");
- writer.endObj(shadeObjectT);
+ writer.endObj(shadeObjectT);
PdfId patObject = writer.newObject();
writer.startObj(patObject);
PutDoc("<<\n/Type /Pattern\n");
PutDoc("/PatternType 2\n");
PutDoc("/Shading "+Pdf::toPdf(shadeObjectT)+" 0 R\n");
PutDoc(">>");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
PdfId formObject = writer.newObject();
writer.startObj(formObject);
@@ -7750,12 +7750,12 @@
PutDoc("/Group << /S /Transparency /CS /DeviceGray >>\n");
double lw = c->lineWidth();
PutDoc("/BBox ["+FToStr(-lw / 2.0)+" "+FToStr(lw / 2.0)+" "+FToStr(c->width()+lw)+" "+FToStr(-(c->height()+lw))+" ]\n");
- PutDoc("/Resources ");
-
- Pdf::ResourceDictionary dict;
- dict.Pattern = Patterns;
- writer.write(dict);
-
+ PutDoc("/Resources ");
+
+ Pdf::ResourceDictionary dict;
+ dict.Pattern = Patterns;
+ writer.write(dict);
+
QByteArray stre = "q\n"+SetClipPath(c)+"h\n";
stre += FToStr(fabs(c->lineWidth()))+" w\n";
stre += "/Pattern cs\n";
@@ -7767,7 +7767,7 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
- writer.endObj(formObject);
+ writer.endObj(formObject);
pageData.XObjects[ResNam+Pdf::toPdf(ResCount)] = formObject;
ResCount++;
QByteArray GXName = ResNam+Pdf::toPdf(ResCount);
@@ -7805,8 +7805,8 @@
PutDoc("/ColorSpace [ /DeviceN [ /Cyan /Magenta /Yellow /Black");
for (int sc = 0; sc < spotColorSet.count(); sc++)
{
- PutDoc(" " + Pdf::toName(spotColorSet.at(sc).simplified()));
- //" /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
+ PutDoc(" " + Pdf::toName(spotColorSet.at(sc).simplified()));
+ //" /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
entx += " 0 1";
}
PutDoc(" ]\n");
@@ -7818,7 +7818,7 @@
else
PutDoc("/ColorSpace /DeviceCMYK\n");
}
- PutDoc("/Background [" + Pdf::toAscii(Gcolors.last()) + "]\n");
+ PutDoc("/Background [" + Pdf::toAscii(Gcolors.last()) + "]\n");
PutDoc("/BitsPerCoordinate 32\n");
PutDoc("/BitsPerComponent 16\n");
PutDoc("/BitsPerFlag 8\n");
@@ -7935,7 +7935,7 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(dat, shadeObject)+"\nendstream");
- writer.endObj(shadeObject);
+ writer.endObj(shadeObject);
PdfId patObject = writer.newObject();
writer.startObj(patObject);
PutDoc("<<\n/Type /Pattern\n");
@@ -7962,7 +7962,7 @@
PutDoc("/Matrix ["+FToStr(mpa.m11())+" "+FToStr(mpa.m12())+" "+FToStr(mpa.m21())+" "+FToStr(mpa.m22())+" "+FToStr(mpa.dx())+" "+FToStr(mpa.dy())+"]\n");
PutDoc("/Shading "+Pdf::toPdf(shadeObject)+" 0 R\n");
PutDoc(">>");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
if (spotMode)
{
@@ -8002,7 +8002,7 @@
PutDoc("/Range [0 1 0 1 0 1 0 1]\n");
PutDoc("/Length "+Pdf::toPdf(colorDesc.length()+1)+"\n");
PutDoc(">>\nstream\n"+EncStream(colorDesc, spotObject)+"\nendstream");
- writer.endObj(spotObject);
+ writer.endObj(spotObject);
}
QByteArray tmp;
if (((Options.Version >= PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_X4)) && (transparencyFound))
@@ -8099,14 +8099,14 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(dat, shadeObjectT)+"\nendstream");
- writer.endObj(shadeObjectT);
+ writer.endObj(shadeObjectT);
PdfId patObject = writer.newObject();
writer.startObj(patObject);
PutDoc("<<\n/Type /Pattern\n");
PutDoc("/PatternType 2\n");
PutDoc("/Shading "+Pdf::toPdf(shadeObjectT)+" 0 R\n");
PutDoc(">>");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
PdfId formObject = writer.newObject();
writer.startObj(formObject);
@@ -8115,12 +8115,12 @@
PutDoc("/Group << /S /Transparency /CS /DeviceGray >>\n");
double lw = c->lineWidth();
PutDoc("/BBox ["+FToStr(-lw / 2.0)+" "+FToStr(lw / 2.0)+" "+FToStr(c->width()+lw)+" "+FToStr(-(c->height()+lw))+" ]\n");
- PutDoc("/Resources ");
-
- Pdf::ResourceDictionary dict;
- dict.Pattern = Patterns;
- writer.write(dict);
-
+ PutDoc("/Resources ");
+
+ Pdf::ResourceDictionary dict;
+ dict.Pattern = Patterns;
+ writer.write(dict);
+
QByteArray stre = "q\n"+SetClipPath(c)+"h\n";
stre += FToStr(fabs(c->lineWidth()))+" w\n";
stre += "/Pattern cs\n";
@@ -8132,7 +8132,7 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
- writer.endObj(formObject);
+ writer.endObj(formObject);
pageData.XObjects[ResNam+Pdf::toPdf(ResCount)] = formObject;
ResCount++;
QByteArray GXName = ResNam+Pdf::toPdf(ResCount);
@@ -8170,8 +8170,8 @@
PutDoc("/ColorSpace [ /DeviceN [ /Cyan /Magenta /Yellow /Black");
for (int sc = 0; sc < spotColorSet.count(); sc++)
{
- PutDoc(" " + Pdf::toName(spotColorSet.at(sc).simplified()));
- //" /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
+ PutDoc(" " + Pdf::toName(spotColorSet.at(sc).simplified()));
+ //" /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
entx += " 0 1";
}
PutDoc(" ]\n");
@@ -8257,7 +8257,7 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(dat, shadeObject)+"\nendstream");
- writer.endObj(shadeObject);
+ writer.endObj(shadeObject);
PdfId patObject = writer.newObject();
writer.startObj(patObject);
PutDoc("<<\n/Type /Pattern\n");
@@ -8284,7 +8284,7 @@
PutDoc("/Matrix ["+FToStr(mpa.m11())+" "+FToStr(mpa.m12())+" "+FToStr(mpa.m21())+" "+FToStr(mpa.m22())+" "+FToStr(mpa.dx())+" "+FToStr(mpa.dy())+"]\n");
PutDoc("/Shading "+Pdf::toPdf(shadeObject)+" 0 R\n");
PutDoc(">>");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
if (spotMode)
{
@@ -8324,7 +8324,7 @@
PutDoc("/Range [0 1 0 1 0 1 0 1]\n");
PutDoc("/Length "+Pdf::toPdf(colorDesc.length()+1)+"\n");
PutDoc(">>\nstream\n"+EncStream(colorDesc, spotObject)+"\nendstream");
- writer.endObj(spotObject);
+ writer.endObj(spotObject);
}
QByteArray tmp;
if (((Options.Version >= PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_X4)) && (transparencyFound))
@@ -8566,7 +8566,7 @@
PutDoc(">>\n");
PutDoc(">>\n");
PutDoc(">>\n");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
PdfId formObject = writer.newObject();
writer.startObj(formObject);
@@ -8575,13 +8575,13 @@
PutDoc("/Group << /S /Transparency /CS /DeviceGray >>\n");
double lw = currItem->lineWidth();
PutDoc("/BBox ["+FToStr(-lw / 2.0)+" "+FToStr(lw / 2.0)+" "+FToStr(currItem->width()+lw)+" "+FToStr(-(currItem->height()+lw))+" ]\n");
- PutDoc("/Resources ");
-
- Pdf::ResourceDictionary dict;
- dict.Pattern = Patterns;
- writer.write(dict);
-
- QByteArray stre = "q\n"+SetClipPath(currItem)+"h\n";
+ PutDoc("/Resources ");
+
+ Pdf::ResourceDictionary dict;
+ dict.Pattern = Patterns;
+ writer.write(dict);
+
+ QByteArray stre = "q\n"+SetClipPath(currItem)+"h\n";
stre += FToStr(fabs(currItem->lineWidth()))+" w\n";
if ((forArrow) || (!stroke))
{
@@ -8600,7 +8600,7 @@
if (Options.Compress)
PutDoc("/Filter /FlateDecode\n");
PutDoc(">>\nstream\n"+EncStream(stre, formObject)+"\nendstream");
- writer.endObj(formObject);
+ writer.endObj(formObject);
pageData.XObjects[ResNam+Pdf::toPdf(ResCount)] = formObject;
ResCount++;
QByteArray GXName = ResNam+Pdf::toPdf(ResCount);
@@ -8634,8 +8634,8 @@
PutDoc("/ColorSpace [ /DeviceN [ /Cyan /Magenta /Yellow /Black");
for (int sc = 0; sc < spotColorSet.count(); sc++)
{
- PutDoc("" + Pdf::toName(spotColorSet.at(sc).simplified()));
- //" /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
+ PutDoc("" + Pdf::toName(spotColorSet.at(sc).simplified()));
+ //" /"+spotColorSet.at(sc).simplified().replace("#", "#23").replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "#20" ));
}
PutDoc(" ]\n");
PutDoc("/DeviceCMYK\n");
@@ -8694,7 +8694,7 @@
}
else
{
- PutDoc("/C0 [" + Pdf::toAscii(Gcolors[cc]));
+ PutDoc("/C0 [" + Pdf::toAscii(Gcolors[cc]));
for (int sc = 0; sc < spotColorSet.count(); sc++)
{
PutDoc(" 0");
@@ -8714,7 +8714,7 @@
}
else
{
- PutDoc("/C1 [" + Pdf::toAscii(Gcolors[cc+1]));
+ PutDoc("/C1 [" + Pdf::toAscii(Gcolors[cc+1]));
for (int sc = 0; sc < spotColorSet.count(); sc++)
{
PutDoc(" 0");
@@ -8724,8 +8724,8 @@
}
else
{
- PutDoc("/C0 [" + Pdf::toAscii(Gcolors[cc]) + "]\n");
- PutDoc("/C1 [" + Pdf::toAscii(Gcolors[cc+1]) + "]\n");
+ PutDoc("/C0 [" + Pdf::toAscii(Gcolors[cc]) + "]\n");
+ PutDoc("/C1 [" + Pdf::toAscii(Gcolors[cc+1]) + "]\n");
}
PutDoc("/N 1\n");
PutDoc(">>\n");
@@ -8735,7 +8735,7 @@
PutDoc(">>\n");
PutDoc(">>\n");
PutDoc(">>\n");
- writer.endObj(patObject);
+ writer.endObj(patObject);
Patterns.insert("Pattern"+Pdf::toPdf(patObject), patObject);
if (spotMode)
{
@@ -8775,7 +8775,7 @@
PutDoc("/Range [0 1 0 1 0 1 0 1]\n");
PutDoc("/Length "+Pdf::toPdf(colorDesc.length()+1)+"\n");
PutDoc(">>\nstream\n"+EncStream(colorDesc, spotObject)+"\nendstream");
- writer.endObj(spotObject);
+ writer.endObj(spotObject);
}
QByteArray tmp;
if (((Options.Version >= PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_X4)) && (transparencyFound))
@@ -8847,7 +8847,7 @@
PutDoc("/XN ("+Pdf::toAscii(itv.key())+")\n");
PutDoc("/IN ("+Pdf::toAscii(itv.key())+")\n");
PutDoc(">>");
- writer.endObj(viewObjL);
+ writer.endObj(viewObjL);
}
PdfId appearanceObj = writer.newObject();
writer.startObj(appearanceObj);
@@ -8874,7 +8874,7 @@
PutDoc(">>\nstream\n");
EncodeArrayToStream(dataP, appearanceObj);
PutDoc("\nendstream");
- writer.endObj(appearanceObj);
+ writer.endObj(appearanceObj);
PdfId annotationObj = writer.newObject();
writer.startObj(annotationObj);
pageData.AObjects.append(annotationObj);
@@ -8884,18 +8884,18 @@
PutDoc("/3DD "+Pdf::toPdf(appearanceObj)+" 0 R\n");
PutDoc("/3DV "+Pdf::toPdf(viewObj)+" 0 R\n");
PutDoc("/3DA <<\n/A /PV\n/TB true\n/NP true\n>>\n");
- QByteArray onState = Pdf::toName(ite->itemName().replace(".", "_" ));
+ QByteArray onState = Pdf::toName(ite->itemName().replace(".", "_" ));
PutDoc("/AS "+onState+"\n");
PdfId appearanceObj1 = writer.newObject();
PutDoc("/AP << /N <<\n" + onState + " " + Pdf::toPdf(appearanceObj1)+" 0 R >> >>\n");
PutDoc("/Rect [ "+FToStr(x+bleedDisplacementX)+" "+FToStr(y2+bleedDisplacementY)+" "+FToStr(x2+bleedDisplacementX)+" "+FToStr(y+bleedDisplacementY)+" ]\n");
PutDoc(">>");
- writer.endObj(appearanceObj);
+ writer.endObj(appearanceObj);
if (!ite->Pfile.isEmpty())
{
PDF_Image(ite, ite->Pfile, ite->imageXScale(), ite->imageYScale(), ite->imageXOffset(), -ite->imageYOffset(), true);
QByteArray cc = Pdf::toPdf(ite->pixm.width())+" 0 0 "+Pdf::toPdf(ite->pixm.height())+" 0 0 cm\n";
- cc += Pdf::toName(ResNam+"I"+Pdf::toPdf(ResCount-1)) + " Do";
+ cc += Pdf::toName(ResNam+"I"+Pdf::toPdf(ResCount-1)) + " Do";
PDF_xForm(appearanceObj1, ite->pixm.width(), ite->pixm.height(), cc);
}
delete tempImageFile;
@@ -8927,15 +8927,15 @@
QByteArray onState = "";
QByteArray anTitle;
if (it.key() == 0)
- anTitle = "Page" + Pdf::toPdf(ActPageP->pageNr() + 1);
+ anTitle = "Page" + Pdf::toPdf(ActPageP->pageNr() + 1);
else
- anTitle = Pdf::toName(it.key()->itemName().replace(".", "_" ));
+ anTitle = Pdf::toName(it.key()->itemName().replace(".", "_" ));
for (int a = 0; a < bList.count(); a++)
{
PdfId kid = PDF_RadioButton(bList[a], parentObject, anTitle);
kidsList.append(kid);
if (bList[a]->annotation().IsChk())
- onState = Pdf::toName(bList[a]->itemName().replace(".", "_" ));
+ onState = Pdf::toName(bList[a]->itemName().replace(".", "_" ));
}
writer.startObj(parentObject);
pageData.AObjects.append(parentObject);
@@ -8956,7 +8956,7 @@
PutDoc("]\n");
PutDoc("/Rect [0 0 0 0]\n");
PutDoc(">>");
- writer.endObj(parentObject);
+ writer.endObj(parentObject);
}
}
@@ -8992,7 +8992,7 @@
QByteArray mm[] = {"4", "2", "0", "32"};
PutDoc(mm[ite->annotation().Vis()]);
PutDoc("\n");
- QByteArray cnx = Pdf::toName(StdFonts["/ZapfDingbats"]);
+ QByteArray cnx = Pdf::toName(StdFonts["/ZapfDingbats"]);
cnx += " "+FToStr(ite->itemText.defaultStyle().charStyle().fontSize() / 10.0)+" Tf";
if (ite->itemText.defaultStyle().charStyle().fillColor() != CommonStrings::None)
cnx += " "+ putColor(ite->itemText.defaultStyle().charStyle().fillColor(), ite->itemText.defaultStyle().charStyle().fillShade(), true);
@@ -9017,7 +9017,7 @@
if (ite->rotation() != 0)
PutDoc("/R "+Pdf::toPdf((abs(static_cast<int>(ite->rotation())) / 90)*90)+" ");
PutDoc(">>\n");
- QByteArray onState = Pdf::toName(ite->itemName().replace(".", "_" ));
+ QByteArray onState = Pdf::toName(ite->itemName().replace(".", "_" ));
if (ite->annotation().IsChk())
PutDoc("/AS "+onState+"\n");
else
@@ -9071,7 +9071,7 @@
}
PutDoc("/Rect [ "+FToStr(x+bleedDisplacementX)+" "+FToStr(y2+bleedDisplacementY)+" "+FToStr(x2+bleedDisplacementX)+" "+FToStr(y+bleedDisplacementY)+" ]\n");
PutDoc(">>");
- writer.endObj(annotationObj);
+ writer.endObj(annotationObj);
cc = createBorderAppearance(ite);
if (ite->itemText.defaultStyle().charStyle().fillColor() != CommonStrings::None)
cc += putColor(ite->itemText.defaultStyle().charStyle().fillColor(), ite->itemText.defaultStyle().charStyle().fillShade(), true);
@@ -9121,7 +9121,7 @@
bmUtf16 += (cc == QChar(13) ? QChar(10) : cc);
}
}
- QByteArray anTitle = Pdf::toPdfDocEncoding(ite->itemName().replace(".", "_" ));
+ QByteArray anTitle = Pdf::toPdfDocEncoding(ite->itemName().replace(".", "_" ));
QStringList bmstUtf16 = bmUtf16.split(QChar(10), QString::SkipEmptyParts);
const QByteArray m[] = {"4", "5", "F", "l", "H", "n"};
QByteArray ct(m[ite->annotation().ChkStil()]);
@@ -9138,7 +9138,7 @@
PdfId AActionObj = writeActions(ite->annotation(), annotationObj);
writer.startObj(annotationObj);
pageData.AObjects.append(annotationObj);
- QByteArray onState = Pdf::toName(ite->itemName().replace(".", "_" ));
+ QByteArray onState = Pdf::toName(ite->itemName().replace(".", "_" ));
PutDoc("<<\n/Type /Annot\n");
switch (ite->annotation().Type())
{
@@ -9201,15 +9201,15 @@
}
if (ite->annotation().ActionType() == Annotation::Action_GoToR_FileRel)
{
- PutDoc("/A << /Type /Action /S /GoToR\n/F " + EncString(Pdf::toPdfDocEncoding(Path2Relative(ite->annotation().Extern(), baseDir)), annotationObj) + "\n");
- PutDoc("/D ["+Pdf::toPdf(ite->annotation().Ziel())+" /XYZ "+Pdf::toPdfDocEncoding(ite->annotation().Action())+"]\n>>\n");
+ PutDoc("/A << /Type /Action /S /GoToR\n/F " + EncString(Pdf::toPdfDocEncoding(Path2Relative(ite->annotation().Extern(), baseDir)), annotationObj) + "\n");
+ PutDoc("/D ["+Pdf::toPdf(ite->annotation().Ziel())+" /XYZ "+Pdf::toPdfDocEncoding(ite->annotation().Action())+"]\n>>\n");
}
if (ite->annotation().ActionType() == Annotation::Action_URI)
PutDoc("/A << /Type /Action /S /URI\n/URI " + EncString(Pdf::toPdfDocEncoding(ite->annotation().Extern()), annotationObj) + "\n>>\n");
if (ite->annotation().ActionType() == Annotation::Action_GoToR_FileAbs)
{
PutDoc("/A << /Type /Action /S /GoToR\n/F " + EncString(Pdf::toPdfDocEncoding(ite->annotation().Extern()), annotationObj) + "\n");
- PutDoc("/D ["+Pdf::toPdf(ite->annotation().Ziel())+" /XYZ " + Pdf::toPdfDocEncoding(ite->annotation().Action())+"]\n>>\n");
+ PutDoc("/D ["+Pdf::toPdf(ite->annotation().Ziel())+" /XYZ " + Pdf::toPdfDocEncoding(ite->annotation().Action())+"]\n>>\n");
}
break;
case Annotation::Button:
@@ -9234,11 +9234,11 @@
PutDoc(" >>\n");
QByteArray cnx;
if (ite->annotation().Type() == Annotation::Checkbox)
- cnx += Pdf::toName(StdFonts["/ZapfDingbats"]);
+ cnx += Pdf::toName(StdFonts["/ZapfDingbats"]);
else
{
if (Options.Version < PDFOptions::PDFVersion_14)
- cnx += Pdf::toName(StdFonts[ind2PDFabr[ite->annotation().Font()]]);
+ cnx += Pdf::toName(StdFonts[ind2PDFabr[ite->annotation().Font()]]);
else
cnx += UsedFontsF[ite->itemText.defaultStyle().charStyle().font().replacementName()].name;
// cnx += UsedFontsP[ite->itemText.defaultStyle().charStyle().font().replacementName()]+"Form";
@@ -9290,7 +9290,7 @@
break;
case Annotation::Combobox:
case Annotation::Listbox:
- cnx = EncStringUTF16(bmstUtf16.count() > 0 ? bmstUtf16[0] : "", annotationObj);
+ cnx = EncStringUTF16(bmstUtf16.count() > 0 ? bmstUtf16[0] : "", annotationObj);
PutDoc("/FT /Ch\n");
PutDoc("/V " + cnx + "\n");
PutDoc("/DV " + cnx + "\n");
@@ -9322,7 +9322,7 @@
case Annotation::Button:
PutDoc("/CA " + EncStringUTF16(bmUtf16, annotationObj) + " ");
if (!ite->annotation().RollOver().isEmpty())
- PutDoc("/RC " + EncStringUTF16(ite->annotation().RollOver(), annotationObj) + " ");
+ PutDoc("/RC " + EncStringUTF16(ite->annotation().RollOver(), annotationObj) + " ");
if (!ite->annotation().Down().isEmpty())
PutDoc("/AC " + EncStringUTF16(ite->annotation().Down(), annotationObj) + " ");
if (ite->annotation().UseIcons())
@@ -9400,13 +9400,13 @@
{
if (ite->annotation().ActionType() == Annotation::Action_GoToR_FileRel)
{
- PutDoc("/A << /Type /Action /S /GoToR\n/F " + EncString(Pdf::toPdfDocEncoding(Path2Relative(ite->annotation().Extern(), baseDir)), annotationObj) + "\n");
- PutDoc("/D ["+Pdf::toPdf(ite->annotation().Ziel())+" /XYZ "+ Pdf::toPdfDocEncoding(ite->annotation().Action())+"]\n>>\n");
+ PutDoc("/A << /Type /Action /S /GoToR\n/F " + EncString(Pdf::toPdfDocEncoding(Path2Relative(ite->annotation().Extern(), baseDir)), annotationObj) + "\n");
+ PutDoc("/D ["+Pdf::toPdf(ite->annotation().Ziel())+" /XYZ "+ Pdf::toPdfDocEncoding(ite->annotation().Action())+"]\n>>\n");
}
if (ite->annotation().ActionType() == Annotation::Action_GoToR_FileAbs)
{
PutDoc("/A << /Type /Action /S /GoToR\n/F " + EncString(Pdf::toPdfDocEncoding(ite->annotation().Extern()), annotationObj) + "\n");
- PutDoc("/D ["+Pdf::toPdf(ite->annotation().Ziel())+" /XYZ "+ Pdf::toPdfDocEncoding(ite->annotation().Action())+"]\n>>\n");
+ PutDoc("/D ["+Pdf::toPdf(ite->annotation().Ziel())+" /XYZ "+ Pdf::toPdfDocEncoding(ite->annotation().Action())+"]\n>>\n");
}
if (ite->annotation().ActionType() == Annotation::Action_ImportData)
PutDoc("/A << /Type /Action /S /ImportData\n/F " + EncString(Pdf::toPdfDocEncoding(ite->annotation().Action()), annotationObj) + " >>\n");
@@ -9468,7 +9468,7 @@
{
if (!ite->annotation().Action().isEmpty())
{
- PutDoc("/A << /Type /Action /S /Named /N /" + Pdf::toPdfDocEncoding(ite->annotation().Action()) + " >>\n");
+ PutDoc("/A << /Type /Action /S /Named /N /" + Pdf::toPdfDocEncoding(ite->annotation().Action()) + " >>\n");
}
}
}
@@ -9501,7 +9501,7 @@
}
PutDoc("/Rect [ "+FToStr(x+bleedDisplacementX)+" "+FToStr(y2+bleedDisplacementY)+" "+FToStr(x2+bleedDisplacementX)+" "+FToStr(y+bleedDisplacementY)+" ]\n");
PutDoc(">>");
- writer.endObj(annotationObj);
+ writer.endObj(annotationObj);
// write icons
if ((ite->annotation().Type() == Annotation::Button) && (ite->annotation().UseIcons()))
{
@@ -9510,7 +9510,7 @@
if (!PDF_Image(ite, ite->Pfile, ite->imageXScale(), ite->imageYScale(), ite->imageXOffset(), -ite->imageYOffset(), true))
return false;
QByteArray cc = Pdf::toPdf(ite->pixm.width())+" 0 0 "+Pdf::toPdf(ite->pixm.height())+" 0 0 cm\n";
- cc += Pdf::toName(ResNam+"I"+Pdf::toPdf(ResCount-1)) + " Do";
+ cc += Pdf::toName(ResNam+"I"+Pdf::toPdf(ResCount-1)) + " Do";
PDF_xForm(icon1Obj, ite->pixm.width(), ite->pixm.height(), cc);
}
if (!ite->Pfile2.isEmpty())
@@ -9555,7 +9555,7 @@
}
if (ite->annotation().Type() == Annotation::Textfield)
{
- QByteArray cc;
+ QByteArray cc;
if (ite->fillColor() != CommonStrings::None)
cc += putColor(ite->fillColor(), ite->fillShade(), false);
cc += FToStr(x)+" "+FToStr(y2)+" "+FToStr(x2-x)+" "+FToStr(y-y2)+" re\nf\n";
@@ -9585,7 +9585,7 @@
}
if (ite->annotation().Type() == Annotation::Checkbox)
{
- QByteArray cc;
+ QByteArray cc;
cc += "q\n1 g\n";
cc += "0 0 "+FToStr(x2-x)+" "+FToStr(y-y2)+" re\nf\n";
cc += createBorderAppearance(ite);
@@ -9604,7 +9604,7 @@
}
if ((ite->annotation().Type() == Annotation::Combobox) || (ite->annotation().Type() == Annotation::Listbox))
{
- QByteArray cc;
+ QByteArray cc;
cc += "1 g\n";
cc += "0 0 "+FToStr(x2-x)+" "+FToStr(y-y2)+" re\nf\n";
cc += createBorderAppearance(ite);
@@ -9862,7 +9862,7 @@
}
}
PutDoc(">>");
- writer.endObj(annotationObj);
+ writer.endObj(annotationObj);
return result;
}
return 0;
@@ -9879,7 +9879,7 @@
if (Options.Compress)
PutDoc("\n/Filter /FlateDecode");
PutDoc(" >>\nstream\n"+EncStream(tmp, result)+"\nendstream");
- writer.endObj(result);
+ writer.endObj(result);
return result;
}
@@ -9905,17 +9905,17 @@
writer.startObj(objNr);
PutDoc("<<\n/Type /XObject\n/Subtype /Form\n");
PutDoc("/BBox [ 0 0 "+FToStr(w)+" "+FToStr(h)+" ]\n");
- PutDoc("/Resources ");
-
- Pdf::ResourceDictionary dict;
- dict.XObject.unite(pageData.ImgObjects);
- dict.XObject.unite(pageData.XObjects);
- dict.Font = pageData.FObjects;
- writer.write(dict);
-
- PutDoc("/Length "+Pdf::toPdf(im.length())+"\n");
+ PutDoc("/Resources ");
+
+ Pdf::ResourceDictionary dict;
+ dict.XObject.unite(pageData.ImgObjects);
+ dict.XObject.unite(pageData.XObjects);
+ dict.Font = pageData.FObjects;
+ writer.write(dict);
+
+ PutDoc("/Length "+Pdf::toPdf(im.length())+"\n");
PutDoc(">>\nstream\n"+EncStream(im, objNr)+"\nendstream");
- writer.endObj(objNr);
+ writer.endObj(objNr);
pageData.XObjects[ResNam+Pdf::toPdf(ResCount)] = objNr;
ResCount++;
}
@@ -9926,14 +9926,14 @@
writer.startObj(form);
PutDoc("<<\n");
PutDoc("/Resources ");
-
- Pdf::ResourceDictionary dict;
- dict.Font = pageData.FObjects;
- writer.write(dict);
-
- PutDoc("/Length "+Pdf::toPdf(im.length())+"\n");
+
+ Pdf::ResourceDictionary dict;
+ dict.Font = pageData.FObjects;
+ writer.write(dict);
+
+ PutDoc("/Length "+Pdf::toPdf(im.length())+"\n");
PutDoc(">>\nstream\n"+EncStream(im, form)+"\nendstream");
- writer.endObj(form);
+ writer.endObj(form);
}
void PDFLibCore::PDF_Bookmark(PageItem *currItem, double ypos)
@@ -10062,7 +10062,7 @@
} // disconnect QByteArray from raw data
free (mbuffer);
PutDoc("\nendstream");
- writer.endObj(xObj);
+ writer.endObj(xObj);
// write resources
if (resources)
{
@@ -10072,7 +10072,7 @@
{
writer.startObj(xResources);
PutDoc("<< >>");
- writer.endObj(xResources);
+ writer.endObj(xResources);
}
if (xParents)
{
@@ -10159,7 +10159,6 @@
}
else if(carray[ci].IsReference())
{
-
nextObj = doc->GetObjects().GetObject(carray[ci].GetReference());
while(nextObj != NULL)
@@ -10175,9 +10174,7 @@
break;
}
}
-
- }
-
+ }
}
// end of copy
mlen = outMemStream.GetLength();
@@ -10206,7 +10203,7 @@
} // disconnect QByteArray from raw data
free (mbuffer);
PutDoc("\nendstream");
- writer.endObj(xObj);
+ writer.endObj(xObj);
// write resources
if (resources)
{
@@ -10216,7 +10213,7 @@
{
writer.startObj(xResources);
PutDoc("<< >>");
- writer.endObj(xResources);
+ writer.endObj(xResources);
}
if (xParents)
{
@@ -10349,7 +10346,7 @@
PutDoc("\nendstream");
}
PutDoc("");
- writer.endObj(scObjID);
+ writer.endObj(scObjID);
// recurse:
for (int i=0; i < referencedObjects.size(); ++i)
{
@@ -10383,8 +10380,8 @@
if (ext.isEmpty())
ext = getImageType(fn);
ScImage img;
- QByteArray tmp, tmpy, dummy, cmd1, cmd2;
- QString BBox;
+ QByteArray tmp, tmpy, dummy, cmd1, cmd2;
+ QString BBox;
QChar tc;
bool found = false;
bool alphaM = false;
@@ -10512,8 +10509,8 @@
if (tmp.startsWith("%%EndComments"))
break;
}
- // BBox is not used...
-
+ // BBox is not used...
+
f.close();
if (found)
{
@@ -10677,7 +10674,7 @@
PutDoc(">>\nstream\n");
EncodeArrayToStream(dataP, embeddedProfile);
PutDoc("\nendstream");
- writer.endObj(embeddedProfile);
+ writer.endObj(embeddedProfile);
PdfId profileResource = writer.newObject();
writer.startObj(profileResource);
dataD.ResName = ResNam+Pdf::toPdf(ResCount);
@@ -10723,7 +10720,7 @@
PutDoc(">>\nstream\n");
EncodeArrayToStream(dataP, embeddedProfile);
PutDoc("\nendstream");
- writer.endObj(embeddedProfile);
+ writer.endObj(embeddedProfile);
PdfId profileResource = writer.newObject();
writer.startObj(profileResource);
dataD.ResName = ResNam+Pdf::toPdf(ResCount);
@@ -10816,7 +10813,7 @@
PutDoc(">>\nstream\n");
EncodeArrayToStream(im2, maskObj);
PutDoc("\nendstream");
- writer.endObj(maskObj);
+ writer.endObj(maskObj);
pageData.ImgObjects[ResNam+"I"+Pdf::toPdf(ResCount)] = maskObj;
ResCount++;
}
@@ -10968,16 +10965,16 @@
else
bytesWritten = WriteImageToStream(img, imageObj, outType, (!hasColorEffect && hasGrayProfile));
PutDoc("\nendstream");
- writer.endObj(imageObj);
+ writer.endObj(imageObj);
if (bytesWritten <= 0)
{
PDF_Error_ImageWriteFailure(fn);
return false;
}
writer.startObj(lengthObj);
- PutDoc(" " + Pdf::toPdf(bytesWritten));
- writer.endObj(lengthObj);
- pageData.ImgObjects[ResNam+"I"+Pdf::toPdf(ResCount)] = imageObj;
+ PutDoc(" " + Pdf::toPdf(bytesWritten));
+ writer.endObj(lengthObj);
+ pageData.ImgObjects[ResNam+"I"+Pdf::toPdf(ResCount)] = imageObj;
ImInfo.ResNum = ResCount;
ImInfo.Width = img.width();
ImInfo.Height = img.height();
@@ -11053,18 +11050,18 @@
bool PDFLibCore::PDF_End_Doc(const QString& PrintPr, const QString& Name, int Components)
{
- PDF_End_Bookmarks();
- PDF_End_Resources();
- PDF_End_Outlines();
- PDF_End_PageTree();
- PDF_End_NamedDests();
- PDF_End_FormObjects();
- PDF_End_JavaScripts();
- PDF_End_Articles();
- PDF_End_Layers();
- PDF_End_OutputProfile(PrintPr, Name, Components);
- PDF_End_Metadata();
- return PDF_End_XRefAndTrailer();
+ PDF_End_Bookmarks();
+ PDF_End_Resources();
+ PDF_End_Outlines();
+ PDF_End_PageTree();
+ PDF_End_NamedDests();
+ PDF_End_FormObjects();
+ PDF_End_JavaScripts();
+ PDF_End_Articles();
+ PDF_End_Layers();
+ PDF_End_OutputProfile(PrintPr, Name, Components);
+ PDF_End_Metadata();
+ return PDF_End_XRefAndTrailer();
}
void PDFLibCore::PDF_End_Bookmarks()
@@ -11075,7 +11072,7 @@
QMap<int,QByteArray> Inha;
if ((Bvie->topLevelItemCount() != 0) && (Options.Bookmarks) && (BookMinUse))
{
- Outlines.Count = Bvie->topLevelItemCount();
+ Outlines.Count = Bvie->topLevelItemCount();
PdfId Basis = writer.reserveObjects(Outlines.Count) - 1;
ip = (BookMItem*)Bvie->topLevelItem(0);
Outlines.First = ip->ItemNr+Basis;
@@ -11103,12 +11100,12 @@
Inhal += "/Count -"+Pdf::toPdf(ip->childCount())+"\n";
if ((ip->PageObject->OwnPage != -1) && PageTree.Kids.contains(ip->PageObject->OwnPage))
{
- QByteArray action = Pdf::toPdfDocEncoding(ip->Action);
+ QByteArray action = Pdf::toPdfDocEncoding(ip->Action);
if (action.isEmpty())
{
const ScPage* page = doc.DocPages.at(ip->PageObject->OwnPage);
double actionPos = page->height() - (ip->PageObject->yPos() - page->yOffset());
- action = "/XYZ 0 " + Pdf::toPdf(actionPos) + " 0";
+ action = "/XYZ 0 " + Pdf::toPdf(actionPos) + " 0";
}
Inhal += "/Dest ["+Pdf::toPdf(PageTree.Kids[ip->PageObject->OwnPage])+" 0 R "+action+"\n";
}
@@ -11119,9 +11116,9 @@
QMap<int,QByteArray> ::ConstIterator contentIt;
for (contentIt = Inha.begin(); contentIt != Inha.end(); ++contentIt)
{
- writer.startObj(ip->ItemNr+Basis);
+ writer.startObj(ip->ItemNr+Basis);
PutDoc(contentIt.value());
- writer.endObj(ip->ItemNr+Basis);
+ writer.endObj(ip->ItemNr+Basis);
}
}
}
@@ -11129,20 +11126,20 @@
void PDFLibCore::PDF_End_Resources()
{
writer.ResourcesObj = writer.newObject();
- writer.startObj(writer.ResourcesObj);
-
- Pdf::ResourceDictionary dict;
- dict.XObject.unite(pageData.ImgObjects);
- dict.XObject.unite(pageData.XObjects);
- dict.Font = pageData.FObjects;
- dict.Shading = Shadings;
- dict.Pattern = Patterns;
- dict.ExtGState = Transpar;
- dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
- dict.ColorSpace.append(asColorSpace(spotMap.values()));
- dict.ColorSpace.append(asColorSpace(spotMapReg.values()));
-
- dict.Properties.clear();
+ writer.startObj(writer.ResourcesObj);
+
+ Pdf::ResourceDictionary dict;
+ dict.XObject.unite(pageData.ImgObjects);
+ dict.XObject.unite(pageData.XObjects);
+ dict.Font = pageData.FObjects;
+ dict.Shading = Shadings;
+ dict.Pattern = Patterns;
+ dict.ExtGState = Transpar;
+ dict.ColorSpace.append(asColorSpace(ICCProfiles.values()));
+ dict.ColorSpace.append(asColorSpace(spotMap.values()));
+ dict.ColorSpace.append(asColorSpace(spotMapReg.values()));
+
+ dict.Properties.clear();
if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4))&& (Options.useLayers))
{
ScLayer ll;
@@ -11152,20 +11149,20 @@
for (int la = 0; la < doc.Layers.count(); ++la)
{
doc.Layers.levelToLayer(ll, la);
- dict.Properties[OCGEntries[ll.Name].Name] = OCGEntries[ll.Name].ObjNum;
+ dict.Properties[OCGEntries[ll.Name].Name] = OCGEntries[ll.Name].ObjNum;
// PutDoc("/"+OCGEntries[ll.Name].Name + " " + Pdf::toObjRef(OCGEntries[ll.Name].ObjNum) + "\n");
Lnr++;
}
}
- writer.write(dict);
- writer.endObj(writer.ResourcesObj);
+ writer.write(dict);
+ writer.endObj(writer.ResourcesObj);
}
void PDFLibCore::PDF_End_Outlines()
{
- writer.startObj(writer.OutlinesObj);
- PutDoc("<<\n/Type /Outlines\n");
+ writer.startObj(writer.OutlinesObj);
+ PutDoc("<<\n/Type /Outlines\n");
PutDoc("/Count "+Pdf::toPdf(Outlines.Count)+"\n");
// if ((Bvie->childCount() != 0) && (Options.Bookmarks))
if ((Bvie->topLevelItemCount() != 0) && (Options.Bookmarks))
@@ -11173,27 +11170,27 @@
PutDoc("/First "+Pdf::toPdf(Outlines.First)+" 0 R\n");
PutDoc("/Last "+Pdf::toPdf(Outlines.Last)+" 0 R\n");
}
- PutDoc(">>");
- writer.endObj(writer.OutlinesObj);
+ PutDoc(">>");
+ writer.endObj(writer.OutlinesObj);
}
void PDFLibCore::PDF_End_PageTree()
{
- writer.startObj(writer.PagesObj);
- PutDoc("<<\n/Type /Pages\n/Kids [");
+ writer.startObj(writer.PagesObj);
+ PutDoc("<<\n/Type /Pages\n/Kids [");
QMap<int, int>::Iterator kidsIt;
for (kidsIt = PageTree.Kids.begin(); kidsIt != PageTree.Kids.end(); ++kidsIt)
PutDoc(Pdf::toPdf(kidsIt.value())+" 0 R ");
PutDoc("]\n");
PutDoc("/Count "+Pdf::toPdf(PageTree.Count)+"\n");
PutDoc("/Resources "+Pdf::toPdf(writer.ResourcesObj)+" 0 R\n");
- PutDoc(">>");
- writer.endObj(writer.PagesObj);
+ PutDoc(">>");
+ writer.endObj(writer.PagesObj);
}
void PDFLibCore::PDF_End_NamedDests()
{
- writer.startObj(writer.DestsObj);
+ writer.startObj(writer.DestsObj);
PutDoc("<<\n");
if (NamedDest.count() != 0)
{
@@ -11201,17 +11198,17 @@
for (vt = NamedDest.begin(); vt != NamedDest.end(); ++vt)
{
if (PageTree.Kids.contains((*vt).PageNr))
- PutDoc(Pdf::toName((*vt).Name) + " [" + Pdf::toObjRef(PageTree.Kids[(*vt).PageNr])
- + " /XYZ " + Pdf::toPdfDocEncoding((*vt).Act) + "]\n");
- }
- }
- PutDoc(">>");
- writer.endObj(writer.DestsObj);
+ PutDoc(Pdf::toName((*vt).Name) + " [" + Pdf::toObjRef(PageTree.Kids[(*vt).PageNr])
+ + " /XYZ " + Pdf::toPdfDocEncoding((*vt).Act) + "]\n");
+ }
+ }
+ PutDoc(">>");
+ writer.endObj(writer.DestsObj);
}
void PDFLibCore::PDF_End_FormObjects()
{
- writer.startObj(writer.AcroFormObj);
+ writer.startObj(writer.AcroFormObj);
PutDoc("<<\n");
PutDoc("/Fields [ ");
if (pageData.FormObjects.count() != 0)
@@ -11229,13 +11226,13 @@
}
if ((pageData.FormObjects.count() != 0) || (CalcFields.count() != 0))
PutDoc("/NeedAppearances true\n/DR " + Pdf::toObjRef(writer.ResourcesObj) + "\n");
- PutDoc(">>");
- writer.endObj(writer.AcroFormObj);
+ PutDoc(">>");
+ writer.endObj(writer.AcroFormObj);
}
void PDFLibCore::PDF_End_JavaScripts()
{
- PdfId jsNameTreeObj = 0;
+ PdfId jsNameTreeObj = 0;
if (doc.JavaScripts.count() != 0)
{
QList<PdfId> Fjav;
@@ -11243,39 +11240,39 @@
for (itja0 = doc.JavaScripts.begin(); itja0 != doc.JavaScripts.end(); ++itja0)
Fjav.append(WritePDFString(itja0.value()));
QMap<QString,QString>::Iterator itja;
- int i = 0;
+ int i = 0;
for (itja = doc.JavaScripts.begin(); itja != doc.JavaScripts.end(); ++itja)
{
PdfId Fjav1 = writer.startObj();
- Fjav.append(Fjav1);
+ Fjav.append(Fjav1);
PutDoc("<< /S /JavaScript /JS "+Pdf::toPdf(Fjav[i])+" 0 R >>");
- writer.endObj(Fjav1);
- ++i;
- }
- jsNameTreeObj = writer.startObj();
+ writer.endObj(Fjav1);
+ ++i;
+ }
+ jsNameTreeObj = writer.startObj();
PutDoc("<< /Names [ ");
QMap<QString,QString>::Iterator itja2;
for (itja2 = doc.JavaScripts.begin(); itja2 != doc.JavaScripts.end(); ++itja2)
{
- PutDoc(EncString(Pdf::toPdfDocEncoding(itja2.key()), jsNameTreeObj) + " " + Pdf::toObjRef(Fjav[i]) + " ");
+ PutDoc(EncString(Pdf::toPdfDocEncoding(itja2.key()), jsNameTreeObj) + " " + Pdf::toObjRef(Fjav[i]) + " ");
++i;
}
- PutDoc("] >>");
- writer.endObj(jsNameTreeObj);
- }
-
- writer.startObj(writer.NamesObj);
+ PutDoc("] >>");
+ writer.endObj(jsNameTreeObj);
+ }
+
+ writer.startObj(writer.NamesObj);
PutDoc("<< ");
if (doc.JavaScripts.count() != 0)
PutDoc("/JavaScript "+Pdf::toPdf(jsNameTreeObj)+" 0 R");
- PutDoc(" >>");
- writer.endObj(writer.NamesObj);
+ PutDoc(" >>");
+ writer.endObj(writer.NamesObj);
}
void PDFLibCore::PDF_End_Articles()
{
- Threads.clear();
- PdfId currentThreadObj = 0;
+ Threads.clear();
+ PdfId currentThreadObj = 0;
if (Options.Articles)
{
for (int ele = 0; ele < doc.Items->count(); ++ele)
@@ -11286,9 +11283,9 @@
{
Beads.clear();
PdfBead bd;
- if (currentThreadObj == 0)
- currentThreadObj = writer.newObject();
-
+ if (currentThreadObj == 0)
+ currentThreadObj = writer.newObject();
+
PdfId fir = currentThreadObj + 1;
PdfId ccb = currentThreadObj + 1;
bd.Parent = currentThreadObj;
@@ -11327,39 +11324,39 @@
Threads.append(currentThreadObj);
PutDoc("<< /Type /Thread\n");
PutDoc(" /F "+Pdf::toPdf(fir)+" 0 R\n");
- PutDoc(">>");
- writer.endObj(currentThreadObj);
-
+ PutDoc(">>");
+ writer.endObj(currentThreadObj);
+
Beads[0].Prev = fir + Beads.count()-1;
Beads.last().Next = fir;
- for (int beac = 0; beac < Beads.count(); ++beac)
- {
- PdfId beadObj = writer.startObj();
- PutDoc("<< /Type /Bead\n");
- PutDoc(" /T "+Pdf::toPdf(Beads[beac].Parent)+" 0 R\n");
- PutDoc(" /N "+Pdf::toPdf(Beads[beac].Next)+" 0 R\n");
- PutDoc(" /V "+Pdf::toPdf(Beads[beac].Prev)+" 0 R\n");
- PutDoc(" /P "+Pdf::toPdf(Beads[beac].Page)+" 0 R\n");
- PutDoc(" /R [ "+Pdf::toPdf(Beads[beac].Rect.x())+" "+
- Pdf::toPdf(Beads[beac].Rect.y())+" ");
- PutDoc(Pdf::toPdf(Beads[beac].Rect.bottomRight().x())+" "+Pdf::toPdf(Beads[beac].Rect.y()-Beads[beac].Rect.height())+" ]\n");
- PutDoc(">>");
- writer.endObj(beadObj);
- }
- currentThreadObj = 0;
- }
+ for (int beac = 0; beac < Beads.count(); ++beac)
+ {
+ PdfId beadObj = writer.startObj();
+ PutDoc("<< /Type /Bead\n");
+ PutDoc(" /T "+Pdf::toPdf(Beads[beac].Parent)+" 0 R\n");
+ PutDoc(" /N "+Pdf::toPdf(Beads[beac].Next)+" 0 R\n");
+ PutDoc(" /V "+Pdf::toPdf(Beads[beac].Prev)+" 0 R\n");
+ PutDoc(" /P "+Pdf::toPdf(Beads[beac].Page)+" 0 R\n");
+ PutDoc(" /R [ "+Pdf::toPdf(Beads[beac].Rect.x())+" "+
+ Pdf::toPdf(Beads[beac].Rect.y())+" ");
+ PutDoc(Pdf::toPdf(Beads[beac].Rect.bottomRight().x())+" "+Pdf::toPdf(Beads[beac].Rect.y()-Beads[beac].Rect.height())+" ]\n");
+ PutDoc(">>");
+ writer.endObj(beadObj);
+ }
+ currentThreadObj = 0;
+ }
}
}
for (int ele = 0; ele < doc.Items->count(); ++ele)
doc.Items->at(ele)->inPdfArticle = false;
}
- writer.startObj(writer.ThreadsObj);
- PutDoc("[ ");
+ writer.startObj(writer.ThreadsObj);
+ PutDoc("[ ");
for (int th = 0; th < Threads.count(); ++th)
PutDoc(Pdf::toObjRef(Threads[th])+" ");
- PutDoc("]");
- writer.endObj(writer.ThreadsObj);
+ PutDoc("]");
+ writer.endObj(writer.ThreadsObj);
}
void PDFLibCore::PDF_End_Layers()
@@ -11367,7 +11364,7 @@
if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers))
{
QList<QByteArray> lay;
- writer.startObj(writer.OCPropertiesObj);
+ writer.startObj(writer.OCPropertiesObj);
PutDoc("<<\n");
PutDoc("/D << /Order [ ");
ScLayer ll;
@@ -11391,7 +11388,7 @@
{
PutDoc("/BaseState /ON\n");
QString occdName = "Default";
- PutDoc("/Name "+Pdf::toLiteralString(occdName)+"\n");
+ PutDoc("/Name "+Pdf::toLiteralString(occdName)+"\n");
}
PutDoc("/OFF [ ");
QHash<QString, PdfOCGInfo>::Iterator itoc;
@@ -11422,9 +11419,9 @@
PutDoc(Pdf::toObjRef(itoc.value().ObjNum)+" ");
}
PutDoc("]\n");
- PutDoc(">>");
- writer.endObj(writer.OCPropertiesObj);
- }
+ PutDoc(">>");
+ writer.endObj(writer.OCPropertiesObj);
+ }
}
void PDFLibCore::PDF_End_OutputProfile(const QString& PrintPr, const QString& Name, int Components)
@@ -11448,8 +11445,8 @@
PutDoc("/N "+Pdf::toPdf(Components)+"\n");
PutDoc(">>\nstream\n");
PutDoc(dataP);
- PutDoc("\nendstream");
- writer.endObj(profileObj);
+ PutDoc("\nendstream");
+ writer.endObj(profileObj);
// if ((Options.Version == PDFOptions::PDFVersion_X4) && (Options.useLayers))
// {
@@ -11461,16 +11458,16 @@
// XRef[8] = bytesWritten();
// PutDoc("9 0 obj\n");
// }
-
- writer.startObj(writer.OutputIntentObj);
+
+ writer.startObj(writer.OutputIntentObj);
PutDoc("<<\n/Type /OutputIntent\n/S /GTS_PDFX\n");
PutDoc("/DestOutputProfile " + Pdf::toObjRef(profileObj) + "\n");
PutDoc("/OutputConditionIdentifier (Custom)\n");
- PutDoc("/Info " + Pdf::toLiteralString(Options.Info) + "\n");
+ PutDoc("/Info " + Pdf::toLiteralString(Options.Info) + "\n");
PutDoc("/OutputCondition " + Pdf::toLiteralString(Name) + "\n");
- PutDoc(">>");
- writer.endObj(writer.OutputIntentObj);
+ PutDoc(">>");
+ writer.endObj(writer.OutputIntentObj);
}
}
@@ -11488,7 +11485,7 @@
// XRef[9] = bytesWritten();
// PutDoc("10 0 obj\n");
// }
- writer.startObj(writer.MetaDataObj);
+ writer.startObj(writer.MetaDataObj);
PutDoc("<<\n");
PutDoc("/Length "+Pdf::toPdf(xmpPacket.size()+1)+"\n");
PutDoc("/Type /Metadata\n");
@@ -11496,13 +11493,13 @@
PutDoc(">>\nstream\n");
PutDoc(xmpPacket);
PutDoc("\nendstream");
- writer.endObj(writer.MetaDataObj);
+ writer.endObj(writer.MetaDataObj);
}
}
bool PDFLibCore::PDF_End_XRefAndTrailer()
{
- writer.writeXrefAndTrailer();
+ writer.writeXrefAndTrailer();
return closeAndCleanup();
}
@@ -11645,11 +11642,11 @@
bool PDFLibCore::closeAndCleanup()
{
- bool writeSucceed = writer.close(abortExport);
+ bool writeSucceed = writer.close(abortExport);
if (!writeSucceed)
PDF_Error_WriteFailure();
- pageData.XObjects.clear();
+ pageData.XObjects.clear();
pageData.ImgObjects.clear();
pageData.FObjects.clear();
pageData.AObjects.clear();
Modified: trunk/Scribus/scribus/pdflib_core.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20112&path=/trunk/Scribus/scribus/pdflib_core.h
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.h (original)
+++ trunk/Scribus/scribus/pdflib_core.h Wed May 20 22:39:10 2015
@@ -89,48 +89,48 @@
bool PDF_IsPDFX(PDFOptions::PDFVersion ver);
bool PDF_Begin_Doc(const QString& fn, SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts, BookMView* vi);
- void PDF_Begin_Catalog();
- void PDF_Begin_MetadataAndEncrypt();
- QMap<QString, QMap<uint, FPointArray> >
- PDF_Begin_FindUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts);
- void PDF_Begin_WriteUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& ReallyUsed);
- void PDF_WriteStandardFonts();
- PdfFont PDF_WriteType3Font(const QByteArray& name, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
- PdfFont PDF_WriteGlyphsAsXForms(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
-
- PdfId PDF_WriteFontDescriptor(const QByteArray& fontName, ScFace& face, ScFace::FontFormat fformat, PdfId embeddedFontObject);
- PdfFont PDF_WriteTtfSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
- PdfFont PDF_WriteCffSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
- PdfFont PDF_EncodeSimpleFont(const QByteArray& fontname, ScFace& face, const QByteArray& baseFont, const QByteArray& subtype, bool isEmbedded, PdfId fontDes, const ScFace::FaceEncoding& gl);
- PdfFont PDF_EncodeCidFont(const QByteArray& fontname, ScFace& face, const QByteArray& baseFont, PdfId fontDes, const ScFace::FaceEncoding& gl, const QMap<uint,uint> glyphmap);
- PdfId PDF_EmbedFontObject(const QString& fontName, ScFace &face);
- PdfId PDF_EmbedFontObject(const QByteArray& ttf, const QByteArray& subtype);
- PdfId PDF_EmbedType1AsciiFontObject(const QByteArray& fontData);
- PdfId PDF_EmbedType1BinaryFontObject(const QByteArray& fontData);
- void PDF_Begin_Colors();
- void PDF_Begin_Layers();
-
+ void PDF_Begin_Catalog();
+ void PDF_Begin_MetadataAndEncrypt();
+ QMap<QString, QMap<uint, FPointArray> >
+ PDF_Begin_FindUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts);
+ void PDF_Begin_WriteUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& ReallyUsed);
+ void PDF_WriteStandardFonts();
+ PdfFont PDF_WriteType3Font(const QByteArray& name, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
+ PdfFont PDF_WriteGlyphsAsXForms(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
+
+ PdfId PDF_WriteFontDescriptor(const QByteArray& fontName, ScFace& face, ScFace::FontFormat fformat, PdfId embeddedFontObject);
+ PdfFont PDF_WriteTtfSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
+ PdfFont PDF_WriteCffSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
+ PdfFont PDF_EncodeSimpleFont(const QByteArray& fontname, ScFace& face, const QByteArray& baseFont, const QByteArray& subtype, bool isEmbedded, PdfId fontDes, const ScFace::FaceEncoding& gl);
+ PdfFont PDF_EncodeCidFont(const QByteArray& fontname, ScFace& face, const QByteArray& baseFont, PdfId fontDes, const ScFace::FaceEncoding& gl, const QMap<uint,uint> glyphmap);
+ PdfId PDF_EmbedFontObject(const QString& fontName, ScFace &face);
+ PdfId PDF_EmbedFontObject(const QByteArray& ttf, const QByteArray& subtype);
+ PdfId PDF_EmbedType1AsciiFontObject(const QByteArray& fontData);
+ PdfId PDF_EmbedType1BinaryFontObject(const QByteArray& fontData);
+ void PDF_Begin_Colors();
+ void PDF_Begin_Layers();
+
void PDF_Begin_Page(const ScPage* pag, QPixmap pm);
void PDF_End_Page(int physPage);
bool PDF_TemplatePage(const ScPage* pag, bool clip = false);
bool PDF_ProcessPage(const ScPage* pag, uint PNr, bool clip = false);
bool PDF_ProcessMasterElements(const ScLayer& layer, const ScPage* page, uint PNr);
bool PDF_ProcessPageElements(const ScLayer& layer, const ScPage* page, uint PNr);
-
+
bool PDF_End_Doc(const QString& PrintPr = "", const QString& Name = "", int Components = 0);
- void PDF_End_Bookmarks();
- void PDF_End_Resources();
- void PDF_End_Outlines();
- void PDF_End_PageTree();
- void PDF_End_NamedDests();
- void PDF_End_FormObjects();
- void PDF_End_JavaScripts();
- void PDF_End_Articles();
- void PDF_End_Layers();
- void PDF_End_OutputProfile(const QString& PrintPr, const QString& Name, int Components);
- void PDF_End_Metadata();
- bool PDF_End_XRefAndTrailer();
- bool closeAndCleanup();
+ void PDF_End_Bookmarks();
+ void PDF_End_Resources();
+ void PDF_End_Outlines();
+ void PDF_End_PageTree();
+ void PDF_End_NamedDests();
+ void PDF_End_FormObjects();
+ void PDF_End_JavaScripts();
+ void PDF_End_Articles();
+ void PDF_End_Layers();
+ void PDF_End_OutputProfile(const QString& PrintPr, const QString& Name, int Components);
+ void PDF_End_Metadata();
+ bool PDF_End_XRefAndTrailer();
+ bool closeAndCleanup();
void PDF_Error(const QString& errorMsg);
void PDF_Error_WriteFailure(void);
@@ -234,13 +234,13 @@
void generateXMP(const QString& timeStamp);
// int bytesWritten() { return Spool.pos(); }
- PdfCatalog Catalog;
- PdfPageData pageData;
- PdfPageTree PageTree;
- PdfOutlines Outlines;
- Pdf::Writer writer;
- QString baseDir;
-
+ PdfCatalog Catalog;
+ PdfPageData pageData;
+ PdfPageTree PageTree;
+ PdfOutlines Outlines;
+ Pdf::Writer writer;
+ QString baseDir;
+
QByteArray Content;
QString ErrorMessage;
ScribusDoc & doc;
@@ -253,7 +253,7 @@
QList<PdfId> Threads;
QList<PdfBead> Beads;
QList<PdfId> CalcFields;
- Pdf::ResourceMap Patterns;
+ Pdf::ResourceMap Patterns;
Pdf::ResourceMap Shadings;
Pdf::ResourceMap Transpar;
QMap<QString,PdfICCD> ICCProfiles;
@@ -287,7 +287,7 @@
bool usingGUI;
double bleedDisplacementX;
double bleedDisplacementY;
- QByteArray xmpPacket;
+ QByteArray xmpPacket;
QStack<QPointF> groupStackPos;
QStack<QPointF> patternStackPos;
Modified: trunk/Scribus/scribus/pdfwriter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20112&path=/trunk/Scribus/scribus/pdfwriter.cpp
==============================================================================
--- trunk/Scribus/scribus/pdfwriter.cpp (original)
+++ trunk/Scribus/scribus/pdfwriter.cpp Wed May 20 22:39:10 2015
@@ -1,862 +1,869 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include <QCryptographicHash>
#include "pdfwriter.h"
#include "rc4.h"
#include "scstreamfilter_rc4.h"
#include "util.h"
-#include <QCryptographicHash>
namespace Pdf
{
-
- bool isWhiteSpace(char c)
- {
- switch (c)
- {
- case 0:
- case 9:
- case 10:
- case 12:
- case 13:
- case 32:
- return true;
- default:
- return false;
- }
- }
-
- bool isDelimiter(char c)
- {
- QByteArray delims("()<>[]{}/%");
- return delims.indexOf(c) >= 0;
- }
-
- bool isRegular(char c)
- {
- return !isWhiteSpace(c) && !isDelimiter(c);
- }
-
- QByteArray toPdfDocEncoding(QString s)
- {
- QByteArray result;
- for (int i = 0; i < s.length(); ++i)
- {
- uchar row = s[i].row();
- uchar cell = s[i].cell();
- switch(row)
- {
- case 0:
- if (cell <= 23
- || (cell >= 32 && cell <= 127)
- || cell >= 161)
- {
- result.append(cell);
- }
- else
- {
- result.append("?");
- }
- break;
- case 0x01:
- switch (cell)
- {
- case 0x92:
- result.append(134);
- break;
- case 0x41:
- result.append(149);
- break;
- case 0x52:
- result.append(150);
- break;
- case 0x60:
- result.append(151);
- break;
- case 0x78:
- result.append(152);
- break;
- case 0x7d:
- result.append(153);
- break;
- case 0x31:
- result.append(154);
- break;
- case 0x42:
- result.append(155);
- break;
- case 0x53:
- result.append(156);
- break;
- case 0x61:
- result.append(157);
- break;
- case 0x7e:
- result.append(158);
- break;
- default:
- result.append("?");
- break;
- }
-
- case 0x02:
- switch (cell)
- {
- case 0xc7:
- result.append(25);
- break;
- case 0xc6:
- result.append(26);
- break;
- case 0xd8:
- result.append(24);
- break;
- case 0xd9:
- result.append(27);
- break;
- case 0xda:
- result.append(30);
- break;
- case 0xdb:
- result.append(29);
- break;
- case 0xdc:
- result.append(31);
- break;
- case 0xdd:
- result.append(28);
- break;
- default:
- result.append("?");
- break;
- }
- case 0x20:
- switch (cell)
- {
- case 0x13:
- result.append(133);
- break;
- case 0x14:
- result.append(132);
- break;
- case 0x18:
- result.append(143);
- break;
- case 0x19:
- result.append(144);
- break;
- case 0x1a:
- result.append(145);
- break;
- case 0x1c:
- result.append(141);
- break;
- case 0x1d:
- result.append(142);
- break;
- case 0x1e:
- result.append(140);
- break;
- case 0x20:
- result.append(129);
- break;
- case 0x21:
- result.append(130);
- break;
- case 0x22:
- result.append(128);
- break;
- case 0x26:
- result.append(131);
- break;
- case 0x30:
- result.append(139);
- break;
- case 0x39:
- result.append(136);
- break;
- case 0x3a:
- result.append(137);
- break;
- case 0x44:
- result.append(135);
- break;
- case 0xac:
- result.append(160);
- break;
-
- default:
- result.append("?");
- break;
- }
- case 0x21:
- switch (cell)
- {
- case 0x22:
- result.append(146);
- break;
- default:
- result.append("?");
- break;
- }
- case 0x22:
- switch (cell)
- {
- case 0x12:
- result.append(138);
- break;
- default:
- result.append("?");
- break;
- }
- case 0xfb:
- switch (cell)
- {
- case 0x01:
- result.append(147);
- break;
- case 0x02:
- result.append(148);
- break;
- default:
- result.append("?");
- break;
- }
-
- }
- }
- return result;
- }
-
- QByteArray toUTF16(QString s)
- {
- QByteArray result;
- result.append(0xfe);
- result.append(0xff);
- for (int i = 0; i < s.length(); ++i)
- {
- result.append(s[i].row());
- result.append(s[i].cell());
- }
- return result;
- }
-
- QByteArray toAscii(QString s)
- {
- QByteArray result;
- for (int i = 0; i < s.length(); ++i)
- {
- uchar row = s[i].row();
- uchar cell = s[i].cell();
- if (row == 0 && cell <= 127)
- {
- result.append(cell);
- }
- else
- {
- result.append("?");
- }
- }
- return result;
- }
-
- QByteArray toPdf(bool v)
- {
- return v? "true" : "false";
- }
-
- QByteArray toPdf(int v)
- {
- return QByteArray::number(v);
- }
-
- QByteArray toPdf(uint v)
- {
- return QByteArray::number(v);
- }
-
- QByteArray toPdf(qlonglong v)
- {
- return QByteArray::number(v);
- }
-
- QByteArray toPdf(qulonglong v)
- {
- return QByteArray::number(v);
- }
-
- QByteArray toPdf(double v)
- {
- return QByteArray::number(v, 'f');
- }
-
- QByteArray toObjRef(PdfId id)
- {
- return toPdf(id) + " 0 R";
- }
-
-
- QByteArray toLiteralString(QString s)
- {
- return toLiteralString(toPdfDocEncoding(s));
- }
-
- QByteArray toLiteralString(QByteArray s)
- {
- int linelength = 80;
- QByteArray result("(");
- for (int i = 0; i < s.length(); ++i)
- {
- uchar v = s[i];
- if ( v == '(' || v == ')' || v == '\\')
- {
- result.append('\\');
- result.append(v);
- }
- else if (v < 32 || v >= 127)
- {
- result.append('\\');
- result.append("01234567"[ (v/64) % 8]);
- result.append("01234567"[ (v/8) % 8]);
- result.append("01234567"[ v % 8]);
- }
- else
- {
- result.append(v);
- }
- if (i % linelength == linelength-1)
- result.append("\\\n");
- }
- result.append(")");
- return result;
- }
-
- QByteArray toHexString(QByteArray s)
- {
- int linelength = 80;
- QByteArray result("<");
- for (int i = 0; i < s.length(); ++i)
- {
- uchar v = s[i];
- result.append("0123456789ABCDEF"[v / 16]);
- result.append("0123456789ABCDEF"[v % 16]);
- if (i % linelength == linelength-1)
- result.append("\\\n");
- }
- result.append(">");
- return result;
- }
-
- QByteArray toHexString8(quint8 b)
- {
- QByteArray result("<");
- result.append("0123456789ABCDEF"[b / 16]);
- result.append("0123456789ABCDEF"[b % 16]);
- result.append(">");
- return result;
- }
-
- QByteArray toHexString16(quint16 b)
- {
- QByteArray result("<");
- result.append("0123456789ABCDEF"[(b >> 12) & 0xf]);
- result.append("0123456789ABCDEF"[(b >> 8) & 0xf]);
- result.append("0123456789ABCDEF"[(b >> 4) & 0xf]);
- result.append("0123456789ABCDEF"[ b & 0xf]);
- result.append(">");
- return result;
- }
-
- QByteArray toHexString32(quint32 b)
- {
- QByteArray result("<");
- result.append("0123456789ABCDEF"[(b >> 28) & 0xf]);
- result.append("0123456789ABCDEF"[(b >> 24) & 0xf]);
- result.append("0123456789ABCDEF"[(b >> 20) & 0xf]);
- result.append("0123456789ABCDEF"[(b >> 16) & 0xf]);
- result.append("0123456789ABCDEF"[(b >> 12) & 0xf]);
- result.append("0123456789ABCDEF"[(b >> 8) & 0xf]);
- result.append("0123456789ABCDEF"[(b >> 4) & 0xf]);
- result.append("0123456789ABCDEF"[ b & 0xf]);
- result.append(">");
- return result;
- }
-
-
- QByteArray toName(QString s)
- {
- return toName(toPdfDocEncoding(s));
- }
-
-
- QByteArray toName(QByteArray s)
- {
- QByteArray result("/");
- for (int i = 0; i < s.length(); ++i)
- {
- uchar c = s[i];
- if (c <= 32 || c >= 127 || c == '#' || isDelimiter(c))
- {
- result.append("#");
- result.append("0123456789ABCDEF"[c / 16]);
- result.append("0123456789ABCDEF"[c % 16]);
- }
- else
- {
- result.append(c);
- }
- }
- return result;
- }
-
- QByteArray toDateString(QDateTime dt)
- {
- QString tmp = dt.toString("yyyy:MM:dd:HH:mm");
- tmp = tmp.replace(":", "");
- return "D:" + tmp.toLatin1() + "Z";
- }
-
-
- QByteArray toRectangleArray(QRect r)
- {
- return "[" + toPdf(r.left()) + " " + toPdf(r.bottom()) + " " + toPdf(r.right()) + " " + toPdf(r.top()) + "]";
- }
-
- QByteArray toRectangleArray(QRectF r)
- {
- return "[" + toPdf(r.left()) + " " + toPdf(r.bottom()) + " " + toPdf(r.right()) + " " + toPdf(r.top()) + "]";
- }
-
-
-
-
- Writer::Writer()
- {
- CatalogObj = 1;
- InfoObj = 2;
- OutlinesObj = 3;
- PagesObj = 4;
- DestsObj = 5;
- AcroFormObj = 6;
- NamesObj = 7;
- ThreadsObj = 8;
-
- OutputIntentObj = 0;
- EncryptObj = 0;
- MetaDataObj = 0;
- ResourcesObj = 0;
-
- CurrentObj = 0;
-
- KeyLen = 5;
- KeyGen.resize(32);
- OwnerKey.resize(32);
- UserKey.resize(32);
- FileID.resize(16);
- EncryKey.resize(5);
-
- int kg_array[] = {
- 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41,
- 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08,
- 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
- 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a };
- for (int a = 0; a < 32; ++a)
- KeyGen[a] = kg_array[a];
-
- }
-
-
- bool Writer::open(const QString& fn)
- {
- Spool.setFileName(fn);
- if (!Spool.open(QIODevice::WriteOnly))
- return false;
- outStream.setDevice(&Spool);
- ObjCounter = 9;
- return true;
- }
-
-
- ScStreamFilter* Writer::openStreamFilter(bool encrypted, PdfId objId)
- {
- if (encrypted)
- {
- QByteArray step1 = ComputeRC4Key(ObjCounter);
- return new ScRC4EncodeFilter(&outStream, step1.data(), qMin(KeyLen+5, 16));
- }
- else
- {
- return new ScNullEncodeFilter(&outStream);
- }
- }
-
-
- bool Writer::close(bool abortExport)
- {
- bool result = (Spool.error() == QFile::NoError);
-
- Spool.close();
- if (abortExport || !result)
- {
- if (Spool.exists())
- Spool.remove();
- }
- return result;
- }
-
-
- void Writer::setFileId(const QByteArray& id)
- {
- FileID = QCryptographicHash::hash(id, QCryptographicHash::Md5);
- }
-
-
- void Writer::setEncryption(bool keyLen16, const QByteArray& PassOwner, const QByteArray& PassUser, int Permissions)
- {
- QByteArray ok = "";
- QByteArray uk = "";
-
- if (keyLen16)
- KeyLen = 16;
- else
- KeyLen = 5;
- CalcOwnerKey(PassOwner, PassUser);
- CalcUserKey(PassUser, Permissions);
- for (uint cl2 = 0; cl2 < 32; ++cl2)
- ok += (OwnerKey[cl2]);
- if (keyLen16)
- {
- for (uint cl3 = 0; cl3 < 16; ++cl3)
- uk += (UserKey[cl3]);
- for (uint cl3r = 0; cl3r < 16; ++cl3r)
- uk += (KeyGen[cl3r]);
- }
- else
- {
- for (uint cl = 0; cl < 32; ++cl)
- uk += (UserKey[cl]);
- }
-
- EncryptObj = newObject();
- startObj(EncryptObj);
- write("<<\n/Filter /Standard\n");
- write( keyLen16 ? "/R 3\n/V 2\n/Length 128\n" : "/R 2\n/V 1\n");
- write("/O "+Pdf::toHexString(ok)+"\n");
- write("/U "+Pdf::toHexString(uk)+"\n");
- write("/P "+Pdf::toPdf(Permissions)+"\n>>");
- endObj(EncryptObj);
-
- }
-
-
- QByteArray Writer::encryptBytes(const QByteArray& in, PdfId ObjNum)
- {
- rc4_context_t rc4;
- QByteArray result(in.length(), ' ');
- if (in.length() > 0)
- {
- QByteArray step1 = ComputeRC4Key(ObjNum);
- rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16));
- rc4_encrypt(&rc4, reinterpret_cast<const uchar*>(in.data()), reinterpret_cast<uchar*>(result.data()), in.length());
- }
- return result;
- }
-
- QByteArray Writer::ComputeRC4Key(PdfId ObjNum)
- {
- int dlen = 0;
- QByteArray data(10, ' ');
- if (KeyLen > 5)
- data.resize(21);
- for (int cd = 0; cd < KeyLen; ++cd)
- {
- data[cd] = EncryKey[cd];
- dlen++;
- }
- data[dlen++] = ObjNum;
- data[dlen++] = ObjNum >> 8;
- data[dlen++] = ObjNum >> 16;
- data[dlen++] = 0;
- data[dlen++] = 0;
- QByteArray rc4Key(16, ' ');
- rc4Key = QCryptographicHash::hash(data, QCryptographicHash::Md5);
- rc4Key.resize(qMin(KeyLen+5, 16));
- return rc4Key;
- }
-
-
- QByteArray Writer::FitKey(const QByteArray & pass)
- {
- QByteArray pw(pass);
- if (pw.length() < 32)
- {
- uint l = pw.length();
- for (uint a = 0; a < 32 - l; ++a)
- pw += (KeyGen[a]);
- }
- else
- pw = pw.left(32);
- return pw;
- }
-
- void Writer::CalcOwnerKey(const QByteArray & Owner, const QByteArray & User)
- {
- rc4_context_t rc4;
- QByteArray pw(FitKey(User));
- QByteArray pw2(FitKey(Owner.isEmpty() ? User : Owner));
- QByteArray step1(16, ' ');
- step1 = QCryptographicHash::hash(pw2, QCryptographicHash::Md5);
- if (KeyLen > 5)
- {
- for (int kl = 0; kl < 50; ++kl)
- step1 = QCryptographicHash::hash(step1, QCryptographicHash::Md5);
- }
- QByteArray us(32, ' ');
- QByteArray enk(16, ' ');
- if (KeyLen > 5)
- {
- for (uint a2 = 0; a2 < 32; ++a2)
- OwnerKey[a2] = QChar(pw.at(a2)).cell();
- for (int rl = 0; rl < 20; rl++)
- {
- for (int j = 0; j < 16; j ++)
- enk[j] = step1[j] ^ rl;
- rc4_init(&rc4, reinterpret_cast<uchar*>(enk.data()), 16);
- rc4_encrypt(&rc4, reinterpret_cast<uchar*>(OwnerKey.data()),
- reinterpret_cast<uchar*>(OwnerKey.data()), 32);
- }
- }
- else
- {
- for (uint a = 0; a < 32; ++a)
- us[a] = static_cast<uchar>(QChar(pw.at(a)).cell());
- rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), 5);
- rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()),
- reinterpret_cast<uchar*>(OwnerKey.data()), 32);
- }
- }
-
- void Writer::CalcUserKey(const QByteArray & User, int Permission)
- {
- rc4_context_t rc4;
- QByteArray pw(FitKey(User));
- QByteArray step1(16, ' ');
- QByteArray perm(4, ' ');
- uint perm_value = static_cast<uint>(Permission);
- perm[0] = perm_value;
- perm[1] = perm_value >> 8;
- perm[2] = perm_value >> 16;
- perm[3] = perm_value >> 24;
- for (uint a = 0; a < 32; ++a)
- pw += (OwnerKey[a]);
- for (uint a1 = 0; a1 < 4; ++a1)
- pw += (perm[a1]);
- for (uint a3 = 0; a3 < 16; ++a3)
- pw += (FileID[a3]);
- step1 = QCryptographicHash::hash(pw, QCryptographicHash::Md5);
- if (KeyLen > 5)
- {
- for (int kl = 0; kl < 50; ++kl)
- step1 = QCryptographicHash::hash(step1, QCryptographicHash::Md5);
- EncryKey.resize(16);
- }
- for (int a2 = 0; a2 < KeyLen; ++a2)
- EncryKey[a2] = step1[a2];
- if (KeyLen > 5)
- {
- QByteArray pr2("");
- for (int kl3 = 0; kl3 < 32; ++kl3)
- pr2 += (KeyGen[kl3]);
- for (uint a4 = 0; a4 < 16; ++a4)
- pr2 += (FileID[a4]);
- step1 = QCryptographicHash::hash(pr2, QCryptographicHash::Md5);
- QByteArray enk(16, ' ');
- for (uint a3 = 0; a3 < 16; ++a3)
- UserKey[a3] = step1[a3];
- for (int rl = 0; rl < 20; rl++)
- {
- for (int j = 0; j < 16; j ++)
- enk[j] = EncryKey[j] ^ rl;
- rc4_init(&rc4, reinterpret_cast<uchar*>(enk.data()), 16);
- rc4_encrypt(&rc4, reinterpret_cast<uchar*>(UserKey.data()), reinterpret_cast<uchar*>(UserKey.data()), 16);
- }
- }
- else
- {
- rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), 5);
- rc4_encrypt(&rc4, reinterpret_cast<uchar*>(KeyGen.data()), reinterpret_cast<uchar*>(UserKey.data()), 32);
- }
- }
-
-// QByteArray PDFLibCore::ComputeMD5(const QString& in)
-// {
-// uint inlen=in.length();
-// QByteArray TBytes(inlen, ' ');
-// for (uint a = 0; a < inlen; ++a)
-// TBytes[a] = static_cast<uchar>(QChar(in.at(a)).cell());
-// return QCryptographicHash::hash(TBytes, QCryptographicHash::Md5);
-// }
-
-
- void Writer::writeHeader(PDFOptions::PDFVersion Version)
- {
- switch (Version)
- {
- case PDFOptions::PDFVersion_X1a:
- case PDFOptions::PDFVersion_X3:
- case PDFOptions::PDFVersion_13:
- write("%PDF-1.3\n");
- break;
- case PDFOptions::PDFVersion_14:
- write("%PDF-1.4\n");
- break;
- case PDFOptions::PDFVersion_X4:
- case PDFOptions::PDFVersion_15:
- write("%PDF-1.5\n");
- break;
- }
- write("%\xc7\xec\x8f\xa2\n");
- }
-
- void Writer::writeXrefAndTrailer()
- {
- QByteArray tmp;
- uint StX = bytesWritten();
- write("xref\n");
- write("0 "+Pdf::toPdf(ObjCounter)+"\n");
- //write("0000000000 65535 f \n");
- for (int a = 0; a < XRef.count(); ++a)
- {
- if (XRef[a] > 0)
- {
- tmp.setNum(XRef[a]);
- while (tmp.length()< 10)
- {
- tmp.prepend('0');
- }
- write(tmp);
- write(" 00000 n \n");
- }
- else
- {
- // unused object, mark as free-never-to-be-used-again
- write("0000000000 65535 f \n");
- }
- }
- write("trailer\n<<\n/Size "+Pdf::toPdf(XRef.count())+"\n");
- QByteArray IDs ="";
- for (uint cl = 0; cl < 16; ++cl)
- IDs += (FileID[cl]);
- QByteArray IDbytes = Pdf::toHexString(IDs);
- write("/Root 1 0 R\n/Info 2 0 R\n/ID ["+IDbytes+IDbytes+"]\n");
- if (EncryptObj > 0)
- write("/Encrypt "+Pdf::toObjRef(EncryptObj)+"\n");
- write(">>\nstartxref\n");
- write(Pdf::toPdf(StX)+"\n%%EOF\n");
- }
-
-
- void Writer::write(const QByteArray& bytes)
- {
- outStream.writeRawData(bytes, bytes.size());
- }
-
- void Writer::write(const ResourceDictionary& dict)
- {
- write("<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n");
- if (dict.XObject.count() != 0)
- {
- write("/XObject <<\n");
- ResourceMap::ConstIterator iti;
- for (iti = dict.XObject.begin(); iti != dict.XObject.end(); ++iti)
- write(Pdf::toName(iti.key()) + " " + Pdf::toObjRef(iti.value()) + "\n");
- write(">>\n");
- }
- if (dict.Font.count() != 0)
- {
- write("/Font << \n");
- QMap<QByteArray,PdfId>::ConstIterator it2;
- for (it2 = dict.Font.begin(); it2 != dict.Font.end(); ++it2)
- write(Pdf::toName(it2.key()) + " " + Pdf::toObjRef(it2.value()) + "\n");
- write(">>\n");
- }
- if (dict.Shading.count() != 0)
- {
- write("/Shading << \n");
- QMap<QByteArray,PdfId>::ConstIterator it3;
- for (it3 = dict.Shading.begin(); it3 != dict.Shading.end(); ++it3)
- write(Pdf::toName(it3.key()) + " " + Pdf::toObjRef(it3.value()) + "\n");
- write(">>\n");
- }
- if (dict.Pattern.count() != 0)
- {
- write("/Pattern << \n");
- QMap<QByteArray,PdfId>::ConstIterator it3p;
- for (it3p = dict.Pattern.begin(); it3p != dict.Pattern.end(); ++it3p)
- write(Pdf::toName(it3p.key()) + " " + Pdf::toObjRef(it3p.value()) + "\n");
- write(">>\n");
- }
- if (dict.ExtGState.count() != 0)
- {
- write("/ExtGState << \n");
- QMap<QByteArray,PdfId>::ConstIterator it3t;
- for (it3t = dict.ExtGState.begin(); it3t != dict.ExtGState.end(); ++it3t)
- write(Pdf::toName(it3t.key()) + " " + Pdf::toObjRef(it3t.value()) + "\n");
- write(">>\n");
- }
- if (dict.Properties.count() != 0)
- {
- write("/Properties << \n");
- QMap<QByteArray,PdfId>::ConstIterator it4p;
- for (it4p = dict.ExtGState.begin(); it4p != dict.ExtGState.end(); ++it4p)
- write(Pdf::toName(it4p.key()) + " " + Pdf::toObjRef(it4p.value()) + "\n");
- write(">>\n");
- }
- if (dict.ColorSpace.count() != 0)
- {
- write("/ColorSpace << \n");
- QList<Resource>::ConstIterator it3c;
- for (it3c = dict.ColorSpace.begin(); it3c != dict.ColorSpace.end(); ++it3c)
- write(Pdf::toName(it3c->ResName) + " " + Pdf::toObjRef(it3c->ResNum) + "\n");
-
- write(">>\n");
- }
- write(">>\n");
- }
-
-
- PdfId Writer::reserveObjects(unsigned int n)
- {
- assert( n < (1<<30) ); // should only be triggered by reserveObjects(-1) or similar
- PdfId result = ObjCounter;
- ObjCounter += n;
- return result;
- }
-
- void Writer::startObj(PdfId id)
- {
- assert( CurrentObj == 0);
- CurrentObj = id;
+
+ bool isWhiteSpace(char c)
+ {
+ switch (c)
+ {
+ case 0:
+ case 9:
+ case 10:
+ case 12:
+ case 13:
+ case 32:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ bool isDelimiter(char c)
+ {
+ QByteArray delims("()<>[]{}/%");
+ return delims.indexOf(c) >= 0;
+ }
+
+ bool isRegular(char c)
+ {
+ return !isWhiteSpace(c) && !isDelimiter(c);
+ }
+
+ QByteArray toPdfDocEncoding(QString s)
+ {
+ QByteArray result;
+ for (int i = 0; i < s.length(); ++i)
+ {
+ uchar row = s[i].row();
+ uchar cell = s[i].cell();
+ switch(row)
+ {
+ case 0:
+ if (cell <= 23
+ || (cell >= 32 && cell <= 127)
+ || cell >= 161)
+ {
+ result.append(cell);
+ }
+ else
+ {
+ result.append("?");
+ }
+ break;
+ case 0x01:
+ switch (cell)
+ {
+ case 0x92:
+ result.append(134);
+ break;
+ case 0x41:
+ result.append(149);
+ break;
+ case 0x52:
+ result.append(150);
+ break;
+ case 0x60:
+ result.append(151);
+ break;
+ case 0x78:
+ result.append(152);
+ break;
+ case 0x7d:
+ result.append(153);
+ break;
+ case 0x31:
+ result.append(154);
+ break;
+ case 0x42:
+ result.append(155);
+ break;
+ case 0x53:
+ result.append(156);
+ break;
+ case 0x61:
+ result.append(157);
+ break;
+ case 0x7e:
+ result.append(158);
+ break;
+ default:
+ result.append("?");
+ break;
+ }
+
+ case 0x02:
+ switch (cell)
+ {
+ case 0xc7:
+ result.append(25);
+ break;
+ case 0xc6:
+ result.append(26);
+ break;
+ case 0xd8:
+ result.append(24);
+ break;
+ case 0xd9:
+ result.append(27);
+ break;
+ case 0xda:
+ result.append(30);
+ break;
+ case 0xdb:
+ result.append(29);
+ break;
+ case 0xdc:
+ result.append(31);
+ break;
+ case 0xdd:
+ result.append(28);
+ break;
+ default:
+ result.append("?");
+ break;
+ }
+ case 0x20:
+ switch (cell)
+ {
+ case 0x13:
+ result.append(133);
+ break;
+ case 0x14:
+ result.append(132);
+ break;
+ case 0x18:
+ result.append(143);
+ break;
+ case 0x19:
+ result.append(144);
+ break;
+ case 0x1a:
+ result.append(145);
+ break;
+ case 0x1c:
+ result.append(141);
+ break;
+ case 0x1d:
+ result.append(142);
+ break;
+ case 0x1e:
+ result.append(140);
+ break;
+ case 0x20:
+ result.append(129);
+ break;
+ case 0x21:
+ result.append(130);
+ break;
+ case 0x22:
+ result.append(128);
+ break;
+ case 0x26:
+ result.append(131);
+ break;
+ case 0x30:
+ result.append(139);
+ break;
+ case 0x39:
+ result.append(136);
+ break;
+ case 0x3a:
+ result.append(137);
+ break;
+ case 0x44:
+ result.append(135);
+ break;
+ case 0xac:
+ result.append(160);
+ break;
+
+ default:
+ result.append("?");
+ break;
+ }
+ case 0x21:
+ switch (cell)
+ {
+ case 0x22:
+ result.append(146);
+ break;
+ default:
+ result.append("?");
+ break;
+ }
+ case 0x22:
+ switch (cell)
+ {
+ case 0x12:
+ result.append(138);
+ break;
+ default:
+ result.append("?");
+ break;
+ }
+ case 0xfb:
+ switch (cell)
+ {
+ case 0x01:
+ result.append(147);
+ break;
+ case 0x02:
+ result.append(148);
+ break;
+ default:
+ result.append("?");
+ break;
+ }
+
+ }
+ }
+ return result;
+ }
+
+ QByteArray toUTF16(QString s)
+ {
+ QByteArray result;
+ result.append(0xfe);
+ result.append(0xff);
+ for (int i = 0; i < s.length(); ++i)
+ {
+ result.append(s[i].row());
+ result.append(s[i].cell());
+ }
+ return result;
+ }
+
+ QByteArray toAscii(QString s)
+ {
+ QByteArray result;
+ for (int i = 0; i < s.length(); ++i)
+ {
+ uchar row = s[i].row();
+ uchar cell = s[i].cell();
+ if (row == 0 && cell <= 127)
+ {
+ result.append(cell);
+ }
+ else
+ {
+ result.append("?");
+ }
+ }
+ return result;
+ }
+
+ QByteArray toPdf(bool v)
+ {
+ return v? "true" : "false";
+ }
+
+ QByteArray toPdf(int v)
+ {
+ return QByteArray::number(v);
+ }
+
+ QByteArray toPdf(uint v)
+ {
+ return QByteArray::number(v);
+ }
+
+ QByteArray toPdf(qlonglong v)
+ {
+ return QByteArray::number(v);
+ }
+
+ QByteArray toPdf(qulonglong v)
+ {
+ return QByteArray::number(v);
+ }
+
+ QByteArray toPdf(double v)
+ {
+ return QByteArray::number(v, 'f');
+ }
+
+ QByteArray toObjRef(PdfId id)
+ {
+ return toPdf(id) + " 0 R";
+ }
+
+
+ QByteArray toLiteralString(QString s)
+ {
+ return toLiteralString(toPdfDocEncoding(s));
+ }
+
+ QByteArray toLiteralString(QByteArray s)
+ {
+ int linelength = 80;
+ QByteArray result("(");
+ for (int i = 0; i < s.length(); ++i)
+ {
+ uchar v = s[i];
+ if ( v == '(' || v == ')' || v == '\\')
+ {
+ result.append('\\');
+ result.append(v);
+ }
+ else if (v < 32 || v >= 127)
+ {
+ result.append('\\');
+ result.append("01234567"[ (v/64) % 8]);
+ result.append("01234567"[ (v/8) % 8]);
+ result.append("01234567"[ v % 8]);
+ }
+ else
+ {
+ result.append(v);
+ }
+ if (i % linelength == linelength-1)
+ result.append("\\\n");
+ }
+ result.append(")");
+ return result;
+ }
+
+ QByteArray toHexString(QByteArray s)
+ {
+ int linelength = 80;
+ QByteArray result("<");
+ for (int i = 0; i < s.length(); ++i)
+ {
+ uchar v = s[i];
+ result.append("0123456789ABCDEF"[v / 16]);
+ result.append("0123456789ABCDEF"[v % 16]);
+ if (i % linelength == linelength-1)
+ result.append("\\\n");
+ }
+ result.append(">");
+ return result;
+ }
+
+ QByteArray toHexString8(quint8 b)
+ {
+ QByteArray result("<");
+ result.append("0123456789ABCDEF"[b / 16]);
+ result.append("0123456789ABCDEF"[b % 16]);
+ result.append(">");
+ return result;
+ }
+
+ QByteArray toHexString16(quint16 b)
+ {
+ QByteArray result("<");
+ result.append("0123456789ABCDEF"[(b >> 12) & 0xf]);
+ result.append("0123456789ABCDEF"[(b >> 8) & 0xf]);
+ result.append("0123456789ABCDEF"[(b >> 4) & 0xf]);
+ result.append("0123456789ABCDEF"[ b & 0xf]);
+ result.append(">");
+ return result;
+ }
+
+ QByteArray toHexString32(quint32 b)
+ {
+ QByteArray result("<");
+ result.append("0123456789ABCDEF"[(b >> 28) & 0xf]);
+ result.append("0123456789ABCDEF"[(b >> 24) & 0xf]);
+ result.append("0123456789ABCDEF"[(b >> 20) & 0xf]);
+ result.append("0123456789ABCDEF"[(b >> 16) & 0xf]);
+ result.append("0123456789ABCDEF"[(b >> 12) & 0xf]);
+ result.append("0123456789ABCDEF"[(b >> 8) & 0xf]);
+ result.append("0123456789ABCDEF"[(b >> 4) & 0xf]);
+ result.append("0123456789ABCDEF"[ b & 0xf]);
+ result.append(">");
+ return result;
+ }
+
+
+ QByteArray toName(QString s)
+ {
+ return toName(toPdfDocEncoding(s));
+ }
+
+
+ QByteArray toName(QByteArray s)
+ {
+ QByteArray result("/");
+ for (int i = 0; i < s.length(); ++i)
+ {
+ uchar c = s[i];
+ if (c <= 32 || c >= 127 || c == '#' || isDelimiter(c))
+ {
+ result.append("#");
+ result.append("0123456789ABCDEF"[c / 16]);
+ result.append("0123456789ABCDEF"[c % 16]);
+ }
+ else
+ {
+ result.append(c);
+ }
+ }
+ return result;
+ }
+
+ QByteArray toDateString(QDateTime dt)
+ {
+ QString tmp = dt.toString("yyyy:MM:dd:HH:mm");
+ tmp = tmp.replace(":", "");
+ return "D:" + tmp.toLatin1() + "Z";
+ }
+
+
+ QByteArray toRectangleArray(QRect r)
+ {
+ return "[" + toPdf(r.left()) + " " + toPdf(r.bottom()) + " " + toPdf(r.right()) + " " + toPdf(r.top()) + "]";
+ }
+
+ QByteArray toRectangleArray(QRectF r)
+ {
+ return "[" + toPdf(r.left()) + " " + toPdf(r.bottom()) + " " + toPdf(r.right()) + " " + toPdf(r.top()) + "]";
+ }
+
+
+
+
+ Writer::Writer()
+ {
+ CatalogObj = 1;
+ InfoObj = 2;
+ OutlinesObj = 3;
+ PagesObj = 4;
+ DestsObj = 5;
+ AcroFormObj = 6;
+ NamesObj = 7;
+ ThreadsObj = 8;
+
+ OutputIntentObj = 0;
+ EncryptObj = 0;
+ MetaDataObj = 0;
+ ResourcesObj = 0;
+
+ CurrentObj = 0;
+
+ KeyLen = 5;
+ KeyGen.resize(32);
+ OwnerKey.resize(32);
+ UserKey.resize(32);
+ FileID.resize(16);
+ EncryKey.resize(5);
+
+ int kg_array[] = {
+ 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41,
+ 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08,
+ 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
+ 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a };
+ for (int a = 0; a < 32; ++a)
+ KeyGen[a] = kg_array[a];
+
+ }
+
+
+ bool Writer::open(const QString& fn)
+ {
+ Spool.setFileName(fn);
+ if (!Spool.open(QIODevice::WriteOnly))
+ return false;
+ outStream.setDevice(&Spool);
+ ObjCounter = 9;
+ return true;
+ }
+
+
+ ScStreamFilter* Writer::openStreamFilter(bool encrypted, PdfId objId)
+ {
+ if (encrypted)
+ {
+ QByteArray step1 = ComputeRC4Key(ObjCounter);
+ return new ScRC4EncodeFilter(&outStream, step1.data(), qMin(KeyLen+5, 16));
+ }
+ else
+ {
+ return new ScNullEncodeFilter(&outStream);
+ }
+ }
+
+
+ bool Writer::close(bool abortExport)
+ {
+ bool result = (Spool.error() == QFile::NoError);
+
+ Spool.close();
+ if (abortExport || !result)
+ {
+ if (Spool.exists())
+ Spool.remove();
+ }
+ return result;
+ }
+
+
+ void Writer::setFileId(const QByteArray& id)
+ {
+ FileID = QCryptographicHash::hash(id, QCryptographicHash::Md5);
+ }
+
+
+ void Writer::setEncryption(bool keyLen16, const QByteArray& PassOwner, const QByteArray& PassUser, int Permissions)
+ {
+ QByteArray ok = "";
+ QByteArray uk = "";
+
+ if (keyLen16)
+ KeyLen = 16;
+ else
+ KeyLen = 5;
+ CalcOwnerKey(PassOwner, PassUser);
+ CalcUserKey(PassUser, Permissions);
+ for (uint cl2 = 0; cl2 < 32; ++cl2)
+ ok += (OwnerKey[cl2]);
+ if (keyLen16)
+ {
+ for (uint cl3 = 0; cl3 < 16; ++cl3)
+ uk += (UserKey[cl3]);
+ for (uint cl3r = 0; cl3r < 16; ++cl3r)
+ uk += (KeyGen[cl3r]);
+ }
+ else
+ {
+ for (uint cl = 0; cl < 32; ++cl)
+ uk += (UserKey[cl]);
+ }
+
+ EncryptObj = newObject();
+ startObj(EncryptObj);
+ write("<<\n/Filter /Standard\n");
+ write( keyLen16 ? "/R 3\n/V 2\n/Length 128\n" : "/R 2\n/V 1\n");
+ write("/O "+Pdf::toHexString(ok)+"\n");
+ write("/U "+Pdf::toHexString(uk)+"\n");
+ write("/P "+Pdf::toPdf(Permissions)+"\n>>");
+ endObj(EncryptObj);
+
+ }
+
+
+ QByteArray Writer::encryptBytes(const QByteArray& in, PdfId ObjNum)
+ {
+ rc4_context_t rc4;
+ QByteArray result(in.length(), ' ');
+ if (in.length() > 0)
+ {
+ QByteArray step1 = ComputeRC4Key(ObjNum);
+ rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16));
+ rc4_encrypt(&rc4, reinterpret_cast<const uchar*>(in.data()), reinterpret_cast<uchar*>(result.data()), in.length());
+ }
+ return result;
+ }
+
+ QByteArray Writer::ComputeRC4Key(PdfId ObjNum)
+ {
+ int dlen = 0;
+ QByteArray data(10, ' ');
+ if (KeyLen > 5)
+ data.resize(21);
+ for (int cd = 0; cd < KeyLen; ++cd)
+ {
+ data[cd] = EncryKey[cd];
+ dlen++;
+ }
+ data[dlen++] = ObjNum;
+ data[dlen++] = ObjNum >> 8;
+ data[dlen++] = ObjNum >> 16;
+ data[dlen++] = 0;
+ data[dlen++] = 0;
+ QByteArray rc4Key(16, ' ');
+ rc4Key = QCryptographicHash::hash(data, QCryptographicHash::Md5);
+ rc4Key.resize(qMin(KeyLen+5, 16));
+ return rc4Key;
+ }
+
+
+ QByteArray Writer::FitKey(const QByteArray & pass)
+ {
+ QByteArray pw(pass);
+ if (pw.length() < 32)
+ {
+ uint l = pw.length();
+ for (uint a = 0; a < 32 - l; ++a)
+ pw += (KeyGen[a]);
+ }
+ else
+ pw = pw.left(32);
+ return pw;
+ }
+
+ void Writer::CalcOwnerKey(const QByteArray & Owner, const QByteArray & User)
+ {
+ rc4_context_t rc4;
+ QByteArray pw(FitKey(User));
+ QByteArray pw2(FitKey(Owner.isEmpty() ? User : Owner));
+ QByteArray step1(16, ' ');
+ step1 = QCryptographicHash::hash(pw2, QCryptographicHash::Md5);
+ if (KeyLen > 5)
+ {
+ for (int kl = 0; kl < 50; ++kl)
+ step1 = QCryptographicHash::hash(step1, QCryptographicHash::Md5);
+ }
+ QByteArray us(32, ' ');
+ QByteArray enk(16, ' ');
+ if (KeyLen > 5)
+ {
+ for (uint a2 = 0; a2 < 32; ++a2)
+ OwnerKey[a2] = QChar(pw.at(a2)).cell();
+ for (int rl = 0; rl < 20; rl++)
+ {
+ for (int j = 0; j < 16; j ++)
+ enk[j] = step1[j] ^ rl;
+ rc4_init(&rc4, reinterpret_cast<uchar*>(enk.data()), 16);
+ rc4_encrypt(&rc4, reinterpret_cast<uchar*>(OwnerKey.data()),
+ reinterpret_cast<uchar*>(OwnerKey.data()), 32);
+ }
+ }
+ else
+ {
+ for (uint a = 0; a < 32; ++a)
+ us[a] = static_cast<uchar>(QChar(pw.at(a)).cell());
+ rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), 5);
+ rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()),
+ reinterpret_cast<uchar*>(OwnerKey.data()), 32);
+ }
+ }
+
+ void Writer::CalcUserKey(const QByteArray & User, int Permission)
+ {
+ rc4_context_t rc4;
+ QByteArray pw(FitKey(User));
+ QByteArray step1(16, ' ');
+ QByteArray perm(4, ' ');
+ uint perm_value = static_cast<uint>(Permission);
+ perm[0] = perm_value;
+ perm[1] = perm_value >> 8;
+ perm[2] = perm_value >> 16;
+ perm[3] = perm_value >> 24;
+ for (uint a = 0; a < 32; ++a)
+ pw += (OwnerKey[a]);
+ for (uint a1 = 0; a1 < 4; ++a1)
+ pw += (perm[a1]);
+ for (uint a3 = 0; a3 < 16; ++a3)
+ pw += (FileID[a3]);
+ step1 = QCryptographicHash::hash(pw, QCryptographicHash::Md5);
+ if (KeyLen > 5)
+ {
+ for (int kl = 0; kl < 50; ++kl)
+ step1 = QCryptographicHash::hash(step1, QCryptographicHash::Md5);
+ EncryKey.resize(16);
+ }
+ for (int a2 = 0; a2 < KeyLen; ++a2)
+ EncryKey[a2] = step1[a2];
+ if (KeyLen > 5)
+ {
+ QByteArray pr2("");
+ for (int kl3 = 0; kl3 < 32; ++kl3)
+ pr2 += (KeyGen[kl3]);
+ for (uint a4 = 0; a4 < 16; ++a4)
+ pr2 += (FileID[a4]);
+ step1 = QCryptographicHash::hash(pr2, QCryptographicHash::Md5);
+ QByteArray enk(16, ' ');
+ for (uint a3 = 0; a3 < 16; ++a3)
+ UserKey[a3] = step1[a3];
+ for (int rl = 0; rl < 20; rl++)
+ {
+ for (int j = 0; j < 16; j ++)
+ enk[j] = EncryKey[j] ^ rl;
+ rc4_init(&rc4, reinterpret_cast<uchar*>(enk.data()), 16);
+ rc4_encrypt(&rc4, reinterpret_cast<uchar*>(UserKey.data()), reinterpret_cast<uchar*>(UserKey.data()), 16);
+ }
+ }
+ else
+ {
+ rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), 5);
+ rc4_encrypt(&rc4, reinterpret_cast<uchar*>(KeyGen.data()), reinterpret_cast<uchar*>(UserKey.data()), 32);
+ }
+ }
+
+// QByteArray PDFLibCore::ComputeMD5(const QString& in)
+// {
+// uint inlen=in.length();
+// QByteArray TBytes(inlen, ' ');
+// for (uint a = 0; a < inlen; ++a)
+// TBytes[a] = static_cast<uchar>(QChar(in.at(a)).cell());
+// return QCryptographicHash::hash(TBytes, QCryptographicHash::Md5);
+// }
+
+
+ void Writer::writeHeader(PDFOptions::PDFVersion Version)
+ {
+ switch (Version)
+ {
+ case PDFOptions::PDFVersion_X1a:
+ case PDFOptions::PDFVersion_X3:
+ case PDFOptions::PDFVersion_13:
+ write("%PDF-1.3\n");
+ break;
+ case PDFOptions::PDFVersion_14:
+ write("%PDF-1.4\n");
+ break;
+ case PDFOptions::PDFVersion_X4:
+ case PDFOptions::PDFVersion_15:
+ write("%PDF-1.5\n");
+ break;
+ }
+ write("%\xc7\xec\x8f\xa2\n");
+ }
+
+ void Writer::writeXrefAndTrailer()
+ {
+ QByteArray tmp;
+ uint StX = bytesWritten();
+ write("xref\n");
+ write("0 "+Pdf::toPdf(ObjCounter)+"\n");
+ //write("0000000000 65535 f \n");
+ for (int a = 0; a < XRef.count(); ++a)
+ {
+ if (XRef[a] > 0)
+ {
+ tmp.setNum(XRef[a]);
+ while (tmp.length()< 10)
+ {
+ tmp.prepend('0');
+ }
+ write(tmp);
+ write(" 00000 n \n");
+ }
+ else
+ {
+ // unused object, mark as free-never-to-be-used-again
+ write("0000000000 65535 f \n");
+ }
+ }
+ write("trailer\n<<\n/Size "+Pdf::toPdf(XRef.count())+"\n");
+ QByteArray IDs ="";
+ for (uint cl = 0; cl < 16; ++cl)
+ IDs += (FileID[cl]);
+ QByteArray IDbytes = Pdf::toHexString(IDs);
+ write("/Root 1 0 R\n/Info 2 0 R\n/ID ["+IDbytes+IDbytes+"]\n");
+ if (EncryptObj > 0)
+ write("/Encrypt "+Pdf::toObjRef(EncryptObj)+"\n");
+ write(">>\nstartxref\n");
+ write(Pdf::toPdf(StX)+"\n%%EOF\n");
+ }
+
+
+ void Writer::write(const QByteArray& bytes)
+ {
+ outStream.writeRawData(bytes, bytes.size());
+ }
+
+ void Writer::write(const ResourceDictionary& dict)
+ {
+ write("<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n");
+ if (dict.XObject.count() != 0)
+ {
+ write("/XObject <<\n");
+ ResourceMap::ConstIterator iti;
+ for (iti = dict.XObject.begin(); iti != dict.XObject.end(); ++iti)
+ write(Pdf::toName(iti.key()) + " " + Pdf::toObjRef(iti.value()) + "\n");
+ write(">>\n");
+ }
+ if (dict.Font.count() != 0)
+ {
+ write("/Font << \n");
+ QMap<QByteArray,PdfId>::ConstIterator it2;
+ for (it2 = dict.Font.begin(); it2 != dict.Font.end(); ++it2)
+ write(Pdf::toName(it2.key()) + " " + Pdf::toObjRef(it2.value()) + "\n");
+ write(">>\n");
+ }
+ if (dict.Shading.count() != 0)
+ {
+ write("/Shading << \n");
+ QMap<QByteArray,PdfId>::ConstIterator it3;
+ for (it3 = dict.Shading.begin(); it3 != dict.Shading.end(); ++it3)
+ write(Pdf::toName(it3.key()) + " " + Pdf::toObjRef(it3.value()) + "\n");
+ write(">>\n");
+ }
+ if (dict.Pattern.count() != 0)
+ {
+ write("/Pattern << \n");
+ QMap<QByteArray,PdfId>::ConstIterator it3p;
+ for (it3p = dict.Pattern.begin(); it3p != dict.Pattern.end(); ++it3p)
+ write(Pdf::toName(it3p.key()) + " " + Pdf::toObjRef(it3p.value()) + "\n");
+ write(">>\n");
+ }
+ if (dict.ExtGState.count() != 0)
+ {
+ write("/ExtGState << \n");
+ QMap<QByteArray,PdfId>::ConstIterator it3t;
+ for (it3t = dict.ExtGState.begin(); it3t != dict.ExtGState.end(); ++it3t)
+ write(Pdf::toName(it3t.key()) + " " + Pdf::toObjRef(it3t.value()) + "\n");
+ write(">>\n");
+ }
+ if (dict.Properties.count() != 0)
+ {
+ write("/Properties << \n");
+ QMap<QByteArray,PdfId>::ConstIterator it4p;
+ for (it4p = dict.ExtGState.begin(); it4p != dict.ExtGState.end(); ++it4p)
+ write(Pdf::toName(it4p.key()) + " " + Pdf::toObjRef(it4p.value()) + "\n");
+ write(">>\n");
+ }
+ if (dict.ColorSpace.count() != 0)
+ {
+ write("/ColorSpace << \n");
+ QList<Resource>::ConstIterator it3c;
+ for (it3c = dict.ColorSpace.begin(); it3c != dict.ColorSpace.end(); ++it3c)
+ write(Pdf::toName(it3c->ResName) + " " + Pdf::toObjRef(it3c->ResNum) + "\n");
+
+ write(">>\n");
+ }
+ write(">>\n");
+ }
+
+
+ PdfId Writer::reserveObjects(unsigned int n)
+ {
+ assert( n < (1<<30) ); // should only be triggered by reserveObjects(-1) or similar
+ PdfId result = ObjCounter;
+ ObjCounter += n;
+ return result;
+ }
+
+ void Writer::startObj(PdfId id)
+ {
+ assert( CurrentObj == 0);
+ CurrentObj = id;
while (static_cast<uint>(XRef.length()) <= id)
- XRef.append(0);
- XRef[id] = bytesWritten();
- write(toPdf(id));
- write(" 0 obj\n");
- }
-
- void Writer::endObj(PdfId id)
- {
- assert( CurrentObj == id);
- CurrentObj = 0;
- write("\nendobj\n");
- }
-
- void Writer::endObjectWithStream(bool encrypted, PdfId id, const QByteArray& streamContent)
- {
- assert( CurrentObj == id);
- write("\nstream\n");
- write(encrypted? encryptBytes(streamContent, id): streamContent);
- write("\nendstream");
- endObj(id);
- }
-
+ XRef.append(0);
+ XRef[id] = bytesWritten();
+ write(toPdf(id));
+ write(" 0 obj\n");
+ }
+
+ void Writer::endObj(PdfId id)
+ {
+ assert( CurrentObj == id);
+ CurrentObj = 0;
+ write("\nendobj\n");
+ }
+
+ void Writer::endObjectWithStream(bool encrypted, PdfId id, const QByteArray& streamContent)
+ {
+ assert( CurrentObj == id);
+ write("\nstream\n");
+ write(encrypted? encryptBytes(streamContent, id): streamContent);
+ write("\nendstream");
+ endObj(id);
+ }
+
} // namespace PDF
Modified: trunk/Scribus/scribus/pdfwriter.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20112&path=/trunk/Scribus/scribus/pdfwriter.h
==============================================================================
--- trunk/Scribus/scribus/pdfwriter.h (original)
+++ trunk/Scribus/scribus/pdfwriter.h Wed May 20 22:39:10 2015
@@ -23,111 +23,111 @@
namespace Pdf
{
-
-
- bool isWhiteSpace(char c);
- bool isDelimiter(char c);
- bool isRegular(char c);
-
- /**
- convert unicode to 8-Bit PdfDocEncoding, cf. PDF32000-2008, 8.9.2 and Annex D
- */
- QByteArray toPdfDocEncoding(QString s);
-
- /**
- conert unicode to UTF16BE with byte order marker, cf. PDF32000-2008, 8.9.2
- */
- QByteArray toUTF16(QString s);
-
- /**
- convert to 7-Bit ASCII, undefined for characters outside 0-127
- */
- QByteArray toAscii(QString s);
-
- /**
- Cf. PDF32000-2008, 7.3.2
- */
- QByteArray toPdf(bool v);
-
- /**
- Cf. PDF32000-2008, 7.3.3
- */
- QByteArray toPdf(int v);
-
- /**
- Cf. PDF32000-2008, 7.3.3
- */
- QByteArray toPdf(uint v);
-
- /**
- Cf. PDF32000-2008, 7.3.3
- */
- QByteArray toPdf(qlonglong v);
-
- /**
- Cf. PDF32000-2008, 7.3.3
- */
- QByteArray toPdf(qulonglong v);
-
- /**
- Cf. PDF32000-2008, 7.3.3
- */
- QByteArray toPdf(double v);
-
- /**
- Cf. PDF32000-2008, 7.3.3
- */
- QByteArray toObjRef(PdfId id);
-
- /**
- convert to a PDF literal string in parentheses. Escape (, ) \ as necessary.
- Cf. PDF32000-2008, 7.3.4.2
- */
- QByteArray toLiteralString(QByteArray s);
- QByteArray toLiteralString(QString s);
-
- /**
- convert to PDF hex string in <> brackets. Cf. PDF32000-2008, 7.3.4.3
- */
- QByteArray toHexString(QByteArray s);
-
- /**
- convert to a one-byte PDF hex string <hh>. Cf. PDF32000-2008, 7.3.4.3
- */
- QByteArray toHexString8(quint8 b);
-
- /**
- convert to a two-byte PDF hex string <hh>. Cf. PDF32000-2008, 7.3.4.3
- */
- QByteArray toHexString16(quint16 b);
-
- /**
- convert to a four-byte PDF hex string <hh>. Cf. PDF32000-2008, 7.3.4.3
- */
- QByteArray toHexString32(quint32 b);
-
- /**
- convert to a PDF 8-Bit name with preceding /.
- Escapes delimiters and chars > 127 with # as necessaray.
- Cf. PDF32000-2008, 7.3.5
- */
- QByteArray toName(QByteArray s);
- QByteArray toName(QString s);
-
- /**
- converts to a PDF date string, cf. PDF32000-2008, 8.9.4
- */
- QByteArray toDateString(QDateTime dt);
-
- /**
- converts to a PDF rectangle, cf. PDF32000-2008, 8.9.5
- */
- QByteArray toRectangleArray(QRect r);
- QByteArray toRectangleArray(QRectF r);
-
-
-
-
+
+
+ bool isWhiteSpace(char c);
+ bool isDelimiter(char c);
+ bool isRegular(char c);
+
+ /**
+ convert unicode to 8-Bit PdfDocEncoding, cf. PDF32000-2008, 8.9.2 and Annex D
+ */
+ QByteArray toPdfDocEncoding(QString s);
+
+ /**
+ convert unicode to UTF16BE with byte order marker, cf. PDF32000-2008, 8.9.2
+ */
+ QByteArray toUTF16(QString s);
+
+ /**
+ convert to 7-Bit ASCII, undefined for characters outside 0-127
+ */
+ QByteArray toAscii(QString s);
+
+ /**
+ Cf. PDF32000-2008, 7.3.2
+ */
+ QByteArray toPdf(bool v);
+
+ /**
+ Cf. PDF32000-2008, 7.3.3
+ */
+ QByteArray toPdf(int v);
+
+ /**
+ Cf. PDF32000-2008, 7.3.3
+ */
+ QByteArray toPdf(uint v);
+
+ /**
+ Cf. PDF32000-2008, 7.3.3
+ */
+ QByteArray toPdf(qlonglong v);
+
+ /**
+ Cf. PDF32000-2008, 7.3.3
+ */
+ QByteArray toPdf(qulonglong v);
+
+ /**
+ Cf. PDF32000-2008, 7.3.3
+ */
+ QByteArray toPdf(double v);
+
+ /**
+ Cf. PDF32000-2008, 7.3.3
+ */
+ QByteArray toObjRef(PdfId id);
+
+ /**
+ convert to a PDF literal string in parentheses. Escape (, ) \ as necessary.
+ Cf. PDF32000-2008, 7.3.4.2
+ */
+ QByteArray toLiteralString(QByteArray s);
+ QByteArray toLiteralString(QString s);
+
+ /**
+ convert to PDF hex string in <> brackets. Cf. PDF32000-2008, 7.3.4.3
+ */
+ QByteArray toHexString(QByteArray s);
+
+ /**
+ convert to a one-byte PDF hex string <hh>. Cf. PDF32000-2008, 7.3.4.3
+ */
+ QByteArray toHexString8(quint8 b);
+
+ /**
+ convert to a two-byte PDF hex string <hh>. Cf. PDF32000-2008, 7.3.4.3
+ */
+ QByteArray toHexString16(quint16 b);
+
+ /**
+ convert to a four-byte PDF hex string <hh>. Cf. PDF32000-2008, 7.3.4.3
+ */
+ QByteArray toHexString32(quint32 b);
+
+ /**
+ convert to a PDF 8-Bit name with preceding /.
+ Escapes delimiters and chars > 127 with # as necessaray.
+ Cf. PDF32000-2008, 7.3.5
+ */
+ QByteArray toName(QByteArray s);
+ QByteArray toName(QString s);
+
+ /**
+ converts to a PDF date string, cf. PDF32000-2008, 8.9.4
+ */
+ QByteArray toDateString(QDateTime dt);
+
+ /**
+ converts to a PDF rectangle, cf. PDF32000-2008, 8.9.5
+ */
+ QByteArray toRectangleArray(QRect r);
+ QByteArray toRectangleArray(QRectF r);
+
+
+
+
/**
* This class handles output to PDF files.
* It implements the "Syntax" section of the PDF specification:
@@ -146,79 +146,79 @@
class Writer
{
public:
- Writer();
-
- // file handling
- bool open (const QString& filename);
- QDataStream& getOutStream() { return outStream; }
- bool close(bool aborted);
- qint64 bytesWritten() { return Spool.pos(); }
-
- // encryption
- void setFileId(const QByteArray& id);
- void setEncryption(bool keylen16, const QByteArray& ownerKey, const QByteArray& userKey, int permissions);
- QByteArray encryptBytes(const QByteArray& in, PdfId objNum);
-
- QByteArray ComputeRC4Key(PdfId ObjNum);
+ Writer();
+
+ // file handling
+ bool open (const QString& filename);
+ QDataStream& getOutStream() { return outStream; }
+ bool close(bool aborted);
+ qint64 bytesWritten() { return Spool.pos(); }
+
+ // encryption
+ void setFileId(const QByteArray& id);
+ void setEncryption(bool keylen16, const QByteArray& ownerKey, const QByteArray& userKey, int permissions);
+ QByteArray encryptBytes(const QByteArray& in, PdfId objNum);
+
+ QByteArray ComputeRC4Key(PdfId ObjNum);
private:
- void CalcOwnerKey(const QByteArray & Owner, const QByteArray & User);
- void CalcUserKey(const QByteArray & User, int Permission);
- QByteArray FitKey(const QByteArray & pass);
+ void CalcOwnerKey(const QByteArray & Owner, const QByteArray & User);
+ void CalcUserKey(const QByteArray & User, int Permission);
+ QByteArray FitKey(const QByteArray & pass);
public:
-
- // writing
- void writeHeader(PDFOptions::PDFVersion vers);
- void writeXrefAndTrailer();
+
+ // writing
+ void writeHeader(PDFOptions::PDFVersion vers);
+ void writeXrefAndTrailer();
void write(const QByteArray& bytes);
- void write(const Pdf::ResourceDictionary& dict);
- void write(const PdfFont font);
-
- // objects
- PdfId reserveObjects(unsigned int n);
-
- PdfId newObject() { return reserveObjects(1); }
-
- void startObj(PdfId id);
-
- PdfId startObj() {
- PdfId res = newObject(); startObj(res); return res;
- }
-
- void endObj(PdfId id);
- void endObjectWithStream(bool encrypted, PdfId id, const QByteArray& streamContent);
- ScStreamFilter* openStreamFilter(bool encrypted, PdfId objId);
-
-
- // private:
- PdfId CatalogObj; // 1
- PdfId InfoObj; // 2
- PdfId OutlinesObj; // 3
- PdfId PagesObj; // 4
- PdfId DestsObj; // 5
- PdfId AcroFormObj; // 6
- PdfId NamesObj; // 7
- PdfId ThreadsObj; // 8
- PdfId OCPropertiesObj; // (9)
- PdfId OutputIntentObj; // (9 or 10)
- PdfId EncryptObj;
- PdfId MetaDataObj;
- PdfId ResourcesObj;
-
+ void write(const Pdf::ResourceDictionary& dict);
+ void write(const PdfFont font);
+
+ // objects
+ PdfId reserveObjects(unsigned int n);
+
+ PdfId newObject() { return reserveObjects(1); }
+
+ void startObj(PdfId id);
+
+ PdfId startObj() {
+ PdfId res = newObject(); startObj(res); return res;
+ }
+
+ void endObj(PdfId id);
+ void endObjectWithStream(bool encrypted, PdfId id, const QByteArray& streamContent);
+ ScStreamFilter* openStreamFilter(bool encrypted, PdfId objId);
+
+
+ // private:
+ PdfId CatalogObj; // 1
+ PdfId InfoObj; // 2
+ PdfId OutlinesObj; // 3
+ PdfId PagesObj; // 4
+ PdfId DestsObj; // 5
+ PdfId AcroFormObj; // 6
+ PdfId NamesObj; // 7
+ PdfId ThreadsObj; // 8
+ PdfId OCPropertiesObj; // (9)
+ PdfId OutputIntentObj; // (9 or 10)
+ PdfId EncryptObj;
+ PdfId MetaDataObj;
+ PdfId ResourcesObj;
+
private:
- PdfId ObjCounter;
- PdfId CurrentObj;
-
- QFile Spool;
- QDataStream outStream;
-
- QList<qint64> XRef;
-
- QByteArray KeyGen;
- QByteArray OwnerKey;
- QByteArray UserKey;
- QByteArray FileID;
- QByteArray EncryKey;
- int KeyLen;
+ PdfId ObjCounter;
+ PdfId CurrentObj;
+
+ QFile Spool;
+ QDataStream outStream;
+
+ QList<qint64> XRef;
+
+ QByteArray KeyGen;
+ QByteArray OwnerKey;
+ QByteArray UserKey;
+ QByteArray FileID;
+ QByteArray EncryKey;
+ int KeyLen;
};
More information about the scribus-commit
mailing list