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

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:

Related

How to Name TTF Properly

I am having trouble with something that appears to be trivial, namely how to name a font, so that I get multiple styles of the same font to tile, display nicely, import nicely using Inno Script Studio, work with C#, not to mention applications.
For instance, here is an Adobe font that work nicely, first what I see in Control Panel, then the TTF details. I will then show what I did with my font and how I do not see the exact same thing, even though I did seemingly the same thing.
Adobe Source Sans Pro Tiles
Adobe Source Sans Pro Details
Adobe Source Sans Pro Semibold: The purpose of a screenshot is to show what I see from the actual TTF using Birdfont font editor, plus version.
Here is the black:
PostScript Name: SourceSansPro-Black
Name: Source Sans Pro
Style: Black
Full Name: Source Sans Pro Black
Here is how I named the font that I am using on my project. The font name, Venera, is the font family and then these are the styles: 100 Extra Light, 300 Light, 500 Medium, 700 Bold, and 900 Black.
BTW, I tried with the numbers, without the numbers, with spaces, and no spaces. There was no combination that worked like what I see with the Adobe font.
PostScript Name: Venera-900Black
Name: Venera
Style: 900 Black
Full Name: Venera 900 Black
Here is the bold:
PostScript Name: Venera-700Bold
Name: Venera
Style: 700 Bold
Full Name: Venera 700 Bold
I did think that maybe styles cannot have embedded spaces, so I tried both 700Bold / 900Black as the Style and even just Bold / Black. The latter was my thought that Windows does not support numbers s part of style names.
What I see is the fonts not overlapping like Adobe, but stacked. One has to delete the TOP font to see that there is a font underneath. Needless to say, Word in such a case does not see both fonts.
Here is what I see after I install the 700 Bold bold font and then the 900 Black font. I took this screenshot after installing the 700 Bold style and before installing the 900 Black style, but the image is identical to what I see after 900 Black. The order makes no difference, I have to delete one font to see the other. The fonts are not stacked like what I see with Adobe. Restarting the computer makes no difference. Removing the numbers or spaces make no difference.
Image with BOTH fonts, just one would never know it from the screenshot.
I suspect that when I get this first part working that Inno Script wants the full name and not the font name as stated in the help material and pages here in SO, but first things first. I need to get the font behaving.
For whatever it is worth, I can set the style to Regular and then set the font name to: Venera700Bold and Venera900Black. I would then wind up with two different fonts that show Venera700Bold Regular and Venera900Black Regular in Control Panel. Inno Script Studio is then quite happy accepting Venera700Bold and Venera900Black as the font name in the Files section.
It is tempting to use this answer, but all the fonts are the same family and I would really rather do things the right way and not subject users to different fonts, especially when I have 7 different Avenir fonts that I have to do the same thing for.
The answer should be Font Name is alphanumeric with however many spaces. The style is alphanumeric with however many spaces. The full name, as the editor says is the concatenation of the font name and style. The unique name and PostScript name must have no spaces and have the style separated from the font name by a dash. Sadly, this recipe, which works for others, such as the Adobe font that I picked at random, does not work for me, so I am missing a piece to the puzzle in my understanding.
Thoughts?
The style names should not include the numeric weight values. The numeric values should only go into the font's 'OS/2' table, not in the name strings. If you include the numbers in the style string, then the OS or apps will probably get confused, treating the number as part of the family name.
If you tried just using "Bold", "Black" as the style names and that's not working, then I would suspect the tool used to create the fonts.

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.

Text in QTextEdit is distorted

I have a QTextEdit in which I want to set some text (unicode) that has been generated by an ASCII Art text renderer. Everything works fine, except that the QTextEdit is distorting the text. The screenshot shows the same unicode text variable set in the QTextEdit via setText() and logged to the console, where it is displayed correctly.
It doesn't seem to matter if I use QTextEdit or QPlainTextEdit, or if I am setting the text via setText(ascii_art_text) or setPlainText(ascii_art_text). I'm using PySide here, however I suspect that isn't of too much interest in this case.
Any ideas how to fix that distortion?
From the looks of your example, it appears that your QTextEdit is not using a monospaced font which is what terminals and text editors typically use. Create a QFont using a monospaced font. E.g.,
# Specific Windows monospaced font.
font = QFont("Courier New")
According to Torsten Marek's answer in How to specify monospace fonts for cross platform Qt applications?, you can get a cross platform monospaced font with:
font = QFont("Monospace")
font.setStyleHint(QFont.TypeWriter)
Once you've determined your font, assign it to your QTextEdit:
text_edit.setCurrentFont(font)

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.

Resources