[Libreoffice-commits] core.git: Branch 'private/moggi/fix-text-rendering' - chart2/source

Markus Mohrhard markus.mohrhard at collabora.co.uk
Sat Jan 18 19:32:51 PST 2014


 chart2/source/view/inc/DummyXShape.hxx   |    3 +
 chart2/source/view/main/DummyXShape.cxx  |   51 ++++++++++++++++++++++-------
 chart2/source/view/main/OpenGLRender.cxx |   54 +++++++++++--------------------
 chart2/source/view/main/OpenGLRender.hxx |    3 +
 4 files changed, 64 insertions(+), 47 deletions(-)

New commits:
commit f815fc35d7e21cdbee2ba83a1475ac799248921c
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Tue Jan 14 23:24:45 2014 +0100

    more work for text rendering
    
    Change-Id: I4c94757de59722b7dfec9e2d0db83fc5734ba942

diff --git a/chart2/source/view/inc/DummyXShape.hxx b/chart2/source/view/inc/DummyXShape.hxx
index 42eec30..121b5e0 100644
--- a/chart2/source/view/inc/DummyXShape.hxx
+++ b/chart2/source/view/inc/DummyXShape.hxx
@@ -382,9 +382,12 @@ public:
 
     virtual void render() SAL_OVERRIDE;
 
+    virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
+
 private:
     OUString maText;
     uno::Any maTrans;
+    BitmapEx maBitmap;
 };
 
 class DummyFormattedText : public DummyXShape
diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx
index 596c0c4..240bf78 100644
--- a/chart2/source/view/main/DummyXShape.cxx
+++ b/chart2/source/view/main/DummyXShape.cxx
@@ -21,6 +21,8 @@
 #include <rtl/ustring.hxx>
 
 #include <vcl/window.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/svapp.hxx>
 #include <tools/gen.hxx>
 #include <editeng/unoprnms.hxx>
 #include <toolkit/helper/vclunohelper.hxx>
@@ -596,14 +598,6 @@ void DummyRectangle::render()
     */
 }
 
-DummyText::DummyText(const OUString& rText, const tNameSequence& rNames,
-        const tAnySequence& rValues, const uno::Any& rTrans ):
-    maText(rText),
-    maTrans(rTrans)
-{
-    setProperties(rNames, rValues, maProperties);
-}
-
 namespace {
 
 struct FontAttribSetter
@@ -653,19 +647,52 @@ private:
 
 }
 
-void DummyText::render()
+DummyText::DummyText(const OUString& rText, const tNameSequence& rNames,
+        const tAnySequence& rValues, const uno::Any& rTrans ):
+    maText(rText),
+    maTrans(rTrans)
 {
-    SAL_WARN("chart2.opengl", "render DummyText");
-    debugProperties(maProperties);
+    setProperties(rNames, rValues, maProperties);
 
     Font aFont;
     std::for_each(maProperties.begin(), maProperties.end(), FontAttribSetter(aFont));
 
+    VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0);
+    aDevice.Erase();
+    Rectangle aRect;
+    aDevice.SetFont(aFont);
+    aDevice.GetTextBoundRect(aRect, rText);
+    int screenWidth = (aRect.BottomRight().X() + 3) & ~3;
+    int screenHeight = (aRect.BottomRight().Y() + 3) & ~3;
+    aDevice.SetOutputSizePixel(Size(screenWidth * 3, screenHeight));
+    aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
+    aDevice.DrawText(Point(0, 0), rText);
+    int bmpWidth = (aRect.Right() - aRect.Left() + 3) & ~3;
+    int bmpHeight = (aRect.Bottom() - aRect.Top() + 3) & ~3;
+    maBitmap = BitmapEx(aDevice.GetBitmapEx(aRect.TopLeft(), Size(bmpWidth, bmpHeight)));
+
+    setSize(awt::Size(bmpWidth, bmpHeight));
+}
+
+void DummyText::render()
+{
+    SAL_WARN("chart2.opengl", "render DummyText");
+    debugProperties(maProperties);
+
     DummyChart* pChart = getRootShape();
-    pChart->m_GLRender.CreateTextTexture(maText, 0, aFont, maPosition, maSize, 0);
+    pChart->m_GLRender.CreateTextTexture(maBitmap, maPosition, maSize, 0);
     pChart->m_GLRender.RenderTextShape();
 }
 
