Kaydet (Commit) 24657548 authored tarafından Khaled Hosny's avatar Khaled Hosny Kaydeden (comit) Caolán McNamara

Don't perform printer font substitution

The so called printer resident fonts is a relic of a bygone era, when
life was simple and there was only ASCII and Type1 fonts.

It is just broken by design these days, offers nothing useful and can go
wrong in many ways. Since 1f3a91cf this
"feature" is disabled by default anyway, so scrap this code to make room
for some long due cleanup.

Change-Id: Id124b2cad1a484099701a885c4d96e6a12af8d9a
Reviewed-on: https://gerrit.libreoffice.org/6858Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 6230cdd2
......@@ -50,24 +50,9 @@ struct PrinterInfo : JobData
// a list of special features separated by ',' not used by psprint
// but assigned from the outside (currently for "fax","pdf=","autoqueue","external_dialog")
OUString m_aFeatures;
// a mapping of fonts to other fonts.
// this provides a method for the user
// to replace arbitrary fonts by printer builtin fonts
// currently this is only a mapping between font names
// assuming that only adbobe standard encoding fonts are
// built into the printer. in future it may be necessary
// to map to a font name and UCS2 vector which should be mapped
// this vector is currently implicitly given by the adobe
// standard encoding
bool m_bPerformFontSubstitution;
boost::unordered_map< OUString, OUString, OUStringHash >
m_aFontSubstitutes;
boost::unordered_map< fontID, fontID >
m_aFontSubstitutions;
PrinterInfo() :
JobData(),
m_bPerformFontSubstitution( false )
JobData()
{}
};
......@@ -133,10 +118,6 @@ protected:
virtual void initialize();
// fill in font substitutions
// the resulting boost::unordered_map maps from source to target font ids
void fillFontSubstitutions( PrinterInfo& rInfo ) const;
// fill default paper if not configured in config file
// default paper is e.g. locale dependent
// if a paper is already set it will not be overwritten
......
......@@ -61,23 +61,6 @@
; if key is absent the default value is driver specific
; PPD_PageSize=A4
; Note: the following two key types are in the global section to provide
; defaults for newly added printers.
; PerformFontSubstitution: whether to replace downloadable fonts
; with resident fonts or not
PerformFontSubstitution=false
; SubstFont_<downloadable font>: the resident font to replace
; <downloadable font> if PerformFontSubstitution is true
SubstFont_Helmet=Helvetica
SubstFont_Albany=Helvetica
SubstFont_Courier New=Courier
SubstFont_Arial=Helvetica
SubstFont_Times New Roman=Times
SubstFont_Thorndale=Times
SubstFont_Timmons=Times
SubstFont_Cumberland=Courier
[Generic Printer]
; for every printer a group with at least the keys
......@@ -114,18 +97,3 @@ Command=
; external_dialog to notify that the print command of a printer will show a dialog
; and therefore the application should not show its own dialog.
;Features=
; PerformFontSubstitution: whether to replace downloadable fonts
; with resident fonts or not
PerformFontSubstitution=false
; SubstFont_<downloadable font>: the resident font to replace
; <downloadable font> if PerformFontSubstitution is true
SubstFont_Helmet=Helvetica
SubstFont_Albany=Helvetica
SubstFont_Courier New=Courier
SubstFont_Arial=Helvetica
SubstFont_Times New Roman=Times
SubstFont_Thorndale=Times
SubstFont_Timmons=Times
SubstFont_Cumberland=Courier
......@@ -60,12 +60,6 @@ PrinterGfx::Init (PrinterJob &rPrinterJob)
mnDpi = rPrinterJob.GetResolution();
rPrinterJob.GetScale (mfScaleX, mfScaleY);
const PrinterInfo& rInfo( PrinterInfoManager::get().getPrinterInfo( rPrinterJob.GetPrinterName() ) );
if( mpFontSubstitutes )
delete const_cast< ::boost::unordered_map<fontID,fontID>* >(mpFontSubstitutes);
if( rInfo.m_bPerformFontSubstitution )
mpFontSubstitutes = new ::boost::unordered_map< fontID, fontID >( rInfo.m_aFontSubstitutions );
else
mpFontSubstitutes = NULL;
mbUploadPS42Fonts = rInfo.m_pParser ? ( rInfo.m_pParser->isType42Capable() ? sal_True : sal_False ) : sal_False;
return sal_True;
......@@ -84,12 +78,6 @@ PrinterGfx::Init (const JobData& rData)
mfScaleX = (double)72.0 / (double)mnDpi;
mfScaleY = (double)72.0 / (double)mnDpi;
const PrinterInfo& rInfo( PrinterInfoManager::get().getPrinterInfo( rData.m_aPrinterName ) );
if( mpFontSubstitutes )
delete const_cast< ::boost::unordered_map<fontID,fontID>* >(mpFontSubstitutes);
if( rInfo.m_bPerformFontSubstitution )
mpFontSubstitutes = new ::boost::unordered_map< fontID, fontID >( rInfo.m_aFontSubstitutions );
else
mpFontSubstitutes = NULL;
mbUploadPS42Fonts = rInfo.m_pParser ? ( rInfo.m_pParser->isType42Capable() ? sal_True : sal_False ) : sal_False;
return sal_True;
......@@ -112,8 +100,7 @@ PrinterGfx::PrinterGfx() :
mbCompressBmp (sal_True),
maFillColor (0xff,0,0),
maTextColor (0,0,0),
maLineColor (0, 0xff, 0),
mpFontSubstitutes( NULL )
maLineColor (0, 0xff, 0)
{
maVirtualStatus.mfLineWidth = 1.0;
maVirtualStatus.mnTextHeight = 12;
......@@ -124,16 +111,6 @@ PrinterGfx::PrinterGfx() :
PrinterGfx::~PrinterGfx()
{
/*
* the original reasoning why mpFontSubstitutes is a pointer was
* that applications should release all PrinterGfx when printers change
* because they are really invalid; the corresponding printers may have
* changed their settings or even not exist anymore.
*
* Alas, this is not always done real time. So we keep a local copy of
* the font substitutes now in case of bad timing.
*/
delete const_cast< ::boost::unordered_map<fontID,fontID>* >(mpFontSubstitutes);
}
void
......
......@@ -912,14 +912,8 @@ void GenPspGraphics::ClearDevFontCache()
GlyphCache::GetInstance().ClearFontCache();
}
void GenPspGraphics::GetDevFontSubstList( OutputDevice* pOutDev )
void GenPspGraphics::GetDevFontSubstList( OutputDevice* )
{
const psp::PrinterInfo& rInfo = psp::PrinterInfoManager::get().getPrinterInfo( m_pJobData->m_aPrinterName );
if( rInfo.m_bPerformFontSubstitution )
{
for( boost::unordered_map< OUString, OUString, OUStringHash >::const_iterator it = rInfo.m_aFontSubstitutes.begin(); it != rInfo.m_aFontSubstitutes.end(); ++it )
pOutDev->ImplAddDevFontSubstitute( it->first, it->second, FONT_SUBSTITUTE_ALWAYS );
}
}
void GenPspGraphics::GetFontMetric( ImplFontMetricData *pMetric, int )
......
......@@ -971,30 +971,24 @@ bool PrinterJob::writeSetup( osl::File* pFile, const JobData& rJob )
WritePS (pFile, "%%BeginSetup\n%\n");
// download fonts
std::list< OString > aFonts[2];
m_pGraphics->writeResources( pFile, aFonts[0], aFonts[1] );
std::list< OString > aFonts;
m_pGraphics->writeResources( pFile, aFonts );
for( int i = 0; i < 2; i++ )
if( !aFonts.empty() )
{
if( !aFonts[i].empty() )
std::list< OString >::const_iterator it = aFonts.begin();
OStringBuffer aLine( 256 );
aLine.append( "%%DocumentSuppliedResources: font " );
aLine.append( *it );
aLine.append( "\n" );
WritePS ( pFile, aLine.getStr() );
while( (++it) != aFonts.end() )
{
std::list< OString >::const_iterator it = aFonts[i].begin();
OStringBuffer aLine( 256 );
if( i == 0 )
aLine.append( "%%DocumentSuppliedResources: font " );
else
aLine.append( "%%DocumentNeededResources: font " );
aLine.setLength(0);
aLine.append( "%%+ font " );
aLine.append( *it );
aLine.append( "\n" );
WritePS ( pFile, aLine.getStr() );
while( (++it) != aFonts[i].end() )
{
aLine.setLength(0);
aLine.append( "%%+ font " );
aLine.append( *it );
aLine.append( "\n" );
WritePS ( pFile, aLine.getStr() );
}
}
}
......
......@@ -36,42 +36,39 @@ using namespace psp ;
namespace psp {
/*
container for a font and its helper fonts:
1st font is the font substitute e.g. helvetica substitutes arial on the printer
2nd is the font itself
3rd is a fallback font, usually a font with unicode glyph repertoir (e.g. andale)
1st is the font itself
2nd is a fallback font, usually a font with unicode glyph repertoir (e.g. andale)
symbol fonts (adobe-fontspecific) may need special glyphmapping
(symbol page vc. latin page)
*/
class Font3
class Font2
{
private:
#define Font3Size 3
#define Font2Size 2
fontID mpFont [Font3Size];
fontID mpFont [Font2Size];
bool mbSymbol;
public:
fontID GetFont (int nIdx) const
{ return nIdx < Font3Size ? mpFont[nIdx] : -1 ; }
{ return nIdx < Font2Size ? mpFont[nIdx] : -1 ; }
bool IsSymbolFont () const
{ return mbSymbol; }
Font3 (const PrinterGfx &rGfx);
~Font3 () {}
Font2 (const PrinterGfx &rGfx);
~Font2 () {}
};
Font3::Font3(const PrinterGfx &rGfx)
Font2::Font2(const PrinterGfx &rGfx)
{
mpFont[0] = rGfx.getFontSubstitute();
mpFont[1] = rGfx.GetFontID();
mpFont[2] = rGfx.getFallbackID();
// mpFont[2] = rGfx.GetFontID();
PrintFontManager &rMgr = PrintFontManager::get();
mbSymbol = mpFont[1] != -1 ?
rMgr.getFontEncoding(mpFont[1]) == RTL_TEXTENCODING_SYMBOL : false;
mpFont[0] = rGfx.GetFontID();
mpFont[1] = rGfx.getFallbackID();
PrintFontManager &rMgr = PrintFontManager::get();
mbSymbol = mpFont[0] != -1 ?
rMgr.getFontEncoding(mpFont[0]) == RTL_TEXTENCODING_SYMBOL : false;
}
} // namespace psp
......@@ -311,7 +308,7 @@ PrinterGfx::DrawText (
// setup font[substitutes] and map the string into the symbol area in case of
// symbol font
Font3 aFont(*this);
Font2 aFont(*this);
sal_Unicode *pEffectiveStr;
if ( aFont.IsSymbolFont() )
{
......@@ -610,12 +607,12 @@ PrinterGfx::getCharWidth (sal_Bool b_vert, sal_Unicode n_char, CharacterMetric *
}
fontID
PrinterGfx::getCharMetric (const Font3 &rFont, sal_Unicode n_char, CharacterMetric *p_bbox)
PrinterGfx::getCharMetric (const Font2 &rFont, sal_Unicode n_char, CharacterMetric *p_bbox)
{
p_bbox->width = -1;
p_bbox->height = -1;
for (fontID n = 0; n < 3; n++)
for (fontID n = 0; n < Font2Size; n++)
{
fontID n_font = rFont.GetFont(n);
if (n_font != -1)
......@@ -629,24 +626,10 @@ PrinterGfx::getCharMetric (const Font3 &rFont, sal_Unicode n_char, CharacterMetr
return rFont.GetFont(0) != -1 ? rFont.GetFont(0) : rFont.GetFont(1);
}
fontID
PrinterGfx::getFontSubstitute () const
{
if( mpFontSubstitutes )
{
::boost::unordered_map< fontID, fontID >::const_iterator it =
mpFontSubstitutes->find( mnFontID );
if( it != mpFontSubstitutes->end() )
return it->second;
}
return -1;
}
sal_Int32
PrinterGfx::GetCharWidth (sal_Unicode nFrom, sal_Unicode nTo, long *pWidthArray)
{
Font3 aFont(*this);
Font2 aFont(*this);
if (aFont.IsSymbolFont() && (nFrom < 256) && (nTo < 256))
{
nFrom += 0xF000;
......@@ -684,7 +667,7 @@ PrinterGfx::OnEndJob ()
}
void
PrinterGfx::writeResources( osl::File* pFile, std::list< OString >& rSuppliedFonts, std::list< OString >& rNeededFonts )
PrinterGfx::writeResources( osl::File* pFile, std::list< OString >& rSuppliedFonts )
{
// write all type 1 fonts
std::list< sal_Int32 >::iterator aFont;
......@@ -739,11 +722,6 @@ PrinterGfx::writeResources( osl::File* pFile, std::list< OString >& rSuppliedFon
// || aIter->GetFontType() == fonttype::Builtin )
{
aIter->PSUploadEncoding (pFile, *this);
if( aIter->GetFontType() == fonttype::Builtin )
rNeededFonts.push_back(
OUStringToOString(
mrFontMgr.getPSName( aIter->GetFontID() ),
RTL_TEXTENCODING_ASCII_US ) );
}
}
}
......
......@@ -117,7 +117,7 @@ public:
* forward declarations
*/
class Font3;
class Font2;
class GlyphSet;
class PrinterJob;
class PrintFontManager;
......@@ -171,7 +171,7 @@ struct GraphicsStatus
GraphicsStatus();
};
class Font3;
class Font2;
class VCL_DLLPUBLIC PrinterGfx
{
......@@ -242,14 +242,12 @@ private:
std::list< GraphicsStatus > maGraphicsStack;
GraphicsStatus& currentState() { return maGraphicsStack.front(); }
/* font / font substitution */
friend class Font3;
const ::boost::unordered_map< fontID, fontID >* mpFontSubstitutes;
/* font */
friend class Font2;
int getCharWidth (sal_Bool b_vert, sal_Unicode n_char,
CharacterMetric *p_bbox);
fontID getCharMetric (const Font3 &rFont, sal_Unicode n_char,
fontID getCharMetric (const Font2 &rFont, sal_Unicode n_char,
CharacterMetric *p_bbox);
fontID getFontSubstitute () const;
fontID getFallbackID () const { return mnFallbackID; }
public:
......@@ -301,7 +299,7 @@ public:
void OnEndPage ();
void OnEndJob ();
void writeResources( osl::File* pFile, std::list< OString >& rSuppliedFonts, std::list< OString >& rNeededFonts );
void writeResources( osl::File* pFile, std::list< OString >& rSuppliedFonts );
PrintFontManager& GetFontMgr () { return mrFontMgr; }
void drawVerticalizedText (const Point& rPoint,
......
......@@ -122,11 +122,6 @@ bool PrinterInfoManager::addOrRemovePossible() const
return false;
}
void PrinterInfoManager::fillFontSubstitutions( PrinterInfo& /* rInfo */ ) const
{
}
void PrinterInfoManager::getSystemPrintCommands( std::list< OUString >& /* rCommands */ )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment