2009-09-17 Armin Le Grand #resolved conflicts for integration 2009-09-07 Armin Le Grand #i103058# re-added handling of StatusBar texts for DrawObject creation, added FullDrag for circle-similar shapes (all in the ellipse toolbar) 2009-09-03 Armin Le Grand #i100514# extended TextAttributes and handling, adapted for super/subscript, adapted WordBreaking (again) 2009-09-02 Armin Le Grand #i104432# secured TextLayouterDevice::getTextBoundRect implementation and usage 2009-09-02 Armin Le Grand #i104232#, #i100514# Mainly solved 1st one, no more local SpellCheck remembering, but adding to compare op's where needed 2009-08-19 Armin Le Grand #i100514# commited in-between version due to 2week holiday 2009-08-13 Armin Le Grand #i99157# applied changes to BitmapEx and SdrHdlBitmapSet 2009-08-06 Armin Le Grand #i100357# added clipping for too big MetaFiles
431 lines
14 KiB
C++
431 lines
14 KiB
C++
/*************************************************************************
|
|
*
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
*
|
|
* $RCSfile: textlayoutdevice.cxx,v $
|
|
*
|
|
* $Revision: 1.10 $
|
|
*
|
|
* last change: $Author: aw $ $Date: 2008-05-27 14:11:20 $
|
|
*
|
|
* The Contents of this file are made available subject to
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
|
*
|
|
*
|
|
* GNU Lesser General Public License Version 2.1
|
|
* =============================================
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
* MA 02111-1307 USA
|
|
*
|
|
************************************************************************/
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
#include "precompiled_drawinglayer.hxx"
|
|
|
|
#include <drawinglayer/primitive2d/textlayoutdevice.hxx>
|
|
#include <vcl/timer.hxx>
|
|
#include <vcl/virdev.hxx>
|
|
#include <vcl/font.hxx>
|
|
#include <vcl/metric.hxx>
|
|
#include <i18npool/mslangid.hxx>
|
|
#include <drawinglayer/primitive2d/textprimitive2d.hxx>
|
|
#include <vcl/svapp.hxx>
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// VDev RevDevice provider
|
|
|
|
namespace
|
|
{
|
|
class ImpTimedRefDev : public Timer
|
|
{
|
|
ImpTimedRefDev** mppStaticPointerOnMe;
|
|
VirtualDevice* mpVirDev;
|
|
sal_uInt32 mnUseCount;
|
|
|
|
public:
|
|
ImpTimedRefDev(ImpTimedRefDev** ppStaticPointerOnMe);
|
|
~ImpTimedRefDev();
|
|
virtual void Timeout();
|
|
|
|
VirtualDevice& acquireVirtualDevice();
|
|
void releaseVirtualDevice();
|
|
};
|
|
|
|
ImpTimedRefDev::ImpTimedRefDev(ImpTimedRefDev** ppStaticPointerOnMe)
|
|
: mppStaticPointerOnMe(ppStaticPointerOnMe),
|
|
mpVirDev(0L),
|
|
mnUseCount(0L)
|
|
{
|
|
SetTimeout(3L * 60L * 1000L); // three minutes
|
|
Start();
|
|
}
|
|
|
|
ImpTimedRefDev::~ImpTimedRefDev()
|
|
{
|
|
OSL_ENSURE(0L == mnUseCount, "destruction of a still used ImpTimedRefDev (!)");
|
|
|
|
if(mppStaticPointerOnMe && *mppStaticPointerOnMe)
|
|
{
|
|
*mppStaticPointerOnMe = 0L;
|
|
}
|
|
|
|
if(mpVirDev)
|
|
{
|
|
delete mpVirDev;
|
|
}
|
|
}
|
|
|
|
void ImpTimedRefDev::Timeout()
|
|
{
|
|
// for obvious reasons, do not call anything after this
|
|
delete (this);
|
|
}
|
|
|
|
VirtualDevice& ImpTimedRefDev::acquireVirtualDevice()
|
|
{
|
|
if(!mpVirDev)
|
|
{
|
|
mpVirDev = new VirtualDevice();
|
|
mpVirDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
|
|
}
|
|
|
|
if(!mnUseCount)
|
|
{
|
|
Stop();
|
|
}
|
|
|
|
mnUseCount++;
|
|
|
|
return *mpVirDev;
|
|
}
|
|
|
|
void ImpTimedRefDev::releaseVirtualDevice()
|
|
{
|
|
OSL_ENSURE(mnUseCount, "mismatch call number to releaseVirtualDevice() (!)");
|
|
mnUseCount--;
|
|
|
|
if(!mnUseCount)
|
|
{
|
|
Start();
|
|
}
|
|
}
|
|
} // end of anonymous namespace
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// access to one global ImpTimedRefDev incarnation in namespace drawinglayer::primitive
|
|
|
|
namespace drawinglayer
|
|
{
|
|
namespace primitive2d
|
|
{
|
|
// static pointer here
|
|
static ImpTimedRefDev* pImpGlobalRefDev = 0L;
|
|
|
|
// static methods here
|
|
VirtualDevice& acquireGlobalVirtualDevice()
|
|
{
|
|
if(!pImpGlobalRefDev)
|
|
{
|
|
pImpGlobalRefDev = new ImpTimedRefDev(&pImpGlobalRefDev);
|
|
}
|
|
|
|
return pImpGlobalRefDev->acquireVirtualDevice();
|
|
}
|
|
|
|
void releaseGlobalVirtualDevice()
|
|
{
|
|
OSL_ENSURE(pImpGlobalRefDev, "releaseGlobalVirtualDevice() without prior acquireGlobalVirtualDevice() call(!)");
|
|
pImpGlobalRefDev->releaseVirtualDevice();
|
|
}
|
|
|
|
TextLayouterDevice::TextLayouterDevice()
|
|
: mrDevice(acquireGlobalVirtualDevice())
|
|
{
|
|
}
|
|
|
|
TextLayouterDevice::~TextLayouterDevice()
|
|
{
|
|
releaseGlobalVirtualDevice();
|
|
}
|
|
|
|
void TextLayouterDevice::setFont(const Font& rFont)
|
|
{
|
|
mrDevice.SetFont( rFont );
|
|
}
|
|
|
|
void TextLayouterDevice::setFontAttributes(
|
|
const FontAttributes& rFontAttributes,
|
|
double fFontScaleX,
|
|
double fFontScaleY,
|
|
const ::com::sun::star::lang::Locale& rLocale)
|
|
{
|
|
setFont(getVclFontFromFontAttributes(
|
|
rFontAttributes,
|
|
fFontScaleX,
|
|
fFontScaleY,
|
|
0.0,
|
|
rLocale));
|
|
}
|
|
|
|
double TextLayouterDevice::getOverlineOffset() const
|
|
{
|
|
const ::FontMetric& rMetric = mrDevice.GetFontMetric();
|
|
double fRet = (rMetric.GetIntLeading() / 2.0) - rMetric.GetAscent();
|
|
return fRet;
|
|
}
|
|
|
|
double TextLayouterDevice::getUnderlineOffset() const
|
|
{
|
|
const ::FontMetric& rMetric = mrDevice.GetFontMetric();
|
|
double fRet = rMetric.GetDescent() / 2.0;
|
|
return fRet;
|
|
}
|
|
|
|
double TextLayouterDevice::getStrikeoutOffset() const
|
|
{
|
|
const ::FontMetric& rMetric = mrDevice.GetFontMetric();
|
|
double fRet = (rMetric.GetAscent() - rMetric.GetIntLeading()) / 3.0;
|
|
return fRet;
|
|
}
|
|
|
|
double TextLayouterDevice::getOverlineHeight() const
|
|
{
|
|
const ::FontMetric& rMetric = mrDevice.GetFontMetric();
|
|
double fRet = rMetric.GetIntLeading() / 2.5;
|
|
return fRet;
|
|
}
|
|
|
|
double TextLayouterDevice::getUnderlineHeight() const
|
|
{
|
|
const ::FontMetric& rMetric = mrDevice.GetFontMetric();
|
|
double fRet = rMetric.GetDescent() / 4.0;
|
|
return fRet;
|
|
}
|
|
|
|
double TextLayouterDevice::getTextHeight() const
|
|
{
|
|
return mrDevice.GetTextHeight();
|
|
}
|
|
|
|
double TextLayouterDevice::getTextWidth(
|
|
const String& rText,
|
|
xub_StrLen nIndex,
|
|
xub_StrLen nLength) const
|
|
{
|
|
return mrDevice.GetTextWidth(rText, nIndex, nLength);
|
|
}
|
|
|
|
bool TextLayouterDevice::getTextOutlines(
|
|
basegfx::B2DPolyPolygonVector& rB2DPolyPolyVector,
|
|
const String& rText,
|
|
xub_StrLen nIndex,
|
|
xub_StrLen nLength,
|
|
const ::std::vector< double >& rDXArray)
|
|
{
|
|
const sal_uInt32 nDXArrayCount(rDXArray.size());
|
|
|
|
if(nDXArrayCount)
|
|
{
|
|
OSL_ENSURE(nDXArrayCount == nLength, "DXArray size does not correspond to text portion size (!)");
|
|
std::vector< sal_Int32 > aIntegerDXArray(nDXArrayCount);
|
|
|
|
for(sal_uInt32 a(0); a < nDXArrayCount; a++)
|
|
{
|
|
aIntegerDXArray[a] = basegfx::fround(rDXArray[a]);
|
|
}
|
|
|
|
return mrDevice.GetTextOutlines(
|
|
rB2DPolyPolyVector,
|
|
rText,
|
|
nIndex,
|
|
nIndex,
|
|
nLength,
|
|
true,
|
|
0,
|
|
&(aIntegerDXArray[0]));
|
|
}
|
|
else
|
|
{
|
|
return mrDevice.GetTextOutlines(
|
|
rB2DPolyPolyVector,
|
|
rText,
|
|
nIndex,
|
|
nIndex,
|
|
nLength,
|
|
true,
|
|
0,
|
|
0);
|
|
}
|
|
}
|
|
|
|
basegfx::B2DRange TextLayouterDevice::getTextBoundRect(
|
|
const String& rText,
|
|
xub_StrLen nIndex,
|
|
xub_StrLen nLength) const
|
|
{
|
|
if(nLength)
|
|
{
|
|
Rectangle aRect;
|
|
|
|
mrDevice.GetTextBoundRect(
|
|
aRect,
|
|
rText,
|
|
nIndex,
|
|
nIndex,
|
|
nLength);
|
|
|
|
// #i104432#, #i102556# take empty results into account
|
|
if(!aRect.IsEmpty())
|
|
{
|
|
return basegfx::B2DRange(aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom());
|
|
}
|
|
}
|
|
|
|
return basegfx::B2DRange();
|
|
}
|
|
} // end of namespace primitive2d
|
|
} // end of namespace drawinglayer
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// helper methods for vcl font handling
|
|
|
|
namespace drawinglayer
|
|
{
|
|
namespace primitive2d
|
|
{
|
|
Font getVclFontFromFontAttributes(
|
|
const FontAttributes& rFontAttributes,
|
|
double fFontScaleX,
|
|
double fFontScaleY,
|
|
double fFontRotation,
|
|
const ::com::sun::star::lang::Locale& rLocale)
|
|
{
|
|
// detect FontScaling
|
|
const sal_uInt32 nHeight(basegfx::fround(fabs(fFontScaleY)));
|
|
const sal_uInt32 nWidth(basegfx::fround(fabs(fFontScaleX)));
|
|
const bool bFontIsScaled(nHeight != nWidth);
|
|
|
|
#ifdef WIN32
|
|
// for WIN32 systems, start with creating an unscaled font. If FontScaling
|
|
// is wanted, that width needs to be adapted using FontMetric again to get a
|
|
// width of the unscaled font
|
|
Font aRetval(
|
|
rFontAttributes.getFamilyName(),
|
|
rFontAttributes.getStyleName(),
|
|
Size(0, nHeight));
|
|
#else
|
|
// for non-WIN32 systems things are easier since these accept a Font creation
|
|
// with initially nWidth != nHeight for FontScaling. Despite that, use zero for
|
|
// FontWidth when no scaling is used to explicitely have that zero when e.g. the
|
|
// Font would be recorded in a MetaFile (The MetaFile FontAction WILL record a
|
|
// set FontWidth; import that in a WIN32 system, and trouble is there)
|
|
Font aRetval(
|
|
rFontAttributes.getFamilyName(),
|
|
rFontAttributes.getStyleName(),
|
|
Size(bFontIsScaled ? nWidth : 0, nHeight));
|
|
#endif
|
|
// define various other FontAttributes
|
|
aRetval.SetAlign(ALIGN_BASELINE);
|
|
aRetval.SetCharSet(rFontAttributes.getSymbol() ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE);
|
|
aRetval.SetVertical(rFontAttributes.getVertical() ? TRUE : FALSE);
|
|
aRetval.SetWeight(static_cast<FontWeight>(rFontAttributes.getWeight()));
|
|
aRetval.SetItalic(rFontAttributes.getItalic() ? ITALIC_NORMAL : ITALIC_NONE);
|
|
aRetval.SetOutline(rFontAttributes.getOutline());
|
|
aRetval.SetLanguage(MsLangId::convertLocaleToLanguage(rLocale));
|
|
|
|
#ifdef WIN32
|
|
// for WIN32 systems, correct the FontWidth if FontScaling is used
|
|
if(bFontIsScaled && nHeight > 0)
|
|
{
|
|
const FontMetric aUnscaledFontMetric(Application::GetDefaultDevice()->GetFontMetric(aRetval));
|
|
|
|
if(aUnscaledFontMetric.GetWidth() > 0)
|
|
{
|
|
const double fScaleFactor((double)nWidth / (double)nHeight);
|
|
const sal_uInt32 nScaledWidth(basegfx::fround((double)aUnscaledFontMetric.GetWidth() * fScaleFactor));
|
|
aRetval.SetWidth(nScaledWidth);
|
|
}
|
|
}
|
|
#endif
|
|
// handle FontRotation (if defined)
|
|
if(!basegfx::fTools::equalZero(fFontRotation))
|
|
{
|
|
sal_Int16 aRotate10th((sal_Int16)(fFontRotation * (-1800.0/F_PI)));
|
|
aRetval.SetOrientation(aRotate10th % 3600);
|
|
}
|
|
|
|
return aRetval;
|
|
}
|
|
|
|
FontAttributes getFontAttributesFromVclFont(
|
|
basegfx::B2DVector& o_rSize,
|
|
const Font& rFont,
|
|
bool bRTL,
|
|
bool bBiDiStrong)
|
|
{
|
|
const FontAttributes aRetval(
|
|
rFont.GetName(),
|
|
rFont.GetStyleName(),
|
|
static_cast<sal_uInt16>(rFont.GetWeight()),
|
|
RTL_TEXTENCODING_SYMBOL == rFont.GetCharSet(),
|
|
rFont.IsVertical(),
|
|
ITALIC_NONE != rFont.GetItalic(),
|
|
rFont.IsOutline(),
|
|
bRTL,
|
|
bBiDiStrong);
|
|
// TODO: eKerning
|
|
|
|
// set FontHeight and init to no FontScaling
|
|
o_rSize.setY(rFont.GetSize().getHeight() > 0 ? rFont.GetSize().getHeight() : 0);
|
|
o_rSize.setX(o_rSize.getY());
|
|
|
|
#ifdef WIN32
|
|
// for WIN32 systems, the FontScaling at the Font is detected by
|
|
// checking that FontWidth != 0. When FontScaling is used, WIN32
|
|
// needs to do extra stuff to detect the correct width (since it's
|
|
// zero and not equal the font height) and it's relationship to
|
|
// the height
|
|
if(rFont.GetSize().getWidth() > 0)
|
|
{
|
|
Font aUnscaledFont(rFont);
|
|
aUnscaledFont.SetWidth(0);
|
|
const FontMetric aUnscaledFontMetric(Application::GetDefaultDevice()->GetFontMetric(aUnscaledFont));
|
|
|
|
if(aUnscaledFontMetric.GetWidth() > 0)
|
|
{
|
|
const double fScaleFactor((double)rFont.GetSize().getWidth() / (double)aUnscaledFontMetric.GetWidth());
|
|
o_rSize.setX(fScaleFactor * o_rSize.getY());
|
|
}
|
|
}
|
|
#else
|
|
// For non-WIN32 systems the detection is the same, but the value
|
|
// is easier achieved since width == height is interpreted as no
|
|
// scaling. Ergo, Width == 0 means width == height, and width != 0
|
|
// means the scaling is in the direct relation of width to height
|
|
if(rFont.GetSize().getWidth() > 0)
|
|
{
|
|
o_rSize.setX((double)rFont.GetSize().getWidth());
|
|
}
|
|
#endif
|
|
return aRetval;
|
|
}
|
|
} // end of namespace primitive2d
|
|
} // end of namespace drawinglayer
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// eof
|