File: ltmain.c

package info (click to toggle)
cuneiform 1.1.0%2Bdfsg-12
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid, trixie
  • size: 72,320 kB
  • sloc: ansic: 183,512; cpp: 101,929; sh: 38; makefile: 36
file content (750 lines) | stat: -rw-r--r-- 22,552 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
/*
Copyright (c) 1993-2008, Cognitive Technologies
All rights reserved.

Разрешается повторное распространение и использование как в виде исходного кода,
так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:

      * При повторном распространении исходного кода должны оставаться указанное
        выше уведомление об авторском праве, этот список условий и последующий
        отказ от гарантий.
      * При повторном распространении двоичного кода в документации и/или в
        других материалах, поставляемых при распространении, должны сохраняться
        указанная выше информация об авторском праве, этот список условий и
        последующий отказ от гарантий.
      * Ни название Cognitive Technologies, ни имена ее сотрудников не могут
        быть использованы в качестве средства поддержки и/или продвижения
        продуктов, основанных на этом ПО, без предварительного письменного
        разрешения.

ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of the Cognitive Technologies nor the names of its
      contributors may be used to endorse or promote products derived from this
      software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/



/****************************************************************************
 *                                                                          *
 *                   P A G E   L A Y O U T                                  *
 *                                                                          *
 *              Written in 1991 by Yuri Panchul                             *
 *                                                                          *
 *              LTMAIN.C - the main routine                                 *
 *                                                                          *
 ***************************************************************************/

# include <stdio.h>
# include <string.h>
# include <time.h>

# include "iolib.h"
# include "layout.h"
# include "extract.h"
# include "kernel.h"
# include "status.h"

# include "dpuma.h"

//#define LT_DUMP 1
//#pragma message(__FILE__"(34): здесь закомментировать '#define LT_DUMP 1'")

extern uint16_t run_options;

/*********************************/
extern Handle hPageBeforeEditing ;
extern Handle hPageMatrix ;
extern Handle hInitialBreaking ;
extern Handle hInclineCalculating ;
//Handle hBlocksAfterFirstExtraction = NULL;
extern Handle hBlocksBreaking ;
extern Handle hBlocksGlueing ;
extern Handle hFirstDustAbsorbtion ;
extern Handle hRemoveEmptyBlocks ;
extern Handle hSecondDustAbsorbtion ;

Bool bOptionForceOneColumn      = FALSE;
Bool bOptionBusinessCardsLayout = FALSE;

Bool bOptionPointSizeAnalysis                = TRUE;
Bool bOptionSmartBreaking                    = TRUE;
Bool bOptionInitialBreakingByPageMatrix      = TRUE;
Bool bOptionBlocksRemovingByPageMatrix       = TRUE;
Bool bOptionBlocksRemovingByDustDistribution = TRUE;
Bool bOptionSpecialHorizontalCutting         = TRUE;
Bool bOptionWhiteStripsBreaking              = TRUE;

# ifdef LT_DEBUG
int  LT_DebugGraphicsLevel = 0;

Bool bDebugOptionCalibratePictureRemovingCriteria = FALSE;
Bool bDebugOptionCalibrateDD_RemovingCriteria     = FALSE;
Bool bDebugOptionCalibrateLinearRemovingCriteria  = FALSE;

Bool bDebugTimeFlag = FALSE;
static clock_t tTimeTotal;
# endif

# ifdef LT_STAND_ALONE
# ifdef LT_DEBUG
static char szQuickHelpText [] =
"usage: layout [-ght] [<roots_file>]\n";

static char szHelpText [] =
"Layout Version 1.0  - Stand-alone program for page layout debugging\n"
"Written in 1991 by Yuri Panchul\n"
"\n"
"Usage: layout [-ght] [<roots_file>]\n";
# else
static char szQuickHelpText [] =
"usage: layout [-h] [<roots_file>]\n";

static char szHelpText [] =
"Layout Version 1.0  - Stand-alone program for page layout debugging\n"
"Written in 1991 by Yuri Panchul\n"
"\n"
"Usage: layout [-h] [<roots_file>]\n";
# endif
# endif

# ifdef LT_STAND_ALONE
char szRootsFilename [100] = DEFAULT_ROOTS_FILENAME;
# endif




