DelphiFAQ Home Search:

Display text diagonally

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

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:

procedure Draw_Watermark_on_DC (const aDC : hDC; const x,y : integer);
var
  plf            : TLOGFONT;
  hfnt, hfntPrev : HFONT;
const
  txt1 : PChar = 'Created with the demo version of'#0;
  txt2 : PChar = '      pasDOC'#0;
  WaterMarkWidth = 300;
  WaterMarkHeight= 300;
begin
  // Specify a font typeface name and weight.
  ZeroMemory (@plf, sizeof(plf));
  lstrcpy(plf.lfFaceName, 'Arial');
  plf.lfHeight := 30;
  plf.lfEscapement := 0;
  plf.lfOrientation:= 450;
  plf.lfWeight := FW_NORMAL;
  plf.lfCharset:= ANSI_CHARSET;
  plf.lfOutPrecision := OUT_TT_PRECIS;
  plf.lfQuality := PROOF_QUALITY;
  hfnt := CreateFontIndirect(plf);

  // Draw the rotated string
  SetBkMode(aDC, TRANSPARENT);
  hfntPrev := SelectObject(aDC, hfnt);
  Windows.TextOut(aDC, x, y + WaterMarkHeight - 25, txt1, strlen(txt1));
  Windows.TextOut(aDC, x+plf.lfHeight * 3, y + WaterMarkHeight - 25, txt2, strlen(txt2));
  SelectObject(aDC, hfntPrev);
  DeleteObject(hfnt);
end;

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.