summaryrefslogtreecommitdiff
path: root/drawinglayer/source/primitive2d/textprimitive2d.cxx
diff options
context:
space:
mode:
authorHerbert Duerr <hdu@openoffice.org>2007-02-21 08:00:34 +0000
committerHerbert Duerr <hdu@openoffice.org>2007-02-21 08:00:34 +0000
commit6b721d4ecb4d755c07cd9717ebbf2ae1250ef652 (patch)
treec6f09d5ecb9d7c65de5642018c9635e35a700d23 /drawinglayer/source/primitive2d/textprimitive2d.cxx
parentb72eefb1659f837f1ad037e2023b32cdd97a824f (diff)
rename TextComplexPortionPrimitive2D to TextDecoratedPortionPrimitive2D
Diffstat (limited to 'drawinglayer/source/primitive2d/textprimitive2d.cxx')
-rw-r--r--drawinglayer/source/primitive2d/textprimitive2d.cxx349
1 files changed, 176 insertions, 173 deletions
diff --git a/drawinglayer/source/primitive2d/textprimitive2d.cxx b/drawinglayer/source/primitive2d/textprimitive2d.cxx
index a3a7b886b03e..ebba6af9b51b 100644
--- a/drawinglayer/source/primitive2d/textprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/textprimitive2d.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: textprimitive2d.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: hdu $ $Date: 2007-02-20 15:24:21 $
+ * last change: $Author: hdu $ $Date: 2007-02-21 09:00:33 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -331,193 +331,196 @@ namespace drawinglayer
{
namespace primitive2d
{
- Primitive2DSequence TextComplexPortionPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
+ Primitive2DSequence TextDecoratedPortionPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
{
Primitive2DSequence aRetval(3);
// First create a simple text primitive and ignore other attributes
aRetval[0] = new TextSimplePortionPrimitive2D(getTextTransform(), getText(), getDXArray(), getFontAttributes(), getFontColor());
- if( meFontUnderline != FONT_UNDERLINE_NONE )
- {
- basegfx::B2DVector aScale, aTranslate;
- double fRotate, fShearX;
- getTextTransform().decompose(aScale, aTranslate, fRotate, fShearX);
- basegfx::B2DHomMatrix aUnscaledTransform;
- aUnscaledTransform.rotate( fRotate );
- aUnscaledTransform.shearX( fShearX );
- aUnscaledTransform.translate( aTranslate.getX(), aTranslate.getY() );
-
- basegfx::B2DHomMatrix aUnrotatedTransform = getTextTransform();
- aUnrotatedTransform.rotate( -fRotate );
+ if( getFontUnderline() == FONT_UNDERLINE_NONE
+ && getFontStrikeout() == FONT_STRIKEOUT_NONE
+ && getEmphasisMarkAbove() == FONT_EMPHASISMARK_NONE
+ && getEmphasisMarkBelow() == FONT_EMPHASISMARK_NONE )
+ return aRetval;
- TextLayouterDevice aTextLayouter;
- aTextLayouter.setFontAttributes(getFontAttributes(), aUnrotatedTransform );
-
-// 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;
-
- const int* pDashDotArray = NULL;
- static const int aDottedArray[] = { 1, 1, 0}; // DOTTED LINE
- static const int aDashDotArray[] = { 1, 1, 4, 1, 0}; // DASHDOT
- static const int aDashDotDotArray[] = { 1, 1, 1, 1, 4, 1, 0}; // DASHDOTDOT
- static const int aDashedArray[] = { 5, 2, 0}; // DASHED LINE
- static const int aLongDashArray[] = { 7, 2, 0}; // LONGDASH
-
- // set Underline attribute
- switch( getFontUnderline() )
- {
- default:
- DBG_WARNING1( "DrawingLayer: Unknown underline attribute (%d)!", getFontUnderline() );
- // fall through
- case primitive2d::FONT_UNDERLINE_NONE:
- fUnderlineHeight = 0;
- break;
- case primitive2d::FONT_UNDERLINE_BOLD:
- fUnderlineHeight *= 2;
- // fall through
- case primitive2d::FONT_UNDERLINE_SINGLE:
- break;
- case primitive2d::FONT_UNDERLINE_DOUBLE:
- bDoubleLine = true;
- break;
- case primitive2d::FONT_UNDERLINE_BOLDDOTTED:
- fUnderlineHeight *= 2;
- // fall through
- case primitive2d::FONT_UNDERLINE_DOTTED:
- eLineJoin = basegfx::tools::B2DLINEJOIN_ROUND;
- pDashDotArray = aDottedArray;
- break;
- case primitive2d::FONT_UNDERLINE_BOLDDASH:
- fUnderlineHeight *= 2;
- // fall through
- case primitive2d::FONT_UNDERLINE_DASH:
- pDashDotArray = aDashedArray;
- break;
- case primitive2d::FONT_UNDERLINE_BOLDLONGDASH:
- fUnderlineHeight *= 2;
- // fall through
- case primitive2d::FONT_UNDERLINE_LONGDASH:
- pDashDotArray = aLongDashArray;
- break;
- case primitive2d::FONT_UNDERLINE_BOLDDASHDOT:
- fUnderlineHeight *= 2;
- // fall through
- case primitive2d::FONT_UNDERLINE_DASHDOT:
- pDashDotArray = aDashDotArray;
- break;
- case primitive2d::FONT_UNDERLINE_BOLDDASHDOTDOT:
- fUnderlineHeight *= 2;
- // fall through
- case primitive2d::FONT_UNDERLINE_DASHDOTDOT:
- eLineJoin = basegfx::tools::B2DLINEJOIN_ROUND;
- pDashDotArray = aDashDotDotArray;
- break;
- case primitive2d::FONT_UNDERLINE_SMALLWAVE:
- // TODO
- bWaveLine = true;
- break;
- case primitive2d::FONT_UNDERLINE_BOLDWAVE:
- fUnderlineHeight *= 2;
- // fall through
- case primitive2d::FONT_UNDERLINE_WAVE:
- // TODO
- bWaveLine = true;
- break;
- case primitive2d::FONT_UNDERLINE_DOUBLEWAVE:
- bWaveLine = true;
- bDoubleLine = true;
- break;
- }
+ // prepare transformation
+ basegfx::B2DVector aScale, aTranslate;
+ double fRotate, fShearX;
+ getTextTransform().decompose(aScale, aTranslate, fRotate, fShearX);
+ basegfx::B2DHomMatrix aUnscaledTransform;
+ aUnscaledTransform.rotate( fRotate );
+ aUnscaledTransform.shearX( fShearX );
+ aUnscaledTransform.translate( aTranslate.getX(), aTranslate.getY() );
- double fTextWidth = 0.0;
- if( getDXArray().empty() )
- fTextWidth = aTextLayouter.getTextWidth( getText(), 0/*TODO*/, getText().Len()/*TODO*/ );
- else
- fTextWidth = getDXArray().back() * aScale.getX();
+ basegfx::B2DHomMatrix aUnrotatedTransform = getTextTransform();
+ aUnrotatedTransform.rotate( -fRotate );
- if( bDoubleLine )
- {
- fUnderlineOffset -= 0.50 * fUnderlineHeight;
- fUnderlineHeight *= 0.64;
- }
+ // get metrics for text decorations like underline/strikeout/emphasis marks
+ TextLayouterDevice aTextLayouter;
+ aTextLayouter.setFontAttributes(getFontAttributes(), aUnrotatedTransform );
- basegfx::B2DPolygon aUnderline;
- ::basegfx::B2DPoint aPoint( 0.0, fUnderlineOffset );
- aUnderline.append( aPoint );
- if( !bWaveLine )
- {
- // straight underline
- aUnderline.append( aPoint + ::basegfx::B2DPoint( fTextWidth, 0.0 ) );
- }
- else
- {
- // wavy underline
- basegfx::B2DPolygon& aWavePoly = aUnderline;
- double fWaveWidth = 4 * fUnderlineHeight;
- if( getFontUnderline() == primitive2d::FONT_UNDERLINE_SMALLWAVE )
- fWaveWidth *= 0.7;
- const double fWaveHeight = 0.5 * fWaveWidth;
- const ::basegfx::B2DPoint aCtrlOffset( fWaveWidth * 0.467308, fWaveHeight );
- for( double fPos = fWaveWidth; fPos < fTextWidth; fPos += fWaveWidth ) {
- // create a symmetrical wave using one cubic bezier curve
- // with y==0 for {x==0, x==0.5*fW or x==1.0*fW}
- // and ymin/ymax at {x=0.25*fW or 0.75*fW}
- const int n = aWavePoly.count();
- aWavePoly.setControlPointA( n-1, aPoint + aCtrlOffset );
- aWavePoly.append( aPoint += ::basegfx::B2DPoint( fWaveWidth, 0.0 ) );
- aWavePoly.setControlPointB( n-1, aPoint - aCtrlOffset );
- }
- // adjust stroke style
+// 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;
+
+ // prepare line styles for text decoration lines
+ const int* pDashDotArray = NULL;
+ static const int aDottedArray[] = { 1, 1, 0}; // DOTTED LINE
+ static const int aDashDotArray[] = { 1, 1, 4, 1, 0}; // DASHDOT
+ static const int aDashDotDotArray[] = { 1, 1, 1, 1, 4, 1, 0}; // DASHDOTDOT
+ static const int aDashedArray[] = { 5, 2, 0}; // DASHED LINE
+ static const int aLongDashArray[] = { 7, 2, 0}; // LONGDASH
+
+ // set Underline attribute
+ switch( getFontUnderline() )
+ {
+ default:
+ DBG_WARNING1( "DrawingLayer: Unknown underline attribute (%d)!", getFontUnderline() );
+ // fall through
+ case primitive2d::FONT_UNDERLINE_NONE:
+ fUnderlineHeight = 0;
+ break;
+ case primitive2d::FONT_UNDERLINE_BOLD:
+ fUnderlineHeight *= 2;
+ // fall through
+ case primitive2d::FONT_UNDERLINE_SINGLE:
+ break;
+ case primitive2d::FONT_UNDERLINE_DOUBLE:
+ bDoubleLine = true;
+ break;
+ case primitive2d::FONT_UNDERLINE_BOLDDOTTED:
+ fUnderlineHeight *= 2;
+ // fall through
+ case primitive2d::FONT_UNDERLINE_DOTTED:
eLineJoin = basegfx::tools::B2DLINEJOIN_ROUND;
- fUnderlineHeight *= 0.5;
- }
-
- const basegfx::BColor& rLineColor = getFontColor();
- attribute::StrokeAttribute aStrokeAttr( rLineColor, fUnderlineHeight, eLineJoin );
- if( pDashDotArray != NULL )
- {
- ::std::vector< double > aDoubleArray;
- for( const int* p = pDashDotArray; *p; ++p )
- aDoubleArray.push_back( *p * fUnderlineHeight);
- const double fFullDashDotLen = ::std::accumulate(aDoubleArray.begin(), aDoubleArray.end(), 0.0);
- aStrokeAttr = attribute::StrokeAttribute( rLineColor,
- fUnderlineHeight, eLineJoin, aDoubleArray, fFullDashDotLen );
+ pDashDotArray = aDottedArray;
+ break;
+ case primitive2d::FONT_UNDERLINE_BOLDDASH:
+ fUnderlineHeight *= 2;
+ // fall through
+ case primitive2d::FONT_UNDERLINE_DASH:
+ pDashDotArray = aDashedArray;
+ break;
+ case primitive2d::FONT_UNDERLINE_BOLDLONGDASH:
+ fUnderlineHeight *= 2;
+ // fall through
+ case primitive2d::FONT_UNDERLINE_LONGDASH:
+ pDashDotArray = aLongDashArray;
+ break;
+ case primitive2d::FONT_UNDERLINE_BOLDDASHDOT:
+ fUnderlineHeight *= 2;
+ // fall through
+ case primitive2d::FONT_UNDERLINE_DASHDOT:
+ pDashDotArray = aDashDotArray;
+ break;
+ case primitive2d::FONT_UNDERLINE_BOLDDASHDOTDOT:
+ fUnderlineHeight *= 2;
+ // fall through
+ case primitive2d::FONT_UNDERLINE_DASHDOTDOT:
+ eLineJoin = basegfx::tools::B2DLINEJOIN_ROUND;
+ pDashDotArray = aDashDotDotArray;
+ break;
+ case primitive2d::FONT_UNDERLINE_SMALLWAVE:
+ // TODO
+ bWaveLine = true;
+ break;
+ case primitive2d::FONT_UNDERLINE_BOLDWAVE:
+ fUnderlineHeight *= 2;
+ // fall through
+ case primitive2d::FONT_UNDERLINE_WAVE:
+ // TODO
+ bWaveLine = true;
+ break;
+ case primitive2d::FONT_UNDERLINE_DOUBLEWAVE:
+ bWaveLine = true;
+ 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( bDoubleLine )
+ {
+ fUnderlineOffset -= 0.50 * fUnderlineHeight;
+ fUnderlineHeight *= 0.64;
+ }
+ basegfx::B2DPolygon aUnderline;
+ ::basegfx::B2DPoint aPoint( 0.0, fUnderlineOffset );
+ aUnderline.append( aPoint );
+ if( !bWaveLine )
+ {
+ // straight underline
+ aUnderline.append( aPoint + ::basegfx::B2DPoint( fTextWidth, 0.0 ) );
+ }
+ else
+ {
+ // wavy underline
+ basegfx::B2DPolygon& aWavePoly = aUnderline;
+ double fWaveWidth = 4 * fUnderlineHeight;
+ if( getFontUnderline() == primitive2d::FONT_UNDERLINE_SMALLWAVE )
+ fWaveWidth *= 0.7;
+ const double fWaveHeight = 0.5 * fWaveWidth;
+ const ::basegfx::B2DPoint aCtrlOffset( fWaveWidth * 0.467308, fWaveHeight );
+ for( double fPos = fWaveWidth; fPos < fTextWidth; fPos += fWaveWidth ) {
+ // create a symmetrical wave using one cubic bezier curve
+ // with y==0 for {x==0, x==0.5*fW or x==1.0*fW}
+ // and ymin/ymax at {x=0.25*fW or 0.75*fW}
+ const int n = aWavePoly.count();
+ aWavePoly.setControlPointA( n-1, aPoint + aCtrlOffset );
+ aWavePoly.append( aPoint += ::basegfx::B2DPoint( fWaveWidth, 0.0 ) );
+ aWavePoly.setControlPointB( n-1, aPoint - aCtrlOffset );
}
- aUnderline.transform( aUnscaledTransform );
- aRetval[1] = new PolygonStrokePrimitive2D( aUnderline, aStrokeAttr );
+ // adjust stroke style
+ eLineJoin = basegfx::tools::B2DLINEJOIN_ROUND;
+ fUnderlineHeight *= 0.5;
+ }
- if( bDoubleLine )
- {
- // 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::B2DHomMatrix aOffsetTransform;
- aOffsetTransform.translate( aOffsetPoint.getX(), aOffsetPoint.getY() );
- aUnderline.transform( aOffsetTransform );
- aRetval[2] = new PolygonStrokePrimitive2D( aUnderline, aStrokeAttr );
- }
+ const basegfx::BColor& rLineColor = getFontColor();
+ attribute::StrokeAttribute aStrokeAttr( rLineColor, fUnderlineHeight, eLineJoin );
+ if( pDashDotArray != NULL )
+ {
+ ::std::vector< double > aDoubleArray;
+ for( const int* p = pDashDotArray; *p; ++p )
+ aDoubleArray.push_back( *p * fUnderlineHeight);
+ const double fFullDashDotLen = ::std::accumulate(aDoubleArray.begin(), aDoubleArray.end(), 0.0);
+ aStrokeAttr = attribute::StrokeAttribute( rLineColor,
+ fUnderlineHeight, eLineJoin, aDoubleArray, fFullDashDotLen );
+ }
+ aUnderline.transform( aUnscaledTransform );
+ aRetval[1] = new PolygonStrokePrimitive2D( aUnderline, aStrokeAttr );
- // TODO: need to take care of
- // -strikethrough
- // -emphasis mark
- // -relief (embosses/engraved)
- // -shadow
- // if( getWordLineMode() )
- // if( getUnderlineAbove() )
+ if( bDoubleLine )
+ {
+ // 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::B2DHomMatrix aOffsetTransform;
+ aOffsetTransform.translate( aOffsetPoint.getX(), aOffsetPoint.getY() );
+ aUnderline.transform( aOffsetTransform );
+ aRetval[2] = new PolygonStrokePrimitive2D( aUnderline, aStrokeAttr );
}
+ // TODO: need to take care of
+ // -strikethrough
+ // -emphasis mark
+ // -relief (embosses/engraved)
+ // -shadow
+ // if( getWordLineMode() )
+ // if( getUnderlineAbove() )
+
return aRetval;
}
- TextComplexPortionPrimitive2D::TextComplexPortionPrimitive2D(
+ TextDecoratedPortionPrimitive2D::TextDecoratedPortionPrimitive2D(
const basegfx::B2DHomMatrix& rNewTransform,
const String& rText,
const ::std::vector< double >& rDXArray,
@@ -547,11 +550,11 @@ namespace drawinglayer
{
}
- bool TextComplexPortionPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
+ bool TextDecoratedPortionPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
{
if(TextSimplePortionPrimitive2D::operator==(rPrimitive))
{
- const TextComplexPortionPrimitive2D& rCompare = (TextComplexPortionPrimitive2D&)rPrimitive;
+ const TextDecoratedPortionPrimitive2D& rCompare = (TextDecoratedPortionPrimitive2D&)rPrimitive;
return (getFontUnderline() == rCompare.getFontUnderline()
&& getFontStrikeout() == rCompare.getFontStrikeout()
@@ -569,7 +572,7 @@ namespace drawinglayer
}
// provide unique ID
- ImplPrimitrive2DIDBlock(TextComplexPortionPrimitive2D, '2','T','C','o')
+ ImplPrimitrive2DIDBlock(TextDecoratedPortionPrimitive2D, '2','T','D','o')
} // end of namespace primitive2d
} // end of namespace drawinglayer