How to check installed fonts styles? - c++

I need a list of all installed fonts in the client machine (Always Windows) that contain the styles bold, italic and bold italic. Is there a function for that?
I'm already able to list all installed fonts with EnumFontFamiliesEx and i suppose that is possible to filter that list, but i'm looking for a "better way" :)
Thanks!
PS: I'm using C++ with MFC.
EDIT:
For fonts that doesn't have these styles Windows can "fake" that behavior (force a font look bold or italic), but i need to know which fonts really have these styles.

As you are using "EnumFontFamiliesEx",the call back function recieves the structure LOGFONT....
LOGFONT has two variables lfWeight and lfItalic.
Use those two variables to check if the enumerated font has style or not.
if lfWeight value is 0 (FW_DONTCARE) and lfItalic is false, you can consider this do not have any style.
Or if you want to be very specific, for example, you want to consider fonts with only Bold and Regular, then you can validate, if lfWeight has value from {400 (REGULAR), 600 (BOLD), 700 (BOLD), 800 (BOLD)}
Below link has all the details.
https://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx

Related

Substitute Wingding fonts for linux

I am using Java aspose.words and trying to build a pdf from docx/ppt in linux. The docx-document has an list with bulletpoints. These bulletpoints use the symbol font.
When i create the pdf with aspose these bulletpoints are shown in webdings font as a clapperboard.
I did not find any free font (for commercial use) that is an equivalent to the symbol font. Does anyone know a good solution to show correct bulletpoints in list?
I found the way to substitute fonts, but i don't know which font to use:
TableSubstitutionRule tableSubstitutionRule = fontSettings.getSubstitutionSettings().getTableSubstitution();
tableSubstitutionRule.addSubstitutes("Symbol", "?WHICH_FONT?");
It might be a known peculiarity. Windows “Symbol” font is a symbolic font (like “Webdings”, “Wingdings”, etc.) which uses Unicode PUA. Thus substitution of this font will cause different glyphs rendering. Provided Mac/Linux “Symbol” font on the other hand is a proper Unicode font (for example Greek characters are in the U+0370…U+03FF Greek and Coptic block). So these fonts are incompatible and Mac/Linux “Symbol” font cannot be used instead of Windows “Symbol” without additional actions. In this particular case you have to change the bullet codepoint from PUA U+F0B7 (or U+00B7 which also can be used in MS Word for symbolic fonts) to the U+2022 in the document to use the Mac “Symbol” font. See the following code for example:
Document doc = new Document("/Users/mac1/Downloads/in.docx");
for (com.aspose.words.List lst : doc.getLists())
{
for (com.aspose.words.ListLevel level : lst.getListLevels())
{
if (level.getFont().getName().equals("Symbol") && level.getNumberFormat().equals("\uF0B7"))
{
level.setNumberFormat("\u2022");
}
}
}
doc.save("/Users/mac1/Downloads/out.pdf");
If this does not help, please post your question in Aspose.Words support forum and attach your input and output document there.

WebStorm: Display ===, != operators as ≡, ≠

I'm looking for a setting/plugin which forces editor to display all occurences of multiple-char equality operators as their corresponding UTF-8 chars (≡, ≠...). I'm sure it is possible - I saw it on some screenshots from WebStorm. Does anyone know how to turn on this behaviour?
It's called font ligatures.
Settings/Preferences
Editor | Colors and Fonts
Enable font ligatures -- select this check box to show the typographic ligatures. Note that this feature depends on the selected fonts.
I could not find dedicated blog post for this new feature .. but you can find some notes here:
https://blog.jetbrains.com/webstorm/2016/06/webstorm-2016-2-eap-162-646/
https://blog.jetbrains.com/idea/2016/07/intellij-idea-2016-2-is-here/
video: https://youtu.be/Bjq-A4LCU9M?t=23m37s
Original ticket: https://youtrack.jetbrains.com/issue/IDEA-127539

New Symbolic Color in Pango Span Text

