-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_ps.cpp
More file actions
104 lines (93 loc) · 3.3 KB
/
Copy pathrender_ps.cpp
File metadata and controls
104 lines (93 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Renderer for Postscript documents.
* Copyright (c) 2021-2026 Benjamin Johnson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <cstdlib> // for std::getenv()
#include <QtCore>
#include "render_ps.h"
#include "renderer_util.h"
static const QString findGhostscript();
PSRenderer::PSRenderer()
: PDFRenderer()
{
}
bool PSRenderer::load()
{
QString program = findHelper("helpers/gs", findGhostscript());
if (program.isEmpty()) {
storeLoadError("Cannot display this file because Ghostscript "
"is not installed.");
return false;
}
QStringList arguments;
arguments << "-q"
<< "-dBATCH"
<< "-dNOPAUSE"
<< "-dSAFER"
<< "-sDEVICE=pdfwrite"
<< "-sOutputFile=-"
<< path();
return loadFromData(runHelper(program, arguments));
}
/*
* Helper function to return the path to the Ghostscript executable.
*/
const QString findGhostscript()
{
static QString program;
if (program.isEmpty()) {
#ifdef Q_OS_WIN
// Possible names for the Ghostscript executable
// Note we include all possible names regardless of the target
// platform so that a 32-bit Renamifier can still find a 64-bit
// Ghostscript if running on such a system.
QStringList gsNames;
gsNames << "gswin64c.exe"
<< "gswin32c.exe";
// Possible names for %ProgramFiles%
QStringList pfDirs;
pfDirs << std::getenv("ProgramFiles")
<< std::getenv("ProgramW6432")
<< std::getenv("ProgramFiles(x86)");
// Ghostscript is usually found under a versioned path like
// %ProgramFiles%\gs\gs9.27\bin
for (int i = 0; i < pfDirs.size(); ++i) {
if (pfDirs[i].isEmpty())
continue;
// Search for Ghostscript installations
QDir gsBaseDir(pfDirs[i] + "/gs");
QStringList gsDirs =
gsBaseDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
for (int j = 0; j < gsDirs.size(); ++j) {
// See what executables this installation provides
for (int k = 0; k < gsNames.size(); ++k) {
QString gsExe = gsBaseDir.path() + "/"
+ gsDirs[j] + "/bin/" + gsNames[k];
if (QFileInfo(gsExe).isExecutable()) {
program = gsExe;
goto finished;
}
}
}
}
#else /* Q_OS_WIN */
program = findInSystemPath("gs");
#endif /* Q_OS_WIN */
}
finished:
return program;
}