r22389 by jghali -

scribus-commit scribus-commit at lists.scribus.net
Tue Feb 13 22:46:43 UTC 2018


Author: jghali
Date: Tue Feb 13 22:46:43 2018
New Revision: 22389

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22389
Log:
#15145: Javascript fails to execute on PDF opening when PDF security is enabled

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=22389&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp	(original)
+++ trunk/Scribus/scribus/pdflib_core.cpp	Tue Feb 13 22:46:43 2018
@@ -1116,7 +1116,8 @@
 			PutDoc("/PageMode /UseOC\n");
 	if (!Options.openAction.isEmpty())
 	{
-		PutDoc("/OpenAction << /S /JavaScript /JS (this."+Pdf::toPdfDocEncoding(Options.openAction)+"\\(\\)) >>\n");
+		writer.OpenActionObj = writer.newObject();
+		PutDoc("/OpenAction << /S /JavaScript /JS " + Pdf::toPdf(writer.OpenActionObj) + " 0 R >>\n");
 	}
 	QDateTime dt = QDateTime::currentDateTimeUtc();
 	Datum = Pdf::toDateString(dt);
@@ -1217,28 +1218,6 @@
 		PutDoc("/GTS_PDFXVersion (PDF/X-4)\n");
 	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());
-//	if (PDF_IsPDFX())
-//		XRef.append(bytesWritten());
-//	if (Options.Version == PDFOptions::PDFVersion_X4)
-//		XRef.append(bytesWritten());
-	if (Options.Encrypt)
-	{ // now done in writer.setEncrption():
-//		writer.EncryptObj = writer.newObject();
-//		writer.startObj(writer.EncryptObj);
-//		PutDoc("<<\n/Filter /Standard\n");
-//		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);
-	}
 }
 
 QMap<QString, QMap<uint, FPointArray> >
@@ -9702,16 +9681,21 @@
 PdfId PDFLibCore::WritePDFStream(const QByteArray& cc)
 {
 	PdfId result = writer.newObject();
+	return WritePDFStream(cc, result);
+}
+
+PdfId PDFLibCore::WritePDFStream(const QByteArray& cc, PdfId objId)
+{
 	QByteArray tmp(cc);
 	if (Options.Compress)
 		tmp = CompressArray(tmp);
-	writer.startObj(result);
-	PutDoc("<< /Length "+Pdf::toPdf(tmp.length()));  // moeglicherweise +1
+	writer.startObj(objId);
+	PutDoc("<< /Length " + Pdf::toPdf(tmp.length()));  // moeglicherweise +1
 	if (Options.Compress)
 		PutDoc("\n/Filter /FlateDecode");
-	PutDoc(" >>\nstream\n"+EncStream(tmp, result)+"\nendstream");
-	writer.endObj(result);
-	return result;
+	PutDoc(" >>\nstream\n" + EncStream(tmp, objId) + "\nendstream");
+	writer.endObj(objId);
+	return objId;
 }
 
 PdfId PDFLibCore::WritePDFString(const QString& cc)
@@ -9730,6 +9714,24 @@
 		}
 	}
 	return WritePDFStream(tmp);
+}
+
+PdfId PDFLibCore::WritePDFString(const QString& cc, PdfId objId)
+{
+	QByteArray tmp;
+	for (int i = 0; i < cc.length(); ++i)
+	{
+		uchar pdfChar = Pdf::toPdfDocEncoding(cc[i]);
+		if ((pdfChar != 0) || cc[i].isNull())
+			tmp += pdfChar;
+		else
+		{
+			tmp += "\\u";
+			tmp += toHex(cc[i].row());
+			tmp += toHex(cc[i].cell());
+		}
+	}
+	return WritePDFStream(tmp, objId);
 }
 
 void PDFLibCore::PDF_xForm(PdfId objNr, double w, double h, QByteArray im)
@@ -11095,6 +11097,9 @@
 
 void PDFLibCore::PDF_End_JavaScripts()
 {
+	if (writer.OpenActionObj != 0)
+		WritePDFString("this." + Options.openAction + "()", writer.OpenActionObj);
+
 	if (writer.NamesObj == 0)
 		return;
 

Modified: trunk/Scribus/scribus/pdflib_core.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22389&path=/trunk/Scribus/scribus/pdflib_core.h
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.h	(original)
+++ trunk/Scribus/scribus/pdflib_core.h	Tue Feb 13 22:46:43 2018
@@ -192,7 +192,9 @@
 //	void       StartObj(PdfId nr);
 //	uint       newObject() { return ObjCounter++; }
 	uint       WritePDFStream(const QByteArray& cc);
+	uint       WritePDFStream(const QByteArray& cc, PdfId objId);
 	uint       WritePDFString(const QString& cc);
+	uint       WritePDFString(const QString& cc, PdfId objId);
 	void       writeXObject(uint objNr, QByteArray dictionary, QByteArray stream);
 	uint       writeObject(QByteArray type, QByteArray dictionary);
 	uint       writeGState(QByteArray dictionary) { return writeObject("/ExtGState", dictionary); }

Modified: trunk/Scribus/scribus/pdfwriter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22389&path=/trunk/Scribus/scribus/pdfwriter.cpp
==============================================================================
--- trunk/Scribus/scribus/pdfwriter.cpp	(original)
+++ trunk/Scribus/scribus/pdfwriter.cpp	Tue Feb 13 22:46:43 2018
@@ -490,6 +490,7 @@
 		EncryptObj = 0;
 		MetaDataObj = 0;
 		ResourcesObj = 0;
+		OpenActionObj = 0;
 		
 		m_ObjCounter = 0;
 		m_CurrentObj = 0;

Modified: trunk/Scribus/scribus/pdfwriter.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22389&path=/trunk/Scribus/scribus/pdfwriter.h
==============================================================================
--- trunk/Scribus/scribus/pdfwriter.h	(original)
+++ trunk/Scribus/scribus/pdfwriter.h	Tue Feb 13 22:46:43 2018
@@ -213,6 +213,7 @@
 	PdfId EncryptObj; 
 	PdfId MetaDataObj;
 	PdfId ResourcesObj;
+	PdfId OpenActionObj;
 	
 private:
 	PdfId m_ObjCounter;




More information about the scribus-commit mailing list