void LT_FreeAllData (void)
{
    WSB_FreeData ();
    SmartBreakingFreeData ();
    HystogramFreeData ();
    SeparatorsFreeData ();
    BlocksFreeData ();
    InitialBreakingFreeData ();
    PageMatrixFreeData ();
    CompsFreeData ();
    IntervalsFreeData ();
//    InclinesFreeData ();
    RootsFreeData ();

# ifdef LT_DEBUG
    LT_GraphicsClose ();
# endif

    LayoutBackupFreeData ();
}

# ifdef LT_DUMP
FILE *pfListing;
# endif

void PageLayoutPart1 (void)
{
int i;
i=0; i=i;
# ifdef MA_DEBUG
    AllocationsAccountingOpen ();
# endif

# ifdef LT_DUMP
    pfListing = fopen ("layout.dmp", "w");

    if (pfListing == NULL)
        ErrorInternal ("Can't open dump file");

    fprintf (pfListing, "nRoots: %d\n", (int) nRoots);

    {
        int i;

        for (i = 0; i < nRoots; i++)
        {
            fprintf (pfListing,
                "x: %4d, y: %4d, w: %4d, h: %4d, block: %4d/%4d [%4x %4x] %4x\n",
                (int) pRoots [i].xColumn,
                (int) pRoots [i].yRow,
                (int) pRoots [i].nWidth,
                (int) pRoots [i].nHeight,
                (int) pRoots [i].nBlock,
                (int) pRoots [i].nUserNum,
                0, //(int) pRoots [i].wSegmentPtr,
                0, //(int) pRoots [i].wLength);
                (int) pRoots [i].bType);
        }
    }
    fclose (pfListing);

# endif

    if (nRoots == 0)
        //ErrorInternal ("Page is empty");
		return;

    nNextBlockNumber = FIRST_REGULAR_BLOCK_NUMBER;

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel > 0)
	if( !LDPUMA_Skip (hPageBeforeEditing) ||
		!LDPUMA_Skip (hPageMatrix) ||
		!LDPUMA_Skip (hInitialBreaking) ||
		!LDPUMA_Skip (hInclineCalculating) ||
		!LDPUMA_Skip (hBlocksBreaking) ||
		!LDPUMA_Skip (hBlocksGlueing) ||
		!LDPUMA_Skip (hFirstDustAbsorbtion) ||
		!LDPUMA_Skip (hRemoveEmptyBlocks) ||
		!LDPUMA_Skip (hSecondDustAbsorbtion))
	{
        LT_GraphicsOpen ();
	}

    if (bDebugTimeFlag)
        tTimeTotal = clock ();
# endif

    RootsSaveNonLayoutData ();
    CalculatePageParameters ();
    SeparatorsGet ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
	if (!LDPUMA_Skip(hPageBeforeEditing))
        LT_GraphicsRootsOutput ("Page");
# endif

    if (bOptionInitialBreakingByPageMatrix ||
        bOptionBlocksRemovingByPageMatrix)
    {
        PageMatrixBuild ();
    }

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
	if (!LDPUMA_Skip(hPageMatrix))
        LT_GraphicsPageMatrixOutput ("Page matrix");
# endif

    // выделить в матрице страницы компоненты связности;
    // настроить в рутах поле nBlock на хранение этой
    // полезной информации; сами компоненты связности -- не хранятся.
    InitialBreakingProceed ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 3)
	if (!LDPUMA_Skip(hInitialBreaking))
        LT_GraphicsBlocksOutput ("Initial breaking");
# endif

//    InclinesAccount ();
    RotatePageToIdeal ();
//    InclinesFreeData ();
    RootStripsCalculate ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 3)
	if(!LDPUMA_Skip(hInclineCalculating))
    {
        LT_GraphicsRootsOutput ("Roots after page rotation");
        LT_GraphicsRootStripsOutput ("Root strips");
    }
# endif

    BlocksExtract ();
	//BlockAnalyse();
# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
    //    LT_GraphicsBlocksOutput ("Blocks after extraction.1");
# endif
 /*    Pit 09-27-94 03:42pm
    new_picture(3,5,300,500);
    del_picture(0);
    new_picture(300,500,100,100);

    BlocksExtract ();

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 2)
        LT_GraphicsBlocksOutput ("Blocks after extraction.2");
# endif
*/
    BlocksBreak ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
	if(!LDPUMA_Skip(hBlocksBreaking))
        LT_GraphicsBlocksOutput ("Blocks after breaking");
