Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / source / font / fontinstance.cxx
blob04d1061296da82dc93bb04f80d84bc388c1ae907
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 .
21 #include "svdata.hxx"
22 #include "fontinstance.hxx"
24 // extend std namespace to add custom hash needed for LogicalFontInstance
26 namespace std
28 template <> struct hash< pair< sal_UCS4, FontWeight > >
30 size_t operator()(const pair< sal_UCS4, FontWeight >& rData) const
32 size_t h1 = hash<sal_UCS4>()(rData.first);
33 size_t h2 = hash<int>()(rData.second);
34 return h1 ^ h2;
40 LogicalFontInstance::LogicalFontInstance( const FontSelectPattern& rFontSelData )
41 : mpFontCache(nullptr)
42 , maFontSelData( rFontSelData )
43 , mxFontMetric( new ImplFontMetricData( rFontSelData ))
44 , mpConversion( nullptr )
45 , mnLineHeight( 0 )
46 , mnRefCount( 1 )
47 , mnOwnOrientation( 0 )
48 , mnOrientation( 0 )
49 , mbInit( false )
50 , mpUnicodeFallbackList( nullptr )
52 maFontSelData.mpFontInstance = this;
55 LogicalFontInstance::~LogicalFontInstance()
57 delete mpUnicodeFallbackList;
58 mpFontCache = nullptr;
59 mxFontMetric = nullptr;
62 void LogicalFontInstance::AddFallbackForUnicode( sal_UCS4 cChar, FontWeight eWeight, const OUString& rFontName )
64 if( !mpUnicodeFallbackList )
65 mpUnicodeFallbackList = new UnicodeFallbackList;
66 (*mpUnicodeFallbackList)[ std::pair< sal_UCS4, FontWeight >(cChar,eWeight) ] = rFontName;
69 bool LogicalFontInstance::GetFallbackForUnicode( sal_UCS4 cChar, FontWeight eWeight, OUString* pFontName ) const
71 if( !mpUnicodeFallbackList )
72 return false;
74 UnicodeFallbackList::const_iterator it = mpUnicodeFallbackList->find( std::pair< sal_UCS4, FontWeight >(cChar,eWeight) );
75 if( it == mpUnicodeFallbackList->end() )
76 return false;
78 *pFontName = (*it).second;
79 return true;
82 void LogicalFontInstance::IgnoreFallbackForUnicode( sal_UCS4 cChar, FontWeight eWeight, const OUString& rFontName )
84 UnicodeFallbackList::iterator it = mpUnicodeFallbackList->find( std::pair< sal_UCS4,FontWeight >(cChar,eWeight) );
85 if( it == mpUnicodeFallbackList->end() )
86 return;
87 if( (*it).second == rFontName )
88 mpUnicodeFallbackList->erase( it );
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */