vcl/headless/svpprn.cxx |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

New commits:
commit 6cbadf8bf1295a9c3d1d9a389e8cf076314facf4
Author:     Hossein <hoss...@libreoffice.org>
AuthorDate: Wed Aug 20 16:29:01 2025 +0200
Commit:     Hossein <hoss...@libreoffice.org>
CommitDate: Thu Aug 21 21:28:29 2025 +0200

    Use o3tl::convert instead of manual conversion
    
    The new code uses the o3tl::convert to do the conversion, as it provides
    a mechanism to do the conversion among different units in LibreOffice.
    
    The old code used 35.27777778 as the conversion factor to convert points
    to 10 microns.
    
    1 point = 1/72 inch
    1 inch  = 25.4 mm = 25400 microns
    factor  = 25400/(72*10) ≈ 35.27777778
    
    Please note that for values bigger than or equal 24999964, the result
    can have small difference compared to the old result. For this value,
    the new conversion gives 881943174, but the old formula gives 881943175
    which is slightly inaccurate, off by 1. In this case, the new conversion
    using o3tl::convert() is more accurate.
    
    Change-Id: Ifcda6f9ad2f3f4d0f623ca157edbd0b4f44041fc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189970
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Hossein   <hoss...@libreoffice.org>

diff --git a/vcl/headless/svpprn.cxx b/vcl/headless/svpprn.cxx
index 07321db86e9b..c7d0abff57cf 100644
--- a/vcl/headless/svpprn.cxx
+++ b/vcl/headless/svpprn.cxx
@@ -60,8 +60,6 @@ static OUString getPdfDir( const PrinterInfo& rInfo )
     return aDir;
 }
 
-static int PtTo10Mu( int nPoints ) { return 
static_cast<int>((static_cast<double>(nPoints)*35.27777778)+0.5); }
-
 static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
 {
     pJobSetup->SetOrientation( rData.m_eOrientation == orientation::Landscape 
? Orientation::Landscape : Orientation::Portrait );
@@ -76,9 +74,9 @@ static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, 
JobData& rData )
     pJobSetup->SetPaperHeight( 0 );
     if( pJobSetup->GetPaperFormat() == PAPER_USER )
     {
-        // transform to 100dth mm
-        width               = PtTo10Mu( width );
-        height              = PtTo10Mu( height );
+        // convert from points to 1/100 mm
+        width = o3tl::convert(width, o3tl::Length::pt, o3tl::Length::mm100);
+        height = o3tl::convert(height, o3tl::Length::pt, o3tl::Length::mm100);
 
         if( rData.m_eOrientation == psp::orientation::Portrait )
         {

Reply via email to