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