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

« back to all changes in this revision

Viewing changes to components/aggpas/svg_test.dpr

  • 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
 
{mac_copy:tiger.svg}
2
 
//
3
 
// AggPas 2.4 RM3 Demo application
4
 
// Note: Press F1 key on run to see more info about this demo
5
 
//
6
 
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
7
 
//
8
 
{$mode delphi}
9
 
program
10
 
 svg_test ;
11
 
 
12
 
uses
13
 
 SysUtils ,
14
 
 
15
 
 agg_basics ,
16
 
 agg_platform_support ,
17
 
 
18
 
 agg_color ,
19
 
 agg_pixfmt ,
20
 
 agg_pixfmt_rgba ,
21
 
 
22
 
 agg_ctrl ,
23
 
 agg_slider_ctrl ,
24
 
 
25
 
 agg_rendering_buffer ,
26
 
 agg_renderer_base ,
27
 
 agg_renderer_scanline ,
28
 
 agg_rasterizer_scanline_aa ,
29
 
 agg_scanline ,
30
 
 agg_scanline_p ,
31
 
 agg_render_scanlines ,
32
 
 
33
 
 agg_trans_affine ,
34
 
 agg_gamma_functions ,
35
 
 agg_gsv_text ,
36
 
 agg_conv_stroke ,
37
 
 
38
 
 agg_svg_parser ,
39
 
 agg_svg_path_renderer ,
40
 
 agg_svg_exception ,
41
 
 file_utils_, AggPasLCL ;
42
 
 
43
 
{$I src/agg_mode.inc }
44
 
 
45
 
const
46
 
 flip_y = false;
47
 
 
48
 
type
49
 
 the_application = object(platform_support )
50
 
   m_path : path_renderer;
51
 
 
52
 
   m_expand ,
53
 
   m_gamma  ,
54
 
   m_scale  ,
55
 
   m_rotate : slider_ctrl;
56
 
 
57
 
   m_min_x ,
58
 
   m_min_y ,
59
 
   m_max_x ,
60
 
   m_max_y ,
61
 
 
62
 
   m_x  ,
63
 
   m_y  ,
64
 
   m_dx ,
65
 
   m_dy : double;
66
 
 
67
 
   m_drag_flag : boolean;
68
 
 
69
 
   constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
70
 
   destructor  Destruct;
71
 
 
72
 
   procedure parse_svg(fname : shortstring );
73
 
 
74
 
   procedure on_resize(sx ,sy : int ); virtual;
75
 
   procedure on_draw; virtual;
76
 
 
77
 
   procedure on_mouse_move(x ,y : int; flags : unsigned ); virtual;
78
 
 
79
 
   procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
80
 
   procedure on_mouse_button_up  (x ,y : int; flags : unsigned ); virtual;
81
 
 
82
 
   procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
83
 
 
84
 
  end;
85
 
 
86
 
{ CONSTRUCT }
87
 
constructor the_application.Construct;
88
 
begin
89
 
 inherited Construct(format_ ,flip_y_ );
90
 
 
91
 
 m_path.Construct;
92
 
 
93
 
 m_expand.Construct(5       ,5      ,256 - 5 ,11      ,not flip_y_ );
94
 
 m_gamma.Construct (5       ,5 + 15 ,256 - 5 ,11 + 15 ,not flip_y_ );
95
 
 m_scale.Construct (256 + 5 ,5      ,512 - 5 ,11      ,not flip_y_ );
96
 
 m_rotate.Construct(256 + 5 ,5 + 15 ,512 - 5 ,11 + 15 ,not flip_y_ );
97
 
 
98
 
 m_min_x:=0.0;
99
 
 m_min_y:=0.0;
100
 
 m_max_x:=0.0;
101
 
 m_max_y:=0.0;
102
 
 
103
 
 m_x :=0.0;
104
 
 m_y :=0.0;
105
 
 m_dx:=0.0;
106
 
 m_dy:=0.0;
107
 
 
108
 
 m_drag_flag:=false;
109
 
 
110
 
 add_ctrl(@m_expand );
111
 
 add_ctrl(@m_gamma );
112
 
 add_ctrl(@m_scale );
