[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. 702a809a19b6d188dddc1124f2f776e700d2969f

Eugeniy Meshcheryakov eugen at debian.org
Sat Aug 18 17:40:10 UTC 2007


The branch, master has been updated
       via  702a809a19b6d188dddc1124f2f776e700d2969f (commit)
       via  9f298dddc36dfce39b1cbb3750f6b7b3f59bb538 (commit)
       via  2fbd0bbec2e348e7d849a9bca16297961f2bf172 (commit)
      from  b4b0fcfdc1ccc77c9ee183fbbb62c08262304f62 (commit)


- Log -----------------------------------------------------------------
commit 702a809a19b6d188dddc1124f2f776e700d2969f
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Sat Aug 18 19:40:03 2007 +0200

    add "Check Instructions" button to instructions editor dialog

commit 9f298dddc36dfce39b1cbb3750f6b7b3f59bb538
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Sat Aug 18 19:20:39 2007 +0200

    Make it possible to check correctness of TT instructions
    One should call encode without arguments (or 0) to do so.

commit 2fbd0bbec2e348e7d849a9bca16297961f2bf172
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Sat Aug 18 19:12:26 2007 +0200

    do not set viewportUpdateMode anymore, that was Qt problem

-----------------------------------------------------------------------

Summary of changes:
 gui/glyphcell.cxx    |    1 -
 gui/ttieditor.cxx    |   31 ++++++++++++++++++++++------
 gui/ttieditor.h      |    3 ++
 nongui/ttfencode.cxx |   53 ++++++++++++++++++++++++++++++++++---------------
 nongui/ttfencode.h   |   11 +++++++++-
 5 files changed, 74 insertions(+), 25 deletions(-)

diff --git a/gui/glyphcell.cxx b/gui/glyphcell.cxx
index fb7d469..ced1879 100644
--- a/gui/glyphcell.cxx
+++ b/gui/glyphcell.cxx
@@ -37,7 +37,6 @@ GlyphCell::GlyphCell(GlyphsModel *model, const QModelIndex &index) : QGraphicsVi
 	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
 	setRenderHint(QPainter::Antialiasing);
 	setDragMode(RubberBandDrag);
-	setViewportUpdateMode(FullViewportUpdate);
 
 	QGraphicsScene *scene = new QGraphicsScene(this);
 	scene->setSceneRect(-5000, -5000, 10000, 10000);
diff --git a/gui/ttieditor.cxx b/gui/ttieditor.cxx
index 89d6553..fcab5be 100644
--- a/gui/ttieditor.cxx
+++ b/gui/ttieditor.cxx
@@ -18,10 +18,13 @@
 #include <QTextEdit>
 #include <QFont>
 #include "ttihighlighter.h"
-#include <QVBoxLayout>
+#include <QHBoxLayout>
 #include <QDialogButtonBox>
 #include <QDataWidgetMapper>
 #include <QModelIndex>
+#include <QPushButton>
+#include "ttfencode.h"
+#include <QMessageBox>
 
 TTIEditor::TTIEditor(QAbstractItemModel *model, const QModelIndex &item, QWidget *parent) : QDialog(parent)
 {
@@ -32,7 +35,7 @@ TTIEditor::TTIEditor(QAbstractItemModel *model, const QModelIndex &item, QWidget
 
 	setAttribute(Qt::WA_DeleteOnClose);
 
-	QTextEdit *textEditor = new QTextEdit;
+	textEditor = new QTextEdit;
 	QFont font;
 	font.setFamily("monospace");
 	font.setStyleHint(QFont::Courier);
@@ -42,18 +45,23 @@ TTIEditor::TTIEditor(QAbstractItemModel *model, const QModelIndex &item, QWidget
 
 	buttons = new QDialogButtonBox(QDialogButtonBox::Ok
 			| QDialogButtonBox::Cancel
-			| QDialogButtonBox::Apply);
+			| QDialogButtonBox::Apply,
+			Qt::Vertical);
+	QPushButton *checkInstructionsButton = new QPushButton("Check Instructions");
+	buttons->addButton(checkInstructionsButton, QDialogButtonBox::ActionRole);
 
-	QVBoxLayout *vbox = new QVBoxLayout;
-	vbox->addWidget(textEditor);
-	vbox->addWidget(buttons);
+	QHBoxLayout *hbox = new QHBoxLayout;
+	hbox->addWidget(textEditor);
+	hbox->addWidget(buttons);
 
-	setLayout(vbox);
+	setLayout(hbox);
 
 	connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
 	connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
 	connect(buttons, SIGNAL(clicked(QAbstractButton *)),
 			this, SLOT(buttonClicked(QAbstractButton *)));
+	connect(checkInstructionsButton, SIGNAL(clicked()),
+			this, SLOT(checkInstructions()));
 
 	mapper = new QDataWidgetMapper;
 	mapper->setModel(model);
@@ -74,3 +82,12 @@ void TTIEditor::buttonClicked(QAbstractButton *button)
 	if (buttons->buttonRole(button) == QDialogButtonBox::ApplyRole)
 		mapper->submit();
 }
+
+void TTIEditor::checkInstructions()
+{
+	TTInstructionsEncoder encoder(textEditor->toPlainText());
+	if (encoder.encode())
+		QMessageBox::information(this, "Check Instructions", "TrueType instructions are valid.");
+	else
+		QMessageBox::warning(this, "Check Instructions", "TrueType instructions are invalid!");
+}
diff --git a/gui/ttieditor.h b/gui/ttieditor.h
index 6a8b7c7..e465d58 100644
--- a/gui/ttieditor.h
+++ b/gui/ttieditor.h
@@ -23,6 +23,7 @@ class QModelIndex;
 class QAbstractButton;
 class QDataWidgetMapper;
 class QDialogButtonBox;
+class QTextEdit;
 
 class TTIEditor : public QDialog
 {
@@ -33,9 +34,11 @@ public:
 public slots:
 	void accept();
 	void buttonClicked(QAbstractButton *button);
+	void checkInstructions();
 private:
 	QDataWidgetMapper *mapper;
 	QDialogButtonBox *buttons;
+	QTextEdit *textEditor;
 };
 
 #endif
diff --git a/nongui/ttfencode.cxx b/nongui/ttfencode.cxx
index 2f84abf..9395554 100644
--- a/nongui/ttfencode.cxx
+++ b/nongui/ttfencode.cxx
@@ -22,15 +22,14 @@
 #include <QtEndian>
 
 TTInstructionsEncoder::TTInstructionsEncoder(const QString &input) :
-	m_status(NoError), m_input(input), inputOffset(0)
+	m_status(NoError), m_input(input), inputOffset(0), m_dataWritten(false)
 {
 
 }
 
+// TODO check for unexpected end of data
 bool TTInstructionsEncoder::encode(QIODevice *output)
 {
-	Q_ASSERT(output);
-
 	m_output = output;
 	for (QString token = nextToken(); !token.isEmpty(); token = nextToken()) {
 		bool found = false;;
@@ -115,7 +114,7 @@ bool TTInstructionsEncoder::encodeNoParams(quint8 base)
 	else
 		putToken(token);
 
-	return m_output->putChar(base);
+	return putChar(base);
 }
 
 // TODO add support for syntax like MD[1]
@@ -142,7 +141,7 @@ bool TTInstructionsEncoder::encodeOneParam(quint8 base, const char *iftrue, cons
 		m_status = SyntaxError;
 		return false;
 	}
-	return m_output->putChar(base + diff);
+	return putChar(base + diff);
 }
 
 bool TTInstructionsEncoder::encodeIUP(quint8 base)
@@ -212,18 +211,16 @@ bool TTInstructionsEncoder::encodeNPUSHX(quint8 base)
 	}
 	if (values.size() > 0xff) {
 		m_status = SyntaxError;
-		return false; // TODO reason?
+		return false;
 	}
 
-	bool ret = m_output->putChar(base) && m_output->putChar((quint8)values.size());
+	bool ret = putChar(base) && putChar((quint8)values.size());
 	if (ret) {
 		foreach (int i, values) {
 			T val = safeToBigEndian((T)i);
-			ret = (m_output->write((const char *)&val, sizeof(val)) == sizeof(val));
-			if (!ret) {
-				m_status = IOError;
+			ret = write((const char *)&val, sizeof(val));
+			if (!ret)
 				break;
-			}
 		}
 	}
 	return ret;
@@ -278,7 +275,7 @@ bool TTInstructionsEncoder::encodeNROUND(quint8 base)
 		m_status = SyntaxError;
 		return false;
 	}
