File: mainform.pas

package info (click to toggle)
lazarus 2.0.10%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 219,188 kB
  • sloc: pascal: 1,867,962; xml: 265,716; cpp: 56,595; sh: 3,005; java: 609; makefile: 568; perl: 297; sql: 222; ansic: 137
file content (96 lines) | stat: -rw-r--r-- 2,689 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
unit mainform;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Forms, Graphics, ExtCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Image: TImage;
    procedure FormCreate(Sender: TObject);
  private

  public

  end; 

var
  Form1: TForm1; 

implementation

uses lclintf, types;

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
  lRes: Integer;
  lStr: String;
  lMaxCount: Integer;
  lPartialWidths: array[0..23] of Integer;
  lSize: TSize;
  i: Integer;
begin
  for i := 0 to 23 do lPartialWidths[i] := 0;

  // Basic initialization
  Image.Canvas.Font.Size := 12;
  Image.Canvas.Pen.Color := clWhite;
  Image.Canvas.Brush.Color := clWhite;
  Image.Canvas.Brush.Style := bsSolid;
  Image.Canvas.Rectangle(0, 0, Image.Width, Image.Height);

  // TextFitInfo test 1 (calls GetTextExtentExPoint with partial widths = nil)
  lStr := 'ABCDEFGHIJKLMNOPQRSXYZ';
  lRes := Image.Canvas.TextFitInfo(lStr, 80);
  Image.Canvas.TextOut(20, 20, Format('TextFitInfo Test 1. Returned %d should be aprox. 7 to 10', [lRes]));
  Image.Canvas.Brush.Color := clBlue;
  Image.Canvas.Brush.Style := bsSolid;
  Image.Canvas.Rectangle(20, 35, 100, 50);
  Image.Canvas.Brush.Style := bsClear;
  Image.Canvas.TextOut(20, 35, lStr);

  // GetTextExtentExPoint test 1 with partial widths and MaxCount
  lStr := 'ABCDEFGHIJKLMNOPQRSXYZ';
  LCLIntf.GetTextExtentExPoint(Image.Canvas.Handle, PChar(lStr),
    Length(lStr), 50, @lMaxCount, @lPartialWidths[0], lSize);
  lRes := Image.Canvas.TextFitInfo(lStr, 50);
  Image.Canvas.Brush.Style := bsClear;
  Image.Canvas.TextOut(20, 60, Format('GetTextExtentExPoint Test 1. Returned MaxCount=%d should be aprox. 4 to 6', [lMaxCount]));
  Image.Canvas.Brush.Color := clBlue;
  for i := 0 to 6 do
  begin
    Image.Canvas.Brush.Style := bsSolid;
    Image.Canvas.Rectangle(20, 75 + i * 15, 20+lPartialWidths[i], 90 + i * 15);
    Image.Canvas.Brush.Style := bsClear;
    Image.Canvas.TextOut(20, 75 + i *15, lStr);
  end;

  // Now add something hard: Arabic
  lStr := 'العرب';
  LCLIntf.GetTextExtentExPoint(Image.Canvas.Handle, PChar(lStr),
    Length(lStr), 50, @lMaxCount, @lPartialWidths[0], lSize);
  lRes := Image.Canvas.TextFitInfo(lStr, 50);
  Image.Canvas.Brush.Style := bsClear;
  Image.Canvas.TextOut(20, 200, Format('GetTextExtentExPoint Arabic. Returned MaxCount=%d should be aprox. 5', [lMaxCount]));
  Image.Canvas.Brush.Color := clBlue;
  for i := 0 to 4 do
  begin
    Image.Canvas.Brush.Style := bsSolid;
    Image.Canvas.Rectangle(20+lSize.cx-lPartialWidths[i], 225 + i * 15, 20+lSize.cx, 240 + i * 15);
    Image.Canvas.Brush.Style := bsClear;
    Image.Canvas.TextOut(20, 225 + i *15, lStr);
  end;
end;

end.