Skip to content

Commit

Permalink
High DPI support: Convert sketcher cursors to SVG
Browse files Browse the repository at this point in the history
Remove xpm
  • Loading branch information
Vanuan authored and wwmayer committed Aug 19, 2020
1 parent 1cad17c commit 7a0aec1
Show file tree
Hide file tree
Showing 29 changed files with 845 additions and 1,768 deletions.
22 changes: 17 additions & 5 deletions src/Gui/BitmapFactory.cpp
Expand Up @@ -23,6 +23,7 @@

#include "PreCompiled.h"
#ifndef _PreComp_
# include <QString>
# include <QApplication>
# include <QBitmap>
# include <QDir>
Expand All @@ -36,7 +37,6 @@
# include <QStyleOption>
# include <sstream>
#endif

#if defined (FC_OS_WIN32) && QT_VERSION < 0x050000
#define QTWEBKIT
#endif
Expand Down Expand Up @@ -296,7 +296,8 @@ QPixmap BitmapFactoryInst::pixmap(const char* name) const
return QPixmap(not_found);
}

QPixmap BitmapFactoryInst::pixmapFromSvg(const char* name, const QSize& size) const
QPixmap BitmapFactoryInst::pixmapFromSvg(const char* name, const QSizeF& size,
const std::map<unsigned long, unsigned long>& colorMapping) const
{
// If an absolute path is given
QPixmap icon;
Expand Down Expand Up @@ -325,15 +326,26 @@ QPixmap BitmapFactoryInst::pixmapFromSvg(const char* name, const QSize& size) co
QFile file(iconPath);
if (file.open(QFile::ReadOnly | QFile::Text)) {
QByteArray content = file.readAll();
icon = pixmapFromSvg(content, size);
icon = pixmapFromSvg(content, size, colorMapping);
}
}

return icon;
}

QPixmap BitmapFactoryInst::pixmapFromSvg(const QByteArray& contents, const QSize& size) const
QPixmap BitmapFactoryInst::pixmapFromSvg(const QByteArray& originalContents, const QSizeF& size,
const std::map<unsigned long, unsigned long>& colorMapping) const
{
QString stringContents = QString::fromUtf8(originalContents);
for ( const auto &colorToColor : colorMapping ) {
ulong fromColor = colorToColor.first;
ulong toColor = colorToColor.second;
QString fromColorString = QString::fromLatin1(":#%1;").arg(fromColor, 6, 16, QChar::fromLatin1('0'));
QString toColorString = QString::fromLatin1(":#%1;").arg(toColor, 6, 16, QChar::fromLatin1('0'));
stringContents = stringContents.replace(fromColorString, toColorString);
}
QByteArray contents = stringContents.toUtf8();

#ifdef QTWEBKIT
// There is a crash when using the Webkit engine in debug mode
// for a couple of SVG files. Thus, use the qsvg plugin.
Expand Down Expand Up @@ -419,7 +431,7 @@ QPixmap BitmapFactoryInst::pixmapFromSvg(const QByteArray& contents, const QSize
return QPixmap::fromImage(image);
#endif // QT_VERSION
#else //QTWEBKIT
QImage image(size, QImage::Format_ARGB32_Premultiplied);
QImage image(size.toSize(), QImage::Format_ARGB32_Premultiplied);
image.fill(0x00000000);

QPainter p(&image);
Expand Down
10 changes: 8 additions & 2 deletions src/Gui/BitmapFactory.h
Expand Up @@ -77,13 +77,19 @@ class GuiExport BitmapFactoryInst : public Base::Factory
QPixmap pixmap(const char* name) const;
/** Retrieves a pixmap by name and size created by an
* scalable vector graphics (SVG).
*
* @param colorMapping - a dictionary of substitute colors.
* Can be used to customize icon color scheme, e.g. crosshair color
*/
QPixmap pixmapFromSvg(const char* name, const QSize& size) const;
QPixmap pixmapFromSvg(const char* name, const QSizeF& size,
const std::map<unsigned long, unsigned long>& colorMapping = std::map<unsigned long, unsigned long>()) const;
/** This method is provided for convenience and does the same
* as the method above except that it creates the pixmap from
* a byte array.
* @param colorMapping - see above.
*/
QPixmap pixmapFromSvg(const QByteArray& contents, const QSize& size) const;
QPixmap pixmapFromSvg(const QByteArray& contents, const QSizeF& size,
const std::map<unsigned long, unsigned long>& colorMapping = std::map<unsigned long, unsigned long>()) const;
/** Returns the names of all registered pixmaps.
* To get the appropriate pixmaps call pixmap() for each name.
*/
Expand Down

0 comments on commit 7a0aec1

Please sign in to comment.