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