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

« back to all changes in this revision

Viewing changes to components/aggpas/freetype_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
 
//
2
 
// AggPas 2.4 RM3 Demo application
3
 
// Note: Press F1 key on run to see more info about this demo
4
 
//
5
 
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
6
 
//
7
 
program
8
 
 freetype_test ;
9
 
 
10
 
uses
11
 
 SysUtils ,
12
 
 
13
 
 agg_basics ,
14
 
 agg_platform_support ,
15
 
 
16
 
 agg_color ,
17
 
 agg_pixfmt ,
18
 
 agg_pixfmt_rgb ,
19
 
 
20
 
 agg_ctrl ,
21
 
 agg_slider_ctrl ,
22
 
 agg_cbox_ctrl ,
23
 
 agg_rbox_ctrl ,
24
 
 
25
 
 agg_rendering_buffer ,
26
 
 agg_renderer_base ,
27
 
 agg_renderer_scanline ,
28
 
 agg_renderer_primitives ,
29
 
 agg_rasterizer_scanline_aa ,
30
 
 agg_scanline ,
31
 
 agg_scanline_u ,
32
 
 agg_scanline_bin ,
33
 
 agg_render_scanlines ,
34
 
 
35
 
 agg_trans_affine ,
36
 
 agg_curves ,
37
 
 agg_conv_curve ,
38
 
 agg_conv_contour ,
39
 
 agg_gamma_lut ,
40
 
 agg_gamma_functions ,
41
 
 agg_font_freetype ,
42
 
 agg_font_cache_manager ;
43
 
 
44
 
{$I agg_mode.inc }
45
 
 
46
 
const
47
 
 flip_y = true;
48
 
 
49
 
 angle_step = 0.5;
50
 
 
51
 
 text_ : PChar =
52
 
  //'0123456789ABCDEFGHIJKLMNOPRSTUVWXYZabcdefghijklmnoprstuvwxyz ' +
53
 
  //'[ BRAVO ][ VALUE ] [ T.W.Lewis ] [ Kerning Examples ] ' +
54
 
  'Anti-Grain Geometry is designed as a set of loosely coupled ' +
55
 
  'algorithms and class templates united with a common idea, ' +
56
 
  'so that all the components can be easily combined. Also, ' +
57
 
  'the template based design allows you to replace any part of ' +
58
 
  'the library without the necessity to modify a single byte in ' +
59
 
  'the existing code. ' +
60
 
  'AGG is designed keeping in mind extensibility and flexibility. ' +
61
 
  'Basically I just wanted to create a toolkit that would allow me ' +
62
 
  '(and anyone else) to add new fancy algorithms very easily. ' +
63
 
  'AGG does not dictate you any style of its use, you are free to ' +
64
 
  'use any part of it. However, AGG is often associated with a tool ' +
65
 
  'for rendering images in memory. That is not quite true, but it can ' +
66
 
  'be a good starting point in studying. The tutorials describe the ' +
67
 
  'use of AGG starting from the low level functionality that deals with ' +
68
 
  'frame buffers and pixels. Then you will gradually understand how to ' +
69
 
  'abstract different parts of the library and how to use them separately. ' +
70
 
  'Remember, the raster picture is often not the only thing you want to ' +
71
 
  'obtain, you will probably want to print your graphics with highest ' +
72
 
  'possible quality and in this case you can easily combine the "vectorial" ' +
73
 
  'part of the library with some API like Windows GDI, having a common ' +
74
 
  'external interface. If that API can render multi-polygons with non-zero ' +
75
 
  'and even-odd filling rules it''s all you need to incorporate AGG into ' +
76
 
  'your application. For example, Windows API PolyPolygon perfectly fits ' +
77
 
  'these needs, except certain advanced things like gradient filling, ' +
78
 
  'Gouraud shading, image transformations, and so on. Or, as an alternative, ' +
79
 
  'you can use all AGG algorithms producing high resolution pixel images and ' +
80
 
  'then to send the result to the printer as a pixel map.' +
81
 
  'Below is a typical brief scheme of the AGG rendering pipeline. ' +
82
 
  'Please note that any component between the Vertex Source ' +
83
 
  'and Screen Output is not mandatory. It all depends on your ' +
84
 
  'particular needs. For example, you can use your own rasterizer, ' +
