Refactor font substitute removing (vcl/svtools)

+ replace list by vector for maFontSubstList

Change-Id: I4d5668611212358c759fa5cf26f5341311551298
Reviewed-on: https://gerrit.libreoffice.org/43855
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Julien Nabet 2017-10-25 22:58:59 +02:00 committed by Noel Grandin
parent 4130a5c4b0
commit aded98ce3d
4 changed files with 15 additions and 34 deletions

View file

@ -1253,8 +1253,7 @@ public:
static void AddFontSubstitute( const OUString& rFontName,
const OUString& rReplaceFontName,
AddFontSubstituteFlags nFlags );
static void RemoveFontSubstitute( sal_uInt16 n );
static sal_uInt16 GetFontSubstituteCount();
static void RemoveFontsSubstitute();
static vcl::Font GetDefaultFont( DefaultFontType nType,
LanguageType eLang,

View file

@ -161,10 +161,7 @@ void SvtFontSubstConfig::Apply()
OutputDevice::BeginFontSubstitution();
// remove old substitutions
sal_uInt16 nOldCount = OutputDevice::GetFontSubstituteCount();
while (nOldCount)
OutputDevice::RemoveFontSubstitute(--nOldCount);
OutputDevice::RemoveFontsSubstitute();
// read new substitutions
sal_Int32 nCount = IsEnabled() ? SubstitutionCount() : 0;

View file

@ -20,7 +20,6 @@
#ifndef INCLUDED_VCL_INC_OUTDEV_H
#define INCLUDED_VCL_INC_OUTDEV_H
#include <list>
#include <set>
#include <vector>
@ -96,10 +95,10 @@ class ImplDirectFontSubstitution
: public ImplFontSubstitution
{
private:
std::list<ImplFontSubstEntry> maFontSubstList;
std::vector<ImplFontSubstEntry> maFontSubstList;
public:
void AddFontSubstitute( const OUString& rFontName, const OUString& rSubstName, AddFontSubstituteFlags nFlags );
void RemoveFontSubstitute( int nIndex );
void RemoveFontsSubstitute();
int GetFontSubstituteCount() const { return maFontSubstList.size(); };
bool FindFontSubstitute( OUString& rSubstName, const OUString& rFontName ) const;

View file

@ -708,45 +708,31 @@ ImplFontSubstEntry::ImplFontSubstEntry( const OUString& rFontName,
maSearchReplaceName = GetEnglishSearchFontName( rSubstFontName );
}
void OutputDevice::RemoveFontSubstitute( sal_uInt16 n )
void OutputDevice::RemoveFontsSubstitute()
{
ImplDirectFontSubstitution* pSubst = ImplGetSVData()->maGDIData.mpDirectFontSubst;
if( pSubst )
pSubst->RemoveFontSubstitute( n );
pSubst->RemoveFontsSubstitute();
}
void ImplDirectFontSubstitution::RemoveFontSubstitute( int nIndex )
void ImplDirectFontSubstitution::RemoveFontsSubstitute()
{
std::list<ImplFontSubstEntry>::iterator it = maFontSubstList.begin();
for( int nCount = 0; (it != maFontSubstList.end()) && (nCount++ != nIndex); ++it ) ;
if( it != maFontSubstList.end() )
maFontSubstList.erase( it );
}
sal_uInt16 OutputDevice::GetFontSubstituteCount()
{
const ImplDirectFontSubstitution* pSubst = ImplGetSVData()->maGDIData.mpDirectFontSubst;
if( !pSubst )
return 0;
int nCount = pSubst->GetFontSubstituteCount();
return (sal_uInt16)nCount;
maFontSubstList.clear();
}
bool ImplDirectFontSubstitution::FindFontSubstitute( OUString& rSubstName,
const OUString& rSearchName ) const
{
// TODO: get rid of O(N) searches
std::list<ImplFontSubstEntry>::const_iterator it = maFontSubstList.begin();
for(; it != maFontSubstList.end(); ++it )
std::vector<ImplFontSubstEntry>::const_iterator it = std::find_if (
maFontSubstList.begin(), maFontSubstList.end(),
[&] (const ImplFontSubstEntry& s) { return (s.mnFlags & AddFontSubstituteFlags::ALWAYS)
&& (s.maSearchName == rSearchName); } );
if (it != maFontSubstList.end())
{
const ImplFontSubstEntry& rEntry = *it;
if( (rEntry.mnFlags & AddFontSubstituteFlags::ALWAYS) && rEntry.maSearchName == rSearchName )
{
rSubstName = rEntry.maSearchReplaceName;
return true;
}
rSubstName = it->maSearchReplaceName;
return true;
}
return false;
}