[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. 08b3bcdfd92d36098f89673d35f5eb6ff5f0559a
Eugeniy Meshcheryakov
eugen at debian.org
Thu May 15 13:28:08 UTC 2008
The following commit has been merged in the master branch:
commit 56937733b33dd6ccd547b13efbb77cfaca2534c5
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Thu May 15 14:28:37 2008 +0200
make GlyphItemBase a subclass of QGraphicsPathItem
Also inverse y coordinate in glyph paths earlier and not require
using scale(1, -1)
diff --git a/gui/glyphgraphics.cxx b/gui/glyphgraphics.cxx
index 648c7ac..253616f 100644
--- a/gui/glyphgraphics.cxx
+++ b/gui/glyphgraphics.cxx
@@ -98,29 +98,34 @@ QPainterPath GlyphGraphics::contourToPath(const GlyphContour *contour)
QPainterPath path;
for (int i = 0; i < contour->points().size(); i++) {
- const GlyphPoint pt = contour->points().at(i);
+ GlyphPoint gpt = contour->points().at(i);
+ QPointF pt(gpt.x(), -gpt.y());
// TODO move away from the loop
if (i == 0) {
- if (pt.on()) {
+ if (gpt.on()) {
path.moveTo(pt);
continue;
}
else {
- if (contour->points().last().on())
- path.moveTo(contour->points().last());
+ GlyphPoint last_gpt = contour->points().last();
+ QPointF last_pt(last_gpt.x(), -last_gpt.y());
+
+ if (last_gpt.on())
+ path.moveTo(last_pt);
else
- path.moveTo((pt + contour->points().last()) / 2);
+ path.moveTo((pt + last_pt) / 2);
}
}
- if (pt.on())
+ if (gpt.on())
path.lineTo(pt);
else {
- const GlyphPoint next = (i < contour->points().size() - 1) ?
+ GlyphPoint next_gpt = (i < contour->points().size() - 1) ?
contour->points().at(i + 1) : contour->points().at(0);
+ QPointF next(next_gpt.x(), -next_gpt.y());
- if (next.on()) {
+ if (next_gpt.on()) {
path.quadTo(pt, next);
i++;
}
diff --git a/gui/glyphiconengine.cxx b/gui/glyphiconengine.cxx
index 492f884..781af5e 100644
--- a/gui/glyphiconengine.cxx
+++ b/gui/glyphiconengine.cxx
@@ -40,7 +40,7 @@ void GlyphIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mo
painter->setRenderHint(QPainter::Antialiasing);
painter->translate(rect.center());
- painter->scale(ratio, -ratio);
+ painter->scale(ratio, ratio);
painter->translate(-paths.rect.center());
painter->setBrush(Qt::black);
diff --git a/gui/glyphitem.cxx b/gui/glyphitem.cxx
index 4d05d01..9641ca6 100644
--- a/gui/glyphitem.cxx
+++ b/gui/glyphitem.cxx
@@ -18,103 +18,31 @@
#include "glyph.h"
#include <QPainter>
-GlyphItemBase::GlyphItemBase(Glyph *glyph, QGraphicsItem *parent) :
- QObject(), QGraphicsItem(parent), m_glyph(glyph)
+GlyphItemBase::GlyphItemBase(Glyph *glyph, bool includeOpen, QGraphicsItem *parent) :
+ QObject(), QGraphicsPathItem(parent), m_glyph(glyph), m_includeOpen(includeOpen)
{
Q_ASSERT(m_glyph);
- calculateBoundingRect();
connect(m_glyph, SIGNAL(outlineChanged()), this, SLOT(updateGeometry()));
+ updateGeometry();
}
void GlyphItemBase::updateGeometry()
{
- prepareGeometryChange();
- calculateBoundingRect();
- update();
-}
-
-void GlyphItemBase::calculateBoundingRect()
-{
- QPainterPath path;
- bool hadContours = false;
-
- foreach (const GlyphContentBase *i, m_glyph->content()) {
- if (i->type() == GlyphContentBase::Contour) {
- const GlyphContour *c = qobject_cast<const GlyphContour *>(i);
- Q_ASSERT(c);
- path.addPath(GlyphGraphics::contourToPath(c));
- hadContours = true;
- }
- }
- if (hadContours) {
- QRectF rect = path.boundingRect();
- qreal top = rect.bottom(), left = rect.left();
- QSizeF size = rect.size();
- m_boundingRect = QRectF(QPointF(left, -top), size);
- }
- else
- m_boundingRect = QRectF();
-}
-
-QRectF GlyphItemBase::boundingRect() const
-{
- return m_boundingRect;
-}
-
-void GlyphItemBase::paintOutline(QPainter *painter, bool paintOpen)
-{
QPainterPath path;
foreach (const GlyphContentBase *i, m_glyph->content()) {
if (i->type() == GlyphContentBase::Contour) {
const GlyphContour *c = qobject_cast<const GlyphContour *>(i);
Q_ASSERT(c);
- if (!c->isOpen())
+ if (!c->isOpen() || m_includeOpen)
path.addPath(GlyphGraphics::contourToPath(c));
}
}
-
- painter->scale(1, -1);
- painter->setPen(Qt::black);
- painter->setBrush(Qt::NoBrush);
- painter->drawPath(path);
-
- if (paintOpen) {
- // draw open contours
- foreach (const GlyphContentBase *i, m_glyph->content()) {
- if (i->type() == GlyphContentBase::Contour) {
- const GlyphContour *c = qobject_cast<const GlyphContour *>(i);
- Q_ASSERT(c);
- if (c->isOpen())
- painter->drawPath(GlyphGraphics::contourToPath(c));
- }
- }
- }
-}
-
-void GlyphItemBase::paintFill(QPainter *painter)
-{
- QPainterPath path;
-
- foreach (const GlyphContentBase *i, m_glyph->content()) {
- if (i->type() == GlyphContentBase::Contour) {
- const GlyphContour *c = qobject_cast<const GlyphContour *>(i);
- Q_ASSERT(c);
- if (!c->isOpen())
- path.addPath(GlyphGraphics::contourToPath(c));
- }
- }
-
- painter->scale(1, -1);
- painter->setPen(Qt::NoBrush);
- painter->setBrush(Qt::gray); // filling should be moved to other place
- painter->drawPath(path);
+ setPath(path);
}
-void GlyphItemOutline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+GlyphItemOutline::GlyphItemOutline(Glyph *glyph, QGraphicsItem *parent) :
+ GlyphItemBase(glyph, true, parent)
{
- Q_UNUSED(option);
- Q_UNUSED(widget);
-
- paintOutline(painter);
+ setPen(QPen(Qt::black));
}
diff --git a/gui/glyphitem.h b/gui/glyphitem.h
index 098d109..6a55b4f 100644
--- a/gui/glyphitem.h
+++ b/gui/glyphitem.h
@@ -15,33 +15,27 @@
*/
#ifndef GLYPHITEM_H
#define GLYPHITEM_H
-#include <QGraphicsItem>
-#include <QList>
-#include "glyphcontentbase.h"
+#include <QGraphicsPathItem>
+#include <QObject>
class Glyph;
-class GlyphItemBase : public QObject, public QGraphicsItem {
+class GlyphItemBase : public QObject, public QGraphicsPathItem {
Q_OBJECT
public:
- GlyphItemBase(Glyph *glyph, QGraphicsItem *parent = 0);
- QRectF boundingRect() const;
+ GlyphItemBase(Glyph *glyph, bool includeOpen, QGraphicsItem *parent = 0);
public slots:
void updateGeometry();
protected:
- void paintOutline(QPainter *painter, bool paintOpen = true);
- void paintFill(QPainter *painter);
- void calculateBoundingRect();
-
Glyph *m_glyph;
QRectF m_boundingRect;
+ bool m_includeOpen;
};
class GlyphItemOutline : public GlyphItemBase {
Q_OBJECT
public:
- GlyphItemOutline(Glyph *glyph, QGraphicsItem *parent = 0) : GlyphItemBase(glyph, parent) {}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ GlyphItemOutline(Glyph *glyph, QGraphicsItem *parent = 0);
};
#endif
diff --git a/gui/glyphsmodel.cxx b/gui/glyphsmodel.cxx
index fb0ce7c..7acfe85 100644
--- a/gui/glyphsmodel.cxx
+++ b/gui/glyphsmodel.cxx
@@ -195,7 +195,7 @@ void GlyphsModel::drawContours(PathList *paths, const Glyph *glyph, int order, Q
if (doc) {
const Glyph *otherGlyph = doc->getGlyph(ref->glyphName());
if (otherGlyph) {
- QPoint newOffset((int)ref->offset().x(), (int)ref->offset().y());
+ QPoint newOffset((int)ref->offset().x(), -(int)ref->offset().y());
newOffset += off;
drawContours(paths, otherGlyph, order + 1, newOffset);
}
@@ -217,10 +217,10 @@ void GlyphsModel::drawGlyph(PathList *paths, const Glyph *glyph)
}
FontDocument *doc = glyph->document();
- if (-rect.top() < doc->descent())
- rect.setTop(-doc->descent());
- if (rect.bottom() < doc->ascent())
- rect.setBottom(doc->ascent());
+ if (-rect.top() < doc->ascent())
+ rect.setTop(-doc->ascent());
+ if (rect.bottom() < doc->descent())
+ rect.setBottom(doc->descent());
paths->rect = rect;
}
diff --git a/gui/glyphsmodeldelegate.cxx b/gui/glyphsmodeldelegate.cxx
index ca28e01..2395991 100644
--- a/gui/glyphsmodeldelegate.cxx
+++ b/gui/glyphsmodeldelegate.cxx
@@ -73,7 +73,7 @@ void GlyphsModelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
painter->setPen(Qt::NoPen);
painter->translate(glyphRect.center());
- painter->scale(ratio, -ratio);
+ painter->scale(ratio, ratio);
painter->translate(-paths.rect.center());
foreach(const GlyphsModel::PathWithOffset &p, paths) {
--
Fondue Font Editor
More information about the fondue-commits
mailing list