summaryrefslogtreecommitdiff
path: root/vcl
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
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')
-rw-r--r--vcl/qa/cppunit/outdev.cxx76
-rw-r--r--vcl/source/gdi/print.cxx19
-rw-r--r--vcl/source/outdev/textline.cxx95
3 files changed, 151 insertions, 39 deletions
diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index bc70ba11ac25..d9aa34a0250c 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -49,6 +49,8 @@ public:
void testTransparentFillColor();
void testFillColor();
void testSystemTextColor();
+ void testShouldDrawWavePixelAsRect();
+ void testGetWaveLineSize();
CPPUNIT_TEST_SUITE(VclOutdevTest);
CPPUNIT_TEST(testVirtualDevice);
@@ -71,6 +73,8 @@ public:
CPPUNIT_TEST(testTransparentFillColor);
CPPUNIT_TEST(testFillColor);
CPPUNIT_TEST(testSystemTextColor);
+ CPPUNIT_TEST(testShouldDrawWavePixelAsRect);
+ CPPUNIT_TEST(testGetWaveLineSize);
CPPUNIT_TEST_SUITE_END();
};
@@ -549,6 +553,78 @@ void VclOutdevTest::testSystemTextColor()
}
}
+namespace
+{
+class WaveLineTester : public OutputDevice
+{
+public:
+ WaveLineTester()
+ : OutputDevice(OUTDEV_VIRDEV)
+ {
+ }
+
+ bool AcquireGraphics() const { return true; }
+ void ReleaseGraphics(bool) {}
+ bool UsePolyPolygonForComplexGradient() { return false; }
+
+ bool testShouldDrawWavePixelAsRect(tools::Long nLineWidth)
+ {
+ return shouldDrawWavePixelAsRect(nLineWidth);
+ }
+
+ Size testGetWaveLineSize(tools::Long nLineWidth) { return GetWaveLineSize(nLineWidth); }
+};
+
+class WaveLineTesterPrinter : public Printer
+{
+public:
+ WaveLineTesterPrinter() {}
+
+ bool AcquireGraphics() const { return true; }
+ void ReleaseGraphics(bool) {}
+ bool UsePolyPolygonForComplexGradient() { return false; }
+
+ Size testGetWaveLineSize(tools::Long nLineWidth) { return GetWaveLineSize(nLineWidth); }
+};
+}
+
+void VclOutdevTest::testShouldDrawWavePixelAsRect()
+{
+ ScopedVclPtrInstance<WaveLineTester> pTestOutDev;
+
+ CPPUNIT_ASSERT(!pTestOutDev->testShouldDrawWavePixelAsRect(0));
+ CPPUNIT_ASSERT(!pTestOutDev->testShouldDrawWavePixelAsRect(1));
+
+ CPPUNIT_ASSERT(pTestOutDev->testShouldDrawWavePixelAsRect(10));
+}
+
+void VclOutdevTest::testGetWaveLineSize()
+{
+ {
+ ScopedVclPtrInstance<WaveLineTester> pTestOutDev;
+
+ pTestOutDev->SetDPIX(96);
+ pTestOutDev->SetDPIY(96);
+
+ CPPUNIT_ASSERT_EQUAL(Size(1, 1), pTestOutDev->testGetWaveLineSize(0));
+ CPPUNIT_ASSERT_EQUAL(Size(1, 1), pTestOutDev->testGetWaveLineSize(1));
+
+ CPPUNIT_ASSERT_EQUAL(Size(10, 10), pTestOutDev->testGetWaveLineSize(10));
+ }
+
+ {
+ ScopedVclPtrInstance<WaveLineTesterPrinter> pTestOutDev;
+
+ pTestOutDev->SetDPIX(96);
+ pTestOutDev->SetDPIY(96);
+
+ CPPUNIT_ASSERT_EQUAL(Size(0, 0), pTestOutDev->testGetWaveLineSize(0));
+ CPPUNIT_ASSERT_EQUAL(Size(1, 1), pTestOutDev->testGetWaveLineSize(1));
+
+ CPPUNIT_ASSERT_EQUAL(Size(10, 10), pTestOutDev->testGetWaveLineSize(10));
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(VclOutdevTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index 593744b4e321..6b6b070a69f3 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -1750,6 +1750,25 @@ css::awt::DeviceInfo Printer::GetDeviceInfo() const
return aInfo;
}
+void Printer::SetWaveLineColors(Color const& rColor, tools::Long)
+{
+ if (mbLineColor || mbInitLineColor)
+ {
+ mpGraphics->SetLineColor();
+ mbInitLineColor = true;
+ }
+
+ mpGraphics->SetFillColor(rColor);
+ mbInitFillColor = true;
+}
+
+Size Printer::GetWaveLineSize(tools::Long nLineWidth) const
+{
+ // FIXME - do we have a bug here? If the linewidth is 0, then we will return
+ // Size(0, 0) - is this correct?
+ return Size(nLineWidth, ((nLineWidth*mnDPIX)+(mnDPIY/2))/mnDPIY);
+}
+
void Printer::SetSystemTextColor(SystemTextColorFlags, bool)
{
SetTextColor(COL_BLACK);
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++;
}
}