From c209ac1c79da10c75739f6ed507acbd9a4acf8b1 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Fri, 3 Jan 2014 11:41:27 +0100 Subject: [PATCH] some improvements for text rendering Change-Id: Ifa52fbd0f5359c505f12d12281ec7bdfb959d8c5 --- chart2/Library_chartopengl.mk | 1 + chart2/inc/ChartModel.hxx | 1 - chart2/source/view/main/DummyXShape.cxx | 67 +++++++++++++++++++----- chart2/source/view/main/OpenGLRender.cxx | 7 +-- chart2/source/view/main/OpenGLRender.hxx | 3 +- 5 files changed, 58 insertions(+), 21 deletions(-) diff --git a/chart2/Library_chartopengl.mk b/chart2/Library_chartopengl.mk index aa4a77e7a1bb..f0e4372721ae 100644 --- a/chart2/Library_chartopengl.mk +++ b/chart2/Library_chartopengl.mk @@ -46,6 +46,7 @@ $(eval $(call gb_Library_use_libraries,chartopengl,\ svt \ svxcore \ tl \ + tk \ ucbhelper \ utl \ vcl \ diff --git a/chart2/inc/ChartModel.hxx b/chart2/inc/ChartModel.hxx index d987cdd765a6..8e965ba203af 100644 --- a/chart2/inc/ChartModel.hxx +++ b/chart2/inc/ChartModel.hxx @@ -148,7 +148,6 @@ private: /** is only valid if m_xDataProvider is set. If m_xDataProvider is set to an external data provider this reference must be set to 0 */ - bool mbInternalDataProvider; ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataProvider > m_xInternalDataProvider; ::com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatsSupplier > diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx index 4523e0c79c9d..f5817cd46699 100644 --- a/chart2/source/view/main/DummyXShape.cxx +++ b/chart2/source/view/main/DummyXShape.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -530,26 +531,64 @@ DummyText::DummyText(const OUString& rText, const tNameSequence& rNames, setProperties(rNames, rValues, maProperties); } +namespace { + +struct FontAttribSetter +{ + FontAttribSetter(Font& rFont): + mrFont(rFont) {} + + void operator()(const std::pair& rProp) + { + const OUString& rPropName = rProp.first; + if(rPropName == "CharFontName") + { + OUString aName = rProp.second.get(); + mrFont.SetName(aName); + } + else if(rPropName == "CharColor") + { + sal_Int32 nColor = rProp.second.get(); + mrFont.SetFillColor(nColor); + } + else if(rPropName == "CharHeight") + { + //float fHeight = rProp.second.get(); + mrFont.SetSize(Size(0,100)); //taken from the MCW implementation + } + else if(rPropName == "CharUnderline") + { + FontUnderline eUnderline = static_cast(rProp.second.get()); + mrFont.SetUnderline(eUnderline); + } + else if(rPropName == "CharWeight") + { + float fWeight = rProp.second.get(); + FontWeight eFontWeight = VCLUnoHelper::ConvertFontWeight(fWeight); + mrFont.SetWeight(eFontWeight); + } + else if(rPropName == "ChartWidth") + { + float fWidth = rProp.second.get(); + FontWidth eFontWidth = VCLUnoHelper::ConvertFontWidth(fWidth); + mrFont.SetWidth(eFontWidth); + } + } +private: + Font& mrFont; +}; + +} + void DummyText::render() { debugProperties(maProperties); - //get text color, the output value always be white, so we use black color to text - std::map< OUString, uno::Any >::const_iterator itr = maProperties.find("CharColor"); - sal_Int32 nColor = 0; - if(itr != maProperties.end()) - { - uno::Any co = itr->second; - nColor = co.get(); - } + Font aFont; + std::for_each(maProperties.begin(), maProperties.end(), FontAttribSetter(aFont)); - //get font, assuming that every font has a set font name - uno::Any font = maProperties.find("CharFontName")->second; - OUString aFontName = font.get(); - - sal_Int32 nRot = 0; DummyChart* pChart = getRootShape(); - pChart->m_GLRender.CreateTextTexture(maText, nColor, aFontName, maPosition, maSize, nRot); + pChart->m_GLRender.CreateTextTexture(maText, 0, aFont, maPosition, maSize, 0); pChart->m_GLRender.RenderTextShape(); } diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx index 7339ab138ac3..1b9372aff3c7 100755 --- a/chart2/source/view/main/OpenGLRender.cxx +++ b/chart2/source/view/main/OpenGLRender.cxx @@ -1334,13 +1334,10 @@ int OpenGLRender::RenderRectangleShape() return 0; } -int OpenGLRender::CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color, ::rtl::OUString font, awt::Point aPos, awt::Size aSize, long rotation) +int OpenGLRender::CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color, const Font& rFont, awt::Point aPos, awt::Size aSize, long rotation) { VirtualDevice aDevice; - Font aFont(font, Size(0, 100)); - aFont.SetWeight(WEIGHT_BOLD); - aFont.SetItalic(ITALIC_NORMAL); - aDevice.SetFont(aFont); + aDevice.SetFont(rFont); Rectangle aRect; aDevice.GetTextBoundRect(aRect, textValue); int screenWidth = (aRect.BottomRight().X() + 3) & ~3; diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx index 90408369827b..ce353b78536a 100755 --- a/chart2/source/view/main/OpenGLRender.hxx +++ b/chart2/source/view/main/OpenGLRender.hxx @@ -8,6 +8,7 @@ */ #include +#include #if defined( _WIN32 ) #include "prewin.h" @@ -176,7 +177,7 @@ public: int RenderRectangleShape(); int RectangleShapePoint(float x, float y, float directionX, float directionY); - int CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color, ::rtl::OUString font, awt::Point aPos, awt::Size aSize, long rotation); + int CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color, const Font& rFont, awt::Point aPos, awt::Size aSize, long rotation); int RenderTextShape(); private: GLint LoadShaders(const char *vertexShader,const char *fragmentShader);