Re-factoring: Avoid pointless class derivation

No need to hide stuff from ourselves at multiple levels. Rename the
CoreText-specific ImplMacTextStyle class to CoreTextStyle and unify it
with its sole derived class CTTextStyle. This is all internal to vcl
anyway.

Change-Id: Ib9e632ccba5c273200d4e3fce79a97db305c6662
This commit is contained in:
Tor Lillqvist
2013-11-28 22:27:26 +02:00
parent f562ec13d0
commit cb17d9392b
6 changed files with 48 additions and 79 deletions

View File

@@ -64,8 +64,10 @@ inline double toRadian(int nDegree)
return nDegree * (M_PI / 1800.0); return nDegree * (M_PI / 1800.0);
} }
CTTextStyle::CTTextStyle( const FontSelectPattern& rFSD ) CoreTextStyle::CoreTextStyle( const FontSelectPattern& rFSD )
: ImplMacTextStyle( rFSD ) : mpFontData( (ImplMacFontData*)rFSD.mpFontData )
, mfFontStretch( 1.0 )
, mfFontRotation( 0.0 )
, mpStyleDict( NULL ) , mpStyleDict( NULL )
{ {
mpFontData = (CTFontData*)rFSD.mpFontData; mpFontData = (CTFontData*)rFSD.mpFontData;
@@ -125,7 +127,7 @@ CTTextStyle::CTTextStyle( const FontSelectPattern& rFSD )
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
CTTextStyle::~CTTextStyle( void ) CoreTextStyle::~CoreTextStyle( void )
{ {
if( mpStyleDict ) if( mpStyleDict )
CFRelease( mpStyleDict ); CFRelease( mpStyleDict );
@@ -133,7 +135,7 @@ CTTextStyle::~CTTextStyle( void )
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
void CTTextStyle::GetFontMetric( float fPixelSize, ImplFontMetricData& rMetric ) const void CoreTextStyle::GetFontMetric( float fPixelSize, ImplFontMetricData& rMetric ) const
{ {
// get the matching CoreText font handle // get the matching CoreText font handle
// TODO: is it worth it to cache the CTFontRef in SetFont() and reuse it here? // TODO: is it worth it to cache the CTFontRef in SetFont() and reuse it here?
@@ -155,7 +157,7 @@ void CTTextStyle::GetFontMetric( float fPixelSize, ImplFontMetricData& rMetric )
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
bool CTTextStyle::GetGlyphBoundRect( sal_GlyphId nGlyphId, Rectangle& rRect ) const bool CoreTextStyle::GetGlyphBoundRect( sal_GlyphId nGlyphId, Rectangle& rRect ) const
{ {
CGGlyph nCGGlyph = nGlyphId & GF_IDXMASK; CGGlyph nCGGlyph = nGlyphId & GF_IDXMASK;
// XXX: this is broken if the glyph came from fallback font // XXX: this is broken if the glyph came from fallback font
@@ -213,7 +215,7 @@ static void MyCGPathApplierFunc( void* pData, const CGPathElement* pElement )
} }
} }
bool CTTextStyle::GetGlyphOutline( sal_GlyphId nGlyphId, basegfx::B2DPolyPolygon& rResult ) const bool CoreTextStyle::GetGlyphOutline( sal_GlyphId nGlyphId, basegfx::B2DPolyPolygon& rResult ) const
{ {
rResult.clear(); rResult.clear();
@@ -235,7 +237,7 @@ bool CTTextStyle::GetGlyphOutline( sal_GlyphId nGlyphId, basegfx::B2DPolyPolygon
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
void CTTextStyle::SetTextColor( const RGBAColor& rColor ) void CoreTextStyle::SetTextColor( const RGBAColor& rColor )
{ {
CGFloat aColor[] = { rColor.GetRed(), rColor.GetGreen(), rColor.GetBlue(), rColor.GetAlpha() }; CGFloat aColor[] = { rColor.GetRed(), rColor.GetGreen(), rColor.GetBlue(), rColor.GetAlpha() };
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
@@ -267,9 +269,9 @@ PhysicalFontFace* CTFontData::Clone( void ) const
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
ImplMacTextStyle* CTFontData::CreateMacTextStyle( const FontSelectPattern& rFSD ) const CoreTextStyle* CTFontData::CreateTextStyle( const FontSelectPattern& rFSD ) const
{ {
return new CTTextStyle( rFSD); return new CoreTextStyle( rFSD);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View File

@@ -23,29 +23,6 @@
#endif #endif
#include "sallayout.hxx" #include "sallayout.hxx"
class CTTextStyle
: public ImplMacTextStyle
{
public:
explicit CTTextStyle( const FontSelectPattern& );
virtual ~CTTextStyle( void );
virtual SalLayout* GetTextLayout( void ) const;
virtual void GetFontMetric( float fDPIY, ImplFontMetricData& ) const;
virtual bool GetGlyphBoundRect( sal_GlyphId, Rectangle& ) const;
virtual bool GetGlyphOutline( sal_GlyphId, basegfx::B2DPolyPolygon& ) const;
virtual void SetTextColor( const RGBAColor& );
private:
/// CoreText text style object
CFMutableDictionaryRef mpStyleDict;
friend class CTLayout;
CFMutableDictionaryRef GetStyleDict( void ) const { return mpStyleDict; }
};
// CoreText specific physically available font face // CoreText specific physically available font face
class CTFontData class CTFontData
: public ImplMacFontData : public ImplMacFontData
@@ -56,7 +33,7 @@ public:
virtual ~CTFontData( void ); virtual ~CTFontData( void );
virtual PhysicalFontFace* Clone( void ) const; virtual PhysicalFontFace* Clone( void ) const;
virtual ImplMacTextStyle* CreateMacTextStyle( const FontSelectPattern& ) const; virtual CoreTextStyle* CreateTextStyle( const FontSelectPattern& ) const;
virtual ImplFontEntry* CreateFontInstance( /*const*/ FontSelectPattern& ) const; virtual ImplFontEntry* CreateFontInstance( /*const*/ FontSelectPattern& ) const;
virtual int GetFontTable( const char pTagName[5], unsigned char* ) const; virtual int GetFontTable( const char pTagName[5], unsigned char* ) const;
}; };

View File

@@ -25,7 +25,7 @@ class CTLayout
: public SalLayout : public SalLayout
{ {
public: public:
explicit CTLayout( const CTTextStyle* ); explicit CTLayout( const CoreTextStyle* );
virtual ~CTLayout( void ); virtual ~CTLayout( void );
virtual bool LayoutText( ImplLayoutArgs& ); virtual bool LayoutText( ImplLayoutArgs& );
@@ -52,7 +52,7 @@ private:
CGPoint GetTextDrawPosition(void) const; CGPoint GetTextDrawPosition(void) const;
double GetWidth(void) const; double GetWidth(void) const;
const CTTextStyle* const mpTextStyle; const CoreTextStyle* const mpTextStyle;
// CoreText specific objects // CoreText specific objects
CFAttributedStringRef mpAttrString; CFAttributedStringRef mpAttrString;
@@ -69,7 +69,7 @@ private:
mutable double mfBaseAdv; mutable double mfBaseAdv;
}; };
CTLayout::CTLayout( const CTTextStyle* pTextStyle ) CTLayout::CTLayout( const CoreTextStyle* pTextStyle )
: mpTextStyle( pTextStyle ) : mpTextStyle( pTextStyle )
, mpAttrString( NULL ) , mpAttrString( NULL )
, mpCTLine( NULL ) , mpCTLine( NULL )
@@ -493,7 +493,7 @@ void CTLayout::MoveGlyph( int /*nStart*/, long /*nNewXPos*/ ) {}
void CTLayout::DropGlyph( int /*nStart*/ ) {} void CTLayout::DropGlyph( int /*nStart*/ ) {}
void CTLayout::Simplify( bool /*bIsBase*/ ) {} void CTLayout::Simplify( bool /*bIsBase*/ ) {}
SalLayout* CTTextStyle::GetTextLayout( void ) const SalLayout* CoreTextStyle::GetTextLayout( void ) const
{ {
return new CTLayout( this); return new CTLayout( this);
} }

View File

@@ -65,19 +65,6 @@ SystemFontList::~SystemFontList( void )
{} {}
// =======================================================================
ImplMacTextStyle::ImplMacTextStyle( const FontSelectPattern& rReqFont )
: mpFontData( (ImplMacFontData*)rReqFont.mpFontData )
, mfFontStretch( 1.0 )
, mfFontRotation( 0.0 )
{}
// -----------------------------------------------------------------------
ImplMacTextStyle::~ImplMacTextStyle( void )
{}
// ======================================================================= // =======================================================================
ImplMacFontData::ImplMacFontData( const ImplMacFontData& rSrc ) ImplMacFontData::ImplMacFontData( const ImplMacFontData& rSrc )
@@ -284,7 +271,7 @@ AquaSalGraphics::AquaSalGraphics()
, maLineColor( COL_WHITE ) , maLineColor( COL_WHITE )
, maFillColor( COL_BLACK ) , maFillColor( COL_BLACK )
, mpMacFontData( NULL ) , mpMacFontData( NULL )
, mpMacTextStyle( NULL ) , mpTextStyle( NULL )
, maTextColor( COL_BLACK ) , maTextColor( COL_BLACK )
, mbNonAntialiasedText( false ) , mbNonAntialiasedText( false )
, mbPrinter( false ) , mbPrinter( false )
@@ -294,7 +281,7 @@ AquaSalGraphics::AquaSalGraphics()
: mrContext( NULL ) : mrContext( NULL )
, mfFakeDPIScale( 1.0 ) , mfFakeDPIScale( 1.0 )
, mpMacFontData( NULL ) , mpMacFontData( NULL )
, mpMacTextStyle( NULL ) , mpTextStyle( NULL )
, maTextColor( COL_BLACK ) , maTextColor( COL_BLACK )
, mbNonAntialiasedText( false ) , mbNonAntialiasedText( false )
#endif #endif
@@ -306,7 +293,7 @@ AquaSalGraphics::~AquaSalGraphics()
{ {
#ifdef MACOSX #ifdef MACOSX
CGPathRelease( mxClipPath ); CGPathRelease( mxClipPath );
delete mpMacTextStyle; delete mpTextStyle;
if( mpXorEmulation ) if( mpXorEmulation )
delete mpXorEmulation; delete mpXorEmulation;
@@ -328,15 +315,15 @@ AquaSalGraphics::~AquaSalGraphics()
void AquaSalGraphics::SetTextColor( SalColor nSalColor ) void AquaSalGraphics::SetTextColor( SalColor nSalColor )
{ {
maTextColor = RGBAColor( nSalColor ); maTextColor = RGBAColor( nSalColor );
if( mpMacTextStyle) if( mpTextStyle)
mpMacTextStyle->SetTextColor( maTextColor ); mpTextStyle->SetTextColor( maTextColor );
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
void AquaSalGraphics::GetFontMetric( ImplFontMetricData* pMetric, int /*nFallbackLevel*/ ) void AquaSalGraphics::GetFontMetric( ImplFontMetricData* pMetric, int /*nFallbackLevel*/ )
{ {
mpMacTextStyle->GetFontMetric( mfFakeDPIScale, *pMetric ); mpTextStyle->GetFontMetric( mfFakeDPIScale, *pMetric );
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -435,7 +422,7 @@ bool AquaSalGraphics::AddTempDevFont( ImplDevFontList*,
sal_Bool AquaSalGraphics::GetGlyphOutline( sal_GlyphId nGlyphId, basegfx::B2DPolyPolygon& rPolyPoly ) sal_Bool AquaSalGraphics::GetGlyphOutline( sal_GlyphId nGlyphId, basegfx::B2DPolyPolygon& rPolyPoly )
{ {
const bool bRC = mpMacTextStyle->GetGlyphOutline( nGlyphId, rPolyPoly ); const bool bRC = mpTextStyle->GetGlyphOutline( nGlyphId, rPolyPoly );
return bRC; return bRC;
} }
@@ -443,7 +430,7 @@ sal_Bool AquaSalGraphics::GetGlyphOutline( sal_GlyphId nGlyphId, basegfx::B2DPol
sal_Bool AquaSalGraphics::GetGlyphBoundRect( sal_GlyphId nGlyphId, Rectangle& rRect ) sal_Bool AquaSalGraphics::GetGlyphBoundRect( sal_GlyphId nGlyphId, Rectangle& rRect )
{ {
const bool bRC = mpMacTextStyle->GetGlyphBoundRect( nGlyphId, rRect ); const bool bRC = mpTextStyle->GetGlyphBoundRect( nGlyphId, rRect );
return bRC; return bRC;
} }
@@ -465,8 +452,8 @@ void AquaSalGraphics::DrawServerFontLayout( const ServerFontLayout& )
sal_uInt16 AquaSalGraphics::SetFont( FontSelectPattern* pReqFont, int /*nFallbackLevel*/ ) sal_uInt16 AquaSalGraphics::SetFont( FontSelectPattern* pReqFont, int /*nFallbackLevel*/ )
{ {
// release the text style // release the text style
delete mpMacTextStyle; delete mpTextStyle;
mpMacTextStyle = NULL; mpTextStyle = NULL;
// handle NULL request meaning: release-font-resources request // handle NULL request meaning: release-font-resources request
if( !pReqFont ) if( !pReqFont )
@@ -477,8 +464,8 @@ sal_uInt16 AquaSalGraphics::SetFont( FontSelectPattern* pReqFont, int /*nFallbac
// update the text style // update the text style
mpMacFontData = static_cast<const ImplMacFontData*>( pReqFont->mpFontData ); mpMacFontData = static_cast<const ImplMacFontData*>( pReqFont->mpFontData );
mpMacTextStyle = mpMacFontData->CreateMacTextStyle( *pReqFont ); mpTextStyle = mpMacFontData->CreateTextStyle( *pReqFont );
mpMacTextStyle->SetTextColor( maTextColor ); mpTextStyle->SetTextColor( maTextColor );
SAL_INFO("vcl.coretext", SAL_INFO("vcl.coretext",
"SetFont" "SetFont"
@@ -500,7 +487,7 @@ sal_uInt16 AquaSalGraphics::SetFont( FontSelectPattern* pReqFont, int /*nFallbac
SalLayout* AquaSalGraphics::GetTextLayout( ImplLayoutArgs& /*rArgs*/, int /*nFallbackLevel*/ ) SalLayout* AquaSalGraphics::GetTextLayout( ImplLayoutArgs& /*rArgs*/, int /*nFallbackLevel*/ )
{ {
SalLayout* pSalLayout = mpMacTextStyle->GetTextLayout(); SalLayout* pSalLayout = mpTextStyle->GetTextLayout();
return pSalLayout; return pSalLayout;
} }

View File

@@ -44,7 +44,7 @@
class AquaSalFrame; class AquaSalFrame;
class ImplDevFontAttributes; class ImplDevFontAttributes;
class ImplMacTextStyle; class CoreTextStyle;
typedef sal_uInt32 sal_GlyphId; typedef sal_uInt32 sal_GlyphId;
typedef std::vector<unsigned char> ByteVector; typedef std::vector<unsigned char> ByteVector;
@@ -61,7 +61,7 @@ public:
virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const; virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const;
virtual sal_IntPtr GetFontId() const; virtual sal_IntPtr GetFontId() const;
virtual ImplMacTextStyle* CreateMacTextStyle( const FontSelectPattern& ) const = 0; virtual CoreTextStyle* CreateTextStyle( const FontSelectPattern& ) const = 0;
virtual int GetFontTable( const char pTagName[5], unsigned char* ) const = 0; virtual int GetFontTable( const char pTagName[5], unsigned char* ) const = 0;
const ImplFontCharMap* GetImplFontCharMap() const; const ImplFontCharMap* GetImplFontCharMap() const;
@@ -83,29 +83,32 @@ private:
mutable bool mbFontCapabilitiesRead; mutable bool mbFontCapabilitiesRead;
}; };
// -------------------- class CoreTextStyle
// - ImplMacTextStyle -
// --------------------
class ImplMacTextStyle
{ {
public: public:
explicit ImplMacTextStyle( const FontSelectPattern& ); CoreTextStyle( const FontSelectPattern& );
virtual ~ImplMacTextStyle( void ); ~CoreTextStyle( void );
virtual SalLayout* GetTextLayout( void ) const = 0; SalLayout* GetTextLayout( void ) const;
virtual void GetFontMetric( float fPDIY, ImplFontMetricData& ) const = 0; void GetFontMetric( float fPDIY, ImplFontMetricData& ) const;
virtual bool GetGlyphBoundRect( sal_GlyphId, Rectangle& ) const = 0; bool GetGlyphBoundRect( sal_GlyphId, Rectangle& ) const;
virtual bool GetGlyphOutline( sal_GlyphId, basegfx::B2DPolyPolygon& ) const = 0; bool GetGlyphOutline( sal_GlyphId, basegfx::B2DPolyPolygon& ) const;
virtual void SetTextColor( const RGBAColor& ) = 0; void SetTextColor( const RGBAColor& );
//###protected:
const ImplMacFontData* mpFontData; const ImplMacFontData* mpFontData;
/// <1.0: font is squeezed, >1.0 font is stretched, else 1.0 /// <1.0: font is squeezed, >1.0 font is stretched, else 1.0
float mfFontStretch; float mfFontStretch;
/// text rotation in radian /// text rotation in radian
float mfFontRotation; float mfFontRotation;
private:
/// CoreText text style object
CFMutableDictionaryRef mpStyleDict;
friend class CTLayout;
CFMutableDictionaryRef GetStyleDict( void ) const { return mpStyleDict; }
}; };
// ------------------ // ------------------
@@ -158,7 +161,7 @@ protected:
// Device Font settings // Device Font settings
const ImplMacFontData* mpMacFontData; const ImplMacFontData* mpMacFontData;
ImplMacTextStyle* mpMacTextStyle; CoreTextStyle* mpTextStyle;
RGBAColor maTextColor; RGBAColor maTextColor;
/// allows text to be rendered without antialiasing /// allows text to be rendered without antialiasing
bool mbNonAntialiasedText; bool mbNonAntialiasedText;

View File

@@ -90,7 +90,7 @@ protected:
// Device Font settings // Device Font settings
const ImplMacFontData* mpMacFontData; const ImplMacFontData* mpMacFontData;
ImplMacTextStyle* mpMacTextStyle; CoreTextStyle* mpTextStyle;
RGBAColor maTextColor; RGBAColor maTextColor;
/// allows text to be rendered without antialiasing /// allows text to be rendered without antialiasing
bool mbNonAntialiasedText; bool mbNonAntialiasedText;