1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include <typeinfo>
21
22 #include <sal/types.h>
23
24 #include <PhysicalFontFace.hxx>
25 #include <salgdi.hxx>
26
27 #include "pdffontcache.hxx"
28
29 using namespace vcl;
30
FontIdentifier(const PhysicalFontFace * pFont,bool bVertical)31 PDFFontCache::FontIdentifier::FontIdentifier( const PhysicalFontFace* pFont, bool bVertical ) :
32 m_nFontId( pFont->GetFontId() ),
33 m_bVertical( bVertical ),
34 m_typeFontFace( const_cast<std::type_info*>(&typeid(pFont)) )
35 {
36 }
37
getFont(const PhysicalFontFace * pFont,bool bVertical)38 PDFFontCache::FontData& PDFFontCache::getFont( const PhysicalFontFace* pFont, bool bVertical )
39 {
40 FontIdentifier aId( pFont, bVertical );
41 FontToIndexMap::iterator it = m_aFontToIndex.find( aId );
42 if( it != m_aFontToIndex.end() )
43 return m_aFonts[ it->second ];
44 m_aFontToIndex[ aId ] = sal_uInt32(m_aFonts.size());
45 m_aFonts.emplace_back( );
46 return m_aFonts.back();
47 }
48
getGlyphWidth(const PhysicalFontFace * pFont,sal_GlyphId nGlyph,bool bVertical,SalGraphics * pGraphics)49 sal_Int32 PDFFontCache::getGlyphWidth( const PhysicalFontFace* pFont, sal_GlyphId nGlyph, bool bVertical, SalGraphics* pGraphics )
50 {
51 sal_Int32 nWidth = 0;
52 FontData& rFontData( getFont( pFont, bVertical ) );
53 if( rFontData.m_nWidths.empty() )
54 {
55 pGraphics->GetGlyphWidths( pFont, bVertical, rFontData.m_nWidths, rFontData.m_aGlyphIdToIndex );
56 }
57 if( ! rFontData.m_nWidths.empty() )
58 {
59 if (nGlyph < rFontData.m_nWidths.size())
60 nWidth = rFontData.m_nWidths[nGlyph];
61 }
62 return nWidth;
63 }
64
65 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
66