some improvements for text rendering

Change-Id: Ifa52fbd0f5359c505f12d12281ec7bdfb959d8c5
This commit is contained in:
Markus Mohrhard 2014-01-03 11:41:27 +01:00
parent d5fb04b109
commit c209ac1c79
5 changed files with 58 additions and 21 deletions

View File

@ -46,6 +46,7 @@ $(eval $(call gb_Library_use_libraries,chartopengl,\
svt \
svxcore \
tl \
tk \
ucbhelper \
utl \
vcl \

View File

@ -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 >

View File

@ -24,6 +24,7 @@
#include <tools/gen.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <editeng/unoprnms.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <algorithm>
@ -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<OUString, uno::Any>& rProp)
{
const OUString& rPropName = rProp.first;
if(rPropName == "CharFontName")
{
OUString aName = rProp.second.get<OUString>();
mrFont.SetName(aName);
}
else if(rPropName == "CharColor")
{
sal_Int32 nColor = rProp.second.get<sal_Int32>();
mrFont.SetFillColor(nColor);
}
else if(rPropName == "CharHeight")
{
//float fHeight = rProp.second.get<float>();
mrFont.SetSize(Size(0,100)); //taken from the MCW implementation
}
else if(rPropName == "CharUnderline")
{
FontUnderline eUnderline = static_cast<FontUnderline>(rProp.second.get<sal_Int16>());
mrFont.SetUnderline(eUnderline);
}
else if(rPropName == "CharWeight")
{
float fWeight = rProp.second.get<float>();
FontWeight eFontWeight = VCLUnoHelper::ConvertFontWeight(fWeight);
mrFont.SetWeight(eFontWeight);
}
else if(rPropName == "ChartWidth")
{
float fWidth = rProp.second.get<float>();
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<sal_Int32>();
}
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<OUString>();
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();
}

View File

@ -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;

View File

@ -8,6 +8,7 @@
*/
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <vcl/font.hxx>
#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);