File: pageblk.cpp

package info (click to toggle)
tesseract 2.04-2%2Bsqueeze1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 7,336 kB
  • ctags: 6,860
  • sloc: cpp: 81,388; sh: 3,446; java: 1,220; makefile: 376
file content (879 lines) | stat: -rw-r--r-- 23,979 bytes parent folder | download | duplicates (2)
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
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
#include "mfcpch.h"
#include          "pageblk.h"
#include    <stdio.h>
#include          <ctype.h>
#include          <math.h>
#ifdef __UNIX__
#include          <unistd.h>
#else
#include          <io.h>
#endif

#include          "hpddef.h"     //must be last (handpd.dll)

#define G_START 0
#define I_START 1
#define R_START 3
#define S_START 5

extern char blabel[NUM_BLOCK_ATTR][4][MAXLENGTH];
extern char backlabel[NUM_BACKGROUNDS][MAXLENGTH];

ELISTIZE_S (PAGE_BLOCK)
void PAGE_BLOCK::pb_delete() {
  switch (pb_type) {
    case PB_TEXT:
      delete ((TEXT_BLOCK *) this);
      break;
    case PB_GRAPHICS:
      delete ((GRAPHICS_BLOCK *) this);
      break;
    case PB_IMAGE:
      delete ((IMAGE_BLOCK *) this);
      break;
    case PB_RULES:
      delete ((RULE_BLOCK *) this);
      break;
    case PB_SCRIBBLE:
      delete ((SCRIBBLE_BLOCK *) this);
      break;
    case PB_WEIRD:
      delete ((WEIRD_BLOCK *) this);
      break;
    default:
      break;
  }
}


#define QUOTE_IT( parm ) #parm

void PAGE_BLOCK::serialise(FILE *f) {

  if (fwrite (&pb_type, sizeof (PB_TYPE), 1, f) != 1)
    WRITEFAILED.error (QUOTE_IT (PAGE_BLOCK::serialise), ABORT, NULL);
  switch (pb_type) {
    case PB_TEXT:
      ((TEXT_BLOCK *) this)->serialise (f);
      break;
    case PB_GRAPHICS:
      ((GRAPHICS_BLOCK *) this)->serialise (f);
      break;
    case PB_RULES:
      ((RULE_BLOCK *) this)->serialise (f);
      break;
    case PB_IMAGE:
      ((IMAGE_BLOCK *) this)->serialise (f);
      break;
    case PB_SCRIBBLE:
      ((SCRIBBLE_BLOCK *) this)->serialise (f);
      break;
    case PB_WEIRD:
      ((WEIRD_BLOCK *) this)->serialise (f);
      break;
    default:
      break;
  }
}


PAGE_BLOCK *PAGE_BLOCK::de_serialise(FILE *f) {
  PB_TYPE type;
  TEXT_BLOCK *tblock;
  GRAPHICS_BLOCK *gblock;
  RULE_BLOCK *rblock;
  IMAGE_BLOCK *iblock;
  SCRIBBLE_BLOCK *sblock;
  WEIRD_BLOCK *wblock;

  if (fread ((void *) &type, sizeof (PB_TYPE), 1, f) != 1)
    WRITEFAILED.error (QUOTE_IT (PAGE_BLOCK::serialise), ABORT, NULL);
  switch (type) {
    case PB_TEXT:
      tblock = (TEXT_BLOCK *) alloc_struct (sizeof (TEXT_BLOCK));
      return tblock->de_serialise (f);
    case PB_GRAPHICS:
      gblock = (GRAPHICS_BLOCK *) alloc_struct (sizeof (GRAPHICS_BLOCK));
      return gblock->de_serialise (f);
    case PB_RULES:
      rblock = (RULE_BLOCK *) alloc_struct (sizeof (RULE_BLOCK));
      return rblock->de_serialise (f);
    case PB_IMAGE:
      iblock = (IMAGE_BLOCK *) alloc_struct (sizeof (IMAGE_BLOCK));
      return iblock->de_serialise (f);
    case PB_SCRIBBLE:
      sblock = (SCRIBBLE_BLOCK *) alloc_struct (sizeof (SCRIBBLE_BLOCK));
      return sblock->de_serialise (f);
    case PB_WEIRD:
      wblock = (WEIRD_BLOCK *) alloc_struct (sizeof (SCRIBBLE_BLOCK));
      return wblock->de_serialise (f);
    default:
      return NULL;
  }
}


