1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pdffontcache.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_vcl.hxx"
33 #include "pdffontcache.hxx"
34 #include <vcl/salgdi.hxx>
35 #include <vcl/outfont.hxx>
36 #include <vcl/sallayout.hxx>
40 PDFFontCache::FontIdentifier::FontIdentifier( const ImplFontData
* pFont
, bool bVertical
) :
41 m_nFontId( pFont
->GetFontId() ),
42 m_nMagic( pFont
->GetFontMagic() ),
43 m_bVertical( bVertical
)
47 PDFFontCache::FontData
& PDFFontCache::getFont( const ImplFontData
* pFont
, bool bVertical
)
49 FontIdentifier
aId( pFont
, bVertical
);
50 FontToIndexMap::iterator it
= m_aFontToIndex
.find( aId
);
51 if( it
!= m_aFontToIndex
.end() )
52 return m_aFonts
[ it
->second
];
53 m_aFontToIndex
[ aId
] = sal_uInt32(m_aFonts
.size());
54 m_aFonts
.push_back( FontData() );
55 return m_aFonts
.back();
58 sal_Int32
PDFFontCache::getGlyphWidth( const ImplFontData
* pFont
, sal_GlyphId nGlyph
, bool bVertical
, SalGraphics
* pGraphics
)
61 FontData
& rFontData( getFont( pFont
, bVertical
) );
62 if( rFontData
.m_nWidths
.empty() )
64 pGraphics
->GetGlyphWidths( pFont
, bVertical
, rFontData
.m_nWidths
, rFontData
.m_aGlyphIdToIndex
);
66 if( ! rFontData
.m_nWidths
.empty() )
68 sal_GlyphId nIndex
= nGlyph
;
69 if( (nGlyph
& GF_ISCHAR
) != 0 )
71 const sal_Ucs cCode
= static_cast<sal_Ucs
>(nGlyph
& GF_IDXMASK
);
72 Ucs2UIntMap::const_iterator it
= rFontData
.m_aGlyphIdToIndex
.find( cCode
);
74 // allow symbol aliasing U+00xx -> U+F0xx if there is no direct match
75 if( it
== rFontData
.m_aGlyphIdToIndex
.end()
76 && pFont
->IsSymbolFont()
78 it
= rFontData
.m_aGlyphIdToIndex
.find( cCode
+0xF000 );
80 nIndex
= (it
!= rFontData
.m_aGlyphIdToIndex
.end()) ? it
->second
: 0;
83 if( nIndex
< rFontData
.m_nWidths
.size() )
84 nWidth
= rFontData
.m_nWidths
[ nIndex
];