#resource directive and fonts

 

I would like to include a redistributable font using the #resource directive, as suggested here:

If "::" is used in font name, the font is downloaded from EX4 resource

However, I cannot get the compiler to recognize any font types. The error is always "unknown resource type".

Has anybody had any success embedding a font in an ex4? If so, what format was the font?

 
Unfortunately, the fonts are not yet supported as resources.
 
Thanks for the reply - do you know if the support is expected any time soon?
 
It is expected, but not soon.

Please use common Windows fonts.
 
OK, thanks once again.
 
Ilyas:
It is expected, but not soon.

Please use common Windows fonts.

Is it included already?

 
Evgeny Potapov:

Is it included already?

I don't think so.

But for redistribution, pack the needed TTF fonts, and install them on the destination machine. 

 
rrocchi:

I don't think so.

But for redistribution, pack the needed TTF fonts, and install them on the destination machine. 

Currently, trying to use a font as a #resource elicits a client lockup...

In any case, please do not install fonts on users machines without their express permission, and especially without version checking installed fonts against the one you are using.


place the font in (eg) the __COMMON_PATH__ folder (this should be trivial from a zip distribution) and load the font resource via winuser.h

#include <WinAPI\winuser.h>
#define FR_PRIVATE (0x10)
string f = TerminalInfoString(TERMINAL_COMMONDATA_PATH) + "\\myfont.ttf";
AddFontResourceExW(f,FR_PRIVATE,0);

Also remember to unload the font at the end, in your deinit() function or object destructor.

  RemoveFontResourceExW(f,FR_PRIVATE,0);


This is really useful for watermarks, nice UI, branding etc.

 
el_looto:

Currently, trying to use a font as a #resource elicits a client lockup...

In any case, please do not install fonts on users machines without their express permission, and especially without version checking installed fonts against the one you are using.


place the font in (eg) the __COMMON_PATH__ folder (this should be trivial from a zip distribution) and load the font resource via winuser.h

Also remember to unload the font at the end, in your deinit() function or object destructor.


This is really useful for watermarks, nice UI, branding etc.

Why do you need WINAPI ? It can be done with mql functions only (at least in mql5, I didn't try in mql4).
 
Alain Verleyen:
Why do you need WINAPI ? It can be done with mql functions only (at least in mql5, I didn't try in mql4).

I have yet to be able to use an uninstalled font with the Standard Library without this method.

//pieces-of-eight font not currently installed onto windows: 
//I am assuming that I do not have access or permission to install fonts onto a clients machine

MYLABELOBJECT.SetFont(TerminalInfoString(TERMINAL_COMMONDATA_PATH) + "\\pieces-of-eight.ttf");

using the full path to the font simply does nothing since it uses ObjectSetString() and just whatever the default font is gets displayed.

TextSetFont() has me completely confused as to how to use it and the attendant TextOut(), but for 2 lines of code I'll just add a font resource and ignore what looks like a lot of low-level mucking about to me.

I'm already knee-deep in the winapi since it allows me to manipulate the windows directly for the UI Im writing. Its necessary for removing the toolbar from undocked charts, resizing the UI windows etc. CHART_WINDOW_HANDLE is the hwnd of the chart, not the frame its sitting in: thats a parent hwnd and thats what you have to manipulate. Although it does give me some ideas for a picture-in-picture chart display.

I may review TextSetFont() later, since ive already had to abandon the standard library for parts of the ui since it deletes objects when the chart tf/symbol changes causing a lot of crashes and bugs since those objects are manipulated manually and used in calculations. Its probably a simple fix, but will have to wait atm.

 

And, of course, the winAPI can find if fonts exist or not on the users system.


#include <WinAPI\fileapi.mqh>
FIND_DATAW FD;
FindFirstFileW(TerminalInfoString(TERMINAL_COMMONDATA_PATH)+"\\pieces-of-eight.ttf",FD)

Returns a file handle (ie the file exists)

where as

FileIsExist("pieces-of-eight.ttf",FILE_COMMON);

returns (false)

even though both functions are searching the same folder for the same file.

Both functions return true if I look for a .png file located in the same place; I conclude that the MQL5 function is parsing out any non-whitelisted filetype from its results, thus If im dealing with fonts and want something inconsequential, like basic error checking, I must use the winAPI.

Reason: