Open jxchong opened 11 years ago
Two things to check:
loadfonts()
?loadfonts()
, does the font show up when you run str(pdfFonts(), max.level=1)
?Yes I ran loadfonts before, actually tried both: loadfonts() loadfonts(device="postscript")
I think the namespace conflict might have been related to the fact that I tried installing the github extrafont install first (wanted to try an OTF font). So, I manually deleted the package folder for extrafont and extrafontdb from the R folder and then reinstalled extrafont.
After starting from a clean slate, I tried to reimport Roboto and a second Google Font download (Open Sans).
font_import(paths="~/Dropbox/Public/Exported Fonts", recursive=TRUE, prompt=FALSE)
Scanning ttf files in ~/Dropbox/Public/Exported Fonts ... Extracting .afm files from .ttf files...~/Dropbox/Public/Exported Fonts/Open_Sans/OpenSans-Bold.ttf => ~/Library/R/3.0/library/extrafontdb/metrics/OpenSans-Bold ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-Black.ttf => ~/Library/R/3.0/library/extrafontdb/metrics/Roboto-Black
[…] Found FontName for 22 fonts. Scanning afm files in /Users/jxchong/Library/R/3.0/library/extrafontdb/metrics Writing font table in /Users/jxchong/Library/R/3.0/library/extrafontdb/fontmap/fonttable.csv Writing Fontmap to /Users/jxchong/Library/R/3.0/library/extrafontdb/fontmap/Fontmap... There were 50 or more warnings (use warnings() to see the first 50)
warnings() Warning messages: 1: In readLines(fd, 30) : seek on a gzfile connection returned an internal error 2: In grepl("^FamilyName", text) : input string 4 is invalid in this locale 3: In grepl("^FontName", text) : input string 4 is invalid in this locale 4: In grepl("^FullName", text) : input string 4 is invalid in this locale 5: In grepl("^Weight", text) : input string 4 is invalid in this locale
loadfonts() Open Sans already registered with pdfFonts(). Open Sans Extrabold already registered with pdfFonts(). Open Sans Light already registered with pdfFonts(). Open Sans Semibold already registered with pdfFonts(). Warning message: In loadfonts() : More than one version of regular/bold/italic found for Roboto. Skipping setup for this font.
When I run the second command:
str(pdfFonts(), max.level=1) $ Open Sans :List of 3 ..- attr(, "class")= chr "Type1Font" $ Open Sans Extrabold :List of 3 ..- attr(, "class")= chr "Type1Font" $ Open Sans Light :List of 3 ..- attr(, "class")= chr "Type1Font" $ Open Sans Semibold :List of 3 ..- attr(, "class")= chr "Type1Font"
(but no Roboto)
Now pdf("test.pdf", width=4, height=7, family="Open Sans") does work (though Roboto doesn't work)
On Thursday, April 11, 2013 at 1:35 PM, Winston Chang wrote:
Two things to check: Did you run loadfonts()? After running loadfonts(), does the font show up when you run str(pdfFonts(), max.level=1)?
— Reply to this email directly or view it on GitHub (https://github.com/wch/extrafont/issues/26#issuecomment-16259619).
I just rebased and pushed the freetype branch. If you want to try that, install that and the freetype2 branch of Rttf2pt1.
As for Roboto, the issue is this: extrafont doesn't know how to distinguish between Roboto Black, Roboto Light, and plain Roboto. The FamilyName entry in all of these is just "Roboto". R wants each font family to have a regular, bold, italic, and bold-italic version, but Roboto doesn't fit this scheme. Here are all the different versions:
Roboto Regular
Roboto Bold
Roboto Italic
Roboto Bold Italic
Roboto Black
Roboto Black Italic
Roboto Light
Roboto Light Italic
Roboto Medium
Roboto Medium Italic
Roboto Thin
Roboto Thin Italic
Probably the best solution is to edit the font table so that the FamilyName entry for the Black version is "Roboto Black" instead of "Roboto". Or you could delete those entries. The font table file should be in the directory returned by system.file("fontmap", "fonttable.csv", package="extrafontdb")
.
Unfortunately, I don't see a straightforward way of automating font imports so it knows how to handle cases like this.
Thanks, just to clarify, it's the Robot Black, Light, Medium, and Thin ones that are the problems? So if I edit the font table to make those have their own distinct family names, that should fix the conflict?
Yes, I think that should do the trick.
I just ran into the same problem. If it can't be fixed automatically, it would at least nice to get a warning instead of silently ignoring the font so the user can fix the problem by hand.
There are quite a few fonts can't be loaded automatically due to this same problem (e.g. Linux Libertine, Merriweather, Signika) so I don't think this is a particularly rare occurrence.
Hi! I just ran into the same problem, using another font. Is there a way to fix this automatically? Kind regards, Jana
Would a fix be replacing FamilyName
with FullName
if there are duplicated font names?
I followed the instructions and installed the Robot font family (downloaded from Google Fonts), but I can't seem to get pdf() to recognize the font.
When I type subset(fonttable(), FamilyName == "Roboto"), it seems to show that the font is loaded, but when I try to generate the pdf, I get an error:
This might be related. After I quit and restarted R library(extrafont) Error : .onAttach failed in attachNamespace() for 'extrafont', details: call: (function (...) error: invalid arguments in 'pdfFonts' (must be font names) Error: package or namespace load failed for ‘extrafont’