r24500 by jghali - Fix regression with loading of color palettes

scribus-commit scribus-commit at lists.scribus.net
Wed Feb 17 21:26:40 UTC 2021


Author: jghali
Date: Wed Feb 17 21:26:39 2021
New Revision: 24500

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24500
Log:
Fix regression with loading of color palettes

Modified:
    trunk/Scribus/scribus/loadsaveplugin.h
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h

Modified: trunk/Scribus/scribus/loadsaveplugin.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24500&path=/trunk/Scribus/scribus/loadsaveplugin.h
==============================================================================
--- trunk/Scribus/scribus/loadsaveplugin.h	(original)
+++ trunk/Scribus/scribus/loadsaveplugin.h	Wed Feb 17 21:26:39 2021
@@ -105,6 +105,9 @@
 		// file type (eg "XML doc with root element SCRIBUSXML and version 1.3.1").
 		// All plugins must implement this method.
 		virtual bool fileSupported(QIODevice* file, const QString & fileName=QString()) const = 0;
+
+		// Examine if the passed palette data to see whether it appears to be loadable with this plugin
+		virtual bool paletteSupported(QIODevice* file, const QString & fileName=QString()) const { return false; }
 
 		// Examine if the passed story data to see whether it appears to be loadable with this plugin
 		virtual bool storySupported(const QByteArray& storyData) const { return false; }

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24500&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp	Wed Feb 17 21:26:39 2021
@@ -152,6 +152,30 @@
 	return false;
 }
 
+bool Scribus150Format::paletteSupported(QIODevice* /* file */, const QString & fileName) const
+{
+	QByteArray docBytes("");
+	if (fileName.right(2) == "gz")
+	{
+		QFile file(fileName);
+		QtIOCompressor compressor(&file);
+		compressor.setStreamFormat(QtIOCompressor::GzipFormat);
+		compressor.open(QIODevice::ReadOnly);
+		docBytes = compressor.read(1024);
+		compressor.close();
+		if (docBytes.isEmpty())
+			return false;
+	}
+	else
+	{
+		// Not gzip encoded, just load it
+		loadRawBytes(fileName, docBytes, 1024);
+	}
+
+	int startElemPos = docBytes.indexOf("<SCRIBUSCOLORS");
+	return (startElemPos >= 0);
+}
+
 bool Scribus150Format::storySupported(const QByteArray& storyData) const
 {
 	QRegExp regExp150("Version=\"1.5.[0-9]");
@@ -167,6 +191,36 @@
 QIODevice* Scribus150Format::slaReader(const QString & fileName)
 {
 	if (!fileSupported(nullptr, fileName))
+		return nullptr;
+
+	QIODevice* ioDevice = nullptr;
+	if (fileName.right(2) == "gz")
+	{
+		aFile.setFileName(fileName);
+		QtIOCompressor *compressor = new QtIOCompressor(&aFile);
+		compressor->setStreamFormat(QtIOCompressor::GzipFormat);
+		if (!compressor->open(QIODevice::ReadOnly))
+		{
+			delete compressor;
+			return nullptr;
+		}
+		ioDevice = compressor;
+	}
+	else
+	{
+		ioDevice = new QFile(fileName);
+		if (!ioDevice->open(QIODevice::ReadOnly))
+		{
+			delete ioDevice;
+			return nullptr;
+		}
+	}
+	return ioDevice;
+}
+
+QIODevice* Scribus150Format::paletteReader(const QString & fileName)
+{
+	if (!paletteSupported(nullptr, fileName))
 		return nullptr;
 
 	QIODevice* ioDevice = nullptr;
@@ -962,7 +1016,7 @@
 	QStack<int> groupStackMI2;
 	QStack<int> groupStackPI2;
 
-	QScopedPointer<QIODevice> ioDevice(slaReader(fileName));
+	QScopedPointer<QIODevice> ioDevice(paletteReader(fileName));
 	if (ioDevice.isNull())
 	{
 		setFileReadError();

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24500&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h	(original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h	Wed Feb 17 21:26:39 2021
@@ -50,7 +50,7 @@
 
 		//Not the same as readSLA. This one only reads max 4k of the file for speed.
 		bool fileSupported(QIODevice* file, const QString & fileName=QString()) const override;
-
+		bool paletteSupported(QIODevice* file, const QString & fileName=QString()) const override;
 		bool storySupported(const QByteArray& storyData) const override;
 
 		bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0) override;
@@ -116,6 +116,7 @@
 		void registerFormats();
 		
 		QIODevice* slaReader(const QString & fileName);
+		QIODevice* paletteReader(const QString & fileName);
 
 		void getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *docParagraphStyles, ScribusDoc* doc, bool equiv);
 		void getStyle(CharStyle& style, ScXmlStreamReader& reader, StyleSet<CharStyle> *docCharStyles, ScribusDoc* doc, bool equiv);




More information about the scribus-commit mailing list