85
 
  'based on Windows API. In this case you won''t need the AGG rasterizer ' +
86
 
  'and renderers. Or, if you need to draw only lines, you can use the ' +
87
 
  'AGG outline rasterizer that has certain restrictions but works faster. ' +
88
 
  'The number of possibilities is endless. ' +
89
 
  'Vertex Source is some object that produces polygons or polylines as ' +
90
 
  'a set of consecutive 2D vertices with commands like MoveTo, LineTo. ' +
91
 
  'It can be a container or some other object that generates vertices ' +
92
 
  'on demand. ' +
93
 
  'Coordinate conversion pipeline consists of a number of coordinate ' +
94
 
  'converters. It always works with vectorial data (X,Y) represented ' +
95
 
  'as floating point numbers (double). For example, it can contain an ' +
96
 
  'affine transformer, outline (stroke) generator, some marker ' +
97
 
  'generator (like arrowheads/arrowtails), dashed lines generator, ' +
98
 
  'and so on. The pipeline can have branches and you also can have ' +
99
 
  'any number of different pipelines. You also can write your own ' +
100
 
  'converter and include it into the pipeline. ' +
101
 
  'Scanline Rasterizer converts vectorial data into a number of ' +
102
 
  'horizontal scanlines. The scanlines usually (but not obligatory) ' +
103
 
  'carry information about Anti-Aliasing as coverage values. ' +
104
 
  'Renderers render scanlines, sorry for the tautology. The simplest ' +
105
 
  'example is solid filling. The renderer just adds a color to the ' +
106
 
  'scanline and writes the result into the rendering buffer. ' +
107
 
  'More complex renderers can produce multi-color result, ' +
108
 
  'like gradients, Gouraud shading, image transformations, ' +
109
 
  'patterns, and so on. Rendering Buffer is a buffer in memory ' +
110
 
  'that will be displayed afterwards. Usually but not obligatory ' +
111
 
  'it contains pixels in format that fits your video system. ' +
112
 
  'For example, 24 bits B-G-R, 32 bits B-G-R-A, or 15 ' +
113
 
  'bits R-G-B-555 for Windows. But in general, there''re no ' +
114
 
  'restrictions on pixel formats or color space if you write ' +
115
 
  'your own low level class that supports that format. ' +
116
 
  'Colors in AGG appear only in renderers, that is, when you ' +
117
 
  'actually put some data to the rendering buffer. In general, ' +
118
 
  'there''s no general purpose structure or class like color, ' +
119
 
  'instead, AGG always operates with concrete color space. ' +
120
 
  'There are plenty of color spaces in the world, like RGB, ' +
121
 
  'HSV, CMYK, etc., and all of them have certain restrictions. ' +
122
 
  'For example, the RGB color space is just a poor subset of ' +
123
 
  'colors that a human eye can recognize. If you look at the full ' +
124
 
  'CIE Chromaticity Diagram, you will see that the RGB triangle ' +
125
 
  'is just a little part of it. ' +
126
 
  'In other words there are plenty of colors in the real world ' +
127
 
  'that cannot be reproduced with RGB, CMYK, HSV, etc. Any color ' +
128
 
  'space except the one existing in Nature is restrictive. Thus, ' +
129
 
  'it was decided not to introduce such an object like color in ' +
130
 
  'order not to restrict the possibilities in advance. Instead, ' +
131
 
  'there are objects that operate with concrete color spaces. ' +
132
 
  'Currently there are agg::rgba and agg::rgba8 that operate ' +
133
 
  'with the most popular RGB color space (strictly speaking there''s ' +
134
 
  'RGB plus Alpha). The RGB color space is used with different ' +
135
 
  'pixel formats, like 24-bit RGB or 32-bit RGBA with different ' +
136
 
  'order of color components. But the common property of all of ' +
137
 
  'them is that they are essentially RGB. Although, AGG doesn''t ' +
138
 
  'explicitly support any other color spaces, there is at least ' +
139
 
  'a potential possibility of adding them. It means that all ' +
140
 
  'class and function templates that depend on the color type ' +
141
 
  'are parameterized with the ColorT argument. ' +
142
 
  'Basically, AGG operates with coordinates of the output device. ' +
143
 
  'On your screen there are pixels. But unlike many other libraries ' +
144
 
  'and APIs AGG initially supports Subpixel Accuracy. It means ' +
145
 
  'that the coordinates are represented as doubles, where fractional ' +
146
 
  'values actually take effect. AGG doesn''t have an embedded ' +
147
 
  'conversion mechanism from world to screen coordinates in order ' +
148
 
  'not to restrict your freedom. It''s very important where and when ' +
149
 
  'you do that conversion, so, different applications can require ' +
150
 
  'different approaches. AGG just provides you a transformer of ' +
151
 
  'that kind, namely, that can convert your own view port to the ' +
152
 
  'device one. And it''s your responsibility to include it into ' +
153
 
  'the proper place of the pipeline. You can also write your ' +
154
 
  'own very simple class that will allow you to operate with ' +
155
 
  'millimeters, inches, or any other physical units. ' +
156
 
  'Internally, the rasterizers use integer coordinates of the ' +
157
 
  'format 24.8 bits, that is, 24 bits for the integer part and 8 ' +
158
 
  'bits for the fractional one. In other words, all the internal ' +
159
 
  'coordinates are multiplied by 256. If you intend to use AGG in ' +
160
 
  'some embedded system that has inefficient floating point ' +
161
 
  'processing, you still can use the rasterizers with their ' +
162
 
  'integer interfaces. Although, you won''t be able to use the ' +
163
 
  'floating point coordinate pipelines in this case. ';
164
 
 
165
 
var
166
 
 font_flip_y : boolean;
167
 
 font_name   : AnsiString;
168
 
 
169
 
type
170
 
 the_application = object(platform_support )
171
 
   m_ren_type : rbox_ctrl;
172
 
 
173
 
   m_height ,
174
 
   m_width  ,
175
 
   m_weight ,
176
 
   m_gamma  : slider_ctrl;
177
 
 
178
 
   m_hinting     ,
179
 
   m_kerning     ,
180
 
   m_performance : cbox_ctrl;
181
 
 
182
 
   m_feng : font_engine_freetype_int32;
183
 
   m_fman : font_cache_manager;
184
 
 
185
 
   m_old_height : double;
186
 
   m_gamma_lut  : gamma_lut;
187
 
 
188
 
  // Pipeline to process the vectors glyph paths (curves + contour)
189
 
   m_curves  : conv_curve;
190
 
   m_contour : conv_contour;
191
 
 
192
 
   m_angle : double;
193
 
 
194
 
   constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
195
 
   destructor  Destruct;
196
 
 
197
 
   function  draw_text(
198
 
              ras : rasterizer_scanline_aa_ptr;
199
 
              sl  : scanline_ptr;
200
 
              ren_solid : renderer_scanline_aa_solid_ptr;
201
 
              ren_bin   : renderer_scanline_bin_solid_ptr ) : unsigned;
202
 
 
203
 
   procedure on_draw; virtual;
204
 
 
205
 
   procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
206
 
   procedure on_ctrl_change; virtual;
207
 
 
208
 
  end;
209
 
 
210
 
{ CONSTRUCT }
211
 
constructor the_application.Construct;
212
 
begin
213
 
 inherited Construct(format_ ,flip_y_ );
214
 
 
215
 
 m_ren_type.Construct   (5.0 ,5.0  ,5.0 + 150.0 ,110.0 ,not flip_y_ );
216
 
 m_height.Construct     (160 ,10.0 ,640 - 5.0 ,18.0 ,not flip_y_ );
217
 
 m_width.Construct      (160 ,30.0 ,640 - 5.0 ,38.0 ,not flip_y_ );
218
 
 m_weight.Construct     (160 ,50.0 ,640 - 5.0 ,58.0 ,not flip_y_ );
219
 
 m_gamma.Construct      (260 ,70.0 ,640 - 5.0 ,78.0 ,not flip_y_ );
220
 
 m_hinting.Construct    (160 ,65.0 ,'Hinting' ,not flip_y_ );
221
 
 m_kerning.Construct    (160 ,80.0 ,'Kerning' ,not flip_y_ );
222
 
 m_performance.Construct(160 ,95.0 ,'Test Performance' ,not flip_y_ );
223
 
 
224
 
 m_feng.Construct;
225
 
 m_fman.Construct(@m_feng );
226
 
 
227
 
 m_old_height:=0.0;
