Discussion:
How to flip text in delphi?
(too old to reply)
LJ
2007-09-06 02:28:51 UTC
Permalink
I draw a string in canvas, how to flip it in horizontal?

i create a TLogFont, it can rotates,but you know it's not same to Flip...

thanks in advance.

Sincerely,
LJ
David Ninnes
2007-09-06 11:49:17 UTC
Permalink
Post by LJ
I draw a string in canvas, how to flip it in horizontal?
i create a TLogFont, it can rotates,but you know it's not same to Flip...
thanks in advance.
Sincerely,
LJ
LJ,

The easiest way that comes to mind is write it to a bitmap and flip the
bitmap. The other way that I haven't tried is to use the
SetWorldTransform with a matrix like here
http://msdn2.microsoft.com/en-us/library/ms533202.aspx it should work
but as I said I haven't tried it.

hth,
Dave
John Herbster
2007-09-06 12:05:42 UTC
Permalink
... a string in canvas, how to flip it in horizontal?
... rotates,but you know it's not same to Flip...
LJ,
What do you mean by "flip",
if not "rotate within plane"?
Mirror image?
--JohnH
yannis
2007-09-06 12:59:49 UTC
Permalink
Post by John Herbster
... a string in canvas, how to flip it in horizontal?
... rotates,but you know it's not same to Flip...
LJ,
What do you mean by "flip",
if not "rotate within plane"?
Mirror image?
--JohnH
yes usually flip means mirror either horizontaly or vertically but
almost never both.

regards
Yannis.
Andrew Jameson
2007-09-06 15:53:34 UTC
Permalink
Post by LJ
I draw a string in canvas, how to flip it in horizontal?
Your answer's probably here :

http://delphiforfun.org/programs/Delphi_Techniques/Inverted_Text.htm

Andrew
David Ninnes
2007-09-09 05:24:32 UTC
Permalink
Post by LJ
I draw a string in canvas, how to flip it in horizontal?
i create a TLogFont, it can rotates,but you know it's not same to Flip...
thanks in advance.
Sincerely,
LJ
The transforms do work, here's some sample code (GDI+) that mirrors
around the x, y and x and y. Drop a TPaintbox on the form set the
onpaint event to the following and you're away.

cheers,
Dave

procedure TForm29.PaintBox1Paint(Sender: TObject);
var
graphics : TGPGraphics;
FontFamily: TGPFontFamily;
Font: TGPFont;
SolidBrush: TGPSolidBrush;
Matrix : TGPmatrix;
SolidPen : TGPPen;
r : TGPrectF;
GraphicsPath : TGPGraphicsPath;
begin
graphics := TGPGraphics.Create(PaintBox1.Canvas.handle);
FontFamily := TGPFontFamily.Create('Times New Roman');
Font := TGPFont.Create(FontFamily, 32, FontStyleRegular,
UnitPixel);
SolidBrush := TGPSolidBrush.Create(MakeColor(255, 0, 0, 255));
SolidPen := TGPPen.Create(MakeColor(255, 0, 0, 255));

// graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);

// so you can see the box
graphics.drawRectangle(SolidPen, MakeRect(0,0,PaintBox1.Width-1,
PaintBox1.height-1));

// the normal text offset to the right half of the paintbox
graphics.TranslateTransform(PaintBox1.width div 2, 0);
graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
solidBrush);

// x mirror
matrix := TGPMatrix.Create(-1,0,0,1,PaintBox1.width div 2,0);
graphics.settransform(matrix);
graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
solidBrush);
matrix.free;

// y mirror
matrix := TGPMatrix.Create(1,0,0,-1,PaintBox1.width div
2,PaintBox1.height);
graphics.settransform(matrix);
graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
solidBrush);
matrix.free;

// x and y mirror
matrix := TGPMatrix.Create(-1,0,0,1,PaintBox1.width div 2,0);
graphics.settransform(matrix);
matrix.free;
matrix := TGPMatrix.Create(1,0,0,-1,0,PaintBox1.height);
graphics.multiplytransform(matrix);
graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
solidBrush);
matrix.free;

graphics.Free;
FontFamily.Free;
Font.Free;
SolidBrush.Free;
end;
LJ
2007-09-10 05:54:12 UTC
Permalink
now,i'm working on gdi.
Thanks, i'll take a look in gdi+.
Post by LJ
I draw a string in canvas, how to flip it in horizontal?
i create a TLogFont, it can rotates,but you know it's not same to Flip...
thanks in advance.
Sincerely,
LJ
The transforms do work, here's some sample code (GDI+) that mirrors around
the x, y and x and y. Drop a TPaintbox on the form set the onpaint event
to the following and you're away.
cheers,
Dave
procedure TForm29.PaintBox1Paint(Sender: TObject);
var
graphics : TGPGraphics;
FontFamily: TGPFontFamily;
Font: TGPFont;
SolidBrush: TGPSolidBrush;
Matrix : TGPmatrix;
SolidPen : TGPPen;
r : TGPrectF;
GraphicsPath : TGPGraphicsPath;
begin
graphics := TGPGraphics.Create(PaintBox1.Canvas.handle);
FontFamily := TGPFontFamily.Create('Times New Roman');
Font := TGPFont.Create(FontFamily, 32, FontStyleRegular,
UnitPixel);
SolidBrush := TGPSolidBrush.Create(MakeColor(255, 0, 0, 255));
SolidPen := TGPPen.Create(MakeColor(255, 0, 0, 255));
// graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
// so you can see the box
graphics.drawRectangle(SolidPen, MakeRect(0,0,PaintBox1.Width-1,
PaintBox1.height-1));
// the normal text offset to the right half of the paintbox
graphics.TranslateTransform(PaintBox1.width div 2, 0);
graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
solidBrush);
// x mirror
matrix := TGPMatrix.Create(-1,0,0,1,PaintBox1.width div 2,0);
graphics.settransform(matrix);
graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
solidBrush);
matrix.free;
// y mirror
matrix := TGPMatrix.Create(1,0,0,-1,PaintBox1.width div
2,PaintBox1.height);
graphics.settransform(matrix);
graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
solidBrush);
matrix.free;
// x and y mirror
matrix := TGPMatrix.Create(-1,0,0,1,PaintBox1.width div 2,0);
graphics.settransform(matrix);
matrix.free;
matrix := TGPMatrix.Create(1,0,0,-1,0,PaintBox1.height);
graphics.multiplytransform(matrix);
graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
solidBrush);
matrix.free;
graphics.Free;
FontFamily.Free;
Font.Free;
SolidBrush.Free;
end;
David Ninnes
2007-09-10 07:52:52 UTC
Permalink
Post by LJ
now,i'm working on gdi.
Thanks, i'll take a look in gdi+.
It should work in GDI too, I do most of my stuff in GDI+, so used that.

cheers,
Dave

Continue reading on narkive:
Loading...