113
 
 add_ctrl(@m_rotate );
114
 
 
115
 
 m_expand.label_('Expand=%3.2f' );
116
 
 m_expand.range_(-1 ,1.2 );
117
 
 m_expand.value_(0.0 );
118
 
 
119
 
 m_gamma.label_('Gamma=%3.2f' );
120
 
 m_gamma.range_(0.0 ,3.0 );
121
 
 m_gamma.value_(1.0 );
122
 
 
123
 
 m_scale.label_('Scale=%3.2f' );
124
 
 m_scale.range_(0.2 ,10.0 );
125
 
 m_scale.value_(1.0 );
126
 
 
127
 
 m_rotate.label_('Rotate=%3.2f' );
128
 
 m_rotate.range_(-180.0 ,180.0 );
129
 
 m_rotate.value_(0.0 );
130
 
 
131
 
end;
132
 
 
133
 
{ DESTRUCT }
134
 
destructor the_application.Destruct;
135
 
begin
136
 
 inherited Destruct;
137
 
 
138
 
 m_path.Destruct;
139
 
 
140
 
 m_expand.Destruct;
141
 
 m_gamma.Destruct;
142
 
 m_scale.Destruct;
143
 
 m_rotate.Destruct;
144
 
 
145
 
end;
146
 
 
147
 
{ PARSE_SVG }
148
 
procedure the_application.parse_svg;
149
 
var
150
 
 p : parser;
151
 
 
152
 
begin
153
 
 p.Construct(@m_path );
154
 
 
155
 
 try
156
 
  p.parse(fname );
157
 
 
158
 
 except
159
 
  p.Destruct;
160
 
  raise;
161
 
 
162
 
 end;
163
 
 
164
 
 m_path.arrange_orientations;
165
 
 m_path.bounding_rect(@m_min_x ,@m_min_y ,@m_max_x ,@m_max_y );
166
 
 
167
 
 caption_(StrPas(PChar(p.title ) ) + ' (F1-Help)' );
168
 
 
169
 
 p.Destruct;
170
 
 
171
 
end;
172
 
 
173
 
{ ON_RESIZE }
174
 
procedure the_application.on_resize;
175
 
begin
176
 
end;
177
 
 
178
 
{ ON_DRAW }
179
 
procedure the_application.on_draw;
180
 
var
181
 
 pixf : pixel_formats;
182
 
 
183
 
 rb  : renderer_base;
184
 
 ren : renderer_scanline_aa_solid;
185
 
 ras : rasterizer_scanline_aa;
186
 
 sl  : scanline_p8;
187
 
 mtx : trans_affine;
188
 
 
189
 
 rgba : aggclr;
190
 
 gmpw : gamma_power;
191
 
 gmno : gamma_none;
192
 
 
193
 
 tat : trans_affine_translation;
194
 
 tas : trans_affine_scaling;
195
 
 tar : trans_affine_rotation;
196
 
 
197
 
 tm : double;
198
 
 
199
 
 vertex_count : unsigned;
200
 
 
201
 
 buf : array[0..127 ] of char;
202
 
 t   : gsv_text;
203
 
 pt  : conv_stroke;
204
 
 
205
 
begin
206
 
// Initialize structures
207
 
 pixfmt_bgra32(pixf ,rbuf_window );
208
 
 
209
 
 rb.Construct (@pixf );
210
 
 ren.Construct(@rb );
211
 
 
212
 
 rgba.ConstrDbl(1 ,1 ,1 );
213
 
 rb.clear      (@rgba );
214
 
 
215
 
 ras.Construct;
216
 
 sl.Construct;
217
 
 mtx.Construct;
218
 
 
219
 
// Render
220
 
 gmpw.Construct(m_gamma._value );
221
 
 ras.gamma     (@gmpw );
222
 
 
223
 
 tat.Construct((m_min_x + m_max_x ) * -0.5 ,(m_min_y + m_max_y ) * -0.5 );
224
 
 mtx.multiply (@tat );
225
 
 
226
 
 tas.Construct(m_scale._value );
227
 
 mtx.multiply (@tas );
228
 
 
229
 
 tar.Construct(deg2rad(m_rotate._value ) );