228
 
 
229
 
 m_gamma_lut.Construct_(8 ,16 );
230
 
 m_curves.Construct    (m_fman.path_adaptor );
231
 
 m_contour.Construct   (@m_curves );
232
 
 
233
 
 m_ren_type.add_item ('Native Mono' );
234
 
 m_ren_type.add_item ('Native Gray 8' );
235
 
 m_ren_type.add_item ('Outline' );
236
 
 m_ren_type.add_item ('AGG Mono' );
237
 
 m_ren_type.add_item ('AGG Gray 8' );
238
 
 m_ren_type.cur_item_(1 );
239
 
 
240
 
 add_ctrl(@m_ren_type );
241
 
 
242
 
 m_ren_type.no_transform;
243
 
 
244
 
 m_height.label_('Font Height=%.2f' );
245
 
 m_height.range_(8, 32);
246
 
 m_height.value_(18 );
247
 
 
248
 
 m_height.num_steps_     (32 - 8 );
249
 
 m_height.text_thickness_(1.5 );
250
 
 
251
 
 add_ctrl(@m_height );
252
 
 
253
 
 m_height.no_transform;
254
 
 
255
 
 m_width.label_('Font Width=%.2f' );
256
 
 m_width.range_(8 ,32 );
257
 
 m_width.value_(18 );
258
 
 
259
 
 m_width.num_steps_     (32 - 8 );
260
 
 m_width.text_thickness_(1.5 );
261
 
 
262
 
 add_ctrl(@m_width );
263
 
 
264
 
 m_width.no_transform;
265
 
 
266
 
 m_weight.label_('Font Weight=%.2f' );
267
 
 m_weight.range_(-1 ,1 );
268
 
 
269
 
 m_weight.text_thickness_(1.5 );
270
 
 
271
 
 add_ctrl(@m_weight );
272
 
 
273
 
 m_weight.no_transform;
274
 
 
275
 
 m_gamma.label_('Gamma=%.2f' );
276
 
 m_gamma.range_(0.1 ,2.0 );
277
 
 m_gamma.value_(1.0 );
278
 
 
279
 
 m_gamma.text_thickness_(1.5 );
280
 
 
281
 
 add_ctrl(@m_gamma );
282
 
 
283
 
 m_gamma.no_transform;
284
 
 
285
 
 add_ctrl(@m_hinting );
286
 
 
287
 
 m_hinting.status_(true );
288
 
 m_hinting.no_transform;
289
 
 
290
 
 add_ctrl(@m_kerning );
291
 
 
292
 
 m_kerning.status_(true );
293
 
 m_kerning.no_transform;
294
 
 
295
 
 add_ctrl(@m_performance );
296
 
 
297
 
 m_performance.no_transform;
298
 
 
299
 
 m_curves.approximation_scale_ (2.0 );
300
 
 m_contour.auto_detect_orientation_(false );
301
 
 
302
 
 m_angle:=0;
303
 
 
304
 
end;
305
 
 
306
 
{ DESTRUCT }
307
 
destructor the_application.Destruct;
308
 
begin
309
 
 inherited Destruct;
310
 
 
311
 
 m_ren_type.Destruct;
312
 
 m_height.Destruct;
313
 
 m_width.Destruct;
314
 
 m_weight.Destruct;
315
 
 m_gamma.Destruct;
316
 
 m_hinting.Destruct;
317
 
 m_kerning.Destruct;
318
 
 m_performance.Destruct;
319
 
 
320
 
 m_feng.Destruct;
321
 
 m_fman.Destruct;
322
 
 
323
 
 m_gamma_lut.Destruct;
324
 
 m_curves.Destruct;
325
 
 m_contour.Destruct;
326
 
 
327
 
end;
328
 
 
329
 
{ DRAW_TEXT }
330
 
function the_application.draw_text;
331
 
var
332
 
 gren : glyph_rendering;
333
 
 
334
 
 num_glyphs : unsigned;
335
 
 
336
 
 mtx : trans_affine;
337
 
 taw : trans_affine_skewing;
338
 
 tar : trans_affine_rotation;
339
 
 tat : trans_affine_translation;
340
 
 
341
 
 x ,y0 ,y : double;
342
 
 
343
 
 p : int8u_ptr;
344
 
 
345
 
 rgba  : aggclr;
