vcl: Create accessor and mutator for font scaling in FontMetric
This is fragile code! There are actually *two* classes that do almost
precisely the same thing, they are:
- ImplFontMetric, and
- ImplFontMetricData
They both have much in common, including their class name, and even
most of their functionality. In fact, they both have common accessor
functions. When I look at the code, it looks like OutputDevice is
actually given an ImplFontMetricData object, which it then uses to
populate an ImplFontMetric object...
Basically, I'm going to merge these classes. To do so, I'm going to
do the following:
Step 1: Implement accessor functions for ImplFontMetric and FontMetric
(then remove the friendship of this class to OutputDevice!)
Step 2: Write a unit test for each accessor function in ImplFontMetric
Step 3: Ensure that ImplFontMetric and ImplFontMetricData use some
sort of smart pointer (probably an intrusive_ptr like I did
ages ago with FontCharMap)
Step 4: Merge the two classes together once their class interfaces
are the same and I am satisfied they do the same thing
Step 5: Find all instances of inefficient usage - for instance, I can
do away with the code that copies the ImplFontMetricData
attributes into an ImplFontMetric object.
Change-Id: I07c1cb848774b130fa2ca60b51da53e07754dd00
Reviewed-on: https://gerrit.libreoffice.org/21399
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
2016-01-13 03:05:29 +11:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <test/bootstrapfixture.hxx>
|
2016-01-14 07:48:48 +11:00
|
|
|
#include <cppunit/TestAssert.h>
|
vcl: Create accessor and mutator for font scaling in FontMetric
This is fragile code! There are actually *two* classes that do almost
precisely the same thing, they are:
- ImplFontMetric, and
- ImplFontMetricData
They both have much in common, including their class name, and even
most of their functionality. In fact, they both have common accessor
functions. When I look at the code, it looks like OutputDevice is
actually given an ImplFontMetricData object, which it then uses to
populate an ImplFontMetric object...
Basically, I'm going to merge these classes. To do so, I'm going to
do the following:
Step 1: Implement accessor functions for ImplFontMetric and FontMetric
(then remove the friendship of this class to OutputDevice!)
Step 2: Write a unit test for each accessor function in ImplFontMetric
Step 3: Ensure that ImplFontMetric and ImplFontMetricData use some
sort of smart pointer (probably an intrusive_ptr like I did
ages ago with FontCharMap)
Step 4: Merge the two classes together once their class interfaces
are the same and I am satisfied they do the same thing
Step 5: Find all instances of inefficient usage - for instance, I can
do away with the code that copies the ImplFontMetricData
attributes into an ImplFontMetric object.
Change-Id: I07c1cb848774b130fa2ca60b51da53e07754dd00
Reviewed-on: https://gerrit.libreoffice.org/21399
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
2016-01-13 03:05:29 +11:00
|
|
|
|
|
|
|
#include <vcl/metric.hxx>
|
|
|
|
|
|
|
|
class VclFontMetricTest : public test::BootstrapFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VclFontMetricTest() : BootstrapFixture(true, false) {}
|
|
|
|
|
2016-01-13 12:13:12 +11:00
|
|
|
void testFullstopCenteredFlag();
|
2016-01-14 07:48:48 +11:00
|
|
|
void testSpacings();
|
2016-01-14 08:51:33 +11:00
|
|
|
void testSlant();
|
2016-01-14 09:11:20 +11:00
|
|
|
void testBulletOffset();
|
vcl: Create accessor and mutator for font scaling in FontMetric
This is fragile code! There are actually *two* classes that do almost
precisely the same thing, they are:
- ImplFontMetric, and
- ImplFontMetricData
They both have much in common, including their class name, and even
most of their functionality. In fact, they both have common accessor
functions. When I look at the code, it looks like OutputDevice is
actually given an ImplFontMetricData object, which it then uses to
populate an ImplFontMetric object...
Basically, I'm going to merge these classes. To do so, I'm going to
do the following:
Step 1: Implement accessor functions for ImplFontMetric and FontMetric
(then remove the friendship of this class to OutputDevice!)
Step 2: Write a unit test for each accessor function in ImplFontMetric
Step 3: Ensure that ImplFontMetric and ImplFontMetricData use some
sort of smart pointer (probably an intrusive_ptr like I did
ages ago with FontCharMap)
Step 4: Merge the two classes together once their class interfaces
are the same and I am satisfied they do the same thing
Step 5: Find all instances of inefficient usage - for instance, I can
do away with the code that copies the ImplFontMetricData
attributes into an ImplFontMetric object.
Change-Id: I07c1cb848774b130fa2ca60b51da53e07754dd00
Reviewed-on: https://gerrit.libreoffice.org/21399
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
2016-01-13 03:05:29 +11:00
|
|
|
void testEqualityOperator();
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(VclFontMetricTest);
|
2016-01-13 12:13:12 +11:00
|
|
|
CPPUNIT_TEST(testFullstopCenteredFlag);
|
2016-01-14 07:48:48 +11:00
|
|
|
CPPUNIT_TEST(testSpacings);
|
2016-01-14 08:51:33 +11:00
|
|
|
CPPUNIT_TEST(testSlant);
|
2016-01-14 09:11:20 +11:00
|
|
|
CPPUNIT_TEST(testBulletOffset);
|
2016-01-14 08:15:40 +11:00
|
|
|
CPPUNIT_TEST(testEqualityOperator);
|
vcl: Create accessor and mutator for font scaling in FontMetric
This is fragile code! There are actually *two* classes that do almost
precisely the same thing, they are:
- ImplFontMetric, and
- ImplFontMetricData
They both have much in common, including their class name, and even
most of their functionality. In fact, they both have common accessor
functions. When I look at the code, it looks like OutputDevice is
actually given an ImplFontMetricData object, which it then uses to
populate an ImplFontMetric object...
Basically, I'm going to merge these classes. To do so, I'm going to
do the following:
Step 1: Implement accessor functions for ImplFontMetric and FontMetric
(then remove the friendship of this class to OutputDevice!)
Step 2: Write a unit test for each accessor function in ImplFontMetric
Step 3: Ensure that ImplFontMetric and ImplFontMetricData use some
sort of smart pointer (probably an intrusive_ptr like I did
ages ago with FontCharMap)
Step 4: Merge the two classes together once their class interfaces
are the same and I am satisfied they do the same thing
Step 5: Find all instances of inefficient usage - for instance, I can
do away with the code that copies the ImplFontMetricData
attributes into an ImplFontMetric object.
Change-Id: I07c1cb848774b130fa2ca60b51da53e07754dd00
Reviewed-on: https://gerrit.libreoffice.org/21399
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
2016-01-13 03:05:29 +11:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
2016-01-13 12:13:12 +11:00
|
|
|
void VclFontMetricTest::testFullstopCenteredFlag()
|
|
|
|
{
|
|
|
|
// default constructor should set scalable flag to false
|
|
|
|
FontMetric aFontMetric;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Fullstop centered flag should be false after default constructor called", !aFontMetric.IsFullstopCentered() );
|
|
|
|
|
|
|
|
aFontMetric.SetFullstopCenteredFlag(true);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Fullstop centered flag should be true", aFontMetric.IsFullstopCentered() );
|
|
|
|
}
|
|
|
|
|
2016-01-14 07:48:48 +11:00
|
|
|
void VclFontMetricTest::testSpacings()
|
|
|
|
{
|
|
|
|
// default constructor should set scalable flag to false
|
|
|
|
FontMetric aFontMetric;
|
|
|
|
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 0L, aFontMetric.GetAscent() );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0L, aFontMetric.GetDescent() );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0L, aFontMetric.GetExternalLeading() );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0L, aFontMetric.GetInternalLeading() );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0L, aFontMetric.GetLineHeight() );
|
2016-01-14 08:15:40 +11:00
|
|
|
|
2016-01-14 07:48:48 +11:00
|
|
|
|
|
|
|
aFontMetric.SetAscent( 100 );
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 100L, aFontMetric.GetAscent() );
|
2016-01-14 07:48:48 +11:00
|
|
|
|
|
|
|
aFontMetric.SetDescent( 100 );
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 100L, aFontMetric.GetDescent() );
|
2016-01-14 07:48:48 +11:00
|
|
|
|
2017-08-16 14:45:49 +02:00
|
|
|
aFontMetric.SetExternalLeading( 100 );
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 100L, aFontMetric.GetExternalLeading() );
|
2016-01-14 07:48:48 +11:00
|
|
|
|
2017-08-16 14:45:49 +02:00
|
|
|
aFontMetric.SetInternalLeading( 100 );
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 100L, aFontMetric.GetInternalLeading() );
|
2016-01-14 08:15:40 +11:00
|
|
|
|
2017-08-16 14:45:49 +02:00
|
|
|
aFontMetric.SetLineHeight( 100 );
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 100L, aFontMetric.GetLineHeight() );
|
2016-01-14 07:48:48 +11:00
|
|
|
}
|
|
|
|
|
2016-01-14 08:51:33 +11:00
|
|
|
void VclFontMetricTest::testSlant()
|
|
|
|
{
|
|
|
|
// default constructor should set scalable flag to false
|
|
|
|
FontMetric aFontMetric;
|
|
|
|
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 0L, aFontMetric.GetSlant() );
|
2016-01-14 08:51:33 +11:00
|
|
|
|
|
|
|
aFontMetric.SetSlant( 45 );
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 45L, aFontMetric.GetSlant() );
|
2016-01-14 08:51:33 +11:00
|
|
|
}
|
|
|
|
|
2016-01-14 09:11:20 +11:00
|
|
|
void VclFontMetricTest::testBulletOffset()
|
|
|
|
{
|
|
|
|
// default constructor should set scalable flag to false
|
|
|
|
FontMetric aFontMetric;
|
|
|
|
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 0L, aFontMetric.GetBulletOffset() );
|
2016-01-14 09:11:20 +11:00
|
|
|
|
|
|
|
aFontMetric.SetBulletOffset( 45 );
|
2018-05-31 13:20:41 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 45L, aFontMetric.GetBulletOffset() );
|
2016-01-14 09:11:20 +11:00
|
|
|
}
|
2016-01-14 08:51:33 +11:00
|
|
|
|
vcl: Create accessor and mutator for font scaling in FontMetric
This is fragile code! There are actually *two* classes that do almost
precisely the same thing, they are:
- ImplFontMetric, and
- ImplFontMetricData
They both have much in common, including their class name, and even
most of their functionality. In fact, they both have common accessor
functions. When I look at the code, it looks like OutputDevice is
actually given an ImplFontMetricData object, which it then uses to
populate an ImplFontMetric object...
Basically, I'm going to merge these classes. To do so, I'm going to
do the following:
Step 1: Implement accessor functions for ImplFontMetric and FontMetric
(then remove the friendship of this class to OutputDevice!)
Step 2: Write a unit test for each accessor function in ImplFontMetric
Step 3: Ensure that ImplFontMetric and ImplFontMetricData use some
sort of smart pointer (probably an intrusive_ptr like I did
ages ago with FontCharMap)
Step 4: Merge the two classes together once their class interfaces
are the same and I am satisfied they do the same thing
Step 5: Find all instances of inefficient usage - for instance, I can
do away with the code that copies the ImplFontMetricData
attributes into an ImplFontMetric object.
Change-Id: I07c1cb848774b130fa2ca60b51da53e07754dd00
Reviewed-on: https://gerrit.libreoffice.org/21399
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
2016-01-13 03:05:29 +11:00
|
|
|
void VclFontMetricTest::testEqualityOperator()
|
|
|
|
{
|
|
|
|
// default constructor should set scalable flag to false
|
|
|
|
FontMetric aLhs, aRhs;
|
|
|
|
|
2016-01-13 12:13:12 +11:00
|
|
|
aLhs.SetFullstopCenteredFlag(true);
|
|
|
|
aRhs.SetFullstopCenteredFlag(true);
|
2017-04-28 14:22:53 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Fullstop centered flag set same, aLhs == aRhs failed", aLhs.operator ==(aRhs) );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Fullstop centered flag set same, aLhs != aRhs succeeded", !aLhs.operator !=(aRhs) );
|
2016-01-13 17:14:53 +11:00
|
|
|
|
2016-01-13 18:33:13 +11:00
|
|
|
aLhs.SetExternalLeading(10);
|
|
|
|
aRhs.SetExternalLeading(10);
|
2017-04-28 14:22:53 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "External leading set same, aLHS == aRhs failed", aLhs.operator ==(aRhs) );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "External leading set same, aLHS != aRhs succeeded", !aLhs.operator !=(aRhs) );
|
2016-01-13 18:33:13 +11:00
|
|
|
|
|
|
|
aLhs.SetInternalLeading(10);
|
|
|
|
aRhs.SetInternalLeading(10);
|
2017-04-28 14:22:53 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Internal leading set same, aLHS == aRhs failed", aLhs.operator ==(aRhs) );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Internal leading set same, aLHS != aRhs succeeded", !aLhs.operator !=(aRhs) );
|
2016-01-14 07:48:48 +11:00
|
|
|
|
|
|
|
aLhs.SetAscent( 100 );
|
|
|
|
aRhs.SetAscent( 100 );
|
2017-04-28 14:22:53 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Ascent set same, aLHS == aRhs failed", aLhs.operator ==(aRhs) );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Ascent set same, aLHS != aRhs succeeded", !aLhs.operator !=(aRhs) );
|
2016-01-14 07:48:48 +11:00
|
|
|
|
|
|
|
aLhs.SetDescent( 100 );
|
|
|
|
aRhs.SetDescent( 100 );
|
2017-04-28 14:22:53 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Descent set same, aLHS == aRhs failed", aLhs.operator ==(aRhs));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Descent set same, aLHS != aRhs succeeded", !aLhs.operator !=(aRhs) );
|
2016-01-14 08:51:33 +11:00
|
|
|
|
|
|
|
aLhs.SetSlant( 100 );
|
|
|
|
aRhs.SetSlant( 100 );
|
2017-04-28 14:22:53 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Slant set same, aLHS == aRhs failed", aLhs.operator ==(aRhs));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Slant set same, aLHS != aRhs succeeded", !aLhs.operator !=(aRhs) );
|
vcl: Create accessor and mutator for font scaling in FontMetric
This is fragile code! There are actually *two* classes that do almost
precisely the same thing, they are:
- ImplFontMetric, and
- ImplFontMetricData
They both have much in common, including their class name, and even
most of their functionality. In fact, they both have common accessor
functions. When I look at the code, it looks like OutputDevice is
actually given an ImplFontMetricData object, which it then uses to
populate an ImplFontMetric object...
Basically, I'm going to merge these classes. To do so, I'm going to
do the following:
Step 1: Implement accessor functions for ImplFontMetric and FontMetric
(then remove the friendship of this class to OutputDevice!)
Step 2: Write a unit test for each accessor function in ImplFontMetric
Step 3: Ensure that ImplFontMetric and ImplFontMetricData use some
sort of smart pointer (probably an intrusive_ptr like I did
ages ago with FontCharMap)
Step 4: Merge the two classes together once their class interfaces
are the same and I am satisfied they do the same thing
Step 5: Find all instances of inefficient usage - for instance, I can
do away with the code that copies the ImplFontMetricData
attributes into an ImplFontMetric object.
Change-Id: I07c1cb848774b130fa2ca60b51da53e07754dd00
Reviewed-on: https://gerrit.libreoffice.org/21399
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
2016-01-13 03:05:29 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(VclFontMetricTest);
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|