Skip to content

Commit 8510d70

Browse files
CodeQL Warnings export functions for PDF, SVG, TIFF, and GIF formats; remove XmlDocMakeSummary.cpp
1 parent 96548ad commit 8510d70

File tree

9 files changed

+134
-318
lines changed

9 files changed

+134
-318
lines changed

modules/graphics_io/src/cpp/ExportGraphics.cpp

Lines changed: 103 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,90 @@ getExportImageFormatFromString(const std::wstring& extension)
9292
return ERROR_EXPORT;
9393
}
9494
//=============================================================================
95+
static bool exportToPDF(GOWindow* f, const std::wstring& filename, GOFigure* hf)
96+
{
97+
QPrinter printer(QPrinter::ScreenResolution);
98+
printer.setOutputFormat(QPrinter::PdfFormat);
99+
printer.setOutputFileName(wstringToQString(filename));
100+
QPainter painter;
101+
painter.begin(&printer);
102+
const auto pageLayout = printer.pageLayout();
103+
const auto pageRect = pageLayout.paintRectPixels(printer.resolution());
104+
const auto paperRect = pageLayout.fullRectPixels(printer.resolution());
105+
double xscale = pageRect.width() / double(f->width());
106+
double yscale = pageRect.height() / double(f->height());
107+
double scale = qMin(xscale, yscale);
108+
painter.translate(
109+
pageRect.x() + paperRect.width() / 2., pageRect.y() + paperRect.height() / 2.);
110+
painter.scale(scale, scale);
111+
painter.translate(-f->width() / 2., -f->height() / 2.);
112+
RenderQt gc(&painter, 0, 0, f->width(), f->height(), L"PDF");
113+
hf->paintMe(gc);
114+
return true;
115+
}
116+
//=============================================================================
117+
static bool exportToImage(GOWindow* f, const std::wstring& filename, IMAGE_FORMAT exportFormat)
118+
{
119+
QPixmap pxmap(f->getMainQWigdet()->grab());
120+
QImage img(pxmap.toImage());
121+
return img.save(wstringToQString(filename),
122+
wstring_to_utf8(getExportImageFormatAsString(exportFormat)).c_str());
123+
}
124+
//=============================================================================
125+
static bool exportToSVG(GOWindow* f, const std::wstring& filename, GOFigure* hf)
126+
{
127+
QSvgGenerator gen;
128+
int width = f->width();
129+
int height = f->height();
130+
gen.setDescription(QString(""));
131+
gen.setTitle(QString(""));
132+
gen.setFileName(wstringToQString(filename));
133+
gen.setSize(QSize(width, height));
134+
qreal dpi = 96.0;
135+
QScreen* screen = nullptr;
136+
QWidget* mainWidget = f->getMainQWigdet();
137+
if (mainWidget) {
138+
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
139+
screen = mainWidget->screen();
140+
#else
141+
screen = QGuiApplication::screenAt(mainWidget->mapToGlobal(QPoint(0, 0)));
142+
#endif
143+
}
144+
if (!screen) {
145+
screen = QGuiApplication::primaryScreen();
146+
}
147+
if (screen) {
148+
dpi = screen->logicalDotsPerInch();
149+
}
150+
gen.setResolution(dpi);
151+
gen.setViewBox(QRect(0, 0, width, height));
152+
QPainter pnt(&gen);
153+
RenderQt gc(&pnt, 0, 0, width, height, L"SVG");
154+
hf->paintMe(gc);
155+
return true;
156+
}
157+
//=============================================================================
158+
#if WITH_TIFF
159+
static bool exportToTIFF(GOWindow* f, const std::wstring& filename)
160+
{
161+
QPixmap pxmap(f->getMainQWigdet()->grab());
162+
QImage img(pxmap.toImage());
163+
QString errorMessage;
164+
return TiffFileHandler::writeTiff(wstringToQString(filename), img, errorMessage);
165+
}
166+
#endif
167+
//=============================================================================
168+
#if WITH_GIF
169+
static bool exportToGIF(GOWindow* f, const std::wstring& filename)
170+
{
171+
QPixmap pxmap(f->getMainQWigdet()->grab());
172+
QImage img(pxmap.toImage());
173+
QGifImage gif(QSize(img.width(), img.height()));
174+
gif.addFrame(img);
175+
return gif.save(wstringToQString(filename));
176+
}
177+
#endif
178+
//=============================================================================
95179
bool
96180
ExportGraphics(GOWindow* f, const std::wstring& filename, IMAGE_FORMAT exportFormat)
97181
{
@@ -107,87 +191,34 @@ ExportGraphics(GOWindow* f, const std::wstring& filename, IMAGE_FORMAT exportFor
107191
double cb = color->at(2);
108192
hf->setThreeVectorDefault(GO_COLOR_PROPERTY_NAME_STR, 1, 1, 1);
109193
hf->updateState();
194+
110195
switch (exportFormat) {
111-
case PDF_EXPORT: {
112-
QPrinter printer(QPrinter::ScreenResolution);
113-
printer.setOutputFormat(QPrinter::PdfFormat);
114-
printer.setOutputFileName(wstringToQString(filename));
115-
QPainter painter;
116-
painter.begin(&printer);
117-
const auto pageLayout = printer.pageLayout();
118-
const auto pageRect = pageLayout.paintRectPixels(printer.resolution());
119-
const auto paperRect = pageLayout.fullRectPixels(printer.resolution());
120-
double xscale = pageRect.width() / double(f->width());
121-
double yscale = pageRect.height() / double(f->height());
122-
double scale = qMin(xscale, yscale);
123-
painter.translate(
124-
pageRect.x() + paperRect.width() / 2., pageRect.y() + paperRect.height() / 2.);
125-
painter.scale(scale, scale);
126-
painter.translate(-f->width() / 2., -f->height() / 2.);
127-
RenderQt gc(&painter, 0, 0, f->width(), f->height(), L"PDF");
128-
hf->paintMe(gc);
129-
result = true;
130-
} break;
196+
case PDF_EXPORT:
197+
result = exportToPDF(f, filename, hf);
198+
break;
131199
case PNG_EXPORT:
132-
case JPG_EXPORT: {
133-
QPixmap pxmap(f->getMainQWigdet()->grab());
134-
QImage img(pxmap.toImage());
135-
result = img.save(wstringToQString(filename),
136-
wstring_to_utf8(getExportImageFormatAsString(exportFormat)).c_str());
137-
} break;
138-
case SVG_EXPORT: {
139-
QSvgGenerator gen;
140-
int width = f->width();
141-
int height = f->height();
142-
gen.setDescription(QString(""));
143-
gen.setTitle(QString(""));
144-
gen.setFileName(wstringToQString(filename));
145-
gen.setSize(QSize(width, height));
146-
qreal dpi = 96.0;
147-
QScreen* screen = nullptr;
148-
QWidget* mainWidget = f->getMainQWigdet();
149-
if (mainWidget) {
150-
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
151-
screen = mainWidget->screen();
152-
#else
153-
screen = QGuiApplication::screenAt(mainWidget->mapToGlobal(QPoint(0, 0)));
154-
#endif
155-
}
156-
if (!screen) {
157-
screen = QGuiApplication::primaryScreen();
158-
}
159-
if (screen) {
160-
dpi = screen->logicalDotsPerInch();
161-
}
162-
gen.setResolution(dpi);
163-
gen.setViewBox(QRect(0, 0, width, height));
164-
QPainter pnt(&gen);
165-
RenderQt gc(&pnt, 0, 0, width, height, L"SVG");
166-
hf->paintMe(gc);
167-
result = true;
168-
} break;
200+
case JPG_EXPORT:
201+
result = exportToImage(f, filename, exportFormat);
202+
break;
203+
case SVG_EXPORT:
204+
result = exportToSVG(f, filename, hf);
205+
break;
169206
#if WITH_TIFF
170-
case TIF_EXPORT: {
171-
QPixmap pxmap(f->getMainQWigdet()->grab());
172-
QImage img(pxmap.toImage());
173-
QString errorMessage;
174-
result = TiffFileHandler::writeTiff(wstringToQString(filename), img, errorMessage);
175-
} break;
207+
case TIF_EXPORT:
208+
result = exportToTIFF(f, filename);
209+
break;
176210
#endif
177211
#if WITH_GIF
178-
case GIF_EXPORT: {
179-
QPixmap pxmap(f->getMainQWigdet()->grab());
180-
QImage img(pxmap.toImage());
181-
QGifImage gif(QSize(img.width(), img.height()));
182-
gif.addFrame(img);
183-
result = gif.save(wstringToQString(filename));
184-
} break;
212+
case GIF_EXPORT:
213+
result = exportToGIF(f, filename);
214+
break;
185215
#endif
186216
case ERROR_EXPORT:
187-
default: {
217+
default:
188218
result = false;
189-
} break;
219+
break;
190220
}
221+
191222
hf->setThreeVectorDefault(GO_COLOR_PROPERTY_NAME_STR, cr, cg, cb);
192223
hf->updateState();
193224
return result;

modules/help_tools/functions/doc.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ function doc(varargin)
146146
%=============================================================================
147147
function urlfound = searchAny(stSearchResults, query)
148148
urlfound = '';
149+
preparedQuery = [' ', strtrim(query), ' '];
149150
for i = 1:length(stSearchResults)
150151
entry = stSearchResults(i);
151-
if contains(entry.title, query, 'IgnoreCase', true) || contains(entry.content, query, 'IgnoreCase', true)
152+
if contains(entry.title, preparedQuery, 'IgnoreCase', true) || contains(entry.content, preparedQuery, 'IgnoreCase', true)
152153
urlfound = entry.url;
153154
if strcmp(urlfound, '/./index.html') && startsWith(entry.path, 'sections/')
154155
urlfound = ['./', entry.path(strlength('sections/'):end), '/index.html'];

modules/help_tools/resources/search_results.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ <h1 class="search-results-title"></h1>
241241
results.forEach(result => {
242242
const href = appendLangToUrl(result.url || result.path || './homepage.html');
243243
const safeTitle = escapeHTML(result.title || '');
244-
const safeSnippet = escapeHTML(result.snippet || '');
244+
const safeSnippet = result.snippet || '';
245245
const safePath = escapeHTML(result.path || '');
246246
html += `
247247
<div class="result-item">

modules/help_tools/src/c/nlsHelp_tools.vcxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@
227227
<ClCompile Include="..\cpp\XmdDocGeneratesImages.cpp" />
228228
<ClCompile Include="..\cpp\XmlDocBuild.cpp" />
229229
<ClCompile Include="..\cpp\XmlDocListOfFiles.cpp" />
230-
<ClCompile Include="..\cpp\XmlDocMakeSummary.cpp" />
231230
<ClCompile Include="..\cpp\XmlDocMergeSummary.cpp" />
232231
<ClCompile Include="..\cpp\XmlDocPrettify.cpp" />
233232
<ClCompile Include="..\cpp\XmlDocSummary.cpp" />
@@ -264,7 +263,6 @@
264263
<ClInclude Include="..\include\XmlDocBuild.hpp" />
265264
<ClInclude Include="..\include\XmlDocGenerateImages.hpp" />
266265
<ClInclude Include="..\include\XmlDocListOfFiles.hpp" />
267-
<ClInclude Include="..\include\XmlDocMakeSummary.hpp" />
268266
<ClInclude Include="..\include\XmlDocMergeSummary.hpp" />
269267
<ClInclude Include="..\include\XmlDocPrettify.hpp" />
270268
<ClInclude Include="..\include\XmlDocSummary.hpp" />

modules/help_tools/src/c/nlsHelp_tools.vcxproj.filters

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
<ClCompile Include="..\cpp\XmlDocToc.cpp">
4646
<Filter>Source Files</Filter>
4747
</ClCompile>
48-
<ClCompile Include="..\cpp\XmlDocMakeSummary.cpp">
49-
<Filter>Source Files</Filter>
50-
</ClCompile>
5148
<ClCompile Include="..\cpp\XmlDocPrettify.cpp">
5249
<Filter>Source Files</Filter>
5350
</ClCompile>
@@ -185,9 +182,6 @@
185182
<ClInclude Include="..\include\nlsHelp_tools_exports.h">
186183
<Filter>Header Files</Filter>
187184
</ClInclude>
188-
<ClInclude Include="..\include\XmlDocMakeSummary.hpp">
189-
<Filter>Header Files</Filter>
190-
</ClInclude>
191185
<ClInclude Include="..\include\XmlDocPrettify.hpp">
192186
<Filter>Header Files</Filter>
193187
</ClInclude>

modules/help_tools/src/cpp/XmlDocListOfFiles.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ readChapter(const std::wstring& directory, std::string& moduleName, std::string&
142142
count++;
143143
}
144144
} else if (xmlStrcmp(node->name, BAD_CAST "chapter_description") == 0) {
145-
xmlBufferPtr buffer = xmlBufferCreate();
146-
if (buffer) {
145+
xmlBufferPtr xmlBuffer = xmlBufferCreate();
146+
if (xmlBuffer) {
147147
for (xmlNodePtr child = node->children; child; child = child->next) {
148-
xmlNodeDump(buffer, node->doc, child, 0, 0);
148+
xmlNodeDump(xmlBuffer, node->doc, child, 0, 0);
149149
}
150-
chapter_description = (const char*)xmlBufferContent(buffer);
151-
xmlBufferFree(buffer);
150+
chapter_description = (const char*)xmlBufferContent(xmlBuffer);
151+
xmlBufferFree(xmlBuffer);
152152
count++;
153153
}
154154
}

modules/help_tools/src/cpp/XmlDocMakeSummary.cpp

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)