346
 
 glyph : glyph_cache_ptr;
347
 
 
348
 
begin
349
 
 gren:=glyph_ren_native_mono;
350
 
 
351
 
 case m_ren_type._cur_item of
352
 
  0 : gren:=glyph_ren_native_mono;
353
 
  1 : gren:=glyph_ren_native_gray8;
354
 
  2 : gren:=glyph_ren_outline;
355
 
  3 : gren:=glyph_ren_agg_mono;
356
 
  4 : gren:=glyph_ren_agg_gray8;
357
 
 
358
 
 end;
359
 
 
360
 
 num_glyphs:=0;
361
 
 
362
 
 m_contour.width_(-m_weight._value * m_height._value * 0.05 );
363
 
 
364
 
 if m_feng.load_font(@font_name[1 ] ,0 ,gren ) then
365
 
  begin
366
 
   m_feng.hinting_(m_hinting._status );
367
 
   m_feng.height_ (m_height._value );
368
 
   m_feng.width_  (m_width._value );
369
 
   m_feng.flip_y_ (font_flip_y);
370
 
 
371
 
   mtx.Construct;
372
 
 
373
 
   if m_angle <> 0 then
374
 
    begin
375
 
     tar.Construct(deg2rad(m_angle ) );
376
 
     mtx.multiply (@tar );
377
 
 
378
 
    end;
379
 
 
380
 
   //taw.Construct(-0.4 ,0 );        mtx.multiply(@taw );
381
 
   //tat.Construct(1 ,0 );           mtx.multiply(@tat );
382
 
 
383
 
   m_feng.transform_(@mtx );
384
 
 
385
 
   x :=10.0;
386
 
   y0:=_height - m_height._value - 10.0;
387
 
   y :=y0;
388
 
   p :=@text_[0 ];
389
 
 
390
 
   while p^ <> 0 do
391
 
    begin
392
 
     glyph:=m_fman.glyph(p^ );
393
 
 
394
 
     if glyph <> NIL then
395
 
      begin
396
 
       if m_kerning._status then
397
 
        m_fman.add_kerning(@x ,@y );
398
 
 
399
 
       if x >= _width - m_height._value then
400
 
        begin
401
 
         x :=10.0;
402
 
         y0:=y0 - m_height._value;
403
 
 
404
 
         if y0 <= 120 then
405
 
          break;
406
 
 
407
 
         y:=y0;
408
 
 
409
 
        end;
410
 
 
411
 
       m_fman.init_embedded_adaptors(glyph ,x ,y );
412
 
 
413
 
       case glyph.data_type of
414
 
        glyph_data_mono :
415
 
         begin
416
 
          rgba.ConstrInt(0 ,0 ,0 );
417
 
          ren_bin.color_(@rgba );
418
 
          
419
 
          render_scanlines(
420
 
           m_fman.mono_adaptor ,
421
 
           m_fman.mono_scanline ,
422
 
           ren_bin );
423
 
 
424
 
         end;
425
 
 
426
 
        glyph_data_gray8 :
427
 
         begin
428
 
          rgba.ConstrInt  (0 ,0 ,0 );
429
 
          ren_solid.color_(@rgba );
430
 
 
431
 
          render_scanlines(
432
 
           m_fman.gray8_adaptor ,
433
 
           m_fman.gray8_scanline ,
434
 
           ren_solid );
435
 
 
436
 
         end;
437
 
 
438
 
        glyph_data_outline :
439
 
         begin
440
 
          ras.reset;
441
 
 
442
 
          if Abs(m_weight._value ) <= 0.01 then
443
 
          // For the sake of efficiency skip the
444
 
          // contour converter if the weight is about zero.
445
 
           ras.add_path(@m_curves )
446
 
          else
447
 
           ras.add_path(@m_contour );
448
 
 
449
 
          rgba.ConstrInt  (0 ,0 ,0 );
450
 
          ren_solid.color_(@rgba );
451
 
 
452
 
          render_scanlines(ras ,sl ,ren_solid );
453
 
 
454
 
         end;
455
 
 
456
 
       end;
457
 
 
458
 
      // increment pen position
459
 
       x:=x + glyph.advance_x;
460
 
       y:=y + glyph.advance_y;
461
 
 
462
 
       inc(num_glyphs );
