Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CLI support #14

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Features:
* font view testing (both original bitmap and edited)
* kerning support
* selection of characters set from the char map
* command line support

what next?:

Expand Down
41 changes: 41 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"test": 123,
"fontconfig": {
"path": "/Users/cdingpeng/gs/DevGame/branches/X-Men_1.0.X-i18n/font",
"filename": "simsun.ttf",
"family": "SimSun",
"style": "Regular",
"faceIndex": 0,
"size": 24,
"characters": "abcsfwej",
"hinting": 1,
"renderMissing": false,
"antialiased": true,
"bold": 0,
"italic": 0,
"width": 100,
"height": 100,
"lineSpacing": 2,
"charSpacing": 2,
"DPI": 120
},
"layoutconfig": {
"onePixelOffset": true,
"potImage": true,
"sizeIncrement": 2,
"offsetLeft": 0,
"offsetTop": 0,
"offsetRight": 0,
"offsetBottom": 0,
"layouter": "Box layout"
},
"outputconfig": {
"path": "/Users/cdingpeng/gs/DevGame/branches/X-Men_1.0.X-i18n/font",
"writeImage": true,
"imageName": "simsun_regular",
"imageFormat": "png",
"writeDescription": true,
"descriptionName": "simsun_regular",
"descriptionFormat": "Sparrow"
}
}
4 changes: 4 additions & 0 deletions src/charactersframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ QString CharactersFrame::removeDuplicates(const QString& text) const {
}

QString CharactersFrame::sortChars(const QString& text) const {
if(text.size()==0)
{
return text;
}
QVector<uint> ucs4chars = text.toUcs4();
qSort(ucs4chars);
return QString::fromUcs4(&ucs4chars.front(), ucs4chars.size());
Expand Down
14 changes: 12 additions & 2 deletions src/fontbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ void FontBuilder::saveConfig(QSettings& settings,
settings.endGroup();
}

void FontBuilder::exportWithConfig(QSettings &settings) {
readConfig(settings,"fontconfig",m_font_config);
m_font_config->normalize();
readConfig(settings,"layoutconfig",m_layout_config);

//m_font_config->blockSignals(font_config_block);
m_font_config->emmitChange();

readConfig(settings,"outputconfig",m_output_config);
on_pushButtonWriteFont_clicked();
}

void FontBuilder::readConfig(QSettings& settings,
const QString& name,
QObject* object) {
Expand Down Expand Up @@ -381,6 +393,4 @@ void FontBuilder::on_action_Open_triggered()

}
}


}
1 change: 1 addition & 0 deletions src/fontbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class FontBuilder : public QMainWindow {
public:
FontBuilder(QWidget *parent = 0);
~FontBuilder();
void exportWithConfig(QSettings& settings);

protected:
void changeEvent(QEvent *e);
Expand Down
62 changes: 61 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@
#include <Qt>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QApplication>
#include <QCommandLineParser>
#else
#include <QtGui/QApplication>
#endif
#include <QCoreApplication>
#include <QFile>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QSettings>
#include <QObject>
#include <QDebug>
#include "fontbuilder.h"

int main(int argc, char *argv[])
Expand All @@ -43,7 +51,59 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationName("AndryBlack");
QCoreApplication::setOrganizationDomain("andryblack.com");
QCoreApplication::setApplicationName("FontBuilder");
QCoreApplication::setApplicationVersion("0.7");

QCommandLineParser parser;
parser.setApplicationDescription("Test");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("config", QCoreApplication::translate("main","config file"));
parser.process(a);

const QStringList args = parser.positionalArguments();

FontBuilder w;
w.show();

if (args.count() > 0)
{
QString configFile = args.at(0);
qDebug() << "Export with config file " << configFile;
QFile file(configFile);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QByteArray rawData = file.readAll();
qDebug() << "With content:\n" << rawData;
QJsonDocument document(QJsonDocument::fromJson(rawData));

if(document.isNull())
{
qDebug() << "Config prase error.";
exit(1);
}

QJsonObject config = document.object();
file.close();

QSettings settings;
for(QJsonObject::const_iterator iter=config.begin(); iter!= config.end(); iter++)
{
settings.beginGroup(iter.key());

QJsonObject node = iter.value().toObject();
for(QJsonObject::const_iterator niter= node.begin(); niter!=node.end(); niter++)
{
settings.setValue(niter.key(),niter.value().toVariant());
}

settings.endGroup();
}
w.exportWithConfig(settings);

qDebug() << "Export finished";
exit(0);
}else
{
w.show();
}

return a.exec();
}