summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2022-09-01 12:39:52 +0300
committerTor Lillqvist <tml@collabora.com>2022-09-01 13:41:43 +0200
commit63f7765c1d50fbd87b53d692a2cd1720a7a16d70 (patch)
treed115767ddf89901055fd9fe017c8496e796f2e29 /desktop
parentcff37ecf6b9ecd8b169224c327570aa7f63b791e (diff)
Use more idiomatic C++
Change-Id: I0e9460f2500b76bec049c12413fbbee5dcb239c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139149 Tested-by: Jenkins Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/lib/init.cxx131
1 files changed, 57 insertions, 74 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index f37c0bba8cd9..95f96ee67cf4 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2627,85 +2627,68 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
// Serif" -> "Liberation Serif/Regular". If even one of the "substitutions" of a font is to
// the same font, don't count that as a missing font.
- for (std::size_t i = 0; i < aFontMappingUseData.size();)
- {
- // If the original font had an empty style and one of its replacement fonts has the same
- // family name, we assume the font is present. The root problem here is that the code
- // that collects font substitutions tends to get just empty styles for the font that is
- // being substituted, as vcl::Font::GetStyleName() tends to return an empty string.
- // (Italicness is instead indicated by what vcl::Font::GetItalic() returns and boldness
- // by what vcl::Font::GetWeight() returns.)
- if (aFontMappingUseData[i].mOriginalFont.indexOf('/') == -1)
- {
- bool bSubstitutedByTheSame = false;
- for (const auto &j : aFontMappingUseData[i].mUsedFonts)
- {
- if (j.startsWith(OUStringConcatenation(aFontMappingUseData[i].mOriginalFont + "/")))
- {
- bSubstitutedByTheSame = true;
- break;
- }
- }
-
- if (bSubstitutedByTheSame)
- aFontMappingUseData.erase(aFontMappingUseData.begin() + i);
- else
- i++;
- }
- else
- {
- i++;
- }
- }
+ aFontMappingUseData.erase
+ (std::remove_if(aFontMappingUseData.begin(), aFontMappingUseData.end(),
+ [](OutputDevice::FontMappingUseItem x)
+ {
+ // If the original font had an empty style and one of its
+ // replacement fonts has the same family name, we assume the font is
+ // present. The root problem here is that the code that collects
+ // font substitutions tends to get just empty styles for the font
+ // that is being substituted, as vcl::Font::GetStyleName() tends to
+ // return an empty string. (Italicness is instead indicated by what
+ // vcl::Font::GetItalic() returns and boldness by what
+ // vcl::Font::GetWeight() returns.)
+
+ if (x.mOriginalFont.indexOf('/') == -1)
+ for (const auto &j : x.mUsedFonts)
+ if (j.startsWith(OUStringConcatenation(x.mOriginalFont + "/")))
+ return true;
+
+ return false;
+ }),
+ aFontMappingUseData.end());
// Filter out substitutions where a proprietary font has been substituted by a
// metric-compatible one. Obviously this is just a heuristic and implemented only for some
// well-known cases.
- for (std::size_t i = 0; i < aFontMappingUseData.size();)
- {
- // Again, handle only cases where the original font does not include a style. Unclear
- // whether there ever will be a style part included in the mOriginalFont.
-
- if (aFontMappingUseData[i].mOriginalFont.indexOf('/') == -1)
- {
- bool bSubstitutedByMetricCompatible = false;
- for (const auto &j : aFontMappingUseData[i].mUsedFonts)
- {
- if ((aFontMappingUseData[i].mOriginalFont == "Arial" &&
- j.startsWith("Liberation Sans/")) ||
- (aFontMappingUseData[i].mOriginalFont == "Times New Roman" &&
- j.startsWith("Liberation Serif/")) ||
- (aFontMappingUseData[i].mOriginalFont == "Courier New" &&
- j.startsWith("Liberation Mono/")) ||
- (aFontMappingUseData[i].mOriginalFont == "Arial Narrow" &&
- j.startsWith("Liberation Sans Narrow/")) ||
- (aFontMappingUseData[i].mOriginalFont == "Cambria" &&
- j.startsWith("Caladea/")) ||
- (aFontMappingUseData[i].mOriginalFont == "Calibri" &&
- j.startsWith("Carlito/")) ||
- (aFontMappingUseData[i].mOriginalFont == "Palatino Linotype" &&
- j.startsWith("P052/")) ||
- // Perhaps a risky heuristic? If some glyphs from Symbol have been mapped to
- // ones in OpenSymbol, don't warn that Symbol is missing.
- (aFontMappingUseData[i].mOriginalFont == "Symbol" &&
- j.startsWith("OpenSymbol/")))
- {
- bSubstitutedByMetricCompatible = true;
- break;
- }
- }
-
- if (bSubstitutedByMetricCompatible)
- aFontMappingUseData.erase(aFontMappingUseData.begin() + i);
- else
- i++;
- }
- else
- {
- i++;
- }
- }
+ aFontMappingUseData.erase
+ (std::remove_if(aFontMappingUseData.begin(), aFontMappingUseData.end(),
+ [](OutputDevice::FontMappingUseItem x)
+ {
+ // Again, handle only cases where the original font does not include
+ // a style. Unclear whether there ever will be a style part included
+ // in the mOriginalFont.
+
+ if (x.mOriginalFont.indexOf('/') == -1)
+ for (const auto &j : x.mUsedFonts)
+ if ((x.mOriginalFont == "Arial" &&
+ j.startsWith("Liberation Sans/")) ||
+ (x.mOriginalFont == "Times New Roman" &&
+ j.startsWith("Liberation Serif/")) ||
+ (x.mOriginalFont == "Courier New" &&
+ j.startsWith("Liberation Mono/")) ||
+ (x.mOriginalFont == "Arial Narrow" &&
+ j.startsWith("Liberation Sans Narrow/")) ||
+ (x.mOriginalFont == "Cambria" &&
+ j.startsWith("Caladea/")) ||
+ (x.mOriginalFont == "Calibri" &&
+ j.startsWith("Carlito/")) ||
+ (x.mOriginalFont == "Palatino Linotype" &&
+ j.startsWith("P052/")) ||
+ // Perhaps a risky heuristic? If some glyphs from Symbol
+ // have been mapped to ones in OpenSymbol, don't warn
+ // that Symbol is missing.
+ (x.mOriginalFont == "Symbol" &&
+ j.startsWith("OpenSymbol/")))
+ {
+ return true;
+ }
+
+ return false;
+ }),
+ aFontMappingUseData.end());
if (aFontMappingUseData.size() > 0)
{