When I load an EMF file with "Image.Picture.Assign(Metafile)" then everything is OK. Looking at the preview window, all Elements are properly scaled, text bewares it's scale - as wanted - independently from the meta scale, and text has the correct rotation.
When I "load" the same EMF with MetaCanvas.Draw(x, y, Meta) then texts are rotated by 180 deg and don't beware their scale independently from meta scale. I only remember a single japanese site where they handle this problem with a simple correction code I don't remember anymore.
The sample code below shows the syntax without text correction.
Sorry for not translating the comments to English.
The code preparates a print preview for metafiles (EMF). Paper dimensions and printable area are zoomable and at the same time the emf graphic is scalable inside the printable area. Moving and rotating of the emf graphic is left out here.
Norbert
- Code: Select all
//------------------------------------------------------------------------------
procedure TImageForm.PreviewMetaFile(EMF: TMetaFile; Ratio: double; ScOfs: integer);
//Mit [pagX, pagY] wird die Größe des Blatts dargestellt.
//Mit [pixX, pixY] wird die Größe der druckbaren Fläche gestrichelt gezeichnet.
//Mit [ofsX, ofsY] gibt der Drucker den Abstand zum Blattrand links oben vor.
//Mit [ScOfs] wird der Abstand des Blatts von Image1 links und oben bestimmt.
//Mit [Ratio] erfolgt die Skalierung der Zeichnung in der druckbaren Fläche.
var
ScaleX, ScaleY, Scale, TrackScale : single;
Meta : tMetafile;
MetaCanvas : TMetafileCanvas;
begin
//Blattrand und druckbare Fläche erzeugen
Meta := TMetafile.Create;
try
//Metafile erzeugen
if Ratio = 0.0 then Ratio := 1.0;
Meta.Width := pagX + ScOfs;
Meta.Height := pagY + ScOfs;
MetaCanvas := TMetafileCanvas.Create(Meta, Printer.Handle);
try
//Fläche des Blatts
MetaCanvas.Brush.Color := clWindow; //Hintergrundfarbe
MetaCanvas.Rectangle(ScOfs, ScOfs, pagX + ScOfs, pagY + ScOfs);
//Druckbare Fläche
MetaCanvas.Pen.Style := psDot;
MetaCanvas.Rectangle(ofsX + ScOfs, ofsY + ScOfs, ofsX + pixX + ScOfs, ofsY + pixY + ScOfs);
MetaCanvas.Pen.Style := psSolid;
//Die Metafile Zeichnung einfügen
MetaCanvas.Draw(ofsX + ScOfs, ofsY + ScOfs, Meta); <----- FAIL
finally
MetaCanvas.Free;
end;
//Blattgröße in [Zoll]
Meta.Inch := 1;
//Blattfläche in Image1 zoomen
Meta.Width := Round(Meta.Width * Ratio);
Meta.Height := Round(Meta.Height * Ratio);
//Blattfläche als Hintergrund zu Image1 übertragen
Image1.Picture.Assign(Meta); // <------ OK
except
Meta.Free;
raise;
end;
end;
Folks, I forgot to tell You that the strange behavior of both functions are depending on changed current system font configuration. As soon as a new EMF was generated all fonts are shown and functionable as designed.
The behavior of fonts only changes after source code was edited, compiled and invoked.
Please replace:
"MetaCanvas.Draw(ofsX + ScOfs, ofsY + ScOfs, Meta);"
with
"MetaCanvas.Draw(ofsX + ScOfs, ofsY + ScOfs, EMF);"
as shown in the procedure declaration.
Norbert
//invisible ninja mod@work