/**********************************************************************
 * PAGE_BLOCK::serialise_asc()  Convert to ascii file.
 *
 **********************************************************************/

void PAGE_BLOCK::serialise_asc(         //convert to ascii
                               FILE *f  //file to use
                              ) {
  serialise_INT32(f, pb_type);
  switch (pb_type) {
    case PB_TEXT:
      ((TEXT_BLOCK *) this)->serialise_asc (f);
      break;
    case PB_GRAPHICS:
      ((GRAPHICS_BLOCK *) this)->serialise_asc (f);
      break;
    case PB_RULES:
      ((RULE_BLOCK *) this)->serialise_asc (f);
      break;
    case PB_IMAGE:
      ((IMAGE_BLOCK *) this)->serialise_asc (f);
      break;
    case PB_SCRIBBLE:
      ((SCRIBBLE_BLOCK *) this)->serialise_asc (f);
      break;
    case PB_WEIRD:
      ((WEIRD_BLOCK *) this)->serialise_asc (f);
      break;
    default:
      break;
  }
}


/**********************************************************************
 * PAGE_BLOCK::internal_serialise_asc()  Convert to ascii file.
 *
 **********************************************************************/

void PAGE_BLOCK::internal_serialise_asc(         //convert to ascii
                                        FILE *f  //file to use
                                       ) {
  ((POLY_BLOCK *) this)->serialise_asc (f);
  serialise_INT32(f, pb_type);
  children.serialise_asc (f);
}


/**********************************************************************
 * PAGE_BLOCK::de_serialise_asc()  Convert from ascii file.
 *
 **********************************************************************/

void PAGE_BLOCK::de_serialise_asc(         //convert from ascii
                                  FILE *f  //file to use
                                 ) {
  PAGE_BLOCK *page_block;        //new block for list
  inT32 len;                     /*length to retrive */
  PAGE_BLOCK_IT it;

  ((POLY_BLOCK *) this)->de_serialise_asc (f);
  pb_type = (PB_TYPE) de_serialise_INT32 (f);
  //      children.de_serialise_asc(f);
  len = de_serialise_INT32 (f);
  it.set_to_list (&children);
  for (; len > 0; len--) {
    page_block = new_de_serialise_asc (f);
    it.add_to_end (page_block);  /*put on the list */
  }
}


/**********************************************************************
 * PAGE_BLOCK::new_de_serialise_asc()  Convert from ascii file.
 *
 **********************************************************************/

PAGE_BLOCK *PAGE_BLOCK::new_de_serialise_asc(         //convert from ascii
                                             FILE *f  //file to use
                                            ) {
  PB_TYPE type;
  TEXT_BLOCK *tblock;
  GRAPHICS_BLOCK *gblock;
  RULE_BLOCK *rblock;
  IMAGE_BLOCK *iblock;
  SCRIBBLE_BLOCK *sblock;
  WEIRD_BLOCK *wblock;

  type = (PB_TYPE) de_serialise_INT32 (f);
  switch (type) {
    case PB_TEXT:
      tblock = new TEXT_BLOCK;
      tblock->de_serialise_asc (f);
      return tblock;
    case PB_GRAPHICS:
      gblock = new GRAPHICS_BLOCK;
      gblock->de_serialise_asc (f);
      return gblock;
    case PB_RULES:
      rblock = new RULE_BLOCK;
      rblock->de_serialise_asc (f);
      return rblock;
    case PB_IMAGE:
      iblock = new IMAGE_BLOCK;
      iblock->de_serialise_asc (f);
      return iblock;
    case PB_SCRIBBLE:
      sblock = new SCRIBBLE_BLOCK;
      sblock->de_serialise_asc (f);
      return sblock;
    case PB_WEIRD:
      wblock = new WEIRD_BLOCK;
      wblock->de_serialise_asc (f);
      return wblock;
    default:
      return NULL;
  }
}


