diff options
author | Tor Lillqvist <tml@collabora.com> | 2022-08-24 15:40:16 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2022-08-25 11:57:55 +0200 |
commit | c8d974444507a96bebc1ef46869809cb8c9ce5c7 (patch) | |
tree | 0780c9e45a7efa909318c9c6245941ccd227cfdd /desktop/source | |
parent | eaf0b96ec2acdea2376413ef3a93c4c17889e23c (diff) |
Tell LibreOfficeKit clients what fonts in a document are missing on the machine
Use the OutputDevice::StartTrackingFontMappingUse() and
OutputDevice::FinishTrackingFontMappingUse() functionality that was
added last year.
Add a new LibreOfficeKit document callback:
LOK_CALLBACK_FONTS_MISSING.
"Font" here means just the family name. We dont really know what style
from the family is missing.
Change-Id: Iec4349b5827e7d1dbdde7f8a9f8da92efde429e0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138802
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'desktop/source')
-rw-r--r-- | desktop/source/lib/init.cxx | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 54b72d7ef88f..a987ad548d64 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2584,6 +2584,8 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, aFilterOptions[3].Value <<= nUpdateDoc; */ + OutputDevice::StartTrackingFontMappingUse(); + const int nThisDocumentId = nDocumentIdCounter++; SfxViewShell::SetCurrentDocId(ViewShellDocId(nThisDocumentId)); uno::Reference<lang::XComponent> xComponent = xComponentLoader->loadComponentFromURL( @@ -2607,6 +2609,49 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, int nState = doc_getSignatureState(pDocument); pLib->mpCallback(LOK_CALLBACK_SIGNATURE_STATUS, OString::number(nState).getStr(), pLib->mpCallbackData); } + + auto aFontMappingUseData = OutputDevice::FinishTrackingFontMappingUse(); + + // Filter out font substitutions that actually aren't any substitutions, like "Liberation + // 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 substituded, as vcl::Font::GetStyleName() tents 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++; + } + } + + for (std::size_t i = 0; i < aFontMappingUseData.size(); ++i) + { + pDocument->maFontsMissing.insert(aFontMappingUseData[i].mOriginalFont); + } + return pDocument; } catch (const uno::Exception& exception) @@ -3801,6 +3846,21 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis, pDocument->mpCallbackFlushHandlers[nView]->setViewId(pViewShell->GetViewShellId().get()); pViewShell->setLibreOfficeKitViewCallback(pDocument->mpCallbackFlushHandlers[nView].get()); } + + if (pDocument->maFontsMissing.size() != 0) + { + std::string sPayload = "{ \"fontsmissing\": [ "; + bool bFirst = true; + for (const auto &f : pDocument->maFontsMissing) + { + if (!bFirst) + sPayload += ", "; + sPayload += "\"" + std::string(f.toUtf8().getStr()) + "\""; + } + sPayload += " ] }"; + pCallback(LOK_CALLBACK_FONTS_MISSING, sPayload.c_str(), pData); + pDocument->maFontsMissing.clear(); + } } else { |