Commit f9fccbee8b265a7576b358191e940299ebe60827

Werner Lemberg 2005-05-19T07:20:24

* src/raster/ftmisc.h: New file. Only needed if ftraster.c is compiled as stand-alone. * src/raster/ftraster.c: Add comment how to compile as stand-alone. s/FT_CONFIG_OPTION_STATIC_RASTER/FT_STATIC_RASTER/. s/TT_STATIC_RASTER/FT_STATIC_RASTER/. [_STANDALONE_]: Include ftimage.h and ftmisc.h. (FT_TRACE1, FT_TRACE6, ft_memset, FT_MEM_ZERO): Define conditionally. (Render_Glyph, Render_Gray_Glyph): Return Raster_Err_None (or Raster_Err_Unsupported). (ft_black_new) [_STANDALONE_]: Fix type of `the_raster'. (ft_black_init, ft_black_reset, ft_black_set_mode, ft_black_render): Use `ras', not `raster'. (ft_black_done): Use FT_UNUSED_RASTER. (Horizontal_Sweep_Init, Horizontal_Sweep_Step, Horizontal_Gray_Sweep_Span): Use FT_UNUSED_RASTER. * docs/CHANGES: Updated.

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
diff --git a/ChangeLog b/ChangeLog
index ea95654..4ba58f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,30 @@
-2004-05-18  Werner Lemberg  <wl@gnu.org>
+2005-05-18  Kirill Smelkov  <kirr@mns.spb.ru>
+
+	* src/raster/ftmisc.h: New file.  Only needed if ftraster.c is
+	compiled as stand-alone.
+
+	* src/raster/ftraster.c: Add comment how to compile as stand-alone.
+	s/FT_CONFIG_OPTION_STATIC_RASTER/FT_STATIC_RASTER/.
+	s/TT_STATIC_RASTER/FT_STATIC_RASTER/.
+	[_STANDALONE_]: Include ftimage.h and ftmisc.h.
+	(FT_TRACE1, FT_TRACE6, ft_memset, FT_MEM_ZERO): Define
+	conditionally.
+	(Render_Glyph, Render_Gray_Glyph): Return Raster_Err_None (or
+	Raster_Err_Unsupported).
+	(ft_black_new) [_STANDALONE_]: Fix type of `the_raster'.
+	(ft_black_init, ft_black_reset, ft_black_set_mode, ft_black_render):
+	Use `ras', not `raster'.
+	(ft_black_done): Use FT_UNUSED_RASTER.
+	(Horizontal_Sweep_Init, Horizontal_Sweep_Step,
+	Horizontal_Gray_Sweep_Span): Use FT_UNUSED_RASTER.
+
+2005-05-18  Werner Lemberg  <wl@gnu.org>
 
 	* docs/announce: Start updating.
 
