include/svtools/ctrlbox.hxx | 3 ++- include/vcl/weldutils.hxx | 3 ++- include/vcl/window.hxx | 4 ++-- svtools/source/control/ctrlbox.cxx | 29 ++++++++++++++++++++++++----- svx/source/tbxctrls/tbcontrl.cxx | 2 ++ vcl/source/app/weldutils.cxx | 4 ++-- vcl/source/window/window.cxx | 14 +++++++++----- 7 files changed, 43 insertions(+), 16 deletions(-)
New commits: commit 093e49e521ed051641f57273ac7f4d526a511c57 Author: Szymon Kłos <[email protected]> AuthorDate: Fri Aug 25 18:01:32 2023 +0200 Commit: Szymon Kłos <[email protected]> CommitDate: Mon Aug 28 16:27:03 2023 +0200 jsdialog: render font previews with hidpi we pass dpi scale, let's use it to determine combobox entry size Change-Id: I4088eca565b301c5693e52b1c05af1a335fc34fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156115 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> Reviewed-by: Szymon Kłos <[email protected]> diff --git a/include/svtools/ctrlbox.hxx b/include/svtools/ctrlbox.hxx index cb200b4c83da..7751eb3b2969 100644 --- a/include/svtools/ctrlbox.hxx +++ b/include/svtools/ctrlbox.hxx @@ -339,7 +339,8 @@ private: void LoadMRUEntries( const OUString& aFontMRUEntriesFile ); void SaveMRUEntries( const OUString& aFontMRUEntriesFile ) const; - OutputDevice& CachePreview(size_t nIndex, Point* pTopLeft); + OutputDevice& CachePreview(size_t nIndex, Point* pTopLeft, + sal_Int32 nDPIX = 96, sal_Int32 nDPIY = 96); public: FontNameBox(std::unique_ptr<weld::ComboBox> p); diff --git a/include/vcl/weldutils.hxx b/include/vcl/weldutils.hxx index 8a4c128515a0..1987066badf8 100644 --- a/include/vcl/weldutils.hxx +++ b/include/vcl/weldutils.hxx @@ -464,7 +464,8 @@ VCL_DLLPUBLIC int GetMinimumEditHeight(); VCL_DLLPUBLIC weld::Window* GetPopupParent(vcl::Window& rOutWin, tools::Rectangle& rRect); // Use Application::GetDefaultDevice to set the PointFont rFont to the OutputDevice -VCL_DLLPUBLIC void SetPointFont(OutputDevice& rDevice, const vcl::Font& rFont); +VCL_DLLPUBLIC void SetPointFont(OutputDevice& rDevice, const vcl::Font& rFont, + bool bUseDeviceDPI = false); } #endif diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx index e595a2ba1690..d03555bd5b99 100644 --- a/include/vcl/window.hxx +++ b/include/vcl/window.hxx @@ -619,7 +619,7 @@ private: SAL_DLLPRIVATE void ImplInitResolutionSettings(); - SAL_DLLPRIVATE void ImplPointToLogic(vcl::RenderContext const & rRenderContext, vcl::Font& rFont) const; + SAL_DLLPRIVATE void ImplPointToLogic(vcl::RenderContext const & rRenderContext, vcl::Font& rFont, bool bUseRenderContextDPI = false) const; SAL_DLLPRIVATE void ImplLogicToPoint(vcl::RenderContext const & rRenderContext, vcl::Font& rFont) const; SAL_DLLPRIVATE bool ImplSysObjClip( const vcl::Region* pOldRegion ); @@ -838,7 +838,7 @@ public: void UpdateSettings( const AllSettings& rSettings, bool bChild = false ); void NotifyAllChildren( DataChangedEvent& rDCEvt ); - void SetPointFont(vcl::RenderContext& rRenderContext, const vcl::Font& rFont); + void SetPointFont(vcl::RenderContext& rRenderContext, const vcl::Font& rFont, bool bUseRenderContextDPI = false); vcl::Font GetPointFont(vcl::RenderContext const & rRenderContext) const; void SetZoomedPointFont(vcl::RenderContext& rRenderContext, const vcl::Font& rFont); tools::Long GetDrawPixel( ::OutputDevice const * pDev, tools::Long nPixels ) const; diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx index 6fab9eb6a0f8..482d53f28e0b 100644 --- a/svtools/source/control/ctrlbox.cxx +++ b/svtools/source/control/ctrlbox.cxx @@ -345,6 +345,8 @@ namespace size_t nMaxDeviceHeight = SAL_MAX_INT16 / 16; // see limitXCreatePixmap and be generous wrt up to x16 hidpi assert(gUserItemSz.Height() != 0); gPreviewsPerDevice = gUserItemSz.Height() == 0 ? 16 : nMaxDeviceHeight / gUserItemSz.Height(); + if (comphelper::LibreOfficeKit::isActive()) + gPreviewsPerDevice = 1; } } @@ -528,8 +530,14 @@ void FontNameBox::EnableWYSIWYG(bool bEnable) m_xComboBox->set_custom_renderer(mbWYSIWYG); } -IMPL_LINK_NOARG(FontNameBox, CustomGetSizeHdl, OutputDevice&, Size) +IMPL_LINK(FontNameBox, CustomGetSizeHdl, OutputDevice&, rDevice, Size) { + if (comphelper::LibreOfficeKit::isActive()) + { + calcCustomItemSize(*m_xComboBox); + gUserItemSz.setWidth(1.0 * rDevice.GetDPIX() / 96.0 * gUserItemSz.getWidth()); + gUserItemSz.setHeight(1.0 * rDevice.GetDPIY() / 96.0 * gUserItemSz.getHeight()); + } return mbWYSIWYG ? gUserItemSz : Size(); } @@ -751,7 +759,8 @@ static void DrawPreview(const FontMetric& rFontMetric, const Point& rTopLeft, Ou rDevice.Pop(); } -OutputDevice& FontNameBox::CachePreview(size_t nIndex, Point* pTopLeft) +OutputDevice& FontNameBox::CachePreview(size_t nIndex, Point* pTopLeft, + sal_Int32 nDPIX, sal_Int32 nDPIY) { SolarMutexGuard aGuard; const FontMetric& rFontMetric = (*mpFontList)[nIndex]; @@ -777,13 +786,21 @@ OutputDevice& FontNameBox::CachePreview(size_t nIndex, Point* pTopLeft) { if (nPage >= gFontPreviewVirDevs.size()) { - if (comphelper::LibreOfficeKit::isActive()) + bool bIsLOK = comphelper::LibreOfficeKit::isActive(); + if (bIsLOK) // allow transparent background in LOK case gFontPreviewVirDevs.emplace_back(VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT, DeviceFormat::DEFAULT)); else gFontPreviewVirDevs.emplace_back(m_xComboBox->create_render_virtual_device()); + VirtualDevice& rDevice = *gFontPreviewVirDevs.back(); rDevice.SetOutputSizePixel(Size(gUserItemSz.Width(), gUserItemSz.Height() * gPreviewsPerDevice)); - weld::SetPointFont(rDevice, m_xComboBox->get_font()); + if (bIsLOK) + { + rDevice.SetDPIX(nDPIX); + rDevice.SetDPIY(nDPIY); + } + + weld::SetPointFont(rDevice, m_xComboBox->get_font(), bIsLOK); assert(gFontPreviewVirDevs.size() == nPage + 1); } @@ -818,7 +835,9 @@ IMPL_LINK(FontNameBox, CustomRenderHdl, weld::ComboBox::render_args, aPayload, v { // use cache of unselected entries Point aTopLeft; - OutputDevice& rDevice = CachePreview(nIndex, &aTopLeft); + OutputDevice& rDevice = CachePreview(nIndex, &aTopLeft, + rRenderContext.GetDPIX(), + rRenderContext.GetDPIY()); rRenderContext.DrawOutDev(aDestPoint, gUserItemSz, aTopLeft, gUserItemSz, diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 71da54267427..2eda9b2be745 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -900,6 +900,8 @@ SvxStyleBox_Base::SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget, IMPL_LINK(SvxStyleBox_Base, CustomGetSizeHdl, OutputDevice&, rArg, Size) { CalcOptimalExtraUserWidth(rArg); + if (comphelper::LibreOfficeKit::isActive()) + return Size(m_nMaxUserDrawFontWidth * rArg.GetDPIX() / 96, ITEM_HEIGHT * rArg.GetDPIY() / 96); return Size(m_nMaxUserDrawFontWidth, ITEM_HEIGHT); } diff --git a/vcl/source/app/weldutils.cxx b/vcl/source/app/weldutils.cxx index f17aed238ae8..28b1004d5af2 100644 --- a/vcl/source/app/weldutils.cxx +++ b/vcl/source/app/weldutils.cxx @@ -617,12 +617,12 @@ weld::Window* GetPopupParent(vcl::Window& rOutWin, tools::Rectangle& rRect) return rOutWin.GetFrameWeld(); } -void SetPointFont(OutputDevice& rDevice, const vcl::Font& rFont) +void SetPointFont(OutputDevice& rDevice, const vcl::Font& rFont, bool bUseDeviceDPI) { auto pDefaultDevice = Application::GetDefaultDevice(); if (pDefaultDevice) if (vcl::Window* pDefaultWindow = pDefaultDevice->GetOwnerWindow()) - pDefaultWindow->SetPointFont(rDevice, rFont); + pDefaultWindow->SetPointFont(rDevice, rFont, bUseDeviceDPI); } ReorderingDropTarget::ReorderingDropTarget(weld::TreeView& rTreeView) diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index c56025f9e0b2..79c3e9d616ff 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -1375,17 +1375,20 @@ void Window::ImplInitResolutionSettings() } } -void Window::ImplPointToLogic(vcl::RenderContext const & rRenderContext, vcl::Font& rFont) const +void Window::ImplPointToLogic(vcl::RenderContext const & rRenderContext, vcl::Font& rFont, + bool bUseRenderContextDPI) const { Size aSize = rFont.GetFontSize(); if (aSize.Width()) { - aSize.setWidth( aSize.Width() * ( mpWindowImpl->mpFrameData->mnDPIX) ); + aSize.setWidth( aSize.Width() * + ( bUseRenderContextDPI ? rRenderContext.GetDPIX() : mpWindowImpl->mpFrameData->mnDPIX) ); aSize.AdjustWidth(72 / 2 ); aSize.setWidth( aSize.Width() / 72 ); } - aSize.setHeight( aSize.Height() * ( mpWindowImpl->mpFrameData->mnDPIY) ); + aSize.setHeight( aSize.Height() + * ( bUseRenderContextDPI ? rRenderContext.GetDPIY() : mpWindowImpl->mpFrameData->mnDPIY) ); aSize.AdjustHeight(72/2 ); aSize.setHeight( aSize.Height() / 72 ); @@ -2174,10 +2177,11 @@ void Window::CollectChildren(::std::vector<vcl::Window *>& rAllChildren ) } } -void Window::SetPointFont(vcl::RenderContext& rRenderContext, const vcl::Font& rFont) +void Window::SetPointFont(vcl::RenderContext& rRenderContext, const vcl::Font& rFont, + bool bUseRenderContextDPI) { vcl::Font aFont = rFont; - ImplPointToLogic(rRenderContext, aFont); + ImplPointToLogic(rRenderContext, aFont, bUseRenderContextDPI); rRenderContext.SetFont(aFont); }
