Skip to content

Commit

Permalink
问题修复
Browse files Browse the repository at this point in the history
修复图标字体转PNG功能中,当导出图片分辨率过低时会出现黑边的问题
  • Loading branch information
188080501 committed Aug 30, 2016
1 parent 2ac2736 commit f2a9228
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
32 changes: 28 additions & 4 deletions Groups/MakeGroup/FontToPng/cpp/FontToPng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ QString Manage::saveIcon(const QString &familieName, const QString &charCodeHexS

if ( !charPackage.code ) { return "error"; }

const auto &&image = this->paintChar( familieName, charPackage, QColor( color ), QSizeF( pixelSize, pixelSize ), QSizeF( pixelSize, pixelSize ) );
const auto &&image = this->paintChar( familieName, charPackage, QColor( color ), QSizeF( pixelSize, pixelSize ), QSizeF( pixelSize, pixelSize ), true );
const auto &&saveSucceed = image.save( filePath, "PNG" );

return ( saveSucceed ) ? ( "OK" ) : ( "error" );
Expand Down Expand Up @@ -156,7 +156,7 @@ void Manage::loadFont(const QString fontName)
if ( !charPackage.code ) { continue; }

this->makeAdaptation( fontPackage.familieName, charPackage );
charPackage.preview = this->paintChar( fontPackage.familieName, charPackage, "#000000", { 60, 60 }, { 60, 60 } );
charPackage.preview = this->paintChar( fontPackage.familieName, charPackage, "#000000", { 60, 60 }, { 60, 60 }, false );

fontPackage.charPackages[ charPackage.code ] = charPackage;
}
Expand All @@ -166,7 +166,7 @@ void Manage::loadFont(const QString fontName)
mutex_.unlock();
}

QImage Manage::paintChar(const QString &familieName, const CharPackage &charPackage, const QColor &color, const QSizeF &charSize, const QSizeF &backgroundSize)
QImage Manage::paintChar(const QString &familieName, const CharPackage &charPackage, const QColor &color, const QSizeF &charSize, const QSizeF &backgroundSize, const bool &moreProcess)
{
QPainter patiner;
QImage image( backgroundSize.toSize(), QImage::Format_ARGB32 );
Expand All @@ -178,6 +178,16 @@ QImage Manage::paintChar(const QString &familieName, const CharPackage &charPack
QFont font( familieName );
font.setPixelSize( qMin( charSize.width(), charSize.height() ) * charPackage.charAdaptation.scale );

QColor backgroundColor = color;
backgroundColor.setAlpha( 1 );

if ( moreProcess )
{
patiner.setBrush( QBrush( backgroundColor ) );
patiner.setPen( QPen( QColor( "#00000000" ) ) );
patiner.drawRect( 0, 0, image.width(), image.height() );
}

patiner.setFont( font );
patiner.setPen( QPen( color ) );

Expand All @@ -190,6 +200,20 @@ QImage Manage::paintChar(const QString &familieName, const CharPackage &charPack
QString( QChar( charPackage.code ) )
);

if ( moreProcess )
{
for ( auto y = 0; y < image.height(); ++y )
{
for ( auto x = 0; x < image.width(); ++x )
{
if ( image.pixelColor( x, y ) == backgroundColor )
{
image.setPixelColor( x, y, QColor( "#00000000" ) );
}
}
}
}

return image;
}

Expand All @@ -198,7 +222,7 @@ void Manage::makeAdaptation(const QString &familieName, CharPackage &charPackage
QSizeF charSize( 400, 400 );
QSizeF backgroundSize( 500, 500 );

auto referenceImage = this->paintChar( familieName, charPackage, { "#000000" }, charSize, backgroundSize);
auto referenceImage = this->paintChar( familieName, charPackage, { "#000000" }, charSize, backgroundSize, false );

qreal xStart = -1;
qreal xEnd = backgroundSize.width();
Expand Down
2 changes: 1 addition & 1 deletion Groups/MakeGroup/FontToPng/cpp/FontToPng.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public slots:
private:
void loadFont(const QString fontName);

QImage paintChar(const QString &familieName, const CharPackage &charPackage, const QColor &color, const QSizeF &charSize, const QSizeF &backgroundSize);
QImage paintChar(const QString &familieName, const CharPackage &charPackage, const QColor &color, const QSizeF &charSize, const QSizeF &backgroundSize, const bool &moreProcess);

void makeAdaptation(const QString &familieName, CharPackage &charPackage);

Expand Down
2 changes: 1 addition & 1 deletion Groups/MakeGroup/FontToPng/qml/FontToPng.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Item {
repeat: false

onTriggered: {
materialUI.showLoading();
materialUI.showLoading( "初始化中,请稍等" );

FontToPngManage.begin();
fontToPng.refresh();
Expand Down
2 changes: 1 addition & 1 deletion Library/JQToolsLibrary/include/JQToolsLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Qt lib import
#include <QObject>

#define JQTOOLS_VERSIONSTRING "16.8.22"
#define JQTOOLS_VERSIONSTRING "16.8.30"

class AbstractTool: public QObject
{
Expand Down

0 comments on commit f2a9228

Please sign in to comment.