gdtools icon indicating copy to clipboard operation
gdtools copied to clipboard

difference in width depending on OS

Open jwijffels opened this issue 2 years ago • 1 comments
trafficstars

When tracking down a difference between 2 systems regarding width of a flextable table, I found that the difference could be traced down to m_str_extents_

I get the following when running on a Red Hat

Browse[2]> m_str_extents_("C BELEIDSDOMEIN FINANCIEN EN BEGROTING", "Verdana", 12, TRUE, FALSE, "")
        [,1]  [,2]
[1,] 276.684 9.168

Browse[2]> sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux 8.7 (Ootpa)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.15.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] knitr_1.42           data.table_1.14.8    tibble_3.1.8         dplyr_1.1.0          magrittr_2.0.3       officedown_0.2.4     vlaanderen.bct_0.2.0 officer_0.5.2        flextable_0.8.5      rmarkdown_2.20      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10             graphql_1.5.1           lattice_0.20-45         zoo_1.8-11              digest_0.6.31           utf8_1.2.3              mime_0.12               R6_2.5.1                cellranger_1.1.0       
[10] evaluate_0.20           httr_1.4.4              pillar_1.8.1            gdtools_0.3.1           rlang_1.0.6             curl_5.0.0              uuid_1.1-0              readxl_1.4.2            stringr_1.5.0          
[19] shiny_1.7.4             compiler_4.2.2          httpuv_1.6.9            xfun_0.37               pkgconfig_2.0.3         askpass_1.1             systemfonts_1.0.4       base64enc_0.1-3         rvg_0.2.5              
[28] gfonts_0.2.0            htmltools_0.5.4         openssl_2.0.5           tidyselect_1.2.0        fontBitstreamVera_0.1.1 httpcode_0.3.0          fansi_1.0.4             crayon_1.5.2            withr_2.5.0            
[37] later_1.3.0             crul_1.3                grid_4.2.2              jsonlite_1.8.4          xtable_1.8-4            lifecycle_1.0.3         zip_2.2.2               cli_3.6.0               stringi_1.7.12         
[46] cachem_1.0.6            RcppSimdJson_0.1.9      promises_1.2.0.1        xml2_1.3.3              ellipsis_0.3.2          generics_0.1.3          vctrs_0.5.2             tools_4.2.2             glue_1.6.2             
[55] fontquiver_0.2.1        fastmap_1.1.0           yaml_2.3.7              fontLiberation_0.1.0    ghql_0.1.0              memoise_2.0.1          

I get the following when running on a Windows Virtual Machine

Browse[2]> m_str_extents_("C BELEIDSDOMEIN FINANCIEN EN BEGROTING", "Verdana", 12, TRUE, FALSE, "")
         [,1]     [,2]
[1,] 316.9746 9.087891
Browse[2]> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 14393)

Matrix products: default

locale:
[1] LC_COLLATE=Dutch_Belgium.1252  LC_CTYPE=Dutch_Belgium.1252    LC_MONETARY=Dutch_Belgium.1252 LC_NUMERIC=C                   LC_TIME=Dutch_Belgium.1252    

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] knitr_1.39           tibble_3.1.8         dplyr_1.0.9          magrittr_2.0.3       officedown_0.2.4     data.table_1.14.2    vlaanderen.bct_0.2.0 officer_0.5.2        flextable_0.8.5     
[10] rmarkdown_2.14      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9              graphql_1.5.1           lattice_0.20-45         zoo_1.8-11              V8_4.2.2                assertthat_0.2.1        digest_0.6.29           utf8_1.2.2             
 [9] mime_0.12               R6_2.5.1                cellranger_1.1.0        evaluate_0.15           httr_1.4.4              pillar_1.8.0            gdtools_0.3.1           rlang_1.0.4            
[17] curl_4.3.2              uuid_1.1-0              readxl_1.4.0            rstudioapi_0.14         xslt_1.4.3              stringr_1.4.0           shiny_1.7.2             compiler_4.2.1         
[25] httpuv_1.6.6            xfun_0.31               pkgconfig_2.0.3         askpass_1.1             systemfonts_1.0.4       base64enc_0.1-3         equatags_0.2.0          rvg_0.2.5              
[33] gfonts_0.2.0            htmltools_0.5.4         openssl_2.0.5           tidyselect_1.1.2        fontBitstreamVera_0.1.1 httpcode_0.3.0          fansi_1.0.3             crayon_1.5.1           
[41] later_1.3.0             crul_1.3                grid_4.2.1              jsonlite_1.8.0          xtable_1.8-4            lifecycle_1.0.1         DBI_1.1.3               zip_2.2.0              
[49] stringi_1.7.8           cli_3.3.0               cachem_1.0.6            renv_0.15.5             RcppSimdJson_0.1.8      promises_1.2.0.1        xml2_1.3.3              ellipsis_0.3.2         
[57] generics_0.1.3          vctrs_0.4.1             tools_4.2.1             glue_1.6.2              fontquiver_0.2.1        purrr_0.3.4             katex_1.4.1             fastmap_1.1.0          
[65] yaml_2.3.5              fontLiberation_0.1.0    ghql_0.1.0              memoise_2.0.1          

