add strikeout style as text decoration

This commit is contained in:
Herbert Duerr 2007-02-22 13:10:26 +00:00
parent 8d83746f9f
commit ff03a80067

View file

@ -4,9 +4,9 @@
*
* $RCSfile: textprimitive2d.cxx,v $
*
* $Revision: 1.9 $
* $Revision: 1.10 $
*
* last change: $Author: hdu $ $Date: 2007-02-21 11:28:48 $
* last change: $Author: hdu $ $Date: 2007-02-22 14:10:26 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@ -333,7 +333,7 @@ namespace drawinglayer
{
Primitive2DSequence TextDecoratedPortionPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
{
Primitive2DSequence aRetval(3);
Primitive2DSequence aRetval(6);
// First create a simple text primitive and ignore other attributes
aRetval[0] = new TextSimplePortionPrimitive2D(getTextTransform(), getText(), getDXArray(), getFontAttributes(), getFontColor());
@ -363,11 +363,16 @@ namespace drawinglayer
// const double fLineHeight = aTextLayouter.getTextHeight();
double fUnderlineOffset = aTextLayouter.getUnderlineOffset();
double fUnderlineHeight = aTextLayouter.getUnderlineHeight();
// const double fStrikeoutOffset = aTextLayouter.getStrikeoutOffset();
basegfx::tools::B2DLineJoin eLineJoin = basegfx::tools::B2DLINEJOIN_NONE;
bool bDoubleLine = false;
bool bWaveLine = false;
double fTextWidth = 0.0;
if( getDXArray().empty() )
fTextWidth = aTextLayouter.getTextWidth( getText(), 0/*TODO*/, getText().Len()/*TODO*/ );
else
fTextWidth = getDXArray().back() * aScale.getX();
// prepare line styles for text decoration lines
const int* pDashDotArray = NULL;
static const int aDottedArray[] = { 1, 1, 0}; // DOTTED LINE
@ -441,16 +446,15 @@ namespace drawinglayer
bDoubleLine = true;
break;
}
double fTextWidth = 0.0;
if( getDXArray().empty() )
fTextWidth = aTextLayouter.getTextWidth( getText(), 0/*TODO*/, getText().Len()/*TODO*/ );
else
fTextWidth = getDXArray().back() * aScale.getX();
if( fUnderlineHeight > 0 )
{
if( bDoubleLine )
{
fUnderlineOffset -= 0.50 * fUnderlineHeight;
fUnderlineHeight *= 0.64;
}
basegfx::B2DPolygon aUnderline;
::basegfx::B2DPoint aPoint( 0.0, fUnderlineOffset );
aUnderline.append( aPoint );
@ -500,14 +504,98 @@ namespace drawinglayer
{
// add another underline below the first underline
const double fLineDist = (bWaveLine ? 3 : 2) * fUnderlineHeight;
::basegfx::B2DPoint aOffsetPoint( 0.0, fLineDist );
aUnscaledTransform.translate( -aTranslate.getX(), -aTranslate.getY() );
aOffsetPoint = aUnscaledTransform * aOffsetPoint;
::basegfx::B2DVector aOffsetVector( 0.0, fLineDist );
aOffsetVector = aUnscaledTransform * aOffsetVector;
basegfx::B2DHomMatrix aOffsetTransform;
aOffsetTransform.translate( aOffsetPoint.getX(), aOffsetPoint.getY() );
aOffsetTransform.translate( aOffsetVector.getX(), aOffsetVector.getY() );
aUnderline.transform( aOffsetTransform );
aRetval[2] = new PolygonStrokePrimitive2D( aUnderline, aStrokeAttr );
}
}
double fStrikeoutHeight = aTextLayouter.getUnderlineHeight();
double fStrikeoutOffset = aTextLayouter.getStrikeoutOffset();
eLineJoin = basegfx::tools::B2DLINEJOIN_NONE;
bDoubleLine = false;
sal_Unicode aStrikeoutChar = '\0';
// set Underline attribute
switch( getFontStrikeout() )
{
default:
DBG_WARNING1( "DrawingLayer: Unknown underline attribute (%d)!", getFontUnderline() );
// fall through
case primitive2d::FONT_STRIKEOUT_NONE:
fStrikeoutHeight = 0;
break;
case primitive2d::FONT_STRIKEOUT_SINGLE:
break;
case primitive2d::FONT_STRIKEOUT_DOUBLE:
bDoubleLine = true;
break;
case primitive2d::FONT_STRIKEOUT_BOLD:
fStrikeoutHeight *= 2;
break;
case primitive2d::FONT_STRIKEOUT_SLASH:
aStrikeoutChar = '/';
// fStrikeoutHeight = 0;
break;
case primitive2d::FONT_STRIKEOUT_X:
aStrikeoutChar = 'X';
// fStrikeoutHeight = 0;
break;
};
if( fStrikeoutHeight > 0 )
{
if( bDoubleLine )
{
fStrikeoutOffset -= 0.50 * fStrikeoutHeight;
fStrikeoutHeight *= 0.64;
}
basegfx::B2DPolygon aStrikeoutLine;
basegfx::B2DPoint aPoint( 0.0, -fStrikeoutOffset );
aStrikeoutLine.append( aPoint );
if( 1/*####*/ )
{
// straight underline
aStrikeoutLine.append( aPoint + ::basegfx::B2DPoint( fTextWidth, 0.0 ) );
}
const basegfx::BColor& rStrikeoutColor = getFontColor();
attribute::StrokeAttribute aStrokeAttr( rStrikeoutColor, fStrikeoutHeight, eLineJoin );
aStrikeoutLine.transform( aUnscaledTransform );
aRetval[3] = new PolygonStrokePrimitive2D( aStrikeoutLine, aStrokeAttr );
if( bDoubleLine )
{
// add another strikeout below the first strikeout
const double fLineDist = 2 * fStrikeoutHeight;
::basegfx::B2DVector aOffsetVector( 0.0, -fLineDist );
aOffsetVector = aUnscaledTransform * aOffsetVector;
basegfx::B2DHomMatrix aOffsetTransform;
aOffsetTransform.translate( aOffsetVector.getX(), aOffsetVector.getY() );
aStrikeoutLine.transform( aOffsetTransform );
aRetval[4] = new PolygonStrokePrimitive2D( aStrikeoutLine, aStrokeAttr );
}
}
if( aStrikeoutChar != '\0' )
{
String aString( &aStrikeoutChar, 1 );
double fStrikeCharWidth = aTextLayouter.getTextWidth( aString, 0, 1 );
double fStrikeCharCount = fTextWidth / fStrikeCharWidth;
int nStrikeCharCount = static_cast<int>(fStrikeCharCount + 0.9);
for( int i = 1; i < nStrikeCharCount; ++i )
aString += aStrikeoutChar;
std::vector<double> aDXArray( nStrikeCharCount );
fStrikeCharWidth /= aScale.getX();
for( int i = 0; i < nStrikeCharCount; ++i )
aDXArray[i] = (i+1) * fStrikeCharWidth;
const basegfx::BColor& rStrikeoutColor = getFontColor();
aRetval[5] = new TextSimplePortionPrimitive2D(getTextTransform(), aString, aDXArray, getFontAttributes(), rStrikeoutColor );
}
// TODO: need to take care of
// -strikethrough