diff --git a/include/vcl/odfstudio/FontResolutionInfo.hxx b/include/vcl/odfstudio/FontResolutionInfo.hxx new file mode 100644 index 000000000000..487b122d1b6b --- /dev/null +++ b/include/vcl/odfstudio/FontResolutionInfo.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include + +#if HAVE_FEATURE_ODFSTUDIO + +#include +#include + +namespace vcl::odfstudio +{ +struct FontResolutionInfo +{ + OUString maRequestedFamily; + OUString maResolvedFamily; + OUString maResolvedStyle; +}; + +VCL_DLLPUBLIC void setLastFontResolution(const FontResolutionInfo& rInfo); +VCL_DLLPUBLIC bool getLastFontResolution(FontResolutionInfo& rInfo); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sidebar/text/TextPropertyPanel.cxx b/svx/source/sidebar/text/TextPropertyPanel.cxx index 719e296dce6c..61d454ff6ad9 100644 --- a/svx/source/sidebar/text/TextPropertyPanel.cxx +++ b/svx/source/sidebar/text/TextPropertyPanel.cxx @@ -24,6 +24,10 @@ #include #include +#if HAVE_FEATURE_ODFSTUDIO +#include +#endif + using namespace css; namespace svx::sidebar { @@ -64,6 +68,10 @@ TextPropertyPanel::TextPropertyPanel(weld::Widget* pParent, const css::uno::Refe , mxPositionBarDispatch(new ToolbarUnoDispatcher(*mxPositionBar, *m_xBuilder, rxFrame)) , mxSpacingBar(m_xBuilder->weld_toolbar(u"spacingbar"_ustr)) , mxSpacingBarDispatch(new ToolbarUnoDispatcher(*mxSpacingBar, *m_xBuilder, rxFrame)) +#if HAVE_FEATURE_ODFSTUDIO + , mxODFStudioFontUsed(m_xBuilder->weld_label(u"odfstudio_font_used"_ustr)) + , maODFStudioFontTimer("ODFStudio FontInspector") +#endif { bool isMobilePhone = false; const SfxViewShell* pViewShell = SfxViewShell::Current(); @@ -71,10 +79,21 @@ TextPropertyPanel::TextPropertyPanel(weld::Widget* pParent, const css::uno::Refe pViewShell && pViewShell->isLOKMobilePhone()) isMobilePhone = true; mxSpacingBar->set_visible(!isMobilePhone); + +#if HAVE_FEATURE_ODFSTUDIO + maODFStudioFontTimer.SetTimeout(500); + maODFStudioFontTimer.SetInvokeHandler( + LINK(this, TextPropertyPanel, ODFStudioFontTimerHdl)); + maODFStudioFontTimer.Start(); +#endif } TextPropertyPanel::~TextPropertyPanel() { +#if HAVE_FEATURE_ODFSTUDIO + maODFStudioFontTimer.Stop(); +#endif + mxResetBarDispatch.reset(); mxDefaultBarDispatch.reset(); mxHyphenationBarDispatch.reset(); @@ -100,6 +119,21 @@ TextPropertyPanel::~TextPropertyPanel() mxFont.reset(); } +#if HAVE_FEATURE_ODFSTUDIO +IMPL_LINK_NOARG(TextPropertyPanel, ODFStudioFontTimerHdl, Timer*, void) +{ + vcl::odfstudio::FontResolutionInfo aInfo; + if (!vcl::odfstudio::getLastFontResolution(aInfo)) + return; + + OUString aLabel = u"Font used: "_ustr + aInfo.maResolvedFamily; + if (!aInfo.maResolvedStyle.isEmpty()) + aLabel += u" "_ustr + aInfo.maResolvedStyle; + mxODFStudioFontUsed->set_label(aLabel); + mxODFStudioFontUsed->set_visible(true); +} +#endif + void TextPropertyPanel::HandleContextChange ( const vcl::EnumContext& rContext) { diff --git a/svx/source/sidebar/text/TextPropertyPanel.hxx b/svx/source/sidebar/text/TextPropertyPanel.hxx index 30cf06bfbeaf..d7d3f0b9724c 100644 --- a/svx/source/sidebar/text/TextPropertyPanel.hxx +++ b/svx/source/sidebar/text/TextPropertyPanel.hxx @@ -19,12 +19,18 @@ #ifndef INCLUDED_SVX_SOURCE_SIDEBAR_TEXT_TEXTPROPERTYPANEL_HXX #define INCLUDED_SVX_SOURCE_SIDEBAR_TEXT_TEXTPROPERTYPANEL_HXX +#include + #include #include #include #include #include +#if HAVE_FEATURE_ODFSTUDIO +#include +#endif + namespace svx::sidebar { class TextPropertyPanel @@ -69,6 +75,12 @@ private: std::unique_ptr mxSpacingBar; std::unique_ptr mxSpacingBarDispatch; +#if HAVE_FEATURE_ODFSTUDIO + std::unique_ptr mxODFStudioFontUsed; + AutoTimer maODFStudioFontTimer; + DECL_LINK(ODFStudioFontTimerHdl, Timer*, void); +#endif + vcl::EnumContext maContext; }; diff --git a/svx/uiconfig/ui/sidebartextpanel.ui b/svx/uiconfig/ui/sidebartextpanel.ui index fbd03e385652..ca622e3c247c 100644 --- a/svx/uiconfig/ui/sidebartextpanel.ui +++ b/svx/uiconfig/ui/sidebartextpanel.ui @@ -7,7 +7,7 @@ True False - + True False @@ -102,6 +102,25 @@ 0 + + + False + False + start + 0 + True + + + static + + + + + 0 + 1 + 2 + + True @@ -162,7 +181,7 @@ 0 - 1 + 2 @@ -253,7 +272,7 @@ 0 - 2 + 3 @@ -324,7 +343,7 @@ 1 - 2 + 3 @@ -419,7 +438,7 @@ 1 - 1 + 2 diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 9970e9c27fc5..acb424e4d0de 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -567,6 +567,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/font/font \ vcl/source/font/FontVariation \ vcl/source/font/EOTConverter \ + $(if $(ENABLE_ODFSTUDIO),vcl/source/font/ODFStudioFontResolution) \ vcl/source/fontsubset/cff \ vcl/source/fontsubset/sft \ vcl/source/pdf/COSWriter \ diff --git a/vcl/source/font/ODFStudioFontResolution.cxx b/vcl/source/font/ODFStudioFontResolution.cxx new file mode 100644 index 000000000000..a0b1d21f7ec5 --- /dev/null +++ b/vcl/source/font/ODFStudioFontResolution.cxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#if HAVE_FEATURE_ODFSTUDIO + +#include + +namespace +{ +std::mutex gFontResolutionMutex; +vcl::odfstudio::FontResolutionInfo gLastFontResolution; +bool gHasFontResolution = false; +} + +namespace vcl::odfstudio +{ +void setLastFontResolution(const FontResolutionInfo& rInfo) +{ + std::scoped_lock aGuard(gFontResolutionMutex); + gLastFontResolution = rInfo; + gHasFontResolution = true; +} + +bool getLastFontResolution(FontResolutionInfo& rInfo) +{ + std::scoped_lock aGuard(gFontResolutionMutex); + if (!gHasFontResolution) + return false; + + rInfo = gLastFontResolution; + return true; +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/font/fontcache.cxx b/vcl/source/font/fontcache.cxx index 9ef72e009872..d3d5b8f14a71 100644 --- a/vcl/source/font/fontcache.cxx +++ b/vcl/source/font/fontcache.cxx @@ -18,9 +18,18 @@ */ #include +#include #include +#if HAVE_FEATURE_ODFSTUDIO +#include +#endif + +#if HAVE_FEATURE_ODFSTUDIO && defined(LINUX) +#include +#endif + #include #include #include @@ -157,6 +166,41 @@ rtl::Reference ImplFontCache::GetFontInstance( PhysicalFont { vcl::font::PhysicalFontFace* pFontData = pFontFamily->FindBestFontFace(aFontSelData); +#if HAVE_FEATURE_ODFSTUDIO + if (pFontData) + { + vcl::odfstudio::setLastFontResolution( + { aFontSelData.GetFamilyName(), pFontData->GetFamilyName(), pFontData->GetStyleName() }); + +#if defined(LINUX) + OString aFontFile; + const auto nFontId = static_cast(pFontData->GetFontId()); + psp::PrintFontManager& rFontManager = psp::PrintFontManager::get(); + if (rFontManager.getFont(nFontId)) + aFontFile = rFontManager.getFontFileSysPath(nFontId); +#endif + + SAL_INFO("odfstudio.fonts", + "requested=\"" << aFontSelData.GetFamilyName() + << "\" target=\"" << aFontSelData.maTargetName + << "\" search=\"" << aFontSelData.maSearchName + << "\" family=\"" << pFontFamily->GetFamilyName() + << "\" face-family=\"" << pFontData->GetFamilyName() + << "\" face-style=\"" << pFontData->GetStyleName() + << "\" full-name=\"" + << pFontData->GetName(vcl::font::NAME_ID_FULL_NAME) + << "\" postscript=\"" + << pFontData->GetName(vcl::font::NAME_ID_POSTSCRIPT_NAME) + << "\" version=\"" + << pFontData->GetName(vcl::font::NAME_ID_VERSION_STRING) +#if defined(LINUX) + << "\" file=\"" << aFontFile +#endif + + << "\""); + } +#endif + // create a new logical font instance from this physical font face pFontInstance = pFontData->CreateFontInstance( aFontSelData ); pFontInstance->mpFontCache = this;