wch / extrafont

Tools for using fonts in R graphics
315 stars 48 forks source link

Uses native encoding for the path of the executable of Rttf2pt1 #85

Closed gabrielmagno closed 3 years ago

gabrielmagno commented 3 years ago

Bug Description

If I have a Windows user name with "special" characters like accents (e.g. flávia), the path where the executable of Rttf2pt1 is installed might have "special" characters as well. In the current version of extrafont, we would get this error when calling font_import():

Scanning ttf files in C:\Windows\Fonts ...
Extracting .afm files from .ttf files...
C:\Windows\Fonts\AGENCYB.TTFError in system2(ttf2pt1, c(args, shQuote(ttfiles[i]), shQuote(tmpfiles[i])),  :
  '"C:/Users/flávia/Documents/R/win-library/4.0/Rttf2pt1/exec/ttf2pt1.exe"' not found

As we can see, the path of the executable was wrongly encoded (it should be C:/Users/flávia/Documents/R/...).

Solution

I propose to convert the Rttf2pt1's path received from which_ttf2pt1() to the native encoding of the system, which should be the encoding of the path string passed to the system2 function. We can do that by symply calling enc2native. If the string is already in the correct encoding (e.g. UTF-8 in Linux), it will not be modified and will keep its current encoding. Code sample:

system2(enc2native(ttf2pt1), ...)
wch commented 3 years ago

Thanks. Can you add an item to the NEWS file?

gabrielmagno commented 3 years ago

@wch Sure. Which version should I label it?

gabrielmagno commented 3 years ago

@wch done. I've added a self-credit note to myself, hope that is ok 😄

wch commented 3 years ago

Looks good, thanks!