# endif

    BlocksAddVirtualSeparatorsBlocks ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
    //    LT_GraphicsBlocksOutput ("Blocks after adding separators");
# endif

    BlocksRemoveFrameLikeRoots ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
    //    LT_GraphicsBlocksOutput ("After removing frame like roots");
# endif

    BlocksGlue ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
	if(!LDPUMA_Skip(hBlocksGlueing))
        LT_GraphicsBlocksOutput ("Blocks after glueing");
# endif

    BlocksBuildEmbeddingLists ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 3)
    //{
    //    LT_GraphicsHighEmbeddingBlocksListOutput ("High embedding blocks list");
    //    LT_GraphicsLowEmbeddingBlocksListOutput  ("Low embedding blocks list");
    //}
# endif

    BlocksAbsorbDust ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
	if(!LDPUMA_Skip(hFirstDustAbsorbtion))
        LT_GraphicsBlocksOutput ("After first dust absorption");
# endif

    PageMatrixExcludeSeparators (TRUE);

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
    //    LT_GraphicsPageMatrixOutput ("Matrix after excluding separators");
# endif

    BlocksRemoveEmptyBlocks ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
	if(!LDPUMA_Skip(hRemoveEmptyBlocks))
        LT_GraphicsBlocksOutput ("After removing empty blocks");
# endif

    BlocksAbsorbDust ();
    BlocksDisAbsorbBoundaryDust ();

# ifdef LT_DEBUG
    //if (LT_DebugGraphicsLevel >= 2)
	if(!LDPUMA_Skip(hSecondDustAbsorbtion))
        LT_GraphicsBlocksOutput ("After second dust absorption");
# endif

    if (cut_page_left || cut_page_right)
    {
        BlocksCutPageEdges ();

# ifdef LT_DEBUG
     //   if (LT_DebugGraphicsLevel >= 2)
     //       LT_GraphicsBlocksOutput ("After BlocksCutPageEdges");
# endif
    }

    LayoutBackupFreeData ();
}

void PageLayoutPart2 (void)
{
    LayoutBackupFreeData ();

# ifdef LT_DUMP
    fprintf (pfListing, "Blocks:\n");

    {
        BLOCK *p;

        for (p = pBlocksList; p != NULL; p = p -> pNext)
            fprintf (pfListing,
                "[%d, %d]-[%d, %d] %d\n",
                (int) p -> Rect.xLeft,
                (int) p -> Rect.yTop,
                (int) p -> Rect.xRight,
                (int) p -> Rect.yBottom,
                (int) p -> Type);
    }
# endif

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 1)
        LT_GraphicsBlocksOutput ("Text blocks");
# endif

    BlocksBuildLeftAndRightLists ();

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 3)
    {
        LT_GraphicsLeftBlocksListOutput  ("Left blocks list");
        LT_GraphicsRightBlocksListOutput ("Right blocks list");
    }
# endif

    BlocksBuildTopAndBottomLists ();

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 3)
    {
        LT_GraphicsTopBlocksListOutput    ("Top blocks list");
        LT_GraphicsBottomBlocksListOutput ("Bottom blocks list");
    }
# endif

/******************************** ATAL 940414 Remove couple functions calls
    TreeBuild ();

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 3)
        LT_GraphicsTreeOutput ("Tree structure before edit");
# endif

    TreeEdit ();

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 2)
        LT_GraphicsTreeOutput ("Tree structure");
# endif
*************************************************/

    TreePass ();

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 2)
        LT_GraphicsBlocksOrderOutput ("Output blocks order");
# endif

    RootsRemoveFromRulers ();

# ifdef LT_DEBUG
    if (bDebugTimeFlag)
    {
//      printf ("\nLayout Time : %f\n",
//          (double) (clock () - tTimeTotal) / CLK_TCK);
    }
# endif

# ifdef LT_USE_STRINGS_EXTRACTION
    StringsExtract ();
# endif

    RootsRestoreNonLayoutData ();
    LT_FreeAllData ();

