xref: /plan9/sys/src/cmd/gs/src/gzspotan.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 2003 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gzspotan.h,v 1.6 2004/01/27 16:07:20 igor Exp $ */
18 /* State and interface definitions for a spot analyzer device. */
19 
20 /*
21  * A spot analyzer device performs an analyzis while handling an output
22  * of the trapezoid fill algorithm for 2 purposes :
23  * a glyph grid fitting, and
24  * a glyph antialiased rendering any number of alpha bits.
25  * Currently we only implement a vertical stem recognition for the grid fitting.
26  */
27 
28 #ifndef gzspotan_INCLUDED
29 #  define gzspotan_INCLUDED
30 
31 #include "gxdevcli.h"
32 
33 #ifndef segment_DEFINED
34 #  define segment_DEFINED
35 typedef struct segment_s segment; /* gzpath.h */
36 #endif
37 
38 #ifndef gx_device_spot_analyzer_DEFINED
39 #   define gx_device_spot_analyzer_DEFINED
40 typedef struct gx_device_spot_analyzer_s gx_device_spot_analyzer;
41 #endif
42 
43 /* -------------- Structures ----------------------------- */
44 
45 typedef struct gx_san_trap_s gx_san_trap;
46 typedef struct gx_san_trap_contact_s gx_san_trap_contact;
47 
48 /* A trapezoid. */
49 struct gx_san_trap_s {
50     /* Buffer link : */
51     gx_san_trap *link; /* Buffer link. */
52     /* The geometry : */
53     fixed ybot, ytop;
54     fixed xlbot, xrbot, xltop, xrtop;
55     /* The spot topology representation : */
56     gx_san_trap_contact *upper; /* Neighbours of the upper band. */
57     const segment *l; /* Outline pointer : left boundary. */
58     const segment *r; /* Outline pointer : right boundary. */
59     int dir_l, dir_r; /* Outline direction : left, right. */
60     bool leftmost, rightmost;
61     /* The topology reconstrustor work data : */
62     gx_san_trap *next; /* Next with same ytop. */
63     gx_san_trap *prev; /* Prev with same ytop. */
64     /* The stem recognizer work data : */
65     bool visited;
66     int fork;
67 };
68 #define private_st_san_trap() /* When GC is invoked, only the buffer link is valid. */\
69   gs_private_st_ptrs1(st_san_trap, gx_san_trap, "gx_san_trap", \
70     san_trap_enum_ptrs, san_trap_reloc_ptrs, link)
71 
72 /* A contact of 2 trapezoids. */
73 /* Represents a neighbourship through a band boundary. */
74 struct gx_san_trap_contact_s {
75     /* Buffer link : */
76     gx_san_trap_contact *link; /* Buffer link. */
77     gx_san_trap_contact *next; /* Next element of the same relation, a cyclic list. */
78     gx_san_trap_contact *prev; /* Prev element of the same relation, a cyclic list. */
79     gx_san_trap *upper, *lower; /* A contacting pair. */
80 };
81 #define private_st_san_trap_contact() /* When GC is invoked, only the buffer link is valid. */\
82   gs_private_st_ptrs1(st_san_trap_contact, gx_san_trap_contact, "gx_san_trap_contact",\
83   san_trap_contact_enum_ptrs, san_trap_contact_reloc_ptrs, link)
84 
85 /* A stem section. */
86 typedef struct gx_san_sect_s gx_san_sect;
87 struct gx_san_sect_s {
88     fixed xl, yl, xr, yr;
89     const segment *l, *r;
90     int side_mask;
91 };
92 
93 /* A spot analyzer device. */
94 struct gx_device_spot_analyzer_s {
95     gx_device_common;
96     int lock;
97     /* Buffers : */
98     gx_san_trap *trap_buffer, *trap_buffer_last, *trap_free;
99     gx_san_trap_contact *cont_buffer, *cont_buffer_last, *cont_free;
100     int trap_buffer_count;
101     int cont_buffer_count;
102     /* The topology reconstrustor work data (no GC invocations) : */
103     gx_san_trap *bot_band;
104     gx_san_trap *top_band;
105     gx_san_trap *bot_current;
106     /* The stem recognizer work data (no GC invocations) : */
107     fixed xmin, xmax;
108 };
109 
110 extern_st(st_device_spot_analyzer);
111 #define public_st_device_spot_analyzer() /* When GC is invoked, only the buffer links are valid. */\
112     gs_public_st_suffix_add4_final(st_device_spot_analyzer, gx_device_spot_analyzer,\
113 	    "gx_device_spot_analyzer", device_spot_analyzer_enum_ptrs,\
114 	    device_spot_analyzer_reloc_ptrs, gx_device_finalize, st_device,\
115 	    trap_buffer, trap_buffer_last, cont_buffer, cont_buffer_last)
116 
117 /* -------------- Interface methods ----------------------------- */
118 
119 /* Obtain a spot analyzer device. */
120 int gx_san__obtain(gs_memory_t *mem, gx_device_spot_analyzer **ppadev);
121 
122 /* Obtain a spot analyzer device. */
123 void gx_san__release(gx_device_spot_analyzer **ppadev);
124 
125 /* Start accumulating a path. */
126 void gx_san_begin(gx_device_spot_analyzer *padev);
127 
128 /* Store a tarpezoid. */
129 /* Assumes an Y-band scanning order with increasing X inside a band. */
130 int gx_san_trap_store(gx_device_spot_analyzer *padev,
131     fixed ybot, fixed ytop, fixed xlbot, fixed xrbot, fixed xltop, fixed xrtop,
132     const segment *l, const segment *r, int dir_l, int dir_r);
133 
134 /* Finish accumulating a path. */
135 void gx_san_end(const gx_device_spot_analyzer *padev);
136 
137 /* Generate stems. */
138 int gx_san_generate_stems(gx_device_spot_analyzer *padev,
139 		bool overall_hints, void *client_data,
140 		int (*handler)(void *client_data, gx_san_sect *ss));
141 
142 #endif /* gzspotan_INCLUDED */
143