-	return m_output->putChar(base + (quint8)color);
+	return putChar(base + (quint8)color);
 }
 
 template <typename T>
@@ -316,13 +313,12 @@ bool TTInstructionsEncoder::encodePUSHX(quint8 base)
 		return false;
 	}
 
-	bool ret = m_output->putChar(base + (quint8)values.size() - 1);
+	bool ret = putChar(base + (quint8)values.size() - 1);
 	if (ret) {
 		foreach (int i, values) {
 			T val = safeToBigEndian((T)i);
-			ret = (m_output->write((const char *)&val, sizeof(val)) == sizeof(val));
+			ret = write((const char *)&val, sizeof(val));
 			if (!ret) {
-				m_status = IOError;
 				break;
 			}
 		}
@@ -394,5 +390,30 @@ bool TTInstructionsEncoder::encodeMDRP(quint8 base)
 		return false;
 	}
 
-	return m_output->putChar(base + off);
+	return putChar(base + off);
+}
+
+bool TTInstructionsEncoder::putChar(char c)
+{
+	m_dataWritten = true;
+	if (m_output) {
+		if (!m_output->putChar(c)) {
+			m_status = IOError;
+			return false;
+		}
+	}
+	return true;
+}
+
+bool TTInstructionsEncoder::write(const char *data, qint64 maxSize)
+{
+	Q_ASSERT(data);
+	m_dataWritten = true;
+	if (m_output) {
+		if (m_output->write(data, maxSize) != maxSize) {
+			m_status = IOError;
+			return false;
+		}
+	}
+	return true;
 }
diff --git a/nongui/ttfencode.h b/nongui/ttfencode.h
index a70d457..5314fdf 100644
--- a/nongui/ttfencode.h
+++ b/nongui/ttfencode.h
@@ -24,8 +24,11 @@ class TTInstructionsEncoder {
 public:
 	enum Status {NoError, SyntaxError, IOError};
 	TTInstructionsEncoder(const QString &input);
-	bool encode(QIODevice *output);
+	bool encode(QIODevice *output = 0);
 	Status status() const {return m_status;}
+	/** returns true if input contained any instructions
+	 */
+	bool hadInstructions() const {return m_dataWritten;}
 private:
 	Status m_status;
 	QString m_input;
@@ -64,6 +67,12 @@ private:
 		EncoderFunc (TTInstructionsEncoder::*f);
 	};
 	static const EncoderTableEntry encoderTable[];
+
+	// these functions also set m_status
+	bool putChar(char c);
+	bool write(const char *data, qint64 maxSize);
+
+	bool m_dataWritten;
 };
 
 #endif

-- 
Fondue Font Editor



More information about the fondue-commits mailing list