230
 
 mtx.multiply (@tar );
231
 
 
232
 
 tat.Construct((m_min_x + m_max_x ) * 0.5 + m_x ,(m_min_y + m_max_y ) * 0.5 + m_y + 30 );
233
 
 mtx.multiply (@tat );
234
 
 
235
 
 m_path.expand(m_expand._value );
236
 
 
237
 
 start_timer;
238
 
 
239
 
 m_path.render(@ras ,@sl ,@ren ,@mtx ,rb._clip_box ,1.0 );
240
 
 
241
 
 tm:=elapsed_time;
242
 
 
243
 
 vertex_count:=m_path.vertex_count;
244
 
 
245
 
// Render the controls
246
 
 gmno.Construct;
247
 
 ras.gamma(@gmno );
248
 
 
249
 
 render_ctrl(@ras ,@sl ,@ren ,@m_expand );
250
 
 render_ctrl(@ras ,@sl ,@ren ,@m_gamma );
251
 
 render_ctrl(@ras ,@sl ,@ren ,@m_scale );
252
 
 render_ctrl(@ras ,@sl ,@ren ,@m_rotate );
253
 
 
254
 
// Display text
255
 
 t.Construct;
256
 
 t.size_(10.0 );
257
 
 t.flip_(true );
258
 
 
259
 
 pt.Construct(@t );
260
 
 pt.width_   (1.5 );
261
 
 
262
 
 sprintf(@buf[0 ]                 ,'Vertices=%d ' ,vertex_count );
263
 
 sprintf(@buf[StrLen(@buf[0 ] ) ] ,'Time=%.3f ms' ,tm );
264
 
 
265
 
 t.start_point_(10.0 ,40.0 );
266
 
 t.text_       (@buf[0 ] );
267
 
 
268
 
 ras.add_path    (@pt );
269
 
 rgba.ConstrDbl  (0 ,0 ,0 );
270
 
 ren.color_      (@rgba );
271
 
 render_scanlines(@ras ,@sl ,@ren );
272
 
 
273
 
// Free AGG resources
274
 
 ras.Destruct;
275
 
 sl.Destruct;
276
 
 
277
 
 t.Destruct;
278
 
 pt.Destruct;
279
 
 
280
 
end;
281
 
 
282
 
{ ON_MOUSE_MOVE }
283
 
procedure the_application.on_mouse_move;
284
 
begin
285
 
 if flags = 0 then
286
 
  m_drag_flag:=false;
287
 
 
288
 
 if m_drag_flag then
289
 
  begin
290
 
   m_x:=x - m_dx;
291
 
   m_y:=y - m_dy;
292
 
 
293
 
   force_redraw;
294
 
 
295
 
  end;
296
 
 
297
 
end;
298
 
 
299
 
{ ON_MOUSE_BUTTON_DOWN }
300
 
procedure the_application.on_mouse_button_down;
301
 
begin
302
 
 m_dx:=x - m_x;
303
 
 m_dy:=y - m_y;
304
 
 
305
 
 m_drag_flag:=true;
306
 
 
307
 
end;
308
 
 
309
 
{ ON_MOUSE_BUTTON_UP }
310
 
procedure the_application.on_mouse_button_up;
311
 
begin
312
 
 m_drag_flag:=false;
313
 
 
314
 
end;
315
 
 
316
 
{ ON_KEY }
317
 
procedure the_application.on_key;
318
 
var
319
 
 mtx : trans_affine;
320
 
 tat : trans_affine_translation;
321
 
 tas : trans_affine_scaling;
322
 
 tar : trans_affine_rotation;
323
 
 
324
 
 m   : array[0..5 ] of double;
325
 
 buf : array[0..127 ] of char;
326
 
 fd  : text;
327
 
 
328
 
begin
329
 
 if key = byte(' ' ) then
330
 
  begin
331
 
   mtx.Construct;
332
 
 
333
 
   tat.Construct((m_min_x + m_max_x ) * -0.5 ,(m_min_y + m_max_y ) * -0.5 );
334
 
   mtx.multiply (@tat );
335
 
 
336
 
   tas.Construct(m_scale._value );
337
 
   mtx.multiply (@tas );