# ifdef LT_DEBUG
    if (bDebugTimeFlag)
    {
//      tTimeTotal = clock () - tTimeTotal;
//      printf ("\nLayout Time : %f\n", (double) tTimeTotal / CLK_TCK);
    }
# endif

# ifdef MA_DEBUG
    AllocationsAccountingClose ();
# endif

# ifdef LT_DUMP
    fprintf (pfListing, "\nAFTER LAYOUT:\n");
    fprintf (pfListing, "nRoots: %d\n", (int) nRoots);

    {
        int i;

        for (i = 0; i < nRoots; i++)
        {
            fprintf (pfListing,
                "x: %4d, y: %4d, w: %4d, h: %4d, block: %4d/%4d [%4x %4x]\n",
                (int) pRoots [i].xColumn,
                (int) pRoots [i].yRow,
                (int) pRoots [i].nWidth,
                (int) pRoots [i].nHeight,
                (int) pRoots [i].nBlock,
                (int) pRoots [i].nUserNum,
                0, //(int) pRoots [i].wSegmentPtr,
                0); //(int) pRoots [i].wLength);
        }
    }

    fclose (pfListing);
# endif
}

void PageStrings1 (void)
{
    int i;

# ifdef MA_DEBUG
    AllocationsAccountingOpen ();
# endif

    if (nRoots == 0)
		ErrorEmptyPage();
//        ErrorInternal ("Page is empty");

    nNextBlockNumber = FIRST_REGULAR_BLOCK_NUMBER;

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel > 0)
        LT_GraphicsOpen ();

    if (bDebugTimeFlag)
        tTimeTotal = clock ();
# endif

    RootsSaveNonLayoutData ();
    CalculatePageParameters ();

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 2)
        LT_GraphicsRootsOutput ("Roots");
# endif

//    InclinesAccount ();
    RotatePageToIdeal ();
//    InclinesFreeData ();
    RootStripsCalculate ();

    for (i = 0; i < nRoots; i++)
        pRoots [i].nBlock = FIRST_REGULAR_BLOCK_NUMBER;

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 2)
        LT_GraphicsRootsOutput ("Roots after page rotation");
# endif

    BlocksExtract ();
	//BlockAnalyse();

# ifdef LT_DEBUG
    if (LT_DebugGraphicsLevel >= 2)
        LT_GraphicsBlocksOutput ("Blocks after extraction");
# endif
}

void PageStrings2 (void)
{
    RootsRemoveFromRulers ();

# ifdef LT_USE_STRINGS_EXTRACTION
    StringsExtract ();
# endif

    RootsRestoreNonLayoutData ();
    LT_FreeAllData ();

# ifdef LT_DEBUG
    if (bDebugTimeFlag)
        tTimeTotal = clock () - tTimeTotal;
# endif

# ifdef MA_DEBUG
    AllocationsAccountingClose ();
# endif
}

