OSX activate PFA/PFB fonts with ATSFontActivateFromMemory - macos

I am trying to find a way to activate PC PFA/PFB PostScript font on OS X by code. CTFontManagerRegisterFontsForURL works only for TTF and OTF, but I was wondering if ATSFontActivateFromMemory could not be used, as it is described as :
You use this function to activate a streamed font, such as a font contained in a PDF file. Your application must first map the streamed font data to memory and then pass the address of the font data in memory to the function ATSFontActivateFromMemory.
I could load the font data and point to it. So far no joy, but I wonder if someone here would have any pointers.

Related

Direct2D: How to convert fallback to SystemLink mode?

I am now converting a project's render engine from GDI to D2D. The GDI use "CreateFontIndirect" to assign font size "-13", font family "Segeo UI". The D2D use "CreateTextFormat" to assign font size "13", font family "Segeo UI". The effect is shown as follow picture:
In GDI case, the system didn't find chinese character in "Segeo UI", it will find in regedit "SystemLink" to locate the chinese font, on my machine is "YaHei". But In D2D case, the system didn't find "YaHei", Which chinese font it will choose to draw, How does it work?
It works according to DirectWrite layout logic. See IDWriteTextLayout2::SetFontFallback(), you'll be able to provide your own fallback implementation, if default configuration is not satisfactory.
Basically, layout object will call your custom fallback methods to map characters to fonts, you can then detect which characters you want to map to which font, potentially reusing system fallback implementation for cases you don't care about.

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:

Why same font size show different actual size in different editors?

Environment: Mac OS El Capitan; MBP 2012-Mid 15'.
Same problem on both built-in LCD and external LCDs. I have tried with 3 external monitors. Also same problem on another MBP with Retina internal LCD. Also, same problem occurs no matter the resolution is scaled, not scaled, or HiDPI.
As the screenshot shows, same font name + same font size + same text + same screen has different visual width in different text editors. I have tried to tune one of the font size to be like 14.1/13.9/etc, but not works, the text is either too small/narrow or too big/wide; what's more, some editors cannot use fraction font size.
Q1: How to show exactly same visual size for same font size?
Q2: Looks like there are two font rendering engines in the OS? If yes, how to specify which one to use for specified app or for all apps?
Thanks a lot.

Cocoa - How to extract data from otf file?

I would like to know how to extract the metadata of an otf file. For example :
chrono number of the glyphs (ex: 001, 002...)
associated unicode in hexadecimal
etc..
Applications like "Font Examiner" can do it :
Font Examiner
Thanks in advance
If this were my problem I'd probably want to solve it using as much public and/or open source code as possible.
For example, you can use the FreeType library (which apparently compiles for both Macintosh & iOS to load the .otf font, then you can get the metadata off the loaded face (e.g. the num_glyphs attribute in FTFace_rec).
If you can load the font into a NSFont or UIFont instance, you do have access to a numberOfGlyphs and a coveredCharacterSet property (the latter shows the characters a font can render).

Resources