First time poster; long time admirer of the Stack Overflow angels.
I'm having an issue with colors in span text that are controlled by Pango.
Long Version:
I'm updating an old UI program which has C++ code guts with GTK, XML (written by Glade), and an RC stylesheet handling the graphics. Some of our colored markup text is hard-coded in the XML. Some of it is dynamically set in the C++ code.
The problem is, that when the program runs on our older systems, the color referenced by span text as 'green' shows up as #00FF00. On our newer systems, 'green' is showing up as #008000.
Example of code printing to a label widget:
gtk_label_set_markup((GtkLabel *) TitleBarLabel, "<span color='green'>Orbital Cannon Positioning</span>");
I'm fairly certain that Pango is in control of the span text markup. I found that the difference between the greens is exactly the difference between X11 and W3C color lists (https://en.wikipedia.org/wiki/X11_color_names#Clashes_between_web_and_X11_colors).
It seems that our old systems are using X11 and our new ones are using W3C, which makes sense.
I could just replace all instances of 'green' with '#00FF00' but if we wanted to change the colors in the future, we'd have to go through the whole thing again. I'd much rather have the colors changeable through a stylesheet instead of baked into the code.
C++ Code:
GtkWidget * TitleBarLabel;
TitleBarLabel = GTK_WIDGET (get_builder_object (builder, "TitleBarLabel"));
gtk_label_set_markup((GtkLabel *) TitleBarLabel, "<span color='#00FF00'>Death Ray Power Status</span>");
I can create a GdkColor at run-time and gdk_color_parse it with values from a config file, and then use gtk_widget_modify_text() to apply the color to the label widgets. But then that doesn't work for all of the hard-coded span text in the XML. Also, we have pleanty of labels with bits of text colored differently inside the same line.
C++ Code:
GdkColor pass_color;
gdk_color_parse("#00FF00", &pass_color);
gtk_widget_modify_text(TitleBarLabel, GTK_STATE_NORMAL, &pass_color);
I can make a style in my RC file for each color and link every single label that would use that color at run-time. But we'd have to remove all markup coloring and add lots of code for grabbing widgets that we never bothered with before and code for setting names of widgets instead of just printing to them with new span text. It gets the desired result of having the colors changeable in a stylesheet but it's a massive undertaking and it's not intuitive for our veteran engineers who are used to using the color attributes.
RC File:
style "pass_color"
{
fg[NORMAL] = #00FF00
}
widget "*TitleBarLabel_Pass" style "pass_color"
C++ Code:
gtk_widget_set_name(TitleBarLabel, "TitleBarLabel_Pass");
Short Version:
Ideally, I would like to be able to make a new color at run-time that we can link with span text in such faction:
<span color='MyNewColor'>Weather Manipulation Settings</span>
Or maybe even create a new tag that applies specific attributes, like:
<span><MyNewColor>Shark Tank pH Balance</MyNewColor></span>
But I doubt that's possible.
I tried playing around with pango_attr_type_register(), pango_attr_foreground_new(), and friends, but I couldn't figure out how attributes work of if they could even do what I thought they did. After much research, it looks like an 'attribute' is just a one-time setting on a single string of text. And not a new value that can be called in line with span text, as I hoped.
Is anything like this remotely possible without rebuilding all of Pango?
Is there a different work around that would get me a stylesheet like setup?
At this point, I'm open to suggestions.
Version Specs:
Computers showing green as #00FF00
OS: Linux Slackware 13.37 and below
GTK: 2.24.4
Pango: 1.28.4
Computers showing green as #008000
OS: Linux Slackware 14.1
GTK: 2.24.20
Pango: 1.34.1
If you are able to use GTK 3.x, I would suggest doing that, where this is much easier to do using CSS. There is even a way to use multiple CSS styles for different regions in the same label, though it is awkward.
In GTK 2, as you noted, you can reference widgets by their name property in your RC file:
widget "shark-tank-ph-label" style "green-text"
style "green-text" {
text[NORMAL] = #008000
}
I would recommend taking this approach even if it's not what you're used to. Refactoring once to remove the hardcoded colors from your labels will make it much easier the next time you have to change something like this, and will also make your code closer to how things would work in GTK 3.x should you decide to make a port in the future.

SketchFlow / SketchStyles is empty. ((Assets) Styles > SketchStyles)

