Substitute Wingding fonts for linux - aspose

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.

Related

Django - suing font awersome in unicode form

I want to use font awersome in my project in the way, that user can choose which icon he wants. I found django-fontawesome-5 but there is one problem - there is no access to icon's unicode and I need it for one javascript component (html doesn't work there, and unicode does). I was looking all over the internet, but I coundn't find anything that would allow me to add font-awersome icons, with their unicodes somhow stored. My question is do you know how to get this feature?
The unicode codes are stored in icons.json and in icons_semantic_ui.json
Since you've got the codes source you can define a custom templatetag or a model/mixin method or a function which just gets a code from one of those json files using icon name
You can see example in fontawesome_5/utils.py

How to check installed fonts styles?

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

Using GetWindowTextW to get Hebrew text from edit control

I have a VisualStudio project set to "Use Multi-Byte Character Set. It's an older codebase and generally I've been able to get around ok using the "W" version of various functions. However I'm running into a problem trying to get a Hebrew string out of an edit control. No matter what I try I get question marks.
E.g.
int textLen = GetWindowTextLengthW(chatBoxHwnd);
wchar_t* buffw = new wchar_t[textLen + 1];
GetWindowTextW(chatBoxHwnd, buffw, textLen + 1);
But when I try to use buffw (such as displaying it with MessageBoxW) I still get question marks.
So the solution was to also use the Unicode version for creating the edit control itself ( CreateWindowExW vs CreateWindowEX) as well as the ancillary functions around that (SendMessageW, SetWindowLongPtrW, etc...)
After that I was able to successfully use the above code to pull Hebrew (and other languages) from the edit box.
Special thanks to this post How to create a unicode window in a non-unicode application

Weird character imported in Qt QString from a system action in osx

I have an app that at some point displays printer info.
On mac, when adding a printer, the default location is set as "me's iMac" unless user changes it. (me being the user name). But the apostrophe is not quite an apostrophe...
me’s iMac
This is how it shows in system printer dialog:
When I try to display the location in my app - using
QString(pCups->getValue("printer-location", i))
I get
How can I fix this substitution ? are they using a special font ? is there some way I can recognize it ?
I am thinking that if the user name contains other special characters, they may also be mapped to non-UTF-8 ones by the system add printer dialog. I don't have control over it... How can I find and fix any of the fancy symbols with standard ones ?
OSX 10.6-10.9
edit: for now I just did a replace with that specific character... But I think I may have other surprises if I don't do a more generic replace for all non-UTF-8 fancy characters
QString(pCups->getValue("printer-location", i)).replace("’", "'");
// this is what it looks like on Windows, though that particular item will only be used on unix (obviously... cups)
QString(pCups->getValue("printer-location", i)).replace("’", "'");
According to this page, QString interprets its C-style string argument as Latin-1 (ISO-8859-1), not UTF-8. The advice given is to always construct QStrings from C-style strings using QString::fromUtf8() instead.
There's an alternative noted on that page, but you are discouraged from using it because it's a process-global setting and therefore may interfere with libraries or the like. You can call QTextCodec::setCodecForCStrings() passing the UTF-8 text codec (QTextCodec::codecForName(“UTF-8”)) early in the startup of your app.

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.