I'm having a problem with metafile rendering in my Delphi XE application.
the problem is that when I'm rendering the metafile, the texts are too large. Irfanview and FastReports render it like this:
windows 7 Paint renders it fine: (here's what the text should look like)
Any ideas what is causing this?
Thank you!
emf
files are just a list of GDI commands. In fact, they can be "played back" very easily by the system, using standard Windows GDI command (in Delphi, a TMetaFile
is just a wrapper around those APIs).
When IrfanView or FastReport renders the metafile content, they just use Windows GDI corresponding commands. When Windows 7 Paint renders the metafile content, it uses the GDI+ renderer. I even think it internally convert the emf
file into emf+
format, then renders it with anti-aliaising using GDI+.
So if the emf
file renders incorrectly in IrfanView or FastReport, I suspect this is because your metafile is not well formed: the third party graphic engine you are using is producing non standard emf. A possible issue is that the font used is missing in the target system, and GDI does not substitute the font with the same as GDI+ does.
Another possibility is that the emf
file is maybe a dual format: it contains both emf
format (which was not properly created so is not rendered correctly using GDI) and emf+
format (which is rendered as expected using GDI+). Normally this dual emf/emf+
format should not exist: even the official GDI+ library does not allow to save its metafile content in emf+. This is some kind of "monster" format, created by your third-party library.
I suggest the following:
emf
file with EmfExplorer;emf
to emf+
converter API.For using GDI+, take a look at an Open Source SynGdiPlus unit: it will add GDI+ anti-aliaising to your produced bitmap. It is able to convert emf
to emf+
. It will use native Vista/Seven API (just like Windows 7 paint), or plain Delphi code under Windows XP.
The cause probably is that different monitor size and screen resolution ratio. GDI has parameters HORZRES
, HORZSIZE
, VERTRES
, VERTSIZE
. In most cases HORZRES/VERTRES
, HORZSIZE/VERTSIZE
(resolution ratio and screen ratio) are the same and everything works well... However if they are different (I have found some examples of this happening on servers) then the pixel is assumed to be rectangular, this causes LOGFONT.lfWidth
to be calculated "wrongly". LOGFONT.lfWidth
determines the aspect ratio of characters and this finally causes the weird looking letters.
One solution is to change the resolution so that HORZRES/VERTRES
, HORZSIZE/VERTSIZE
match. The other solution is to use a printer DC to render your things. Setting the LOGFONT.lfWidth
value explicitly may help. Also updating video driver may help.
I encountered the same problem, I had temporary drawing to a metafile canvas that used GetDC(0)
as reference instead of printer DC. Here are some links that have the same problem:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With