Debian Codegraph @

cuneiform_src/Kern/hhh/tigerh/h/edp.h

raw
1 /*
2 Copyright (c) 1993-2008, Cognitive Technologies
3 All rights reserved.
4
5 Разрешается повторное распространение и использование как в виде исходного кода,
6 так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:
7
8 * При повторном распространении исходного кода должны оставаться указанное
9 выше уведомление об авторском праве, этот список условий и последующий
10 отказ от гарантий.
11 * При повторном распространении двоичного кода в документации и/или в
12 других материалах, поставляемых при распространении, должны сохраняться
13 указанная выше информация об авторском праве, этот список условий и
14 последующий отказ от гарантий.
15 * Ни название Cognitive Technologies, ни имена ее сотрудников не могут
16 быть использованы в качестве средства поддержки и/или продвижения
17 продуктов, основанных на этом ПО, без предварительного письменного
18 разрешения.
19
20 ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
21 ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
22 ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
23 ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
24 МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
25 НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
26 ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
27 НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
28 СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
29 ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
30 НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
31 ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.
32
33 Redistribution and use in source and binary forms, with or without modification,
34 are permitted provided that the following conditions are met:
35
36 * Redistributions of source code must retain the above copyright notice,
37 this list of conditions and the following disclaimer.
38 * Redistributions in binary form must reproduce the above copyright notice,
39 this list of conditions and the following disclaimer in the documentation
40 and/or other materials provided with the distribution.
41 * Neither the name of the Cognitive Technologies nor the names of its
42 contributors may be used to endorse or promote products derived from this
43 software without specific prior written permission.
44
45 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */
56
57 #ifndef __EDP__
58 #define __EDP__
59
60 #define RTF_DEBUG 0 // 0-off, 1-print, 2-additional lines to ED
61 #include "cttypes.h"
62 #include "edfile.h"
63 #include "msgerr.h"
64 #include <stdlib.h>
65
66 //*****************************************************************************
67 #define NATURAL uint
68 #define GOOD_PROB 70
69
70 /* Scan codes for keyboard */
71 #define BACK_SPACE 0x0e
72 #define ENTER 0x1c
73 #define ESCAPE 0x01
74 #define UP_ARROW 0x48
75 #define LEFT_ARROW 0x4b
76 #define RIGHT_ARROW 0x4d
77 #define DOWN_ARROW 0x50
78 #define INS 0x52
79 #define F1 0x3b
80 #define F2 0x3c
81 #define F3 0x3d
82 #define F4 0x3e
83 #define F5 0x3f
84 #define ALT_X 0x2d
85
86 typedef struct sheet_disk_descr SDD; // Header of ED-file
87 typedef struct fragm_disk_descr FDD; // Fragment descriptor in header of file
88 typedef struct fragm_disk FD; // Begin-of-fragment record
89 typedef struct line_beg LB; // Begin_of_line record
90 typedef struct bit_map_ref BMR; // Bitmap reference record
91
92 //*****************************************************************************
93 // Part descriptor
94 typedef struct d_dp {
95 uchar type;
96 #define VERT 0x01 // vertical splitting
97 #define HOR 0x02 // horisontal splitting
98 #define NONSP 0x04 // nonsplittable part
99 #define TERM 0x08 // terminal part
100 #define NEW 0x20 // not yet splitted
101 #define NONREST 0x40 // not yet restructed
102 int16_t x, w, y, h; // coordinates and sizes
103 struct d_dp *parent; // encompassing part
104 struct d_dp *next; // next and previsious parts
105 struct d_dp *prev; // of the same level
106 struct d_dp *first; // first and last subparts
107 struct d_dp *last; // (if not terminal)
108 int16_t npart; // number of subparts
109 struct d_df *fr1; // first fragment
110 struct d_df *fr2; // next of last fragment
111 int16_t nfrag; // number of fragments;
112 } DP;
113
114 //*****************************************************************************
115 // Fragment descriptor in memory
116 typedef struct d_df {
117 struct d_df* next; // Next fragment in the chain
118 struct d_df* prev; // Prev fragment in the chain
119 int16_t x, w; // Horizontal position of alignement borders in TIF
120 int16_t y, h; // Vertical position
121 FDD* fdd; // FDD address
122 struct d_dl* line1; // First line address
123 struct d_dl* line2; // Last line address
124 struct d_dp* part; // Terminal part adress
125 int16_t num; // Number of fragment givet automatically
126 int16_t user_num; // Number of fragment given by user
127 int16_t lplain; // Width of fragment in ED text mode
128 uint16_t type;
129 #define ONE_LINE 0x0001
130 #define LEFT_ALLIGN 0x0002
131 #define RIGHT_ALLIGN 0x0004
132 #define CENTER 0x0008
133 #define POS_INDENT 0x0010
134 #define NEG_INDENT 0x0020
135 #define BULLET 0x0040
136 #define POESY 0x0080
137 #define LN_SPACE 0x0100
138 #define NOT_RECOG 0x0200
139 #define BORDER 0x0400
140 #define BRACKET 0x8000
141 #define MCOL_BEG (BRACKET|0x1000)
142 #define NEW_COL (BRACKET|0x2000)
143 #define MCOL_END (BRACKET|0x3000)
144 #define TAB_BEG (BRACKET|0x4000)
145 #define NEW_ROW (BRACKET|0x5000)
146 #define DEL (NOT_RECOG|BORDER)
147 #define FICT_FR_FLAGS (BORDER|BRACKET)
148
149 int16_t base; // Regular margin from 'x'
150 int16_t xmin; // Calculated minimum x-coord for fragment
151 struct d_df *rel_fr; // for centered fragment - centered parent
152 // TAB_BEG - list of cells sizes (x,w)
153 int16_t pnum; // if TAB_BEG | MCOL_BEG - number of cells/columns
154 } DF;
155
156 #define fict_fr(a) (a->type & (FICT_FR_FLAGS))
157
158 // Line descriptor
159 typedef struct d_dl {
160 struct d_dl*next; // Adress of the next line in the column
161 struct d_dl*prev; // Adress of the prev line in the column
162 int16_t baseline; // 3d baseline position (ideal)
163 int16_t upper; // Upper boundary of the line
164 uchar height; // Height beetween 2nd and 3rd baselines
165 uchar pitch; // Pitch - number of plain characters per inch or 0.
166 int16_t x, w; // Horizontal position
167 uchar paragraph;
168 #define ORD_LN 0
169 #define NEW_PAR 0x1 // new paragraph
170 #define BUL_PAR 0x2 // paragraph with bullet
171 int16_t indent; // size of indent (only if paragraph)
172 int16_t bulind; // size of bullet indent (only if bullet)
173 uint16_t type; // 0 for deleted line
174 #define DL_HUGE_XW 0x1 // XW changed due to huge letter
175 #define DL_HUGE 0x2 // Huge letter
176 #define DL_ASSEMBLY 0x4 // Line assembled from pieces
177 #define DL_SINGLE 0x8 // Single-letter line
178 uchar* edbeg; // Address of the ED-text
179 int16_t edlth; // It's length
180 int16_t npieces; // Number of original pieces within line - 1
181 int16_t lplain; // Number of print characters including spaces
182 } DL;
183
184 // RTF segment header
185 // typedef struct d_seg
186 // {
187 // void* next; // Next segment
188 // void* begtext; // Begin of used space in the segment
189 // void* endtext; // End of used space in the segment
190 // int16_t flag;
191 // #define SEG_MALLOC 1 // Segment was created by malloc
192 // } SEG;
193
194 struct line_ref {
195 struct line_ref * next;
196 struct line_ref * prev;
197 DF * frag;
198 DL * line;
199 int16_t finy;
200 int16_t x;
201 uint16_t width;
202 uint16_t indent;
203 uint16_t base;
204 uchar flag;
205 uint16_t type; // Copy of fragment's type
206 uchar paragraph;
207 uchar res[3];
208 };
209 typedef struct line_ref LREF;
210
211 //*****************************************************************************
212 typedef struct {
213 int16_t dpi; // Resolution of scanner in dots per inch
214 int16_t turn; // Turn of page: turn=(xideal-xreal)/yreal*2048=
215 // =(yreal-yideal)/xreal*2048
216 // Symbol substitutions
217 char subst_bad; // Subst. for not recognized character
218 char subst_dash[3]; // Subst. for dash
219
220 // E D
221 int16_t edfile; // ED-file handle
222 uchar *edbeg; // Begin address of the ED file
223 uchar *edcur; // Current address in the ED-file
224 uchar *edfree; // End ptr to ED-file
225 SDD* psdd; // ED header
226 int16_t font; // Font properties as in ED struct font_kegle
227
228 #define FONT_SERIFIC 1
229 #define FONT_HELVETIC 2
230 #define FONT_BOLD 4
231 #define FONT_LIGHT 8
232 #define FONT_ITALIC 16
233 #define FONT_STRAIGHT 32
234 #define FONT_UNDERLINE 64
235
236 // Parts
237 DP* part; // Table of parts
238
239 // Fragments
240 DF* frag; // Table of fragments
241 DF* pf; // Current frag address
242 int16_t nf; // It's number
243 int16_t nfrag; // No of fragments
244
245 // Lines
246 DL* line; // Table of lines
247 DL* pl; // Current line desc address
248 int16_t nl; // It's number
249 int16_t qlines; // No of lines
250
251 // Graph of fragments
252 int16_t* graph; // Array of exits
253 int16_t qgr; // No of used elements in array
254
255
256 // Debug
257 int16_t debug; // 1-debug activated
258 FILE *prt; // Debug print file
259
260 // External memory pool
261 uchar *begfree;
262 uchar *endfree;
263
264 // Control of dynamic memory taken by malloc's
265 uint32_t dynmem_size; // Total count of dynamic memory size
266 int16_t tables_in_dynamic_memory; // Flag =1 if tables are in dynamic mem
267 int16_t ed_in_dynamic_memory; // Flag =1 if ED is in dynalic memory
268
269
270 // Follow coordinates in TIFF
271 uint16_t page_pix_width; // page width in pixels
272 uint16_t page_width; // page width in twips
273 uint16_t column_width; // current column width
274 uint16_t column_width_save; // column width saved
275 uint16_t columns_quant; // number of columns
276
277 // Tables support
278 PWORD cells_w; // cell widthes array
279 PWORD cells_x; // x of cells
280 PWORD cells_g; // gaps of cells
281 uint16_t cells_quant; // number of cells
282 uint16_t current_cell; // current cell number
283 uchar section_fill; // non empty section flag
284 uchar table_flag; // table flag
285
286 // ED save working area
287 int16_t Xmin; // Minimal left coordinate of all fragments
288 int16_t Xmax; // Maximal right coordinate of all fragments
289 PWORD char_tab; // Tabulation table pointer
290 DF ** sort_frag; // List of sorted by upper fragment
291 uint16_t cn; // Local fragment counter for sortlist
292 int16_t cy; // Current 'y' for plank
293 int16_t finy; // Minimal of rows to finish active lines
294 LREF * cfirst; // First fictive element in lines chain
295 LREF * clast; // Last fictive element in lines chain
296 LREF * cfree; // Free lines reference chain start
297 LREF * collect; // Pointer to collect line
298
299 // Line RTF buffer uses memory for graph during scan of ED file
300 uchar *rtfbeg; // Address of buffer= address of graph
301 uchar *rtfcur; // Pointer to free space in the buffer
302 int32_t rtflth; // Length of text in buffer
303 uchar *rtffree;
304 uchar *rtfend;
305 uchar rtfspec;
306 uchar rtflchar;
307 puchar rtf_hugep;
308 uchar rtf_hugelist[2];
309 #define RTF_LINE_BUF_SIZE sizeof(L.graph)
310
311 puchar hyp_buff; // Pointer to hyphination buffer start
312 puchar hyp_ptr; // Pointer to current place in that buffer
313 puchar hyp_in_rtf; // Pointer to defis in RTF file if it is last in a string
314 puchar hyp_last; // Pointer to last defis in RTF file
315 puchar hyp_line_start; // Pointer to first character of a line in RTF file
316
317
318 } dL;
319 //*****************************************************************************
320
321 int16_t ed_scan(Bool(*func_spec)(puchar p, int16_t lth), Bool(*func_char)(puchar p,
322 int16_t lth), puchar start, puchar end);
323
324 #if RTF_DEBUG!=0
325 #define PGM " "
326 #define MSG(s) if(L.debug)fprintf(L.prt,"\n" PGM s)
327 #define MSG2(s1,s2) if(L.debug)fprintf(L.prt,"\n" PGM s1,s2)
328 #define MSG3(s1,s2,s3) if(L.debug)fprintf(L.prt,"\n" PGM s1,s2,s3)
329 #define MSG4(s1,s2,s3,s4) if(L.debug)fprintf(L.prt,"\n" PGM s1,s2,s3,s4)
330 #define MSG5(s1,s2,s3,s4,s5) if(L.debug)fprintf(L.prt,"\n" PGM s1,s2,s3,s4,s5)
331 #else
332 #define MSG(s) /* */
333 #define MSG2(s1,s2) /* */
334 #define MSG3(s1,s2,s3) /* */
335 #define MSG4(s1,s2,s3,s4) /* */
336 #define MSG5(s1,s2,s3,s4,s5) /* */
337 #endif
338 //*****************************************************************************
339 #define msg_6_1 "RTF: Open error in RTF-file."
340 #define msg_6_2 "RTF: Write error in RTF-file."
341 #define msg_6_3 "RTF: Out of memory." /**/
342 #define msg_6_4 ""
343 #define msg_6_5 "RTF: Open error in ED-file."
344 #define msg_6_6 "RTF: Read error in ED-file." /**/
345 #define msg_6_7 "RTF: Incorect length of ED-file header."
346 #define msg_6_8 "RTF: Too many lines."
347 #define msg_6_9 "RTF: ED-file is corrupted."
348 #define msg_6_10 "RTF: Too long line."
349 #define msg_6_11 "RTF: Write error in ED-file."
350 #define msg_6_12 "RTF: Too many fragments."
351 #define msg_6_13 "RTF: More fragments in ED-file than shown in header."
352 #define msg_6_14 "RTF: Duplicated fragment in table."
353
354 #endif