summaryrefslogtreecommitdiff
path: root/vcl/source/outdev/textline.cxx
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2021-05-12 20:16:24 +1000
committerTomaž Vajngerl <quikee@gmail.com>2021-09-02 02:23:35 +0200
commit368e21fbc34fa4104f16498a54ab77704f39e6b4 (patch)
tree7fe5c287cebb355942cb75a00f893431b132774c /vcl/source/outdev/textline.cxx
parent11b954e4f92da7620ba2dc89430fa09d3946f780 (diff)
tdf#74702 vcl: make helper funcs for ImplDrawWaveLine() and ImplDrawWavePixel()
Unit tests written for Printer and OutputDevice, note that I might have uncovered a bug. Change-Id: Ic8e6e02ce0df349fc6fb6a3334105c1e6dfa3f36 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113563 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source/outdev/textline.cxx')
-rw-r--r--vcl/source/outdev/textline.cxx95
1 files changed, 56 insertions, 39 deletions
diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx
index 2ce85be775ad..9fd82541262f 100644
--- a/vcl/source/outdev/textline.cxx
+++ b/vcl/source/outdev/textline.cxx
@@ -113,21 +113,20 @@ void OutputDevice::ImplInitAboveTextLineSize()
void OutputDevice::ImplDrawWavePixel( tools::Long nOriginX, tools::Long nOriginY,
tools::Long nCurX, tools::Long nCurY,
+ tools::Long nWidth,
Degree10 nOrientation,
SalGraphics* pGraphics,
const OutputDevice& rOutDev,
- bool bDrawPixAsRect,
tools::Long nPixWidth, tools::Long nPixHeight )
{
- if ( nOrientation )
+ if (nOrientation)
{
Point aPoint( nOriginX, nOriginY );
aPoint.RotateAround( nCurX, nCurY, nOrientation );
}
- if ( bDrawPixAsRect )
+ if (shouldDrawWavePixelAsRect(nWidth))
{
-
pGraphics->DrawRect( nCurX, nCurY, nPixWidth, nPixHeight, rOutDev );
}
else
@@ -136,6 +135,43 @@ void OutputDevice::ImplDrawWavePixel( tools::Long nOriginX, tools::Long nOriginY
}
}
+bool OutputDevice::shouldDrawWavePixelAsRect(tools::Long nLineWidth) const
+{
+ if (nLineWidth > 1)
+ return true;
+
+ return false;
+}
+
+void OutputDevice::SetWaveLineColors(Color const& rColor, tools::Long nLineWidth)
+{
+ // On printers that output pixel via DrawRect()
+ if (nLineWidth > 1)
+ {
+ if (mbLineColor || mbInitLineColor)
+ {
+ mpGraphics->SetLineColor();
+ mbInitLineColor = true;
+ }
+
+ mpGraphics->SetFillColor( rColor );
+ mbInitFillColor = true;
+ }
+ else
+ {
+ mpGraphics->SetLineColor( rColor );
+ mbInitLineColor = true;
+ }
+}
+
+Size OutputDevice::GetWaveLineSize(tools::Long nLineWidth) const
+{
+ if (nLineWidth > 1)
+ return Size(nLineWidth, ((nLineWidth*mnDPIX)+(mnDPIY/2))/mnDPIY);
+
+ return Size(1, 1);
+}
+
void OutputDevice::ImplDrawWaveLine( tools::Long nBaseX, tools::Long nBaseY,
tools::Long nDistX, tools::Long nDistY,
tools::Long nWidth, tools::Long nHeight,
@@ -172,39 +208,20 @@ void OutputDevice::ImplDrawWaveLine( tools::Long nBaseX, tools::Long nBaseY,
tools::Long nDiffY = nHeight-1;
tools::Long nCount = nWidth;
tools::Long nOffY = -1;
- tools::Long nPixWidth;
- tools::Long nPixHeight;
- bool bDrawPixAsRect;
- // On printers that output pixel via DrawRect()
- if ( (GetOutDevType() == OUTDEV_PRINTER) || (nLineWidth > 1) )
- {
- if ( mbLineColor || mbInitLineColor )
- {
- mpGraphics->SetLineColor();
- mbInitLineColor = true;
- }
- mpGraphics->SetFillColor( rColor );
- mbInitFillColor = true;
- bDrawPixAsRect = true;
- nPixWidth = nLineWidth;
- nPixHeight = ((nLineWidth*mnDPIX)+(mnDPIY/2))/mnDPIY;
- }
- else
- {
- mpGraphics->SetLineColor( rColor );
- mbInitLineColor = true;
- nPixWidth = 1;
- nPixHeight = 1;
- bDrawPixAsRect = false;
- }
+
+ SetWaveLineColors(rColor, nLineWidth);
+ Size aSize(GetWaveLineSize(nLineWidth));
+
+ tools::Long nPixWidth = aSize.Width();
+ tools::Long nPixHeight = aSize.Height();
if ( !nDiffY )
{
while ( nWidth )
{
- ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nOrientation,
+ ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nLineWidth, nOrientation,
mpGraphics, *this,
- bDrawPixAsRect, nPixWidth, nPixHeight );
+ nPixWidth, nPixHeight );
nCurX++;
nWidth--;
}
@@ -217,17 +234,17 @@ void OutputDevice::ImplDrawWaveLine( tools::Long nBaseX, tools::Long nBaseY,
{
for( tools::Long i = nDiffY; i; --i )
{
- ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nOrientation,
+ ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nLineWidth, nOrientation,
mpGraphics, *this,
- bDrawPixAsRect, nPixWidth, nPixHeight );
+ nPixWidth, nPixHeight );
nCurX++;
nCurY += nOffY;
}
for( tools::Long i = nDiffX; i; --i )
{
- ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nOrientation,
+ ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nLineWidth, nOrientation,
mpGraphics, *this,
- bDrawPixAsRect, nPixWidth, nPixHeight );
+ nPixWidth, nPixHeight );
nCurX++;
}
nOffY = -nOffY;
@@ -237,18 +254,18 @@ void OutputDevice::ImplDrawWaveLine( tools::Long nBaseX, tools::Long nBaseY,
{
for( tools::Long i = nDiffY; i && nFreq; --i, --nFreq )
{
- ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nOrientation,
+ ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nLineWidth, nOrientation,
mpGraphics, *this,
- bDrawPixAsRect, nPixWidth, nPixHeight );
+ nPixWidth, nPixHeight );
nCurX++;
nCurY += nOffY;
}
for( tools::Long i = nDiffX; i && nFreq; --i, --nFreq )
{
- ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nOrientation,
+ ImplDrawWavePixel( nBaseX, nBaseY, nCurX, nCurY, nLineWidth, nOrientation,
mpGraphics, *this,
- bDrawPixAsRect, nPixWidth, nPixHeight );
+ nPixWidth, nPixHeight );
nCurX++;
}
}