aboutsummaryrefslogtreecommitdiffstats
path: root/softwarecontext
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-08-07 15:43:23 +0200
committerLars Knoll <lars.knoll@digia.com>2014-08-08 15:57:10 +0300
commit9c09e0e86bc5056c2bc34b711024bac8e09dbf74 (patch)
treee9bef60667fd481e1ef823ff7629981da2d1a95a /softwarecontext
parentda54d17352dfc4070eb6fa105ce853e3d35490ef (diff)
Basic support for text rendering
Change-Id: I365c44b596f8866df2aff4e9f5e088bec0010539 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'softwarecontext')
-rw-r--r--softwarecontext/context.cpp7
-rw-r--r--softwarecontext/context.h1
-rw-r--r--softwarecontext/glyphnode.cpp47
-rw-r--r--softwarecontext/glyphnode.h28
-rw-r--r--softwarecontext/softwarecontext.pro6
5 files changed, 87 insertions, 2 deletions
diff --git a/softwarecontext/context.cpp b/softwarecontext/context.cpp
index 7de0aa5cde..c0c4720c81 100644
--- a/softwarecontext/context.cpp
+++ b/softwarecontext/context.cpp
@@ -44,6 +44,7 @@
#include "rectanglenode.h"
#include "imagenode.h"
#include "pixmaptexture.h"
+#include "glyphnode.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QElapsedTimer>
@@ -137,6 +138,7 @@ RenderContext::RenderContext(QSGContext *ctx)
Context::Context(QObject *parent)
: QSGContext(parent)
{
+ setDistanceFieldEnabled(false);
}
QSGRectangleNode *Context::createRectangleNode()
@@ -149,6 +151,11 @@ QSGImageNode *Context::createImageNode()
return new ImageNode();
}
+QSGGlyphNode *Context::createGlyphNode(QSGRenderContext */*rc*/, bool /*preferNativeGlyphNode*/)
+{
+ return new GlyphNode();
+}
+
void RenderContext::initialize(QOpenGLContext *context)
{
QSGRenderContext::initialize(context);
diff --git a/softwarecontext/context.h b/softwarecontext/context.h
index 75cf02d767..0eb51ba9cd 100644
--- a/softwarecontext/context.h
+++ b/softwarecontext/context.h
@@ -91,6 +91,7 @@ public:
virtual QSGRectangleNode *createRectangleNode();
virtual QSGImageNode *createImageNode();
+ virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode);
private:
};
diff --git a/softwarecontext/glyphnode.cpp b/softwarecontext/glyphnode.cpp
new file mode 100644
index 0000000000..1102980eb2
--- /dev/null
+++ b/softwarecontext/glyphnode.cpp
@@ -0,0 +1,47 @@
+#include "glyphnode.h"
+
+GlyphNode::GlyphNode()
+ : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0)
+{
+ setMaterial((QSGMaterial*)1);
+ setGeometry(&m_geometry);
+}
+
+
+void GlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &glyphs)
+{
+ m_position = position;
+ m_glyphRun = glyphs;
+}
+
+void GlyphNode::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+void GlyphNode::setStyle(QQuickText::TextStyle style)
+{
+}
+
+void GlyphNode::setStyleColor(const QColor &color)
+{
+}
+
+QPointF GlyphNode::baseLine() const
+{
+ return QPointF();
+}
+
+void GlyphNode::setPreferredAntialiasingMode(QSGGlyphNode::AntialiasingMode)
+{
+}
+
+void GlyphNode::update()
+{
+}
+
+void GlyphNode::paint(QPainter *painter)
+{
+ painter->setPen(m_color);
+ painter->drawGlyphRun(m_position - QPointF(0, m_glyphRun.rawFont().ascent()), m_glyphRun);
+}
diff --git a/softwarecontext/glyphnode.h b/softwarecontext/glyphnode.h
new file mode 100644
index 0000000000..1724ef8394
--- /dev/null
+++ b/softwarecontext/glyphnode.h
@@ -0,0 +1,28 @@
+#ifndef GLYPHNODE_H
+#define GLYPHNODE_H
+
+#include <private/qsgadaptationlayer_p.h>
+
+class GlyphNode : public QSGGlyphNode
+{
+public:
+ GlyphNode();
+
+ virtual void setGlyphs(const QPointF &position, const QGlyphRun &glyphs);
+ virtual void setColor(const QColor &color);
+ virtual void setStyle(QQuickText::TextStyle style);
+ virtual void setStyleColor(const QColor &color);
+ virtual QPointF baseLine() const;
+ virtual void setPreferredAntialiasingMode(AntialiasingMode);
+ virtual void update();
+
+ virtual void paint(QPainter *painter);
+
+private:
+ QPointF m_position;
+ QGlyphRun m_glyphRun;
+ QColor m_color;
+ QSGGeometry m_geometry;
+};
+
+#endif // GLYPHNODE_H
diff --git a/softwarecontext/softwarecontext.pro b/softwarecontext/softwarecontext.pro
index 0c6486fc8b..31bb122eaf 100644
--- a/softwarecontext/softwarecontext.pro
+++ b/softwarecontext/softwarecontext.pro
@@ -11,7 +11,8 @@ SOURCES += \
renderloop.cpp \
rectanglenode.cpp \
imagenode.cpp \
- pixmaptexture.cpp
+ pixmaptexture.cpp \
+ glyphnode.cpp
HEADERS += \
context.h \
@@ -19,7 +20,8 @@ HEADERS += \
renderloop.h \
rectanglenode.h \
imagenode.h \
- pixmaptexture.h
+ pixmaptexture.h \
+ glyphnode.h
OTHER_FILES += softwarecontext.json