summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2016-01-01 17:52:50 +1100
committerChris Sherlock <chris.sherlock79@gmail.com>2016-01-01 18:51:23 +0000
commit264e6c04afaff96dda6cd510c1da90bb519a1f66 (patch)
tree8ad63fa1ad70136ee105b91a054f128bd4522281
parent820eeba6772a356cf57b9d1f4d114122f6a63abb (diff)
vcl: remove poor-man's RTTI in PhysicalFontFace
The *only* things relying on the in-built magic number are PDFFontCache and PDFWriterImpl. PDFWriterImpl::emitBuiltinFont has as its first parameter a const PhysicalFontFace*, but this is only called upon by PDFWriterImpl::emitFonts, which instantiates an ImplPdfBuiltinFontData object from a built-in font map... so basically it is always guaranteed to get a ImplPdfBuiltinFontData object. ImplPdfBuiltinFontData derives from PhysicalFontFace, so to prevent the need to check the class being used is a ImplPdfBuiltinFontData, just make emitBuiltinFont require as it's first parameter ImplPdfBuiltinFontData! Unfortunately, we can't get around RTTI completely, because PDFFontCache::FontIdentifier requires a way of distinguishing between two different PhysicalFontFaces... Change-Id: I74c8cd294580bbecd12dd2427ac405f97a7e7f7e Reviewed-on: https://gerrit.libreoffice.org/21030 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
-rw-r--r--vcl/generic/glyphs/gcach_ftyp.cxx2
-rw-r--r--vcl/generic/glyphs/gcach_ftyp.hxx1
-rw-r--r--vcl/generic/print/genpspgraphics.cxx3
-rw-r--r--vcl/inc/PhysicalFontFace.hxx12
-rw-r--r--vcl/quartz/salgdi.cxx2
-rw-r--r--vcl/source/font/PhysicalFontFace.cxx3
-rw-r--r--vcl/source/gdi/pdffontcache.cxx6
-rw-r--r--vcl/source/gdi/pdffontcache.hxx14
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx28
-rw-r--r--vcl/source/gdi/pdfwriter_impl.hxx19
-rw-r--r--vcl/win/gdi/salgdi3.cxx2
11 files changed, 43 insertions, 49 deletions
diff --git a/vcl/generic/glyphs/gcach_ftyp.cxx b/vcl/generic/glyphs/gcach_ftyp.cxx
index f5b4a0d3ca1c..a570548feb1b 100644
--- a/vcl/generic/glyphs/gcach_ftyp.cxx
+++ b/vcl/generic/glyphs/gcach_ftyp.cxx
@@ -420,7 +420,7 @@ ServerFont* FreetypeManager::CreateFont( const FontSelectPattern& rFSD )
}
ImplFTSFontData::ImplFTSFontData( FtFontInfo* pFI, const ImplFontAttributes& rDFA )
-: PhysicalFontFace( rDFA, IFTSFONT_MAGIC ),
+: PhysicalFontFace( rDFA ),
mpFtFontInfo( pFI )
{
SetBuiltInFontFlag( false );
diff --git a/vcl/generic/glyphs/gcach_ftyp.hxx b/vcl/generic/glyphs/gcach_ftyp.hxx
index 1fe995ae0169..32777770db03 100644
--- a/vcl/generic/glyphs/gcach_ftyp.hxx
+++ b/vcl/generic/glyphs/gcach_ftyp.hxx
@@ -150,7 +150,6 @@ class ImplFTSFontData : public PhysicalFontFace
{
private:
FtFontInfo* mpFtFontInfo;
- enum { IFTSFONT_MAGIC = 0x1F150A1C };
public:
ImplFTSFontData( FtFontInfo*, const ImplFontAttributes& );
diff --git a/vcl/generic/print/genpspgraphics.cxx b/vcl/generic/print/genpspgraphics.cxx
index 207e41428b2a..f687ba28fea2 100644
--- a/vcl/generic/print/genpspgraphics.cxx
+++ b/vcl/generic/print/genpspgraphics.cxx
@@ -542,7 +542,6 @@ void GenPspGraphics::invert(long,long,long,long,SalInvert)
class ImplPspFontData : public PhysicalFontFace
{
private:
- enum { PSPFD_MAGIC = 0xb5bf01f0 };
sal_IntPtr mnFontId;
public:
@@ -553,7 +552,7 @@ public:
};
ImplPspFontData::ImplPspFontData( const psp::FastPrintFontInfo& rInfo )
-: PhysicalFontFace( GenPspGraphics::Info2FontAttributes(rInfo), PSPFD_MAGIC ),
+: PhysicalFontFace( GenPspGraphics::Info2FontAttributes(rInfo) ),
mnFontId( rInfo.m_nID )
{}
diff --git a/vcl/inc/PhysicalFontFace.hxx b/vcl/inc/PhysicalFontFace.hxx
index bb0b9002d36b..06a8fe23d1f2 100644
--- a/vcl/inc/PhysicalFontFace.hxx
+++ b/vcl/inc/PhysicalFontFace.hxx
@@ -66,33 +66,29 @@ public:
class VCL_PLUGIN_PUBLIC PhysicalFontFace : public ImplFontAttributes
{
public:
+ virtual ~PhysicalFontFace() {}
+
// by using an PhysicalFontFace object as a factory for its corresponding
// ImplFontEntry an ImplFontEntry can be extended to cache device and
// font instance specific data
virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const = 0;
+ virtual PhysicalFontFace* Clone() const = 0;
int GetHeight() const { return mnHeight; }
int GetWidth() const { return mnWidth; }
virtual sal_IntPtr GetFontId() const = 0;
- int GetFontMagic() const { return mnMagic; }
bool IsScalable() const { return (mnHeight == 0); }
- bool CheckMagic( int n ) const { return (n == mnMagic); }
bool IsBetterMatch( const FontSelectPattern&, FontMatchStatus& ) const;
sal_Int32 CompareWithSize( const PhysicalFontFace& ) const;
sal_Int32 CompareIgnoreSize( const PhysicalFontFace& ) const;
- virtual ~PhysicalFontFace() {}
- virtual PhysicalFontFace* Clone() const = 0;
protected:
- explicit PhysicalFontFace( const ImplFontAttributes&, int nMagic );
+ explicit PhysicalFontFace( const ImplFontAttributes& );
void SetBitmapSize( int nW, int nH ) { mnWidth=nW; mnHeight=nH; }
long mnWidth; // Width (in pixels)
long mnHeight; // Height (in pixels)
-
-private:
- const int mnMagic; // poor man's RTTI
};
#endif // INCLUDED_VCL_INC_PHYSICALFONTFACE_HXX
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 0619b54e60df..bfff1fd79554 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -64,7 +64,7 @@ CoreTextFontData::CoreTextFontData( const CoreTextFontData& rSrc )
}
CoreTextFontData::CoreTextFontData( const ImplFontAttributes& rDFA, sal_IntPtr nFontId )
- : PhysicalFontFace( rDFA, 0 )
+ : PhysicalFontFace( rDFA )
, mnFontId( nFontId )
, mbOs2Read( false )
, mbHasOs2Table( false )
diff --git a/vcl/source/font/PhysicalFontFace.cxx b/vcl/source/font/PhysicalFontFace.cxx
index c7c7ee283ab4..7bebc992297b 100644
--- a/vcl/source/font/PhysicalFontFace.cxx
+++ b/vcl/source/font/PhysicalFontFace.cxx
@@ -25,11 +25,10 @@
#include "PhysicalFontFace.hxx"
-PhysicalFontFace::PhysicalFontFace( const ImplFontAttributes& rDFA, int nMagic )
+PhysicalFontFace::PhysicalFontFace( const ImplFontAttributes& rDFA )
: ImplFontAttributes( rDFA )
, mnWidth(0)
, mnHeight(0)
- , mnMagic( nMagic )
{
// StarSymbol is a unicode font, but it still deserves the symbol flag
if( !IsSymbolFont() )
diff --git a/vcl/source/gdi/pdffontcache.cxx b/vcl/source/gdi/pdffontcache.cxx
index ccb131dd7cc9..68ede0bd676e 100644
--- a/vcl/source/gdi/pdffontcache.cxx
+++ b/vcl/source/gdi/pdffontcache.cxx
@@ -17,6 +17,8 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <typeinfo>
+
#include <sal/types.h>
#include "outfont.hxx"
@@ -30,8 +32,8 @@ using namespace vcl;
PDFFontCache::FontIdentifier::FontIdentifier( const PhysicalFontFace* pFont, bool bVertical ) :
m_nFontId( pFont->GetFontId() ),
- m_nMagic( pFont->GetFontMagic() ),
- m_bVertical( bVertical )
+ m_bVertical( bVertical ),
+ m_typeFontFace( const_cast<std::type_info*>(&typeid(pFont)) )
{
}
diff --git a/vcl/source/gdi/pdffontcache.hxx b/vcl/source/gdi/pdffontcache.hxx
index 88229e293379..8192bf1dbc80 100644
--- a/vcl/source/gdi/pdffontcache.hxx
+++ b/vcl/source/gdi/pdffontcache.hxx
@@ -20,6 +20,8 @@
#ifndef INCLUDED_VCL_SOURCE_GDI_PDFFONTCACHE_HXX
#define INCLUDED_VCL_SOURCE_GDI_PDFFONTCACHE_HXX
+#include <typeinfo>
+
#include <sal/types.h>
#include <sallayout.hxx>
@@ -32,22 +34,26 @@ namespace vcl
struct FontIdentifier
{
sal_IntPtr m_nFontId;
- int m_nMagic;
bool m_bVertical;
+ std::type_info* m_typeFontFace;
FontIdentifier( const PhysicalFontFace*, bool bVertical );
- FontIdentifier() : m_nFontId(0), m_nMagic(0), m_bVertical( false ) {}
+ FontIdentifier() : m_nFontId(0), m_bVertical( false ) {}
bool operator==( const FontIdentifier& rRight ) const
{
return m_nFontId == rRight.m_nFontId &&
- m_nMagic == rRight.m_nMagic &&
+ m_typeFontFace == rRight.m_typeFontFace &&
m_bVertical == rRight.m_bVertical;
}
+
+ // Less than needed for std::set and std::map
bool operator<( const FontIdentifier& rRight ) const
{
+ std::type_info *pType = rRight.m_typeFontFace;
+
return m_nFontId < rRight.m_nFontId ||
- m_nMagic < rRight.m_nMagic ||
+ m_typeFontFace->before( *pType ) ||
m_bVertical < rRight.m_bVertical;
}
};
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 9e8428f372a9..9ccdbd091125 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -2239,29 +2239,6 @@ OutputDevice* PDFWriterImpl::getReferenceDevice()
return m_pReferenceDevice;
}
-class ImplPdfBuiltinFontData : public PhysicalFontFace
-{
-private:
- const PDFWriterImpl::BuiltinFont& mrBuiltin;
-
-public:
- static int const PDF_FONT_MAGIC = int(0xBDFF0A1C);
- explicit ImplPdfBuiltinFontData( const PDFWriterImpl::BuiltinFont& );
- const PDFWriterImpl::BuiltinFont& GetBuiltinFont() const { return mrBuiltin; }
-
- virtual PhysicalFontFace* Clone() const override { return new ImplPdfBuiltinFontData(*this); }
- virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const override;
- virtual sal_IntPtr GetFontId() const override { return reinterpret_cast<sal_IntPtr>(&mrBuiltin); }
-};
-
-inline const ImplPdfBuiltinFontData* GetPdfFontData( const PhysicalFontFace* pFontData )
-{
- const ImplPdfBuiltinFontData* pFD = nullptr;
- if( pFontData && pFontData->CheckMagic( ImplPdfBuiltinFontData::PDF_FONT_MAGIC ) )
- pFD = static_cast<const ImplPdfBuiltinFontData*>( pFontData );
- return pFD;
-}
-
static ImplFontAttributes GetDevFontAttributes( const PDFWriterImpl::BuiltinFont& rBuiltin )
{
ImplFontAttributes aDFA;
@@ -2283,7 +2260,7 @@ static ImplFontAttributes GetDevFontAttributes( const PDFWriterImpl::BuiltinFont
}
ImplPdfBuiltinFontData::ImplPdfBuiltinFontData( const PDFWriterImpl::BuiltinFont& rBuiltin )
-: PhysicalFontFace( GetDevFontAttributes(rBuiltin), PDF_FONT_MAGIC ),
+: PhysicalFontFace( GetDevFontAttributes(rBuiltin) ),
mrBuiltin( rBuiltin )
{}
@@ -2938,9 +2915,8 @@ bool PDFWriterImpl::emitTilings()
return true;
}
-sal_Int32 PDFWriterImpl::emitBuiltinFont( const PhysicalFontFace* pFont, sal_Int32 nFontObject )
+sal_Int32 PDFWriterImpl::emitBuiltinFont( const ImplPdfBuiltinFontData* pFD, sal_Int32 nFontObject )
{
- const ImplPdfBuiltinFontData* pFD = GetPdfFontData( pFont );
if( !pFD )
return 0;
const BuiltinFont& rBuiltinFont = pFD->GetBuiltinFont();
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index 542b2b512629..7d81df8b4311 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -43,6 +43,7 @@
#include "sallayout.hxx"
#include "outdata.hxx"
#include "pdffontcache.hxx"
+#include "PhysicalFontFace.hxx"
class StyleSettings;
class FontSelectPattern;
@@ -70,6 +71,7 @@ namespace vcl
class PDFStreamIf;
class Matrix3;
+class ImplPdfBuiltinFontData;
class PDFWriterImpl
{
@@ -833,7 +835,7 @@ i12626
/* writes all gradient patterns */
bool emitGradients();
/* writes a builtin font object and returns its objectid (or 0 in case of failure ) */
- sal_Int32 emitBuiltinFont( const PhysicalFontFace*, sal_Int32 nObject = -1 );
+ sal_Int32 emitBuiltinFont( const ImplPdfBuiltinFontData*, sal_Int32 nObject = -1 );
/* writes a type1 embedded font object and returns its mapping from font ids to object ids (or 0 in case of failure ) */
std::map< sal_Int32, sal_Int32 > emitEmbeddedFont( const PhysicalFontFace*, EmbedFont& );
/* writes a type1 system font object and returns its mapping from font ids to object ids (or 0 in case of failure ) */
@@ -1254,6 +1256,21 @@ public:
}
};
+class ImplPdfBuiltinFontData : public PhysicalFontFace
+{
+private:
+ const PDFWriterImpl::BuiltinFont& mrBuiltin;
+
+public:
+ explicit ImplPdfBuiltinFontData( const PDFWriterImpl::BuiltinFont& );
+ const PDFWriterImpl::BuiltinFont& GetBuiltinFont() const { return mrBuiltin; }
+
+ virtual PhysicalFontFace* Clone() const override { return new ImplPdfBuiltinFontData(*this); }
+ virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const override;
+ virtual sal_IntPtr GetFontId() const override { return reinterpret_cast<sal_IntPtr>(&mrBuiltin); }
+};
+
+
}
#endif //_VCL_PDFEXPORT_HXX
diff --git a/vcl/win/gdi/salgdi3.cxx b/vcl/win/gdi/salgdi3.cxx
index 9e290beae7a1..8d69c6026b95 100644
--- a/vcl/win/gdi/salgdi3.cxx
+++ b/vcl/win/gdi/salgdi3.cxx
@@ -995,7 +995,7 @@ const void * GrFontData::getTable(unsigned int name, size_t *len) const
ImplWinFontData::ImplWinFontData( const ImplFontAttributes& rDFS,
int nHeight, BYTE eWinCharSet, BYTE nPitchAndFamily )
-: PhysicalFontFace( rDFS, 0 ),
+: PhysicalFontFace( rDFS ),
mnId( 0 ),
mbHasKoreanRange( false ),
mbHasCJKSupport( false ),