Comments (18)
Hm, that is strange. The first thing to try is to delete your existing font database by reinstalling the extrafontdb package:
install.packages('extrafontdb')
# Restart R, then re-import fonts
library(extrafont)
font_import()
loadfonts()
If you still have a problem, then my next theory is that it has something to do with Asian font paths.... I wonder if there's something odd in your Fontmap file. Please run this to get the path to that file:
file.path(extrafont:::fontmap_path(), "Fontmap")
# "/Users/winston/R/extrafontdb/fontmap/Fontmap"
If you look inside that file, do you see any strange paths or filenames? For example, here are some lines from my version of that file:
/CMRoman-Bold (/Users/winston/R/fontcm/fonts/outlines/fcmb8a.pfb) ;
/CMRoman-BoldItalic (/Users/winston/R/fontcm/fonts/outlines/fcmbi8a.pfb) ;
/CMRoman-Italic (/Users/winston/R/fontcm/fonts/outlines/fcmri8a.pfb) ;
/CMRoman-Regular (/Users/winston/R/fontcm/fonts/outlines/fcmr8a.pfb) ;
...
/-Keyboard (/System/Library/Fonts/Keyboard.ttf) ;
...
/Georgia-Bold (/Library/Fonts/Georgia Bold.ttf) ;
/Georgia-BoldItalic (/Library/Fonts/Georgia Bold Italic.ttf) ;
/Georgia-Italic (/Library/Fonts/Georgia Italic.ttf) ;
/Impact (/Library/Fonts/Impact.ttf) ;
Also, you may want to check the output of fonttable()
to see if anything looks weird there.
from extrafont.
Thanks.
The Fontmap
file looks fine, and here is the output of fonttable()
> subset(fonttable(), FontName == "Impact")
package afmfile fontfile FullName FamilyName FontName Bold Italic Symbol afmsymfile
72 NA Impact.afm.gz /Library/Fonts/Impact.ttf Impact Impact Impact FALSE FALSE FALSE NA
Here is the trace of the cmd
in embedFonts
:
> trace(embedFonts, quote(print(cmd)), at = 12)
Tracing function "embedFonts" in package "grDevices"
[1] "embedFonts"
> unload(inst("extrafont"))
> library(extrafont)
> embed_fonts("font_plot.pdf", outfile="font_plot_embed.pdf")
Tracing embedFonts(file = file, format = format, outfile = outfile, options = paste(paste("-I", .... step 12
[1] "gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=/var/folders/na/na81MsJUHRmVyCHG4xD0X++++TI/-Tmp-//RtmpByAuFz/Rembed53e685a1258 -sFONTPATH= -I'/Library/Frameworks/R.framework/Versions/2.15/Resources/library/extrafontdb/fontmap' 'font_plot.pdf'"
The cmd
looks wired.
[1] "gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=/var/folders/na/na81MsJUHRmVyCHG4xD0X++++TI/-Tmp-//RtmpByAuFz/Rembed53e685a1258 -sFONTPATH= -I'/Library/Frameworks/R.framework/Versions/2.15/Resources/library/extrafontdb/fontmap' 'font_plot.pdf'"
especially for -sFONTPATH=
maybe this is the problem by using different version of gs
?
> system("gs --version")
9.05
> system("gs --help")
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
from extrafont.
And this command (from shell) can generate the embedded pdf.
gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=/var/folders/na/na81MsJUHRmVyCHG4xD0X++++TI/-Tmp-//RtmpukJoUm/Rembed64d5d8cefdf -sFONTPATH=/Library/Fonts 'font_plot.pdf'
then, this induces the same error:
gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=/var/folders/na/na81MsJUHRmVyCHG4xD0X++++TI/-Tmp-//RtmpukJoUm/Rembed64df005022 -sFONTPATH=/Library/Fonts -I'/Library/Frameworks/R.framework/Versions/2.15/Resources/library/extrafontdb/fontmap' 'font_plot.pdf'
So, -I'/Library/Frameworks/R.framework/Versions/2.15/Resources/library/extrafontdb/fontmap'
is doing something wired.
from extrafont.
My cmd
looks the same:
> embed_fonts("font_plot.pdf", outfile="font_plot_embed.pdf")
Tracing embedFonts(file = file, format = format, outfile = outfile, options = paste(paste("-I", .... step 12
[1] "gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=/var/folders/26/df_1sr1d2w1_x179whkc7xxw0000gn/T//Rtmp4E8FlX/Rembedc0f0441dd951 -sFONTPATH= -I'/Users/winston/R/extrafontdb/fontmap' 'font_plot.pdf'"
The -I
option points it to the Fontmap file, and that file contains the font path for each font. I still wonder if your Fontmap file has something strange in it. Here is another experiment to try (two options):
- Delete every line in Fontmap except the line for Impact.
- Re-install extrafontdb, and then run
font_import(pattern="Impact")
.
from extrafont.
Still not fixed. Could you please show the output of gs -h
?
from extrafont.
Just in case this is the content of Fontmap
:
/Impact (/Library/Fonts/Impact.ttf) ;
now there is only 1 line.
from extrafont.
Finally I may figure out the reason. It may be the format of path.
[takahashi@haruna extrafont]$ gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -I/Users/takahashi/tmp/fontmap -sDEVICE=pdfwrite -sOutputFile=f2.pdf 'font_plot.pdf'
[takahashi@haruna extrafont]$ gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -I/Library/Frameworks/R.framework/Versions/2.15/Resources/library/extrafontdb/fontmap -sDEVICE=pdfwrite -sOutputFile=f2.pdf 'font_plot.pdf'
*** Warning: GenericResourceDir doesn't point to a valid resource directory.
the -sGenericResourceDir=... option can be used to set this.
The contents of the fontmap
folder is same.
I couldn't find any reference of the format of the path for gs resource dir, but only difference is the name of path...
Probably this is less related to the extrafont itself.
from extrafont.
Finally I figured out. The -I
options cannot correctly handle the path including the string "Resources"
[takahashi@haruna extrafont]$ gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -I/Users/takahashi/tmp/Resources/x -sDEVICE=pdfwrite -sOutputFile=f2.pdf 'font_plot.pdf'
*** Warning: GenericResourceDir doesn't point to a valid resource directory.
the -sGenericResourceDir=... option can be used to set this.
gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -I/Users/takahashi/tmp/zesources/x -sDEVICE=pdfwrite -sOutputFile=f2.pdf 'font_plot.pdf'
[takahashi@haruna extrafont]$ gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -I/Users/takahashi/tmp/zesources/x -sDEVICE=pdfwrite -sOutputFile=f2.pdf 'font_plot.pdf'
[takahashi@haruna extrafont]$
Could you please test this?
This is definitely the bug of gs..., but the R library path in OSX includes "Resources", some dirty hack may be necessary.
from extrafont.
Wow, I think you're right:
$ gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=out.pdf -sFONTPATH= -I'/Users/winston/temp/Resources/fontmap' 'font_plot.pdf'
*** Warning: GenericResourceDir doesn't point to a valid resource directory.
the -sGenericResourceDir=... option can be used to set this.
**** Error reading a content stream. The page may be incomplete.
**** File did not complete the page properly and may be damaged.
**** Warning: File has unbalanced q/Q operators (too many q's)
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> R 2.15.2 <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
$ gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=out.pdf -sFONTPATH= -I'/Users/winston/temp/esources/fontmap' 'font_plot.pdf'
Here's a hack that seems to work for me: use resources
instead of Resources
:
gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=out.pdf -sFONTPATH= -I'/Users/winston/temp/resources/fontmap' 'font_plot.pdf'
Yuck. But it works. (Assuming a case-insensitive HFS filesystem)
from extrafont.
Yes, resource
works also for me. Thanks.
Then, should the fixpath_os
like this?
function (path)
{
if (grepl("^mingw", sessionInfo()$R.version$os)) {
gsub("/", "\\\\", path)
} elseif (grepl("darwin", R.version$os) {
gsub("Resources", "resources")
}
else {
path
}
}
from extrafont.
I think something like that should work, but it should be done outside of that function, and inside embed_fonts
instead. This is because fixpath_os
should be usable in other places where the Resources
hack is unnecessary.
from extrafont.
Hm, now that I think about it a bit more, it might be better to create a symlink to the fontmap directory in the temp dir. This is because the resources
hack won't work for computers with case-sensitive HFS+ filesystems.
from extrafont.
Hm, now that I think about it a bit more, it might be better to create a symlink to the fontmap directory in the temp dir.
agreed. Then, in embed_fonts
,
- copy the
Fontmap
into a temp dir. - run embedding with fontmap of the temp dir
- remove the
Fontmap
in the temp dir.
make sense.
from extrafont.
OK, I pushed a fix in the fix-fontmap
branch, but I haven't tested it. Can you try it and tell me if it works?
from extrafont.
Excellent, works perfectly!!
Thanks.
from extrafont.
Thanks for your help figuring out the problem and a fix!
I made a small change and merged it into master. Can you test the master branch?
from extrafont.
The test on the master branch is ok!!
Thanks for your excellent work!
from extrafont.
Great, thank you!
from extrafont.
Related Issues (20)
- Easy speed-up possible? HOT 1
- No Fontname. Skipping, for all of my fonts in Windows? HOT 1
- package ‘extrafonts’ is not available (for R version 4.0.2) HOT 1
- `argument is of length zero` error in `afm_scan_files`
- wish: sort `fonts()` alphabetically HOT 1
- new font is ignored
- Using extrafont within knitr to pdf HOT 1
- windowFonts() not recognized in .Rprofile HOT 3
- how to install the font of "Young" in Mac?
- "GhostScript was not found" on M1 Big Sur Mac HOT 2
- Correctly finds font directory, but says "No FontName. Skipping" for all fonts HOT 29
- font_import segfaults. HOT 3
- a problem when I ues font_import
- Installing a font from .otf/.ttf files
- Seek replacement for `ttf2pt1` for extracting font metrics HOT 2
- "Found FontName for 0 fonts." on 64-bit Windows OS
- Type1 importing not working
- Can´t load dinpro light
- Font embedding not working due to GhostScript `-I` switch
- Font is embeded, but i can not document properly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from extrafont.