1 /* Copyright (C) 2001-2006 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied, modified
8    or distributed except as expressly authorized under the terms of that
9    license.  Refer to licensing information at http://www.artifex.com/
10    or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11    San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12 */
13 
14 /* $Id: gxchar.h 8219 2007-08-31 04:47:58Z leonardo $ */
15 /* Internal character definition for Ghostscript library */
16 /* Requires gsmatrix.h, gxfixed.h */
17 
18 #ifndef gxchar_INCLUDED
19 #  define gxchar_INCLUDED
20 
21 #include "gschar.h"
22 #include "gxtext.h"
23 
24 /* The type of cached characters is opaque. */
25 #ifndef cached_char_DEFINED
26 #  define cached_char_DEFINED
27 typedef struct cached_char_s cached_char;
28 #endif
29 
30 /* The type of cached font/matrix pairs is opaque. */
31 #ifndef cached_fm_pair_DEFINED
32 #  define cached_fm_pair_DEFINED
33 typedef struct cached_fm_pair_s cached_fm_pair;
34 #endif
35 
36 /* The type of font objects is opaque. */
37 #ifndef gs_font_DEFINED
38 #  define gs_font_DEFINED
39 typedef struct gs_font_s gs_font;
40 #endif
41 
42 /* The type of text enum objects is opaque. */
43 #ifndef gs_text_enum_DEFINED
44 #  define gs_text_enum_DEFINED
45 typedef struct gs_text_enum_s gs_text_enum_t;
46 #endif
47 
48 /* The types of memory and null devices may be opaque. */
49 #ifndef gx_device_memory_DEFINED
50 #  define gx_device_memory_DEFINED
51 typedef struct gx_device_memory_s gx_device_memory;
52 #endif
53 #ifndef gx_device_null_DEFINED
54 #  define gx_device_null_DEFINED
55 typedef struct gx_device_null_s gx_device_null;
56 #endif
57 
58 /* An enumeration object for string display. */
59 typedef enum {
60     sws_none,
61     sws_cache,			/* setcachedevice[2] */
62     sws_no_cache,		/* setcharwidth */
63     sws_cache_width_only,	/* setcharwidth for xfont char */
64     sws_retry			/* retry setcachedevice[2] */
65 } show_width_status;
66 struct gs_show_enum_s {
67     /* Put this first for subclassing. */
68     gs_text_enum_common;	/* (procs, text, index) */
69     /* Following are set at creation time */
70     bool auto_release;		/* true if old API, false if new */
71     gs_state *pgs;
72     int level;			/* save the level of pgs */
73     gs_char_path_mode charpath_flag;
74     gs_state *show_gstate;	/* for setting pgs->show_gstate */
75 				/* at returns/callouts */
76     int can_cache;		/* -1 if can't use cache at all, */
77 				/* 0 if can read but not load, */
78 				/* 1 if can read and load */
79     gs_int_rect ibox;		/* int version of quick-check */
80 				/* (inner) clipping box */
81     gs_int_rect obox;		/* int version of (outer) clip box */
82     int ftx, fty;		/* transformed font translation */
83     /* Following are updated dynamically */
84     gs_glyph (*encode_char)(gs_font *, gs_char, gs_glyph_space_t);  /* copied from font */
85     gs_log2_scale_point fapi_log2_scale; /* scaling factors for oversampling with FAPI, -1 = not valid */
86     gs_point fapi_glyph_shift;          /* glyph shift for FAPI-handled font */
87     gx_device_memory *dev_cache;	/* cache device */
88     gx_device_memory *dev_cache2;	/* underlying alpha memory device, */
89 				/* if dev_cache is an alpha buffer */
90     gx_device_null *dev_null;	/* null device for stringwidth */
91     /*uint index; */		/* index within string */
92     /*uint xy_index;*/		/* index within X/Y widths */
93     /*gs_char returned.current_char;*/	/* current char for render or move */
94     /*gs_glyph returned.current_glyph;*/	/* current glyph ditto */
95     gs_fixed_point wxy;		/* width of current char in device coords */
96     gs_point wxy_float;		/* same for huge characters */
97     bool use_wxy_float;
98     gs_fixed_point origin;	/* unrounded origin of current char */
99 				/* in device coords, needed for */
100 				/* charpath and WMode=1 */
101     cached_char *cc;		/* being accumulated */
102     /*gs_point returned.total_width;*/		/* total width of string, set at end */
103     show_width_status width_status;
104     /*gs_log2_scale_point log2_scale;*/
105     int (*continue_proc) (gs_show_enum *);	/* continuation procedure */
106 };
107 #define gs_show_enum_s_DEFINED
108 /* The structure descriptor is public for gschar.c. */
109 #define public_st_gs_show_enum() /* in gxchar.c */\
110   gs_public_st_composite(st_gs_show_enum, gs_show_enum, "gs_show_enum",\
111     show_enum_enum_ptrs, show_enum_reloc_ptrs)
112 
113 /* Get the current character code. */
114 int gx_current_char(const gs_text_enum_t * pte);
115 
116 /* Cached character procedures (in gxccache.c and gxccman.c) */
117 #ifndef gs_font_dir_DEFINED
118 #  define gs_font_dir_DEFINED
119 typedef struct gs_font_dir_s gs_font_dir;
120 
121 #endif
122 int  gx_alloc_char_bits(gs_font_dir *, gx_device_memory *, gx_device_memory *, ushort, ushort, const gs_log2_scale_point *, int, cached_char **);
123 void gx_open_cache_device(gx_device_memory *, cached_char *);
124 void gx_free_cached_char(gs_font_dir *, cached_char *);
125 int  gx_add_cached_char(gs_font_dir *, gx_device_memory *, cached_char *, cached_fm_pair *, const gs_log2_scale_point *);
126 void gx_add_char_bits(gs_font_dir *, cached_char *, const gs_log2_scale_point *);
127 cached_char *
128             gx_lookup_cached_char(const gs_font *, const cached_fm_pair *, gs_glyph, int, int, gs_fixed_point *);
129 int gx_lookup_xfont_char(const gs_state * pgs, cached_fm_pair * pair,
130 		     gs_char chr, gs_glyph glyph, int wmode, cached_char **pcc);
131 int gx_image_cached_char(gs_show_enum *, cached_char *);
132 void gx_compute_text_oversampling(const gs_show_enum * penum, const gs_font *pfont,
133 				  int alpha_bits, gs_log2_scale_point *p_log2_scale);
134 int set_char_width(gs_show_enum *penum, gs_state *pgs, floatp wx, floatp wy);
135 int gx_default_text_restore_state(gs_text_enum_t *pte);
136 int gx_hld_stringwidth_begin(gs_imager_state * pis, gx_path **path);
137 
138 #endif /* gxchar_INCLUDED */
139