diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2016-01-16 12:24:17 +1100 |
---|---|---|
committer | Chris Sherlock <chris.sherlock79@gmail.com> | 2016-01-16 05:59:52 +0000 |
commit | bb3fc6cda5700e64eec3233737765e0ab55f5b9e (patch) | |
tree | 360f9fa9fd995927227a233e0f1a6c5daec0bd4c | |
parent | 65c1137757e394961808a29b5607ee0ed6977a34 (diff) |
vcl: created accessors and mutators for font classes
Font accessors:
- GetFamily()
- GetPitch()
- GetWidthType()
- GetWeight()
- GetItalic()
- GetName() <--- shouldn't that be GetFamilyName()?!?
- GetStyleName()
Font mutators did not need to be added.
Font unit tests are testing:
- Setting and getting FontFamily private member
- Setting and getting FontPitch private member
- Setting and getting FontWidth private member
- Setting and getting FontWeight private member
- Setting and getting FontItalic private member
- Setting and getting the family name and style
ImplFont accessors:
- GetFamilyNoAsk()
- GetPitchNoAsk()
- GetWidthTypeNoAsk()
- GetWeightNoAsk()
- GetItalicNoAsk()
- GetFamilyName()
- GetStyleName()
(These "NoAsk" functions are necessary because the default getters call on a function
that checks the configuration for default values, something that is not wanted in all
cases).
Change-Id: Icfbc8b4e5253d55a80892df050b0803dfc7d7c9f
Reviewed-on: https://gerrit.libreoffice.org/21501
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
-rw-r--r-- | include/vcl/font.hxx | 5 | ||||
-rw-r--r-- | vcl/inc/impfont.hxx | 9 | ||||
-rw-r--r-- | vcl/qa/cppunit/font.cxx | 63 | ||||
-rw-r--r-- | vcl/source/font/font.cxx | 86 |
4 files changed, 120 insertions, 43 deletions
diff --git a/include/vcl/font.hxx b/include/vcl/font.hxx index 04052ad3f47a..c8a2c2df9037 100644 --- a/include/vcl/font.hxx +++ b/include/vcl/font.hxx @@ -78,6 +78,7 @@ public: long GetWidth() const; void SetFamily( FontFamily ); + FontFamily GetFamily(); FontFamily GetFamily() const; void SetCharSet( rtl_TextEncoding ); rtl_TextEncoding GetCharSet() const; @@ -94,6 +95,7 @@ public: void SetCJKContextLanguage( LanguageType ); LanguageType GetCJKContextLanguage() const; void SetPitch( FontPitch ePitch ); + FontPitch GetPitch(); FontPitch GetPitch() const; void SetOrientation( short nLineOrientation ); @@ -105,10 +107,13 @@ public: bool IsKerning() const; void SetWeight( FontWeight ); + FontWeight GetWeight(); FontWeight GetWeight() const; void SetWidthType( FontWidth ); + FontWidth GetWidthType(); FontWidth GetWidthType() const; void SetItalic( FontItalic ); + FontItalic GetItalic(); FontItalic GetItalic() const; void SetOutline( bool bOutline ); bool IsOutline() const; diff --git a/vcl/inc/impfont.hxx b/vcl/inc/impfont.hxx index a4d9e25ec2af..54b4cf8135aa 100644 --- a/vcl/inc/impfont.hxx +++ b/vcl/inc/impfont.hxx @@ -38,14 +38,21 @@ public: // device independent font functions const OUString& GetFamilyName() const { return maFamilyName; } FontFamily GetFamily() { if(meFamily==FAMILY_DONTKNOW) AskConfig(); return meFamily; } + FontFamily GetFamilyNoAsk() const { return meFamily; } FontFamily GetFamilyType() { return GetFamily(); } + FontFamily GetFamilyTypeNoAsk() const { return GetFamilyNoAsk(); } const OUString& GetStyleName() const { return maStyleName; } FontWeight GetWeight() { if(meWeight==WEIGHT_DONTKNOW) AskConfig(); return meWeight; } + FontWeight GetWeightNoAsk() const { return meWeight; } FontItalic GetSlantType() { return GetItalic(); } + FontItalic GetSlantType() const { return GetItalicNoAsk(); } FontItalic GetItalic() { if(meItalic==ITALIC_DONTKNOW) AskConfig(); return meItalic; } + FontItalic GetItalicNoAsk() const { return meItalic; } FontPitch GetPitch() { if(mePitch==PITCH_DONTKNOW) AskConfig(); return mePitch; } - FontWidth GetWidthType() { if(meWidthType==WIDTH_DONTKNOW)AskConfig(); return meWidthType; } + FontPitch GetPitchNoAsk() const { return mePitch; } + FontWidth GetWidthType() { if(meWidthType==WIDTH_DONTKNOW) AskConfig(); return meWidthType; } + FontWidth GetWidthTypeNoAsk() const { return meWidthType; } bool IsSymbolFont() const { return mbSymbol; } diff --git a/vcl/qa/cppunit/font.cxx b/vcl/qa/cppunit/font.cxx index 0e70ee329369..b5ae8d71325d 100644 --- a/vcl/qa/cppunit/font.cxx +++ b/vcl/qa/cppunit/font.cxx @@ -21,13 +21,76 @@ class VclFontTest : public test::BootstrapFixture public: VclFontTest() : BootstrapFixture(true, false) {} + void testName(); + void testWeight(); + void testWidthType(); + void testPitch(); + void testItalic(); void testSymbolFlagAndCharSet(); CPPUNIT_TEST_SUITE(VclFontTest); + CPPUNIT_TEST(testName); + CPPUNIT_TEST(testWeight); + CPPUNIT_TEST(testWidthType); + CPPUNIT_TEST(testPitch); + CPPUNIT_TEST(testItalic); CPPUNIT_TEST(testSymbolFlagAndCharSet); CPPUNIT_TEST_SUITE_END(); }; +void VclFontTest::testName() +{ + vcl::Font aFont; + + CPPUNIT_ASSERT_MESSAGE( "Family name should be empty", aFont.GetName().isEmpty()); + CPPUNIT_ASSERT_MESSAGE( "Style name should be empty", aFont.GetStyleName().isEmpty()); + aFont.SetName("Test family name"); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Family name should not be empty", OUString("Test family name"), aFont.GetName()); + aFont.SetStyleName("Test style name"); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Style name should not be empty", OUString("Test style name"), aFont.GetStyleName()); +} + +void VclFontTest::testWeight() +{ + vcl::Font aFont; + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Weight should be WEIGHT_DONTKNOW", FontWeight::WEIGHT_DONTKNOW, aFont.GetWeight()); + + aFont.SetWeight(FontWeight::WEIGHT_BLACK); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Weight should be WEIGHT_BLACK", FontWeight::WEIGHT_BLACK, aFont.GetWeight()); +} + +void VclFontTest::testWidthType() +{ + vcl::Font aFont; + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font width should be WIDTH_DONTKNOW", FontWidth::WIDTH_DONTKNOW, aFont.GetWidthType()); + + aFont.SetWidthType(FontWidth::WIDTH_EXPANDED); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font width should be EXPANDED", FontWidth::WIDTH_EXPANDED, aFont.GetWidthType()); +} + +void VclFontTest::testItalic() +{ + vcl::Font aFont; + + // shouldn't this be set to ITALIC_DONTKNOW? currently it defaults to ITALIC_NONE + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Italic should be ITALIC_NONE", FontItalic::ITALIC_NONE, aFont.GetItalic()); + + aFont.SetItalic(FontItalic::ITALIC_NORMAL); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Italic should be EXPANDED", FontItalic::ITALIC_NORMAL, aFont.GetItalic()); +} + +void VclFontTest::testPitch() +{ + vcl::Font aFont; + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Pitch should be PITCH_DONTKNOW", FontPitch::PITCH_DONTKNOW, aFont.GetPitch()); + + aFont.SetPitch(FontPitch::PITCH_FIXED); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Pitch should be PITCH_FIXED", FontPitch::PITCH_FIXED, aFont.GetPitch()); +} + void VclFontTest::testSymbolFlagAndCharSet() { // default constructor should set scalable flag to false diff --git a/vcl/source/font/font.cxx b/vcl/source/font/font.cxx index 28c80bb1e432..dfb219a2c893 100644 --- a/vcl/source/font/font.cxx +++ b/vcl/source/font/font.cxx @@ -59,14 +59,14 @@ Font::Font( const vcl::Font& rFont ) Font::Font( const OUString& rFamilyName, const Size& rSize ) { mpImplFont = new ImplFont; - mpImplFont->maFamilyName = rFamilyName; + mpImplFont->SetFamilyName( rFamilyName ); mpImplFont->maSize = rSize; } Font::Font( const OUString& rFamilyName, const OUString& rStyleName, const Size& rSize ) { mpImplFont = new ImplFont; - mpImplFont->maFamilyName= rFamilyName; + mpImplFont->SetFamilyName( rFamilyName ); mpImplFont->maStyleName = rStyleName; mpImplFont->maSize = rSize; } @@ -140,7 +140,7 @@ void Font::SetAlign( FontAlign eAlign ) void Font::SetName( const OUString& rFamilyName ) { MakeUnique(); - mpImplFont->maFamilyName = rFamilyName; + mpImplFont->SetFamilyName( rFamilyName ); } void Font::SetStyleName( const OUString& rStyleName ) @@ -239,10 +239,10 @@ void Font::SetCJKContextLanguage( LanguageType eLanguage ) void Font::SetPitch( FontPitch ePitch ) { - if( mpImplFont->mePitch != ePitch ) + if( mpImplFont->GetPitchNoAsk() != ePitch ) { MakeUnique(); - mpImplFont->mePitch = ePitch; + mpImplFont->SetPitch( ePitch ); } } @@ -280,28 +280,28 @@ bool Font::IsKerning() const void Font::SetWeight( FontWeight eWeight ) { - if( mpImplFont->meWeight != eWeight ) + if( mpImplFont->GetWeightNoAsk() != eWeight ) { MakeUnique(); - mpImplFont->meWeight = eWeight; + mpImplFont->SetWeight( eWeight ); } } void Font::SetWidthType( FontWidth eWidth ) { - if( mpImplFont->meWidthType != eWidth ) + if( mpImplFont->GetWidthTypeNoAsk() != eWidth ) { MakeUnique(); - mpImplFont->meWidthType = eWidth; + mpImplFont->SetWidthType( eWidth ); } } void Font::SetItalic( FontItalic eItalic ) { - if( mpImplFont->meItalic != eItalic ) + if( mpImplFont->GetItalicNoAsk() != eItalic ) { MakeUnique(); - mpImplFont->meItalic = eItalic; + mpImplFont->SetItalic( eItalic ); } } @@ -417,16 +417,16 @@ void Font::Merge( const vcl::Font& rFont ) SetLanguageTag( rFont.GetLanguageTag() ); SetCJKContextLanguageTag( rFont.GetCJKContextLanguageTag() ); // don't use access methods here, might lead to AskConfig(), if DONTKNOW - SetFamily( rFont.mpImplFont->meFamily ); - SetPitch( rFont.mpImplFont->mePitch ); + SetFamily( rFont.mpImplFont->GetFamilyNoAsk() ); + SetPitch( rFont.mpImplFont->GetPitchNoAsk() ); } // don't use access methods here, might lead to AskConfig(), if DONTKNOW - if ( rFont.mpImplFont->meWeight != WEIGHT_DONTKNOW ) + if ( rFont.mpImplFont->GetWeightNoAsk() != WEIGHT_DONTKNOW ) SetWeight( rFont.GetWeight() ); - if ( rFont.mpImplFont->meItalic != ITALIC_DONTKNOW ) + if ( rFont.mpImplFont->GetItalicNoAsk() != ITALIC_DONTKNOW ) SetItalic( rFont.GetItalic() ); - if ( rFont.mpImplFont->meWidthType != WIDTH_DONTKNOW ) + if ( rFont.mpImplFont->GetWidthTypeNoAsk() != WIDTH_DONTKNOW ) SetWidthType( rFont.GetWidthType() ); if ( rFont.GetSize().Height() ) @@ -459,12 +459,12 @@ void Font::Merge( const vcl::Font& rFont ) void Font::GetFontAttributes( FontAttributes& rAttrs ) const { - rAttrs.SetFamilyName( mpImplFont->maFamilyName ); + rAttrs.SetFamilyName( mpImplFont->GetFamilyName() ); rAttrs.SetStyleName( mpImplFont->maStyleName ); - rAttrs.SetFamilyType( mpImplFont->meFamily ); - rAttrs.SetPitch( mpImplFont->mePitch ); - rAttrs.SetItalic( mpImplFont->meItalic ); - rAttrs.SetWeight( mpImplFont->meWeight ); + rAttrs.SetFamilyType( mpImplFont->GetFamilyNoAsk() ); + rAttrs.SetPitch( mpImplFont->GetPitchNoAsk() ); + rAttrs.SetItalic( mpImplFont->GetItalicNoAsk() ); + rAttrs.SetWeight( mpImplFont->GetWeightNoAsk() ); rAttrs.SetWidthType( WIDTH_DONTKNOW ); rAttrs.SetSymbolFlag( mpImplFont->meCharSet == RTL_TEXTENCODING_SYMBOL ); } @@ -476,17 +476,17 @@ SvStream& ReadImplFont( SvStream& rIStm, ImplFont& rImplFont ) bool bTmp; sal_uInt8 nTmp8; - rImplFont.maFamilyName = rIStm.ReadUniOrByteString(rIStm.GetStreamCharSet()); + rImplFont.SetFamilyName( rIStm.ReadUniOrByteString(rIStm.GetStreamCharSet()) ); rImplFont.maStyleName = rIStm.ReadUniOrByteString(rIStm.GetStreamCharSet()); ReadPair( rIStm, rImplFont.maSize ); rIStm.ReadUInt16( nTmp16 ); rImplFont.meCharSet = (rtl_TextEncoding) nTmp16; rIStm.ReadUInt16( nTmp16 ); rImplFont.meFamily = (FontFamily) nTmp16; - rIStm.ReadUInt16( nTmp16 ); rImplFont.mePitch = (FontPitch) nTmp16; - rIStm.ReadUInt16( nTmp16 ); rImplFont.meWeight = (FontWeight) nTmp16; + rIStm.ReadUInt16( nTmp16 ); rImplFont.SetPitch( (FontPitch) nTmp16 ); + rIStm.ReadUInt16( nTmp16 ); rImplFont.SetWeight( (FontWeight) nTmp16 ); rIStm.ReadUInt16( nTmp16 ); rImplFont.meUnderline = (FontUnderline) nTmp16; rIStm.ReadUInt16( nTmp16 ); rImplFont.meStrikeout = (FontStrikeout) nTmp16; - rIStm.ReadUInt16( nTmp16 ); rImplFont.meItalic = (FontItalic) nTmp16; + rIStm.ReadUInt16( nTmp16 ); rImplFont.SetItalic( (FontItalic) nTmp16 ); rIStm.ReadUInt16( nTmp16 ); rImplFont.maLanguageTag.reset( (LanguageType) nTmp16); rIStm.ReadUInt16( nTmp16 ); rImplFont.meWidthType = (FontWidth) nTmp16; @@ -517,19 +517,19 @@ SvStream& ReadImplFont( SvStream& rIStm, ImplFont& rImplFont ) SvStream& WriteImplFont( SvStream& rOStm, const ImplFont& rImplFont ) { VersionCompat aCompat( rOStm, StreamMode::WRITE, 3 ); - rOStm.WriteUniOrByteString( rImplFont.maFamilyName, rOStm.GetStreamCharSet() ); + rOStm.WriteUniOrByteString( rImplFont.GetFamilyName(), rOStm.GetStreamCharSet() ); rOStm.WriteUniOrByteString( rImplFont.maStyleName, rOStm.GetStreamCharSet() ); WritePair( rOStm, rImplFont.maSize ); rOStm.WriteUInt16( GetStoreCharSet( rImplFont.meCharSet ) ); - rOStm.WriteUInt16( rImplFont.meFamily ); - rOStm.WriteUInt16( rImplFont.mePitch ); - rOStm.WriteUInt16( rImplFont.meWeight ); + rOStm.WriteUInt16( rImplFont.GetFamilyNoAsk() ); + rOStm.WriteUInt16( rImplFont.GetPitchNoAsk() ); + rOStm.WriteUInt16( rImplFont.GetWeightNoAsk() ); rOStm.WriteUInt16( rImplFont.meUnderline ); rOStm.WriteUInt16( rImplFont.meStrikeout ); - rOStm.WriteUInt16( rImplFont.meItalic ); + rOStm.WriteUInt16( rImplFont.GetItalicNoAsk() ); rOStm.WriteUInt16( rImplFont.maLanguageTag.getLanguageType( false) ); - rOStm.WriteUInt16( rImplFont.meWidthType ); + rOStm.WriteUInt16( rImplFont.GetWidthTypeNoAsk() ); rOStm.WriteInt16( rImplFont.mnOrientation ); @@ -778,7 +778,7 @@ bool Font::IsTransparent() const { return mpImplFont->mbTransparent; } FontAlign Font::GetAlign() const { return mpImplFont->meAlign; } -const OUString& Font::GetName() const { return mpImplFont->maFamilyName; } +const OUString& Font::GetName() const { return mpImplFont->GetFamilyName(); } const OUString& Font::GetStyleName() const { return mpImplFont->maStyleName; } @@ -808,15 +808,17 @@ bool Font::IsVertical() const { return mpImplFont->mbVertical; } FontKerning Font::GetKerning() const { return mpImplFont->mnKerning; } -FontPitch Font::GetPitch() const { return mpImplFont->GetPitch(); } +FontPitch Font::GetPitch() { return mpImplFont->GetPitch(); } +FontWeight Font::GetWeight() { return mpImplFont->GetWeight(); } +FontWidth Font::GetWidthType() { return mpImplFont->GetWidthType(); } +FontItalic Font::GetItalic() { return mpImplFont->GetItalic(); } +FontFamily Font::GetFamily() { return mpImplFont->GetFamily(); } -FontWeight Font::GetWeight() const { return mpImplFont->GetWeight(); } - -FontWidth Font::GetWidthType() const { return mpImplFont->GetWidthType(); } - -FontItalic Font::GetItalic() const { return mpImplFont->GetItalic(); } - -FontFamily Font::GetFamily() const { return mpImplFont->GetFamily(); } +FontPitch Font::GetPitch() const { return mpImplFont->GetPitchNoAsk(); } +FontWeight Font::GetWeight() const { return mpImplFont->GetWeightNoAsk(); } +FontWidth Font::GetWidthType() const { return mpImplFont->GetWidthTypeNoAsk(); } +FontItalic Font::GetItalic() const { return mpImplFont->GetItalicNoAsk(); } +FontFamily Font::GetFamily() const { return mpImplFont->GetFamilyNoAsk(); } bool Font::IsOutline() const { return mpImplFont->mbOutline; } @@ -1008,8 +1010,8 @@ void ImplFont::AskConfig() meFamily = FAMILY_DECORATIVE; } - if( meWeight == WEIGHT_DONTKNOW ) - meWeight = eWeight; + if( GetWeight() == WEIGHT_DONTKNOW ) + SetWeight( eWeight ); if( meWidthType == WIDTH_DONTKNOW ) meWidthType = eWidthType; } |