+void DummyText::setPropertyValue( const OUString& rName, const uno::Any& rValue)
+    throw(beans::UnknownPropertyException, beans::PropertyVetoException,
+            lang::IllegalArgumentException, lang::WrappedTargetException,
+            uno::RuntimeException)
+{
+    SAL_WARN("chart2.opengl", "property value set after image has been created");
+    DummyXShape::setPropertyValue(rName, rValue);
+}
+
 DummyFormattedText::DummyFormattedText(uno::Sequence< uno::Reference<
         chart2::XFormattedString > >& rFormattedString,
         uno::Reference< beans::XPropertySet > , double fRotation):
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index bd83199..42fdaa2 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -10,7 +10,6 @@
 #include <GL/glew.h>
 #include <vector>
 #include "OpenGLRender.hxx"
-#include <vcl/bitmapex.hxx>
 #include <vcl/bmpacc.hxx>
 #include <vcl/graph.hxx>
 #include <com/sun/star/awt/XBitmap.hpp>
@@ -36,8 +35,6 @@
 #include <editeng/unoprnms.hxx>
 #include <vcl/virdev.hxx>
 #include <vcl/dibtools.hxx>
-#include <vcl/bmpacc.hxx>
-#include <vcl/svapp.hxx>
 
 #include <boost/scoped_array.hpp>
 
@@ -45,7 +42,7 @@ using namespace com::sun::star;
 
 using namespace std;
 
-#define DEBUG_PNG 0
+#define DEBUG_PNG 1
 #define BMP_HEADER_LEN 54
 
 #if DEBUG_PNG
@@ -1417,27 +1414,14 @@ int OpenGLRender::RenderRectangleShape()
 }
 
 
-int OpenGLRender::CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color, const Font& rFont, awt::Point aPos, awt::Size aSize, long rotation)
+int OpenGLRender::CreateTextTexture(const BitmapEx& rBitmapEx, awt::Point aPos, awt::Size aSize, long rotation)
 {
-    VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0);
-    aDevice.Erase();
-    Rectangle aRect;
-    aDevice.SetFont(rFont);
-    aDevice.GetTextBoundRect(aRect, textValue);
-    int screenWidth = (aRect.BottomRight().X() + 3) & ~3;
-    int screenHeight = (aRect.BottomRight().Y() + 3) & ~3;
-    aDevice.SetOutputSizePixel(Size(screenWidth * 3, screenHeight));
-    aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
-    aDevice.DrawText(Point(0, 0), textValue);
-    int bmpWidth = (aRect.Right() - aRect.Left() + 3) & ~3;
-    int bmpHeight = (aRect.Bottom() - aRect.Top() + 3) & ~3;
-    BitmapEx aBitmapEx(aDevice.GetBitmapEx(aRect.TopLeft(), Size(bmpWidth, bmpHeight)));
 
 #if DEBUG_PNG // debug PNG writing
     static int nIdx = 0;
     OUString aName = OUString( "file:///home/moggi/Documents/work/text" ) + OUString::number( nIdx++ ) + ".png";
     try {
-        vcl::PNGWriter aWriter( aBitmapEx );
+        vcl::PNGWriter aWriter( rBitmapEx );
         SvFileStream sOutput( aName, STREAM_WRITE );
         aWriter.Write( sOutput );
         sOutput.Close();
@@ -1446,8 +1430,11 @@ int OpenGLRender::CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color,
     }
 #endif
 
-    Bitmap aBitmap (aBitmapEx.GetBitmap());
-    AlphaMask aAlpha (aBitmapEx.GetAlpha());
+    long bmpWidth = rBitmapEx.GetSizePixel().Width();
+    long bmpHeight = rBitmapEx.GetSizePixel().Height();
+
+    Bitmap aBitmap (rBitmapEx.GetBitmap());
+    AlphaMask aAlpha (rBitmapEx.GetAlpha());
     boost::scoped_array<sal_uInt8> bitmapBuf(new sal_uInt8[4* bmpWidth * bmpHeight ]);
     Bitmap::ScopedReadAccess pReadAccces( aBitmap );
     AlphaMask::ScopedReadAccess pAlphaReadAccess( aAlpha );
