xref: /aoo42x/main/vcl/source/gdi/pdffontcache.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_vcl.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "pdffontcache.hxx"
27cdf0e10cSrcweir #include <salgdi.hxx>
28cdf0e10cSrcweir #include <outfont.hxx>
29cdf0e10cSrcweir #include <sallayout.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using namespace vcl;
32cdf0e10cSrcweir 
FontIdentifier(const ImplFontData * pFont,bool bVertical)33cdf0e10cSrcweir PDFFontCache::FontIdentifier::FontIdentifier( const ImplFontData* pFont, bool bVertical ) :
34cdf0e10cSrcweir     m_nFontId( pFont->GetFontId() ),
35cdf0e10cSrcweir     m_nMagic( pFont->GetFontMagic() ),
36cdf0e10cSrcweir     m_bVertical( bVertical )
37cdf0e10cSrcweir {
38cdf0e10cSrcweir }
39cdf0e10cSrcweir 
getFont(const ImplFontData * pFont,bool bVertical)40cdf0e10cSrcweir PDFFontCache::FontData& PDFFontCache::getFont( const ImplFontData* pFont, bool bVertical )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     FontIdentifier aId( pFont, bVertical );
43cdf0e10cSrcweir     FontToIndexMap::iterator it = m_aFontToIndex.find( aId );
44cdf0e10cSrcweir     if( it != m_aFontToIndex.end() )
45cdf0e10cSrcweir         return m_aFonts[ it->second ];
46cdf0e10cSrcweir     m_aFontToIndex[ aId ] = sal_uInt32(m_aFonts.size());
47cdf0e10cSrcweir     m_aFonts.push_back( FontData() );
48cdf0e10cSrcweir     return m_aFonts.back();
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
getGlyphWidth(const ImplFontData * pFont,sal_GlyphId nGlyph,bool bVertical,SalGraphics * pGraphics)51cdf0e10cSrcweir sal_Int32 PDFFontCache::getGlyphWidth( const ImplFontData* pFont, sal_GlyphId nGlyph, bool bVertical, SalGraphics* pGraphics )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     sal_Int32 nWidth = 0;
54cdf0e10cSrcweir     FontData& rFontData( getFont( pFont, bVertical ) );
55cdf0e10cSrcweir     if( rFontData.m_nWidths.empty() )
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         pGraphics->GetGlyphWidths( pFont, bVertical, rFontData.m_nWidths, rFontData.m_aGlyphIdToIndex );
58cdf0e10cSrcweir     }
59cdf0e10cSrcweir     if( ! rFontData.m_nWidths.empty() )
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         sal_GlyphId nIndex = nGlyph;
62cdf0e10cSrcweir         if( (nGlyph & GF_ISCHAR) != 0 )
63cdf0e10cSrcweir         {
64cdf0e10cSrcweir             const sal_Ucs cCode = static_cast<sal_Ucs>(nGlyph & GF_IDXMASK);
65cdf0e10cSrcweir             Ucs2UIntMap::const_iterator it = rFontData.m_aGlyphIdToIndex.find( cCode );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 			// allow symbol aliasing U+00xx -> U+F0xx if there is no direct match
68cdf0e10cSrcweir             if( it == rFontData.m_aGlyphIdToIndex.end()
69cdf0e10cSrcweir 			&&  pFont->IsSymbolFont()
70cdf0e10cSrcweir 			&&  (cCode < 0x0100) )
71cdf0e10cSrcweir                 it = rFontData.m_aGlyphIdToIndex.find( cCode+0xF000 );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir             nIndex = (it != rFontData.m_aGlyphIdToIndex.end()) ? it->second : 0;
74cdf0e10cSrcweir         }
75cdf0e10cSrcweir         nIndex &= GF_IDXMASK;
76cdf0e10cSrcweir         if( nIndex < rFontData.m_nWidths.size() )
77cdf0e10cSrcweir             nWidth = rFontData.m_nWidths[ nIndex ];
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir     return nWidth;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82