void PAGE_BLOCK::show_attrs(DEBUG_WIN *f) {
  PAGE_BLOCK_IT it;

  switch (pb_type) {
    case PB_TEXT:
      ((TEXT_BLOCK *) this)->show_attrs (f);
      break;
    case PB_GRAPHICS:
      ((GRAPHICS_BLOCK *) this)->show_attrs (f);
      break;
    case PB_RULES:
      ((RULE_BLOCK *) this)->show_attrs (f);
      break;
    case PB_IMAGE:
      ((IMAGE_BLOCK *) this)->show_attrs (f);
      break;
    case PB_SCRIBBLE:
      ((SCRIBBLE_BLOCK *) this)->show_attrs (f);
      break;
    case PB_WEIRD:
      ((WEIRD_BLOCK *) this)->show_attrs (f);
      break;
    default:
      break;
  }

  if (!children.empty ()) {
    f->dprintf ("containing subblocks\n");
    it.set_to_list (&children);
    for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
      it.data ()->show_attrs (f);
    f->dprintf ("end of subblocks\n");
  }
}


PAGE_BLOCK::PAGE_BLOCK (ICOORDELT_LIST * points, PB_TYPE type, PAGE_BLOCK_LIST * child):POLY_BLOCK (points,
POLY_PAGE) {
  PAGE_BLOCK_IT
    c = &children;

  pb_type = type;
  children.clear ();
  c.move_to_first ();
  c.add_list_before (child);
}


PAGE_BLOCK::PAGE_BLOCK (ICOORDELT_LIST * points, PB_TYPE type):POLY_BLOCK (points,
POLY_PAGE) {
  pb_type = type;
  children.clear ();
}


void PAGE_BLOCK::add_a_child(PAGE_BLOCK *newchild) {
  PAGE_BLOCK_IT c = &children;

  c.move_to_first ();
  c.add_to_end (newchild);
}


/**********************************************************************
 * PAGE_BLOCK::rotate
 *
 * Rotate the PAGE_BLOCK and its children
 **********************************************************************/

void PAGE_BLOCK::rotate(  //cos,sin
                        FCOORD rotation) {
                                 //sub block iterator
  PAGE_BLOCK_IT child_it = &children;
  PAGE_BLOCK *child;             //child block

  for (child_it.mark_cycle_pt (); !child_it.cycled_list ();
  child_it.forward ()) {
    child = child_it.data ();
    child->rotate (rotation);
  }
  if (pb_type == PB_TEXT)
    ((TEXT_BLOCK *) this)->rotate (rotation);
  else
    POLY_BLOCK::rotate(rotation);
}


/**********************************************************************
 * PAGE_BLOCK::move
 *
 * Move the PAGE_BLOCK and its children
 **********************************************************************/

void PAGE_BLOCK::move(ICOORD shift  //amount to move
                     ) {
                                 //sub block iterator
  PAGE_BLOCK_IT child_it = &children;
  PAGE_BLOCK *child;             //child block

  for (child_it.mark_cycle_pt (); !child_it.cycled_list ();
  child_it.forward ()) {
    child = child_it.data ();
    child->move (shift);
  }
  if (pb_type == PB_TEXT)
    ((TEXT_BLOCK *) this)->move (shift);
  else
    POLY_BLOCK::move(shift);
}

#ifndef GRAPHICS_DISABLED
void PAGE_BLOCK::basic_plot(ScrollView* window, ScrollView::Color colour) {
  PAGE_BLOCK_IT c = &children;

  POLY_BLOCK::plot (window, colour, 0);

  if (!c.empty ())
    for (c.mark_cycle_pt (); !c.cycled_list (); c.forward ())
      c.data ()->plot (window, colour);
}


