Imagemagick C++ api conversion from svg to png not using custom fonts - c++

I am using the ImageMagick C++ api to convert from SVG to PNG. The SVG has a .css file and .ttf fonts are in the input data.
If I add the fonts to the ~/.fonts folder and use the fc-cache command, my conversion works fine. The conversion also works fine if I use already-installed-fonts on my system.
The problem is that I cannot adjust any configuration on the server where it will be running, so i was looking for a runtime solution.
Using fc-cache to point at the directory where the fonts are didn't work for me.
I found the MAGICK_FONT_PATH environment variable and I created a type.xml in the input data fonts folder. Then I pointed the MAGICK_FONT_PATH to the type.xml folder, and when I list fonts with convert -list font I can see the fonts, but using the imageMagick api directly from C++ doesn't use the fonts.
The code is something like:
magickImage.write(&blob);
Does anyone know how to use custom fonts with the imagemagick api? Where the fonts-to-be-used are defined in the .css file?

Related

How to get the ios document/library path through Qt5?

I used find my ios app's document/library path by going up starts from QApplication::applicationDirPath().
However from iOS 7/8, the bundle path is moved away from data path.
So how can I get my app's writable paths through Qt C++ only? Is there a correct way that packed with Qt?
I don't want to write on APPROOT's document. And I understand that I can write objective-c codes to find the path.
So my app is installed at:
/var/mobile/Containers/Bundle/Application/XXXX/
What I want to get is
/var/mobile/Containers/Data/Application/YYYY/Documents
/var/mobile/Containers/Data/Application/YYYY/Library
note that the bundle's long id (the XXXX) is different from Data's (the YYYY)
If you need to take the document or any other standard library directories path, use QStandardPaths from Qt5:
QStandardPaths::AppDataLocation
For other paths consider to read the official Qt docs about QStandardPaths

Qt Antialiasing Issue on OSX

I'm trying to build a Qt-based app on OSX (using CMake), but all the widgets (and text) that I'm creating look terrible.
For example, here is a screenshot of the checkbox and magnification text within the System Preferences app:
and here is a sample checkbox and text from my app:
My Info.plist file contains
<key>NSHighResolutionCapable</key>
<string>True</string>
but this doesn't seem to have an effect. I've also tried setting the render hint for fonts, but again, nothing changes. Is there something special that needs to be done to get simple things like checkboxes to render well on OSX when using Qt?
So the Info.plist tweak ended up being the correct fix, but OSX caches the .plist files. Deleting the entire generated bundle (including the .plist) fixed the issue. Hooray for good looking checkboxes.

Load bitmap file (.bmp)

I noticed the boost::gil::extension::io only supports png or jpeg files.. While this is often enough I'm wondering how to load a bitmap (*.bmp) file into an image? Shouldn't this be actually easier than jpeg etc?
Hopefully you solved it.
Just to add: install latest version of GIL on existing boost and then compile.
The bitmap files comes under new 'io_new' folder.

Find out the mime type and associated applications with Qt

How can I find out a mime-type or content-type of a given file?
I cannot use the suffix because the file could be renamed.
Possible additions would be categorizing them as jpg, gif, png and so on are image files and can be opened by editing applications, which has been set in the OS.
Thank you in advance.
What platform? On *nix, you should refer to how the program file does it, which is based on a few heuristics including checks of the first few bytes of a file (many file formats start with a fixed header, including many image formats).
If you're on Windows, the *nix file command is probably still instructive, even if you can't reuse its code as directly. There may also be some better solution in the Windows APIs (I'm not a Windows programmer).
This could help, it is with C# but I think you can get the idea.
http://kseesharp.blogspot.com/2008/04/c-get-mimetype-from-file-name.html
You can use some sort of class for acccesing Windows Registry from qt or using the Windows API directly from qt.
I am not a qt programmer.
You can't, not from within Qt.
However, if all you want is to show a file with the correct application, you can use QDesktopServices::openUrl(), which wraps open (Windows/OSX) and xdg-open (Unix). The URL may also be a local file (in that case, use QUrl::fromLocalFile() to construct the URL).
For categorizing image files. For Qt and just only for image files.
QByteArray imageFormat = QImageReader::imageFormat(fileName); //Where fileName - path to your file
Further mapping imageFormat to mime-type is not complicable
It doesn't look like Qt offers that capability yet. However, you may want to look into the libmagic library which does what the file and other similar commands do. Assuming the library is maintained properly it will include new MIME types as time passes. From what I can tell it is part of the file tool suite. Under a Debian system do something like this:
sudo apt-get install libmagic-dev
to get the development library and use #include to make use of it.

Cross-platform fonts in WxWidgets GLCanvas

I'm developing a cross-platform app w/ wxWidgets and opengl...
I'm not sure what the best way is to have fonts work in the glcanvas. I've tried using FTGL but I think the version included in Fedora 11 must be broken or something since I can't get the example code on the web site to compile. I could try using GLUT or SDL but I'm not sure I want to include those as dependencies...
EDIT: Turns out it's just a different version than the one that is documented on the web site and has a completely different API.
Even if I have a font library though, all the ones I've seen require a path to a font file, and I have no idea how to do that in a cross-platform manner.
All platforms deal with fonts differently. There is no cross platform way to find fonts on a system. Alternatives include...
Package your fonts with your app so you know where they are.
Convert the fonts to a binary blob and embed them in your app.
Test for the OS and set the font path accordingly.
Transliterate this tutorial to C++ and array-embed a gzipped copy of the GNU Unifont. QuesoGLC might also be an option, but watch out for performance gotchas.