[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Bcalligra=5D_plugins/vectorshape/libsvm=3A_SVM=3A_Im?=
From: Inge Wallin <inge () lysator ! liu ! se>
Date: 2011-04-30 20:59:56
Message-ID: 20110430205956.36E7DA60A4 () git ! kde ! org
[Download RAW message or body]
Git commit 10b6407961fbc196a411badbcbb1cff3239aa05e by Inge Wallin.
Committed on 30/04/2011 at 22:59.
Pushed by ingwa into branch 'master'.
SVM: Implement META_TEXTCOLOR_ACTION that controls the text color.
M +2 -1 plugins/vectorshape/libsvm/SvmGraphicsContext.cpp
M +4 -2 plugins/vectorshape/libsvm/SvmGraphicsContext.h
M +28 -2 plugins/vectorshape/libsvm/SvmPainterBackend.cpp
M +37 -2 plugins/vectorshape/libsvm/SvmParser.cpp
http://commits.kde.org/calligra/10b6407961fbc196a411badbcbb1cff3239aa05e
diff --git a/plugins/vectorshape/libsvm/SvmGraphicsContext.cpp \
b/plugins/vectorshape/libsvm/SvmGraphicsContext.cpp index 973d5e4..0eb4c45 100644
--- a/plugins/vectorshape/libsvm/SvmGraphicsContext.cpp
+++ b/plugins/vectorshape/libsvm/SvmGraphicsContext.cpp
@@ -27,8 +27,9 @@ namespace Libsvm
SvmGraphicsContext::SvmGraphicsContext()
: lineColor(Qt::black)
, fillBrush(Qt::NoBrush)
+ , textColor(Qt::black)
, mapMode()
- , font("Helvetica", 300) // 200 is of course a completely bogus value
+ , font("Helvetica", 300) // 300 is of course a completely bogus value
//... more here
, changedItems(0xffffffff) // Everything changed the first time.
{
diff --git a/plugins/vectorshape/libsvm/SvmGraphicsContext.h \
b/plugins/vectorshape/libsvm/SvmGraphicsContext.h index 4a3743f..4933a00 100644
--- a/plugins/vectorshape/libsvm/SvmGraphicsContext.h
+++ b/plugins/vectorshape/libsvm/SvmGraphicsContext.h
@@ -44,8 +44,9 @@ namespace Libsvm
enum GraphicsContextMembers {
GCLineColor = 0x0001,
GCFillBrush = 0x0002,
- GCMapMode = 0x0004,
- GCFont = 0x0008
+ GCTextColor = 0x0004,
+ GCMapMode = 0x0008,
+ GCFont = 0x0010
// ...more here
};
@@ -55,6 +56,7 @@ struct SvmGraphicsContext {
QColor lineColor;
QBrush fillBrush;
+ QColor textColor;
MapMode mapMode;
QFont font;
// ... much more here;
diff --git a/plugins/vectorshape/libsvm/SvmPainterBackend.cpp \
b/plugins/vectorshape/libsvm/SvmPainterBackend.cpp index e8be050..8d2d4ea 100644
--- a/plugins/vectorshape/libsvm/SvmPainterBackend.cpp
+++ b/plugins/vectorshape/libsvm/SvmPainterBackend.cpp
@@ -35,6 +35,9 @@
#include "SvmGraphicsContext.h"
+#define DEBUG_SVMPAINT 0
+
+
/**
Namespace for StarView Metafile (SVM) classes
*/
@@ -60,14 +63,21 @@ void SvmPainterBackend::init(const SvmHeader &header)
qreal scaleX = qreal( m_outputSize.width() ) / header.width;
qreal scaleY = qreal( m_outputSize.height() ) / header.height;
- // Keep aspect ration. Use the smaller value so that we don't get
+#if DEBUG_SVMPAINT
+ kDebug(31000) << "scale before:" << scaleX << ", " << scaleY;
+#endif
+
+ // Keep aspect ratio. Use the smaller value so that we don't get
// an overflow in any direction.
+#if 0 // Set this to 1 to keep aspect ratio.
if ( scaleX > scaleY )
scaleX = scaleY;
else
scaleY = scaleX;
+#endif
#if DEBUG_SVMPAINT
- kDebug(31000) << "scale = " << scaleX << ", " << scaleY;
+ kDebug(31000) << "shape size:" << m_outputSize;
+ kDebug(31000) << "scale after:" << scaleX << ", " << scaleY;
#endif
// Transform the SVM object so that it fits in the shape as much
@@ -119,7 +129,11 @@ void SvmPainterBackend::textArray(SvmGraphicsContext &context,
const QPoint &point, const QString &string)
{
updateFromGraphicscontext(context);
+
+ m_painter->save();
+ m_painter->setPen(context.textColor);
m_painter->drawText(point, string);
+ m_painter->restore();
}
@@ -130,18 +144,30 @@ void \
SvmPainterBackend::updateFromGraphicscontext(SvmGraphicsContext &context) {
if (context.changedItems & GCLineColor) {
m_painter->setPen(context.lineColor);
+#if DEBUG_SVMPAINT
kDebug(31000) << "*** Setting line color to" << context.lineColor;
+#endif
}
if (context.changedItems & GCFillBrush) {
m_painter->setBrush(context.fillBrush);
+#if DEBUG_SVMPAINT
kDebug(31000) << "*** Setting fill brush to" << context.fillBrush;
+#endif
+ }
+ if (context.changedItems & GCTextColor) {
+ m_painter->setPen(context.textColor);
+#if DEBUG_SVMPAINT
+ kDebug(31000) << "*** Setting text color to" << context.textColor;
+#endif
}
if (context.changedItems & GCMapMode) {
// FIXME
}
if (context.changedItems & GCFont) {
m_painter->setFont(context.font);
+#if DEBUG_SVMPAINT
kDebug(31000) << "*** Setting font to" << context.font;
+#endif
}
// Reset all changes until next time.
diff --git a/plugins/vectorshape/libsvm/SvmParser.cpp \
b/plugins/vectorshape/libsvm/SvmParser.cpp index 9c941ce..cfdaf76 100644
--- a/plugins/vectorshape/libsvm/SvmParser.cpp
+++ b/plugins/vectorshape/libsvm/SvmParser.cpp
@@ -38,7 +38,7 @@
// 0 - No debug
// 1 - Print a lot of debug info
// 2 - Just print all the records instead of parsing them
-#define DEBUG_SVMPARSER 1
+#define DEBUG_SVMPARSER 0
namespace Libsvm
{
@@ -161,6 +161,18 @@ bool SvmParser::parse(const QByteArray &data)
mBackend->init(header);
+#if DEBUG_SVMPARSER
+ {
+ QPolygon polygon;
+ polygon << QPoint(0, 0);
+ polygon << QPoint(header.width, header.height);
+ mBackend->polyLine(mContext, polygon);
+ }
+#endif
+
+ // Parse all actions and call the appropriate backend callback for
+ // the graphics drawing actions. The context actions will
+ // manipulate the graphics context, which is maintained here.
for (uint action = 0; action < header.actionCount; ++action) {
quint16 actionType;
quint16 version;
@@ -209,6 +221,7 @@ bool SvmParser::parse(const QByteArray &data)
QRect rect;
parseRect(stream, rect);
+ kDebug(31000) << "Rect:" << rect;
mBackend->rect(mContext, rect);
}
break;
@@ -223,6 +236,7 @@ bool SvmParser::parse(const QByteArray &data)
QPolygon polygon;
parsePolygon(stream, polygon);
+ kDebug(31000) << "Polyline:" << polygon;
mBackend->polyLine(mContext, polygon);
// FIXME: Version 2: Lineinfo, Version 3: polyflags
@@ -235,6 +249,7 @@ bool SvmParser::parse(const QByteArray &data)
QPolygon polygon;
parsePolygon(stream, polygon);
+ kDebug(31000) << "Polygon:" << polygon;
mBackend->polygon(mContext, polygon);
// FIXME: Version 2: Lineinfo, Version 3: polyflags
@@ -267,6 +282,7 @@ bool SvmParser::parse(const QByteArray &data)
}
foreach (QPolygon polygon, polygons) {
+ kDebug(31000) << "Polygon:" << polygon;
mBackend->polygon(mContext, polygon);
}
}
@@ -275,13 +291,13 @@ bool SvmParser::parse(const QByteArray &data)
case META_TEXTARRAY_ACTION:
{
QPoint startPoint;
- quint16 strLength;
QString string;
stream >> startPoint;
parseString(stream, string);
// FIXME: Much more here
+
kDebug(31000) << "Text: " << startPoint << string;
mBackend->textArray(mContext, startPoint, string);
}
@@ -314,6 +330,7 @@ bool SvmParser::parse(const QByteArray &data)
stream >> doSet;
mContext.lineColor = doSet ? QColor::fromRgb(colorData) : Qt::NoPen;
+ kDebug(31000) << "Color:" << mContext.lineColor;
mContext.changedItems |= GCLineColor;
}
break;
@@ -328,22 +345,39 @@ bool SvmParser::parse(const QByteArray &data)
kDebug(31000) << "Fill color :" << colorData << '(' << doSet << ')';
mContext.fillBrush = doSet ? QBrush(QColor::fromRgb(colorData)) : \
Qt::NoBrush; + kDebug(31000) << "Brush:" << mContext.fillBrush;
mContext.changedItems |= GCFillBrush;
}
break;
case META_TEXTCOLOR_ACTION:
+ {
+ quint32 colorData;
+ stream >> colorData;
+
+ mContext.textColor = QColor::fromRgb(colorData);
+ kDebug(31000) << "Color:" << mContext.textColor;
+ mContext.changedItems |= GCTextColor;
+ }
case META_TEXTFILLCOLOR_ACTION:
case META_TEXTALIGN_ACTION:
break;
case META_MAPMODE_ACTION:
{
stream >> mContext.mapMode;
+ kDebug(31000) << "mapMode:" << "Origin" << mContext.mapMode.origin
+ << "scaleX"
+ << mContext.mapMode.scaleX.numerator << \
mContext.mapMode.scaleX.numerator + << \
(qreal(mContext.mapMode.scaleX.numerator) / mContext.mapMode.scaleX.numerator) + \
<< "scaleY" + << mContext.mapMode.scaleY.numerator << \
mContext.mapMode.scaleY.numerator + << \
(qreal(mContext.mapMode.scaleX.numerator) / mContext.mapMode.scaleX.numerator); \
mContext.changedItems |= GCMapMode; }
break;
case META_FONT_ACTION:
{
parseFont(stream, mContext.font);
+ kDebug(31000) << "Font:" << mContext.font;
mContext.changedItems |= GCFont;
}
break;
@@ -381,6 +415,7 @@ bool SvmParser::parse(const QByteArray &data)
#if DEBUG_SVMPARSER
kDebug(31000) << "unknown action type:" << actionType;
#endif
+ break;
}
delete [] rawData;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic