[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. 46385198db7b5ab402404f5dc442d4a3d4199eeb

Eugeniy Meshcheryakov eugen at debian.org
Wed Apr 2 13:55:44 UTC 2008


The following commit has been merged in the master branch:
commit 46385198db7b5ab402404f5dc442d4a3d4199eeb
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Wed Apr 2 15:55:14 2008 +0200

    try to convert instructions from FontForge to Fondue format

diff --git a/filters/sfdimportfilter.cxx b/filters/sfdimportfilter.cxx
index 99f6382..f609e57 100644
--- a/filters/sfdimportfilter.cxx
+++ b/filters/sfdimportfilter.cxx
@@ -35,6 +35,7 @@ private:
 	Glyph *readGlyph(const QString &name, QTextStream *sfd);
 	bool readGlyphContent(Glyph *g, QTextStream *sfd);
 	bool processReferences(FontDocument *doc);
+	QStringList convertInstructions(const QStringList &orig);
 
 	SFDImportFilter *m_filter;
 	QHash<int, QString> toNameMap;
@@ -70,6 +71,11 @@ void SFDImportFilter::addError(const QString &text)
 	m_errors << QString("Error: %1").arg(text);
 }
 
+void SFDImportFilter::addWarning(const QString &text)
+{
+	m_errors << QString("Warning: %1").arg(text);
+}
+
 /***************************** Private part ********************************/
 
 SFDImportFilterPriv::SFDImportFilterPriv(SFDImportFilter *filter) : m_filter(filter)
@@ -92,6 +98,68 @@ FontDocument *SFDImportFilterPriv::importFile(QFile *file)
 	return 0;
 }
 
+QStringList SFDImportFilterPriv::convertInstructions(const QStringList &orig)
+{
+	// we expect normal FontForge format here:
+	// 1. one instruction/value per line
+	// 2. all values are stored using n?push[bw]
+	// 3. all numbers are decimal
+	static const QRegExp pushRx("(push[bw])_([12345678])", Qt::CaseInsensitive);
+	static const QRegExp npushRx("npush[bw]", Qt::CaseInsensitive);
+	unsigned int numbersToRead = 0;
+	bool readSkipNum = false;
+
+	QStringList res;
+
+	foreach (const QString &line, orig) {
+		if (readSkipNum) {
+			// previous instruction was npush[bw]
+			// read number of arguments
+			numbersToRead = line.toUInt();
+			if (!numbersToRead) {
+				m_filter->addWarning(QString("Instruction conversion failed: bad NPUSH"));
+				return QStringList();
+			}
+			readSkipNum = false;
+			continue;
+		}
+
+		if (numbersToRead) {
+			// we are in a push instruction, copy numbers
+			// check if skipped value is a decimal number
+			bool ok;
+			line.toInt(&ok);
+			if (!ok) {
+				m_filter->addWarning(QString("Instruction conversion failed: bad number (%1)")
+						.arg(line));
+				return QStringList();
+			}
+			res << line;
+			numbersToRead--;
+			continue;
+		}
+
+		QRegExp rx = pushRx;
+		if (rx.exactMatch(line.simplified())) {
+			res << rx.cap(1); // TODO do not eat space here
+			numbersToRead = rx.cap(2).toUInt();
+			Q_ASSERT(numbersToRead);
+			continue;
+		}
+
+		rx = npushRx;
+		if (rx.exactMatch(line.simplified())) {
+			readSkipNum = true;
+			res << line;
+			continue;
+		}
+
+		// copy other instructions as-is
+		res << line;
+	}
+	return res;
+}
+
 QString SFDImportFilterPriv::readTTTable(QTextStream *sfd)
 {
 	Q_ASSERT(sfd);
@@ -109,8 +177,13 @@ QString SFDImportFilterPriv::readTTTable(QTextStream *sfd)
 		code << line;
 	}
 
-	// XXX FIXME TODO convert instructions
-	return code.join("\n");
+	// try to convert instructions first
+	QStringList converted = convertInstructions(code);
+	if (converted.isEmpty()) {// conversion failed? or maybe empty instructions?
+		qDebug() << "conversion failed";
+		return code.join("\n");
+	}
+	return converted.join("\n");
 }
 
 bool SFDImportFilterPriv::readCvt(FontDocument *doc, QTextStream *sfd)
diff --git a/filters/sfdimportfilter.h b/filters/sfdimportfilter.h
index f6dd0eb..9a6856e 100644
--- a/filters/sfdimportfilter.h
+++ b/filters/sfdimportfilter.h
@@ -24,6 +24,7 @@ public:
 	FontDocument *importFile(QFile *file);
 	QStringList errors() const;
 	void addError(const QString &text);
+	void addWarning(const QString &text);
 private:
 	QStringList m_errors;
 };

-- 
Fondue Font Editor



More information about the fondue-commits mailing list