void PAGE_BLOCK::plot(ScrollView* window, ScrollView::Color colour) {
  TEXT_BLOCK *tblock;
  WEIRD_BLOCK *wblock;

  switch (pb_type) {
    case PB_TEXT:
      basic_plot(window, colour);
      tblock = (TEXT_BLOCK *) this;
      tblock->plot (window, colour, REGION_COLOUR, SUBREGION_COLOUR);
      break;
    case PB_WEIRD:
      wblock = (WEIRD_BLOCK *) this;
      wblock->plot (window, colour);
      break;
    default:
      basic_plot(window, colour);
      break;
  }
}
#endif

void show_all_in(PAGE_BLOCK *pblock, POLY_BLOCK *show_area, DEBUG_WIN *f) {
  PAGE_BLOCK_IT c;
  inT16 i, pnum;

  c.set_to_list (pblock->child ());
  pnum = pblock->child ()->length ();
  for (i = 0; i < pnum; i++, c.forward ()) {
    if (show_area->contains (c.data ()))
      c.data ()->show_attrs (f);
    else if (show_area->overlap (c.data ()))
      show_all_in (c.data (), show_area, f);
  }
}


void delete_all_in(PAGE_BLOCK *pblock, POLY_BLOCK *delete_area) {
  PAGE_BLOCK_IT c;
  inT16 i, pnum;

  c.set_to_list (pblock->child ());
  pnum = pblock->child ()->length ();
  for (i = 0; i < pnum; i++, c.forward ()) {
    if (delete_area->contains (c.data ()))
      c.extract ()->pb_delete ();
    else if (delete_area->overlap (c.data ()))
      delete_all_in (c.data (), delete_area);
  }
}


PAGE_BLOCK *smallest_containing(PAGE_BLOCK *pblock, POLY_BLOCK *other) {
  PAGE_BLOCK_IT c;

  c.set_to_list (pblock->child ());
  if (c.empty ())
    return (pblock);

  for (c.mark_cycle_pt (); !c.cycled_list (); c.forward ())
    if (c.data ()->contains (other))
      return (smallest_containing (c.data (), other));

  return (pblock);
}


TEXT_BLOCK::TEXT_BLOCK (ICOORDELT_LIST * points, BOOL8 backg[NUM_BACKGROUNDS]):PAGE_BLOCK (points,
PB_TEXT) {
  int
    i;

  for (i = 0; i < NUM_BACKGROUNDS; i++)
    background.set_bit (i, backg[i]);

  text_regions.clear ();
}


void
TEXT_BLOCK::set_attrs (BOOL8 backg[NUM_BACKGROUNDS]) {
  int i;

  for (i = 0; i < NUM_BACKGROUNDS; i++)
    background.set_bit (i, backg[i]);
}


void TEXT_BLOCK::add_a_region(TEXT_REGION *newchild) {
  TEXT_REGION_IT c;

  c.set_to_list (&text_regions);

  c.move_to_first ();
  c.add_to_end (newchild);
}


/**********************************************************************
 * TEXT_BLOCK::rotate
 *
 * Rotate the TEXT_BLOCK and its children
 **********************************************************************/

void TEXT_BLOCK::rotate(  //cos,sin
                        FCOORD rotation) {
                                 //sub block iterator
  TEXT_REGION_IT child_it = &text_regions;
  TEXT_REGION *child;            //child block

  for (child_it.mark_cycle_pt (); !child_it.cycled_list ();
  child_it.forward ()) {
    child = child_it.data ();
    child->rotate (rotation);
  }
  POLY_BLOCK::rotate(rotation);
}


/**********************************************************************
 * TEXT_BLOCK::move
 *
 * Move the TEXT_BLOCK and its children
 **********************************************************************/

void TEXT_BLOCK::move(ICOORD shift  //amount to move
                     ) {
                                 //sub block iterator
  TEXT_REGION_IT child_it = &text_regions;
  TEXT_REGION *child;            //child block

  for (child_it.mark_cycle_pt (); !child_it.cycled_list ();
  child_it.forward ()) {
    child = child_it.data ();
    child->move (shift);
  }
  POLY_BLOCK::move(shift);
}


/**********************************************************************
 * TEXT_BLOCK::serialise_asc()  Convert to ascii file.
 *
 **********************************************************************/