The Red Hat has

$ sudo yum install -y harfbuzz-devel fribidi-devel
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)                                                                     43 MB/s |  57 MB     00:01    
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)                                                                  39 MB/s |  52 MB     00:01    
Dependencies resolved.
=========================================================================================================================================================
 Package                            Architecture              Version                          Repository                                           Size
=========================================================================================================================================================
Installing:
 fribidi-devel                      x86_64                    1.0.4-9.el8                      rhel-8-for-x86_64-appstream-rpms                     64 k
 harfbuzz-devel                     x86_64                    1.7.5-3.el8                      rhel-8-for-x86_64-appstream-rpms                    181 k
Installing dependencies:
 graphite2-devel                    x86_64                    1.3.10-10.el8                    rhel-8-for-x86_64-appstream-rpms                     46 k

Transaction Summary
=========================================================================================================================================================
Install  3 Packages

Total download size: 291 k
Installed size: 1.7 M
Downloading Packages:
(1/3): graphite2-devel-1.3.10-10.el8.x86_64.rpm                                                                          530 kB/s |  46 kB     00:00    
(2/3): harfbuzz-devel-1.7.5-3.el8.x86_64.rpm                                                                             1.8 MB/s | 181 kB     00:00    
(3/3): fribidi-devel-1.0.4-9.el8.x86_64.rpm                                                                              587 kB/s |  64 kB     00:00    
---------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                    2.6 MB/s | 291 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                 1/1 
  Installing       : graphite2-devel-1.3.10-10.el8.x86_64                                                                                            1/3 
  Installing       : harfbuzz-devel-1.7.5-3.el8.x86_64                                                                                               2/3 
  Installing       : fribidi-devel-1.0.4-9.el8.x86_64                                                                                                3/3 
  Running scriptlet: fribidi-devel-1.0.4-9.el8.x86_64                                                                                                3/3 
  Verifying        : graphite2-devel-1.3.10-10.el8.x86_64                                                                                            1/3 
  Verifying        : harfbuzz-devel-1.7.5-3.el8.x86_64                                                                                               2/3 
  Verifying        : fribidi-devel-1.0.4-9.el8.x86_64                                                                                                3/3 
Installed products updated.

Installed:
  fribidi-devel-1.0.4-9.el8.x86_64                 graphite2-devel-1.3.10-10.el8.x86_64                 harfbuzz-devel-1.7.5-3.el8.x86_64                

Complete!
$ sudo yum install -y freetype-devel libpng-devel libtiff-devel libjpeg-turbo-devel
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)                                                                     57 kB/s | 2.4 kB     00:00    
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)                                                                  71 kB/s | 2.8 kB     00:00    
Package freetype-devel-2.9.1-9.el8.x86_64 is already installed.
Package libpng-devel-2:1.6.34-5.el8.x86_64 is already installed.
Dependencies resolved.
=========================================================================================================================================================
 Package                              Architecture            Version                            Repository                                         Size
=========================================================================================================================================================
Installing:
 libjpeg-turbo-devel                  x86_64                  1.5.3-12.el8                       rhel-8-for-x86_64-appstream-rpms                  109 k
 libtiff-devel                        x86_64                  4.0.9-26.el8_7                     rhel-8-for-x86_64-appstream-rpms                  512 k

Transaction Summary
=========================================================================================================================================================
Install  2 Packages

Total download size: 621 k
Installed size: 1.8 M
Downloading Packages:
(1/2): libjpeg-turbo-devel-1.5.3-12.el8.x86_64.rpm                                                                       1.4 MB/s | 109 kB     00:00    
(2/2): libtiff-devel-4.0.9-26.el8_7.x86_64.rpm                                                                           5.7 MB/s | 512 kB     00:00    
---------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                    6.8 MB/s | 621 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                 1/1 
  Installing       : libtiff-devel-4.0.9-26.el8_7.x86_64                                                                                             1/2 
  Installing       : libjpeg-turbo-devel-1.5.3-12.el8.x86_64                                                                                         2/2 
  Running scriptlet: libjpeg-turbo-devel-1.5.3-12.el8.x86_64                                                                                         2/2 
  Verifying        : libjpeg-turbo-devel-1.5.3-12.el8.x86_64                                                                                         1/2 
  Verifying        : libtiff-devel-4.0.9-26.el8_7.x86_64                                                                                             2/2 
Installed products updated.

Installed:
  libjpeg-turbo-devel-1.5.3-12.el8.x86_64                                       libtiff-devel-4.0.9-26.el8_7.x86_64                                      

Complete!

Any ideas on how I can fix this such that these widths will be the same?

I see there is some UTF-8 handing at https://github.com/davidgohel/gdtools/blob/master/src/font_metrics.cpp#L63-L68 Not sure this is related

jwijffels avatar Mar 08 '23 20:03 jwijffels

The metric is still calculated with cairo, you can check this is the same version with gdtools::version_cairo().

Also, and prior to this, make sure you have and use the same font family (Verdana) on both systems. If not sure, try with gdtools::register_gfont("Open Sans").

davidgohel avatar Mar 10 '23 17:03 davidgohel