使用extrafont软件包检索Windows字体后,字体表仍为空

时间:2017-09-04 09:50:00

标签: r pdf fonts

为了将带有字体名称Calibri的ggplots保存到pdf文件,我尝试使用extrafont包,以便能够在ggplot2中使用此字体类型。

这些是我采取的步骤:

font_import()

获得所有字体后(在此过程中似乎没有任何错误),我收到此错误:

Scanning afm files in <<library path>>/extrafontdb/metrics
Error in if (grepl("Bold", weight)) { : argument is of length zero

以及这些错误:

Warning messages:
1: In readLines(srcfile) :
  invalid input found on input connection 'C:<<path>>\AppData\Local\Temp\26\RtmpANG4o2/fonts/ahronbd.afm'
2: In readLines(srcfile) :
  incomplete final line found on 'C:<<path>>\AppData\Local\Temp\26\RtmpANG4o2/fonts/ahronbd.afm'

etc. 

当我运行此代码时:

loadfonts()
fonts()

输出为NULL

当我尝试使用ggsave()将ggplot保存为pdf时,错误显示:

Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
  invalid font type

我猜最后一个错误并不令人惊讶,因为字体表似乎是空的。

这里出了什么问题以及如何解决这个问题?

编辑我以为我找到了解决方案。当我使用loadfonts(device="win")代替loadfonts()时,一开始似乎都很顺利,但我错了。 fonts()仍然是空的。

1 个答案:

答案 0 :(得分:0)

对于在那里的任何激怒搜索,我在Windows上都遇到了同样的问题,并通过以下方法解决了该问题:

vid = videoinput('winvideo', 2);

triggerconfig(vid, 'manual');
vid.TriggerRepeat = inf;
vid.FramesPerTrigger = 1;

start(vid);
trigger(vid);

img = getdata(vid);
h = imshow(img);

while (condition)
    trigger(vid);
    img = getdata(vid);
    h.CData = img;
end

stop(vid);
delete(vid);

现在应该填充font_import(paths = "C:/Path_to_font") 。我在字体预览和相关设置中找到了字体的路径,然后单击相关的字体。大概大多数字体都在同一位置。