[Libreoffice-commits] core.git: vcl/qa vcl/source
Chris Sherlock (via logerrit)
logerrit at kemper.freedesktop.org
Fri Sep 3 05:21:14 UTC 2021
vcl/qa/cppunit/outdev.cxx | 73 ++++++++++++++++++++++++++++++++++++++
vcl/source/outdev/font.cxx | 73 +++++++++++++++++++++++++++++++-------
vcl/source/outdev/outdevstate.cxx | 46 -----------------------
3 files changed, 133 insertions(+), 59 deletions(-)
New commits:
commit a01c60927c3cedf775d3ba66d3602988c274fb09
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
AuthorDate: Wed Aug 25 16:13:57 2021 +1000
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri Sep 3 07:20:41 2021 +0200
vcl: Migrate OutputDevice font functions to font.cxx
Add unit tests for SetFont() and GetFont()
Change-Id: I5b66cd5531aa0f9fd73357dd2a168d9c5b655b35
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121016
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 0f2039d27943..adbf72751b4c 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -52,6 +52,8 @@ public:
void testDefaultLineColor();
void testTransparentLineColor();
void testLineColor();
+ void testFont();
+ void testTransparentFont();
void testSystemTextColor();
void testShouldDrawWavePixelAsRect();
void testGetWaveLineSize();
@@ -80,6 +82,8 @@ public:
CPPUNIT_TEST(testDefaultLineColor);
CPPUNIT_TEST(testTransparentLineColor);
CPPUNIT_TEST(testLineColor);
+ CPPUNIT_TEST(testFont);
+ CPPUNIT_TEST(testTransparentFont);
CPPUNIT_TEST(testSystemTextColor);
CPPUNIT_TEST(testShouldDrawWavePixelAsRect);
CPPUNIT_TEST(testGetWaveLineSize);
@@ -652,6 +656,75 @@ void VclOutdevTest::testLineColor()
CPPUNIT_ASSERT_EQUAL(COL_RED, rColor);
}
+void VclOutdevTest::testFont()
+{
+ ScopedVclPtrInstance<VirtualDevice> pVDev;
+
+ // Use Dejavu fonts, they are shipped with LO, so they should be ~always available.
+ // Use Sans variant for simpler glyph shapes (no serifs).
+ vcl::Font font("DejaVu Sans", "Book", Size(0, 36));
+ font.SetColor(COL_BLACK);
+ font.SetFillColor(COL_RED);
+
+ GDIMetaFile aMtf;
+ aMtf.Record(pVDev.get());
+
+ pVDev->SetFont(font);
+ bool bSameFont(font == pVDev->GetFont());
+ CPPUNIT_ASSERT_MESSAGE("Font is not the same", bSameFont);
+
+ // four actions:
+ // 1. Font action
+ // 2. Text alignment action
+ // 3. Text fill color action
+ // 4. As not COL_TRANSPARENT (means use system font color), font color action
+ size_t nActionsExpected = 4;
+ CPPUNIT_ASSERT_EQUAL(nActionsExpected, aMtf.GetActionSize());
+
+ MetaAction* pAction = aMtf.GetAction(0);
+ CPPUNIT_ASSERT_EQUAL(MetaActionType::FONT, pAction->GetType());
+ auto pFontAction = static_cast<MetaFontAction*>(pAction);
+ bool bSameMetaFont = (font == pFontAction->GetFont());
+ CPPUNIT_ASSERT_MESSAGE("Metafile font is not the same", bSameMetaFont);
+
+ pAction = aMtf.GetAction(1);
+ CPPUNIT_ASSERT_EQUAL(MetaActionType::TEXTALIGN, pAction->GetType());
+ auto pTextAlignAction = static_cast<MetaTextAlignAction*>(pAction);
+ CPPUNIT_ASSERT_EQUAL(font.GetAlignment(), pTextAlignAction->GetTextAlign());
+
+ pAction = aMtf.GetAction(2);
+ CPPUNIT_ASSERT_EQUAL(MetaActionType::TEXTFILLCOLOR, pAction->GetType());
+ auto pTextFillColorAction = static_cast<MetaTextFillColorAction*>(pAction);
+ CPPUNIT_ASSERT_EQUAL(COL_RED, pTextFillColorAction->GetColor());
+
+ pAction = aMtf.GetAction(3);
+ CPPUNIT_ASSERT_EQUAL(MetaActionType::TEXTCOLOR, pAction->GetType());
+ auto pTextColorAction = static_cast<MetaTextColorAction*>(pAction);
+ CPPUNIT_ASSERT_EQUAL(COL_BLACK, pTextColorAction->GetColor());
+}
+
+void VclOutdevTest::testTransparentFont()
+{
+ ScopedVclPtrInstance<VirtualDevice> pVDev;
+
+ // Use Dejavu fonts, they are shipped with LO, so they should be ~always available.
+ // Use Sans variant for simpler glyph shapes (no serifs).
+ vcl::Font font("DejaVu Sans", "Book", Size(0, 36));
+ font.SetColor(COL_TRANSPARENT);
+
+ GDIMetaFile aMtf;
+ aMtf.Record(pVDev.get());
+
+ pVDev->SetFont(font);
+
+ // three actions as it sets the colour to the default system color (and doesn't add a text color action):
+ // 1. Font action
+ // 2. Text alignment action
+ // 3. Text fill color action
+ size_t nActionsExpected = 3;
+ CPPUNIT_ASSERT_EQUAL(nActionsExpected, aMtf.GetActionSize());
+}
+
void VclOutdevTest::testSystemTextColor()
{
{
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index bfaa0226b1ce..3f84afb2c3bf 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -17,33 +17,80 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <rtl/ustrbuf.hxx>
+#include <sal/log.hxx>
+#include <tools/debug.hxx>
#include <i18nlangtag/mslangid.hxx>
#include <i18nlangtag/lang.h>
-
#include <unotools/configmgr.hxx>
+
+#include <vcl/event.hxx>
+#include <vcl/fontcharmap.hxx>
+#include <vcl/metaact.hxx>
#include <vcl/metric.hxx>
-#include <vcl/virdev.hxx>
#include <vcl/print.hxx>
#include <vcl/sysdata.hxx>
-#include <vcl/fontcharmap.hxx>
-#include <vcl/event.hxx>
-#include <font/FeatureCollector.hxx>
-#include <rtl/ustrbuf.hxx>
-#include <sal/log.hxx>
-#include <tools/debug.hxx>
-
-#include <sallayout.hxx>
-#include <salgdi.hxx>
-#include <svdata.hxx>
-#include <impglyphitem.hxx>
+#include <vcl/virdev.hxx>
#include <outdev.h>
#include <window.h>
#include <PhysicalFontCollection.hxx>
+#include <drawmode.hxx>
+#include <font/FeatureCollector.hxx>
+#include <impglyphitem.hxx>
+#include <sallayout.hxx>
+#include <salgdi.hxx>
+#include <svdata.hxx>
#include <strings.hrc>
+void OutputDevice::SetFont( const vcl::Font& rNewFont )
+{
+ vcl::Font aFont = vcl::drawmode::GetFont(rNewFont, GetDrawMode(), GetSettings().GetStyleSettings());
+
+ if ( mpMetaFile )
+ {
+ mpMetaFile->AddAction( new MetaFontAction( aFont ) );
+ // the color and alignment actions don't belong here
+ // TODO: get rid of them without breaking anything...
+ mpMetaFile->AddAction( new MetaTextAlignAction( aFont.GetAlignment() ) );
+ mpMetaFile->AddAction( new MetaTextFillColorAction( aFont.GetFillColor(), !aFont.IsTransparent() ) );
+ }
+
+ if ( maFont.IsSameInstance( aFont ) )
+ return;
+
+ // Optimization MT/HDU: COL_TRANSPARENT means SetFont should ignore the font color,
+ // because SetTextColor() is used for this.
+ // #i28759# maTextColor might have been changed behind our back, commit then, too.
+ if( aFont.GetColor() != COL_TRANSPARENT
+ && (aFont.GetColor() != maFont.GetColor() || aFont.GetColor() != maTextColor ) )
+ {
+ maTextColor = aFont.GetColor();
+ mbInitTextColor = true;
+ if( mpMetaFile )
+ mpMetaFile->AddAction( new MetaTextColorAction( aFont.GetColor() ) );
+ }
+ maFont = aFont;
+ mbNewFont = true;
+
+ if( !mpAlphaVDev )
+ return;
+
+ // #i30463#
+ // Since SetFont might change the text color, apply that only
+ // selectively to alpha vdev (which normally paints opaque text
+ // with COL_BLACK)
+ if( aFont.GetColor() != COL_TRANSPARENT )
+ {
+ mpAlphaVDev->SetTextColor( COL_BLACK );
+ aFont.SetColor( COL_TRANSPARENT );
+ }
+
+ mpAlphaVDev->SetFont( aFont );
+}
+
FontMetric OutputDevice::GetDevFont( int nDevFontIndex ) const
{
FontMetric aFontMetric;
diff --git a/vcl/source/outdev/outdevstate.cxx b/vcl/source/outdev/outdevstate.cxx
index a859f29faecb..7be07f4d81e1 100644
--- a/vcl/source/outdev/outdevstate.cxx
+++ b/vcl/source/outdev/outdevstate.cxx
@@ -277,50 +277,4 @@ void OutputDevice::SetRasterOp( RasterOp eRasterOp )
mpAlphaVDev->SetRasterOp( eRasterOp );
}
-void OutputDevice::SetFont( const vcl::Font& rNewFont )
-{
- vcl::Font aFont = vcl::drawmode::GetFont(rNewFont, GetDrawMode(), GetSettings().GetStyleSettings());
-
- if ( mpMetaFile )
- {
- mpMetaFile->AddAction( new MetaFontAction( aFont ) );
- // the color and alignment actions don't belong here
- // TODO: get rid of them without breaking anything...
- mpMetaFile->AddAction( new MetaTextAlignAction( aFont.GetAlignment() ) );
- mpMetaFile->AddAction( new MetaTextFillColorAction( aFont.GetFillColor(), !aFont.IsTransparent() ) );
- }
-
- if ( maFont.IsSameInstance( aFont ) )
- return;
-
- // Optimization MT/HDU: COL_TRANSPARENT means SetFont should ignore the font color,
- // because SetTextColor() is used for this.
- // #i28759# maTextColor might have been changed behind our back, commit then, too.
- if( aFont.GetColor() != COL_TRANSPARENT
- && (aFont.GetColor() != maFont.GetColor() || aFont.GetColor() != maTextColor ) )
- {
- maTextColor = aFont.GetColor();
- mbInitTextColor = true;
- if( mpMetaFile )
- mpMetaFile->AddAction( new MetaTextColorAction( aFont.GetColor() ) );
- }
- maFont = aFont;
- mbNewFont = true;
-
- if( !mpAlphaVDev )
- return;
-
- // #i30463#
- // Since SetFont might change the text color, apply that only
- // selectively to alpha vdev (which normally paints opaque text
- // with COL_BLACK)
- if( aFont.GetColor() != COL_TRANSPARENT )
- {
- mpAlphaVDev->SetTextColor( COL_BLACK );
- aFont.SetColor( COL_TRANSPARENT );
- }
-
- mpAlphaVDev->SetFont( aFont );
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list