From 9c09e0e86bc5056c2bc34b711024bac8e09dbf74 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 7 Aug 2014 15:43:23 +0200 Subject: Basic support for text rendering Change-Id: I365c44b596f8866df2aff4e9f5e088bec0010539 Reviewed-by: Lars Knoll --- softwarecontext/context.cpp | 7 ++++++ softwarecontext/context.h | 1 + softwarecontext/glyphnode.cpp | 47 +++++++++++++++++++++++++++++++++++++ softwarecontext/glyphnode.h | 28 ++++++++++++++++++++++ softwarecontext/softwarecontext.pro | 6 +++-- 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 softwarecontext/glyphnode.cpp create mode 100644 softwarecontext/glyphnode.h 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 #include @@ -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 + +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 -- cgit v1.2.3