How to create IDWriteTextFormat from IDWriteFontFace - c++

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.

Related

How to load font from resource using dwrite API?

I want to load a font from a compiled resource which is the program itself. I can load it using AddFontMemResourceEx when I was using GDI. However, direct 2D has it own Dwrite API which is not compatible with GDI. The official document suggests using CreateCustomFontFileReference + CreateCustomFontCollection. Could anyone give me an example how to do it?
Take a look at the DirectWriteCustomFontSets sample in the microsoft/windows-classic-samples repo on GitHub (here). It demonstrates five scenarios using a custom font set, and based on your question it sounds like case 4 would apply to your situation: "Creates a custom font set using font data contained in in-memory buffers."
For this scenario, the key interface is IDWriteInMemoryFontFileLoader, which was added in the Windows 10 Creators Update (spring 2017).
The specific files in the sample project that will be most relevant are:
CustomFontSetManager.h/.cpp — this includes members applicable to the other scenarios as well
BinaryResources.h/.cpp
Document.h/.cpp — this is described as simulating a document file containing the font data (e.g., a .doc file), but it could be any kind of binary.

FontConfig get fonts to render a given string

I'm trying to implement a C/C++ program that given a string and a font configuration return the best font set to render the string.
The string might need more the one font to be rendered correctly. How FontConfig handle this situation? Is it smart enough to tell me which character should be render by which font?
Note: I'm a Java developer so I'm not that strong with C++, so maybe my question have a trivial answer.

programmatically feed a kml-file and retrieve/generate a .png-file

How can I, programmatically, draw a KML-file (routing information on a map) onto a map and then save the result to a .png-file?
What I try to accomplish: a program of mine (written in C++) produces a route. Now I would like this program to emit a .png-file instead with the route draw on it.
I've looked into the google maps api as well as others (e.g. cartagen) but google maps is java-script oriented and cartagen produces html5 output.
Probably you can use Qt Framework to achive this.
It has great XML support so it should be easy to read KML.
It has support for drawing simple shapes.
It has support for PNGs too.
There is also library called libkml - it can probably help you with manipulating with KML files.
I highly doubt if there is any "Ready to Use" solution.

Java library to create and dynamically modify business diagrams

I am looking for a good java library to manipulate box, arrows and labels in order to dynamically create and fill diagrams like the following and render them to a png :
Another example
I can create a static template to be filled later, but I will need to dynamically create labels for every box and edges in the diagrams.
For now I have tried using batik to manipulate an svg template but creating multiline labels for the edges is proving quite complicated. The SVG way with batik seems to force me to create 1 text object for each label line with absolute positioning for each which is a real pain.
I would like to be able to define the label specifying only the text and the link they relate to, eventually some hints as to how it should be placed and let the library place them.
Any suggestions ?
If this is in a commercial scenario, the Java graph drawing library yFiles can be a good match for your requirements:
You can use a convenient API to create and style your diagram and automatically layout the diagram with lots and lots options to constrain the resulting layout to suit your needs.
Multi-line and (simple) HTML labels are supported out-of-the-box.
Also you can export to PNG (as well as other pixel based image formats) and vector graphics formats like SVG, PDF, EPS.
This can be done both in a regular Java (Swing) application as well as in a headless environment (e.g. to create images on a server and to send them to a web-based thin client dynamically).
To get a feel what can be done using that library, I suggest you take a look at the freely available graph editor application "yEd" that is based on yFiles and lets you try out the above steps in an interactive manner.
(Disclosure: I work for yWorks, but on Stackoverflow I do not represent my employer.)

HTML renderer drop-in, C++ code

I want to drop in an HTML renderer that will basically be used for render-to-texture operations.
If I can render the HTML to an HDC, that would be perfect.
I found HTMLayout, which isn't bad. But it isn't open source. But I'm wondering if there's a way to somehow tap into IE or Mozilla/Gecko code, how realisitic/difficult this will be, and possibly some pointers on how to do it.
It will be for a regular straight C++ directx application
Edit
Wow! Mozilla has an embedding kit!
Take a look at WebKit.
Qt can do it, render to a QPainter. See for example http://doc.trolltech.com/4.6/qwebpage.html But not sure if it's easily used if you are not already using Qt.