Here is a sample code to create a vertical font:
function MakeVerticalFont(f: TFont): TFont;
var
lf : TLogFont;
tf : TFont;
begin
tf := TFont.Create;
tf.Assign( f );
GetObject(tf.Handle, sizeof(lf), @lf);
lf.lfEscapement := 900; // <--
lf.lfOrientation := 900; // <-- here we specify a rotation angle
tf.Handle := CreateFontIndirect(lf);
result := tf;
end;
[...]
var tf: TFont;
Begin
...
tf := MakeVerticalFont( mycanvas.Font );
mycanvas.Font.Assign( tf ); // <--- assign the `same` font rotated by 90 degrees
...
Update: Try to render vertical text on a form:
var tf : TFont;
tmpcanvas : TCanvas;
begin
tmpcanvas := form1.Canvas;
tmpcanvas.Font.Name := 'Arial';
tmpcanvas.Font.Height := 12;
tf := MakeVerticalFont(tmpcanvas.font);
tmpcanvas.Font.Assign(tf);
tmpcanvas.TextOut(50, 50, 'Am I vertical?');
tf.free;
Update 2: I think it's better to use the DrawTextEx Function which supports text alignment and word wrapping.
My Delphi version doesn't include it in the documentation but you can see the various flags in the above link.
Below is a sample code to see how to use it. I have disabled vertical font because it seems that word wrapping doesn't work well with vertical fonts.
procedure TForm1.Button1Click(Sender: TObject);
var tf : TFont;
tmpcanvas : TCanvas;
rc: TRect;
s : string;
begin
tmpcanvas := form1.Canvas;
tmpcanvas.Font.Name := 'Arial';
tmpcanvas.Font.Height := 14;
tf := MakeVerticalFont(tmpcanvas.font);
//tmpcanvas.Font.Assign(tf); <--- `disabled`
s := 'Hello world! I''m a long string';
rc := RECT(10, 10, 50, 200);
windows.DrawTextEx(
tmpcanvas.Handle,
PChar(s),
length(s),
rc,
DT_LEFT or DT_WORDBREAK,
nil);
tf.Free;
end;
Note that when you want to align text in the rectangle you should use the DT_SINGLELINE
flag.
For example this combination: DT_CENTER or DT_VCENTER or DT_SINGLELINE
, will center the text in the middle of the rectangle.