How to know the character string to be specified in local of #font-face only with Windows7 function - windows-7

The local function requires a postscript name or a full font name as an argument:
For OpenType and TrueType fonts, this string is used to match only the Postscript name or the full font name in the name table of locally available fonts. ref
However, when I opened the font file in Notepad, I couldn't find these names or even the name table. Is there a way to view the name table in the font file using only the functions provided in Windows7?

The Postscript name of a font was not intended for use by end users, and so you won't see it exposed anywhere in Windows 7 or in Windows 10.
If you need to find the Postscript name of a font, then you should use a font inspection utility that is intended for more specialized user scenarios. Here are a couple of free utilities that you could use:
SIL ViewGlyph — see View Names in the Options menu
BabelMap — see Font Information in the Fonts menu

Related

Italic and bold Latin, and Greek letters using custom unicode font in gnuplot to produce (e)ps or pdf

I would like to create a postscript or pdf figure with enhanced notations, italic or bold Latin characters, and sometimes (regular) Greek characters. How to do that in general?
Let's say I downloaded CMU Sans Serif, a font that has glyphs for all the strange characters I ever want to use. I converted them to pfa with an online tool and copied the files to the path of working directory.
Expectations
Let's say I'd like to produce the following notation somewhere.
What I tried: original
I create a gnuplot script encoded in a utf-8 file (without BOM) with the content
set term postscript eps enhanced "CMUSansSerif" 15 fontfile add 'CMUSansSerif.pfa' fontfile add 'CMUSansSerif-Oblique.pfa' fontfile add 'CMUSansSerif-Bold.pfa'
set encoding utf8
set o "print.eps"
p x t "Label: {/CMUSansSerif-Bold important }{/CMUSansSerif-Oblique note}: ∫⟨α₂ + β²⟩ = äßű"
set o
and executed with the newest gnuplot, version 5.2.6.
What I got
I used a vector graphics editor to open the eps file and relevant part looks like this:
What I also tried
According to Ethan's answer I added adobeglyphnames to the termoptions. It made at least the letters available but other Unicode symbols are still unavailable. The result is:
Question
What went wrong? How could I produce the desired output?
So many possibilities, where things can go wrong: Is the font not suitable for this task? Did I download a wrong version of it? Did the pfa converter do a bad job? Did I include the font files incorrectly? Was there something wrong with the set encoding? Do I use a bad vector graphics editor? Do I have wrong fonts installed and the vector graphics editor tries to use them?
I am afraid that the answer is that in general PostScript is the wrong tool for this. If it is at all possible for you to work with PDF output instead, I suggest you do that. It is even possible the resulting PDF file can be translated to a PostScript file by standard tools (e.g. pdf2ps). That is likely to work if the non-ascii characters are limited to Greek and other relatively common symbols but I don't know how much of the full unicode tables are covered by those standard tools.
If you really need to produce PostScript with additional unicode characters directly from gnuplot, you can find full instructions and sample character encoding tables in the gnuplot distribution files:
.../term/PostScript/unicode_maps.README
.../term/PostScript/unicode_big.map
.../term/PostScript/unicode_small.map
I am not familiar with the online tool font conversion you used but probably it failed because it did not have, or at any rate did not use, suitable character encoding tables for the desired conversion.
===
One other thought. There are two ways that a *.pfa font can encode unicode characters that are common enough to have a name assigned by Adobe for use in PostScript. (1) It may use generic names like uni0439 for Unicode code points. (2) It may use Adobe-specific names from the list here:
agl-aglfn glyph list
When selecting PostScript output from gnuplot you can tell it which of these two conventions is used by the font you provide. The default is "noadobeglyphnames".
set term postscript {no}adobeglyphnames
==
(recipe for using "set term pdfcairo")
Font handling is unfortunately system-specific, so I cannot tell you how to install or configure fonts on all your target machines. I will show you a procedure that works on a linux desktop that uses the fontconfig utilities for system font handling.
Create directory /home/share/fonts/CMUSans
Add this directory to the search list in file /etc/fonts/local.conf
Copy *.ttf files into this directory from the CMU Sans Serif zip archive you link to in your original query. The system fontconfig system tools should now be able to find these fonts. By inspection they self-report as "CMU Sans Serif"
in gnuplot (tested with version 5.2.6)
set term pdfcairo font "CMU Sans Serif,15"
set output 'enhanced_utf8.pdf'
load 'enhanced_utf8.dem'
convert output pdf file to PostScript with the following command
pdf2ps enhanced_utf8.pdf enhanced_utf8.ps
Screenshot of the result is shown below
It seems that CMU Sans Serif doesn't contain the UTF-8 characters you are asking for. Check the font with a font editor like Birdfont. Although the webpage shows symbols you want to use, the font itself does not contain them. However, your browser may show symbols, but they are just fallback representations from other fonts.

How can I get the original font name of some text using PDFKit?

I wrote a script which parses information from PDF files and outputs it to HTML. It's written in Python, using pdfminer.
On some text segments, the font style can have semantic significance. For instance: bold, italic and color should trigger different behavior. Pdfminer provides scripts with the font name, but not the color, and it has a number of other issues; so I'm working on a Swift version of that program, using Apple's PDFKit, to extract the same features.
I now find that I have the opposite problem. While PDFKit makes it easy to retrieve color, retrieving the original font name seems to be non-obvious. PDFSelection objects have an attributedString property, but for fonts that are not installed on my computer, the NSFont object is Helvetica. Of course, the fonts in question are fairly expensive, and acquiring a copy just for this purpose would be poor form.
Short of dropping to CGPDFContentStream (which is way too big of a hammer for what I want to get), is there a way of getting the original font name? I know in advance what the fonts are going to be, can I use that to my advantage?
PDFKit seems to use the standard font lookup system and then falls back on some default, so this can be resolved by spoofing the font to ensure that PDFKit doesn't need to fall back. Inspecting the document, I was able to identify that it uses the following fonts (referenced with their PostScript name):
"NeoSansIntel"
"NeoSansIntelMedium"
"NeoSansIntel,Italic"
I used a free font creation utility to create dummy fonts with these PostScript names, and I added them to my app bundle. I then used CTFontManagerRegisterFontsForURLs to load these fonts (in the .process scope), and now PDFKit uses these fonts for attributed strings that need them.
Of course, the fonts are bogus and this is useless for rendering. However, it works perfectly for the purpose of identifying text that uses these font.

How to use different styles of local fonts in plots with Gadfly in Julia-lang on Mac?

