Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgrayraster.c
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2000-2026 by David Turner, Robert Wilhelm, and Werner Lemberg.
3// SPDX-License-Identifier: FTL OR GPL-2.0-only
4/****************************************************************************
5 *
6 * qgrayraster.c, derived from ftgrays.c of FreeType 2.15.0
7 *
8 * A new `perfect' anti-aliasing renderer (body).
9 *
10 * Copyright (C) 2000-2026 by
11 * David Turner, Robert Wilhelm, and Werner Lemberg.
12 *
13 * This file is part of the FreeType project, and may only be used,
14 * modified, and distributed under the terms of the FreeType project
15 * license, ../../3rdparty/freetype/LICENSE.txt. By continuing to use,
16 * modify, or distribute this file you indicate that you have read
17 * the license and understand and accept it fully.
18 *
19 */
20
21 /**************************************************************************
22 *
23 * Qt: This file is built in stand-alone mode, with the FreeType types
24 * mapped to their Qt copies in qrasterdefs_p.h. Local modifications
25 * are marked with `Qt:' comments.
26 *
27 */
28
29 /**************************************************************************
30 *
31 * This file can be compiled without the rest of the FreeType engine, by
32 * defining the STANDALONE_ macro when compiling it. You also need to
33 * put the files `ftgrays.h' and `ftimage.h' into the current
34 * compilation directory. Typically, you could do something like
35 *
36 * - copy `src/smooth/ftgrays.c' (this file) to your current directory
37 *
38 * - copy `include/freetype/ftimage.h' and `src/smooth/ftgrays.h' to the
39 * same directory
40 *
41 * - compile `ftgrays' with the STANDALONE_ macro defined, as in
42 *
43 * cc -c -DSTANDALONE_ ftgrays.c
44 *
45 * The renderer can be initialized with a call to
46 * `ft_gray_raster.raster_new'; an anti-aliased bitmap can be generated
47 * with a call to `ft_gray_raster.raster_render'.
48 *
49 * See the comments and documentation in the file `ftimage.h' for more
50 * details on how the raster works.
51 *
52 */
53
54 /**************************************************************************
55 *
56 * This is a new anti-aliasing scan-converter for FreeType 2. The
57 * algorithm used here is _very_ different from the one in the standard
58 * `ftraster' module. Actually, `ftgrays' computes the _exact_
59 * coverage of the outline on each pixel cell by straight segments.
60 *
61 * It is based on ideas that I initially found in Raph Levien's
62 * excellent LibArt graphics library (see https://www.levien.com/libart
63 * for more information, though the web pages do not tell anything
64 * about the renderer; you'll have to dive into the source code to
65 * understand how it works).
66 *
67 * Note, however, that this is a _very_ different implementation
68 * compared to Raph's. Coverage information is stored in a very
69 * different way, and I don't use sorted vector paths. Also, it doesn't
70 * use floating point values.
71 *
72 * Bézier segments are flattened by splitting them until their deviation
73 * from straight line becomes much smaller than a pixel. Therefore, the
74 * pixel coverage by a Bézier curve is calculated approximately. To
75 * estimate the deviation, we use the distance from the control point
76 * to the conic chord centre or the cubic chord trisection. These
77 * distances vanish fast after each split. In the conic case, they vanish
78 * predictably and the number of necessary splits can be calculated.
79 *
80 * This renderer has the following advantages:
81 *
82 * - It doesn't need an intermediate bitmap. Instead, linked lists
83 * of cells (pixels visited by an outline) are stored, which requires
84 * less memory and can be maintained on the stack for small glyphs.
85 *
86 * - One can supply a callback function that will be called by the
87 * renderer to draw gray spans on any target surface. You can thus
88 * do direct composition on any kind of bitmap, provided that you give
89 * the renderer the right callback.
90 *
91 * - A perfect anti-aliaser, i.e., it computes the _exact_ coverage on
92 * each pixel cell by straight segments.
93 *
94 * - It performs a single pass on the outline (the `standard' FT2
95 * renderer makes two passes).
96 *
97 * - It can easily be modified to render to _any_ number of gray levels
98 * cheaply.
99 *
100 * - For small (< 80) pixel sizes, it is faster than the standard
101 * renderer.
102 *
103 */
104
105
106 /**************************************************************************
107 *
108 * The macro FT_COMPONENT is used in trace mode. It is an implicit
109 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
110 * messages during execution.
111 */
112#undef FT_COMPONENT
113#define FT_COMPONENT smooth
114
115
116 /* Qt: always build in stand-alone mode */
117#define STANDALONE_
118
119#ifdef STANDALONE_
120
121
122 /* The size in bytes of the render pool used by the scan-line converter */
123 /* to do all of its work. */
124#define FT_RENDER_POOL_SIZE 16384L
125
126
127 /* Auxiliary macros for token concatenation. */
128#define FT_ERR_XCAT( x, y ) x ## y
129#define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y )
130
131#define FT_BEGIN_STMNT do {
132#define FT_END_STMNT } while ( 0 )
133
134#define FT_MIN( a, b ) ( (a) < (b) ? (a) : (b) )
135#define FT_MAX( a, b ) ( (a) > (b) ? (a) : (b) )
136#define FT_ABS( a ) ( (a) < 0 ? -(a) : (a) )
137
138
139 /*
140 * Approximate sqrt(x*x+y*y) using the `alpha max plus beta min'
141 * algorithm. We use alpha = 1, beta = 3/8, giving us results with a
142 * largest error less than 7% compared to the exact value.
143 */
144#define FT_HYPOT( x, y )
145 ( x = FT_ABS( x ),
146 y = FT_ABS( y ),
147 x > y ? x + ( 3 * y >> 3 )
148 : y + ( 3 * x >> 3 ) )
149
150
151 /* define this to dump debugging information */
152/* #define FT_DEBUG_LEVEL_TRACE */
153
154
155#ifdef FT_DEBUG_LEVEL_TRACE
156#include <stdio.h>
157#include <stdarg.h>
158#endif
159
160#include <stddef.h>
161#include <string.h>
162#include <setjmp.h>
163#include <limits.h>
164#define FT_CHAR_BIT CHAR_BIT
165#define FT_UINT_MAX UINT_MAX
166#define FT_INT_MAX INT_MAX
167#define FT_ULONG_MAX ULONG_MAX
168
169#define ADD_INT( a, b )
170 (int)( (unsigned int)(a) + (unsigned int)(b) )
171
172#define FT_STATIC_BYTE_CAST( type, var ) (type)(unsigned char)(var)
173
174
175#define ft_memset memset
176
178
179
180#define Smooth_Err_Ok 0
181#define Smooth_Err_Invalid_Outline -1
182#define Smooth_Err_Cannot_Render_Glyph -2
183#define Smooth_Err_Invalid_Argument -3
184#define Smooth_Err_Raster_Overflow -4
185
186#define FT_BEGIN_HEADER /* nothing */
187#define FT_END_HEADER /* nothing */
188
189 /* Qt: use the FreeType types from qrasterdefs_p.h */
190#define QT_FT_BEGIN_HEADER
191#define QT_FT_END_HEADER
192#include <private/qrasterdefs_p.h>
193#include <private/qgrayraster_p.h>
194#include <stdlib.h>
195
196#define FT_Pos QT_FT_Pos
197#define FT_Vector QT_FT_Vector
198#define FT_BBox QT_FT_BBox
199#define FT_Bitmap QT_FT_Bitmap
200#define FT_Outline QT_FT_Outline
201#define FT_Outline_Funcs QT_FT_Outline_Funcs
202#define FT_Outline_MoveTo_Func QT_FT_Outline_MoveTo_Func
203#define FT_Outline_LineTo_Func QT_FT_Outline_LineTo_Func
204#define FT_Outline_ConicTo_Func QT_FT_Outline_ConicTo_Func
205#define FT_Outline_CubicTo_Func QT_FT_Outline_CubicTo_Func
206#define FT_Span QT_FT_Span
207#define FT_Raster QT_FT_Raster
208#define FT_Raster_Params QT_FT_Raster_Params
209#define FT_Raster_Funcs QT_FT_Raster_Funcs
210#define FT_Raster_Span_Func QT_FT_Raster_Span_Func
211#define FT_Raster_New_Func QT_FT_Raster_New_Func
212#define FT_Raster_Reset_Func QT_FT_Raster_Reset_Func
213#define FT_Raster_Set_Mode_Func QT_FT_Raster_Set_Mode_Func
214#define FT_Raster_Render_Func QT_FT_Raster_Render_Func
215#define FT_Raster_Done_Func QT_FT_Raster_Done_Func
216#define FT_CURVE_TAG QT_FT_CURVE_TAG
217#define FT_CURVE_TAG_ON QT_FT_CURVE_TAG_ON
218#define FT_CURVE_TAG_CONIC QT_FT_CURVE_TAG_CONIC
219#define FT_CURVE_TAG_CUBIC QT_FT_CURVE_TAG_CUBIC
220#define FT_OUTLINE_EVEN_ODD_FILL QT_FT_OUTLINE_EVEN_ODD_FILL
221#define FT_RASTER_FLAG_AA QT_FT_RASTER_FLAG_AA
222#define FT_RASTER_FLAG_DIRECT QT_FT_RASTER_FLAG_DIRECT
223#define FT_GLYPH_FORMAT_OUTLINE QT_FT_GLYPH_FORMAT_OUTLINE
224
225#define gray_TRaster_ TRaster_ /* QT_FT_Raster is `struct TRaster_*' */
226#define ft_grays_raster QT_MANGLE_NAMESPACE( qt_ft_grays_raster )
227
228 typedef int FT_Int;
229 typedef unsigned int FT_UInt;
230 typedef unsigned long FT_ULong;
231 typedef long long FT_Int64;
232 typedef unsigned long long FT_UInt64;
233#define FT_INT64 long long
234
235#if defined( __has_attribute )
236#if __has_attribute( fallthrough )
237#define FALL_THROUGH __attribute__(( fallthrough ))
238#endif
239#endif
240#ifndef FALL_THROUGH
241#define FALL_THROUGH ( (void)0 )
242#endif
243
244
245 /* This macro is used to indicate that a function parameter is unused. */
246 /* Its purpose is simply to reduce compiler warnings. Note also that */
247 /* simply defining it as `(void)x' doesn't avoid warnings with certain */
248 /* ANSI compilers (e.g. LCC). */
249#define FT_UNUSED( x ) (x) = (x)
250
251
252 /* we only use level 5 & 7 tracing messages; cf. ftdebug.h */
253
254#ifdef FT_DEBUG_LEVEL_TRACE
255
256 void
257 FT_Message( const char* fmt,
258 ... )
259 {
260 va_list ap;
261
262
263 va_start( ap, fmt );
264 vfprintf( stderr, fmt, ap );
265 va_end( ap );
266 }
267
268
269 /* empty function useful for setting a breakpoint to catch errors */
270 int
271 FT_Throw( int error,
272 int line,
273 const char* file )
274 {
275 FT_UNUSED( error );
276 FT_UNUSED( line );
277 FT_UNUSED( file );
278
279 return 0;
280 }
281
282
283 /* we don't handle tracing levels in stand-alone mode; */
284#ifndef FT_TRACE5
285#define FT_TRACE5( varformat ) FT_Message varformat
286#endif
287#ifndef FT_TRACE7
288#define FT_TRACE7( varformat ) FT_Message varformat
289#endif
290#ifndef FT_ERROR
291#define FT_ERROR( varformat ) FT_Message varformat
292#endif
293
294#define FT_THROW( e )
295 ( FT_Throw( FT_ERR_CAT( Smooth_Err_, e ),
296 __LINE__,
297 __FILE__ ) |
298 FT_ERR_CAT( Smooth_Err_, e ) )
299
300#else /* !FT_DEBUG_LEVEL_TRACE */
301
302#define FT_TRACE5( x ) do { } while ( 0 ) /* nothing */
303#define FT_TRACE7( x ) do { } while ( 0 ) /* nothing */
304#define FT_ERROR( x ) do { } while ( 0 ) /* nothing */
305#define FT_THROW( e ) FT_ERR_CAT( Smooth_Err_, e )
306
307#endif /* !FT_DEBUG_LEVEL_TRACE */
308
309
310#define FT_Trace_Enable() do { } while ( 0 ) /* nothing */
311#define FT_Trace_Disable() do { } while ( 0 ) /* nothing */
312
313
314#define FT_DEFINE_OUTLINE_FUNCS( class_,
315 move_to_, line_to_,
316 conic_to_, cubic_to_,
317 shift_, delta_ )
318 static const FT_Outline_Funcs class_ =
319 {
320 move_to_,
321 line_to_,
322 conic_to_,
323 cubic_to_,
324 shift_,
325 delta_
326 };
327
328#define FT_DEFINE_RASTER_FUNCS( class_, glyph_format_,
329 raster_new_, raster_reset_,
330 raster_set_mode_, raster_render_,
331 raster_done_ )
332 const FT_Raster_Funcs class_ =
333 {
334 glyph_format_,
335 raster_new_,
336 raster_reset_,
337 raster_set_mode_,
338 raster_render_,
339 raster_done_
340 };
341
342
343#else /* !STANDALONE_ */
344
345
346#include <ft2build.h>
347#include FT_CONFIG_CONFIG_H
348#include "ftgrays.h"
349#include <freetype/internal/ftobjs.h>
350#include <freetype/internal/ftdebug.h>
351#include <freetype/internal/ftcalc.h>
352#include <freetype/ftoutln.h>
353
354#include "ftsmerrs.h"
355
356
357#endif /* !STANDALONE_ */
358
359
360#ifndef FT_MEM_SET
361#define FT_MEM_SET( d, s, c ) ft_memset( d, s, c )
362#endif
363
364#ifndef FT_MEM_ZERO
365#define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count )
366#endif
367
368#ifndef FT_ZERO
369#define FT_ZERO( p ) FT_MEM_ZERO( p, sizeof ( *(p) ) )
370#endif
371
372 /* as usual, for the speed hungry :-) */
373
374#undef RAS_ARG
375#undef RAS_ARG_
376#undef RAS_VAR
377#undef RAS_VAR_
378
379#ifndef FT_STATIC_RASTER
380
381#define RAS_ARG gray_PWorker worker
382#define RAS_ARG_ gray_PWorker worker,
383
384#define RAS_VAR worker
385#define RAS_VAR_ worker,
386
387#else /* FT_STATIC_RASTER */
388
389#define RAS_ARG void
390#define RAS_ARG_ /* empty */
391#define RAS_VAR /* empty */
392#define RAS_VAR_ /* empty */
393
394#endif /* FT_STATIC_RASTER */
395
396
397 /* must be at least 6 bits! */
398#define PIXEL_BITS 8
399
400#define ONE_PIXEL ( 1 << PIXEL_BITS )
401#undef TRUNC
402#define TRUNC( x ) (TCoord)( (x) >> PIXEL_BITS )
403#undef FRACT
404#define FRACT( x ) (TCoord)( (x) & ( ONE_PIXEL - 1 ) )
405
406#if PIXEL_BITS >= 6
407#define UPSCALE( x ) ( (x) * ( ONE_PIXEL >> 6 ) )
408#define DOWNSCALE( x ) ( (x) >> ( PIXEL_BITS - 6 ) )
409#else
410#define UPSCALE( x ) ( (x) >> ( 6 - PIXEL_BITS ) )
411#define DOWNSCALE( x ) ( (x) * ( 64 >> PIXEL_BITS ) )
412#endif
413
414
415 /* Compute `dividend / divisor' and return both its quotient and */
416 /* remainder, cast to a specific type. This macro also ensures that */
417 /* the remainder is always positive. We use the remainder to keep */
418 /* track of accumulating errors and compensate for them. */
419#define FT_DIV_MOD( type, dividend, divisor, quotient, remainder )
421 (quotient) = (type)( (dividend) / (divisor) );
422 (remainder) = (type)( (dividend) % (divisor) );
423 if ( (remainder) < 0 )
424 {
425 (quotient)--;
426 (remainder) += (type)(divisor);
427 }
429
430#if defined( __GNUC__ ) && __GNUC__ < 7 && defined( __arm__ )
431 /* Work around a bug specific to GCC which make the compiler fail to */
432 /* optimize a division and modulo operation on the same parameters */
433 /* into a single call to `__aeabi_idivmod'. See */
434 /* */
435 /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43721 */
436#undef FT_DIV_MOD
437#define FT_DIV_MOD( type, dividend, divisor, quotient, remainder )
438 FT_BEGIN_STMNT
439 (quotient) = (type)( (dividend) / (divisor) );
440 (remainder) = (type)( (dividend) - (quotient) * (divisor) );
441 if ( (remainder) < 0 )
442 {
443 (quotient)--;
444 (remainder) += (type)(divisor);
445 }
446 FT_END_STMNT
447#endif /* __arm__ */
448
449
450 /* Calculating coverages for a slanted line requires a division each */
451 /* time the line crosses from cell to cell. These macros speed up */
452 /* the repetitive divisions by replacing them with multiplications */
453 /* and right shifts so that at most two divisions are performed for */
454 /* each slanted line. Nevertheless, these divisions are noticeable */
455 /* in the overall performance because flattened curves produce a */
456 /* very large number of slanted lines. */
457 /* */
458 /* The division results here are always within ONE_PIXEL. Therefore */
459 /* the shift magnitude should be at least PIXEL_BITS wider than the */
460 /* divisors to provide sufficient accuracy of the multiply-shift. */
461 /* It should not exceed (64 - PIXEL_BITS) to prevent overflowing and */
462 /* leave enough room for 64-bit unsigned multiplication however. */
463#define FT_UDIVPREP( c, b )
464 FT_Int64 b ## _r = c ? (FT_Int64)0xFFFFFFFF / ( b ) : 0
465#define FT_UDIV( a, b )
466 (TCoord)( ( (FT_UInt64)( a ) * (FT_UInt64)( b ## _r ) ) >> 32 )
467
468
469 /* Scale area and apply fill rule to calculate the coverage byte. */
470 /* The top fill bit is used for the non-zero rule. The eighth */
471 /* fill bit is used for the even-odd rule. The higher coverage */
472 /* bytes are either clamped for the non-zero-rule or discarded */
473 /* later for the even-odd rule. */
474#define FT_FILL_RULE( coverage, area, fill )
476 coverage = (int)( area >> ( PIXEL_BITS * 2 + 1 - 8 ) );
477 if ( coverage & fill )
478 coverage = ~coverage;
479 if ( coverage > 255 && fill & INT_MIN )
480 coverage = 255;
482
483
484 /* It is faster to write small spans byte-by-byte than calling */
485 /* `memset'. This is mainly due to the cost of the function call. */
486#define FT_GRAY_SET( d, s, count )
488 unsigned char* q = d;
489 switch ( count )
490 {
491 case 7: *q++ = (unsigned char)s; FALL_THROUGH;
492 case 6: *q++ = (unsigned char)s; FALL_THROUGH;
493 case 5: *q++ = (unsigned char)s; FALL_THROUGH;
494 case 4: *q++ = (unsigned char)s; FALL_THROUGH;
495 case 3: *q++ = (unsigned char)s; FALL_THROUGH;
496 case 2: *q++ = (unsigned char)s; FALL_THROUGH;
497 case 1: *q = (unsigned char)s; FALL_THROUGH;
498 case 0: break;
499 default: FT_MEM_SET( d, s, count );
500 }
502
503
504 /**************************************************************************
505 *
506 * TYPE DEFINITIONS
507 */
508
509 /* don't change the following types to FT_Int or FT_Pos, since we might */
510 /* need to define them to "float" or "double" when experimenting with */
511 /* new algorithms */
512
513 typedef long TPos; /* subpixel coordinate */
514 typedef int TCoord; /* integer scanline/pixel coordinate */
515 typedef int TArea; /* cell areas, coordinate products */
516
517
518 typedef struct TCell_* PCell;
519
520 typedef struct TCell_
521 {
522 TCoord x; /* same with gray_TWorker.ex */
523 TCoord cover; /* same with gray_TWorker.cover */
526
527 } TCell;
528
529 typedef struct TPixmap_
530 {
531 unsigned char* origin; /* pixmap origin at the bottom-left */
532 int pitch; /* pitch to go down one row */
533
534 } TPixmap;
535
536 /* Maximum number of gray cells in the stack buffer; */
537 /* for example, a buffer of 680 cells can accommodate */
538 /* a glyph with the taxicab perimeter of 680 pixels. */
539 /* A larger buffer can be allocated when necessary. */
540#if FT_RENDER_POOL_SIZE > 2048
541#define FT_MAX_GRAY_POOL ( FT_RENDER_POOL_SIZE / sizeof ( TCell ) )
542#else
543#define FT_MAX_GRAY_POOL ( 2048 / sizeof ( TCell ) )
544#endif
545
546 /* FT_Span buffer size for direct rendering only */
547 /* Qt: spans hold y and are not flushed per row */
548#define FT_MAX_GRAY_SPANS 256
549
550
551#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
552 /* We disable the warning `structure was padded due to */
553 /* __declspec(align())' in order to compile cleanly with */
554 /* the maximum level of warnings. */
555#pragma warning( push )
556#pragma warning( disable : 4324 )
557#endif /* _MSC_VER */
558
559 typedef struct gray_TWorker_
560 {
561 TCoord min_ex, min_ey; /* min and max integer pixel coordinates */
563
564 int error; /* pool overflow exception */
565 PCell buffer; /* buffer */
566 PCell cell_null; /* last cell, used as dumpster and limit */
567 PCell cell; /* current cell */
568 PCell cell_free; /* call allocation next free slot */
569
570 PCell* ycells; /* array of cell linked-lists; one per */
571 /* vertical coordinate in the current band */
572
573 TPos x, y; /* last point position */
574
575 FT_Outline outline; /* input outline */
576 TPixmap target; /* target pixmap */
577
580
581 } gray_TWorker, *gray_PWorker;
582
583#if defined( _MSC_VER )
584#pragma warning( pop )
585#endif
586
587#ifndef FT_STATIC_RASTER
588#define ras (*worker)
589#else
590 static gray_TWorker ras;
591#endif
592
593 /* The |x| value of the null cell. Must be the largest possible */
594 /* integer value stored in a `TCell.x` field. */
595#define CELL_MAX_X_VALUE INT_MAX
596
597
598#define FT_INTEGRATE( ras, a, b )
599 ras.cell->cover = ADD_INT( ras.cell->cover, a ),
600 ras.cell->area = ADD_INT( ras.cell->area, (a) * (TArea)(b) )
601
602
603 typedef struct gray_TRaster_
604 {
605 void* memory;
606
607 } gray_TRaster, *gray_PRaster;
608
609
610#ifdef FT_DEBUG_LEVEL_TRACE
611
612 /* to be called while in the debugger -- */
613 /* this function causes a compiler warning since it is unused otherwise */
614 static void
615 gray_dump_cells( RAS_ARG )
616 {
617 int y;
618
619
620 for ( y = ras.min_ey; y < ras.max_ey; y++ )
621 {
622 PCell cell = ras.ycells[y - ras.min_ey];
623
624
625 printf( "%3d:", y );
626
627 for ( ; cell != ras.cell_null; cell = cell->next )
628 printf( " (%3d, c:%4d, a:%6d)",
629 cell->x, cell->cover, cell->area );
630 printf( "\n" );
631 }
632 }
633
634#endif /* FT_DEBUG_LEVEL_TRACE */
635
636
637 /**************************************************************************
638 *
639 * Set the current cell to a new position.
640 */
641 static void
643 TCoord ey )
644 {
645 /* Move the cell pointer to a new position in the linked list. We use */
646 /* a dumpster null cell for everything outside of the clipping region */
647 /* during the render phase. This means that: */
648 /* */
649 /* . the new vertical position must be within min_ey..max_ey-1. */
650 /* . the new horizontal position must be strictly less than max_ex */
651 /* */
652 /* Note that if a cell is to the left of the clipping region, it is */
653 /* actually set to the (min_ex-1) horizontal position. */
654
655 if ( ey < ras.min_ey || ey >= ras.max_ey || ex >= ras.max_ex )
657 else
658 {
659 PCell* pcell = ras.ycells + ( ey - ras.min_ey );
660 PCell cell;
661
662
663 ex = FT_MAX( ex, ras.min_ex - 1 );
664
665 while ( 1 )
666 {
667 cell = *pcell;
668
669 if ( cell->x > ex )
670 break;
671
672 if ( cell->x == ex )
673 goto Found;
674
675 pcell = &cell->next;
676 }
677
678 /* insert new cell */
679 cell = ras.cell_free;
680 if ( cell == ras.cell_null )
681 {
682 ras.error = FT_THROW( Raster_Overflow );
683 goto Found;
684 }
685
686 ras.cell_free = cell + 1;
687
688 cell->x = ex;
689 cell->area = 0;
690 cell->cover = 0;
691
692 cell->next = *pcell;
693 *pcell = cell;
694
695 Found:
696 ras.cell = cell;
697 }
698 }
699
700
701#ifndef FT_INT64
702
703 /**************************************************************************
704 *
705 * Render a scanline as one or more cells.
706 */
707 static void
708 gray_render_scanline( RAS_ARG_ TCoord ey,
709 TPos x1,
710 TCoord y1,
711 TPos x2,
712 TCoord y2 )
713 {
714 TCoord ex1, ex2, fx1, fx2, first, dy, delta, mod;
715 TPos p, dx;
716 int incr;
717
718
719 ex1 = TRUNC( x1 );
720 ex2 = TRUNC( x2 );
721
722 /* trivial case. Happens often */
723 if ( y1 == y2 )
724 {
725 gray_set_cell( RAS_VAR_ ex2, ey );
726 return;
727 }
728
729 fx1 = FRACT( x1 );
730 fx2 = FRACT( x2 );
731
732 /* everything is located in a single cell. That is easy! */
733 /* */
734 if ( ex1 == ex2 )
735 goto End;
736
737 /* ok, we'll have to render a run of adjacent cells on the same */
738 /* scanline... */
739 /* */
740 dx = x2 - x1;
741 dy = y2 - y1;
742
743 if ( dx > 0 )
744 {
745 p = ( ONE_PIXEL - fx1 ) * dy;
746 first = ONE_PIXEL;
747 incr = 1;
748 }
749 else
750 {
751 p = fx1 * dy;
752 first = 0;
753 incr = -1;
754 dx = -dx;
755 }
756
757 /* the fractional part of y-delta is mod/dx. It is essential to */
758 /* keep track of its accumulation for accurate rendering. */
759 /* XXX: y-delta and x-delta below should be related. */
760 FT_DIV_MOD( TCoord, p, dx, delta, mod );
761
762 FT_INTEGRATE( ras, delta, fx1 + first );
763 y1 += delta;
764 ex1 += incr;
765 gray_set_cell( RAS_VAR_ ex1, ey );
766
767 if ( ex1 != ex2 )
768 {
769 TCoord lift, rem;
770
771
772 p = ONE_PIXEL * dy;
773 FT_DIV_MOD( TCoord, p, dx, lift, rem );
774
775 do
776 {
777 delta = lift;
778 mod += rem;
779 if ( mod >= (TCoord)dx )
780 {
781 mod -= (TCoord)dx;
782 delta++;
783 }
784
785 FT_INTEGRATE( ras, delta, ONE_PIXEL );
786 y1 += delta;
787 ex1 += incr;
788 gray_set_cell( RAS_VAR_ ex1, ey );
789 } while ( ex1 != ex2 );
790 }
791
792 fx1 = ONE_PIXEL - first;
793
794 End:
795 FT_INTEGRATE( ras, y2 - y1, fx1 + fx2 );
796 }
797
798
799 /**************************************************************************
800 *
801 * Render a given line as a series of scanlines.
802 */
803 static void
804 gray_render_line( RAS_ARG_ TPos to_x,
805 TPos to_y )
806 {
807 TCoord ey1, ey2, fy1, fy2, first, delta, mod;
808 TPos p, dx, dy, x, x2;
809 int incr;
810
811
812 ey1 = TRUNC( ras.y );
813 ey2 = TRUNC( to_y ); /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */
814
815 /* perform vertical clipping */
816 if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) ||
817 ( ey1 < ras.min_ey && ey2 < ras.min_ey ) )
818 goto End;
819
820 fy1 = FRACT( ras.y );
821 fy2 = FRACT( to_y );
822
823 /* everything is on a single scanline */
824 if ( ey1 == ey2 )
825 {
826 gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, to_x, fy2 );
827 goto End;
828 }
829
830 dx = to_x - ras.x;
831 dy = to_y - ras.y;
832
833 /* vertical line - avoid calling gray_render_scanline */
834 if ( dx == 0 )
835 {
836 TCoord ex = TRUNC( ras.x );
837 TCoord two_fx = FRACT( ras.x ) << 1;
838
839
840 if ( dy > 0)
841 {
842 first = ONE_PIXEL;
843 incr = 1;
844 }
845 else
846 {
847 first = 0;
848 incr = -1;
849 }
850
851 delta = first - fy1;
852 FT_INTEGRATE( ras, delta, two_fx);
853 ey1 += incr;
854
855 gray_set_cell( RAS_VAR_ ex, ey1 );
856
857 delta = first + first - ONE_PIXEL;
858 while ( ey1 != ey2 )
859 {
860 FT_INTEGRATE( ras, delta, two_fx);
861 ey1 += incr;
862
863 gray_set_cell( RAS_VAR_ ex, ey1 );
864 }
865
866 delta = fy2 - ONE_PIXEL + first;
867 FT_INTEGRATE( ras, delta, two_fx);
868
869 goto End;
870 }
871
872 /* ok, we have to render several scanlines */
873 if ( dy > 0)
874 {
875 p = ( ONE_PIXEL - fy1 ) * dx;
876 first = ONE_PIXEL;
877 incr = 1;
878 }
879 else
880 {
881 p = fy1 * dx;
882 first = 0;
883 incr = -1;
884 dy = -dy;
885 }
886
887 /* the fractional part of x-delta is mod/dy. It is essential to */
888 /* keep track of its accumulation for accurate rendering. */
889 FT_DIV_MOD( TCoord, p, dy, delta, mod );
890
891 x = ras.x + delta;
892 gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, x, first );
893
894 ey1 += incr;
895 gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 );
896
897 if ( ey1 != ey2 )
898 {
899 TCoord lift, rem;
900
901
902 p = ONE_PIXEL * dx;
903 FT_DIV_MOD( TCoord, p, dy, lift, rem );
904
905 do
906 {
907 delta = lift;
908 mod += rem;
909 if ( mod >= (TCoord)dy )
910 {
911 mod -= (TCoord)dy;
912 delta++;
913 }
914
915 x2 = x + delta;
916 gray_render_scanline( RAS_VAR_ ey1,
917 x, ONE_PIXEL - first,
918 x2, first );
919 x = x2;
920
921 ey1 += incr;
922 gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 );
923 } while ( ey1 != ey2 );
924 }
925
926 gray_render_scanline( RAS_VAR_ ey1,
927 x, ONE_PIXEL - first,
928 to_x, fy2 );
929
930 End:
931 ras.x = to_x;
932 ras.y = to_y;
933 }
934
935#else
936
937 /**************************************************************************
938 *
939 * Render a straight line across multiple cells in any direction.
940 */
941 static void
943 TPos to_y )
944 {
945 TPos dx, dy;
946 TCoord fx1, fy1, fx2, fy2;
947 TCoord ex1, ey1, ex2, ey2;
948
949
950 ey1 = TRUNC( ras.y );
951 ey2 = TRUNC( to_y );
952
953 /* perform vertical clipping */
954 if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) ||
955 ( ey1 < ras.min_ey && ey2 < ras.min_ey ) )
956 goto End;
957
958 ex1 = TRUNC( ras.x );
959 ex2 = TRUNC( to_x );
960
961 fx1 = FRACT( ras.x );
962 fy1 = FRACT( ras.y );
963
964 dx = to_x - ras.x;
965 dy = to_y - ras.y;
966
967 if ( ex1 == ex2 && ey1 == ey2 ) /* inside one cell */
968 ;
969 else if ( dy == 0 ) /* ex1 != ex2 */ /* any horizontal line */
970 {
971 gray_set_cell( RAS_VAR_ ex2, ey2 );
972 goto End;
973 }
974 else if ( dx == 0 )
975 {
976 /* Qt: skip the rows outside the band, where the cells are */
977 /* discarded anyway; long vertical lines are common in Qt */
978 TCoord ey_stop;
979
980
981 if ( dy > 0 ) /* vertical line up */
982 {
983 if ( ey1 < ras.min_ey - 1 )
984 {
985 ey1 = ras.min_ey - 1;
986 gray_set_cell( RAS_VAR_ ex1, ey1 );
987 }
988 ey_stop = FT_MIN( ey2, ras.max_ey );
989
990 do
991 {
992 fy2 = ONE_PIXEL;
993 FT_INTEGRATE( ras, fy2 - fy1, fx1 * 2 );
994 fy1 = 0;
995 ey1++;
996 gray_set_cell( RAS_VAR_ ex1, ey1 );
997 } while ( ey1 != ey_stop );
998 }
999 else /* vertical line down */
1000 {
1001 if ( ey1 > ras.max_ey )
1002 {
1003 ey1 = ras.max_ey;
1004 gray_set_cell( RAS_VAR_ ex1, ey1 );
1005 }
1006 ey_stop = FT_MAX( ey2, ras.min_ey - 1 );
1007
1008 do
1009 {
1010 fy2 = 0;
1011 FT_INTEGRATE( ras, fy2 - fy1, fx1 * 2 );
1012 fy1 = ONE_PIXEL;
1013 ey1--;
1014 gray_set_cell( RAS_VAR_ ex1, ey1 );
1015 } while ( ey1 != ey_stop );
1016 }
1017
1018 if ( ey1 != ey2 )
1019 {
1020 ey1 = ey2;
1021 gray_set_cell( RAS_VAR_ ex1, ey1 );
1022 }
1023 }
1024 else /* any other line */
1025 {
1026 FT_Int64 prod = dx * (FT_Int64)fy1 - dy * (FT_Int64)fx1;
1027 FT_UDIVPREP( ex1 != ex2, dx );
1028 FT_UDIVPREP( ey1 != ey2, dy );
1029
1030
1031 /* The fundamental value `prod' determines which side and the */
1032 /* exact coordinate where the line exits current cell. It is */
1033 /* also easily updated when moving from one cell to the next. */
1034 do
1035 {
1036 if ( prod - dx * ONE_PIXEL > 0 &&
1037 prod <= 0 ) /* left */
1038 {
1039 fx2 = 0;
1040 fy2 = FT_UDIV( -prod, -dx );
1041 prod -= dy * ONE_PIXEL;
1042 FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
1043 fx1 = ONE_PIXEL;
1044 fy1 = fy2;
1045 ex1--;
1046 }
1047 else if ( prod - dx * ONE_PIXEL + dy * ONE_PIXEL > 0 &&
1048 prod - dx * ONE_PIXEL <= 0 ) /* up */
1049 {
1050 prod -= dx * ONE_PIXEL;
1051 fx2 = FT_UDIV( -prod, dy );
1052 fy2 = ONE_PIXEL;
1053 FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
1054 fx1 = fx2;
1055 fy1 = 0;
1056 ey1++;
1057 }
1058 else if ( prod + dy * ONE_PIXEL >= 0 &&
1059 prod - dx * ONE_PIXEL + dy * ONE_PIXEL <= 0 ) /* right */
1060 {
1061 prod += dy * ONE_PIXEL;
1062 fx2 = ONE_PIXEL;
1063 fy2 = FT_UDIV( prod, dx );
1064 FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
1065 fx1 = 0;
1066 fy1 = fy2;
1067 ex1++;
1068 }
1069 else /* ( prod > 0 &&
1070 prod + dy * ONE_PIXEL < 0 ) down */
1071 {
1072 fx2 = FT_UDIV( prod, -dy );
1073 fy2 = 0;
1074 prod += dx * ONE_PIXEL;
1075 FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
1076 fx1 = fx2;
1077 fy1 = ONE_PIXEL;
1078 ey1--;
1079 }
1080
1081 gray_set_cell( RAS_VAR_ ex1, ey1 );
1082
1083 } while ( ex1 != ex2 || ey1 != ey2 );
1084 }
1085
1086 fx2 = FRACT( to_x );
1087 fy2 = FRACT( to_y );
1088
1089 FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
1090
1091 End:
1092 ras.x = to_x;
1093 ras.y = to_y;
1094 }
1095
1096#endif
1097
1098 /*
1099 * For now, the code that uses DDA to render conic curves requires
1100 * `FT_Int64` to be defined. See for example
1101 * https://gitlab.freedesktop.org/freetype/freetype/-/issues/1071.
1102 */
1103
1104#ifdef FT_INT64
1105
1106#define LEFT_SHIFT( a, b ) (FT_Int64)( (FT_UInt64)(a) << (b) )
1107
1108
1109 static void
1111 const FT_Vector* to )
1112 {
1113 FT_Vector p0, p1, p2;
1114 TPos ax, ay, bx, by, dx, dy;
1115 int shift;
1116
1117 FT_Int64 rx, ry;
1118 FT_Int64 qx, qy;
1119 FT_Int64 px, py;
1120
1121 FT_UInt count;
1122
1123
1124 p0.x = ras.x;
1125 p0.y = ras.y;
1126 p1.x = UPSCALE( control->x );
1127 p1.y = UPSCALE( control->y );
1128 p2.x = UPSCALE( to->x );
1129 p2.y = UPSCALE( to->y );
1130
1131 /* short-cut the arc that crosses the current band */
1132 if ( ( TRUNC( p0.y ) >= ras.max_ey &&
1133 TRUNC( p1.y ) >= ras.max_ey &&
1134 TRUNC( p2.y ) >= ras.max_ey ) ||
1135 ( TRUNC( p0.y ) < ras.min_ey &&
1136 TRUNC( p1.y ) < ras.min_ey &&
1137 TRUNC( p2.y ) < ras.min_ey ) )
1138 {
1139 ras.x = p2.x;
1140 ras.y = p2.y;
1141 return;
1142 }
1143
1144 bx = p1.x - p0.x;
1145 by = p1.y - p0.y;
1146 ax = p2.x - p1.x - bx; /* p0.x + p2.x - 2 * p1.x */
1147 ay = p2.y - p1.y - by; /* p0.y + p2.y - 2 * p1.y */
1148
1149 dx = FT_ABS( ax );
1150 dy = FT_ABS( ay );
1151 if ( dx < dy )
1152 dx = dy;
1153
1154 if ( dx <= ONE_PIXEL / 4 )
1155 {
1156 gray_render_line( RAS_VAR_ p2.x, p2.y );
1157 return;
1158 }
1159
1160 /* We can calculate the number of necessary segments because */
1161 /* each bisection predictably reduces deviation exactly 4-fold. */
1162 /* Even 32-bit deviation would vanish after 16 bisections. */
1163 shift = 16;
1164 do
1165 {
1166 dx >>= 2;
1167 shift--;
1168
1169 } while ( dx > ONE_PIXEL / 4 );
1170 count = 0x10000U >> shift;
1171
1172 /*
1173 * The (P0,P1,P2) arc equation, for t in [0,1] range:
1174 *
1175 * P(t) = P0*(1-t)^2 + P1*2*t*(1-t) + P2*t^2
1176 *
1177 * P(t) = P0 + 2*(P1-P0)*t + (P0+P2-2*P1)*t^2
1178 * = P0 + 2*B*t + A*t^2
1179 *
1180 * for A = P0 + P2 - 2*P1
1181 * and B = P1 - P0
1182 *
1183 * Let's consider the difference when advancing by a small
1184 * parameter h:
1185 *
1186 * Q(h,t) = P(t+h) - P(t) = 2*B*h + A*h^2 + 2*A*h*t
1187 *
1188 * And then its own difference:
1189 *
1190 * R(h,t) = Q(h,t+h) - Q(h,t) = 2*A*h*h = R (constant)
1191 *
1192 * Since R is always a constant, it is possible to compute
1193 * successive positions with:
1194 *
1195 * P = P0
1196 * Q = Q(h,0) = 2*B*h + A*h*h
1197 * R = 2*A*h*h
1198 *
1199 * loop:
1200 * P += Q
1201 * Q += R
1202 * EMIT(P)
1203 *
1204 * To ensure accurate results, perform computations on 64-bit
1205 * values, after scaling them by 2^32.
1206 *
1207 * h = 1 / 2^N
1208 *
1209 * R << 32 = 2 * A << (32 - N - N)
1210 * = A << (33 - 2*N)
1211 *
1212 * Q << 32 = (2 * B << (32 - N)) + (A << (32 - N - N))
1213 * = (B << (33 - N)) + (A << (32 - 2*N))
1214 */
1215
1216 rx = LEFT_SHIFT( ax, shift + shift );
1217 ry = LEFT_SHIFT( ay, shift + shift );
1218
1219 qx = LEFT_SHIFT( bx, shift + 17 ) + rx;
1220 qy = LEFT_SHIFT( by, shift + 17 ) + ry;
1221
1222 rx *= 2;
1223 ry *= 2;
1224
1225 px = LEFT_SHIFT( p0.x, 32 );
1226 py = LEFT_SHIFT( p0.y, 32 );
1227
1228 do
1229 {
1230 px += qx;
1231 py += qy;
1232 qx += rx;
1233 qy += ry;
1234
1235 gray_render_line( RAS_VAR_ (FT_Pos)( px >> 32 ),
1236 (FT_Pos)( py >> 32 ) );
1237 } while ( --count );
1238 }
1239
1240#else /* !FT_INT64 */
1241
1242 /*
1243 * Note that multiple attempts to speed up the function below
1244 * with SSE2 intrinsics, using various data layouts, have turned
1245 * out to be slower than the non-SIMD code below.
1246 */
1247 static void
1248 gray_split_conic( FT_Vector* base )
1249 {
1250 TPos a, b;
1251
1252
1253 base[4].x = base[2].x;
1254 a = base[0].x + base[1].x;
1255 b = base[1].x + base[2].x;
1256 base[3].x = b >> 1;
1257 base[2].x = ( a + b ) >> 2;
1258 base[1].x = a >> 1;
1259
1260 base[4].y = base[2].y;
1261 a = base[0].y + base[1].y;
1262 b = base[1].y + base[2].y;
1263 base[3].y = b >> 1;
1264 base[2].y = ( a + b ) >> 2;
1265 base[1].y = a >> 1;
1266 }
1267
1268
1269 static void
1270 gray_render_conic( RAS_ARG_ const FT_Vector* control,
1271 const FT_Vector* to )
1272 {
1273 FT_Vector bez_stack[16 * 2 + 1]; /* enough to accommodate bisections */
1274 FT_Vector* arc = bez_stack;
1275 TPos dx, dy;
1276 int draw;
1277
1278
1279 arc[0].x = UPSCALE( to->x );
1280 arc[0].y = UPSCALE( to->y );
1281 arc[1].x = UPSCALE( control->x );
1282 arc[1].y = UPSCALE( control->y );
1283 arc[2].x = ras.x;
1284 arc[2].y = ras.y;
1285
1286 /* short-cut the arc that crosses the current band */
1287 if ( ( TRUNC( arc[0].y ) >= ras.max_ey &&
1288 TRUNC( arc[1].y ) >= ras.max_ey &&
1289 TRUNC( arc[2].y ) >= ras.max_ey ) ||
1290 ( TRUNC( arc[0].y ) < ras.min_ey &&
1291 TRUNC( arc[1].y ) < ras.min_ey &&
1292 TRUNC( arc[2].y ) < ras.min_ey ) )
1293 {
1294 ras.x = arc[0].x;
1295 ras.y = arc[0].y;
1296 return;
1297 }
1298
1299 dx = FT_ABS( arc[2].x + arc[0].x - 2 * arc[1].x );
1300 dy = FT_ABS( arc[2].y + arc[0].y - 2 * arc[1].y );
1301 if ( dx < dy )
1302 dx = dy;
1303
1304 /* We can calculate the number of necessary bisections because */
1305 /* each bisection predictably reduces deviation exactly 4-fold. */
1306 /* Even 32-bit deviation would vanish after 16 bisections. */
1307 draw = 1;
1308 while ( dx > ONE_PIXEL / 4 )
1309 {
1310 dx >>= 2;
1311 draw <<= 1;
1312 }
1313
1314 /* We use decrement counter to count the total number of segments */
1315 /* to draw starting from 2^level. Before each draw we split as */
1316 /* many times as there are trailing zeros in the counter. */
1317 do
1318 {
1319 int split = draw & ( -draw ); /* isolate the rightmost 1-bit */
1320
1321
1322 while ( ( split >>= 1 ) )
1323 {
1324 gray_split_conic( arc );
1325 arc += 2;
1326 }
1327
1328 gray_render_line( RAS_VAR_ arc[0].x, arc[0].y );
1329 arc -= 2;
1330
1331 } while ( --draw );
1332 }
1333
1334#endif /* !FT_INT64 */
1335
1336
1337 /*
1338 * For cubic Bézier, binary splits are still faster than DDA
1339 * because the splits are adaptive to how quickly each sub-arc
1340 * approaches their chord trisection points.
1341 *
1342 * It might be useful to experiment with SSE2 to speed up
1343 * `gray_split_cubic`, though.
1344 */
1345 static void
1347 {
1348 TPos a, b, c;
1349
1350
1351 base[6].x = base[3].x;
1352 a = base[0].x + base[1].x;
1353 b = base[1].x + base[2].x;
1354 c = base[2].x + base[3].x;
1355 base[5].x = c >> 1;
1356 c += b;
1357 base[4].x = c >> 2;
1358 base[1].x = a >> 1;
1359 a += b;
1360 base[2].x = a >> 2;
1361 base[3].x = ( a + c ) >> 3;
1362
1363 base[6].y = base[3].y;
1364 a = base[0].y + base[1].y;
1365 b = base[1].y + base[2].y;
1366 c = base[2].y + base[3].y;
1367 base[5].y = c >> 1;
1368 c += b;
1369 base[4].y = c >> 2;
1370 base[1].y = a >> 1;
1371 a += b;
1372 base[2].y = a >> 2;
1373 base[3].y = ( a + c ) >> 3;
1374 }
1375
1376
1377 static void
1379 const FT_Vector* control2,
1380 const FT_Vector* to )
1381 {
1382 FT_Vector bez_stack[16 * 3 + 1]; /* enough to accommodate bisections */
1383 FT_Vector* arc = bez_stack;
1384
1385
1386 arc[0].x = UPSCALE( to->x );
1387 arc[0].y = UPSCALE( to->y );
1388 arc[1].x = UPSCALE( control2->x );
1389 arc[1].y = UPSCALE( control2->y );
1390 arc[2].x = UPSCALE( control1->x );
1391 arc[2].y = UPSCALE( control1->y );
1392 arc[3].x = ras.x;
1393 arc[3].y = ras.y;
1394
1395 /* short-cut the arc that crosses the current band */
1396 if ( ( TRUNC( arc[0].y ) >= ras.max_ey &&
1397 TRUNC( arc[1].y ) >= ras.max_ey &&
1398 TRUNC( arc[2].y ) >= ras.max_ey &&
1399 TRUNC( arc[3].y ) >= ras.max_ey ) ||
1400 ( TRUNC( arc[0].y ) < ras.min_ey &&
1401 TRUNC( arc[1].y ) < ras.min_ey &&
1402 TRUNC( arc[2].y ) < ras.min_ey &&
1403 TRUNC( arc[3].y ) < ras.min_ey ) )
1404 {
1405 ras.x = arc[0].x;
1406 ras.y = arc[0].y;
1407 return;
1408 }
1409
1410 for (;;)
1411 {
1412 /* with each split, control points quickly converge towards */
1413 /* chord trisection points and the vanishing distances below */
1414 /* indicate when the segment is flat enough to draw */
1415 if ( FT_ABS( 2 * arc[0].x - 3 * arc[1].x + arc[3].x ) > ONE_PIXEL / 2 ||
1416 FT_ABS( 2 * arc[0].y - 3 * arc[1].y + arc[3].y ) > ONE_PIXEL / 2 ||
1417 FT_ABS( arc[0].x - 3 * arc[2].x + 2 * arc[3].x ) > ONE_PIXEL / 2 ||
1418 FT_ABS( arc[0].y - 3 * arc[2].y + 2 * arc[3].y ) > ONE_PIXEL / 2 )
1419 goto Split;
1420
1421 gray_render_line( RAS_VAR_ arc[0].x, arc[0].y );
1422
1423 if ( arc == bez_stack )
1424 return;
1425
1426 arc -= 3;
1427 continue;
1428
1429 Split:
1430 gray_split_cubic( arc );
1431 arc += 3;
1432 }
1433 }
1434
1435
1436 static int
1438 void* worker_ ) /* gray_PWorker */
1439 {
1440 gray_PWorker worker = (gray_PWorker)worker_;
1441
1442 TPos x, y;
1443
1444
1445 /* start to a new position */
1446 x = UPSCALE( to->x );
1447 y = UPSCALE( to->y );
1448
1450
1451 ras.x = x;
1452 ras.y = y;
1453
1454 return ras.error;
1455 }
1456
1457
1458 static int
1460 void* worker_ ) /* gray_PWorker */
1461 {
1462 gray_PWorker worker = (gray_PWorker)worker_;
1463
1464
1465 gray_render_line( RAS_VAR_ UPSCALE( to->x ), UPSCALE( to->y ) );
1466
1467 return ras.error;
1468 }
1469
1470
1471 static int
1472 gray_conic_to( const FT_Vector* control,
1473 const FT_Vector* to,
1474 void* worker_ ) /* gray_PWorker */
1475 {
1476 gray_PWorker worker = (gray_PWorker)worker_;
1477
1478
1479 gray_render_conic( RAS_VAR_ control, to );
1480
1481 return ras.error;
1482 }
1483
1484
1485 static int
1486 gray_cubic_to( const FT_Vector* control1,
1487 const FT_Vector* control2,
1488 const FT_Vector* to,
1489 void* worker_ ) /* gray_PWorker */
1490 {
1491 gray_PWorker worker = (gray_PWorker)worker_;
1492
1493
1494 gray_render_cubic( RAS_VAR_ control1, control2, to );
1495
1496 return ras.error;
1497 }
1498
1499
1500#ifdef STANDALONE_
1501
1502 /**************************************************************************
1503 *
1504 * The following functions should only compile in stand-alone mode,
1505 * i.e., when building this component without the rest of FreeType.
1506 *
1507 */
1508
1509 /**************************************************************************
1510 *
1511 * @Function:
1512 * FT_Outline_Decompose
1513 *
1514 * @Description:
1515 * Walk over an outline's structure to decompose it into individual
1516 * segments and Bézier arcs. This function is also able to emit
1517 * `move to' and `close to' operations to indicate the start and end
1518 * of new contours in the outline.
1519 *
1520 * @Input:
1521 * outline ::
1522 * A pointer to the source target.
1523 *
1524 * func_interface ::
1525 * A table of `emitters', i.e., function pointers
1526 * called during decomposition to indicate path
1527 * operations.
1528 *
1529 * @InOut:
1530 * user ::
1531 * A typeless pointer which is passed to each
1532 * emitter during the decomposition. It can be
1533 * used to store the state during the
1534 * decomposition.
1535 *
1536 * @Return:
1537 * Error code. 0 means success.
1538 */
1539 static int
1541 const FT_Outline_Funcs* func_interface,
1542 void* user )
1543 {
1544#undef SCALED
1545#define SCALED( x ) ( (x) * ( 1L << shift ) - delta )
1546
1547 FT_Vector v_last;
1548 FT_Vector v_control;
1549 FT_Vector v_start;
1550
1551 FT_Vector* point;
1552 FT_Vector* limit;
1553 char* tags;
1554
1555 int error;
1556
1557 int n; /* index of contour in outline */
1558 int first; /* index of first point in contour */
1559 int last; /* index of last point in contour */
1560
1561 char tag; /* current point's state */
1562
1563 int shift;
1564 TPos delta;
1565
1566
1567 if ( !outline )
1568 return FT_THROW( Invalid_Outline );
1569
1570 if ( !func_interface )
1571 return FT_THROW( Invalid_Argument );
1572
1573 shift = func_interface->shift;
1574 delta = func_interface->delta;
1575
1576 last = -1;
1577 for ( n = 0; n < outline->n_contours; n++ )
1578 {
1579 FT_TRACE5(( "FT_Outline_Decompose: Contour %d\n", n ));
1580
1581 first = last + 1;
1582 last = outline->contours[n];
1583 if ( last < first )
1584 goto Invalid_Outline;
1585
1586 limit = outline->points + last;
1587
1588 v_start = outline->points[first];
1589 v_start.x = SCALED( v_start.x );
1590 v_start.y = SCALED( v_start.y );
1591
1592 v_last = outline->points[last];
1593 v_last.x = SCALED( v_last.x );
1594 v_last.y = SCALED( v_last.y );
1595
1596 v_control = v_start;
1597
1598 point = outline->points + first;
1599 tags = outline->tags + first;
1600 tag = FT_CURVE_TAG( tags[0] );
1601
1602 /* check first point to determine origin */
1603 if ( tag != FT_CURVE_TAG_ON )
1604 {
1605 char last_tag = FT_CURVE_TAG( outline->tags[last] );
1606
1607
1608 /* first point is a control point. Yes, this happens. */
1609 if ( last_tag == FT_CURVE_TAG_ON )
1610 {
1611 /* start at last point if it is on the curve */
1612 v_start = v_last;
1613 limit--;
1614 }
1615 else
1616 {
1617 if ( last_tag != tag )
1618 goto Invalid_Outline;
1619
1620 /* if both first and last points are controls, */
1621 /* start at their middle and record its position */
1622 /* for closure */
1623 v_start.x = ( v_start.x + v_last.x ) / 2;
1624 v_start.y = ( v_start.y + v_last.y ) / 2;
1625
1626 v_last = v_start;
1627 }
1628 point--;
1629 tags--;
1630 }
1631
1632 FT_TRACE5(( " move to (%.2f, %.2f)\n",
1633 v_start.x / 64.0, v_start.y / 64.0 ));
1634 error = func_interface->move_to( &v_start, user );
1635 if ( error )
1636 goto Exit;
1637
1638 while ( point < limit )
1639 {
1640 point++;
1641 tags++;
1642
1643 tag = FT_CURVE_TAG( tags[0] );
1644 switch ( tag )
1645 {
1646 case FT_CURVE_TAG_ON: /* emit a single line_to */
1647 {
1648 FT_Vector vec;
1649
1650
1651 vec.x = SCALED( point->x );
1652 vec.y = SCALED( point->y );
1653
1654 FT_TRACE5(( " line to (%.2f, %.2f)\n",
1655 vec.x / 64.0, vec.y / 64.0 ));
1656 error = func_interface->line_to( &vec, user );
1657 if ( error )
1658 goto Exit;
1659 continue;
1660 }
1661
1662 case FT_CURVE_TAG_CONIC: /* consume conic arcs */
1663 v_control.x = SCALED( point->x );
1664 v_control.y = SCALED( point->y );
1665
1666 Do_Conic:
1667 if ( point < limit )
1668 {
1669 FT_Vector vec;
1670 FT_Vector v_middle;
1671
1672
1673 point++;
1674 tags++;
1675 tag = FT_CURVE_TAG( tags[0] );
1676
1677 vec.x = SCALED( point->x );
1678 vec.y = SCALED( point->y );
1679
1680 if ( tag == FT_CURVE_TAG_ON )
1681 {
1682 FT_TRACE5(( " conic to (%.2f, %.2f)"
1683 " with control (%.2f, %.2f)\n",
1684 vec.x / 64.0, vec.y / 64.0,
1685 v_control.x / 64.0, v_control.y / 64.0 ));
1686 error = func_interface->conic_to( &v_control, &vec, user );
1687 if ( error )
1688 goto Exit;
1689 continue;
1690 }
1691
1692 if ( tag != FT_CURVE_TAG_CONIC )
1693 goto Invalid_Outline;
1694
1695 v_middle.x = ( v_control.x + vec.x ) / 2;
1696 v_middle.y = ( v_control.y + vec.y ) / 2;
1697
1698 FT_TRACE5(( " conic to (%.2f, %.2f)"
1699 " with control (%.2f, %.2f)\n",
1700 v_middle.x / 64.0, v_middle.y / 64.0,
1701 v_control.x / 64.0, v_control.y / 64.0 ));
1702 error = func_interface->conic_to( &v_control, &v_middle, user );
1703 if ( error )
1704 goto Exit;
1705
1706 v_control = vec;
1707 goto Do_Conic;
1708 }
1709
1710 FT_TRACE5(( " conic to (%.2f, %.2f)"
1711 " with control (%.2f, %.2f)\n",
1712 v_start.x / 64.0, v_start.y / 64.0,
1713 v_control.x / 64.0, v_control.y / 64.0 ));
1714 error = func_interface->conic_to( &v_control, &v_start, user );
1715 goto Close;
1716
1717 default: /* FT_CURVE_TAG_CUBIC */
1718 {
1719 FT_Vector vec1, vec2;
1720
1721
1722 if ( point + 1 > limit ||
1723 FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC )
1724 goto Invalid_Outline;
1725
1726 point += 2;
1727 tags += 2;
1728
1729 vec1.x = SCALED( point[-2].x );
1730 vec1.y = SCALED( point[-2].y );
1731
1732 vec2.x = SCALED( point[-1].x );
1733 vec2.y = SCALED( point[-1].y );
1734
1735 if ( point <= limit )
1736 {
1737 FT_Vector vec;
1738 FT_Vector v_middle;
1739
1740
1741 tag = FT_CURVE_TAG( tags[0] );
1742
1743 vec.x = SCALED( point->x );
1744 vec.y = SCALED( point->y );
1745
1746 if ( tag == FT_CURVE_TAG_CUBIC )
1747 {
1748 v_middle.x = ( vec2.x + vec.x ) / 2;
1749 v_middle.y = ( vec2.y + vec.y ) / 2;
1750
1751 vec = v_middle;
1752 }
1753 else if ( tag != FT_CURVE_TAG_ON )
1754 goto Invalid_Outline;
1755
1756 FT_TRACE5(( " cubic to (%.2f, %.2f)"
1757 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1758 vec.x / 64.0, vec.y / 64.0,
1759 vec1.x / 64.0, vec1.y / 64.0,
1760 vec2.x / 64.0, vec2.y / 64.0 ));
1761 error = func_interface->cubic_to( &vec1, &vec2, &vec, user );
1762 if ( error )
1763 goto Exit;
1764
1765 if ( tag == FT_CURVE_TAG_CUBIC )
1766 {
1767 point--;
1768 tags--;
1769 }
1770 continue;
1771 }
1772
1773 FT_TRACE5(( " cubic to (%.2f, %.2f)"
1774 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1775 v_start.x / 64.0, v_start.y / 64.0,
1776 vec1.x / 64.0, vec1.y / 64.0,
1777 vec2.x / 64.0, vec2.y / 64.0 ));
1778 error = func_interface->cubic_to( &vec1, &vec2, &v_start, user );
1779 goto Close;
1780 }
1781 }
1782 }
1783
1784 /* close the contour with a line segment */
1785 FT_TRACE5(( " line to (%.2f, %.2f)\n",
1786 v_start.x / 64.0, v_start.y / 64.0 ));
1787 error = func_interface->line_to( &v_start, user );
1788
1789 Close:
1790 if ( error )
1791 goto Exit;
1792 }
1793
1794 FT_TRACE5(( "FT_Outline_Decompose: Done\n", n ));
1795 return Smooth_Err_Ok;
1796
1797 Exit:
1798 FT_TRACE5(( "FT_Outline_Decompose: Error 0x%x\n", error ));
1799 return error;
1800
1801 Invalid_Outline:
1802 return FT_THROW( Invalid_Outline );
1803 }
1804
1805#endif /* STANDALONE_ */
1806
1807
1809 func_interface,
1810
1811 (FT_Outline_MoveTo_Func) gray_move_to, /* move_to */
1812 (FT_Outline_LineTo_Func) gray_line_to, /* line_to */
1813 (FT_Outline_ConicTo_Func)gray_conic_to, /* conic_to */
1814 (FT_Outline_CubicTo_Func)gray_cubic_to, /* cubic_to */
1815
1816 0, /* shift */
1817 0 /* delta */
1818 )
1819
1820
1821 static int
1822 gray_convert_glyph_inner( RAS_ARG_
1823 int continued )
1824 {
1825 int error;
1826
1827
1828 if ( continued )
1830 error = FT_Outline_Decompose( &ras.outline, &func_interface, &ras );
1831 if ( continued )
1833
1834 FT_TRACE7(( error == Smooth_Err_Raster_Overflow
1835 ? "band [%d..%d]: to be bisected\n"
1836 : "band [%d..%d]: %td cell%s remaining\n",
1837 ras.min_ey,
1838 ras.max_ey,
1839 ras.cell_null - ras.cell_free,
1840 ras.cell_null - ras.cell_free == 1 ? "" : "s" ));
1841
1842 return error;
1843 }
1844
1845
1846 static void
1848 {
1849 int fill = ( ras.outline.flags & FT_OUTLINE_EVEN_ODD_FILL ) ? 0x100
1850 : INT_MIN;
1851 int coverage;
1852 int y;
1853
1854
1855 for ( y = ras.min_ey; y < ras.max_ey; y++ )
1856 {
1857 PCell cell = ras.ycells[y - ras.min_ey];
1858 TCoord x = ras.min_ex;
1859 TArea cover = 0;
1860
1861 unsigned char* line = ras.target.origin - ras.target.pitch * y;
1862
1863
1864 for ( ; cell != ras.cell_null; cell = cell->next )
1865 {
1866 TArea area;
1867
1868
1869 if ( cover != 0 && cell->x > x )
1870 {
1871 FT_FILL_RULE( coverage, cover, fill );
1872 FT_GRAY_SET( line + x, coverage, cell->x - x );
1873 }
1874
1875 cover += (TArea)cell->cover * ( ONE_PIXEL * 2 );
1876 area = cover - cell->area;
1877
1878 if ( area != 0 && cell->x >= ras.min_ex )
1879 {
1880 FT_FILL_RULE( coverage, area, fill );
1881 line[cell->x] = (unsigned char)coverage;
1882 }
1883
1884 x = cell->x + 1;
1885 }
1886
1887 if ( cover != 0 ) /* only if cropped */
1888 {
1889 FT_FILL_RULE( coverage, cover, fill );
1890 FT_GRAY_SET( line + x, coverage, ras.max_ex - x );
1891 }
1892 }
1893 }
1894
1895
1896 /* Qt: add a span, merging it with the previous one if possible */
1897 static void
1899 int* n,
1900 TCoord x,
1901 TCoord len,
1902 TCoord y,
1903 int coverage )
1904 {
1905 coverage &= 0xFF;
1906 if ( coverage == 0 || len <= 0 )
1907 return;
1908
1909 if ( *n > 0 )
1910 {
1911 FT_Span* last = span + *n - 1;
1912
1913
1914 if ( last->y == y &&
1915 last->x + last->len == x &&
1916 last->coverage == coverage )
1917 {
1918 last->len += len;
1919 return;
1920 }
1921 }
1922
1923 if ( *n == FT_MAX_GRAY_SPANS )
1924 {
1925 /* flush the span buffer and reset the count */
1926 ras.render_span( *n, span, ras.render_span_data );
1927 *n = 0;
1928 }
1929
1930 span[*n].x = x;
1931 span[*n].len = len;
1932 span[*n].y = y;
1933 span[*n].coverage = (unsigned char)coverage;
1934 ++*n;
1935 }
1936
1937
1938 static void
1940 {
1941 int fill = ( ras.outline.flags & FT_OUTLINE_EVEN_ODD_FILL ) ? 0x100
1942 : INT_MIN;
1943 int coverage;
1944 int y;
1945
1947 int n = 0;
1948
1949
1950 for ( y = ras.min_ey; y < ras.max_ey; y++ )
1951 {
1952 PCell cell = ras.ycells[y - ras.min_ey];
1953 TCoord x = ras.min_ex;
1954 TArea cover = 0;
1955
1956
1957 for ( ; cell != ras.cell_null; cell = cell->next )
1958 {
1959 TArea area;
1960
1961
1962 if ( cover != 0 && cell->x > x )
1963 {
1964 FT_FILL_RULE( coverage, cover, fill );
1965 gray_add_span( RAS_VAR_ span, &n, x, cell->x - x, y, coverage );
1966 }
1967
1968 cover += (TArea)cell->cover * ( ONE_PIXEL * 2 );
1969 area = cover - cell->area;
1970
1971 if ( area != 0 && cell->x >= ras.min_ex )
1972 {
1973 FT_FILL_RULE( coverage, area, fill );
1974 gray_add_span( RAS_VAR_ span, &n, cell->x, 1, y, coverage );
1975 }
1976
1977 x = cell->x + 1;
1978 }
1979
1980 if ( cover != 0 ) /* only if cropped */
1981 {
1982 FT_FILL_RULE( coverage, cover, fill );
1983 gray_add_span( RAS_VAR_ span, &n, x, ras.max_ex - x, y, coverage );
1984 }
1985 }
1986
1987 if ( n )
1988 ras.render_span( n, span, ras.render_span_data );
1989 }
1990
1991
1992 static int
1994 {
1995 TCoord bands[32]; /* enough to accommodate bisections */
1996 TCoord* band = bands;
1997
1998 int continued = 0;
1999 int error = Smooth_Err_Ok;
2000
2001
2002 /* Initialize the null cell at the end of the poll. */
2006 ras.cell_null->next = NULL;
2007
2008 /* set up vertical bands */
2010
2011 while ( 1 )
2012 {
2013 size_t n;
2014 TCoord i, count = ras.max_ey - ras.min_ey;
2015
2016
2017 /* memory management: zero out and skip ycells */
2018 for ( i = 0; i < count; ++i )
2020
2021 n = ( (size_t)count * sizeof ( PCell ) + sizeof ( TCell ) - 1 )
2022 / sizeof ( TCell );
2023
2027
2028 error = gray_convert_glyph_inner( RAS_VAR_ continued );
2029 continued = 1;
2030
2031 if ( !error )
2032 {
2033 if ( ras.render_span ) /* for FT_RASTER_FLAG_DIRECT only */
2035 else
2037
2038 if ( band == bands )
2039 break; /* done */
2040
2042 ras.min_ey = *--band;
2043 continue;
2044 }
2045 else if ( error != Smooth_Err_Raster_Overflow )
2046 goto Exit;
2047
2048 /* render pool overflow, reduce the render band by half */
2049 count >>= 1;
2050
2051 /* this happens only if the rendering pool is too small */
2052 if ( count == 0 )
2053 {
2054 FT_TRACE7(( "gray_convert_glyph: rotten glyph\n" ));
2055 error = FT_THROW( Raster_Overflow );
2056 goto Exit;
2057 }
2058
2059 *band++ = ras.min_ey;
2060 ras.min_ey += count;
2061 }
2062
2063 Exit:
2064 return error;
2065 }
2066
2067
2068 static int
2070 const FT_Raster_Params* params )
2071 {
2072 FT_ULong estimate;
2073 int ret;
2074
2075 const FT_Outline* outline = (const FT_Outline*)params->source;
2076 const FT_Bitmap* target_map = params->target;
2077
2078#ifndef FT_STATIC_RASTER
2079 gray_TWorker worker[1];
2080#endif
2081
2082
2083 if ( !raster )
2084 return FT_THROW( Invalid_Argument );
2085
2086 /* this version does not support monochrome rendering */
2087 if ( !( params->flags & FT_RASTER_FLAG_AA ) )
2088 return FT_THROW( Cannot_Render_Glyph );
2089
2090 if ( !outline )
2091 return FT_THROW( Invalid_Outline );
2092
2093 /* return immediately if the outline is empty */
2094 if ( outline->n_points == 0 || outline->n_contours == 0 )
2095 return Smooth_Err_Ok;
2096
2097 if ( !outline->contours || !outline->points )
2098 return FT_THROW( Invalid_Outline );
2099
2100 if ( outline->n_points !=
2101 outline->contours[outline->n_contours - 1] + 1 )
2102 return FT_THROW( Invalid_Outline );
2103
2104 ras.outline = *outline;
2105
2106 if ( params->flags & FT_RASTER_FLAG_DIRECT )
2107 {
2108 if ( !params->gray_spans )
2109 return Smooth_Err_Ok;
2110
2111 ras.render_span = (FT_Raster_Span_Func)params->gray_spans;
2112 ras.render_span_data = params->user;
2113
2114 ras.min_ex = (TCoord)params->clip_box.xMin;
2115 ras.min_ey = (TCoord)params->clip_box.yMin;
2116 ras.max_ex = (TCoord)params->clip_box.xMax;
2117 ras.max_ey = (TCoord)params->clip_box.yMax;
2118
2119 /* Qt: the clip box is typically the whole paint device, */
2120 /* so limit it to the outline's control box */
2121 {
2122 const FT_Vector* vec = outline->points;
2123 const FT_Vector* limit = vec + outline->n_points;
2124
2125 TPos xMin = vec->x, yMin = vec->y;
2126 TPos xMax = vec->x, yMax = vec->y;
2127
2128
2129 for ( vec++; vec < limit; vec++ )
2130 {
2131 xMin = FT_MIN( xMin, vec->x );
2132 yMin = FT_MIN( yMin, vec->y );
2133 xMax = FT_MAX( xMax, vec->x );
2134 yMax = FT_MAX( yMax, vec->y );
2135 }
2136
2137 /* the outline is in 26.6 format */
2138 ras.min_ex = FT_MAX( ras.min_ex, (TCoord)( xMin >> 6 ) );
2139 ras.min_ey = FT_MAX( ras.min_ey, (TCoord)( yMin >> 6 ) );
2140 ras.max_ex = FT_MIN( ras.max_ex, (TCoord)( ( xMax + 63 ) >> 6 ) );
2141 ras.max_ey = FT_MIN( ras.max_ey, (TCoord)( ( yMax + 63 ) >> 6 ) );
2142 }
2143 }
2144 else
2145 {
2146 /* if direct mode is not set, we must have a target bitmap */
2147 if ( !target_map )
2148 return FT_THROW( Invalid_Argument );
2149
2150 /* nothing to do */
2151 if ( !target_map->width || !target_map->rows )
2152 return Smooth_Err_Ok;
2153
2154 if ( !target_map->buffer )
2155 return FT_THROW( Invalid_Argument );
2156
2157 if ( target_map->pitch < 0 )
2158 ras.target.origin = target_map->buffer;
2159 else
2160 ras.target.origin = target_map->buffer
2161 + ( target_map->rows - 1 ) * (unsigned int)target_map->pitch;
2162
2163 ras.target.pitch = target_map->pitch;
2164
2165 ras.render_span = (FT_Raster_Span_Func)NULL;
2166 ras.render_span_data = NULL;
2167
2168 ras.min_ex = 0;
2169 ras.min_ey = 0;
2170 ras.max_ex = (TCoord)target_map->width;
2171 ras.max_ey = (TCoord)target_map->rows;
2172 }
2173
2174 /* exit if nothing to do */
2176 return Smooth_Err_Ok;
2177
2178 /* allocate memory based on empirical estimate from CJK fonts */
2179 estimate = ( ras.max_ex - ras.min_ex + ras.max_ey - ras.min_ey ) * 10UL;
2180 if ( estimate > FT_MAX_GRAY_POOL )
2181 {
2182 /* Qt: no FT_Memory, use malloc */
2183 ras.buffer = (PCell)malloc( estimate * sizeof ( TCell ) );
2184 if ( !ras.buffer )
2185 ret = FT_THROW( Raster_Overflow );
2186 else
2187 {
2188 ras.cell_null = ras.buffer + estimate - 1;
2190 free( ras.buffer );
2191 }
2192 }
2193 else
2194 {
2195 TCell buffer[FT_MAX_GRAY_POOL]; /* stack allocation */
2196
2197
2198 ras.buffer = buffer;
2200
2202 }
2203
2204 return ret;
2205 }
2206
2207
2208 /**** RASTER OBJECT CREATION: In stand-alone mode, we simply use *****/
2209 /**** a static object. *****/
2210
2211#ifdef STANDALONE_
2212
2213 /* Qt: allocate a raster object per paint engine, and no memory argument */
2214 static int
2216 {
2217 gray_PRaster raster = (gray_PRaster)malloc( sizeof ( gray_TRaster ) );
2218
2219
2220 *araster = (FT_Raster)raster;
2221 if ( !raster )
2222 return FT_THROW( Raster_Overflow );
2223
2224 FT_ZERO( raster );
2225
2226 return 0;
2227 }
2228
2229
2230 static void
2232 {
2233 free( raster );
2234 }
2235
2236#else /* !STANDALONE_ */
2237
2238 static int
2239 gray_raster_new( void* memory_,
2240 FT_Raster* araster_ )
2241 {
2242 FT_Memory memory = (FT_Memory)memory_;
2243 gray_PRaster* araster = (gray_PRaster*)araster_;
2244
2245 FT_Error error;
2246 gray_PRaster raster = NULL;
2247
2248
2249 if ( !FT_NEW( raster ) )
2250 raster->memory = memory;
2251
2252 *araster = raster;
2253
2254 return error;
2255 }
2256
2257
2258 static void
2259 gray_raster_done( FT_Raster raster )
2260 {
2261 FT_Memory memory = (FT_Memory)((gray_PRaster)raster)->memory;
2262
2263
2264 FT_FREE( raster );
2265 }
2266
2267#endif /* !STANDALONE_ */
2268
2269
2270 static void
2272 unsigned char* pool_base,
2273 unsigned long pool_size )
2274 {
2275 FT_UNUSED( raster );
2276 FT_UNUSED( pool_base );
2277 FT_UNUSED( pool_size );
2278 }
2279
2280
2281 static int
2283 unsigned long mode,
2284 void* args )
2285 {
2286 FT_UNUSED( raster );
2287 FT_UNUSED( mode );
2288 FT_UNUSED( args );
2289
2290
2291 return 0; /* nothing to do */
2292 }
2293
2294
2297
2299
2300 (FT_Raster_New_Func) gray_raster_new, /* raster_new */
2301 (FT_Raster_Reset_Func) gray_raster_reset, /* raster_reset */
2302 (FT_Raster_Set_Mode_Func)gray_raster_set_mode, /* raster_set_mode */
2303 (FT_Raster_Render_Func) gray_raster_render, /* raster_render */
2304 (FT_Raster_Done_Func) gray_raster_done /* raster_done */
2305 )
2306
2307
2308/* END */
2309
2310
2311/* Local Variables: */
2312/* coding: utf-8 */
2313/* End: */
#define __has_attribute(x)
#define FT_CURVE_TAG_CUBIC
#define FT_END_STMNT
static void gray_render_conic(RAS_ARG_ const FT_Vector *control, const FT_Vector *to)
static int gray_raster_new(FT_Raster *araster)
#define FT_RASTER_FLAG_AA
#define RAS_ARG
#define UPSCALE(x)
struct TCell_ * PCell
#define ft_memset
#define FT_DEFINE_RASTER_FUNCS(class_, glyph_format_, raster_new_, raster_reset_, raster_set_mode_, raster_render_, raster_done_)
long TPos
#define FT_Raster_Span_Func
#define FT_ABS(a)
#define TRUNC(x)
static void gray_render_line(RAS_ARG_ TPos to_x, TPos to_y)
#define FT_UDIVPREP(c, b)
#define FALL_THROUGH
static int gray_conic_to(const FT_Vector *control, const FT_Vector *to, void *worker_)
#define FT_CURVE_TAG_CONIC
int TArea
long long FT_Int64
#define FT_Raster_Render_Func
int TCoord
#define FT_MIN(a, b)
ptrdiff_t FT_PtrDist
#define FT_CURVE_TAG
#define FT_OUTLINE_EVEN_ODD_FILL
unsigned long FT_ULong
static int FT_Outline_Decompose(const FT_Outline *outline, const FT_Outline_Funcs *func_interface, void *user)
unsigned long long FT_UInt64
#define FT_FILL_RULE(coverage, area, fill)
#define Smooth_Err_Raster_Overflow
#define FT_MEM_SET(d, s, c)
#define FT_TRACE5(x)
#define FT_Outline_CubicTo_Func
#define FT_ERR_CAT(x, y)
static int gray_cubic_to(const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to, void *worker_)
#define FT_Span
#define LEFT_SHIFT(a, b)
#define STANDALONE_
static void gray_sweep(RAS_ARG)
#define RAS_VAR
static int gray_convert_glyph(RAS_ARG)
#define FT_Bitmap
#define FT_Outline_LineTo_Func
int FT_Int
static void gray_render_cubic(RAS_ARG_ const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to)
#define FT_UNUSED(x)
#define FT_Raster_Reset_Func
#define FT_INT64
#define RAS_VAR_
#define PIXEL_BITS
#define FRACT(x)
#define FT_RASTER_FLAG_DIRECT
#define FT_Pos
static void gray_sweep_direct(RAS_ARG)
#define FT_Trace_Disable()
static void gray_raster_done(FT_Raster raster)
#define FT_ZERO(p)
#define ras
#define FT_Raster_Funcs
#define FT_Raster
static void gray_add_span(RAS_ARG_ FT_Span *span, int *n, TCoord x, TCoord len, TCoord y, int coverage)
#define FT_Outline_ConicTo_Func
#define FT_CURVE_TAG_ON
#define RAS_ARG_
static int gray_move_to(const FT_Vector *to, void *worker_)
#define FT_UDIV(a, b)
#define SCALED(x)
static void gray_set_cell(RAS_ARG_ TCoord ex, TCoord ey)
#define FT_Outline_Funcs
static void gray_split_cubic(FT_Vector *base)
#define FT_MAX(a, b)
static int gray_raster_set_mode(FT_Raster raster, unsigned long mode, void *args)
#define FT_Outline
#define FT_ERR_XCAT(x, y)
#define FT_TRACE7(x)
#define FT_Raster_New_Func
#define FT_Vector
#define Smooth_Err_Ok
#define FT_INTEGRATE(ras, a, b)
unsigned int FT_UInt
#define FT_THROW(e)
#define FT_Trace_Enable()
#define FT_GRAY_SET(d, s, count)
#define FT_DEFINE_OUTLINE_FUNCS(class_, move_to_, line_to_, conic_to_, cubic_to_, shift_, delta_)
#define FT_MAX_GRAY_POOL
#define CELL_MAX_X_VALUE
#define FT_MEM_ZERO(dest, count)
#define ft_grays_raster
#define FT_Raster_Set_Mode_Func
#define FT_GLYPH_FORMAT_OUTLINE
#define gray_TRaster_
#define ADD_INT(a, b)
static int gray_line_to(const FT_Vector *to, void *worker_)
#define FT_Outline_MoveTo_Func
#define FT_RENDER_POOL_SIZE
static void gray_raster_reset(FT_Raster raster, unsigned char *pool_base, unsigned long pool_size)
static int gray_raster_render(FT_Raster raster, const FT_Raster_Params *params)
#define FT_Raster_Done_Func
#define ONE_PIXEL
#define FT_MAX_GRAY_SPANS
#define FT_Raster_Params
#define FT_BEGIN_STMNT
TCoord cover
PCell next
TCoord x
TArea area
unsigned char * origin
FT_Raster_Span_Func render_span
FT_Outline outline
void * render_span_data