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
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
|
//C- -*- C++ -*-
//C- -------------------------------------------------------------------
//C- DjVuLibre-3.5
//C- Copyright (c) 2002 Leon Bottou and Yann Le Cun.
//C- Copyright (c) 2001 AT&T
//C-
//C- This software is subject to, and may be distributed under, the
//C- GNU General Public License, Version 2. The license should have
//C- accompanied the software or you may obtain a copy of the license
//C- from the Free Software Foundation at http://www.fsf.org .
//C-
//C- This program is distributed in the hope that it will be useful,
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//C- GNU General Public License for more details.
//C-
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
//C- distributed by Lizardtech Software. On July 19th 2002, Lizardtech
//C- Software authorized us to replace the original DjVu(r) Reference
//C- Library notice by the following text (see doc/lizard2002.djvu):
//C-
//C- ------------------------------------------------------------------
//C- | DjVu (r) Reference Library (v. 3.5)
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
//C- | 6,058,214 and patents pending.
//C- |
//C- | This software is subject to, and may be distributed under, the
//C- | GNU General Public License, Version 2. The license should have
//C- | accompanied the software or you may obtain a copy of the license
//C- | from the Free Software Foundation at http://www.fsf.org .
//C- |
//C- | The computer code originally released by LizardTech under this
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
//C- | ORIGINAL CODE." Subject to any third party intellectual property
//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
//C- | non-exclusive license to make, use, sell, or otherwise dispose of
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
//C- | General Public License. This grant only confers the right to
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
//C- | the extent such infringement is reasonably necessary to enable
//C- | recipient to make, have made, practice, sell, or otherwise dispose
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
//C- | any greater extent that may be necessary to utilize further
//C- | modifications or combinations.
//C- |
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
//C- +------------------------------------------------------------------
//
// $Id: DjVuAnno.cpp,v 1.12 2004/04/17 23:56:11 leonb Exp $
// $Name: release_3_5_15 $
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if NEED_GNUG_PRAGMAS
# pragma implementation
#endif
#include "DjVuAnno.h"
#include "GContainer.h"
#include "GException.h"
#include "IFFByteStream.h"
#include "BSByteStream.h"
#include "GMapAreas.h"
#include "debug.h"
#include <ctype.h>
#ifdef HAVE_NAMESPACES
namespace DJVU {
# ifdef NOT_DEFINED // Just to fool emacs c++ mode
}
#endif
#endif
// GLParser.h and GLParser.cpp used to be separate files capable to decode
// that weird ANTa chunk format into C++ structures and lists. But since
// its implementation is temporary and is used only in this file (DjVuAnno.cpp)
// it appears reasonable to build it in here.
//***************************************************************************
//****************************** GLParser.h *********************************
//***************************************************************************
class GLObject : public GPEnabled
{
public:
enum GLObjectType { INVALID=0, NUMBER=1, STRING=2, SYMBOL=3, LIST=4 };
static const char * const GLObjectString[LIST+1];
GLObject(int _number=0);
GLObject(GLObjectType type, const char * str);
GLObject(const char * name, const GPList<GLObject> & list);
virtual ~GLObject(void);
int get_number(void) const;
GUTF8String get_string(void) const;
GUTF8String get_symbol(void) const;
GPList<GLObject> & get_list(void);
GP<GLObject> operator[](int n) const;
GLObjectType get_type(void) const;
GUTF8String get_name(void) const;
void print(ByteStream & str, int compact=1, int indent=0, int * cur_pos=0) const;
private:
GLObjectType type;
GUTF8String name;
int number;
GUTF8String string;
GUTF8String symbol;
GPList<GLObject> list;
void throw_can_not_convert_to(const GLObjectType to) const;
};
const char * const GLObject::GLObjectString[]=
{"invalid", "number", "string", "symbol", "list"};
inline GLObject::GLObjectType
GLObject::get_type(void) const { return type; }
inline
GLObject::~GLObject(void) {}
class GLToken
{
public:
enum GLTokenType { OPEN_PAR, CLOSE_PAR, OBJECT };
GLTokenType type;
GP<GLObject> object;
GLToken(GLTokenType type, const GP<GLObject> & object);
};
inline
GLToken::GLToken(GLTokenType xtype, const GP<GLObject> & xobject) :
type(xtype), object(xobject) {}
class GLParser
{
public:
void parse(const char * str);
GPList<GLObject> & get_list(void);
GP<GLObject> get_object(const char * name, bool last=true);
void print(ByteStream & str, int compact=1);
GLParser(void);
GLParser(const char * str);
~GLParser(void);
private:
GPList<GLObject> list;
bool compat;
void skip_white_space(const char * & start);
void check_compat(const char *str);
GLToken get_token(const char * & start);
void parse(const char * cur_name, GPList<GLObject> & list,
const char * & start);
};
GLParser::GLParser(void)
: compat(false)
{
}
GLParser::~GLParser(void)
{
}
GPList<GLObject> &
GLParser::get_list(void)
{
return list;
}
GLParser::GLParser(const char * str)
: compat(false)
{
parse(str);
}
//***************************************************************************
//***************************** GLParser.cpp ********************************
//***************************************************************************
GLObject::GLObject(int xnumber) : type(NUMBER), number(xnumber) {}
GLObject::GLObject(GLObjectType xtype, const char * str) : type(xtype)
{
if (type!=STRING && type!=SYMBOL)
G_THROW( ERR_MSG("DjVuAnno.bad_type") );
if (type==STRING)
string=str;
else symbol=str;
}
GLObject::GLObject(const char * xname, const GPList<GLObject> & xlist) :
type(LIST), name(xname), list(xlist) {}
void
GLObject::print(ByteStream & str, int compact, int indent, int * cur_pos) const
{
int local_cur_pos = 0;
if (!cur_pos) { cur_pos = &local_cur_pos; }
GUTF8String buffer;
const char * to_print=0;
switch(type)
{
case NUMBER:
to_print=buffer.format("%d",number);
break;
case STRING:
{
int length = string.length();
const char *data = (const char*)string;
buffer = GUTF8String("\"");
while (*data && length>0)
{
int span = 0;
while (span<length && (unsigned char)(data[span])>=0x20 &&
data[span]!=0x7f && data[span]!='"' && data[span]!='\\' )
span++;
if (span > 0)
{
buffer = buffer + GUTF8String(data, span);
data += span;
length -= span;
}
else
{
char buf[8];
static const char *tr1 = "\"\\tnrbf";
static const char *tr2 = "\"\\\t\n\r\b\f";
sprintf(buf,"\\%03o", (int)(((unsigned char*)data)[span]));
for (int i=0; tr2[i]; i++)
if (data[span] == tr2[i])
buf[1] = tr1[i];
if (buf[1]<'0' || buf[1]>'3')
buf[2] = 0;
buffer = buffer + GUTF8String(buf);
data += 1;
length -= 1;
}
}
buffer = buffer + GUTF8String("\"");
to_print = buffer;
}
break;
case SYMBOL:
to_print=buffer.format("%s",(const char *)symbol);
break;
case LIST:
to_print=buffer.format("(%s",(const char *)name);
break;
case INVALID:
break;
}
if (!compact && *cur_pos+strlen(to_print)>70)
{
char ch='\n';
str.write(&ch, 1);
ch=' ';
for(int i=0;i<indent;i++) str.write(&ch, 1);
*cur_pos=indent;
}
str.write(to_print, strlen(to_print));
char ch=' ';
str.write(&ch, 1);
*cur_pos+=strlen(to_print)+1;
if (type==LIST)
{
int indent=*cur_pos-strlen(to_print);
for(GPosition pos=list;pos;++pos)
list[pos]->print(str, compact, indent, cur_pos);
str.write(") ", 2);
*cur_pos+=2;
}
}
// This function constructs message names for external lookup.
// The message names are constructed to avoid the problems of concatenating
// phrases (which does not translate well into other languages). The
// message names that can be generated are (listed here to appease the
// auditing program which reads comments):
// ERR_MSG("DjVuAnno.invalid2number"), ERR_MSG("DjVuAnno.string2number"),
// ERR_MSG("DjVuAnno.symbol2number"), ERR_MSG("DjVuAnno.list2number")
// ERR_MSG("DjVuAnno.invalid2string"), ERR_MSG("DjVuAnno.number2string"),
// ERR_MSG("DjVuAnno.symbol2string"), ERR_MSG("DjVuAnno.list2string")
// ERR_MSG("DjVuAnno.invalid2symbol"), ERR_MSG("DjVuAnno.number2symbol"),
// ERR_MSG("DjVuAnno.string2symbol"), ERR_MSG("DjVuAnno.list2symbol")
// ERR_MSG("DjVuAnno.invalid2list"), ERR_MSG("DjVuAnno.number2list"),
// ERR_MSG("DjVuAnno.string2list"), ERR_MSG("DjVuAnno.symbol2list")
void
GLObject::throw_can_not_convert_to(const GLObjectType to) const
{
static const GUTF8String two('2');
static const GUTF8String tab('\t');
GUTF8String mesg("DjVuAnno.");
switch(type)
{
case NUMBER:
mesg+=GLObjectString[NUMBER]+two+GLObjectString[to]+tab+GUTF8String(number);
break;
case STRING:
mesg+=GLObjectString[STRING]+two+GLObjectString[to]+tab+string;
break;
case SYMBOL:
mesg+=GLObjectString[SYMBOL]+two+GLObjectString[to]+tab+symbol;
break;
case LIST:
mesg+=GLObjectString[LIST]+two+GLObjectString[to]+tab+name;
break;
default:
mesg+=GLObjectString[INVALID]+two+GLObjectString[to];
break;
}
G_THROW(mesg);
}
GUTF8String
GLObject::get_string(void) const
{
if (type!=STRING)
{
throw_can_not_convert_to(STRING);
}
return string;
}
GUTF8String
GLObject::get_symbol(void) const
{
if (type!=SYMBOL)
{
throw_can_not_convert_to(SYMBOL);
}
return symbol;
}
int
GLObject::get_number(void) const
{
if (type!=NUMBER)
{
throw_can_not_convert_to(NUMBER);
}
return number;
}
GUTF8String
GLObject::get_name(void) const
{
if (type!=LIST)
{
throw_can_not_convert_to(LIST);
}
return name;
}
GP<GLObject>
GLObject::operator[](int n) const
{
if (type!=LIST)
{
throw_can_not_convert_to(LIST);
}
if (n>=list.size()) G_THROW( ERR_MSG("DjVuAnno.too_few") "\t"+name);
int i;
GPosition pos;
for(i=0, pos=list;i<n && pos;i++, ++pos)
continue;
return list[pos];
}
GPList<GLObject> &
GLObject::get_list(void)
{
if (type!=LIST)
{
throw_can_not_convert_to(LIST);
}
return list;
}
//********************************** GLParser *********************************
void
GLParser::skip_white_space(const char * & start)
{
while(*start && isspace(*start)) start++;
if (!*start)
G_THROW( ByteStream::EndOfFile );
}
GLToken
GLParser::get_token(const char * & start)
{
skip_white_space(start);
char c = *start;
if (c == '(')
{
start++;
return GLToken(GLToken::OPEN_PAR, 0);
}
else if (c == ')')
{
start++;
return GLToken(GLToken::CLOSE_PAR, 0);
}
else if (c=='-' || (c>='0' && c<='9'))
{
return GLToken(GLToken::OBJECT,
new GLObject(strtol(start, (char **) &start, 10)));
}
else if (c=='"')
{
GUTF8String str;
start++;
while(1)
{
int span = 0;
while (start[span] && start[span]!='\\' && start[span]!='\"')
span++;
if (span > 0)
{
str = str + GUTF8String(start,span);
start += span;
}
else if (start[0]=='\"')
{
start += 1;
break;
}
else if (start[0]=='\\' && compat)
{
char c = start[1];
if (c == '\"')
{
start += 2;
str += '\"';
}
else
{
start += 1;
str += '\\';
}
}
else if (start[0]=='\\' && start[1])
{
char c = *++start;
if (c>='0' && c<='7')
{
int x = 0;
for (int i=0; i<3 && c>='0' && c<='7'; i++)
{
x = x * 8 + c - '0';
c = *++start;
}
str += (char)(x & 0xff);
}
else
{
const static char *tr1 = "tnrbfva";
const static char *tr2 = "\t\n\r\b\f\013\007";
for (int i=0; tr1[i]; i++)
if (c == tr1[i])
c = tr2[i];
start += 1;
str += c;
}
}
else
{
G_THROW( ByteStream::EndOfFile );
}
}
return GLToken(GLToken::OBJECT,
new GLObject(GLObject::STRING, str));
}
else
{
GUTF8String str;
while(1)
{
char ch=*start++;
if (!ch)
G_THROW( ByteStream::EndOfFile );
if (ch==')') { start--; break; }
if (isspace(ch)) break;
str+=ch;
}
return GLToken(GLToken::OBJECT, new GLObject(GLObject::SYMBOL, str));
}
}
void
GLParser::parse(const char * cur_name, GPList<GLObject> & list,
const char * & start)
{
DEBUG_MSG("GLParse::parse(): Parsing contents of object '" << cur_name << "'\n");
DEBUG_MAKE_INDENT(3);
while(1)
{
GLToken token=get_token(start);
if (token.type==GLToken::OPEN_PAR)
{
if (isspace(*start))
{
GUTF8String mesg=GUTF8String( ERR_MSG("DjVuAnno.paren") "\t")+cur_name;
G_THROW(mesg);
}
GLToken tok=get_token(start);
GP<GLObject> object=tok.object; // This object should be SYMBOL
// We will convert it to LIST later
if (tok.type!=GLToken::OBJECT || object->get_type()!=GLObject::SYMBOL)
{
if (tok.type==GLToken::OPEN_PAR ||
tok.type==GLToken::CLOSE_PAR)
{
GUTF8String mesg=GUTF8String( ERR_MSG("DjVuAnno.no_paren") "\t")+cur_name;
G_THROW(mesg);
}
if (tok.type==GLToken::OBJECT)
{
GLObject::GLObjectType type=object->get_type();
if (type==GLObject::NUMBER)
{
GUTF8String mesg( ERR_MSG("DjVuAnno.no_number") "\t");
mesg += cur_name;
G_THROW(mesg);
}
else if (type==GLObject::STRING)
{
GUTF8String mesg( ERR_MSG("DjVuAnno.no_string") "\t");
mesg += cur_name;
G_THROW(mesg);
}
}
}
// OK. Get the object contents
GPList<GLObject> new_list;
G_TRY
{
parse(object->get_symbol(), new_list, start);
}
G_CATCH(exc)
{
if (exc.cmp_cause(ByteStream::EndOfFile))
G_RETHROW;
}
G_ENDCATCH;
list.append(new GLObject(object->get_symbol(), new_list));
continue;
}
if (token.type==GLToken::CLOSE_PAR)
return;
list.append(token.object);
}
}
void
GLParser::check_compat(const char *s)
{
int state = 0;
while (s && *s && !compat)
{
switch(state)
{
case 0:
if (*s == '\"')
state = '\"';
break;
case '\"':
if (*s == '\"')
state = 0;
else if (*s == '\\')
state = '\\';
else if ((unsigned char)(*s)<0x20 || *s==0x7f)
compat = true;
break;
case '\\':
if (!strchr("01234567tnrbfva\"\\",*s))
compat = true;
state = '\"';
break;
}
s += 1;
}
}
void
GLParser::parse(const char * str)
{
DEBUG_MSG("GLParser::parse(): parsing string contents\n");
DEBUG_MAKE_INDENT(3);
G_TRY
{
check_compat(str);
parse("toplevel", list, str);
} G_CATCH(exc)
{
if (exc.cmp_cause(ByteStream::EndOfFile))
G_RETHROW;
} G_ENDCATCH;
}
void
GLParser::print(ByteStream & str, int compact)
{
for(GPosition pos=list;pos;++pos)
list[pos]->print(str, compact);
}
GP<GLObject>
GLParser::get_object(const char * name, bool last)
{
GP<GLObject> object;
for(GPosition pos=list;pos;++pos)
{
GP<GLObject> obj=list[pos];
if (obj->get_type()==GLObject::LIST &&
obj->get_name()==name)
{
object=obj;
if (!last) break;
}
}
return object;
}
//***************************************************************************
//********************************** ANT ************************************
//***************************************************************************
static const char *zoom_strings[]={
"default","page","width","one2one","stretch"};
static const int zoom_strings_size=sizeof(zoom_strings)/sizeof(const char *);
static const char *mode_strings[]={
"default","color","fore","back","bw"};
static const int mode_strings_size=sizeof(mode_strings)/sizeof(const char *);
static const char *align_strings[]={
"default","left","center","right","top","bottom"};
static const int align_strings_size=sizeof(align_strings)/sizeof(const char *);
#define PNOTE_TAG "pnote"
#define BACKGROUND_TAG "background"
#define ZOOM_TAG "zoom"
#define MODE_TAG "mode"
#define ALIGN_TAG "align"
#define HALIGN_TAG "halign"
#define VALIGN_TAG "valign"
#define METADATA_TAG "metadata"
static const unsigned long default_bg_color=0xffffffff;
DjVuANT::DjVuANT(void)
{
bg_color=default_bg_color;
zoom=0;
mode=MODE_UNSPEC;
hor_align=ver_align=ALIGN_UNSPEC;
}
DjVuANT::~DjVuANT()
{
}
GUTF8String
DjVuANT::get_paramtags(void) const
{
GUTF8String retval;
if(zoom > 0)
{
retval+="<PARAM name=\"" ZOOM_TAG "\" value=\""+GUTF8String(zoom)+="\" />\n";
}else if(zoom && ((-zoom)<zoom_strings_size))
{
retval+="<PARAM name=\"" ZOOM_TAG "\" value=\""+GUTF8String(zoom_strings[-zoom])+"\" />\n";
}
if((mode>0)&&(mode<mode_strings_size))
{
retval+="<PARAM name=\"" MODE_TAG "\" value=\""+GUTF8String(mode_strings[mode])+"\" />\n";
}
if((hor_align>ALIGN_UNSPEC)&&(hor_align<align_strings_size))
{
retval+="<PARAM name=\"" HALIGN_TAG "\" value=\""+GUTF8String(align_strings[hor_align])+"\" />\n";
}
if((ver_align>ALIGN_UNSPEC)&&(ver_align<align_strings_size))
{
retval+="<PARAM name=\"" VALIGN_TAG "\" value=\""+GUTF8String(align_strings[ver_align])+"\" />\n";
}
if((bg_color&0xffffff) == bg_color)
{
retval+="<PARAM name=\"" BACKGROUND_TAG "\" value=\""+GUTF8String().format("#%06lX",bg_color)+"\" />\n";
}
return retval;
}
void
DjVuANT::writeParam(ByteStream &str_out) const
{
str_out.writestring(get_paramtags());
}
GUTF8String
DjVuANT::get_xmlmap(const GUTF8String &name,const int height) const
{
GUTF8String retval("<MAP name=\""+name.toEscaped()+"\" >\n");
for(GPosition pos(map_areas);pos;++pos)
{
retval+=map_areas[pos]->get_xmltag(height);
}
return retval+"</MAP>\n";
}
void
DjVuANT::writeMap(
ByteStream &str_out,const GUTF8String &name,const int height) const
{
str_out.writestring("<MAP name=\""+name.toEscaped()+"\" >\n");
for(GPosition pos(map_areas);pos;++pos)
{
str_out.writestring(GUTF8String(map_areas[pos]->get_xmltag(height)));
}
str_out.writestring(GUTF8String("</MAP>\n"));
}
GUTF8String
DjVuANT::read_raw(ByteStream & str)
{
GUTF8String raw;
char buffer[1024];
int length;
while((length=str.read(buffer, 1024)))
raw+=GUTF8String(buffer, length);
return raw;
}
void
DjVuANT::decode(class GLParser & parser)
{
bg_color=get_bg_color(parser);
zoom=get_zoom(parser);
mode=get_mode(parser);
hor_align=get_hor_align(parser);
ver_align=get_ver_align(parser);
map_areas=get_map_areas(parser);
#ifndef NO_METADATA_IN_ANT_CHUNK
metadata=get_metadata(parser);
#endif
}
void
DjVuANT::decode(ByteStream & str)
{
GLParser parser(read_raw(str));
decode(parser);
}
void
DjVuANT::merge(ByteStream & str)
{
GLParser parser(encode_raw());
GUTF8String add_raw=read_raw(str);
parser.parse(add_raw);
decode(parser);
}
void
DjVuANT::encode(ByteStream &bs)
{
GUTF8String raw=encode_raw();
bs.writall((const char*) raw, raw.length());
}
unsigned int
DjVuANT::get_memory_usage() const
{
return sizeof(DjVuANT);
}
unsigned char
DjVuANT::decode_comp(char ch1, char ch2)
{
unsigned char dig1=0;
if (ch1)
{
ch1=toupper(ch1);
if (ch1>='0' && ch1<='9') dig1=ch1-'0';
if (ch1>='A' && ch1<='F') dig1=10+ch1-'A';
unsigned char dig2=0;
if (ch2)
{
ch2=toupper(ch2);
if (ch2>='0' && ch2<='9') dig2=ch2-'0';
if (ch2>='A' && ch2<='F') dig2=10+ch2-'A';
return (dig1 << 4) | dig2;
}
return dig1;
}
return 0;
}
unsigned long int
DjVuANT::cvt_color(const char * color, unsigned long int def)
{
if (color[0]!='#') return def;
unsigned long int color_rgb=0;
color++;
const char * start, * end;
// Do blue
end=color+strlen(color); start=end-2;
if (start<color) start=color;
if (end>start)
color_rgb|=decode_comp(start[0], start+1<end ? start[1] : 0);
// Do green
end=color+strlen(color)-2; start=end-2;
if (start<color) start=color;
if (end>start)
color_rgb|=decode_comp(start[0], start+1<end ? start[1] : 0) << 8;
// Do red
end=color+strlen(color)-4; start=end-2;
if (start<color) start=color;
if (end>start)
color_rgb|=decode_comp(start[0], start+1<end ? start[1] : 0) << 16;
// Do the fourth byte
end=color+strlen(color)-6; start=end-2;
if (start<color) start=color;
if (end>start)
color_rgb|=decode_comp(start[0], start+1<end ? start[1] : 0) << 24;
return color_rgb;
}
unsigned long int
DjVuANT::get_bg_color(GLParser & parser)
{
unsigned long retval=default_bg_color;
DEBUG_MSG("DjVuANT::get_bg_color(): getting background color ...\n");
DEBUG_MAKE_INDENT(3);
G_TRY
{
GP<GLObject> obj=parser.get_object(BACKGROUND_TAG);
if (obj && obj->get_list().size()==1)
{
GUTF8String color=(*obj)[0]->get_symbol();
DEBUG_MSG("color='" << color << "'\n");
retval=cvt_color(color, 0xffffff);
}
#ifndef NDEBUG
if(retval == default_bg_color)
{
DEBUG_MSG("can't find any.\n");
}
#endif // NDEBUG
} G_CATCH_ALL {} G_ENDCATCH;
#ifndef NDEBUG
if(retval == default_bg_color)
{
DEBUG_MSG("resetting color to 0xffffffff (UNSPEC)\n");
}
#endif // NDEBUG
return retval;
}
int
DjVuANT::get_zoom(GLParser & parser)
// Returns:
// <0 - special zoom (like ZOOM_STRETCH)
// =0 - not set
// >0 - numeric zoom (%%)
{
int retval=ZOOM_UNSPEC;
DEBUG_MSG("DjVuANT::get_zoom(): getting zoom factor ...\n");
DEBUG_MAKE_INDENT(3);
G_TRY
{
GP<GLObject> obj=parser.get_object(ZOOM_TAG);
if (obj && obj->get_list().size()==1)
{
const GUTF8String zoom((*obj)[0]->get_symbol());
DEBUG_MSG("zoom='" << zoom << "'\n");
for(int i=0;(i<zoom_strings_size);++i)
{
if(zoom == zoom_strings[i])
{
retval=(-i);
break;
}
}
if(retval == ZOOM_UNSPEC)
{
if (zoom[0]!='d')
{
G_THROW( ERR_MSG("DjVuAnno.bad_zoom") );
}else
{
retval=zoom.substr(1, zoom.length()).toInt(); //atoi((const char *) zoom+1);
}
}
}
#ifndef NDEBUG
if(retval == ZOOM_UNSPEC)
{
DEBUG_MSG("can't find any.\n");
}
#endif // NDEBUG
} G_CATCH_ALL {} G_ENDCATCH;
#ifndef NDEBUG
if(retval == ZOOM_UNSPEC)
{
DEBUG_MSG("resetting zoom to 0 (UNSPEC)\n");
}
#endif // NDEBUG
return retval;
}
int
DjVuANT::get_mode(GLParser & parser)
{
int retval=MODE_UNSPEC;
DEBUG_MSG("DjVuAnt::get_mode(): getting default mode ...\n");
DEBUG_MAKE_INDENT(3);
G_TRY
{
GP<GLObject> obj=parser.get_object(MODE_TAG);
if (obj && obj->get_list().size()==1)
{
const GUTF8String mode((*obj)[0]->get_symbol());
DEBUG_MSG("mode='" << mode << "'\n");
for(int i=0;(i<mode_strings_size);++i)
{
if(mode == mode_strings[i])
{
retval=i;
break;
}
}
}
#ifndef NDEBUG
if(retval == MODE_UNSPEC)
{
DEBUG_MSG("can't find any.\n");
}
#endif // NDEBUG
} G_CATCH_ALL {} G_ENDCATCH;
#ifndef NDEBUG
if(retval == MODE_UNSPEC)
{
DEBUG_MSG("resetting mode to MODE_UNSPEC\n");
}
#endif // NDEBUG
return retval;
}
static inline DjVuANT::alignment
legal_halign(const int i)
{
DjVuANT::alignment retval;
switch((DjVuANT::alignment)i)
{
case DjVuANT::ALIGN_LEFT:
case DjVuANT::ALIGN_CENTER:
case DjVuANT::ALIGN_RIGHT:
retval=(DjVuANT::alignment)i;
break;
default:
retval=DjVuANT::ALIGN_UNSPEC;
break;
}
return retval;
}
static inline DjVuANT::alignment
legal_valign(const int i)
{
DjVuANT::alignment retval;
switch((DjVuANT::alignment)i)
{
case DjVuANT::ALIGN_CENTER:
case DjVuANT::ALIGN_TOP:
case DjVuANT::ALIGN_BOTTOM:
retval=(DjVuANT::alignment)i;
break;
default:
retval=DjVuANT::ALIGN_UNSPEC;
break;
}
return retval;
}
DjVuANT::alignment
DjVuANT::get_hor_align(GLParser & parser)
{
DEBUG_MSG("DjVuAnt::get_hor_align(): getting hor page alignemnt ...\n");
DEBUG_MAKE_INDENT(3);
alignment retval=ALIGN_UNSPEC;
G_TRY
{
GP<GLObject> obj=parser.get_object(ALIGN_TAG);
if (obj && obj->get_list().size()==2)
{
const GUTF8String align((*obj)[0]->get_symbol());
DEBUG_MSG("hor_align='" << align << "'\n");
for(int i=(int)ALIGN_UNSPEC;(i<align_strings_size);++i)
{
const alignment j=legal_halign(i);
if((i == (int)j)&&(align == align_strings[i]))
{
retval=j;
break;
}
}
}
#ifndef NDEBUG
if(retval == ALIGN_UNSPEC)
{
DEBUG_MSG("can't find any.\n");
}
#endif // NDEBUG
} G_CATCH_ALL {} G_ENDCATCH;
#ifndef NDEBUG
if(retval == ALIGN_UNSPEC)
{
DEBUG_MSG("resetting alignment to ALIGN_UNSPEC\n");
}
#endif // NDEBUG
return retval;
}
DjVuANT::alignment
DjVuANT::get_ver_align(GLParser & parser)
{
DEBUG_MSG("DjVuAnt::get_ver_align(): getting vert page alignemnt ...\n");
DEBUG_MAKE_INDENT(3);
alignment retval=ALIGN_UNSPEC;
G_TRY
{
GP<GLObject> obj=parser.get_object(ALIGN_TAG);
if (obj && obj->get_list().size()==2)
{
const GUTF8String align((*obj)[1]->get_symbol());
DEBUG_MSG("ver_align='" << align << "'\n");
for(int i=(int)ALIGN_UNSPEC;(i<align_strings_size);++i)
{
const alignment j=legal_valign(i);
if((i == (int)j)&&(align == align_strings[i]))
{
retval=j;
break;
}
}
}
#ifndef NDEBUG
if(retval == ALIGN_UNSPEC)
{
DEBUG_MSG("can't find any.\n");
}
#endif // NDEBUG
} G_CATCH_ALL {} G_ENDCATCH;
#ifndef NDEBUG
if(retval == ALIGN_UNSPEC)
{
DEBUG_MSG("resetting alignment to ALIGN_UNSPEC\n");
}
#endif // NDEBUG
return retval;
}
#ifndef NO_METADATA_IN_ANT_CHUNK
GMap<GUTF8String, GUTF8String>
DjVuANT::get_metadata(GLParser & parser)
{
DEBUG_MSG("DjVuANT::get_map_areas(): forming and returning back list of map areas\n");
DEBUG_MAKE_INDENT(3);
GMap<GUTF8String, GUTF8String> mdata;
GPList<GLObject> list=parser.get_list();
for(GPosition pos=list;pos;++pos)
{
GLObject & obj=*list[pos];
if (obj.get_type()==GLObject::LIST && obj.get_name()==METADATA_TAG)
{
G_TRY
{
for(int obj_num=0;obj_num<obj.get_list().size();obj_num++)
{
GLObject & el=*obj[obj_num];
const int type = el.get_type();
if (type == GLObject::LIST)
{
const GUTF8String & name=el.get_name();
mdata[name]=(el[0])->get_string();
}
}
}
G_CATCH_ALL { } G_ENDCATCH;
}
}
return mdata;
}
#endif
GPList<GMapArea>
DjVuANT::get_map_areas(GLParser & parser)
{
DEBUG_MSG("DjVuANT::get_map_areas(): forming and returning back list of map areas\n");
DEBUG_MAKE_INDENT(3);
GPList<GMapArea> map_areas;
GPList<GLObject> list=parser.get_list();
for(GPosition pos=list;pos;++pos)
{
GLObject & obj=*list[pos];
const int type=obj.get_type();
if (type == GLObject::LIST)
{
const GUTF8String name=obj.get_name();
if(name == GMapArea::MAPAREA_TAG)
{
G_TRY {
// Getting the url
GUTF8String url;
GUTF8String target=GMapArea::TARGET_SELF;
GLObject & url_obj=*(obj[0]);
if (url_obj.get_type()==GLObject::LIST)
{
if (url_obj.get_name()!=GMapArea::URL_TAG)
G_THROW( ERR_MSG("DjVuAnno.bad_url") );
url=(url_obj[0])->get_string();
target=(url_obj[1])->get_string();
} else url=url_obj.get_string();
// Getting the comment
GUTF8String comment=(obj[1])->get_string();
DEBUG_MSG("found maparea '" << comment << "' (" <<
url << ":" << target << ")\n");
GLObject * shape=obj[2];
GP<GMapArea> map_area;
if (shape->get_type()==GLObject::LIST)
{
if (shape->get_name()==GMapArea::RECT_TAG)
{
DEBUG_MSG("it's a rectangle.\n");
GRect grect((*shape)[0]->get_number(),
(*shape)[1]->get_number(),
(*shape)[2]->get_number(),
(*shape)[3]->get_number());
GP<GMapRect> map_rect=GMapRect::create(grect);
map_area=(GMapRect *)map_rect;
} else if (shape->get_name()==GMapArea::POLY_TAG)
{
DEBUG_MSG("it's a polygon.\n");
int points=shape->get_list().size()/2;
GTArray<int> xx(points-1), yy(points-1);
for(int i=0;i<points;i++)
{
xx[i]=(*shape)[2*i]->get_number();
yy[i]=(*shape)[2*i+1]->get_number();
}
GP<GMapPoly> map_poly=GMapPoly::create(xx,yy,points);
map_area=(GMapPoly *)map_poly;
} else if (shape->get_name()==GMapArea::OVAL_TAG)
{
DEBUG_MSG("it's an ellipse.\n");
GRect grect((*shape)[0]->get_number(),
(*shape)[1]->get_number(),
(*shape)[2]->get_number(),
(*shape)[3]->get_number());
GP<GMapOval> map_oval=GMapOval::create(grect);
map_area=(GMapOval *)map_oval;
}
}
if (map_area)
{
map_area->url=url;
map_area->target=target;
map_area->comment=comment;
for(int obj_num=3;obj_num<obj.get_list().size();obj_num++)
{
GLObject * el=obj[obj_num];
if (el->get_type()==GLObject::LIST)
{
const GUTF8String & name=el->get_name();
if (name==GMapArea::BORDER_AVIS_TAG)
map_area->border_always_visible=true;
else if (name==GMapArea::HILITE_TAG)
{
GLObject * obj=el->get_list()[el->get_list().firstpos()];
if (obj->get_type()==GLObject::SYMBOL)
map_area->hilite_color=cvt_color(obj->get_symbol(), 0xff);
} else
{
int border_type=
name==GMapArea::NO_BORDER_TAG ? GMapArea::NO_BORDER :
name==GMapArea::XOR_BORDER_TAG ? GMapArea::XOR_BORDER :
name==GMapArea::SOLID_BORDER_TAG ? GMapArea::SOLID_BORDER :
name==GMapArea::SHADOW_IN_BORDER_TAG ? GMapArea::SHADOW_IN_BORDER :
name==GMapArea::SHADOW_OUT_BORDER_TAG ? GMapArea::SHADOW_OUT_BORDER :
name==GMapArea::SHADOW_EIN_BORDER_TAG ? GMapArea::SHADOW_EIN_BORDER :
name==GMapArea::SHADOW_EOUT_BORDER_TAG ? GMapArea::SHADOW_EOUT_BORDER : -1;
if (border_type>=0)
{
map_area->border_type=(GMapArea::BorderType) border_type;
for(GPosition pos=el->get_list();pos;++pos)
{
GLObject * obj=el->get_list()[pos];
if (obj->get_type()==GLObject::SYMBOL)
map_area->border_color=cvt_color(obj->get_symbol(), 0xff);
if (obj->get_type()==GLObject::NUMBER)
map_area->border_width=obj->get_number();
}
}
}
} // if (el->get_type()==...)
} // for(int obj_num=...)
map_areas.append(map_area);
} // if (map_area) ...
} G_CATCH_ALL {} G_ENDCATCH;
}
}
} // while(item==...)
DEBUG_MSG("map area list size = " << list.size() << "\n");
return map_areas;
}
void
DjVuANT::del_all_items(const char * name, GLParser & parser)
{
GPList<GLObject> & list=parser.get_list();
GPosition pos=list;
while(pos)
{
GLObject & obj=*list[pos];
if (obj.get_type()==GLObject::LIST &&
obj.get_name()==name)
{
GPosition this_pos=pos;
++pos;
list.del(this_pos);
} else ++pos;
}
}
GUTF8String
DjVuANT::encode_raw(void) const
{
GUTF8String buffer;
GLParser parser;
//*** Background color
del_all_items(BACKGROUND_TAG, parser);
if (bg_color!=default_bg_color)
{
buffer.format("(" BACKGROUND_TAG " #%02X%02X%02X)",
(unsigned int)((bg_color & 0xff0000) >> 16),
(unsigned int)((bg_color & 0xff00) >> 8),
(unsigned int)(bg_color & 0xff));
parser.parse(buffer);
}
//*** Zoom
del_all_items(ZOOM_TAG, parser);
if (zoom!=ZOOM_UNSPEC)
{
buffer="(" ZOOM_TAG " ";
const int i=1-zoom;
if((i>=0)&& (i<zoom_strings_size))
{
buffer+=zoom_strings[i];
}else
{
buffer+="d"+GUTF8String(zoom);
}
buffer+=")";
parser.parse(buffer);
}
//*** Mode
del_all_items(MODE_TAG, parser);
if (mode!=MODE_UNSPEC)
{
const int i=mode-1;
if((i>=0)&& (i<mode_strings_size))
{
buffer="(" MODE_TAG " " + GUTF8String(mode_strings[mode]) + ")";
}
parser.parse(buffer);
}
//*** Alignment
del_all_items(ALIGN_TAG, parser);
if (hor_align!=ALIGN_UNSPEC || ver_align!=ALIGN_UNSPEC)
{
buffer= GUTF8String("(" ALIGN_TAG " ")
+align_strings[((hor_align<ALIGN_UNSPEC)||
(hor_align>=align_strings_size))?ALIGN_UNSPEC:hor_align]
+" "+align_strings[((ver_align<ALIGN_UNSPEC)||
(ver_align>=align_strings_size))?ALIGN_UNSPEC:ver_align]+")";
parser.parse(buffer);
}
//*** Metadata
#ifndef NO_METADATA_IN_ANT_CHUNK
del_all_items(METADATA_TAG, parser);
if (!metadata.isempty())
{
GUTF8String mdatabuffer("(");
mdatabuffer += METADATA_TAG ;
for (GPosition pos=metadata; pos; ++pos)
mdatabuffer +=" (" + metadata.key(pos)+" \""+metadata[pos]+"\")";
mdatabuffer += " )";
parser.parse(mdatabuffer);
}
#endif
//*** Mapareas
del_all_items(GMapArea::MAPAREA_TAG, parser);
for(GPosition pos=map_areas;pos;++pos)
parser.parse(map_areas[pos]->print());
GP<ByteStream> gstr=ByteStream::create();
ByteStream &str=*gstr;
parser.print(str, 1);
GUTF8String ans;
int size = str.size();
str.seek(0);
str.read(ans.getbuf(size), size);
return ans;
}
bool
DjVuANT::is_empty(void) const
{
GUTF8String raw=encode_raw();
for(int i=raw.length()-1;i>=0;i--)
if (isspace(raw[i])) raw.setat(i, 0);
else break;
return raw.length()==0;
}
GP<DjVuANT>
DjVuANT::copy(void) const
{
GP<DjVuANT> ant=new DjVuANT(*this);
// Now process the list of hyperlinks.
ant->map_areas.empty();
for(GPosition pos=map_areas;pos;++pos)
ant->map_areas.append(map_areas[pos]->get_copy());
return ant;
}
//***************************************************************************
//******************************** DjVuAnno *********************************
//***************************************************************************
GUTF8String
DjVuAnno::get_xmlmap(const GUTF8String &name,const int height) const
{
return ant
?(ant->get_xmlmap(name,height))
:("<MAP name=\""+name.toEscaped()+"\"/>\n");
}
void
DjVuAnno::writeMap(ByteStream &str_out,const GUTF8String &name,const int height) const
{
if(ant)
{
ant->writeMap(str_out,name,height);
}else
{
str_out.writestring(get_xmlmap(name,height));
}
}
GUTF8String
DjVuAnno::get_paramtags(void) const
{
return ant
?(ant->get_paramtags())
:GUTF8String();
}
void
DjVuAnno::writeParam(ByteStream &str_out) const
{
str_out.writestring(get_paramtags());
}
void
DjVuAnno::decode(const GP<ByteStream> &gbs)
{
GUTF8String chkid;
GP<IFFByteStream> giff=IFFByteStream::create(gbs);
IFFByteStream &iff=*giff;
while( iff.get_chunk(chkid) )
{
if (chkid == "ANTa")
{
if (ant) {
ant->merge(*iff.get_bytestream());
} else {
ant=DjVuANT::create();
ant->decode(*iff.get_bytestream());
}
}
else if (chkid == "ANTz")
{
GP<ByteStream> gbsiff=BSByteStream::create(giff->get_bytestream());
if (ant) {
ant->merge(*gbsiff);
} else {
ant=DjVuANT::create();
ant->decode(*gbsiff);
}
}
// Add decoding of other chunks here
iff.close_chunk();
}
}
void
DjVuAnno::encode(const GP<ByteStream> &gbs)
{
GP<IFFByteStream> giff=IFFByteStream::create(gbs);
IFFByteStream &iff=*giff;
if (ant)
{
#if 0
iff.put_chunk("ANTa");
ant->encode(iff);
iff.close_chunk();
#else
iff.put_chunk("ANTz");
{
// GP<ByteStream> bsbinput = giff.get_bytestream();
GP<ByteStream> bsb = BSByteStream::create(giff->get_bytestream(), 50);
ant->encode(*bsb);
}
iff.close_chunk();
#endif
}
// Add encoding of other chunks here
}
GP<DjVuAnno>
DjVuAnno::copy(void) const
{
GP<DjVuAnno> anno= new DjVuAnno;
// Copy any primitives (if any)
*anno=*this;
// Copy each substructure
if (ant) anno->ant = ant->copy();
return anno;
}
void
DjVuAnno::merge(const GP<DjVuAnno> & anno)
{
if (anno)
{
GP<ByteStream> gstr=ByteStream::create();
encode(gstr);
anno->encode(gstr);
gstr->seek(0);
decode(gstr);
}
}
#ifdef HAVE_NAMESPACES
}
# ifndef NOT_USING_DJVU_NAMESPACE
using namespace DJVU;
# endif
#endif
|