Thursday, February 25, 2010

Draw Rotated Text

Current version of Lazarus provides the ability to draws text in an arbitrary rotation angle. Although is needed just to set the TFont.Orientation property to configure the feature, the position of the draw text will change according to the angle. So, to make things easier, i wrote a routine that draws a rotated text centered in a given Rect.

If someone needs something similar:


type
TRotateType = (rtNone, rtCounterClockWise, rtClockWise, rtFlip);

procedure DrawRotateText(Canvas: TCanvas; const R: TRect;
const Text: String; RotateType: TRotateType);
var
TextExtent: TSize;
SavedOrientation: Integer;
begin
SavedOrientation := Canvas.Font.Orientation;
TextExtent := Canvas.TextExtent(Text);
case RotateType of
rtNone:
begin
Canvas.Font.Orientation := 0;
Canvas.TextOut((R.Right - R.Left - TextExtent.cx) div 2,
(R.Bottom - R.Left - TextExtent.cy) div 2, Text);
end;
rtCounterClockWise:
begin
Canvas.Font.Orientation := 900;
Canvas.TextOut((R.Right - R.Left - TextExtent.cy) div 2,
(R.Bottom - R.Left + TextExtent.cx) div 2, Text);
end;
rtFlip:
begin
Canvas.Font.Orientation := 1800;
Canvas.TextOut((R.Right - R.Left + TextExtent.cx) div 2,
(R.Bottom - R.Left + TextExtent.cy) div 2, Text);
end;
rtClockWise:
begin
Canvas.Font.Orientation := -900;
Canvas.TextOut((R.Right - R.Left + TextExtent.cy) div 2,
(R.Bottom - R.Left - TextExtent.cx) div 2, Text);
end;
end;
Canvas.Font.Orientation := SavedOrientation;
end;

Thursday, February 11, 2010

Wednesday, February 03, 2010

Convert database files from Ansi to UTF-8

While porting old Delphi projects that uses paradox files i faced the problem that the data was stored in an ANSI code page (the current Lazarus version expects UTF-8 encoded strings).

So i wrote an simple application that can convert the encoding of database files (sqlite3, dbf, paradox).

That program can be useful for more than legacy code: after converting a spreadsheet data to a sqlite3 file using Sqlite Data Wizard. The resulted file was in ANSI and there was no option (AFAIK) to convert directly to UTF-8.

I put it here in hope that can be used by someone else.