diff --git a/README.md b/README.md index f363f5c..da88955 100644 --- a/README.md +++ b/README.md @@ -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?: diff --git a/config.json b/config.json new file mode 100644 index 0000000..c8ae3cd --- /dev/null +++ b/config.json @@ -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" + } +} \ No newline at end of file diff --git a/src/charactersframe.cpp b/src/charactersframe.cpp index bdf62df..a769441 100644 --- a/src/charactersframe.cpp +++ b/src/charactersframe.cpp @@ -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 ucs4chars = text.toUcs4(); qSort(ucs4chars); return QString::fromUcs4(&ucs4chars.front(), ucs4chars.size()); diff --git a/src/fontbuilder.cpp b/src/fontbuilder.cpp index 7d6b2b9..1e11267 100644 --- a/src/fontbuilder.cpp +++ b/src/fontbuilder.cpp @@ -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) { @@ -381,6 +393,4 @@ void FontBuilder::on_action_Open_triggered() } } - - } diff --git a/src/fontbuilder.h b/src/fontbuilder.h index 151a73e..9179399 100644 --- a/src/fontbuilder.h +++ b/src/fontbuilder.h @@ -57,6 +57,7 @@ class FontBuilder : public QMainWindow { public: FontBuilder(QWidget *parent = 0); ~FontBuilder(); + void exportWithConfig(QSettings& settings); protected: void changeEvent(QEvent *e); diff --git a/src/main.cpp b/src/main.cpp index 36ca413..2405534 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,10 +31,18 @@ #include #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #include +#include #else #include #endif #include +#include +#include +#include +#include +#include +#include +#include #include "fontbuilder.h" int main(int argc, char *argv[]) @@ -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(); }