void-packages/srcpkgs/scribus/patches/0011-podofo-0.10-code-style...

142 lines
6.2 KiB
Diff

From 9cd60ef7831fff69f2dacc2bf216c3537b2cd6e9 Mon Sep 17 00:00:00 2001
From: Jean Ghali <jghali@libertysurf.fr>
Date: Sat, 12 Aug 2023 21:12:49 +0000
Subject: [PATCH 07/13] PDFAnalyzer: code style fixes and cleanups
git-svn-id: svn://scribus.net/trunk/Scribus@25573 11d20701-8431-0410-a711-e3c959e3b870
(cherry picked from commit 9be7a29f08a00bb3c10024cd9a31a82742d42e22)
---
scribus/pdf_analyzer.cpp | 56 +++++++++++++++++++++-------------------
1 file changed, 30 insertions(+), 26 deletions(-)
--- a/scribus/pdf_analyzer.cpp
+++ b/scribus/pdf_analyzer.cpp
@@ -78,7 +78,8 @@ PDFAnalyzer::PDFAnalyzer(QString & filen
m_pdfdoc = nullptr;
PdfError::EnableDebug( false );
- try {
+ try
+ {
m_pdfdoc = new PdfMemDocument(filename.toLocal8Bit().data());
}
catch (PdfError & e)
@@ -99,12 +100,13 @@ bool PDFAnalyzer::inspectPDF(int pageNum
if (!m_pdfdoc)
return false;
PdfPage* page = m_pdfdoc->GetPage(pageNum);
- return page?inspectCanvas(page, usedColorSpaces, hasTransparency, usedFonts, imgs):false;
+ return page ? inspectCanvas(page, usedColorSpaces, hasTransparency, usedFonts, imgs) : false;
}
PDFColorSpace PDFAnalyzer::getCSType(PdfObject* cs)
{
- try {
+ try
+ {
// colorspace is either a name or an array
if (cs && cs->IsName())
{
@@ -165,20 +167,21 @@ PDFColorSpace PDFAnalyzer::getCSType(Pdf
bool PDFAnalyzer::inspectCanvas(PdfCanvas* canvas, QList<PDFColorSpace> & usedColorSpaces, bool & hasTransparency, QList<PDFFont> & usedFonts, QList<PDFImage> & imgs)
{
// this method can be used to get used color spaces, detect transparency, and get used fonts in either PdfPage or PdfXObject
- PdfObject* colorSpaceRes;
- PdfObject* xObjects;
- PdfObject* transGroup;
- PdfObject* extGState;
- PdfObject* fontRes;
+ PdfObject* colorSpaceRes { nullptr };
+ PdfObject* xObjects { nullptr };
+ PdfObject* transGroup { nullptr };
+ PdfObject* extGState { nullptr };
+ PdfObject* fontRes { nullptr };
QMap<PdfName, PDFColorSpace> processedNamedCS;
QMap<PdfName, PDFFont> processedNamedFont;
QList<PdfName> processedNamedXObj;
QList<PdfName> processedNamedGS;
- try {
+ try
+ {
// get hold of a PdfObject pointer of this canvas
// needed for the finding resources code below to work
PdfPage* page = dynamic_cast<PdfPage*>(canvas);
- PdfObject* canvasObject = page?(page->GetObject()):((dynamic_cast<PdfXObject*>(canvas))->GetObject());
+ PdfObject* canvasObject = page ? (page->GetObject()) : ((dynamic_cast<PdfXObject*>(canvas))->GetObject());
// find a resource with ColorSpace entry
PdfObject* resources = canvas->GetResources();
@@ -186,13 +189,13 @@ bool PDFAnalyzer::inspectCanvas(PdfCanva
{
resources = par->GetIndirectKey("Resources");
}
- colorSpaceRes = resources?resources->GetIndirectKey("ColorSpace"):nullptr;
- xObjects = resources?resources->GetIndirectKey("XObject"):nullptr;
- extGState = resources?resources->GetIndirectKey("ExtGState"):nullptr;
- fontRes = resources?resources->GetIndirectKey("Font"):nullptr;
+ colorSpaceRes = resources ? resources->GetIndirectKey("ColorSpace") : nullptr;
+ xObjects = resources ? resources->GetIndirectKey("XObject") : nullptr;
+ extGState = resources ? resources->GetIndirectKey("ExtGState") : nullptr;
+ fontRes = resources ? resources->GetIndirectKey("Font") : nullptr;
// getting the transparency group of this content stream (if available)
- transGroup = canvasObject?canvasObject->GetIndirectKey("Group"):nullptr;
+ transGroup = canvasObject ? canvasObject->GetIndirectKey("Group") : nullptr;
if (transGroup)
{
PdfObject* subtype = transGroup->GetIndirectKey("S");
@@ -219,7 +222,8 @@ bool PDFAnalyzer::inspectCanvas(PdfCanva
return false;
}
- try {
+ try
+ {
// start parsing the content stream
PdfContentsTokenizer tokenizer(canvas);
EPdfContentsType t;
@@ -502,7 +506,7 @@ bool PDFAnalyzer::inspectCanvas(PdfCanva
if (args.size() == 1 && args[0].IsName() && xObjects)
{
PdfObject* xObject = xObjects->GetIndirectKey(args[0].GetName());
- PdfObject* subtypeObject = xObject?xObject->GetIndirectKey("Subtype"):nullptr;
+ PdfObject* subtypeObject = xObject ? xObject->GetIndirectKey("Subtype") : nullptr;
if (subtypeObject && subtypeObject->IsName())
{
if (subtypeObject->GetName() == "Image")
@@ -557,10 +561,10 @@ bool PDFAnalyzer::inspectCanvas(PdfCanva
PdfName cs("CS");
if (args.contains(colorspace) || args.contains(cs))
{
- int csIdx = args.contains(colorspace)?args.indexOf(colorspace):args.indexOf(cs);
- if (args[csIdx+1].IsName())
+ int csIdx = args.contains(colorspace) ? args.indexOf(colorspace) : args.indexOf(cs);
+ if (args[csIdx + 1].IsName())
{
- PdfName csName = args[csIdx+1].GetName();
+ PdfName csName = args[csIdx + 1].GetName();
if ((csName == "G" || csName == "DeviceGray") && !usedColorSpaces.contains(CS_DeviceGray))
usedColorSpaces.append(CS_DeviceGray);
else if ((csName == "RGB" || csName == "DeviceRGB") && !usedColorSpaces.contains(CS_DeviceRGB))
@@ -594,14 +598,14 @@ bool PDFAnalyzer::inspectCanvas(PdfCanva
PdfName w("W");
if ((args.contains(height) || args.contains(h)) && (args.contains(width) || args.contains(w)))
{
- int heightIdx = args.contains(height)?args.indexOf(height):args.indexOf(h);
- int widthIdx = args.contains(width)?args.indexOf(width):args.indexOf(w);
- double height = args[heightIdx+1].GetReal();
- double width = args[widthIdx+1].GetReal();
+ int heightIdx = args.contains(height) ? args.indexOf(height) : args.indexOf(h);
+ int widthIdx = args.contains(width) ? args.indexOf(width) : args.indexOf(w);
+ double height = args[heightIdx + 1].GetReal();
+ double width = args[widthIdx + 1].GetReal();
PDFImage img;
img.imgName = "Inline Image";
- img.dpiX = qRound(width/(currGS.ctm.m11()/72));
- img.dpiY = qRound(height/(currGS.ctm.m22()/72));
+ img.dpiX = qRound(width / (currGS.ctm.m11() / 72));
+ img.dpiY = qRound(height / (currGS.ctm.m22() / 72));
imgs.append(img);
}
inlineImgDict = false;