summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorKhaled Hosny <khaledhosny@eglug.org>2016-12-02 05:45:58 +0200
committerKhaled Hosny <khaledhosny@eglug.org>2016-12-02 17:11:43 +0000
commit5d7a1ddf36eb0774a3d11e9c0dba59562d3e0c11 (patch)
tree42ce6f7ee121395f1ed981858c7a9308b4cc3fc1 /vcl
parent1f8a70262ad99668210d9d6a128efd8382f63dd5 (diff)
Simplify FontManager a bit
There does not seem to be any need for that atom thing as we are perfectly happy using plain OUStrings in the same struct, not to mention that font names are supposed to be unique so I don’t see what we are saving here. As this was the only use for unotools/atom, it goes with it. Change-Id: If9d58d84fff0403f9b2c41fe594b99028b30c2f4 Reviewed-on: https://gerrit.libreoffice.org/31520 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Khaled Hosny <khaledhosny@eglug.org>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/unx/fontmanager.hxx16
-rw-r--r--vcl/unx/generic/fontmanager/fontconfig.cxx5
-rw-r--r--vcl/unx/generic/fontmanager/fontmanager.cxx62
3 files changed, 27 insertions, 56 deletions
diff --git a/vcl/inc/unx/fontmanager.hxx b/vcl/inc/unx/fontmanager.hxx
index 9c05f431e319..d922301031d1 100644
--- a/vcl/inc/unx/fontmanager.hxx
+++ b/vcl/inc/unx/fontmanager.hxx
@@ -36,16 +36,11 @@
#include "config_dbus.h"
-#define ATOM_FAMILYNAME 2
-#define ATOM_PSNAME 3
-
/*
* some words on metrics: every length returned by PrintFontManager and
* friends are PostScript afm style, that is they are 1/1000 font height
*/
-namespace utl { class MultiAtomProvider; }
-
class FontSubsetInfo;
class FontConfigFontOptions;
class FontSelectPattern;
@@ -128,10 +123,11 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
struct PrintFont
{
// font attributes
- int m_nFamilyName; // atom
- std::vector<int> m_aAliases;
- int m_nPSName; // atom
+ OUString m_aFamilyName;
+ std::vector<OUString> m_aAliases;
+ OUString m_aPSName;
OUString m_aStyleName;
+ FontFamily m_eFamilyStyle;
FontItalic m_eItalic;
FontWidth m_eWidth;
FontWeight m_eWeight;
@@ -158,8 +154,6 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
fontID m_nNextFontID;
std::unordered_map< fontID, PrintFont* > m_aFonts;
- std::unordered_map< int, FontFamily > m_aFamilyTypes;
- utl::MultiAtomProvider* m_pAtoms;
// for speeding up findFontFileID
std::unordered_map< OString, std::set< fontID >, OStringHash >
m_aFontFileToFontID;
@@ -190,7 +184,7 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
it = m_aFonts.find( nID );
return it == m_aFonts.end() ? nullptr : it->second;
}
- void fillPrintFontInfo( PrintFont* pFont, FastPrintFontInfo& rInfo ) const;
+ static void fillPrintFontInfo(PrintFont* pFont, FastPrintFontInfo& rInfo);
void fillPrintFontInfo( PrintFont* pFont, PrintFontInfo& rInfo ) const;
OString getDirectory( int nAtom ) const;
diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx b/vcl/unx/generic/fontmanager/fontconfig.cxx
index 217ac0f3eb62..3c594f545f31 100644
--- a/vcl/unx/generic/fontmanager/fontconfig.cxx
+++ b/vcl/unx/generic/fontmanager/fontconfig.cxx
@@ -44,7 +44,6 @@ using namespace psp;
#include <cstdio>
#include <cstdarg>
-#include <unotools/atom.hxx>
#include <unotools/configmgr.hxx>
#include "osl/module.h"
@@ -579,7 +578,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS
continue;
}
- int nFamilyName = m_pAtoms->getAtom( ATOM_FAMILYNAME, OStringToOUString( OString( reinterpret_cast<char*>(family) ), RTL_TEXTENCODING_UTF8 ) );
+ OUString aFamilyName = OStringToOUString(OString(reinterpret_cast<char*>(family)), RTL_TEXTENCODING_UTF8);
PrintFont* pUpdate = aFonts.front();
std::list<PrintFont*>::const_iterator second_font = aFonts.begin();
++second_font;
@@ -617,7 +616,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS
if( pUpdate )
{
// set family name
- if( pUpdate->m_nFamilyName != nFamilyName )
+ if( pUpdate->m_aFamilyName != aFamilyName )
{
}
if( eWeightRes == FcResultMatch )
diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx
index 612aa975a600..8a3af665c29e 100644
--- a/vcl/unx/generic/fontmanager/fontmanager.cxx
+++ b/vcl/unx/generic/fontmanager/fontmanager.cxx
@@ -23,8 +23,6 @@
#include <stdlib.h>
#include <osl/thread.h>
-#include "unotools/atom.hxx"
-
#include "unx/fontmanager.hxx"
#include "fontsubset.hxx"
#include "impfontcharmap.hxx"
@@ -95,8 +93,7 @@ inline sal_uInt16 getUInt16BE( const sal_uInt8*& pBuffer )
* PrintFont implementations
*/
PrintFontManager::PrintFont::PrintFont()
-: m_nFamilyName(0)
-, m_nPSName(0)
+: m_eFamilyStyle(FAMILY_DONTKNOW)
, m_eItalic(ITALIC_DONTKNOW)
, m_eWidth(WIDTH_DONTKNOW)
, m_eWeight(WEIGHT_DONTKNOW)
@@ -137,7 +134,6 @@ PrintFontManager& PrintFontManager::get()
PrintFontManager::PrintFontManager()
: m_nNextFontID( 1 )
- , m_pAtoms( new MultiAtomProvider() )
, m_nNextDirAtom( 1 )
{
#if ENABLE_DBUS
@@ -152,7 +148,6 @@ PrintFontManager::~PrintFontManager()
deinitFontconfig();
for( std::unordered_map< fontID, PrintFont* >::const_iterator it = m_aFonts.begin(); it != m_aFonts.end(); ++it )
delete (*it).second;
- delete m_pAtoms;
}
OString PrintFontManager::getDirectory( int nAtom ) const
@@ -586,11 +581,11 @@ bool PrintFontManager::analyzeSfntFile( PrintFont* pFont ) const
analyzeSfntFamilyName( pTTFont, aNames );
// set family name from XLFD if possible
- if( ! pFont->m_nFamilyName )
+ if (pFont->m_aFamilyName.isEmpty())
{
if( !aNames.empty() )
{
- pFont->m_nFamilyName = m_pAtoms->getAtom( ATOM_FAMILYNAME, aNames.front() );
+ pFont->m_aFamilyName = aNames.front();
aNames.pop_front();
}
else
@@ -603,20 +598,18 @@ bool PrintFontManager::analyzeSfntFile( PrintFont* pFont ) const
if ( dotIndex == -1 )
dotIndex = pFont->m_aFontFile.getLength();
- pFont->m_nFamilyName = m_pAtoms->getAtom( ATOM_FAMILYNAME, OStringToOUString( pFont->m_aFontFile.copy( 0, dotIndex ), aEncoding ) );
+ pFont->m_aFamilyName = OStringToOUString(pFont->m_aFontFile.copy(0, dotIndex), aEncoding);
}
}
- for( ::std::list< OUString >::iterator it = aNames.begin(); it != aNames.end(); ++it )
+ for (auto const& aAlias : aNames)
{
- if( !it->isEmpty() )
+ if (!aAlias.isEmpty())
{
- int nAlias = m_pAtoms->getAtom( ATOM_FAMILYNAME, *it );
- if( nAlias != pFont->m_nFamilyName )
+ if (pFont->m_aFamilyName != aAlias)
{
- std::vector< int >::const_iterator al_it =
- std::find( pFont->m_aAliases.begin(), pFont->m_aAliases.end(), nAlias );
+ auto al_it = std::find(pFont->m_aAliases.begin(), pFont->m_aAliases.end(), aAlias);
if( al_it == pFont->m_aAliases.end() )
- pFont->m_aAliases.push_back( nAlias );
+ pFont->m_aAliases.push_back(aAlias);
}
}
}
@@ -626,11 +619,11 @@ bool PrintFontManager::analyzeSfntFile( PrintFont* pFont ) const
SAL_WARN_IF( !aInfo.psname, "vcl", "No PostScript name in font:" << aFile.getStr() );
- OUString sPSName = aInfo.psname ?
+ pFont->m_aPSName = aInfo.psname ?
OUString(aInfo.psname, rtl_str_getLength(aInfo.psname), aEncoding) :
- m_pAtoms->getString(ATOM_FAMILYNAME, pFont->m_nFamilyName); // poor font does not have a postscript name
+ pFont->m_aFamilyName; // poor font does not have a postscript name
- pFont->m_nPSName = m_pAtoms->getAtom( ATOM_PSNAME, sPSName );
+ pFont->m_eFamilyStyle = matchFamilyName(pFont->m_aFamilyName);
switch( aInfo.weight )
{
@@ -788,20 +781,6 @@ void PrintFontManager::initialize()
aStep1 = times( &tms );
#endif
- // part three - fill in family styles
- std::unordered_map< fontID, PrintFont* >::iterator font_it;
- for (font_it = m_aFonts.begin(); font_it != m_aFonts.end(); ++font_it)
- {
- std::unordered_map< int, FontFamily >::const_iterator it =
- m_aFamilyTypes.find( font_it->second->m_nFamilyName );
- if (it != m_aFamilyTypes.end())
- continue;
- const OUString& rFamily =
- m_pAtoms->getString( ATOM_FAMILYNAME, font_it->second->m_nFamilyName);
- FontFamily eType = matchFamilyName( rFamily );
- m_aFamilyTypes[ font_it->second->m_nFamilyName ] = eType;
- }
-
#if OSL_DEBUG_LEVEL > 1
aStep2 = times( &tms );
fprintf( stderr, "PrintFontManager::initialize: collected %" SAL_PRI_SIZET "u fonts\n", m_aFonts.size() );
@@ -825,13 +804,11 @@ void PrintFontManager::getFontList( ::std::list< fontID >& rFontIDs )
rFontIDs.push_back( it->first );
}
-void PrintFontManager::fillPrintFontInfo( PrintFont* pFont, FastPrintFontInfo& rInfo ) const
+void PrintFontManager::fillPrintFontInfo(PrintFont* pFont, FastPrintFontInfo& rInfo)
{
- std::unordered_map< int, FontFamily >::const_iterator style_it =
- m_aFamilyTypes.find( pFont->m_nFamilyName );
- rInfo.m_aFamilyName = m_pAtoms->getString( ATOM_FAMILYNAME, pFont->m_nFamilyName );
+ rInfo.m_aFamilyName = pFont->m_aFamilyName;
rInfo.m_aStyleName = pFont->m_aStyleName;
- rInfo.m_eFamilyStyle = style_it != m_aFamilyTypes.end() ? style_it->second : FAMILY_DONTKNOW;
+ rInfo.m_eFamilyStyle = pFont->m_eFamilyStyle;
rInfo.m_eItalic = pFont->m_eItalic;
rInfo.m_eWidth = pFont->m_eWidth;
rInfo.m_eWeight = pFont->m_eWeight;
@@ -841,8 +818,8 @@ void PrintFontManager::fillPrintFontInfo( PrintFont* pFont, FastPrintFontInfo& r
rInfo.m_bSubsettable = true;
rInfo.m_aAliases.clear();
- for( int i : pFont->m_aAliases )
- rInfo.m_aAliases.push_back( m_pAtoms->getString( ATOM_FAMILYNAME, i ) );
+ for (auto const& aAlias : pFont->m_aAliases)
+ rInfo.m_aAliases.push_back(aAlias);
}
void PrintFontManager::fillPrintFontInfo( PrintFont* pFont, PrintFontInfo& rInfo ) const
@@ -992,13 +969,14 @@ OString PrintFontManager::getFontFile( PrintFont* pFont ) const
const OUString& PrintFontManager::getPSName( fontID nFontID ) const
{
+ static OUString aEmpty;
PrintFont* pFont = getFont( nFontID );
- if( pFont && pFont->m_nPSName == 0 )
+ if (pFont && pFont->m_aPSName.isEmpty())
{
analyzeSfntFile(pFont);
}
- return m_pAtoms->getString( ATOM_PSNAME, pFont ? pFont->m_nPSName : INVALID_ATOM );
+ return pFont ? pFont->m_aPSName : aEmpty;
}
int PrintFontManager::getFontAscend( fontID nFontID ) const