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/inc/jsdialog/jsdialogbuilder.hxx |    2 +-
 vcl/jsdialog/executor.cxx            |   11 ++++++++++-
 vcl/jsdialog/jsdialogbuilder.cxx     |    5 ++++-
 vcl/source/app/weldutils.cxx         |    4 ++--
 vcl/source/window/window.cxx         |   14 +++++++++-----
 10 files changed, 58 insertions(+), 19 deletions(-)

New commits:
commit 038bce9b92d8b8f64d1f3797c02d3cde3a9471c2
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Fri Aug 25 16:00:21 2023 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Thu Aug 31 10:15:50 2023 +0200

    jsdialog: combobox rendering with DPI set
    
    Change-Id: I0efb8f765cc95e0eee02fb5905bc392fc754f3ad
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156114
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156250
    Tested-by: Jenkins

diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx 
b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index dc6e04c3eb4e..f632753d35b1 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -621,7 +621,7 @@ public:
     virtual void set_active(int pos) override;
     virtual bool changed_by_direct_pick() const override;
 
-    void render_entry(int pos);
+    void render_entry(int pos, int dpix, int dpiy);
 };
 
 class JSNotebook final : public JSWidget<SalInstanceNotebook, ::TabControl>
diff --git a/vcl/jsdialog/executor.cxx b/vcl/jsdialog/executor.cxx
index 57a1c4db22d8..17c56d78e61e 100644
--- a/vcl/jsdialog/executor.cxx
+++ b/vcl/jsdialog/executor.cxx
@@ -133,7 +133,16 @@ bool ExecuteAction(const OUString& nWindowId, const 
OUString& rWidget, StringMap
                 {
                     auto pJSCombobox = dynamic_cast<JSComboBox*>(pWidget);
                     if (pJSCombobox)
-                        
pJSCombobox->render_entry(o3tl::toInt32(rData["data"]));
+                    {
+                        // pos;dpix;dpiy
+                        const OUString& sParams = rData["data"];
+                        const OUString aPos = sParams.getToken(0, ';');
+                        const OUString aDpiScaleX = sParams.getToken(1, ';');
+                        const OUString aDpiScaleY = sParams.getToken(2, ';');
+
+                        pJSCombobox->render_entry(o3tl::toInt32(aPos), 
o3tl::toInt32(aDpiScaleX),
+                                                  o3tl::toInt32(aDpiScaleY));
+                    }
                     return true;
                 }
             }
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 8f7949c474ca..cd191d15a9d8 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -1664,9 +1664,12 @@ void JSComboBox::set_active(int pos)
 
 bool JSComboBox::changed_by_direct_pick() const { return true; }
 
-void JSComboBox::render_entry(int pos)
+void JSComboBox::render_entry(int pos, int dpix, int dpiy)
 {
     ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::WITH_ALPHA);
+    pDevice->SetDPIX(96.0 * dpix / 100);
+    pDevice->SetDPIY(96.0 * dpiy / 100);
+
     Size aRenderSize = signal_custom_get_size(*pDevice);
     pDevice->SetOutputSize(aRenderSize);
 
commit 3fad74eb9def27788faddd74f5285120e0aefdd9
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Fri Aug 25 18:01:32 2023 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Thu Aug 31 10:15:45 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 <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156251
    Tested-by: Jenkins

diff --git a/include/svtools/ctrlbox.hxx b/include/svtools/ctrlbox.hxx
index 0d7293fc77eb..39863b171b0e 100644
--- a/include/svtools/ctrlbox.hxx
+++ b/include/svtools/ctrlbox.hxx
@@ -340,7 +340,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 0f9c6f3f45b5..73f2e4e5bc03 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -615,7 +615,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 );
@@ -833,7 +833,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 f07041f4a423..40dd39b0d289 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::WITH_ALPHA));
             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 0d862f8964f8..9fdb74a73c21 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -899,6 +899,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 cbe0356a8e1f..235e3140adca 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 869516b45902..35b17761e2c4 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -1374,17 +1374,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 );
 
@@ -2170,10 +2173,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);
 }
 

Reply via email to