463
 
 
464
 
      end;
465
 
 
466
 
     inc(ptrcomp(p ) ,sizeof(int8u ) );
467
 
 
468
 
    end;
469
 
 
470
 
  end
471
 
 else
472
 
  message_(
473
 
   'Please copy file timesi.ttf to the current directory'#13 +
474
 
   'or download it from http://www.antigrain.com/timesi.zip' );
475
 
 
476
 
 result:=num_glyphs;
477
 
 
478
 
end;
479
 
 
480
 
{ ON_DRAW }
481
 
procedure the_application.on_draw;
482
 
var
483
 
 pf : pixel_formats;
484
 
 
485
 
 rgba : aggclr;
486
 
 
487
 
 ren_base  : renderer_base;
488
 
 ren_solid : renderer_scanline_aa_solid;
489
 
 ren_bin   : renderer_scanline_bin_solid;
490
 
 
491
 
 sl  : scanline_u8;
492
 
 ras : rasterizer_scanline_aa;
493
 
 
494
 
 gm_th : gamma_threshold;
495
 
 gm_no : gamma_none;
496
 
 gm_pw : gamma_power;
497
 
 
498
 
begin
499
 
// Initialize structures
500
 
 pixfmt_bgr24_gamma(pf ,rbuf_window ,@m_gamma_lut );
501
 
 
502
 
 ren_base.Construct (@pf );
503
 
 ren_solid.Construct(@ren_base );
504
 
 ren_bin.Construct  (@ren_base );
505
 
 
506
 
 rgba.ConstrDbl(1 ,1 ,1 );
507
 
 ren_base.clear(@rgba );
508
 
 
509
 
 sl.Construct;
510
 
 ras.Construct;
511
 
 
512
 
 if m_height._value <> m_old_height then
513
 
  begin
514
 
   m_old_height:=m_height._value;
515
 
 
516
 
   m_width.value_(m_old_height );
517
 
 
518
 
  end;
519
 
 
520
 
// Setup Gamma
521
 
 if m_ren_type._cur_item = 3 then
522
 
  begin
523
 
  // When rendering in mono format,
524
 
  // Set threshold gamma = 0.5
525
 
   gm_th.Construct(m_gamma._value / 2.0 );
526
 
   m_feng.gamma_  (@gm_th );
527
 
 
528
 
  end
529
 
 else
530
 
  begin
531
 
   gm_no.Construct;
532
 
   m_feng.gamma_(@gm_no );
533
 
 
534
 
   m_gamma_lut.gamma_(m_gamma._value );
535
 
 
536
 
  end;
537
 
 
538
 
 if m_ren_type._cur_item = 2 then
539
 
  begin
540
 
  // For outline cache set gamma for the rasterizer
541
 
   gm_pw.Construct(m_gamma._value );
542
 
   ras.gamma      (@gm_pw );
543
 
 
544
 
  end;
545
 
 
546
 
// Render the text
547
 
 draw_text(@ras ,@sl ,@ren_solid ,@ren_bin );
548
 
 
549
 
// Render the controls
550
 
 gm_pw.Construct(1.0 );
551
 
 ras.gamma      (@gm_pw );
552
 
 
553
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_ren_type );
554
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_height );
555
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_width );
556
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_weight );
557
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_gamma );
558
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_hinting );
559
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_kerning );
560
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_performance );
561
 
 
562
 
// Free AGG resources
563
 
 sl.Destruct;
564
 
 ras.Destruct;
565
 
 
566
 
end;
567
 
 
568
 
{ ON_KEY }
569
 
procedure the_application.on_key;
570
 
begin
571
 
 if key = byte(' ' ) then
572
 
  begin
573
 
   font_flip_y:=not font_flip_y;
574
 
 
575
 
   force_redraw;
576
 
 
577
 
  end;
578
 
 
579
 
 if key = key_kp_minus then
580
 
  begin
581
 
   m_angle:=m_angle + angle_step;
582
 
 
583
 
   if m_angle > 360 then
584
 
    m_angle:=0;
585
 
 
586
 
   force_redraw;
587
 
 
588
 
  end;
589
 
 
590
 
 if key = key_kp_plus then
591
 
  begin
592
 
   m_angle:=m_angle - angle_step;
593
 
 
594
 
   if m_angle < 0 then
