1 {***************************************************************************}
3 {* FreeType Performance Timer *}
6 {* This source code has been compiled and run under both Virtual Pascal *}
7 {* on OS/2 and Borland's BP7. *}
10 {* The C scan-line converter has been highly optimized, unlike the *}
11 {* Pascal one which is still 'aged'. Don't be surprised to see drastic *}
12 {* performance differences then.. *}
14 {***************************************************************************}
23 Dos
, (* for GetTime *)
29 TTError
, (* for CheckError *)
30 TTTypes
; (* for commodity types *)
42 Precis2
= Precis
div 2;
58 outlines
: array[0..Max_Glyphs
-1] of TT_Outline
;
65 numPoints
, numContours
: int
;
69 Rotation
: int
; (* Angle modulo 1024 *)
76 instance
: TT_Instance
;
79 metrics
: TT_Glyph_Metrics
;
80 imetrics
: TT_Instance_Metrics
;
82 props
: TT_Face_Properties
;
88 grayLines
: array[0..2048] of Byte;
104 Bit
.flow
:= TT_Flow_Down
;
112 Bit
.flow
:= TT_Flow_Down
;
116 GetMem( Bit
.buffer
, Bit
.size
);
117 if Bit
.buffer
= NIL then
119 Writeln('ERREUR:InitRows:Not enough memory to allocate BitMap');
123 FillChar( Bit
.Buffer
^, Bit
.Size
, 0 );
130 FillChar( Bit
.Buffer
^, Bit
.Size
, 0 );
134 procedure Preload_Glyphs( var start
: Int
);
136 i
, j
, fin
, np
, nc
: integer;
137 outline
: TT_Outline
;
140 fin
:= start
+ Max_Glyphs
;
141 if fin
> num_glyphs
then fin
:= num_glyphs
;
143 tot_glyph
:= fin
-start
;
150 Write('Loading ', fin
-start
,' glyphs ');
153 for i
:= start
to fin
-1 do
156 if TT_Load_Glyph( instance
,
159 TT_Load_Default
) = TT_Err_Ok
then
161 TT_Get_Glyph_Outline( glyph
, outline
);
163 TT_New_Outline( outline
.n_points
,
165 outlines
[cur_glyph
] );
167 outline
.high_precision
:= false;
168 outline
.second_pass
:= false;
170 TT_Copy_Outline( outline
, outlines
[cur_glyph
] );
173 TT_Translate_Outline( outlines
[cur_glyph
],
186 function ConvertRaster(index
: integer) : boolean;
189 error
:= TT_Get_Outline_Pixmap( outlines
[index
], Bit
)
191 error
:= TT_Get_Outline_Bitmap( outlines
[index
], Bit
);
193 ConvertRaster
:= (error
<> TT_Err_Ok
);
199 Writeln('Simple TrueType Glyphs viewer - part of the FreeType project' );
201 Writeln('Usage : ',paramStr(0),' FontName[.TTF]');
206 function Get_Time
: LongInt;
218 GetTime( heure
, min
, sec
, cent
);
219 Get_Time
:= 6000*longint(min
) + 100*longint(sec
) + cent
;
238 if ParamCount
= 0 then Usage
;
240 gray_level
:= ParamStr(1)='-g';
243 if ParamCount
<> 2 then Usage
else
245 if ParamCount
<> 1 then Usage
;
247 if gray_level
then Filename
:= ParamStr(2)
248 else Filename
:= ParamStr(1);
250 if Pos('.',FileName
) = 0 then FileName
:=FileName
+'.TTF';
252 error
:= TT_Open_Face( filename
, face
);
254 if error
<> TT_Err_Ok
then
256 Writeln('ERROR: Could not open ', FileName
);
260 TT_Get_Face_Properties( face
, props
);
262 num_glyphs
:= props
.num_Glyphs
;
264 i
:= length(FileName
);
265 while (i
> 1) and (FileName
[i
] <> '\') do dec(i
);
267 FileName
:= Copy( FileName
, i
+1, length(FileName
) );
269 error
:= TT_New_Glyph( face
, glyph
);
270 if error
<> TT_Err_Ok
then
272 Writeln('ERROR : Could not get glyph' );
276 i
:= props
.max_Points
* num_glyphs
;
279 i
:= i
* sizeof(Long
);
284 i
:= props
.max_Contours
* num_glyphs
;
286 GetMem( cons
, i
*sizeof(UShort
) );
288 error
:= TT_New_Instance( face
, instance
);
289 if error
<> TT_Err_Ok
then
291 Writeln('ERROR: Could not open face instance from ', Filename
);
295 error
:= TT_Set_Instance_PointSize( instance
, 400 );
296 if error
<> TT_Err_Ok
then
298 Writeln('ERROR: Could set pointsize' );
310 if not Set_Graph_Screen( Graphics_Mode_Gray
) then
311 Panic1( 'could not set grayscale graphics mode' );
315 if not Set_Graph_Screen( Graphics_Mode_Mono
) then
316 Panic1( 'could not set mono graphics mode' );
326 while start
< num_glyphs
do
329 Preload_Glyphs(start
);
337 for cur_glyph
:= 0 to tot_glyph
-1 do
339 if not ConvertRaster(cur_glyph
) then
342 Display_Bitmap_On_Screen( Bit
.Buffer
^, Bit
.rows
, Bit
.cols
);
354 writeln( T0
/100:0:2,' s' );
358 for cur_glyph
:= 0 to tot_glyph
-1 do
359 TT_Done_Outline( outlines
[cur_glyph
] );
369 writeln('Render time : ', T1
/100:0:2,' s' );
370 writeln('Total time : ', T
/100:0:2,' s');
371 writeln('Glyphs/second : ', Long(num_glyphs
)*100/T1
:0:1 );
372 writeln('Fails : ',Fail
);