I want to create plots with Gadfly in Julia programming language using a specific font style (e.g., Avenir Next Bold) of a local font (Avenir Next) on my Mac. It works for the standard font style in the case of an standard histogram example:
using Gadfly
plot(x=randn(2000), Geom.histogram(bincount=100),
Theme(minor_label_font="Avenir Next",
major_label_font="Avenir Next",
key_label_font="Avenir Next"))
Yet when a specific font style such as "Avenir Next Bold" is used the default font is applied instead of the provided one. The Avenir Next fonts are saved as a "container" in a ttc format. I tried to convert the ttc file into single ttf files for the font styles and to call the exact paths where the files are located. Both don't work.
I think this is a case of getting the font name exactly right.
(I used HeavyItalic because it's easier to tell if the correct font is chosen.)
It might be that you have to use the PostScript font name, although I'm not sure why that would be, unless deep down in Cairo that's how fonts are accessed... ?
You can get the PostScript names (if that's what they are) by looking at a font manager. For example, FontBook shows them on the info panel:

Ghostscript - can we substitute to ignore embedded fonts in PS?

I am trying to convert a Postscript file to PDF. The PS file has an embedded font that I want to ignore and substitute with a local system font. This is because the font is OCR based and it makes more sense to read the character strings in this case.
I set up a Fontmap file but it only works when I delete the font data from the PS file, so that the font is actually missing. Is there a way to do this without modifying the PS file?
There is no switch or command to do this for the very good reason that it would break conformance with the specification. If you embed a font in a PostScript program that font will be used in preference to any other font.
This allows you (for example) to use specific versions of a font by embedding them, rather than relying on the font present in the interpreter which may be different.
However, because PostScript is a programming language, you could redefine the 'definefont' operator so that it examined the dictionary operand for the FontName, before defining the font, and if it is the font you want to ignore you could fail to define it. You would then go through the missing font machinery which would find your substitute.

TTF/OTF font selection in R for windows: onscreen vs pdf()

I know that in R on Linux or Mac, fonts are consistently defined as an argument family="Charis SIL" to par(), text(), or one of the graphic device functions like tiff(), svg(), etc (substitute "Charis SIL" with whatever font name you want). I also know that on Windows, that only works for the cairo_pdf() and svg() devices; raster graphic devices like jpeg(), tiff(), png(), and bmp() require that the font be mapped in the "Windows font database" first:
# this doesn't work on windows
jpeg(filename='test1.jpg', family='Charis SIL')
plot(0,0,type='n',ann=FALSE,frame.plot=FALSE)
text(0,0,labels='iyeøɛœaɶɪʏæɑɒʌɔɤoɯuʊɨʉɘɵəɜɞɐɚɝ')
dev.off()
# (gives warnings: Font family not found in Windows font database)
# this does work on windows (assuming you have the Charis SIL font installed)
windowsFonts(myCustomWindowsFontName=windowsFont('Charis SIL'))
jpeg(filename='test2.jpg', family='myCustomWindowsFontName')
plot(0,0,type='n',ann=FALSE,frame.plot=FALSE)
text(0,0,labels='iyeøɛœaɶɪʏæɑɒʌɔɤoɯuʊɨʉɘɵəɜɞɐɚɝ')
dev.off()
The pdf() device is different still: it seems to need fonts defined in either the postscriptFonts() and/or pdfFonts() database, which means only Type1 fonts:
# this doesn't work on windows
pdf('test.pdf', family='Charis SIL')
# gives error: Unknown family "Charis SIL"
# this doesn't work either
windowsFonts(myCustomWindowsFontName=windowsFont('Charis SIL'))
pdf('test.pdf', family='myCustomWindowsFontName')
# gives error: Unknown family "myCustomWindowsFontName"
# this also won't work
pdf.options(family='Charis SIL')
pdf('test.pdf')
# gives error: Invalid font type
# also gives warning: font family "Charis SIL" not found in Postscript font database
Ordinarily this would not matter, because cairo_pdf() is a fine substitute for the pdf() device and handles TTF and OTF fonts just fine. The problem is that if a user plots to the onscreen device and then uses the menu commands to save as PDF, it appears to call pdf() instead of cairo_pdf(), which then throws errors:
# this part works
windowsFonts(myCustomWindowsFontName=windowsFont('Charis SIL'))
par(family='myCustomWindowsFontName')
plot(0,0,type='n',ann=FALSE,frame.plot=FALSE)
text(0,0,labels='iyeøɛœaɶɪʏæɑɒʌɔɤoɯuʊɨʉɘɵəɜɞɐɚɝ')
# but menu command "File > Save As > PDF" gives errors:
# Error: Invalid font type
# Warning: font family "Charis SIL" not found in Postscript font database
This is a problem because the R package I'm developing keeps failing "R CMD check" on Windows, apparently because the example code generates on-screen output that gets saved out as PDF automatically, which generates the above-mentioned errors. One solution is to give up custom fonts for the on-screen devices in Windows (i.e., just ignore the "family" argument if the chosen output is "screen"). Another option is to use the Cairo() package for onscreen plotting, but I'd prefer to stick with base graphics if I can. Is there any way I can get custom fonts in an onscreen plot and not have it throw errors when using the "save as PDF" menu commands?
The way I eventually solved this was as follows:
oldSans <- windowsFonts()$sans
windowsFonts(sans=windowsFont('Charis SIL'))
par(family='sans') # this line isn't necessary anymore
plot(0,0,type='n',ann=FALSE,frame.plot=FALSE)
text(0,0,labels='iyeøɛœaɶɪʏæɑɒʌɔɤoɯuʊɨʉɘɵəɜɞɐɚɝ')
windowsFonts(sans=oldSans)
In this way, the correct font will be used in the on-screen window, and when the user uses the menu commands to save as PDF, the PDF will get saved out but with the default sans font instead of the custom one. It is a "solution" only in the sense that the PDF does get exported, but if the plot has non-ASCII glyphs there is no guarantee that they'll show up in a PDF generated in this way. It is also arguably WORSE than the original situation, because the action no longer throws an error or even a warning. The moral of the story: don't rely on the menu commands in your GUI to do things that you should know how to do in the console.

Resources