void LayoutPart1 (void)
{
extern int SheetsCorrectRoots();
# ifdef LT_DEBUG
    switch (layout)
    {
        case 0:  LT_DebugGraphicsLevel = 0;  break;
        case 1:  LT_DebugGraphicsLevel = 1;  break;
        case 2:  LT_DebugGraphicsLevel = 2;  break;
        case 3:  LT_DebugGraphicsLevel = 3;  break;
        case 4:  LT_DebugGraphicsLevel = 4;  break;
        case 5:  LT_DebugGraphicsLevel = 1;  break;
        case 6:  LT_DebugGraphicsLevel = 1;  break;
        case 7:  LT_DebugGraphicsLevel = 1;  break;
        case 8:  LT_DebugGraphicsLevel = 1;  break;
        case 9:  LT_DebugGraphicsLevel = 0;  break;
        case 10: LT_DebugGraphicsLevel = 0;  break;
    }

    bDebugTimeFlag = FALSE;

    bDebugOptionCalibratePictureRemovingCriteria = FALSE;
    bDebugOptionCalibrateDD_RemovingCriteria     = FALSE;
    bDebugOptionCalibrateLinearRemovingCriteria  = FALSE;
# endif

# ifdef SE_DEBUG
    switch (layout)
    {
        case 0:  SE_DebugGraphicsLevel = 0;  break;
        case 1:  SE_DebugGraphicsLevel = 0;  break;
        case 2:  SE_DebugGraphicsLevel = 0;  break;
        case 3:  SE_DebugGraphicsLevel = 0;  break;
        case 4:  SE_DebugGraphicsLevel = 0;  break;
        case 5:  SE_DebugGraphicsLevel = 1;  break;
        case 6:  SE_DebugGraphicsLevel = 2;  break;
        case 7:  SE_DebugGraphicsLevel = 3;  break;
        case 8:  SE_DebugGraphicsLevel = 4;  break;
        case 9:  SE_DebugGraphicsLevel = 0;  break;
        case 10: SE_DebugGraphicsLevel = 0;  break;
    }
# endif

# ifdef MA_DEBUG
    switch (layout)
    {
        case 0:  MA_DebugLevel = 0;  break;
        case 1:  MA_DebugLevel = 0;  break;
        case 2:  MA_DebugLevel = 0;  break;
        case 3:  MA_DebugLevel = 0;  break;
        case 4:  MA_DebugLevel = 0;  break;
        case 5:  MA_DebugLevel = 0;  break;
        case 6:  MA_DebugLevel = 0;  break;
        case 7:  MA_DebugLevel = 0;  break;
        case 8:  MA_DebugLevel = 0;  break;
        case 9:  MA_DebugLevel = 1;  break;
        case 10: MA_DebugLevel = 2;  break;
    }
# endif

    bOptionForceOneColumn      = ((run_options & FORCE_ONE_COLUMN) != 0);
    bOptionBusinessCardsLayout = ((run_options & BCRLOUT) != 0);

    bOptionPointSizeAnalysis                = TRUE;
    bOptionSmartBreaking                    = TRUE;
    bOptionInitialBreakingByPageMatrix      = TRUE;
    bOptionBlocksRemovingByPageMatrix       = ! bOptionBusinessCardsLayout;
    bOptionBlocksRemovingByDustDistribution = ! bOptionBusinessCardsLayout;
    bOptionSpecialHorizontalCutting         = FALSE;
    bOptionWhiteStripsBreaking              = TRUE;

    if (bOptionForceOneColumn)
        PageStrings1 ();
    else
        PageLayoutPart1 ();

// маркируются ROOTы попадающие в ячейки таблиц
    //DDD SheetsCorrectRoots(); // Piter 08-17-95 07:29pm
    BlocksExtract ();
	//BlockAnalyse();

// ******** temporary ***************
    // Piter 08-28-95 05:58pm
    // Удаление фрагментов не входящих в таблицы
//{
//    BLOCK *p;
//    lrep:
//       for (p = pBlocksList; p != NULL; p = p -> pNext)
//  switch(p -> nUserNum)
//  {
//  case 0:
//        BlockRemove (p);
//        goto lrep;
//  }

//}//**************************************

}

void LayoutPart2 (void)
{
    if (bOptionForceOneColumn)
        PageStrings2 ();
    else
        PageLayoutPart2 ();
}
/**********************************************/
# ifdef LT_STAND_ALONE
/*
void PageLayout(void);

void main (int nArgc, char **pArgv)
{
    int  i;
    int nFilesDefined = 0;
    char *p;

    for (i = 1; i < nArgc; i++)
    {
        if (*pArgv[i] == '-')
        {
            for (p = pArgv[i] + 1; *p; p++)
                switch (*p)
                {
# ifdef LT_DEBUG
                    case 'g':
                        LT_DebugGraphicsLevel++;
                        break;
# endif
                    case 'h':
                        printf (szHelpText);
                        exit (0);
# ifdef LT_DEBUG
                    case 't':
                        bDebugTimeFlag = TRUE;
                        break;
# endif
                    default:
                        fprintf (stderr, "Bad option: \"%s\"\n%s\n",
                                pArgv [i], szQuickHelpText);
                        exit (-1);
                        break;
                }
        }
        else
        {
            switch (nFilesDefined)
            {
                case 0:
                    strcpy (szRootsFilename, pArgv [i]);
                    nFilesDefined++;
                    break;

                default:
                    fprintf (stderr, "Unnecessary filename: \"%s\"\n%s\n",
                                pArgv [i], szQuickHelpText);
                    exit (-1);
            }
        }
    }

    RootsLoadFile (szRootsFilename);
    PageLayout ();
    exit (0);
}
*/
# endif