Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / source / gdi / pdffontcache.cxx
blob67a8614db142152c47c0dd2777dab96227fdae4a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <typeinfo>
22 #include <sal/types.h>
24 #include "fontinstance.hxx"
25 #include "PhysicalFontFace.hxx"
26 #include "salgdi.hxx"
27 #include "sallayout.hxx"
29 #include "pdffontcache.hxx"
31 using namespace vcl;
33 PDFFontCache::FontIdentifier::FontIdentifier( const PhysicalFontFace* pFont, bool bVertical ) :
34 m_nFontId( pFont->GetFontId() ),
35 m_bVertical( bVertical ),
36 m_typeFontFace( const_cast<std::type_info*>(&typeid(pFont)) )
40 PDFFontCache::FontData& PDFFontCache::getFont( const PhysicalFontFace* pFont, bool bVertical )
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();
51 sal_Int32 PDFFontCache::getGlyphWidth( const PhysicalFontFace* pFont, sal_GlyphId nGlyph, bool bVertical, SalGraphics* pGraphics )
53 sal_Int32 nWidth = 0;
54 FontData& rFontData( getFont( pFont, bVertical ) );
55 if( rFontData.m_nWidths.empty() )
57 pGraphics->GetGlyphWidths( pFont, bVertical, rFontData.m_nWidths, rFontData.m_aGlyphIdToIndex );
59 if( ! rFontData.m_nWidths.empty() )
61 if (nGlyph < rFontData.m_nWidths.size())
62 nWidth = rFontData.m_nWidths[nGlyph];
64 return nWidth;
67 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */