[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. ed73113b32615b1e35ad3f59ed7868f1686cd564
Eugeniy Meshcheryakov
eugen at debian.org
Wed Apr 2 15:46:10 UTC 2008
The following commit has been merged in the master branch:
commit ed73113b32615b1e35ad3f59ed7868f1686cd564
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Wed Apr 2 17:44:42 2008 +0200
create TTFExportFilter class and use it
diff --git a/filters/filters.rules b/filters/filters.rules
index 37c894d..f5cef86 100644
--- a/filters/filters.rules
+++ b/filters/filters.rules
@@ -1,13 +1,15 @@
noinst_LIBRARIES += libfonduefilters.a
libfonduefilters_a_SOURCES = \
- filters/sfdimportfilter.cxx
+ filters/sfdimportfilter.cxx \
+ filters/ttfexportfilter.cxx
libfonduefilters_a_CPPFLAGS = $(QtCore_CFLAGS)
noinst_HEADERS += \
filters/sfdimportfilter.h \
filters/importfilterbase.h \
- filters/exportfilterbase.h
+ filters/exportfilterbase.h \
+ filters/ttfexportfilter.h
## vim:ft=automake
diff --git a/nongui/ttfwriter.cxx b/filters/ttfexportfilter.cxx
similarity index 95%
rename from nongui/ttfwriter.cxx
rename to filters/ttfexportfilter.cxx
index 7ecac83..ebd7cfc 100644
--- a/nongui/ttfwriter.cxx
+++ b/filters/ttfexportfilter.cxx
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ttfwriter.h"
+#include "ttfexportfilter.h"
#include <QDebug>
#include <QIODevice>
#include <QtEndian>
@@ -23,6 +23,67 @@
#include "ttfencode.h"
#include "glyphcontour.h"
#include <QStringList>
+#include <QFile>
+
+class TTFWriter {
+public:
+ TTFWriter(const FontDocument *doc);
+ bool write(QIODevice *dev);
+private:
+ void createGlyphList();
+
+ bool writeCvt();
+ bool writeFpgm();
+ bool writePrep();
+ bool writeGlyphs();
+ bool writeMaxp();
+ bool writeHead();
+ bool writeCmap();
+ bool writeName();
+ bool writePost();
+ bool writeHmtx();
+ bool writeHhea();
+
+ bool writeCompositeGlyph(QIODevice *dev, const Glyph *g);
+ bool writeSimpleGlyph(QIODevice *dev, const Glyph *g);
+
+ void appendTable(quint32 tag, QByteArray &table);
+
+ const FontDocument *m_doc;
+
+ QMap<quint32, QByteArray> tables;
+ QHash<quint32, quint32> tableLengths;
+
+ QList<const Glyph *> sortedGlyphs;
+ int encodedGlyphsCount;
+
+ // some global maximums
+ qint16 maxAscent;
+ qint16 maxDescent;
+ quint16 maxAdvanceWidth;
+ qint16 minLSB;
+ qint16 minRSB;
+ qint16 maxExtent;
+};
+
+QString TTFExportFilter::menuName() const
+{
+ return "TrueType File...";
+}
+
+QString TTFExportFilter::fileMask() const
+{
+ return "TrueType files (*.ttf)";
+}
+
+bool TTFExportFilter::exportFile(FontDocument *doc, QFile *file)
+{
+ Q_ASSERT(doc);
+ Q_ASSERT(file);
+
+ TTFWriter writer(doc);
+ return writer.write(file);
+}
static inline quint32 makeTag(unsigned char a, unsigned char b,
unsigned char c, unsigned char d)
diff --git a/filters/sfdimportfilter.h b/filters/ttfexportfilter.h
similarity index 72%
copy from filters/sfdimportfilter.h
copy to filters/ttfexportfilter.h
index 9a6856e..69028fe 100644
--- a/filters/sfdimportfilter.h
+++ b/filters/ttfexportfilter.h
@@ -13,20 +13,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef SFDIMPORTFILTER_H
-#define SFDIMPORTFILTER_H
-#include "importfilterbase.h"
+#ifndef TTFEXPORTFILTER_H
+#define TTFEXPORTFILTER_H
+#include "exportfilterbase.h"
-class SFDImportFilter : public ImportFilterBase {
+class TTFExportFilter : public ExportFilterBase {
public:
QString menuName() const;
QString fileMask() const;
- FontDocument *importFile(QFile *file);
- QStringList errors() const;
- void addError(const QString &text);
- void addWarning(const QString &text);
-private:
- QStringList m_errors;
+ bool exportFile(FontDocument *doc, QFile *file);
};
#endif
diff --git a/gui/mainwindow.cxx b/gui/mainwindow.cxx
index ff25bfb..f4a42b7 100644
--- a/gui/mainwindow.cxx
+++ b/gui/mainwindow.cxx
@@ -33,12 +33,12 @@
#include "unicodeproxymodel.h"
#include "cvtmodel.h"
#include "cvteditor.h"
-#include "ttfwriter.h"
#include "maxpeditor.h"
#include "documentinfomodel.h"
#include "documentinfoeditor.h"
#include "scriptconsole.h"
#include "sfdimportfilter.h"
+#include "ttfexportfilter.h"
#include <QDebug>
#include "config.h"
@@ -74,6 +74,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
MainWindow::~MainWindow()
{
qDeleteAll(m_importFilters);
+ qDeleteAll(m_exportFilters);
}
void MainWindow::createActions()
@@ -98,8 +99,15 @@ void MainWindow::createActions()
connect(act, SIGNAL(triggered()), this, SLOT(importFile()));
importActions << act;
}
- exportTTFAction = new QAction("Export As TTF...", this);
- connect(exportTTFAction, SIGNAL(triggered()), this, SLOT(exportTTF()));
+
+ foreach (ExportFilterBase *filter, m_exportFilters) {
+ QAction *act = new QAction(filter->menuName(), this);
+ act->setData(QVariant::fromValue<ExportFilterBase *>(filter));
+ connect(act, SIGNAL(triggered()), this, SLOT(exportFile()));
+ act->setEnabled(false);
+ connect(this, SIGNAL(documentAvailable(bool)), act, SLOT(setEnabled(bool)));
+ exportActions << act;
+ }
editDocumentInfoAction = new QAction("Document Info...", this);
connect(editDocumentInfoAction, SIGNAL(triggered()), this, SLOT(editDocumentInfo()));
@@ -131,7 +139,6 @@ void MainWindow::createActions()
saveAction->setEnabled(false);
saveAsAction->setEnabled(false);
- exportTTFAction->setEnabled(false);
editDocumentInfoAction->setEnabled(false);
editPrepAction->setEnabled(false);
editFpgmAction->setEnabled(false);
@@ -140,7 +147,6 @@ void MainWindow::createActions()
connect(this, SIGNAL(documentAvailable(bool)), saveAction, SLOT(setEnabled(bool)));
connect(this, SIGNAL(documentAvailable(bool)), saveAsAction, SLOT(setEnabled(bool)));
- connect(this, SIGNAL(documentAvailable(bool)), exportTTFAction, SLOT(setEnabled(bool)));
connect(this, SIGNAL(documentAvailable(bool)), editDocumentInfoAction, SLOT(setEnabled(bool)));
connect(this, SIGNAL(documentAvailable(bool)), editPrepAction, SLOT(setEnabled(bool)));
connect(this, SIGNAL(documentAvailable(bool)), editFpgmAction, SLOT(setEnabled(bool)));
@@ -159,7 +165,10 @@ void MainWindow::createMenus()
foreach (QAction *act, importActions)
importMenu->addAction(act);
- fileMenu->addAction(exportTTFAction);
+ QMenu *exportMenu = fileMenu->addMenu("Export");
+ foreach (QAction *act, exportActions)
+ exportMenu->addAction(act);
+
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
@@ -376,11 +385,21 @@ bool MainWindow::saveAs()
return saveFile(fileName);
}
-bool MainWindow::exportTTF()
+bool MainWindow::exportFile()
{
- QString fileName = QFileDialog::getSaveFileName(this, 0, 0, "TrueType Font File (*.ttf)");
+ QAction *act = qobject_cast<QAction *>(sender());
+ if (!act) {
+ qDebug() << "exportFile() sender is not QAction";
+ return false;
+ }
+
+ ExportFilterBase *filter = qvariant_cast<ExportFilterBase *>(act->data());
+ Q_ASSERT(filter);
+
+ QString fileName = QFileDialog::getSaveFileName(this, 0, 0, filter->fileMask());
if (fileName.isEmpty())
return false;
+
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
QMessageBox::warning(this, "Fondue", QString("Cannot write file %1:\n%2")
@@ -390,12 +409,16 @@ bool MainWindow::exportTTF()
}
Q_ASSERT(m_doc);
- TTFWriter writer(m_doc);
- if (!writer.write(&file)) {
- QMessageBox::warning(this, "Fondue", QString("Cannot export to TrueType."));
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+ bool ret = filter->exportFile(m_doc, &file);
+ QApplication::restoreOverrideCursor();
+ file.close();
+
+ if (!ret) {
+ QMessageBox::warning(this, "Fondue", QString("Cannot export document:\n%1")
+ .arg(filter->errors().join("\n")));
return false;
}
- file.close();
return true;
}
@@ -577,4 +600,5 @@ void MainWindow::setupFilters()
{
// TODO move list setup somewhere
m_importFilters << new SFDImportFilter;
+ m_exportFilters << new TTFExportFilter;
}
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index 394ee66..1675c9e 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -30,6 +30,7 @@ class DocumentInfoModel;
class CVTModel;
class ScriptConsole;
class ImportFilterBase;
+class ExportFilterBase;
class MainWindow: public QMainWindow {
Q_OBJECT
@@ -48,7 +49,7 @@ public slots:
bool save();
bool saveAs();
bool importFile();
- bool exportTTF();
+ bool exportFile();
void editDocumentInfo();
@@ -101,7 +102,7 @@ private:
QAction *saveAction;
QAction *saveAsAction;
QList<QAction *> importActions;
- QAction *exportTTFAction;
+ QList<QAction *> exportActions;
QAction *editDocumentInfoAction;
@@ -124,6 +125,7 @@ private:
ScriptConsole *m_scriptConsole;
QList<ImportFilterBase *> m_importFilters;
+ QList<ExportFilterBase *> m_exportFilters;
};
#endif
diff --git a/nongui/nongui.rules b/nongui/nongui.rules
index 925f560..6301605 100644
--- a/nongui/nongui.rules
+++ b/nongui/nongui.rules
@@ -7,7 +7,6 @@ libfonduenongui_a_SOURCES = \
nongui/fontdocument.cxx \
nongui/ttfencode.cxx \
nongui/cvtmodel.cxx \
- nongui/ttfwriter.cxx \
nongui/glyph.cxx \
nongui/unicodenameslist.cxx \
nongui/documentinfomodel.cxx \
@@ -50,7 +49,6 @@ noinst_HEADERS += \
nongui/cvtentry.h \
nongui/ttfencode.h \
nongui/cvtmodel.h \
- nongui/ttfwriter.h \
nongui/unicodenameslist.h \
nongui/documentinfomodel.h \
nongui/glyphcontentbase.h \
diff --git a/nongui/ttfwriter.h b/nongui/ttfwriter.h
deleted file mode 100644
index afc2929..0000000
--- a/nongui/ttfwriter.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Copyright © 2007 Євгеній Мещеряков <eugen at debian.org>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef TTFWRITER_H
-#define TTFWRITER_H
-#include <QMap>
-#include <QByteArray>
-#include <QHash>
-
-class FontDocument;
-class QIODevice;
-class Glyph;
-
-class TTFWriter {
-public:
- TTFWriter(const FontDocument *doc);
- bool write(QIODevice *dev);
-private:
- void createGlyphList();
-
- bool writeCvt();
- bool writeFpgm();
- bool writePrep();
- bool writeGlyphs();
- bool writeMaxp();
- bool writeHead();
- bool writeCmap();
- bool writeName();
- bool writePost();
- bool writeHmtx();
- bool writeHhea();
-
- bool writeCompositeGlyph(QIODevice *dev, const Glyph *g);
- bool writeSimpleGlyph(QIODevice *dev, const Glyph *g);
-
- void appendTable(quint32 tag, QByteArray &table);
-
- const FontDocument *m_doc;
-
- QMap<quint32, QByteArray> tables;
- QHash<quint32, quint32> tableLengths;
-
- QList<const Glyph *> sortedGlyphs;
- int encodedGlyphsCount;
-
- // some global maximums
- qint16 maxAscent;
- qint16 maxDescent;
- quint16 maxAdvanceWidth;
- qint16 minLSB;
- qint16 minRSB;
- qint16 maxExtent;
-};
-
-#endif
--
Fondue Font Editor
More information about the fondue-commits
mailing list