@@ -1462,26 +1449,26 @@ int OpenGLRender::CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color,
             bitmapBuf[i++] = aCol.GetRed();
             bitmapBuf[i++] = aCol.GetGreen();
             bitmapBuf[i++] = aCol.GetBlue();
-            bitmapBuf[i++] = *pAScan++;
+            bitmapBuf[i++] = 255 - *pAScan++;
         }
     }
 
     TextInfo aTextInfo;
-    aTextInfo.x = (float)(aPos.X + aSize.Width / 2) / OPENGL_SCALE_VALUE;
-    aTextInfo.y = (float)(aPos.Y + aSize.Height / 2) / OPENGL_SCALE_VALUE;
+    aTextInfo.x = (float)(aPos.X + aSize.Width / 2);
+    aTextInfo.y = (float)(aPos.Y + aSize.Height / 2);
     aTextInfo.z = m_fZStep;
     aTextInfo.rotation = -(double)rotation * GL_PI / 18000.0f;
-    aTextInfo.vertex[0] = (float)(-aSize.Width / 2) / OPENGL_SCALE_VALUE;
-    aTextInfo.vertex[1] = (float)(-aSize.Height / 2) / OPENGL_SCALE_VALUE;
+    aTextInfo.vertex[0] = (float)(aPos.X);
+    aTextInfo.vertex[1] = (float)(aPos.Y);
 
-    aTextInfo.vertex[2] = (float)(aSize.Width / 2) / OPENGL_SCALE_VALUE;
-    aTextInfo.vertex[3] = (float)(-aSize.Height / 2) / OPENGL_SCALE_VALUE;
+    aTextInfo.vertex[2] = (float)(aPos.X + aSize.Width);
+    aTextInfo.vertex[3] = (float)(aPos.Y);
 
-    aTextInfo.vertex[4] = (float)(aSize.Width / 2) / OPENGL_SCALE_VALUE;
-    aTextInfo.vertex[5] = (float)(aSize.Height / 2) / OPENGL_SCALE_VALUE;
+    aTextInfo.vertex[4] = (float)(aPos.X + aSize.Width);
+    aTextInfo.vertex[5] = (float)(aPos.Y + aSize.Height);
 
-    aTextInfo.vertex[6] = (float)(-aSize.Width / 2) / OPENGL_SCALE_VALUE;
-    aTextInfo.vertex[7] = (float)(aSize.Height / 2) / OPENGL_SCALE_VALUE;
+    aTextInfo.vertex[6] = (float)(aPos.X);
+    aTextInfo.vertex[7] = (float)(aPos.Y + aSize.Height);
 
     //if has ratotion, we must re caculate the central pos
     if (!rtl::math::approxEqual(0, rotation))
@@ -1519,7 +1506,6 @@ int OpenGLRender::CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color,
     glBindTexture(GL_TEXTURE_2D, 0);
     CHECK_GL_ERROR();
     m_TextInfoList.push_back(aTextInfo);
-    aDevice.Erase();
     return 0;
 }
 
@@ -1531,7 +1517,7 @@ int OpenGLRender::RenderTextShape()
     for (size_t i = 0; i < listNum; i++)
     {
         TextInfo &textInfo = m_TextInfoList.front();
-        PosVecf3 trans = {textInfo.x, textInfo.y, textInfo.z};
+        PosVecf3 trans = {0, 0, 0};
         PosVecf3 angle = {0.0f, 0.0f, float(textInfo.rotation)};
         PosVecf3 scale = {1.0, 1.0, 1.0f};
         MoveModelf(trans, angle, scale);
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index 84d083e..8fcdb11 100644
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -22,6 +22,7 @@
 #include <vcl/window.hxx>
 #include <vcl/syschild.hxx>
 #include <vcl/sysdata.hxx>
+#include <vcl/bitmapex.hxx>
 
 #if defined( _WIN32 )
     #include <GL/glu.h>
@@ -171,7 +172,7 @@ public:
     int RenderRectangleShape();
     int RectangleShapePoint(float x, float y, float directionX, float directionY);
 
-    int CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color, const Font& rFont,
+    int CreateTextTexture(const BitmapEx& rBitmapEx,
             com::sun::star::awt::Point aPos, com::sun::star::awt::Size aSize, long rotation);
     int RenderTextShape();
 


More information about the Libreoffice-commits mailing list