| 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 |
/* |
| 58 |
ЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫ |
| 59 |
ЫЫ ЫЫ |
| 60 |
ЫЫ Copyright (C) 1990 Cognitive Technology Corporation. ЫЫ |
| 61 |
ЫЫ All rights reserved. This program is proprietary and ЫЫ |
| 62 |
ЫЫ a trade secret of Cognitive Technology Corporation. ЫЫ |
| 63 |
ЫЫ ЫЫ |
| 64 |
ЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫ |
| 65 |
*/ |
| 66 |
|
| 67 |
/**************************************************************************** |
| 68 |
* * |
| 69 |
* * |
| 70 |
* P A G E L A Y O U T * |
| 71 |
* * |
| 72 |
* Written in 1991 by Yuri Panchul * |
| 73 |
* * |
| 74 |
* LAYOUT.H - the header file * |
| 75 |
* * |
| 76 |
***************************************************************************/ |
| 77 |
|
| 78 |
# ifndef __LAYOUT_H_INCLUDE |
| 79 |
# define __LAYOUT_H_INCLUDE |
| 80 |
|
| 81 |
# include "ltconfig.h" |
| 82 |
# include "c_types.h" |
| 83 |
# include "lterrors.h" |
| 84 |
# include "roots.h" |
| 85 |
# include "madebug.h" |
| 86 |
# include "struct.h" |
| 87 |
|
| 88 |
#include "picture.h" |
| 89 |
#include "ctp.h" |
| 90 |
#include "ccom.h" |
| 91 |
|
| 92 |
void q_sort( char *, size_t, size_t, |
| 93 |
int (*)( const void *, const void * ) ); |
| 94 |
|
| 95 |
# ifdef LT_STAND_ALONE |
| 96 |
# define DEFAULT_ROOTS_FILENAME "a.rts" |
| 97 |
# endif |
| 98 |
|
| 99 |
# define APPEND_TO_DUMP { \ |
| 100 |
FILE *f = fopen ("aaa", "a"); \ |
| 101 |
fprintf (f, "%s: %d\n", __FILE__, __LINE__); \ |
| 102 |
fclose (f); \ |
| 103 |
} |
| 104 |
|
| 105 |
/**************************************************************************** |
| 106 |
* Common structures * |
| 107 |
***************************************************************************/ |
| 108 |
|
| 109 |
typedef struct |
| 110 |
{ |
| 111 |
int x; |
| 112 |
int y; |
| 113 |
} LPOINT; |
| 114 |
|
| 115 |
typedef struct |
| 116 |
{ |
| 117 |
int xLeft; |
| 118 |
int yTop; |
| 119 |
int xRight; |
| 120 |
int yBottom; |
| 121 |
} RECTANGLE; |
| 122 |
|
| 123 |
# define EXCHANGE_INTS(a, b) { int temp; temp = a; a = b; b = temp; } |
| 124 |
|
| 125 |
/**************************************************************************** |
| 126 |
* Declarations * |
| 127 |
***************************************************************************/ |
| 128 |
|
| 129 |
struct _RootStrip; |
| 130 |
typedef struct _RootStrip ROOT_STRIP; |
| 131 |
|
| 132 |
struct _Component; |
| 133 |
typedef struct _Component COMP; |
| 134 |
|
| 135 |
struct _Interval; |
| 136 |
typedef struct _Interval INTERVAL; |
| 137 |
|
| 138 |
struct _Strip; |
| 139 |
typedef struct _Strip STRIP; |
| 140 |
|
| 141 |
struct _Separator; |
| 142 |
typedef struct _Separator SEPARATOR; |
| 143 |
|
| 144 |
struct _Block; |
| 145 |
typedef struct _Block BLOCK; |
| 146 |
|
| 147 |
struct _RootBackup; |
| 148 |
typedef struct _RootBackup ROOT_BACKUP; |
| 149 |
|
| 150 |
struct _BackupCopy; |
| 151 |
typedef struct _BackupCopy BACKUP_COPY; |
| 152 |
|
| 153 |
|
| 154 |
/**************************************************************************** |
| 155 |
* Working with roots * |
| 156 |
***************************************************************************/ |
| 157 |
|
| 158 |
struct _RootStrip |
| 159 |
{ |
| 160 |
ROOT *pBegin; |
| 161 |
ROOT *pEnd; |
| 162 |
}; |
| 163 |
|
| 164 |
extern ROOT_STRIP *pRootStrips; |
| 165 |
extern int nRootStrips; |
| 166 |
|
| 167 |
extern int nRootStripsStep; |
| 168 |
extern int nRootStripsOffset; |
| 169 |
|
| 170 |
# ifdef LT_STAND_ALONE |
| 171 |
Bool RootsLoadFile (char * pFilename); |
| 172 |
# endif |
| 173 |
void CalculatePageParameters (void); |
| 174 |
|
| 175 |
void RootStripsCalculate (void); |
| 176 |
void RootStripsGetLoopParameters |
| 177 |
(int yTop, int yBottom, ROOT **ppBegin, ROOT **ppAfter); |
| 178 |
|
| 179 |
void RootsRemoveFromRulers (void); |
| 180 |
|
| 181 |
void RootsSaveNonLayoutData (void); |
| 182 |
void RootsRestoreNonLayoutData_ForDustAndRemoved (void); |
| 183 |
void RootsRestoreNonLayoutData_ForBlock (BLOCK *p); |
| 184 |
void RootsRestoreNonLayoutData (void); |
| 185 |
|
| 186 |
void RootsFreeData (void); |
| 187 |
|
| 188 |
extern int nRootSpaceWidth; |
| 189 |
extern int nRootSpaceHeight; |
| 190 |
extern RECTANGLE rRootSpace; |
| 191 |
|
| 192 |
/**************************************************************************** |
| 193 |
* Inclines accounting * |
| 194 |
***************************************************************************/ |
| 195 |
|
| 196 |
# define INCLINE_FACTOR 2048 |
| 197 |
|
| 198 |
extern int *pnHeightesCounter; |
| 199 |
extern int nHeightesAllocated; |
| 200 |
extern int nHeightes; |
| 201 |
|
| 202 |
extern int16_t nIncline; |
| 203 |
|
| 204 |
Bool InclinesAccount (void); |
| 205 |
void InclinesFreeData (void); |
| 206 |
|
| 207 |
void IdealXY (int16_t x, int16_t y, int16_t *px, int16_t *py); |
| 208 |
void RealXY (int16_t x, int16_t y, int16_t *px, int16_t *py); |
| 209 |
|
| 210 |
void RotatePageToIdeal (void); |
| 211 |
|
| 212 |
// пересчет координат с учетом наклона |
| 213 |
# define IDEAL_XY(x, y) \ |
| 214 |
{\ |
| 215 |
y = (int16_t) (y - (int32_t) x * nIncline / INCLINE_FACTOR);\ |
| 216 |
x = (int16_t) (x + (int32_t) y * nIncline / INCLINE_FACTOR);\ |
| 217 |
} |
| 218 |
|
| 219 |
// возврат к настоящим координатам |
| 220 |
# define REAL_XY(x, y) \ |
| 221 |
{\ |
| 222 |
x = (int16_t) (x - (int32_t) y * nIncline / INCLINE_FACTOR);\ |
| 223 |
y = (int16_t) (y + (int32_t) x * nIncline / INCLINE_FACTOR);\ |
| 224 |
} |
| 225 |
|
| 226 |
/**************************************************************************** |
| 227 |
**************************************************************************** |
| 228 |
** ** |
| 229 |
** ComponentsExtracting ** |
| 230 |
** ** |
| 231 |
**************************************************************************** |
| 232 |
***************************************************************************/ |
| 233 |
|
| 234 |
/**************************************************************************** |
| 235 |
* Intervals * |
| 236 |
***************************************************************************/ |
| 237 |
|
| 238 |
struct _Interval |
| 239 |
{ |
| 240 |
int xBegin; |
| 241 |
int xEnd; |
| 242 |
COMP *pComp; |
| 243 |
}; |
| 244 |
|
| 245 |
extern INTERVAL *pIntervals; |
| 246 |
extern int nIntervals; |
| 247 |
|
| 248 |
extern INTERVAL *pPrevIntervals; |
| 249 |
extern int nPrevIntervals; |
| 250 |
|
| 251 |
void IntervalsInit (void); |
| 252 |
void IntervalsBuild (int y); |
| 253 |
void IntervalsStep (int y); |
| 254 |
void IntervalsFreeData (void); |
| 255 |
|
| 256 |
/**************************************************************************** |
| 257 |
* Strips * |
| 258 |
***************************************************************************/ |
| 259 |
|
| 260 |
struct _Strip |
| 261 |
{ |
| 262 |
STRIP *pNext; |
| 263 |
|
| 264 |
int y; |
| 265 |
int xBegin; |
| 266 |
int xEnd; |
| 267 |
}; |
| 268 |
|
| 269 |
# define STRIPS_POOL_FIRST_ALLOCATION 1000 |
| 270 |
# define STRIPS_POOL_ALLOCATION_QUANTUM 500 |
| 271 |
|
| 272 |
extern STRIP *pStripsPool; |
| 273 |
extern int nStripsPoolLength; |
| 274 |
extern STRIP *pFreeStripsList; |
| 275 |
|
| 276 |
STRIP *StripNew (void); |
| 277 |
void StripDelete (STRIP *pStrip); |
| 278 |
|
| 279 |
/**************************************************************************** |
| 280 |
* Components * |
| 281 |
***************************************************************************/ |
| 282 |
|
| 283 |
// прямоугольник + площадь (+ номер); образуют список |
| 284 |
struct _Component // equal to COMP |
| 285 |
{ |
| 286 |
COMP *pNext; |
| 287 |
COMP *pPrev; |
| 288 |
|
| 289 |
int Number; |
| 290 |
|
| 291 |
int xLeft; |
| 292 |
int yTop; |
| 293 |
int xRight; |
| 294 |
int yBottom; |
| 295 |
Bool bRectangleAccounted; |
| 296 |
|
| 297 |
STRIP *pStripsListBegin; |
| 298 |
STRIP *pStripsListEnd; |
| 299 |
|
| 300 |
int nSquare; |
| 301 |
}; |
| 302 |
|
| 303 |
# define COMPS_POOL_FIRST_ALLOCATION 100 |
| 304 |
# define COMPS_POOL_ALLOCATION_QUANTUM 50 |
| 305 |
|
| 306 |
extern COMP *pCompsPool; |
| 307 |
extern int nCompsPoolLength; |
| 308 |
extern COMP *pFreeCompsList; |
| 309 |
|
| 310 |
extern COMP *pCompsList; |
| 311 |
|
| 312 |
COMP *CompNew (void); |
| 313 |
void CompDelete (COMP *pComp); |
| 314 |
void CompAddInterval (COMP *pComp, int y, INTERVAL *pInterval); |
| 315 |
void CompsConnect (COMP *pComp1, COMP *pComp2); |
| 316 |
void CompOR_Matrix (COMP *pComp, int Mask); |
| 317 |
void CompAND_Matrix (COMP *pComp, int Mask); |
| 318 |
|
| 319 |
void CompsBuild |
| 320 |
( |
| 321 |
uchar *pMatrix, |
| 322 |
int nWidth, |
| 323 |
int nHeight, |
| 324 |
int nSize, |
| 325 |
int BlackMask |
| 326 |
); |
| 327 |
|
| 328 |
void CompsFreeData (void); |
| 329 |
|
| 330 |
/**************************************************************************** |
| 331 |
**************************************************************************** |
| 332 |
** ** |
| 333 |
** Initial Breaking ** |
| 334 |
** ** |
| 335 |
**************************************************************************** |
| 336 |
***************************************************************************/ |
| 337 |
|
| 338 |
/**************************************************************************** |
| 339 |
* PageMatrix * |
| 340 |
***************************************************************************/ |
| 341 |
|
| 342 |
# define PMC_NULL 0 |
| 343 |
# define PMC_ROOT 1 |
| 344 |
# define PMC_DUST 2 |
| 345 |
# define PMC_PICTURE 4 |
| 346 |
|
| 347 |
# define PMC_DEBUG1 8 |
| 348 |
# define PMC_DEBUG2 16 |
| 349 |
|
| 350 |
# define PMC_FLAGS_MASK (PMC_ROOT | PMC_DUST | PMC_PICTURE) |
| 351 |
|
| 352 |
#ifdef HUGE_IMAGE |
| 353 |
# define PAGE_MATRIX_WIDTH 1024 // 512 |
| 354 |
# define PAGE_MATRIX_WIDTH_SHIFT 10 // 9 |
| 355 |
# define PAGE_MATRIX_HEIGHT 1024 |
| 356 |
|
| 357 |
# define PAGE_MATRIX_SIZE (1024*1024) // 512 |
| 358 |
#else |
| 359 |
# define PAGE_MATRIX_WIDTH 256 |
| 360 |
# define PAGE_MATRIX_WIDTH_SHIFT 8 |
| 361 |
# define PAGE_MATRIX_HEIGHT 256 |
| 362 |
|
| 363 |
# define PAGE_MATRIX_SIZE 65536 |
| 364 |
#endif |
| 365 |
/* (PAGE_MATRIX_WIDTH * PAGE_MATRIX_HEIGHT) */ |
| 366 |
|
| 367 |
# define PAGE_COMP_SHIFT 4 |
| 368 |
# define PAGE_COMP_FACTOR (1 << PAGE_COMP_SHIFT) |
| 369 |
# define PAGE_COMP_MASK (~((~0 >> PAGE_COMP_SHIFT) << PAGE_COMP_SHIFT)) |
| 370 |
# define XY_COMPRESS(x) \ |
| 371 |
((x) < 0 ? -(-(x) >> PAGE_COMP_SHIFT) : (x) >> PAGE_COMP_SHIFT) |
| 372 |
# define XY_UNCOMPRESS(x) \ |
| 373 |
((x) < 0 ? -(-(x) << PAGE_COMP_SHIFT) : (x) << PAGE_COMP_SHIFT) |
| 374 |
|
| 375 |
# define PAGE_MATRIX_REAL_WIDTH (PAGE_MATRIX_WIDTH << PAGE_COMP_SHIFT) |
| 376 |
# define PAGE_MATRIX_REAL_HEIGHT (PAGE_MATRIX_HEIGHT << PAGE_COMP_SHIFT) |
| 377 |
|
| 378 |
extern uchar *PageMatrix; /* [PAGE_MATRIX_SIZE] */ |
| 379 |
extern Bool bPageMatrixInitialized; |
| 380 |
|
| 381 |
void PageMatrixInit (int nWidth, int nHeight); |
| 382 |
void SpecCompPut (MN *mn); |
| 383 |
void PageMatrixPutRoots (void); |
| 384 |
void PageMatrixHorzGlue (void); |
| 385 |
void PageMatrixVertGlue (void); |
| 386 |
void PageMatrixExcludeIntersections (void); |
| 387 |
void PageMatrixBuild (void); |
| 388 |
void PageMatrixPutSeparators (Bool bConvertToRealCoords); |
| 389 |
void PageMatrixExcludeSeparators (Bool bConvertToRealCoords); |
| 390 |
uchar PageMatrixFlagsByIdealXY (int xIdeal, int yIdeal); |
| 391 |
void PageMatrixFreeData (void); |
| 392 |
|
| 393 |
# define PAGE_MATRIX_MARK_SHIFT 3 |
| 394 |
# define COMP_SERIES_LENGTH 7 |
| 395 |
|
| 396 |
void InitialBreakingProceed (void); |
| 397 |
void InitialBreakingFreeData (void); |
| 398 |
|
| 399 |
/**************************************************************************** |
| 400 |
* Working with separators * |
| 401 |
***************************************************************************/ |
| 402 |
|
| 403 |
# define SEP_NULL 0 |
| 404 |
# define SEP_VERT 1 |
| 405 |
# define SEP_HORZ 2 |
| 406 |
# define SEP_RECT 3 |
| 407 |
|
| 408 |
# define SEPF_NULL 0 |
| 409 |
# define SEPF_IS_PART 1 |
| 410 |
|
| 411 |
struct _Separator |
| 412 |
{ |
| 413 |
int Type; |
| 414 |
unsigned uFlags; |
| 415 |
int xBegin; |
| 416 |
int yBegin; |
| 417 |
int xEnd; |
| 418 |
int yEnd; |
| 419 |
int nWidth; |
| 420 |
}; |
| 421 |
|
| 422 |
extern SEPARATOR *pSeps; |
| 423 |
extern int nSeps; |
| 424 |
|
| 425 |
void SeparatorsGet (void); |
| 426 |
void SeparatorsFreeData (void); |
| 427 |
|
| 428 |
/**************************************************************************** |
| 429 |
* Working with blocks * |
| 430 |
***************************************************************************/ |
| 431 |
|
| 432 |
/* Block type */ |
| 433 |
|
| 434 |
# define BLOCK_NULL 0 |
| 435 |
# define BLOCK_TEXT 1 |
| 436 |
# define BLOCK_HORZ_SEPARATOR 2 |
| 437 |
# define BLOCK_VERT_SEPARATOR 3 |
| 438 |
# define BLOCK_RECT_SEPARATOR 4 |
| 439 |
# define BLOCK_PICTURE 5 // Pit |
| 440 |
|
| 441 |
/* Block Flags */ |
| 442 |
|
| 443 |
# define BF_NULL 0 |
| 444 |
|
| 445 |
/* Internal flags */ |
| 446 |
|
| 447 |
# define BF_NOT_BREAK_BLOCK 0x1 |
| 448 |
# define BF_NOT_GLUE_BLOCK 0x2 |
| 449 |
# define BF_NOT_REMOVE_FRAME_LIKE_ROOTS 0x4 |
| 450 |
# define BF_INSERTED_INTO_EMBEDDING_LISTS 0x8 |
| 451 |
# define BF_INSERTED_INTO_LEFT_AND_RIGHT_LISTS 0x10 |
| 452 |
# define BF_INSERTED_INTO_TOP_AND_BOTTOM_LISTS 0x20 |
| 453 |
|
| 454 |
/* External flags */ |
| 455 |
|
| 456 |
# define BF_SMART_BREAKING_APPLIED 0x100 |
| 457 |
# define BF_WHITE_STRIPS_BREAKING_APPLIED 0x200 |
| 458 |
# define BF_GLUED_FROM_ONE_LINE_BLOCKS 0x400 |
| 459 |
# define BF_CROSSED 0x800 |
| 460 |
|
| 461 |
struct _Block |
| 462 |
{ |
| 463 |
BLOCK *pNext; |
| 464 |
BLOCK *pPrev; |
| 465 |
|
| 466 |
int16_t Type; |
| 467 |
unsigned uFlags; |
| 468 |
int nNumber; |
| 469 |
int nUserNum; // Number call of User ExractBlocks Piter 08-17-95 06:20pm |
| 470 |
//05-25-94 03:01pm,Pit |
| 471 |
uchar language; // на каком языке написано |
| 472 |
RECTANGLE Rect; |
| 473 |
|
| 474 |
int nEmbedding; |
| 475 |
BLOCK *pLowerEmbedding; |
| 476 |
BLOCK *pHigherEmbedding; |
| 477 |
|
| 478 |
BLOCK *pLeft; |
| 479 |
BLOCK *pRight; |
| 480 |
BLOCK *pUp; |
| 481 |
BLOCK *pDown; |
| 482 |
|
| 483 |
ROOT *pRoots; |
| 484 |
ROOT *pEndRoots; |
| 485 |
|
| 486 |
int nRoots; |
| 487 |
int nLetters; |
| 488 |
int nDust; |
| 489 |
int nHeightesSum; |
| 490 |
int nAverageHeight; // примерно (см. BlockSetAverageHeight()) -- |
| 491 |
// -- "средняя высота рута в блоке". |
| 492 |
int nParents; |
| 493 |
int nChildren; |
| 494 |
BLOCK *pParent; |
| 495 |
|
| 496 |
SEPARATOR *pUpSep; // Own block separators |
| 497 |
SEPARATOR *pDownSep; |
| 498 |
SEPARATOR *pLeftSep; |
| 499 |
SEPARATOR *pRightSep; |
| 500 |
|
| 501 |
int *pHorzHystogram; // (вертикальная) гистограмма для разделения |
| 502 |
// ПО ГОРИЗОНТАЛИ |
| 503 |
int nActualHeight; // судя по BlockHorzHystogramBuild() -- |
| 504 |
// /примерно/ равно (Rect.bottom - Rect.top) |
| 505 |
int nStartColumnWidth; // см. BlockCalculateBreakingParameters(); |
| 506 |
int nUnconditionalMinColumnWidth; // пока могу только сказать, |
| 507 |
int nConditionalMinColumnWidth; // что 1st>=2nd>=3rd (сверху вниз) |
| 508 |
|
| 509 |
int *pHystogram; // Hystogram for strings extraction |
| 510 |
int nHystColumns; |
| 511 |
int hPicture; // Pit. Описание картинки |
| 512 |
}; |
| 513 |
|
| 514 |
extern BLOCK *pBlocksList; |
| 515 |
extern BLOCK *pHighEmbeddingBlocksList; |
| 516 |
extern BLOCK *pLowEmbeddingBlocksList; |
| 517 |
extern BLOCK *pLeftBlocksList; |
| 518 |
extern BLOCK *pRightBlocksList; |
| 519 |
extern BLOCK *pTopBlocksList; |
| 520 |
extern BLOCK *pBottomBlocksList; |
| 521 |
extern int nNextBlockNumber; |
| 522 |
|
| 523 |
Bool RectEq (RECTANGLE *p, RECTANGLE *q); |
| 524 |
Bool RectIsCrossed (RECTANGLE *p, RECTANGLE *q); |
| 525 |
void RectAsgPlus (RECTANGLE *p, RECTANGLE *q); |
| 526 |
Bool RectIncludes (RECTANGLE *p, RECTANGLE *q); |
| 527 |
|
| 528 |
BLOCK *BlocksAddDescriptor (void); |
| 529 |
void BlocksRemoveDescriptor (BLOCK *p); |
| 530 |
void BlockAccountRoot (BLOCK *p, ROOT *pRoot); |
| 531 |
void BlockSetAverageHeight (BLOCK *p); |
| 532 |
void BlockCalculateBreakingParameters (BLOCK *p); |
| 533 |
void BlockReCalculateBreakingParameters (BLOCK *p); |
| 534 |
void BlockSetRootsNumbers (BLOCK *p); |
| 535 |
void BlocksSetRootsNumbers (void); |
| 536 |
void BlocksRestoreBreakedBlock (BLOCK *p, BLOCK *q, BLOCK *r); |
| 537 |
void BlockEnglish(BLOCK *p); // Pit 02-11-94 |
| 538 |
|
| 539 |
# ifdef LT_DEBUG |
| 540 |
void BlocksSetRandomRootsNumbers (void); |
| 541 |
# endif |
| 542 |
|
| 543 |
void BlockRenameRoots (BLOCK *p, int nBlock); |
| 544 |
void BlocksFreeData (void); |
| 545 |
void BlocksBuildEmbeddingLists (void); |
| 546 |
void BlocksBuildLeftAndRightLists (void); |
| 547 |
void BlocksBuildTopAndBottomLists (void); |
| 548 |
|
| 549 |
/**************************************************************************** |
| 550 |
* Hystogram * |
| 551 |
***************************************************************************/ |
| 552 |
|
| 553 |
extern int *pHystogram; |
| 554 |
extern int *pHystVertHeightesSum; |
| 555 |
extern int *pHystHorzHeightesSum; |
| 556 |
extern int *pHystInt1; |
| 557 |
extern int *pHystInt2; |
| 558 |
extern int *pHystTops; |
| 559 |
extern int *pHystBottoms; |
| 560 |
extern int nHystColumns; |
| 561 |
extern int nHystColumnWidth; |
| 562 |
|
| 563 |
Bool HystogramAllocateBody (void); |
| 564 |
void HystogramMakeIntegral (int *pInt, int *p, int nWidth); |
| 565 |
void HystogramFreeData (void); |
| 566 |
|
| 567 |
/**************************************************************************** |
| 568 |
**************************************************************************** |
| 569 |
** ** |
| 570 |
** SmartBreaking ** |
| 571 |
** ** |
| 572 |
**************************************************************************** |
| 573 |
***************************************************************************/ |
| 574 |
|
| 575 |
/**************************************************************************** |
| 576 |
* SmartBreaking matrix * |
| 577 |
***************************************************************************/ |
| 578 |
|
| 579 |
# define WHITE_CELL 0 |
| 580 |
# define BLACK_CELL 1 |
| 581 |
# define MARKED_CELL 2 |
| 582 |
# define SUSPICION_COMP_CELL 4 |
| 583 |
|
| 584 |
extern uchar *pSB_Matrix; |
| 585 |
extern int nSB_Width; |
| 586 |
extern int nSB_Height; |
| 587 |
extern int nSB_Size; |
| 588 |
extern int nSB_CellWidth; |
| 589 |
extern int nSB_CellHeight; |
| 590 |
|
| 591 |
# if defined (LT_DEBUG) || defined (SE_DEBUG) |
| 592 |
extern BLOCK *pSB_Block; |
| 593 |
# endif |
| 594 |
|
| 595 |
Bool SB_MatrixBuild (BLOCK *pBlock, int nCellWidth, int nCellHeight); |
| 596 |
void SB_MatrixFreeData (void); |
| 597 |
|
| 598 |
# define FCC_NOT_FOUND 0 |
| 599 |
# define FCC_FOUND 1 |
| 600 |
# define FCC_CANT_FOUND 2 |
| 601 |
# define FCC_FOUND_SUSPICION 3 |
| 602 |
|
| 603 |
int CompsFindCompToCut (COMP **ppResult); |
| 604 |
|
| 605 |
Bool TrySmartBreaking (BLOCK *pBlock); |
| 606 |
void SmartBreakingFreeData (void); |
| 607 |
|
| 608 |
/**************************************************************************** |
| 609 |
**************************************************************************** |
| 610 |
** ** |
| 611 |
** End of SmartBreaking ** |
| 612 |
** ** |
| 613 |
**************************************************************************** |
| 614 |
***************************************************************************/ |
| 615 |
|
| 616 |
/**************************************************************************** |
| 617 |
* * |
| 618 |
* White Strips Breaking * |
| 619 |
* * |
| 620 |
***************************************************************************/ |
| 621 |
|
| 622 |
typedef struct _WSB_Point |
| 623 |
{ |
| 624 |
int xBegin; |
| 625 |
int xMain; |
| 626 |
int xEnd; |
| 627 |
|
| 628 |
int yMin; |
| 629 |
int yMax; |
| 630 |
int yAverage; |
| 631 |
} WSB_POINT; |
| 632 |
|
| 633 |
extern int * pWSB_Hyst1; |
| 634 |
extern int * pWSB_Hyst2; |
| 635 |
extern int nWSB_HystColumns; |
| 636 |
extern int xWSB_HystOffset; |
| 637 |
|
| 638 |
# define WSB_POINTS_POOL_ALLOCATION_QUANTUM 32 |
| 639 |
|
| 640 |
extern WSB_POINT * pWSB_Points; |
| 641 |
extern int nWSB_Points; |
| 642 |
|
| 643 |
void WSB_BuildHystograms (void); |
| 644 |
void WSB_AddPoint (WSB_POINT Point); |
| 645 |
void WSB_BuildPoints (void); |
| 646 |
Bool WSB_BreakBlock (BLOCK * p, WSB_POINT Point); |
| 647 |
Bool WSB_CutUpperLine (BLOCK * p, WSB_POINT Point); |
| 648 |
void WhiteStripsBreaking (void); |
| 649 |
void WSB_FreeData (void); |
| 650 |
|
| 651 |
/**************************************************************************** |
| 652 |
* Graphics output * |
| 653 |
***************************************************************************/ |
| 654 |
|
| 655 |
# if defined (LT_DEBUG) || defined (SE_DEBUG) |
| 656 |
void LT_GraphicsOpen (void); |
| 657 |
void LT_GraphicsClearScreen (void); |
| 658 |
void LT_GraphicsTitle (const char *pTitle); |
| 659 |
int LT_Getch (void); |
| 660 |
|
| 661 |
void LT_GraphicsRootsOutput (const char *pTitle); |
| 662 |
void LT_GraphicsRootStripsOutput (char *pTitle); |
| 663 |
void LT_GraphicsPageMatrixOutput (char *pTitle); |
| 664 |
void LT_GraphicsBlocksOutput (const char *pTitle); |
| 665 |
void LT_GraphicsHystogramOutput (const char *pTitle); |
| 666 |
void LT_GraphicsSpecialCuttingOutput (char *pTitle); |
| 667 |
void LT_GraphicsSB_MatrixOutput (char *pTitle); |
| 668 |
void LT_GraphicsWSB_Hystogram_1_Output (char *pTitle); |
| 669 |
void LT_GraphicsWSB_Hystogram_2_Output (char *pTitle); |
| 670 |
void LT_GraphicsWSB_PointsOutput (char *pTitle); |
| 671 |
void LT_GraphicsPictureRemovingConditionsOutput (char * pTitle); |
| 672 |
void LT_GraphicsDD_RemovingConditionsOutput (char * pTitle); |
| 673 |
void LT_GraphicsTreeOutput (char *pTitle); |
| 674 |
void LT_GraphicsHighEmbeddingBlocksListOutput (char *pTitle); |
| 675 |
void LT_GraphicsLowEmbeddingBlocksListOutput (char *pTitle); |
| 676 |
void LT_GraphicsLeftBlocksListOutput (char *pTitle); |
| 677 |
void LT_GraphicsRightBlocksListOutput (char *pTitle); |
| 678 |
void LT_GraphicsTopBlocksListOutput (char *pTitle); |
| 679 |
void LT_GraphicsBottomBlocksListOutput (char *pTitle); |
| 680 |
void LT_GraphicsBlocksOrderOutput (char *pTitle); |
| 681 |
void LT_GraphicsCurrentStringOutput (const char *pTitle); |
| 682 |
void LT_GraphicsStringsOutput (const char *pTitle); |
| 683 |
void LT_GraphicsStringsForwardOrderOutput (const char *pTitle); |
| 684 |
void LT_GraphicsStringsBackwardOrderOutput (const char *pTitle); |
| 685 |
void LT_GraphicsStringsUpOrderOutput (const char *pTitle); |
| 686 |
void LT_GraphicsStringsDownOrderOutput (const char *pTitle); |
| 687 |
void LT_GraphicsRasterOutput (const char *pTitle); |
| 688 |
void LT_GraphicsBreakingOutput (const char *pTitle); |
| 689 |
void LT_ShowBlock(char *pTitle); |
| 690 |
|
| 691 |
void LT_GraphicsBlockOutput2 (char *pTitle); |
| 692 |
|
| 693 |
void LT_GraphicsPictureRemovingConditionsOutput2 (char *pTitle); |
| 694 |
void LT_GraphicsDD_RemovingConditionsOutput2 (char *pTitle); |
| 695 |
void LT_GraphicsLinearRemovingConditionsOutput2 (char *pTitle); |
| 696 |
void LT_GraphicsClose (void); |
| 697 |
|
| 698 |
extern BLOCK *pDebugBlock; |
| 699 |
extern RECTANGLE rDebugRect; |
| 700 |
extern int xDebugVertLine; |
| 701 |
# endif |
| 702 |
|
| 703 |
/**************************************************************************** |
| 704 |
* Blocks processing tools * |
| 705 |
***************************************************************************/ |
| 706 |
|
| 707 |
Bool BlockBreakOnVertical (BLOCK *p, BLOCK **pq, BLOCK **pr, |
| 708 |
int x, int nBreakingWidth); |
| 709 |
Bool BlockBreakOnHorizontal (BLOCK *p, BLOCK **pq, BLOCK **pr, |
| 710 |
int y); |
| 711 |
Bool BlockBreakByRectangle (BLOCK *p, BLOCK **pq, BLOCK **pr, |
| 712 |
int xBegin, int yBegin, int xEnd, int yEnd); |
| 713 |
BLOCK *BlocksGlueTwo (BLOCK *p, BLOCK *q); |
| 714 |
void BlockRemove (BLOCK *p); |
| 715 |
|
| 716 |
/**************************************************************************** |
| 717 |
* Layout backup / restore procedures * |
| 718 |
***************************************************************************/ |
| 719 |
#include "sheet.h" |
| 720 |
|
| 721 |
struct _RootBackup |
| 722 |
{ |
| 723 |
int16_t nBlock; |
| 724 |
ROOT *pNext; |
| 725 |
}; |
| 726 |
|
| 727 |
struct _BackupCopy |
| 728 |
{ |
| 729 |
BACKUP_COPY *pNext; |
| 730 |
BACKUP_COPY *pPrev; |
| 731 |
|
| 732 |
ROOT_BACKUP *pRootBackups; |
| 733 |
|
| 734 |
int nBlocks; |
| 735 |
BLOCK *pBlocks; |
| 736 |
|
| 737 |
long lPictures; // size of pictures buffer Pit 09-29-94 03:05pm |
| 738 |
puchar pPictures; // pictures buffer |
| 739 |
|
| 740 |
int nSheets; // зЁб«® в Ў«Ёж |
| 741 |
SHT *sht; // Ёе ®ЇЁб ⥫Ё |
| 742 |
}; |
| 743 |
|
| 744 |
extern BACKUP_COPY *pBC_First; |
| 745 |
extern BACKUP_COPY *pBC_Last; |
| 746 |
extern BACKUP_COPY *pBC_Current; |
| 747 |
extern int nBC_Copies; |
| 748 |
|
| 749 |
void LayoutBackup (void); |
| 750 |
void LayoutUndo (void); |
| 751 |
void LayoutRedo (void); |
| 752 |
void LayoutBackupFreeData (void); |
| 753 |
|
| 754 |
/**************************************************************************** |
| 755 |
* Hand layout functions * |
| 756 |
***************************************************************************/ |
| 757 |
|
| 758 |
void HandLayoutFreeData (void); |
| 759 |
|
| 760 |
/**************************************************************************** |
| 761 |
* Main subroutines * |
| 762 |
***************************************************************************/ |
| 763 |
|
| 764 |
void PageMatrixBuild (void); |
| 765 |
void InitialBreakingProceed (void); |
| 766 |
void BlocksExtract (void); |
| 767 |
void BlocksBreak (void); |
| 768 |
void BlocksGlue (void); |
| 769 |
void BlocksRemoveEmptyBlocks (void); |
| 770 |
void BlocksRemoveFrameLikeRoots (void); |
| 771 |
void BlocksAbsorbDust (void); |
| 772 |
void BlocksDisAbsorbBoundaryDust (void); |
| 773 |
void BlocksCutPageEdges (); |
| 774 |
void BlocksAddVirtualSeparatorsBlocks (void); |
| 775 |
void TreeBuild (void); |
| 776 |
void TreeEdit (void); |
| 777 |
void TreePass (void); |
| 778 |
|
| 779 |
void LT_FreeAllData (void); |
| 780 |
void LayoutPart1 (void); |
| 781 |
void LayoutPart2 (void); |
| 782 |
|
| 783 |
# ifdef LT_DEBUG |
| 784 |
extern Bool bDebugTimeFlag; |
| 785 |
extern int LT_DebugGraphicsLevel; |
| 786 |
extern Bool bDebugOptionCalibratePictureRemovingCriteria; |
| 787 |
extern Bool bDebugOptionCalibrateDD_RemovingCriteria; |
| 788 |
extern Bool bDebugOptionCalibrateLinearRemovingCriteria; |
| 789 |
# endif |
| 790 |
|
| 791 |
extern Bool bOptionForceOneColumn; |
| 792 |
extern Bool bOptionBusinessCardsLayout; |
| 793 |
|
| 794 |
extern Bool bOptionPointSizeAnalysis; |
| 795 |
extern Bool bOptionSmartBreaking; |
| 796 |
extern Bool bOptionInitialBreakingByPageMatrix; |
| 797 |
extern Bool bOptionBlocksRemovingByPageMatrix; |
| 798 |
extern Bool bOptionBlocksRemovingByDustDistribution; |
| 799 |
extern Bool bOptionSpecialHorizontalCutting; |
| 800 |
extern Bool bOptionWhiteStripsBreaking; |
| 801 |
|
| 802 |
|
| 803 |
//Bool AddRoot(CCOM_comp * comp);// Piter |
| 804 |
Bool AddRoot(CCOM_comp * comp, Bool32 FirstTime);// Roman |
| 805 |
|
| 806 |
# endif |
| 807 |
|