/src/libreoffice/vcl/source/font/DirectFontSubstitution.cxx
Line | Count | Source (jump to first uncovered line) |
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 <unotools/fontdefs.hxx> |
21 | | |
22 | | #include <font/DirectFontSubstitution.hxx> |
23 | | |
24 | | #include <svdata.hxx> |
25 | | |
26 | | #include <string> |
27 | | #include <vector> |
28 | | |
29 | | namespace vcl::font |
30 | | { |
31 | | void DirectFontSubstitution::AddFontSubstitute(const OUString& rFontName, |
32 | | const OUString& rSubstFontName, |
33 | | AddFontSubstituteFlags nFlags) |
34 | 0 | { |
35 | 0 | maFontSubstList.emplace_back(rFontName, rSubstFontName, nFlags); |
36 | 0 | } |
37 | | |
38 | 0 | void DirectFontSubstitution::RemoveFontsSubstitute() { maFontSubstList.clear(); } |
39 | | |
40 | | bool DirectFontSubstitution::FindFontSubstitute(OUString& rSubstName, |
41 | | std::u16string_view rSearchName) const |
42 | 0 | { |
43 | | // TODO: get rid of O(N) searches |
44 | 0 | std::vector<FontSubstEntry>::const_iterator it = std::find_if( |
45 | 0 | maFontSubstList.begin(), maFontSubstList.end(), [&](const FontSubstEntry& s) { |
46 | 0 | return (s.mnFlags & AddFontSubstituteFlags::ALWAYS) && (s.maSearchName == rSearchName); |
47 | 0 | }); |
48 | 0 | if (it != maFontSubstList.end()) |
49 | 0 | { |
50 | 0 | rSubstName = it->maSearchReplaceName; |
51 | 0 | return true; |
52 | 0 | } |
53 | 0 | return false; |
54 | 0 | } |
55 | | |
56 | | void ImplFontSubstitute(OUString& rFontName) |
57 | 0 | { |
58 | | // must be canonicalised |
59 | 0 | assert(GetEnglishSearchFontName(rFontName) == rFontName); |
60 | 0 | OUString aSubstFontName; |
61 | | // apply user-configurable font replacement (eg, from the list in Tools->Options) |
62 | 0 | const DirectFontSubstitution* pSubst = ImplGetSVData()->maGDIData.mpDirectFontSubst; |
63 | 0 | if (pSubst && pSubst->FindFontSubstitute(aSubstFontName, rFontName)) |
64 | 0 | { |
65 | 0 | rFontName = aSubstFontName; |
66 | 0 | return; |
67 | 0 | } |
68 | 0 | } |
69 | | } |
70 | | |
71 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |