[rkward-cvs] SF.net SVN: rkward-code:[4627] branches/development_branches/ rkward_graphpics_device/rkward/rbackend/rkwarddevice

tfry at users.sf.net tfry at users.sf.net
Sun Mar 24 19:29:42 UTC 2013


Revision: 4627
          http://sourceforge.net/p/rkward/code/4627
Author:   tfry
Date:     2013-03-24 19:29:41 +0000 (Sun, 24 Mar 2013)
Log Message:
-----------
Slowly making progress.

Modified Paths:
--------------
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp	2013-03-23 19:27:03 UTC (rev 4626)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp	2013-03-24 19:29:41 UTC (rev 4627)
@@ -75,7 +75,7 @@
 }
 
 void RKGraphicsDevice::circle (double x, double y, double r, const QPen& pen, const QBrush& brush) {
-	QGraphicsEllipseItem* circle = new QGraphicsEllipseItem (x - r, y - r, r, r, clip);
+	QGraphicsEllipseItem* circle = new QGraphicsEllipseItem (x - r, y - r, r+r, r+r, clip);
 	circle->setPen (pen);
 	circle->setBrush (brush);
 	circle->setZValue (item_z += .1);
@@ -104,3 +104,23 @@
 	text->setZValue (item_z += .1);
 	text->setTextInteractionFlags (Qt::TextSelectableByMouse);
 }
+
+void RKGraphicsDevice::metricInfo (const QChar& c, const QFont& font, double* ascent, double* descent, double* width) {
+	QFontMetricsF fm (font);
+	*ascent = fm.ascent ();	// TODO: or should we return the metrics of this particular char (similar to strWidth)
+	*descent = fm.descent ();
+	*width = fm.width (c);
+}
+
+void RKGraphicsDevice::polygon (const QPolygonF& pol, const QPen& pen, const QBrush& brush) {
+	QGraphicsPolygonItem *poli = new QGraphicsPolygonItem (pol, clip);
+	poli->setPen (pen);
+	poli->setBrush (brush);
+	poli->setZValue (item_z += .1);
+}
+
+void RKGraphicsDevice::polyline (const QPolygonF& pol, const QPen& pen) {
+	QGraphicsPolygonItem *poli = new QGraphicsPolygonItem (pol, clip);
+	poli->setPen (pen);
+	poli->setZValue (item_z += .1);
+}

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h	2013-03-23 19:27:03 UTC (rev 4626)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h	2013-03-24 19:29:41 UTC (rev 4627)
@@ -39,7 +39,10 @@
 	void line (double x1, double y1, double x2, double y2, const QPen& pen);
 	double strWidth (const QString &text, const QFont& font);
 	void text (double x, double y, const QString &text, double rot, double hadj, const QColor& col, const QFont& font);
+	void metricInfo (const QChar& c, const QFont& font, double *ascent, double *descent, double *width);
 	void setClip (const QRectF& new_clip);
+	void polygon (const QPolygonF& pol, const QPen& pen, const QBrush &brush);
+	void polyline (const QPolygonF& pol, const QPen& pen);
 private:
 	QGraphicsScene* scene;
 	QGraphicsView* view;

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp	2013-03-23 19:27:03 UTC (rev 4626)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp	2013-03-24 19:29:41 UTC (rev 4627)
@@ -95,7 +95,10 @@
 
 static QPen readPen (QDataStream &instream) {
 	QPen ret = readSimplePen (instream);
-#warning: Read further attribs!
+	quint8 lends, ljoin;
+	double lmitre;
+	instream >> lends >> ljoin >> lmitre;
+#warning: Apply attribs!
 	return ret;
 }
 
@@ -115,6 +118,20 @@
 	return ret;
 }
 
+static QVector<QPointF> readPoints (QDataStream &instream, bool close) {
+	quint32 n;
+	instream >> n;
+	QVector<QPointF> points;
+	points.reserve (n + (close ? 1 : 0));
+	for (int i = 0; i < n; ++i) {
+		double x, y;
+		instream >> x >> y;
+		points.append (QPointF (x, y));
+	}
+	if (n && close) points.append (points[0]);
+	return points;
+}
+
 void RKGraphicsDeviceFrontendTransmitter::newData () {
 	RK_TRACE (GRAPHICS_DEVICE);
 
@@ -150,7 +167,13 @@
 			device->line (x1, y1, x2, y2, readPen (streamer.instream));
 			continue;
 		} else if (opcode == RKDPolygon) {
+			QPolygonF pol (readPoints (streamer.instream, true));
+			device->polygon (pol, readPen (streamer.instream), readBrush (streamer.instream));
+			continue;
 		} else if (opcode == RKDPolyline) {
+			QPolygonF pol (readPoints (streamer.instream, false));
+			device->polyline (pol, readPen (streamer.instream));
+			continue;
 		} else if (opcode == RKDRect) {
 		} else if (opcode == RKDStrWidthUTF8) {
 			QString out;
@@ -160,6 +183,13 @@
 			streamer.writeOutBuffer ();
 			continue;
 		} else if (opcode == RKDMetricInfo) {
+			QChar c;
+			double ascent, descent, width;
+			streamer.instream >> c;
+			device->metricInfo (c, readFont (streamer.instream), &ascent, &descent, &width);
+			streamer.outstream << ascent << descent << width;
+			streamer.writeOutBuffer ();
+			continue;
 		} else if (opcode == RKDTextUTF8) {
 			double x, y, rot, hadj;
 			QString out;
@@ -173,7 +203,6 @@
 		} else if (opcode == RKDDeActivate) {
 		} else if (opcode == RKDClip) {
 		} else if (opcode == RKDMode) {
-		} else if (opcode == RKDClip) {
 		} else if (opcode == RKDLocator) {
 		} else if (opcode == RKDNewPageConfirm) {
 		}

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2013-03-23 19:27:03 UTC (rev 4626)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2013-03-24 19:29:41 UTC (rev 4627)
@@ -142,10 +142,20 @@
 	RKD_OUT_STREAM << WRITE_FILL ();
 }
 
+static QString RToQString (const char *str, bool is_symbol) {
+	if (is_symbol) {
+		int n = strlen (str);
+		char outbuf[n*4 + 4];
+		Rf_AdobeSymbol2utf8 (outbuf, str, n*4);
+		return QString::fromUtf8 (outbuf);
+	}
+	return QString::fromUtf8 (str);
+}
+
 static void RKD_TextUTF8 (double x, double y, const char *str, double rot, double hadj, R_GE_gcontext *gc, pDevDesc dev) {
 	RKGraphicsDataStreamWriteGuard guard;
 	RKD_OUT_STREAM << WRITE_HEADER (RKDTextUTF8, dev);
-	RKD_OUT_STREAM << x << y << QString::fromUtf8 (str) << rot << hadj;
+	RKD_OUT_STREAM << x << y << RToQString (str, gc->fontface == 5) << rot << hadj;
 	RKD_OUT_STREAM << WRITE_COL ();
 	RKD_OUT_STREAM << WRITE_FONT (dev);
 }
@@ -154,7 +164,7 @@
 	{
 		RKGraphicsDataStreamWriteGuard guard;
 		RKD_OUT_STREAM << WRITE_HEADER (RKDStrWidthUTF8, dev);
-		RKD_OUT_STREAM << QString::fromUtf8 (str);
+		RKD_OUT_STREAM << RToQString (str, gc->fontface == 5);
 		RKD_OUT_STREAM << WRITE_FONT (dev);
 	}
 	double ret;
@@ -175,14 +185,25 @@
 	{
 		RKGraphicsDataStreamWriteGuard wguard;
 		RKD_OUT_STREAM << WRITE_HEADER (RKDMetricInfo, dev);
-		RKD_OUT_STREAM << QChar (c);
+		QChar unichar;
+		if (c < 0) { unichar = QChar (-c); }
+		else if ((gc->fontface == 5) || (!mbcslocale)) {
+			char inbuf[2];
+			inbuf[0] = c;
+			inbuf[1] = 0;
+			QString dummy = RToQString (inbuf, gc->fontface == 5);
+			if (!dummy.isEmpty ()) unichar = dummy.at (0);
+		} else {
+#warning TODO: handle non-unicode locale?
+			unichar = QChar (c);
+		}
+		RKD_OUT_STREAM << unichar;
 		RKD_OUT_STREAM << WRITE_FONT (dev);
 	}
 	{
 		RKGraphicsDataStreamReadGuard rguard;
-		RKD_IN_STREAM >> *ascent;
-		RKD_IN_STREAM >> *descent;
-		RKD_IN_STREAM >> *width;
+		RKD_IN_STREAM >> *ascent >> *descent >> *width;
+//qDebug ("for char %d: a %f, d %f, w %f", c, *ascent, *descent, *width);
 	}
 }
 





More information about the rkward-tracker mailing list