How to load font from resource using dwrite API? - c++

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.

Related

QPdfDocument/QPdfView: How to display an animated PDF?

I implemented a PDF Viewing widget in C++ using Qt, loosely based on https://doc.qt.io/qt-5/qtpdf-pdfviewer-example.html, using the pdfwidgets module. (For this question, we can assume that I copied the code in that link 1:1).
This works well so far.
But now the thing is, the PDF I want to display happens to be an animated PDF. Opened in a regular viewer like Acrobat, it will show a short sequence. That sequence is located on a single page, the frames are not different slides.
In the documentation of the QPdfDocument and the QPdfPageNavigation classes, I can't find any functionality that deals with animated pages. It would suffice if I had any way to set the current animation phase.
Is this possible at all? If so, how?
It's not implemented at the moment. On Windows, you could use an ActiveQt widget to embed Acrobat Reader inside your application, if present. Otherwise you'd need to find a PDF rendering library - most likely a commercial one - that has such support.

create table in pdf using haru library in c++

I need to create Table structure and fill data using Haru library in C++. Can anyone provide me sample example which create table structure using Haru library.
I while ago I needed to produce some data tables as part of another project using Haru PDF. To simplify the creation of complex tables I wrote a small utility module to be used with the Haru PDF library that greatly simplifies the creation of complex tables. The module allows full customization of the table and supports for example cell spanning (both row and column). It also allows for the separation of layout and look&fell by a theme concept.
A simple usage example (just to give an idea) would be
int num_rows=5;
int num_cols=4;
char *table_title="Example 1: Basic table with default theme";
hpdf_table_t t = hpdf_table_create(num_rows,num_cols,table_title);
hpdf_table_set_content(t,content);
hpdf_table_set_labels(t,labels);
HPDF_REAL xpos=100;
HPDF_REAL ypos=630;
HPDF_REAL width=400;
HPDF_REAL height=0; // Calculate height automatically
hpdf_table_stroke(pdf_doc,pdf_page,t,xpos,ypos,width,height);
It is out of scope for this answer to discuss the code in more details but it should be fairly self documenting.
The module also allows both purely programmatic tables but also the creation of entirely data driven table creation (all layout and look & feel is taken from a structure). This allows a light-way model-view-controller approach to make maintenance easier. To fully use this relies on the client implementing callback functions that the module will call to get the corresponding data.
Since this was never intended to be released as a separate utility I haven't written up (yet) full documentation but I put together a quick standalone example which shows some of the features. The resulting PDF from running the example is included at github. However, all public API are fully Doxygen commented which should give some ideas on how it fits together.
You can find the module at (https://github.com/johan162/hpdf_table)
Update: Due to surprisingly many visits/questions I have taken the time to make a new release (1.4.0) with a completely rewritten documentation and reference which explains all the functionality of the library. The release also fixes all known small bugs as well as several new features.
You can use the draw_graph function in the encoding_list.c demo as an example. It is part of the source tar ball.

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.

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.)

MS Word/ ODF Automation in Qt

How can I perform automation of MS Word documents (.doc) or ODF documents (.odt) in Qt 4.5? I know using the QAxWidget, QAxObject.
I have data (QString) and few images as well. I have to add them into the document. I googled but I couldn't find any commands for MS- Word/ ODF. But I want the specific commands that should be passed in QAxObject::dynamicCall() function to perform my operations.
For e.g in MS Excel we have to use something like,
excel.querySubObject("ActiveWorkBook");
which will return the object of the Active workbook of the Excel document.
What are all the commands that are available for the generation of MS-Word or ODF (odt) documents? I am using Windows XP. Any links, examples are welcome..
Take a look at http://doc.trolltech.com/qq/qq27-odfwriter.html, Qt provides functionality to create OpenDocument Format (ODF) files.
The ActiveX commands related to the MS Word can be obtained by the VBAWD10.chm that is being installed along with MS - Word.
The details of the ActiveX help documents available can be obtained here.
The toughest part is to conform those in such a way that it can accessed through the ActiveQt Module.
I provided a similar solution to my question here
Hope it helps for those who are all looking similar solutions..