-2004-05-16  Vitaliy Pasternak  <v_a_pasternak@mail.ru>
+	* docs/CHANGES: Updated.
+
+2005-05-16  Vitaliy Pasternak  <v_a_pasternak@mail.ru>
 
 	* builds/win32/visualc/freetype.vcproj: Updated.
 	Exclude debug info for `Release' versions to reduce library size.
diff --git a/docs/CHANGES b/docs/CHANGES
index 6cf5d0c..a807aac 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -100,6 +100,9 @@ LATEST CHANGES BETWEEN 2.1.10 and 2.1.9
       compressed form (as a trie) which saves about 20KByte of code as
       well.
 
+    - Kyrill  Smelkov provided  patches to make  src/raster/ftraster.c
+      compile stand-alone again.
+
 
 ======================================================================
 
diff --git a/src/raster/ftmisc.h b/src/raster/ftmisc.h
new file mode 100644
index 0000000..c5dbd50
--- /dev/null
+++ b/src/raster/ftmisc.h
@@ -0,0 +1,83 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftmisc.h                                                               */
+/*                                                                         */
+/*    Miscellaneous macros for stand-alone rasterizer (specification       */
+/*    only).                                                               */
+/*                                                                         */
+/*  Copyright 2005 by                                                      */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used        */
+/*  modified and distributed under the terms of the FreeType project       */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+  /***************************************************/
+  /*                                                 */
+  /* This file is *not* portable!  You have to adapt */
+  /* its definitions to your platform.               */
+  /*                                                 */
+  /***************************************************/
+
+#ifndef __FTMISC_H__
+#define __FTMISC_H__
+
+#include <string.h> /* memset */
+
+#define FT_BEGIN_HEADER
+#define FT_END_HEADER
+
+#define FT_LOCAL_DEF( x )   static x
+
+  /* from include/freetype2/fttypes.h */
+
+  typedef unsigned char  FT_Byte;
+  typedef signed int     FT_Int;
+  typedef unsigned int   FT_UInt;
+  typedef signed long    FT_Long;
+  typedef unsigned long  FT_ULong;
+  typedef signed long    FT_F26Dot6;
+  typedef int            FT_Error;
+
+#define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
+          ( ( (FT_ULong)_x1 << 24 ) |     \
+            ( (FT_ULong)_x2 << 16 ) |     \
+            ( (FT_ULong)_x3 <<  8 ) |     \
+              (FT_ULong)_x4         )
+
+
+  /* from src/ftcalc.c */
+
+#include <inttypes.h>
+
+  typedef int64_t  FT_Int64;
+
+  static FT_Long
+  FT_MulDiv( FT_Long  a,
+             FT_Long  b,
+             FT_Long  c )
+  {
+    FT_Int   s;
+    FT_Long  d;
+
+
+    s = 1;
+    if ( a < 0 ) { a = -a; s = -1; }
+    if ( b < 0 ) { b = -b; s = -s; }
+    if ( c < 0 ) { c = -c; s = -s; }
+
+    d = (FT_Long)( c > 0 ? ( (FT_Int64)a * b + ( c >> 1 ) ) / c
+                         : 0x7FFFFFFFL );
+
+    return ( s > 0 ) ? d : -d;
+  }
+
+#endif /* __FTMISC_H__ */
+
+
+/* END */
diff --git a/src/raster/ftraster.c b/src/raster/ftraster.c
index cf634d7..d3e5bb1 100644
--- a/src/raster/ftraster.c
+++ b/src/raster/ftraster.c
@@ -17,15 +17,49 @@
 
   /*************************************************************************/
   /*                                                                       */
+  /* This file can be compiled without the rest of the FreeType engine, by */
+  /* defining the _STANDALONE_ macro when compiling it.  You also need to  */
+  /* put the files `ftimage.h' and `ftmisc.h' into the $(incdir)           */
+  /* directory.  Typically, you should do something like                   */
+  /*                                                                       */
+  /* - copy `src/raster/ftraster.c' (this file) to your current directory  */
+  /*                                                                       */
+  /* - copy `include/freetype/ftimage.h' and `src/raster/ftmisc.h'         */
+  /*   to your current directory                                           */
+  /*                                                                       */
+  /* - compile `ftraster' with the _STANDALONE_ macro defined, as in       */
+  /*                                                                       */
+  /*     cc -c -D_STANDALONE_ ftraster.c                                   */
+  /*                                                                       */
+  /* The renderer can be initialized with a call to                        */
+  /* `ft_standard_raster.raster_new'; a bitmap can be generated            */
+  /* with a call to `ft_standard_raster.raster_render'.                    */
+  /*                                                                       */
+  /* See the comments and documentation in the file `ftimage.h' for more   */
+  /* details on how the raster works.                                      */
+  /*                                                                       */
+  /*************************************************************************/
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* This is a rewrite of the FreeType 1.x scan-line converter             */
   /*                                                                       */
   /*************************************************************************/
 
+#ifdef _STANDALONE_
+
+#include "ftmisc.h"
+#include "ftimage.h"
+
+#else /* !_STANDALONE_ */
 
 #include <ft2build.h>
 #include "ftraster.h"
 #include FT_INTERNAL_CALC_H   /* for FT_MulDiv only */
 
+#endif /* !_STANDALONE_ */
+
 
   /*************************************************************************/
   /*                                                                       */
@@ -153,7 +187,9 @@
 #endif
 
 #ifndef FT_TRACE
-#define FT_TRACE( x )  do ; while ( 0 )     /* nothing */
+#define FT_TRACE( x )   do ; while ( 0 )    /* nothing */
+#define FT_TRACE1( x )  do ; while ( 0 )    /* nothing */
+#define FT_TRACE6( x )  do ; while ( 0 )    /* nothing */
 #endif
 
 #define Raster_Err_None          0
@@ -163,6 +199,7 @@
 #define Raster_Err_Invalid      -4
 #define Raster_Err_Unsupported  -5
 
+#define ft_memset   memset
 
 #else /* _STANDALONE_ */
 
@@ -187,6 +224,9 @@
 #define FT_MEM_SET( d, s, c )  ft_memset( d, s, c )
 #endif
 
+#ifndef FT_MEM_ZERO
+#define FT_MEM_ZERO( dest, count )  FT_MEM_SET( dest, 0, count )
+#endif
 
   /* FMulDiv means `Fast MulDiv'; it is used in case where `b' is       */
   /* typically a small value and the result of a*b is known to fit into */
@@ -323,7 +363,7 @@
   ( ( sizeof ( TProfile ) + sizeof ( Alignment ) - 1 ) / sizeof ( long ) )
 
 
-#ifdef TT_STATIC_RASTER
+#ifdef FT_STATIC_RASTER
 
 
 #define RAS_ARGS       /* void */
@@ -335,7 +375,7 @@
 #define FT_UNUSED_RASTER  do ; while ( 0 )
 
 
-#else /* TT_STATIC_RASTER */
+#else /* FT_STATIC_RASTER */
 
 
 #define RAS_ARGS       TRaster_Instance*  raster,
@@ -347,7 +387,7 @@
 #define FT_UNUSED_RASTER  FT_UNUSED( raster )
 
 
-#endif /* TT_STATIC_RASTER */
+#endif /* FT_STATIC_RASTER */
 
 
   typedef struct TRaster_Instance_  TRaster_Instance;
@@ -495,7 +535,7 @@
   };
 
 
