Embedding Third Party Fonts as resource for Win32 Application - c++

I was wondering how i can embed a third party font into my app( and use it ) so i can distribute my app with the font of my choice for users who do not have the font installed on their systems. Is this possible, or do i have to distribute the font if i want the users to be able to use the font in question. Thanks.

Stick the actual font file into a User-Defined Resource.

Very few fonts will have a license that allows this. Even a free font should be checked.
You can use CreateScalableFontResource and AddFontResource to make a font file available to your application. The font must be available as a separate file for this to work.

Related

How to package several icons for different sizes in a VS C++ app?

I'm developing a C++ app in Visual Studio 2022 with a UI (UI library is wxWidgets). I'm trying to figure out how icons work. I gathered from researching that Windows expects a variety of different icons to be packaged with apps for the best UX (see Which icon sizes should my Windows application's icon include?). However I can't seem to find a way to get multiple icons taken into account.
My understanding so far is that all resource related things, including icons, are controlled by Resource.h and <projectName>.rc, both of which are initially provided by the VS template for a C++ App.
I've removed the provided icons (i.e the "normal" and "small" ones) and have instead imported many icons, one for each size, in the Resource View.
But regardless of that, always one icon seem to be used at a time.
Checking the contents of <projectName>.rc, I see the following:
I also expect the following, in Resource.h, to be relevant:
It seems that independently of the icon sizes, IDI_ICON1 is used. If it's 16x16, it's upscaled in context that requires it, if it's 256x256, it's downscaled (poorly, somehow ?) when required i.e in almost all contexts.
How should this be done ? Are there resources available on the matter I may have missed ?
You should embed all your ico files with different resolution into one ico file. The ico file is actually a container and can contain multiple images inside.

Qt Application use icon from user icon theme in Linux

When I set icons for my Qt application I can provide *.png files and use QIcon("icon.png"), However, I want to use standard icons that were provided by the distribution and configured by the user. e.g. those from /usr/share/icons/. So that it respects the system's icon theme.
What method should I use to make the Qt application use the system's icon theme?
Indeed, freedesktop.org has an Icon Theme Specification document that defines the notion of icon theme and defines an algorithm to search for specific icons. Qt follows this spec in its implementation, and as mentioned by #eyllanesc QIcon::fromTheme() static method can be used to lookup needed icons.
Another relevant document, by the way, is Icon Naming Specification, which defines some well-known names for most often used icons.

Must I use path to fonts?

The FT_New_Face function seems to be the one I'm looking for, but it requires a path to the font file. I would like to open a font like "Times New Roman," without supplying a path. How can I do that?
Most unix-based systems use Fontconfig for this to get best matching font file from set of search parameters ( family name, variations, weight etc )
Fontconfig is a library for configuring and customizing font access.
Fontconfig can:
discover new fonts when installed automatically, removing a common
source of configuration problems.
perform font name substitution, so that appropriate alternative fonts can be selected if fonts are missing.
identify the set of fonts required to completely cover a set
of languages.
have GUI configuration tools built as it uses an XML-based configuration file (though with autodiscovery, we believe
this need is minimized).
efficiently and quickly find the fonts you
need among the set of fonts you have installed, even if you have
installed thousands of fonts, while minimzing memory usage.
be used in concert with the X Render Extension and FreeType to implement high quality, anti-aliased and subpixel rendered text on a display.
Fontconfig does not:
render the fonts themselves (this is left to FreeType or other
rendering mechanisms)
depend on the X Window System in any fashion, so
that printer only applications do not have such dependencies
Fontconfig is relatively portable and used on a variety of systems, however OSX has CoreText which has similar functionality and Windows has DirectWrite
Refer to this question for help on how to use Fontconfig.

Localization Font

I am very new to localization, I am trying to localize a small software which has 19 folders 'en', 'jp, 'tw' as names for example. Inside each one is a text file saved as utf-8 with language data.
The problem is when I try and copy and paste from a chinese site I get strange glyphs like this [][][][] I presume its because my system font is not chinese and it does not support that.
As a developer should I somehow change my entire system font to have all of these languages supported? Is there such a font? I am unsure how software companies handle these things.
As a developer should I somehow change my entire system font to have
all of these languages supported?
No, you should not. Consider localization string as data.
The problem is when I try and copy and paste from a chinese site I get
strange glyphs like this [][][][] I presume its because my system font
is not chinese and it does not support that.
But you should be provided with such data and you should know it's encoding.
Also, I've suggest you to check internationalization libraries (like gettext) to prevent reinventing the wheel.

How to create IDWriteTextFormat from IDWriteFontFace

I'm creating W8 C++/CX DirectX application and I'm trying to use custom font file from application own storage. I figure out how to use IDWriteFactory::CreateFontFileReference to load IDWriteFontFile from directory and then how to create IDWriteFontFace from it.
What I don't know now is how to use IDWriteFontFace for loading IDWriteTextFormat, if it is possible at all. Should I do this though IDWriteFontCollection ?
Sorry if the answer is really stupid and trivial, I am very new to DirectX and learn everything on the go.
See MSDN DirectWrite help topic on Custom Font Collections for the necessary high level view of how to load your own custom fonts at runtime. Your guess about how to do this was wrong.
It appears that the best sample on how to do this ships directly with the Win7SDK directWrite samples. See the DirectWrite\CustomFont C++ sample.
The process does not involve obtaining or using any IDWriteFontFace types. In fact, the only thing you can do with an IDWriteFontFace that I can see is determine glyphindices.
Instead, you start with a factory, as in all directX APIs, then with the factory, you want to make a font collection, and a font file loader, and enumerate fonts using that font collection. The interfaces for creating a text format expect you to pass in your custom font collection, not your font face.
A sample of correct use of the interface type IDWritefontFace to get glyph information is found here on codeproject.
You can not create IDWriteTextFormat with IDWriteFontFace, you can create a IDWriteTextFormat instance with function IDWriteFactory::CreateTextFormat.
IDWriteFontFace was used to describe the properties of font, while IDWriteTextFormat used to describe the properties of text.