when rendering metafile, the texts are too large - delphi

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

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:
http://us.generation-nt.com/answer/createenhmetafile-app-running-via-remote-desktop-help-27451862.html
http://social.msdn.microsoft.com/Forums/en/windowsgeneraldevelopmentissues/thread/a4a12ed8-c673-4a5c-94e1-7165b16f6955

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.

Related

Exchanging documents among several system and printing them

There are two systems. I need to get the document in some format and print it in my application.
The source file should be in a pdf format.
Do you know the component for delphi7 that i could be able to open pdf file and print it on delphi's canvas. Is such approach good for the pdf document quality?
Or which format of the source document could be better to print in delphi application?
Thanks
I think almost all PDF preview components may do it.
When searching - https://www.google.ru/search?client=opera&q=delphi+render+pdf+to+canvas&sourceid=opera - you would instantly get at least few commercial libs:
http://www.gnostice.com/nl_article.asp?id=229&t=Convert_PDF_To_High-Resolution_Images_Using_Delphi
http://www.quickpdflibrary.com/faq/can-i-use-quick-pdf-as-a-viewer-in-my-delphi-application.php
http://www.wpcubed.com/manuals/wpviewpdf/idh_twpviewpdf_printhdc.htm
TCanvas is a wapper around Windows HDC. See http://docwiki.embarcadero.com/Libraries/en/Vcl.Graphics.TCanvas.Handle

Report generators that can produce PDF/A compliant files

Which of the mainstream Delphi report generators (if any) supports generating PDF files that comply with PDF/A standard? I'm mostly curious about FastReports and QuickReport.
We provided an open source report builder, to be used from code, which is able to produce PDF or even PDF/A compliant files.
You create your report from code, then you can preview it on the screen. You can then print or export the report as PDF. Note that the report drawing uses GDI+, even if you embed .emf files or TMetaFile in them: with antialiaising, they just look smooth on screen. There are some report-dedicated methods to create the report, but also a true Canvas property, in which you can draw whatever you want.
You can use the same class without the preview function, just to create a pdf file from some content.
It's free, licensed under MPL/LGPL/GPL, and compiles and run from Delphi 6 up to XE. It's 100% Unicode-ready, even before Delphi 2009.
In order to have your reports being compliant with the PDF/A standard, you must ensure that the ExportPDFA1 property is set to true. Only a sub-set of the font file (i.e. only used characters) will be joined to the pdf content, saving disk space. Therefore PDF/A files will be bigger than PDF files generated with the default options.
Reporting has just been enhanced (in our source code repository): now handle bookmarks, links, and document outline, and life-navigation within the report preview. The generated PDF file also handle those links and outline tree. Some issues were also fixed (about bitmaps or underlined text). And one bitmap will be stored only once in the PDF, if it's drawn several times on the report. So make sure you're using the latest source code repository version.
Have you considered using a PDF printer such as PDF Factory?
Generally the quickest way to get PDF's from reports.

Delphi 7 GIF in picture Dialog

I am using Delphi 7 and the OpenPictureDialog to open / preview various images. This works fine when opening a bmp, jpg, etc.; however, if I try to do the same with a gif I get the following error. Anyone got any idea why or have a fix for it?
thanks
Colin
Use this TGIFImage. This is the original unit which was donated to CodeGear in 2006. It supports Delphi7.
copy GifImage.pas to your project path (from gifimaged2010b.zip) ,
and add to your uses list ;
thats all
It will automatically add GIF in filters for openpicturedialog (**)
Just use the GraphicEx library by Mike Lischke. Just add a couple files to your uses list and your application natively supports GIF, TIFF, PNG and many many others. The standard TImage will work with them and also the TPictureDialog (along with all others standard components that use TGraphic - take note that some features will only work at runtime).
If you use our free syngdiplus unit, you'll get GIF, JPEG and TIFF image support at once, by using the gdiplus library, available on every Windows since Windows XP. It supports loading and saving pictures, and the preview in TPictureDialog. And your exe size with increase much less than with GraphicEx or TGifImage.
Works from Delphi 6 up to Delphi XE.
And you'll be able to draw any TCanvas with anti-aliaising.
See http://synopse.info/forum/viewforum.php?id=4
Delphi 7 simply doesn't support GIF images. This has led to a number of third-party components for reading GIF files. However, as of Delphi 2006 (IIRC), the RTL/VCL can read GIF files as well. Just include GifImg in the uses clause. (In fact, as of Delphi 2009, the RTL/VCL can also read PNG files. And then there is really no need for GIF support, because the PNG file format is superior in almost every way. The only thing supported by GIF that is not supported by PNG is (low-quality(1)) animations.)
(1) GIF only supports 256 colours.

Covnerting PDF's to TBitmap image

what is the easiest method to convert a PDF into a TBitmap image in delphi?
if there are any commercial available tools for delphi, I can buy one if it is reliable and or not expensive...
I am thinking of some kind of viewer which I can browse pages.. zoom... and export in the desired resolution..
I have had good results with QuickPDF. It's relatively inexpensive and there is a trial version available.
You could try using the ghostscript api from delphi (see http://ftp.uasw.edu/pub/ghostscript/contrib/ for delphi example files) to convert to a bitmap.
Though I've not used it (was just aware of its existence) I would expect you should be able to put the data into a memory stream and read it from there.
Though, if your software is going to be non-open source it could be an issue .

How to merge tiff images with Delphi?

I have 4 small tiff images and I would like to generate a big one by merging the 4 single one. Does anyone know how to do it directly with Delphi or some good component that could do it?
You could use GraphicEx by Mike Lischke to load the Tiff images:
http://www.soft-gems.net/index.php?option=com_content&task=view&id=13&Itemid=33
ImageMagick is a command line application that can do such kind of operations on different image file formats including tiff.
The API seems to be usable from Delphi, see PascalMagick.
Another excellent graphics library for Delphi is Graphics32
Edit: As Vegar said, it looks that Graphics32 cannot be used to load TIFF format.
Another library you can use is FreeImage. It supports loading and writing of TIFF files. Beware: the Delphi wrapper is not actively maintained, but it works. We use it in our software to display previews of images.
ImageEn one of the best Image libraries for Delphi, and it's native VCL ;-)

Resources