-#ifdef FT_CONFIG_OPTION_STATIC_RASTER
+#ifdef FT_STATIC_RASTER
 
   static TRaster_Instance  cur_ras;
 #define ras  cur_ras
@@ -504,7 +544,7 @@
 
 #define ras  (*raster)
 
-#endif /* FT_CONFIG_OPTION_STATIC_RASTER */
+#endif /* FT_STATIC_RASTER */
 
 
   /*************************************************************************/
@@ -2250,7 +2290,7 @@
                                   Short*  max )
   {
     /* nothing, really */
-    FT_UNUSED( raster );
+    FT_UNUSED_RASTER;
     FT_UNUSED( min );
     FT_UNUSED( max );
   }
@@ -2399,7 +2439,7 @@
   Horizontal_Sweep_Step( RAS_ARG )
   {
     /* Nothing, really */
-    FT_UNUSED( raster );
+    FT_UNUSED_RASTER;
   }
 
 
@@ -2546,7 +2586,7 @@
                                        PProfile    right )
   {
     /* nothing, really */
-    FT_UNUSED( raster );
+    FT_UNUSED_RASTER;
     FT_UNUSED( y );
     FT_UNUSED( x1 );
     FT_UNUSED( x2 );
@@ -3020,7 +3060,7 @@
         return error;
     }
 
-    return Raster_Err_Ok;
+    return Raster_Err_None;
   }
 
 
@@ -3096,7 +3136,7 @@
         return error;
     }
 
-    return Raster_Err_Ok;
+    return Raster_Err_None;
   }
 
 #else /* !FT_RASTER_OPTION_ANTI_ALIASING */
@@ -3106,7 +3146,7 @@
   {
     FT_UNUSED_RASTER;
 
-    return Raster_Err_Cannot_Render_Glyph;
+    return Raster_Err_Unsupported;
   }
 
 #endif /* !FT_RASTER_OPTION_ANTI_ALIASING */
@@ -3129,7 +3169,7 @@
           ( ( c << 2 ) & 0x0030 ) |
                    (c  & 0x0003 );
 
-      raster->count_table[n] = (UInt)c;
+      ras.count_table[n] = (UInt)c;
     }
 
 #ifdef FT_RASTER_OPTION_ANTI_ALIASING
@@ -3138,7 +3178,7 @@
     for ( n = 0; n < 5; n++ )
       raster->grays[n] = n * 255 / 4;
 
-    raster->gray_width = RASTER_GRAY_LINES / 2;
+    ras.gray_width = RASTER_GRAY_LINES / 2;
 
 #endif
   }
@@ -3155,10 +3195,10 @@
   ft_black_new( void*      memory,
                 FT_Raster  *araster )
   {
-     static FT_RasterRec_  the_raster;
+     static TRaster_Instance  the_raster;
 
 
-     *araster = &the_raster;
+     *araster = (FT_Raster)&the_raster;
      FT_MEM_ZERO( &the_raster, sizeof ( the_raster ) );
      ft_black_init( &the_raster );
 
@@ -3170,7 +3210,7 @@
   ft_black_done( FT_Raster  raster )
   {
     /* nothing */
-    raster->init = 0;
+    FT_UNUSED( raster );
   }
 
 
@@ -3214,11 +3254,11 @@
                   const char*        pool_base,
                   long               pool_size )
   {
-    if ( raster && pool_base && pool_size >= 4096 )
+    if ( (&ras) && pool_base && pool_size >= 4096 )
     {
       /* save the pool */
-      raster->buff     = (PLong)pool_base;
-      raster->sizeBuff = raster->buff + pool_size / sizeof ( Long );
+      ras.buff     = (PLong)pool_base;
+      ras.sizeBuff = ras.buff + pool_size / sizeof ( Long );
     }
   }
 
@@ -3233,11 +3273,11 @@
     if ( mode == FT_MAKE_TAG( 'p', 'a', 'l', '5' ) )
     {
       /* set 5-levels gray palette */
-      raster->grays[0] = palette[0];
-      raster->grays[1] = palette[1];
-      raster->grays[2] = palette[2];
-      raster->grays[3] = palette[3];
-      raster->grays[4] = palette[4];
+      ras.grays[0] = palette[0];
+      ras.grays[1] = palette[1];
+      ras.grays[2] = palette[2];
+      ras.grays[3] = palette[3];
+      ras.grays[4] = palette[4];
     }
 
 #else
@@ -3258,7 +3298,7 @@
     const FT_Bitmap*  target_map = params->target;
 
 
-    if ( !raster || !raster->buff || !raster->sizeBuff )
+    if ( !(&ras) || !ras.buff || !ras.sizeBuff )
       return Raster_Err_Not_Ini;
 
     /* return immediately if the outline is empty */
@@ -3282,8 +3322,8 @@
     ras.target   = *target_map;
 
     return ( ( params->flags & FT_RASTER_FLAG_AA )
-               ? Render_Gray_Glyph( raster )
-               : Render_Glyph( raster ) );
+               ? Render_Gray_Glyph( RAS_VAR )
+               : Render_Glyph( RAS_VAR ) );
   }