void TEXT_BLOCK::serialise_asc(         //convert to ascii
                               FILE *f  //file to use
                              ) {
  ((PAGE_BLOCK *) this)->internal_serialise_asc (f);
  serialise_INT32 (f, background.val);
  text_regions.serialise_asc (f);
}


/**********************************************************************
 * TEXT_BLOCK::de_serialise_asc()  Convert from ascii file.
 *
 **********************************************************************/

void TEXT_BLOCK::de_serialise_asc(         //convert from ascii
                                  FILE *f  //file to use
                                 ) {
  ((PAGE_BLOCK *) this)->de_serialise_asc (f);
  background.val = de_serialise_INT32 (f);
  text_regions.de_serialise_asc (f);
}


#ifndef GRAPHICS_DISABLED
void TEXT_BLOCK::plot(ScrollView* window,
                      ScrollView::Color colour,
                      ScrollView::Color region_colour,
                      ScrollView::Color subregion_colour) {
  TEXT_REGION_IT t = &text_regions, tc;

  PAGE_BLOCK::basic_plot(window, colour);

  if (!t.empty ())
  for (t.mark_cycle_pt (); !t.cycled_list (); t.forward ()) {
    t.data ()->plot (window, region_colour, t.data ()->id_no ());
    tc.set_to_list (t.data ()->regions ());
    if (!tc.empty ())
      for (tc.mark_cycle_pt (); !tc.cycled_list (); tc.forward ())
        tc.data ()->plot (window, subregion_colour, -1);
  }
}
#endif


void TEXT_BLOCK::show_attrs(DEBUG_WIN *f) {
  TEXT_REGION_IT it;

  f->dprintf ("TEXT BLOCK\n");
  print_background(f, background);
  if (!text_regions.empty ()) {
    f->dprintf ("containing text regions:\n");
    it.set_to_list (&text_regions);
    for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
      it.data ()->show_attrs (f);
    f->dprintf ("end of regions\n");
  }
}


DLLSYM void show_all_tr_in(TEXT_BLOCK *tblock,
                           POLY_BLOCK *show_area,
                           DEBUG_WIN *f) {
  TEXT_REGION_IT t, tc;
  inT16 i, tnum, j, ttnum;

  t.set_to_list (tblock->regions ());
  tnum = tblock->regions ()->length ();
  for (i = 0; i < tnum; i++, t.forward ()) {
    if (show_area->contains (t.data ()))
      t.data ()->show_attrs (f);
    else if (show_area->overlap (t.data ())) {
      tc.set_to_list (t.data ()->regions ());
      ttnum = t.data ()->regions ()->length ();
      for (j = 0; j < ttnum; j++, tc.forward ())
        if (show_area->contains (tc.data ()))
          tc.data ()->show_attrs (f);
    }
  }
}


void delete_all_tr_in(TEXT_BLOCK *tblock, POLY_BLOCK *delete_area) {
  TEXT_REGION_IT t, tc;
  inT16 i, tnum, j, ttnum;

  t.set_to_list (tblock->regions ());
  tnum = tblock->regions ()->length ();
  for (i = 0; i < tnum; i++, t.forward ()) {
    if (delete_area->contains (t.data ()))
      delete (t.extract ());
    else if (delete_area->overlap (t.data ())) {
      tc.set_to_list (t.data ()->regions ());
      ttnum = t.data ()->regions ()->length ();
      for (j = 0; j < ttnum; j++, tc.forward ())
        if (delete_area->contains (tc.data ()))
          delete (tc.extract ());
    }
  }
}


RULE_BLOCK::RULE_BLOCK (ICOORDELT_LIST * points, inT8 sing, inT8 colo):PAGE_BLOCK (points,
PB_RULES) {
  multiplicity = sing;
  colour = colo;
}


void RULE_BLOCK::set_attrs(inT8 sing, inT8 colo) {
  multiplicity = sing;
  colour = colo;
}


void RULE_BLOCK::show_attrs(DEBUG_WIN *f) {
  f->dprintf ("RULE BLOCK with attributes %s, %s\n",
    blabel[R_START][multiplicity], blabel[R_START + 1][colour]);
}


