~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to examples/lazfreetype/mainform.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
unit mainform;
 
2
 
 
3
{$mode objfpc}{$H+}
 
4
 
 
5
interface
 
6
 
 
7
uses
 
8
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
 
9
  ComCtrls, ExtCtrls, Spin, fpimage,
 
10
 
 
11
  IntfGraphics, GraphType,      //Intf basic routines
 
12
 
 
13
  EasyLazFreeType,  LazFreeTypeIntfDrawer  //EasyFreeType with Intf
 
14
 
 
15
  ;
 
16
 
 
17
type
 
18
 
 
19
  { TForm1 }
 
20
 
 
21
  TForm1 = class(TForm)
 
22
    Label1: TLabel;
 
23
    LFontSize: TLabel;
 
24
    Panel_Option: TPanel;
 
25
    SpinEdit_Zoom: TSpinEdit;
 
26
    TrackBar_Size: TTrackBar;
 
27
    procedure FormCreate(Sender: TObject);
 
28
    procedure FormDestroy(Sender: TObject);
 
29
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
 
30
    procedure FormPaint(Sender: TObject);
 
31
    procedure SpinEdit_ZoomChange(Sender: TObject);
 
32
    procedure TrackBar_SizeChange(Sender: TObject);
 
33
  private
 
34
    procedure UpdateSizeLabel;
 
35
    { private declarations }
 
36
  public
 
37
    { public declarations }
 
38
    lazimg: TLazIntfImage;
 
39
    drawer: TIntfFreeTypeDrawer;
 
40
    ftFont1,ftFont2,ftFont3: TFreeTypeFont;
 
41
    mx,my: integer; //mouse position
 
42
  end;
 
43
 
 
44
var
 
45
  Form1: TForm1; 
 
46
 
 
47
implementation
 
48
 
 
49
{ TForm1 }
 
50
 
 
51
procedure TForm1.FormCreate(Sender: TObject);
 
52
begin
 
53
  mx := clientwidth div 2;
 
54
  my := clientheight div 2;
 
55
 
 
56
  lazimg := TLazIntfImage.Create(0,0, [riqfRGB]);
 
57
  drawer := TIntfFreeTypeDrawer.Create(lazimg);
 
58
  ftFont1 := nil;
 
59
  ftFont2 := nil;
 
60
  ftFont3 := nil;
 
61
 
 
62
  try
 
63
    ftFont1 := TFreeTypeFont.Create;
 
64
    ftFont1.Name := 'arial.ttf';
 
65
 
 
66
    ftFont2 := TFreeTypeFont.Create;
 
67
    ftFont2.Name := 'timesi.ttf';
 
68
 
 
69
    ftFont3 := TFreeTypeFont.Create;
 
70
    ftFont3.Name := 'verdana.ttf';
 
71
  except
 
72
    on ex: Exception do
 
73
    begin
 
74
      FreeAndNil(drawer);
 
75
      FreeAndNil(lazimg);
 
76
      FreeAndNil(ftFont1);
 
77
      FreeAndNil(ftFont2);
 
78
      FreeAndNil(ftFont3);
 
79
      MessageDlg('Font error',ex.Message,mtError,[mbOk],0);
 
80
    end;
 
81
  end;
 
82
 
 
83
  UpdateSizeLabel;
 
84
end;
 
85
 
 
86
procedure TForm1.FormDestroy(Sender: TObject);
 
87
begin
 
88
  ftFont1.Free;
 
89
  ftFont2.Free;
 
90
  ftFont3.Free;
 
91
  drawer.Free;
 
92
  lazimg.Free;
 
93
end;
 
94
 
 
95
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
 
96
  Y: Integer);
 
97
begin
 
98
  mx := X;
 
99
  my := Y;
 
100
  invalidate;
 
101
end;
 
102
 
 
103
procedure TForm1.UpdateSizeLabel;
 
104
begin
 
105
  LFontSize.Caption := inttostr(TrackBar_Size.Position)+'pt';
 
106
  if ftFont1 <> nil then ftFont1.SizeInPoints := TrackBar_Size.Position;
 