595
 
    m_angle:=360 - angle_step;
596
 
 
597
 
   force_redraw;
598
 
 
599
 
  end;
600
 
 
601
 
 if key = key_f1 then
602
 
  message_(
603
 
   'This example demonstrates the use of the FreeType font engine with cache. '#13 +
604
 
   'Cache can keep three types of data, vector path, Anti-Aliased scanline shape, '#13 +
605
 
   'and monochrome scanline shape. In case of caching scanline shapes the speed '#13 +
606
 
   'is pretty good and comparable with Windows hardware accelerated font rendering.'#13#13 +
607
 
   'How to play with:'#13#13 +
608
 
   'Press the spacebar to flip the text vertically.'#13#13 +
609
 
   'Key Plus - Increase font angle (not for Natives)'#13 +
610
 
   'Key Minus - Decrease font angle (not for Natives)' +
611
 
   #13#13'Note: F2 key saves current "screenshot" file in this demo''s directory.  ' );
612
 
 
613
 
end;
614
 
 
615
 
{ ON_CTRL_CHANGE }
616
 
procedure the_application.on_ctrl_change;
617
 
var
618
 
 pf : pixel_formats;
619
 
 
620
 
 rgba : aggclr;
621
 
 
622
 
 ren_base  : renderer_base;
623
 
 ren_solid : renderer_scanline_aa_solid;
624
 
 ren_bin   : renderer_scanline_bin_solid;
625
 
 
626
 
 sl  : scanline_u8;
627
 
 ras : rasterizer_scanline_aa;
628
 
 
629
 
 num_glyphs ,i : unsigned;
630
 
 
631
 
 t : double;
632
 
 
633
 
 buf : array[0..99 ] of char;
634
 
 
635
 
begin
636
 
 if m_performance._status then
637
 
  begin
638
 
   pixfmt_bgr24_gamma(pf ,rbuf_window ,@m_gamma_lut );
639
 
 
640
 
   ren_base.Construct (@pf );
641
 
   ren_solid.Construct(@ren_base );
642
 
   ren_bin.Construct  (@ren_base );
643
 
 
644
 
   rgba.ConstrDbl(1 ,1 ,1 );
645
 
   ren_base.clear(@rgba );
646
 
 
647
 
   sl.Construct;
648
 
   ras.Construct;
649
 
 
650
 
   num_glyphs:=0;
651
 
 
652
 
   start_timer;
653
 
 
654
 
   for i:=0 to 49 do
655
 
    inc(num_glyphs ,draw_text(@ras ,@sl ,@ren_solid ,@ren_bin ) );
656
 
 
657
 
   t:=elapsed_time;
658
 
 
659
 
   sprintf(@buf[0 ]             ,'Glyphs=%u, ' ,num_glyphs );
660
 
   sprintf(@buf[StrLen(@buf ) ] ,'Time=%.3fms, ' ,t );
661
 
   sprintf(@buf[StrLen(@buf ) ] ,'%.3f glyps/sec, ' ,(num_glyphs / t ) * 1000.0 );
662
 
   sprintf(@buf[StrLen(@buf ) ] ,'%.3f microsecond/glyph' , (t / num_glyphs) * 1000.0);
663
 
 
664
 
   message_(@buf[0 ] );
665
 
 
666
 
   m_performance.status_(false );
667
 
 
668
 
   force_redraw;
669
 
 
670
 
   sl.Destruct;
671
 
   ras.Destruct;
672
 
 
673
 
  end;
674
 
 
675
 
end;
676
 
 
677
 
VAR
678
 
 app : the_application;
679
 
 
680
 
BEGIN
681
 
 font_flip_y:=false;
682
 
 font_name  :='timesi.ttf';
683
 
 
684
 
{$IFDEF WIN32 }
685
 
 if ParamCount > 0 then
686
 
  font_name:=ParamStr(1 );
687
 
 
688
 
{$ENDIF }
689
 
 
690
 
 app.Construct(pix_format_bgr24 ,flip_y );
691
 
 app.caption_ ('AGG Example. Rendering Fonts with FreeType (F1-Help)' );
692
 
 
693
 
 if app.init(640 ,520 ,window_resize ) then
694
 
  app.run;
695
 
 
696
 
 app.Destruct;
697
 
 
698
 
END.