5

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:

look at the text to the left of the graph

windows 7 Paint renders it fine: (here's what the text should look like)

windows 7 Paint renders it fine

Any ideas what is causing this?

Thank you!

Argalatyr
  • 4,639
  • 3
  • 36
  • 62
X-Ray
  • 2,816
  • 1
  • 37
  • 66
  • 5
    How are you creating the meta file? What about some code? – David Heffernan Jan 09 '12 at 20:08
  • Looking more closely at this on a real computer, I recognise that sort of effect. I've seen it with output of my own program. I think that's just the nature of the way some packages rasterise a metafile. Clearly the metafile is fine because one package renders it well. The other program you should look at is Word. If you want to export for consumption by a raster graphics package then export as bitmap in PNG format preferably. – David Heffernan Jan 09 '12 at 20:26
  • thank your for your comments. @DavidHeffernan: the metafile is created by the 3rd party graphing engine. – X-Ray Jan 09 '12 at 22:10
  • i'm using a metafile so it's a "vectored" file format intended to be nice for rendering to the report canvas for printing. – X-Ray Jan 09 '12 at 22:13
  • OK, but you talk about bitmaps in your question and they aren't vector, they are raster – David Heffernan Jan 09 '12 at 22:20
  • i shouldn't have mentioned rendering to a bitmap because i don't know what they render it to. – X-Ray Jan 09 '12 at 23:41
  • 2
    edited to remove mention of bitmap, per comment here – Argalatyr Jan 10 '12 at 05:53

3 Answers3

4

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:

  • Download and check your emf file with EmfExplorer;
  • Try to use GDI+ to render the metafile;
  • Try to use the 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.

Arnaud Bouchez
  • 42,305
  • 3
  • 71
  • 159
2

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:

Egon
  • 1,705
  • 18
  • 32
0

A bit of a gamble, but:

Maybe has to do with the new system font in Vista+ that newer Delphi's support? If it happened during porting, fixate the font used in the tmetafile in the old and new version.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89