107
  if ftFont2 <> nil then ftFont2.SizeInPoints := TrackBar_Size.Position;
 
108
  if ftFont3 <> nil then ftFont3.SizeInPoints := TrackBar_Size.Position;
 
109
end;
 
110
 
 
111
procedure TForm1.FormPaint(Sender: TObject);
 
112
const testtext = 'Enjoy'+LineEnding+'and play!';
 
113
var bmp: TBitmap;
 
114
    tx,ty: integer;
 
115
    p: array of TCharPosition;
 
116
    x,y: single;
 
117
    i: integer;
 
118
    StartTime,EndTime,EndTime2: TDateTime;
 
119
    zoom: integer;
 
120
begin
 
121
  if lazimg = nil then exit;
 
122
  canvas.Font.Name := 'Comic Sans MS';
 
123
 
 
124
  zoom := SpinEdit_Zoom.Value;
 
125
  StartTime := Now;
 
126
 
 
127
  tx := ClientWidth div zoom;
 
128
  ty := Panel_Option.Top div zoom;
 
129
  if (lazimg.Width <> tx) or (lazimg.Height <> ty) then
 
130
    lazimg.SetSize(tx,ty);
 
131
 
 
132
  drawer.FillPixels(TColorToFPColor(clWhite));
 
133
 
 
134
  x := mx/zoom;
 
135
  y := my/zoom;
 
136
 
 
137
  ftFont1.Hinted := true;
 
138
  ftFont1.ClearType := true;
 
139
  ftFont1.Quality := grqHighQuality;
 
140
  ftFont1.SmallLinePadding := false;
 
141
  drawer.DrawText(ftFont1.Information[ftiFullName], ftFont1, x, y, colBlack, [ftaRight, ftaBottom]);
 
142
 
 
143
  ftFont2.Hinted := false;
 
144
  ftFont2.ClearType := false;
 
145
  ftFont2.Quality := grqHighQuality;
 
146
  drawer.DrawText(ftFont2.Information[ftiFullName], ftFont2, x, y, colRed, 192, [ftaCenter, ftaBaseline]);
 
147
 
 
148
  ftFont3.Hinted := false;
 
149
  ftFont3.ClearType := false;
 
150
  ftFont3.Quality := grqMonochrome;
 
151
  drawer.DrawText(ftFont3.Information[ftiFullName]+' '+ftFont3.VersionNumber, ftFont3, x, y, colBlack, 128, [ftaLeft, ftaTop]);
 
152
 
 
153
  p := ftFont1.CharsPosition(ftFont1.Information[ftiFullName],[ftaRight, ftaBottom]);
 
154
  for i := 0 to high(p) do
 
155
  begin
 
156
    drawer.DrawVertLine(round(x+p[i].x),round(y+p[i].yTop),round(y+p[i].yBottom), TColorToFPColor(clBlue));
 
157
    drawer.DrawHorizLine(round(x+p[i].x),round(y+p[i].yBase),round(x+p[i].x+p[i].width), TColorToFPColor(clBlue));
 
158
  end;
 
159
 
 
160
  EndTime := Now;
 
161
 
 
162
  bmp := TBitmap.Create;
 
163
  bmp.LoadFromIntfImage(lazimg);
 
164
  Canvas.StretchDraw(rect(0,0,lazimg.width*zoom,lazimg.height*zoom),bmp);
 
165
  bmp.Free;
 
166
 
 
167
  EndTime2 := Now;
 
168
 
 
169
  Canvas.TextOut(0,0, inttostr(round((EndTime-StartTime)*24*60*60*1000))+' ms + '+inttostr(round((EndTime2-EndTime)*24*60*60*1000))+' ms');
 
170
 
 
171
end;
 
172
 
 
173
procedure TForm1.SpinEdit_ZoomChange(Sender: TObject);
 
174
begin
 
175
  Invalidate;
 
176
end;
 
177
 
 
178
procedure TForm1.TrackBar_SizeChange(Sender: TObject);
 
179
begin
 
180
  UpdateSizeLabel;
 
181
  Invalidate;
 
182
end;
 
183
 
 
184
{$R *.lfm}
 
185
 
 
186
end.
 
187