diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-01-14 23:24:45 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-01-29 08:09:54 +0100 |
commit | 9e9a4b401a6a4ecedbb4478fd72ed648a9fd8598 (patch) | |
tree | 4c0533ec1dde49f1fbee81ac4a41fb7e84d44cd5 /chart2 | |
parent | 2a7538ffc0965353a41841bdcd347faa722f641c (diff) |
more work for text rendering
Change-Id: I4c94757de59722b7dfec9e2d0db83fc5734ba942
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/view/inc/DummyXShape.hxx | 3 | ||||
-rw-r--r-- | chart2/source/view/main/DummyXShape.cxx | 51 | ||||
-rwxr-xr-x | chart2/source/view/main/OpenGLRender.cxx | 54 | ||||
-rwxr-xr-x | chart2/source/view/main/OpenGLRender.hxx | 3 |
4 files changed, 64 insertions, 47 deletions
diff --git a/chart2/source/view/inc/DummyXShape.hxx b/chart2/source/view/inc/DummyXShape.hxx index f915650c8eb3..7112ac7fc1ae 100644 --- a/chart2/source/view/inc/DummyXShape.hxx +++ b/chart2/source/view/inc/DummyXShape.hxx @@ -374,9 +374,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 1beab62bd751..9f6316a03538 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 <cppuhelper/supportsservice.hxx> #include <editeng/unoprnms.hxx> @@ -618,14 +620,6 @@ void DummyRectangle::render() pChart->m_GLRender.RenderRectangleShape(bBorder, bFill); } -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 @@ -675,19 +669,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 7673d8a8b3e6..f407d119cf0b 100755 --- 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 @@ -1459,27 +1456,14 @@ int OpenGLRender::RenderRectangleShape(bool bBorder, bool bFill) } -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(); @@ -1488,8 +1472,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 ); @@ -1504,26 +1491,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)) @@ -1561,7 +1548,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; } @@ -1573,7 +1559,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 7010edceab55..28790457fc0c 100755 --- a/chart2/source/view/main/OpenGLRender.hxx +++ b/chart2/source/view/main/OpenGLRender.hxx @@ -28,6 +28,7 @@ #include <vcl/window.hxx> #include <vcl/syschild.hxx> #include <vcl/sysdata.hxx> +#include <vcl/bitmapex.hxx> #if defined( _WIN32 ) #include <GL/glu.h> @@ -170,7 +171,7 @@ public: int RenderRectangleShape(bool bBorder, bool bFill); 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(); |