338
 
 
339
 
   tar.Construct(deg2rad(m_rotate._value ) );
340
 
   mtx.multiply (@tar );
341
 
 
342
 
   tat.Construct((m_min_x + m_max_x ) * 0.5 ,(m_min_y + m_max_y ) * 0.5 );
343
 
   mtx.multiply (@tat );
344
 
 
345
 
   tat.Construct(m_x ,m_y );
346
 
   mtx.multiply (@tat );
347
 
 
348
 
   mtx.store_to(@m );
349
 
 
350
 
   sprintf(@buf[0 ]                 ,'%3.3f, ' ,m[0 ] );
351
 
   sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f, ' ,m[1 ] );
352
 
   sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f, ' ,m[2 ] );
353
 
   sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f, ' ,m[3 ] );
354
 
   sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f, ' ,m[4 ] );
355
 
   sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f'   ,m[5 ] );
356
 
 
357
 
   message_(@buf[0 ] );
358
 
 
359
 
  {$I- }
360
 
   AssignFile(fd ,'transform.txt' );
361
 
   rewrite   (fd );
362
 
   writeln   (fd ,PChar(@buf[0 ] ) );
363
 
   close     (fd );
364
 
 
365
 
  end;
366
 
 
367
 
 if key = key_f1 then
368
 
  message_(
369
 
   'The SVG viewer is just another example of using Anti-Grain Geometry. The viewer '#13 +
370
 
   'supports absolute minimum of the SVG specification, it basically can be used as '#13 +
371
 
   'a simple example of AGG plus SVG. But of course, its functionality can be extended. '#13 +
372
 
   'The main point of the viewer is high quality and high performance. The Anti-Aliasing '#13 +
373
 
   'algorithm produces 256 levels of transparency. Actually, AGG computes the exact '#13 +
374
 
   'coverage of the outline on each pixel cell.'#13#13 +
375
 
 
376
 
   'Besides, the viewer has a very nice feature that I haven''t seen in any other ones. '#13 +
377
 
   'It''s eliminating of the "problem of adjacent edges". It appears when rendering '#13 +
378
 
   'adjacent polygons with anti-aliasing and looks like thin "web" upon the image. '#13 +
379
 
   'Strictly speaking, it''s possible to get rid of it completely only when the polygons '#13 +
380
 
   'are fully opaque. When they are translucent, the effect will appear anyway. However, '#13 +
381
 
   'it''s possible to reduce the effect so that it becomes almost invisible.'#13#13 +
382
 
   'How to play with:'#13#13 +
383
 
   'Use mouse to move the drawing around. Change size & rotation with top controls.'#13 +
384
 
   'Press the spacebar key to display and save the current transformation matrix.' );
385
 
 
386
 
end;
387
 
 
388
 
VAR
389
 
 app   : the_application;
390
 
 fname : shortstring;
391
 
 af    : api_file;
392
 
 
393
 
label
394
 
 Esc ;
395
 
 
396
 
BEGIN
397
 
 app.Construct(pix_format_bgra32 ,flip_y );
398
 
 
399
 
 fname:=app.file_source('svg' ,'tiger.svg' );
400
 
 
401
 
 if param_count > 0 then
402
 
  fname:=param_str(1 )
403
 
 
404
 
 else
405
 
  begin
406
 
   if api_open_file(af ,fname ) then
407
 
    api_close_file(af )
408
 
   else
409
 
    begin
410
 
     app.message_('Usage: svg_test <svg_file>' );
411
 
 
412
 
     goto Esc;  
413
 
        
414
 
    end;
415
 
 
416
 
  end;  
417
 
 
418
 
 try
419
 
  app.parse_svg(fname );
420
 
 
421
 
  if app.init(512 ,600 ,window_resize ) then
422
 
   app.run;
423
 
 
424
 
 except
425
 
  on e:svg_exception do
426
 
   begin
427
 
    app.message_(PChar(e._msg ) );
428
 
    e.Free;
429
 
 
430
 
   end;
431
 
 
432
 
 else
433
 
  app.message_('Unknown exception' );
434
 
 
435
 
 end;
436
 
 
437
 
Esc:
438
 
 app.Destruct;
439
 
 
440
 
END.