I get Windows font by calling GetStockObject API. Then before drawing by GDI+ I need to change this font charset (or to create a copy of it with changed charset). What are the ways to impelement it?
This link may help explain now to modify an existing system font. You'd just need to set your alternate charset in your call to CreateFontIndirect().
Windows fonts are generally based on Unicode. They don't use charsets.
Also, this sounds like an XY problem. What real problem are you trying to solve?
Related
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.
I'm new to X11 programming, and development is in Linux Environment, i have come across an issue with font which I'm not familiar.
Here is my question:
How to change the character set in XmStringCreate(text,charset) in X11 ?
For Example:
XmStringCreate(text,charset) has the value XmStringCreateLtoR(text,XmString_DEFAULT_CHARSET)
I want to change the DEFAULT_CHARSET to ISO859-15.
And How to handle the XmString_DEFAULT_CHARSET.
The second argument to XmStringCreate is a string associated with a specific font via a fontlist resource, which any widget capable of displaying text has.
If you only need to display ISO8859-15, just put ISO8859-15 font(s) in your fontlist resource, and you're done.
If you need to display more that one legacy charset, put several fonts in your fontList and associate a tag with each one.
*fontList: -b&h-luxi sans-bold-o-normal--0-0-0-0-p-0-iso8859-1:charset1,
-b&h-luxi sans-bold-o-normal--0-0-0-0-p-0-iso8859-15:charset2
Use "charset1" or "charset2" as the second argumnt to XmStringCreate.
Can anyone tell me how I get the HFONT handle to send a WM_SETFONT message? The font is calibri and should already be installed on Windows, all I can see is the add/create functions here
http://msdn.microsoft.com/en-us/library/windows/desktop/dd144821%28v=vs.85%29.aspx
the CreateFont function states it returns a handle but Im wondering why I would need to create something thats already there.
The only thing that's "there" is a set of font files in the c:\windows\fonts directory. They contain the outline of the font. You really do have to call CreateFont(). At which point Windows actually accesses the file and creates the specific font you ask for. With the requested height, weight, etc.
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.
Given an HFONT, how do I tell if it's a symbol font? A pdf library I'm using needs to treat symbol fonts differently, so I need a way to programatically tell if any given font is a symbol font or not.
Use GetObject to get the font's properties to a LOGFONT structure. Check the lfCharSet member; if it's SYMBOL_CHARSET, you have a symbol font.
Mark Ransom's answer is going to work 99.999% of the time, but there's a theoretical possibility that it could give the wrong answer.
To avoid this possibility, you should use GetTextMetrics to get the TEXTMETRICS of the actual font and check if the tmCharSet is SYMBOL_CHARSET.
What's the difference between checking lfCharSet and tmCharSet?
When you create an HFONT, Windows makes an internal copy of the LOGFONT. It describes the font you want, which could be different than the font you get.
When you select the HFONT into a device (or information) context, the font mapper finds the actual font that best matches the LOGFONT associated with that HFONT. The best match, however, might not be an exact match. So when you need to find out something about the actual font, you should take care to query the HDC rather than the HFONT.
If you query the HFONT with GetObject, you just get the original LOGFONT back. GetObject doesn't tell you anything about the actual font because it doesn't know what actual font the font mapper chose (or will choose).
APIs that ask about the font selected into a particular DC, like GetTextMetrics, GetTextFace, etc., will give you information about the actual font.
For this problem, Mark's answer (using GetObject) is probably always going to work, because the odds of the font mapper choosing a symbol font when you want a textual font (or vice versa) are minuscule. In general, though, when you want to know something about the actual font, find a way to ask the HDC.