/**********************************************************************
 * RULE_BLOCK::serialise_asc()  Convert to ascii file.
 *
 **********************************************************************/

void RULE_BLOCK::serialise_asc(         //convert to ascii
                               FILE *f  //file to use
                              ) {
  ((PAGE_BLOCK *) this)->internal_serialise_asc (f);
  serialise_INT32(f, multiplicity);
  serialise_INT32(f, colour);
}


/**********************************************************************
 * RULE_BLOCK::de_serialise_asc()  Convert from ascii file.
 *
 **********************************************************************/

void RULE_BLOCK::de_serialise_asc(         //convert from ascii
                                  FILE *f  //file to use
                                 ) {
  ((PAGE_BLOCK *) this)->de_serialise_asc (f);
  multiplicity = de_serialise_INT32 (f);
  colour = de_serialise_INT32 (f);
}


GRAPHICS_BLOCK::GRAPHICS_BLOCK (ICOORDELT_LIST * points, BOOL8 backg[NUM_BACKGROUNDS], inT8 foreg):PAGE_BLOCK (points,
PB_GRAPHICS) {
  int
    i;

  for (i = 0; i < NUM_BACKGROUNDS; i++)
    background.set_bit (i, backg[i]);

  foreground = foreg;
}


void
GRAPHICS_BLOCK::set_attrs (BOOL8 backg[NUM_BACKGROUNDS], inT8 foreg) {
  int i;

  for (i = 0; i < NUM_BACKGROUNDS; i++)
    background.set_bit (i, backg[i]);

  foreground = foreg;
}


void GRAPHICS_BLOCK::show_attrs(DEBUG_WIN *f) {
  f->dprintf ("GRAPHICS BLOCK with attribute %s\n",
    blabel[G_START][foreground]);
  print_background(f, background);
}


/**********************************************************************
 * GRAPHICS_BLOCK::serialise_asc()  Convert to ascii file.
 *
 **********************************************************************/

void GRAPHICS_BLOCK::serialise_asc(         //convert to ascii
                                   FILE *f  //file to use
                                  ) {
  ((PAGE_BLOCK *) this)->internal_serialise_asc (f);
  serialise_INT32 (f, background.val);
  serialise_INT32(f, foreground);
}


/**********************************************************************
 * GRAPHICS_BLOCK::de_serialise_asc()  Convert from ascii file.
 *
 **********************************************************************/

void GRAPHICS_BLOCK::de_serialise_asc(         //convert from ascii
                                      FILE *f  //file to use
                                     ) {
  ((PAGE_BLOCK *) this)->de_serialise_asc (f);
  background.val = de_serialise_INT32 (f);
  foreground = de_serialise_INT32 (f);
}


IMAGE_BLOCK::IMAGE_BLOCK (ICOORDELT_LIST * points, inT8 colo, inT8 qual):PAGE_BLOCK (points,
PB_IMAGE) {
  colour = colo;
  quality = qual;
}


void IMAGE_BLOCK::set_attrs(inT8 colo, inT8 qual) {
  colour = colo;
  quality = qual;
}


void IMAGE_BLOCK::show_attrs(DEBUG_WIN *f) {
  f->dprintf ("IMAGE BLOCK with attributes %s, %s\n", blabel[I_START][colour],
    blabel[I_START + 1][quality]);
}


/**********************************************************************
 * IMAGE_BLOCK::serialise_asc()  Convert to ascii file.
 *
 **********************************************************************/

void IMAGE_BLOCK::serialise_asc(         //convert to ascii
                                FILE *f  //file to use
                               ) {
  ((PAGE_BLOCK *) this)->internal_serialise_asc (f);
  serialise_INT32(f, colour);
  serialise_INT32(f, quality);
}


/**********************************************************************
 * IMAGE_BLOCK::de_serialise_asc()  Convert from ascii file.
 *
 **********************************************************************/

void IMAGE_BLOCK::de_serialise_asc(         //convert from ascii
                                   FILE *f  //file to use
                                  ) {
  ((PAGE_BLOCK *) this)->de_serialise_asc (f);
  colour = de_serialise_INT32 (f);
  quality = de_serialise_INT32 (f);
}


SCRIBBLE_BLOCK::SCRIBBLE_BLOCK (ICOORDELT_LIST * points, BOOL8 backg[NUM_BACKGROUNDS], inT8 foreg):PAGE_BLOCK (points,
PB_SCRIBBLE) {
  int
    i;

  for (i = 0; i < NUM_BACKGROUNDS; i++)
    background.set_bit (i, backg[i]);

  foreground = foreg;
}


void
SCRIBBLE_BLOCK::set_attrs (BOOL8 backg[NUM_BACKGROUNDS], inT8 foreg) {
  int i;

  for (i = 0; i < NUM_BACKGROUNDS; i++)
    background.set_bit (i, backg[i]);

  foreground = foreg;
}


void SCRIBBLE_BLOCK::show_attrs(DEBUG_WIN *f) {
  f->dprintf ("SCRIBBLE BLOCK with attributes %s\n",
    blabel[S_START][foreground]);
  print_background(f, background);
}


/**********************************************************************
 * SCRIBBLE_BLOCK::serialise_asc()  Convert to ascii file.
 *
 **********************************************************************/

void SCRIBBLE_BLOCK::serialise_asc(         //convert to ascii
                                   FILE *f  //file to use
                                  ) {
  ((PAGE_BLOCK *) this)->internal_serialise_asc (f);
  serialise_INT32 (f, background.val);
  serialise_INT32(f, foreground);
}


/**********************************************************************
 * SCRIBBLE_BLOCK::de_serialise_asc()  Convert from ascii file.
 *
 **********************************************************************/

void SCRIBBLE_BLOCK::de_serialise_asc(         //convert from ascii
                                      FILE *f  //file to use
                                     ) {
  ((PAGE_BLOCK *) this)->de_serialise_asc (f);
  background.val = de_serialise_INT32 (f);
  foreground = de_serialise_INT32 (f);
}


WEIRD_BLOCK::WEIRD_BLOCK (ICOORDELT_LIST * points, inT32 id_no):PAGE_BLOCK (points,
PB_WEIRD) {
  id_number = id_no;
}


#ifndef GRAPHICS_DISABLED
void WEIRD_BLOCK::plot(ScrollView* window, ScrollView::Color colour) {
  PAGE_BLOCK_IT c = this->child ();

  POLY_BLOCK::plot(window, colour, id_number);

  if (!c.empty ())
    for (c.mark_cycle_pt (); !c.cycled_list (); c.forward ())
      c.data ()->plot (window, colour);
}
#endif


void WEIRD_BLOCK::set_id(inT32 id_no) {
  id_number = id_no;
}


void WEIRD_BLOCK::show_attrs(DEBUG_WIN *f) {
  f->dprintf ("WEIRD BLOCK with id number %d\n", id_number);
}


/**********************************************************************
 * WEIRD_BLOCK::serialise_asc()  Convert to ascii file.
 *
 **********************************************************************/

void WEIRD_BLOCK::serialise_asc(         //convert to ascii
                                FILE *f  //file to use
                               ) {
  ((PAGE_BLOCK *) this)->internal_serialise_asc (f);
  serialise_INT32(f, id_number);
}


/**********************************************************************
 * WEIRD_BLOCK::de_serialise_asc()  Convert from ascii file.
 *
 **********************************************************************/

void WEIRD_BLOCK::de_serialise_asc(         //convert from ascii
                                   FILE *f  //file to use
                                  ) {
  ((PAGE_BLOCK *) this)->de_serialise_asc (f);
  id_number = de_serialise_INT32 (f);
}


void print_background(DEBUG_WIN *f, BITS16 background) {
  int i;

  f->dprintf ("Background is \n");
  for (i = 0; i < NUM_BACKGROUNDS; i++) {
    if (background.bit (i))
      f->dprintf ("%s, ", backlabel[i]);
  }

  f->dprintf ("\n");

}