I just installed the Expression Blend Studio 4 (Trial) from Microsoft.
I have several tutorials telling me to change the style, that I should go to
(Assets) Styles > SketchStyles
There is nothing under that area except a warning(and link)
This category shows all the styles you have created for the current document or application. Additional styles can be found in the online Expression Gallery.
That link gets me no where fast. It basically goes to the home page of Expression Blend.
If you look at this 90 second video.
http://electricbeach.org/files/sketchflow_overview.wmv
At the 30-36 second mark, he is switching the style from squiggly to something more professional.
I'm trying to demo that same thing, which I believe (keep in mind I'm new to this) I am changing FROM the WigglyStyles style to something else.
With
(Assets) Styles > SketchStyles
being empty, I don't know what I'm missing.
...........
So a 2 part question:
How do I get entries to show up under (Assets) Styles > SketchStyles?
(If different from #1), how do I change the overall style from WigglyStyles to something else (and back to WigglyStyles)?
Thanks!
Is misssing the SketchStyles.xaml.
SketchStyles.xaml – this file contain the resource dictionary with number of styles which SketchFlow project makes use of them internally.
Solution:
Create a new solution, a (sketchflow silverlight solution), copy the SketchStyles.xaml from your created solution drag and drop the to the project that doesn't have this file, and press ctrl+shift+B to build it.
hope it helped.
The message was throwing me off.
The little triangle, pointed "to the right" initially, has to be clicked (and then points down) exposing the sub items.
The message:
This category shows all the styles you have created for the current document or application. Additional styles can be found in the online Expression Gallery.
is what was throwing me off. (And I was thinking the same thing as alimbada, that my install went awry).
Once I expand "Styles" (via the small triangle), everything is there.
Ok!! Did I mention I'm a developer, not a designer?? (haha).
Aka, this was just a big "duh" moment.
Thanks.
I just had a quick play with Sketchflow since I have Blend installed and those styles show up fine. Maybe your install went awry?

Get a font filename based on Font Name and Style (Bold/Italic)

This has been driving me crazy all day.
I need to get a font filename (eg. Arial.ttf) based on its name (Arial in this case) and whether it is bold, italic or both. Using those pieces of information, I need to find the font file so I can use it for rendering.
Some more examples:
Calibri, Bold would resolve to calibrib.ttf.
Calibri, Italic would resolve to calibrii.ttf.
Any ideas on how I could achieve this in C++ (Win32)
First, to my knowledge, there is no reliable way to do that.
The Windows API deals with font families and mappings, not with font files, which are dealt with at a lower level. Also note that even if you manage to get the file name of a font, no rendering function (that I know of) will accept it, so what will you do with it?
That said, you can look in the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts in order to obtain the file name of a font from its logical name. An implementation of that solution can be found here.
Related to the earlier posts, this seems to be a reliable way:
1) Read the registered Windows font list from
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts\
You will obtain file names and alternate file paths here.
The Font names are not useful as they can change with user's locale.
2) Load the TrueType files (.ttf, .ttc, .otf):
Use FreeType https://www.freetype.org/). Just initialize the freetype library and load face with FT_New_Face(library, path, 0, &face).
3) Obtain the font Family name using FreeType.
Use FT_Get_Sfnt_Name_Count() and FT_Get_Sfnt_Name() to obtain the string table.
You will need to check if the encoding is Ansi, UTF16 or other, as some strings will be in multiple different languages and encodings.
4) Obtain the OS2 TrueType properties.
Use (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2) to get the OS2 structure.
Interpret the structure using docs like https://www.microsoft.com/typography/otspec/os2.htm#fc
5) Now you have font file path, family name, style properties and other information. Build a list of these and function to search for a file based on font family and style.
This Code Project project does what you want. As-is it fails on Windows 7 because the GetWinVer function stops at XP. It is trivial to add the case for Windows 7.
You normally do this by calling CreateFontIndirect and then getting the system to render. Perhaps you could explain why you can't use this standard approach.
One solution would be to access the font files and extract the name from the name table to create your own lookup (an STL map would be a simple way of doing that). Details of the TTF file format can be found here.