1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <unotools/fontdefs.hxx>
22 #include <font/DirectFontSubstitution.hxx>
31 void DirectFontSubstitution::AddFontSubstitute(const OUString
& rFontName
,
32 const OUString
& rSubstFontName
,
33 AddFontSubstituteFlags nFlags
)
35 maFontSubstList
.emplace_back(rFontName
, rSubstFontName
, nFlags
);
38 void DirectFontSubstitution::RemoveFontsSubstitute() { maFontSubstList
.clear(); }
40 bool DirectFontSubstitution::FindFontSubstitute(OUString
& rSubstName
,
41 std::u16string_view rSearchName
) const
43 // TODO: get rid of O(N) searches
44 std::vector
<FontSubstEntry
>::const_iterator it
= std::find_if(
45 maFontSubstList
.begin(), maFontSubstList
.end(), [&](const FontSubstEntry
& s
) {
46 return (s
.mnFlags
& AddFontSubstituteFlags::ALWAYS
) && (s
.maSearchName
== rSearchName
);
48 if (it
!= maFontSubstList
.end())
50 rSubstName
= it
->maSearchReplaceName
;
56 void ImplFontSubstitute(OUString
& rFontName
)
58 // must be canonicalised
59 assert(GetEnglishSearchFontName(rFontName
) == rFontName
);
60 OUString aSubstFontName
;
61 // apply user-configurable font replacement (eg, from the list in Tools->Options)
62 const DirectFontSubstitution
* pSubst
= ImplGetSVData()->maGDIData
.mpDirectFontSubst
;
63 if (pSubst
&& pSubst
->FindFontSubstitute(aSubstFontName
, rFontName
))
65 rFontName
= aSubstFontName
;
71 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */