FreeType support for right-to-left languages - right-to-left

Does FreeType support the use of right-to-left languages, like Hebrew? I can get it to display correctly if I just reverse the string first, but this isn't as efficient. So what I am asking is there a way to configure FreeType to automatically right a Hebrew string right to left?

I believe what you are looking for is a text layout library, e.g Pango see http://www.pango.org
FreeType focuses on the extraction of the glyph data from a font file; it is up to the user to implement the language specific stuff such as the layout of the text.

Related

How to get the height at which to draw a strikethrough from FreeType

FreeType has font metrics for the underline position, but I can't seem to find any metrics for the strikethrough position. How do text engines usually compute this value? Should I just put it at 1/3*ascent or whatever looks good? I suppose that for Latin at least this should be 1/2*height of "m" but I'm looking for a more general solution.
This information is not provided for all the various font formats supported by Freetype; so it is not exposed on the "main" interface.
In the (common but not universal) case of TrueType or OpenType fonts it can be retrieved in the TT_OS2 table, fields yStrikeoutSize and yStrikeoutPosition; you should be prepared for the table to be lacking, or yStrikeoutSize to be null or negative thus unusable.
I do not remember of an equivalent for plain Postscript fonts (.pfb/.pfa, even in .afm.)
The various bitmap formats might have the information available; an example is strike_out in Windows FNT; notice this is the position, while the size defaults to be the same as underlining. Basically every format is alone here.

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.

GraphViz: how to get UTF-8 AND external PostScript procedures?

Goal: draw a flowchart which contains non-Latin1 symbols.
Problem: GraphViz does not provide all node shapes necessary for drawing a flowchart (e.g. "Document", "Predefined Process" etc). Fortunately, a person named Jason Brazile created a nice library of missing shapes. However, it works only when using the PostScript driver (dot -Tps).
There are two basic PostScript drivers in GraphViz: built-in driver which does not support Unicode, and Cairo which does, but apparently does not support external PostScript procedures (the user-defined PS shapes are absent in the resulting layout).
Question: How do I use UTF-8 labels and flowchart shapes at the same time?
I asked the GraphViz developers about this and looks like the answer is that there is no way to do that:
We looked at this problem years ago. The native graphviz -Tps
Postscript driver does not have any custom font loading capabilites.
As mentioned here: http://tldp.org/HOWTO/Unicode-HOWTO-5.html
rendering utf-8 fonts in Postscript is a do-it-yourself job. It would
probably take weeks or months of work, but if you want to try to make
this modification to graphviz, it might be possible to appropriate
code from one of the other tools mentioned in that website. (Make
sure it is non-GPL code, otherwise it can't be distributed!)
Another option would be to modify the cairopango driver to render text
on top of a user shape after it is loaded. (Do we not already support
this? It seems obvious.) Then either find a way to render external
graphviz PS shapes after they are loaded and copy the rendered images
into the cairopango canvas (hey we already import ghostscript into
graphviz) or convert the custom PS shapes externally into images that
can be loaded by the cairopango driver. This might not take as much
time.
Either way, it will take an expert C programmer.
Probably none of us have much time to work on this (our time would be
better used trying to get funding to support the project in a more
general way, but we all have other jobs now) but you could offer a
bounty on bountysource and see what happens....

How to convert true type font to bitmap in Ruby?

I'm trying to take TrueType fonts and convert them to bitmap/PNG fonts for a game. I use Ruby for most of my asset processing.
Is this possible?
I believe you will want to use canvas for that. CreateJS library will help you a lot with this. It has a built-in function for that:
http://createjs.com/docs/easeljs/classes/BitmapText.html
Ruby Bitmap Fonts is a BDF (Glyph Bitmap Distribution Format) renderer for Ruby, and able to generate a bitmap for fonts specified in BDF. It's available as a Ruby Gem too. Other libraries or tools will be able to convert font specifications to BDF.

freetype use fallback for missing glyphs

How can I tell freetype to use a fallback font when a string does contain a character that is not present in the Font I'm using as a default?
I need to render non-latin glyphs correctly in my application.
Do I have to manage a fallback myself?
If so: how do I detect if there is a missing glyph in a given string?
I'm sorry, I don't know if you need to handle fallback yourself, but my guess would be that you do. As for how to detect if there is missing glyph, you could use this method: FT_Get_Char_index If it returns 0, it means symbol was not found.
The GNU Unifont can serve as a fallback font for every codepoint in the Basic Multilingual Plane (BMP), which would be 0x0000-0xFFFF. That should cover the vast majority of what you might encounter. Available for download here (archive).
The Unicode Last Resort font can serve as a final fallback for every codepoint in all of the planes. These glyphs only show broad categories. Available for download here.
It looks like you would have to detect the absence of a glyph with FT_Get_Char_Index() as SMart explained, and in those cases turn to Unifont or the Last Resort font.

Resources