[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. 36ffff05aaea3f454bc2ed11626d82599b9440dd

Eugeniy Meshcheryakov eugen at debian.org
Fri Aug 31 13:03:16 UTC 2007


The branch, master has been updated
       via  36ffff05aaea3f454bc2ed11626d82599b9440dd (commit)
      from  f602a45688c78ea6a94078a3ffdb41d0e7e20c59 (commit)


- Shortlog ------------------------------------------------------------
36ffff0 move glyph metrics calculation to class Glyph

Summary of changes:
 nongui/glyph.cxx     |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 nongui/glyph.h       |    2 +
 nongui/nongui.rules  |    3 +-
 nongui/ttfwriter.cxx |   44 +++++---------------------------------
 4 files changed, 67 insertions(+), 39 deletions(-)
-----------------------------------------------------------------------
Details of changes:

commit 36ffff05aaea3f454bc2ed11626d82599b9440dd
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Fri Aug 31 15:03:05 2007 +0200

    move glyph metrics calculation to class Glyph

diff --git a/nongui/glyph.cxx b/nongui/glyph.cxx
new file mode 100644
index 0000000..dfc4772
--- /dev/null
+++ b/nongui/glyph.cxx
@@ -0,0 +1,57 @@
+/* Copyright (C) 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 2 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+#include "glyph.h"
+#include "contour.h"
+
+bool Glyph::computeMetrics(qreal &xMin, qreal &xMax, qreal &yMin, qreal &yMax) const
+{
+	// TODO do something with open contours
+	if (content.isEmpty()) {
+		xMin = xMax = yMin = yMax = 0;
+		return false;
+	}
+	Contour c = content.at(0).value<Contour>();
+	if (c.isEmpty())
+		return false; // empty contours are not allowed
+	xMin = xMax = c.at(0).x();
+	yMin = yMax = c.at(0).y();
+	
+	int contNo = 0;
+	int pointNo = 1;
+
+	for (;;) {
+		while (pointNo < c.size()) {
+			const GlyphPoint &pt = c.at(pointNo);
+			qreal x = pt.x();
+			qreal y = pt.y();
+			if (xMin > x) xMin = x;
+			if (xMax < x) xMax = x;
+			if (yMin > y) yMin = y;
+			if (yMax < y) yMax = y;
+			pointNo++;
+		}
+		contNo++;
+		pointNo = 0;
+		if (contNo < content.size())
+			c = content[contNo].value<Contour>();
+		else
+			break;
+		if (c.isEmpty())
+			return false;
+	}
+	return true;
+}
diff --git a/nongui/glyph.h b/nongui/glyph.h
index 4b4ff01..5fd9109 100644
--- a/nongui/glyph.h
+++ b/nongui/glyph.h
@@ -110,6 +110,8 @@ public:
 
 	void setUnicode(int u) {m_unicode = u;}
 	int unicode() const {return m_unicode;}
+
+	bool computeMetrics(qreal &xMin, qreal &xMax, qreal &yMin, qreal &yMax) const;
 private:
 	qreal horiz_adv_x;
 	bool horiz_adv_x_set;
diff --git a/nongui/nongui.rules b/nongui/nongui.rules
index 0d48576..2146829 100644
--- a/nongui/nongui.rules
+++ b/nongui/nongui.rules
@@ -7,7 +7,8 @@ libfonduenongui_a_SOURCES =		\
 	nongui/fontdocument.cxx		\
 	nongui/ttfencode.cxx		\
 	nongui/cvtmodel.cxx		\
-	nongui/ttfwriter.cxx
+	nongui/ttfwriter.cxx		\
+	nongui/glyph.cxx
 
 nodist_libfonduenongui_a_SOURCES = 	\
 	nongui/decodertable.tbl.cxx	\
diff --git a/nongui/ttfwriter.cxx b/nongui/ttfwriter.cxx
index 7eba457..d0a645b 100644
--- a/nongui/ttfwriter.cxx
+++ b/nongui/ttfwriter.cxx
@@ -283,53 +283,21 @@ bool TTFWriter::writeCompositeGlyph(QIODevice *dev, const Glyph *g)
 	return true;
 }
 
-static bool computeMinMax(const QList<QVariant> &content,
-		qint16 &xMin, qint16 &xMax, qint16 &yMin, qint16 &yMax)
-{
-	if (!content.size()) {
-		xMin = xMax = yMin = yMax = 0;
-		return true;
-	}
-	Contour c = content.at(0).value<Contour>();
-	if (!c.size())
-		return false; // empty contours are not allowed
-	xMin = xMax = (qint16)c.at(0).x();
-	yMin = yMax = (qint16)c.at(0).y();
-
-	foreach (QVariant v, content) {
-		Q_ASSERT(v.canConvert<Contour>());
-		c = v.value<Contour>();
-		if (c.isOpen())
-			return false; // not allowed
-		if (!c.size())
-			return false;
-		foreach (const GlyphPoint &pt, c) {
-			qint16 x = (qint16)pt.x();
-			qint16 y = (qint16)pt.y();
-			if (xMin > x) xMin = x;
-			if (xMax < x) xMax = x;
-			if (yMin > y) yMin = y;
-			if (yMax < y) yMax = y;
-		}
-	}
-	return true;
-}
-
 #define TTFLAG_ON_CURVE		1
 
 bool TTFWriter::writeSimpleGlyph(QIODevice *dev, const Glyph *g)
 {
 	qint16 nContours = g->content.size();
-	qint16 xMin, xMax, yMin, yMax;
-	if (!computeMinMax(g->content, xMin, xMax, yMin, yMax)) {
+	qreal xMin, xMax, yMin, yMax;
+	if (!g->computeMetrics(xMin, xMax, yMin, yMax)) {
 		qDebug() << "computeMinMax failed:" << g->objectName();
 		return false;
 	}
 	bool ret = writeBigEndian(dev, nContours);
-	ret = ret && writeBigEndian(dev, xMin);
-	ret = ret && writeBigEndian(dev, yMin);
-	ret = ret && writeBigEndian(dev, xMax);
-	ret = ret && writeBigEndian(dev, yMax);
+	ret = ret && writeBigEndian(dev, (qint16)xMin);
+	ret = ret && writeBigEndian(dev, (qint16)yMin);
+	ret = ret && writeBigEndian(dev, (qint16)xMax);
+	ret = ret && writeBigEndian(dev, (qint16)yMax);
 	if (!ret)
 		return false;
 	// write endpoints of contours

-- 
Fondue Font Editor



More information about the fondue-commits mailing list