How to get font name from a file? - c++

I've been using GetFontResourceInfoW to get font name from font file, but turns out it's not robust and often fails. This function works most of time if font is in the system fonts folder.
I need to get the font name without installing it. If font file is a collection of styles then I need the names of fonts in this collection.
Arial, Arial Black, Arial Italic etc. ..
I've looked into PrivateCollection of GDI+ but it doesn't support font files like .fon and .fnt and DirectWrite is worse. The legacy GDI supports all formats, but I can't find a function capable doing what I looking for.
Is there any other API I could use to accomplish this?

Related

Does Freetype support variable fonts?

I am building support for Freetype (2.10.1) in my application and I just came across my first serious problem. I opened a font called bahnschrift.ttf that was available in my Windows fonts folder and it seems to support several different styles in a single file. However, Freetype reports only a single face available.
How can I create separate faces for the different font styles in this case? Does Freetype support variable fonts?
Thanks.
FreeType supports variable fonts since version 2.8.
You probably got to the point of instantiating an FT_Face with FreeType. From there, most of the documentation related to OpenType font variations is in the Multiple Masters section of the documentation:
https://www.freetype.org/freetype2/docs/reference/ft2-multiple_masters.html
To find out which variable axes a font has, you can use:
FT_Get_MM_Var on your FT_Face which contains the named styles in FT_MM_Var structures.
To then set variable font design coordinates, use FT_Set_Var_Design_Coordinates or FT_Set_Named_Instance to select a specific named instance.

Decoding Microsoft True Type Font Files

I am working on an embedded platform (STM32F407) with a TFT LCD as a display (480x800px) and would like to make my user interface somewhat customizable to the end user. I figured the best source of fonts would be windows compatible as their the most common.
My current implementation uses my own custom drawn font in a binary format and a descriptor table giving the character width and ascii value but having to draw my own font bit by bit is tedious.
I would like to read in a True Type Font file from an SD card and be able to use the different sized glyphs inside it but I have not seen a strait forward implementation on how to actually achieve this magic. Can somebody point me to a good c/c++ example of what I am looking for?
Even better as a way to iron out the kinks I would like to make a simple gcc command line program that will print out my input with a selected font using '#' as pixels. That way I can just worry about implementation and not any other random bugs that might pop up.
Can anybody help me out?
Perhaps you can use the Freetype library.
As duskwuff says: TTF is primarily a vector format, would need to write a renderer. Better off using an image file to define the font, or using a bitmap font format like FNT (Windows) or BDF (UNIX).
Here is my answer to my own question: AngelCode's BMFont & Useage. This makes choosing selective characters from the installed char set, mix in a font and exports an image with a map file to each character. Simple to use.

Marlett Font: Can I load it and use it in WinAPI

What functions do I use to load the Marlett font in Native WinAPI(if its possible)?
I am attempting to create my own transparent checkbox in Native WinAPI. I am at the stage where I need to draw the checkbox tick therefore it would be cool if I could just load the Marlett font then TextOut() - ie print - the checkbox tick.
Maybe I need to obtain a copy of the Marlett font as a file then I load it in at runtime, or is it on all Windows OS's from 2k upwards?
http://www.siao2.com/2006/01/26/517738.aspx
This is answered trivially by consulting Wikipedia:
Marlett is a TrueType font that has been used in Microsoft Windows since Windows 95.
Hence you can just load the font using the conventional CreateFont or CreateFontIndirect, if you prefer.

freeglut's glutStrokeString giving a "stroke font not found error"

I am trying to use glutStrokeString using freeglut.
The program runs fine up to the point it has to call glutStrokeString, then it outputs the console freeglut stroke font not found.
Any idea why?
GLUT_BITMAP_HELVETICA_18, as the name suggests, is a bitmap font. You can't use them with the Stroke rendering commands. So if you want to use that font, you have to use glutBitmapString.
FreeGLUT comes with two stroke fonts: GLUT_STROKE_ROMAN and GLUT_STROKE_MONO_ROMAN. So if you want to use the stroke commands to render the fonts, you have to use one of those kinds of fonts.
Just check out the file, gluit/freeglut_font.c, in your glut source code, contains everything you need to know, Also check fghFontByID() and fghStrokeByID() which are actually used to computed the font id for both the functions that is glutBitmapString() & glutStrokeString()
or check out this

How do I determine the fallback font for Pango?

I'm rendering some text using pangomm, but the font that I am using doesn't have glyphs for parts of the text (in this case, there is some Japanese mixed in with English). Pango seems to render the text correctly using a fallback font.
How can I determine which font is being used as the fallback?
Actually the font selection is based on the selected Pango font backend. Mostly used (I think) is Fontconfig.
You fonts are basically always chosen by looking at the fonts Unicode coverage, meaning that Fontconfig tries to choose the font that covers the letters in the text you want to render best.
Not knowing if your problem applies to Fontconfig, I won't go into to much detail. But if so, have a look at http://www.freedesktop.org/software/fontconfig/fontconfig-user.html, especially the section on 'font matching'.
Feel free to ask again.