Author: William Gerbert
Display text diagonally
Answer:
To display text diagonally (or by any other degree), you need to create a font. The
font may be created using the function CreateFontIndirect. The parameter's record
member .lfOrientation specifies the angle in 0.1 degrees, e.g. 450 equals 45
degrees.
When the font handle is no longer needed, it should be deleted with DeleteObject().
The following function writes a sort of watermark on a DC and uses the API function
TextOut for this:
1
2 procedure Draw_Watermark_on_DC(const aDC: hDC; const x, y: integer);
3 var
4 plf: TLOGFONT;
5 hfnt, hfntPrev: HFONT;
6 const
7 txt1: PChar = 'Created with the demo version of'#0;
8 txt2: PChar = ' pasDOC'#0;
9 WaterMarkWidth = 300;
10 WaterMarkHeight = 300;
11 begin
12 // Specify a font typeface name and weight.
13 ZeroMemory(@plf, sizeof(plf));
14 lstrcpy(plf.lfFaceName, 'Arial');
15 plf.lfHeight := 30;
16 plf.lfEscapement := 0;
17 plf.lfOrientation := 450;
18 plf.lfWeight := FW_NORMAL;
19 plf.lfCharset := ANSI_CHARSET;
20 plf.lfOutPrecision := OUT_TT_PRECIS;
21 plf.lfQuality := PROOF_QUALITY;
22 hfnt := CreateFontIndirect(plf);
23
24 // Draw the rotated string
25 SetBkMode(aDC, TRANSPARENT);
26 hfntPrev := SelectObject(aDC, hfnt);
27 Windows.TextOut(aDC, x, y + WaterMarkHeight - 25, txt1, strlen(txt1));
28 Windows.TextOut(aDC, x + plf.lfHeight * 3, y + WaterMarkHeight - 25, txt2,
29 strlen(txt2));
30 SelectObject(aDC, hfntPrev);
31 DeleteObject(hfnt);
32 end;
|