Debian Codegraph @

jade/MifFOTBuilder.cxx

raw
1 /* Copyright (c) 1998 ISOGEN International Corp.
2
3 Permission is hereby granted, free of charge, to any person obtaining
4 a copy of this software and associated documentation files (the
5 ``Software''), to deal in the Software without restriction, including
6 without limitation the rights to use, copy, modify, merge, publish,
7 distribute, sublicense, and/or sell copies of the Software, and to
8 permit persons to whom the Software is furnished to do so, subject to
9 the following conditions:
10
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
15 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL ISOGEN INTERNATIONAL CORP. BE LIABLE FOR ANY CLAIM,
18 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
20 THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of ISOGEN International
23 Corp. shall not be used in advertising or otherwise to promote the
24 sale, use or other dealings in this Software without prior written
25 authorization from ISOGEN International Corp. */
26
27 /* Created by Kathleen Marszalek and Paul Prescod. */
28
29 #include "config.h"
30
31 #ifdef JADE_MIF
32
33 #include "MifFOTBuilder.h"
34 #include "MifMessages.h"
35 #include "TmpOutputByteStream.h"
36 #include <OpenSP/CharMap.h>
37 #include <OpenSP/CmdLineApp.h>
38 #include <OpenSP/ErrnoMessageArg.h>
39 #include "FOTBuilder.h"
40 #include <OpenSP/Hash.h>
41 #include <OpenSP/HashTable.h>
42 #include <OpenSP/IList.h>
43 #include <OpenSP/IQueue.h>
44 #include <OpenSP/InputSource.h>
45 #include <OpenSP/Message.h>
46 #include <OpenSP/OutputByteStream.h>
47 #include <OpenSP/Owner.h>
48 #include <OpenSP/PointerTable.h>
49 #include <OpenSP/StorageManager.h>
50 #include <OpenSP/StringC.h>
51 #include <OpenSP/Vector.h>
52 #include "dsssl_ns.h"
53
54 #include <assert.h>
55 #include <errno.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58
59 #ifdef DSSSL_NAMESPACE
60 namespace DSSSL_NAMESPACE {
61 #endif
62
63 //#define assert(exp) (void)( (exp) || (throw "assertion_failed", 0) )
64
65 #define PROPERTY( propertyType, propertyName ) \
66 propertyType propertyName; \
67 void set ## propertyName ( propertyType p ) \
68 { propertyName = p; setProperties |= f ## propertyName ;}
69
70 #define PROPERTY_OUT( propertyName ) \
71 if( properties & f ## propertyName ) \
72 os << '\n' << MifOutputByteStream::INDENT \
73 << "<" #propertyName " " << propertyName << ">";
74
75 #define VECTOR_OF_PROPERTIES( propertyType, propertyName ) \
76 Vector< propertyType > propertyName ## s; \
77 void propertyName ## sAreSet() \
78 { setProperties |= f ## propertyName ## s ;}
79
80 #define STATIC_PROPERTY( propertyType, propertyName ) \
81 static propertyType propertyName; \
82 static void set ## propertyName ( propertyType p ) \
83 { propertyName = p; setProperties |= f ## propertyName ;}
84
85 class StringHash {
86 public:
87 static unsigned long hash( const String<char> & );
88 };
89
90 class MifOutputByteStream;
91 class MifTmpOutputByteStream;
92 class MifDoc {
93
94 public:
95
96 MifDoc( const String<CmdLineApp::AppChar> &fileLoc, CmdLineApp *app );
97 ~MifDoc();
98 static MifDoc &curInstance() { assert( CurInstance != NULL ); return *CurInstance; }
99 static MifDoc *CurInstance;
100
101 struct T_indent {
102
103 T_indent( unsigned i ) : data( i ) {}
104 long data;
105 operator unsigned() const { return data; }
106 };
107
108 struct T_dimension {
109
110 T_dimension( long u = 0 ) : data( u ) {}
111 long data;
112 operator long() const { return data; }
113 T_dimension &operator=( long s ) { data = s; return *this; }
114 };
115
116 struct T_string : public String<char> {
117
118 T_string() : String<char>() {};
119 T_string( const String<char> &s ) : String<char>( s ) {};
120 T_string( String<CmdLineApp::AppChar> &s ) : String<char>()
121 { for( size_t i = 0; i < s.size(); i++ ) *this += char( s[i] ); }
122 T_string( const char *cS ) : String<char>( cS, strlen( cS ) ) {};
123 T_string &operator=( String<char> s ) { String<char>::operator=( s ); return *this; }
124 void escapeSpecialChars();
125 };
126
127 struct T_boolean {
128
129 T_boolean( bool b = false ) : data( b ) {}
130 bool data;
131 operator bool() const { return data; }
132 T_boolean &operator=( bool b ) { data = b; return *this; }
133 };
134
135 typedef T_string T_tagstring;
136 typedef T_string T_pathname;
137 typedef String<char> T_keyword;
138
139 typedef long T_integer;
140 typedef unsigned T_ID;
141 typedef long T_degrees;
142 typedef double T_percentage;
143 typedef long T_metric;
144
145 struct T_WH { T_dimension w, h; // width, height
146 T_WH( T_dimension w_, T_dimension h_ ) : w( w_ ), h( h_ ) {}
147 T_WH() : w( 0L ), h( 0L ) {} };
148 struct T_XY { T_dimension x, y;
149 T_XY( T_dimension x_, T_dimension y_ ) : x( x_ ), y( y_ ) {}
150 T_XY() : x( 0L ), y( 0L ) {} };
151 struct T_LTRB { T_dimension l, t, r, b; // left, top, right, bottom
152 T_LTRB( T_dimension l_, T_dimension t_, T_dimension r_, T_dimension b_ )
153 : l( l_ ), t( t_ ), r( r_ ), b( b_ ) {}
154 T_LTRB() : l( 0L ), t( 0L ), r( 0L ), b( 0L ) {} };
155 struct T_LTWH { T_dimension l, t, w, h; // left, top, width, height
156 T_LTWH( T_dimension l_, T_dimension t_, T_dimension w_, T_dimension h_ )
157 : l( l_ ), t( t_ ), w( w_ ), h( h_ ) {}
158 T_LTWH() : l( 0L ), t( 0L ), w( 0L ), h( 0L ) {} };
159 struct T_XYWH { T_dimension x, y, w, h; };
160
161
162 // special characters
163 static const String<char> sTab;
164 static const String<char> sHardSpace;
165 static const String<char> sSoftHyphen;
166 static const String<char> sHardHyphen;
167 static const String<char> sHardReturn;
168 static const String<char> sNumberSpace;
169 static const String<char> sThinSpace;
170 static const String<char> sEnSpace;
171 static const String<char> sEmSpace;
172 static const String<char> sCent;
173 static const String<char> sPound;
174 static const String<char> sYen;
175 static const String<char> sEnDash;
176 static const String<char> sEmDash;
177 static const String<char> sDagger;
178 static const String<char> sDoubleDagger;
179 static const String<char> sBullet;
180
181 // for tagged text flows
182 static const String<char> sA;
183
184 // FWeight
185 static const String<char> sRegular;
186 static const String<char> sBold;
187
188 // FAngle
189 // sRegular;
190 static const String<char> sItalic;
191
192 // FVar
193 // sRegular;
194
195 // FColor
196 static const String<char> sWhite;
197 static const String<char> sBlack;
198
199 // FUnderlining
200 static const String<char> sFNoUnderlining;
201 static const String<char> sFSingle;
202 static const String<char> sFDouble;
203 static const String<char> sFNumeric;
204
205 // FPosition
206 static const String<char> sFNormal;
207 static const String<char> sFSuperscript;
208 static const String<char> sFSubscript;
209
210 // FCase
211 static const String<char> sFAsTyped;
212 static const String<char> sFSmallCaps;
213 static const String<char> sFLowercase;
214 static const String<char> sFUppercase;
215
216 // FFamily
217 static const String<char> sTimesNewRoman;
218
219 struct FontFormat : public Link {
220
221 enum { fNone = 0, fFFamily = 0x1, fFAngle = 0x2, fFWeight = 0x4, fFVar = 0x8,
222 fFSize = 0x10, fFColor = 0x20, fFUnderlining = 0x40, fFOverline = 0x80,
223 fFStrike = 0x100, fFPosition = 0x200, fFPairKern = 0x400, fFCase = 0x800,
224 fFDX = 0x1000, fFDY = 0x2000, fFDW = 0x4000, fAll = 0x7FFF };
225 unsigned setProperties;
226
227 FontFormat() : setProperties( 0 ) {}
228
229 // font name
230 PROPERTY( T_string, FFamily );
231 PROPERTY( T_string, FAngle );
232 PROPERTY( T_string, FWeight );
233 PROPERTY( T_string, FVar );
234
235 // font size and color
236 PROPERTY( T_dimension, FSize );
237 PROPERTY( T_tagstring, FColor );
238
239 // font style
240 PROPERTY( T_keyword, FUnderlining );
241 PROPERTY( T_boolean, FOverline );
242 PROPERTY( T_boolean, FStrike );
243 PROPERTY( T_keyword, FPosition );
244 PROPERTY( T_boolean, FPairKern );
245 PROPERTY( T_keyword, FCase );
246
247 // kerning information
248 PROPERTY( T_percentage, FDX );
249 PROPERTY( T_percentage, FDY );
250 PROPERTY( T_percentage, FDW );
251
252 void setDSSSLDefaults() {
253
254 setFFamily( sTimesNewRoman );
255 setFAngle( sRegular );
256 setFWeight( sRegular );
257 setFVar( sRegular );
258 setFSize( 10000 );
259 setFColor( sBlack ),
260 setFUnderlining( sFNoUnderlining );
261 setFOverline( false );
262 setFStrike( false );
263 setFPosition( sFNormal );
264 setFPairKern( false );
265 setFCase( sFAsTyped );
266 setFDX( 0 );
267 setFDY( 0 );
268 setFDW( 0 );
269 }
270
271 enum FontStatement { stPgfFont, stFont };
272
273 unsigned compare( FontFormat &f );
274 void setFrom( FontFormat &f, unsigned properties );
275 void out( MifOutputByteStream &os, unsigned properties, FontStatement fontStatement );
276 void ffOut( MifOutputByteStream &os, unsigned properties, FontStatement fontStatement )
277 { out( os, properties, fontStatement ); }
278 void out( MifOutputByteStream &os, FontStatement fontStatement )
279 { out( os, setProperties, fontStatement ); }
280 void ffOut( MifOutputByteStream &os, FontStatement fontStatement )
281 { out( os, fontStatement ); }
282 void updateFrom( FontFormat & );
283 void ffUpdateFrom( FontFormat &f ) { updateFrom( f ); }
284 void clearSetProperties() { setProperties = 0; }
285 };
286
287 static const String<char> sNONE;
288
289 // paragraph formats
290 static const String<char> sDefaultPgfFormat;
291 static const String<char> sHeader;
292 static const String<char> sFooter;
293
294 // PgfAlignment
295 static const String<char> sLeftRight;
296 static const String<char> sLeft;
297 static const String<char> sRight;
298 static const String<char> sCenter;
299
300 // PgfLineSpacing
301 static const String<char> sFixed;
302 static const String<char> sProportional;
303
304 // PgfCellAlignment
305 static const String<char> sTop;
306 static const String<char> sMiddle;
307 static const String<char> sBottom;
308
309 // PgfPlacement
310 static const String<char> sAnywhere;
311 static const String<char> sColumnTop;
312 static const String<char> sPageTop;
313 static const String<char> sLPageTop;
314 static const String<char> sRPageTop;
315
316 // PgfPlacementStyle
317 static const String<char> sNormal;
318 static const String<char> sStraddle;
319
320 // PgfLanguage
321 static const String<char> sNoLanguage;
322 static const String<char> sUSEnglish;
323 static const String<char> sUKEnglish;
324 static const String<char> sGerman;
325 static const String<char> sSwissGerman;
326 static const String<char> sFrench;
327 static const String<char> sCanadianFrench;
328 static const String<char> sSpanish;
329 static const String<char> sCatalan;
330 static const String<char> sItalian;
331 static const String<char> sPortuguese;
332 static const String<char> sBrazilian;
333 static const String<char> sDanish;
334 static const String<char> sDutch;
335 static const String<char> sNorwegian;
336 static const String<char> sNynorsk;
337 static const String<char> sFinnish;
338 static const String<char> sSwedish;
339
340
341 // TStype
342 // sLeft;
343 // sRight;
344 // sCenter;
345 static const String<char> sDecimal;
346
347 // TSLeaderStr;
348 static const String<char> sSPACE;
349
350 struct TabStop {
351
352 enum { fNone = 0, fTSX = 0x1, fTSType = 0x2, fTSLeaderStr = 0x4,
353 fTSDecimalChar = 0x8, fAll = 0xF };
354 unsigned setProperties;
355
356 TabStop( T_keyword type = sLeft, T_dimension x = 0, T_string tSLeaderStr = sSPACE )
357 : TSX( x ), TSType( type ), setProperties( fTSType | fTSX )
358 { setTSLeaderStr( tSLeaderStr ); }
359
360 PROPERTY( T_dimension, TSX );
361 PROPERTY( T_keyword, TSType );
362 PROPERTY( T_string, TSLeaderStr );
363 PROPERTY( T_integer, TSDecimalChar );
364
365 void out( MifOutputByteStream &os );
366 };
367
368 struct ParagraphFormat : public FontFormat {
369
370 enum { fNone = 0, fPgfFIndent = 0x1, fPgfLIndent = 0x2, fPgfRIndent = 0x4,
371 fPgfAlignment = 0x8, fPgfSpBefore = 0x10, fPgfSpAfter = 0x20,
372 fPgfLineSpacing = 0x40, fPgfLeading = 0x80, fPgfWithPrev = 0x100,
373 fPgfWithNext = 0x200, fPgfBlockSize = 0x400, fPgfAutoNum = 0x800,
374 fPgfNumFormat = 0x1000, fPgfNumberFont = 0x2000, fPgfHyphenate = 0x4000,
375 fHyphenMaxLines = 0x8000, fHyphenMinPrefix = 0x10000,
376 fHyphenMinSuffix = 0x20000, fHyphenMinWord = 0x40000,
377 fPgfLetterSpace = 0x80000, fPgfLanguage = 0x100000,
378 fPgfCellAlignment = 0x200000, fPgfCellMargins = 0x400000,
379 fPgfCellLMarginFixed = 0x800000, fPgfCellTMarginFixed = 0x1000000,
380 fPgfCellRMarginFixed = 0x2000000, fPgfCellBMarginFixed = 0x4000000,
381 fPgfTag = 0x8000000, fTabStops = 0x10000000, fPgfPlacement = 0x20000000,
382 fPgfNumTabs = 0x40000000, fPgfPlacementStyle = 0x80000000,
383 fAll = 0xFFFFFFFF };
384 unsigned setProperties;
385
386 ParagraphFormat() : setProperties( 0 ) {}
387
388 // basic properties
389 PROPERTY( T_tagstring, PgfTag );
390 PROPERTY( T_dimension, PgfFIndent );
391 PROPERTY( T_dimension, PgfLIndent );
392 PROPERTY( T_dimension, PgfRIndent );
393 PROPERTY( T_keyword, PgfAlignment );
394 PROPERTY( T_dimension, PgfSpBefore );
395 PROPERTY( T_dimension, PgfSpAfter );
396 PROPERTY( T_keyword, PgfLineSpacing );
397 PROPERTY( T_dimension, PgfLeading );
398 PROPERTY( T_integer, PgfNumTabs );
399 Vector<TabStop> TabStops;
400
401 // default font properties
402
403 // pagination properties
404 PROPERTY( T_keyword, PgfPlacement );
405 PROPERTY( T_keyword, PgfPlacementStyle );
406 PROPERTY( T_boolean, PgfWithPrev );
407 PROPERTY( T_boolean, PgfWithNext );
408 PROPERTY( T_integer, PgfBlockSize );
409
410 // numbering properties
411 PROPERTY( T_boolean, PgfAutoNum );
412 PROPERTY( T_string, PgfNumFormat );
413 PROPERTY( T_tagstring, PgfNumberFont );
414
415 // advanced properties
416 PROPERTY( T_boolean, PgfHyphenate );
417 PROPERTY( T_integer, HyphenMaxLines );
418 PROPERTY( T_integer, HyphenMinPrefix );
419 PROPERTY( T_integer, HyphenMinSuffix );
420 PROPERTY( T_integer, HyphenMinWord );
421 PROPERTY( T_boolean, PgfLetterSpace );
422 PROPERTY( T_keyword, PgfLanguage );
423
424 // table cell properties
425 PROPERTY( T_keyword, PgfCellAlignment );
426 PROPERTY( T_LTRB, PgfCellMargins );
427 PROPERTY( T_boolean, PgfCellLMarginFixed );
428 PROPERTY( T_boolean, PgfCellTMarginFixed );
429 PROPERTY( T_boolean, PgfCellRMarginFixed );
430 PROPERTY( T_boolean, PgfCellBMarginFixed );
431
432 // miscellaneous properties
433 // none
434
435 void setDSSSLDefaults() {
436
437 FontFormat::setDSSSLDefaults();
438 setPgfFIndent( 0 );
439 setPgfLIndent( 0 );
440 setPgfRIndent( 0 );
441 setPgfAlignment( sLeft );
442 setPgfSpBefore( 0 );
443 setPgfSpAfter( 0 );
444 setPgfLineSpacing( sFixed );
445 setPgfLeading( 0 );
446 setPgfNumTabs( 0 );
447 setPgfWithPrev( false );
448 setPgfWithNext( false );
449 setPgfBlockSize( 2 );
450 setPgfAutoNum( false );
451 // setPgfNumFormat( sNONE );
452 // setPgfNumberFont( sNONE );
453 setPgfHyphenate( false );
454 setHyphenMaxLines( 999 );
455 setHyphenMinPrefix( 2 );
456 setHyphenMinSuffix( 2 );
457 setHyphenMinWord( 2 );
458 setPgfLetterSpace( false );
459 setPgfLanguage( sNoLanguage );
460 setPgfCellAlignment( sTop );
461 setPgfCellMargins( T_LTRB( 0, 0, 0, 0 ) );
462 setPgfCellLMarginFixed( true );
463 setPgfCellTMarginFixed( true );
464 setPgfCellRMarginFixed( true );
465 setPgfCellBMarginFixed( true );
466 // setPgfTag( sNONE );
467 setPgfPlacement( sAnywhere );
468 setPgfPlacementStyle( sNormal );
469 }
470
471 void forceSetProperties( unsigned properties, unsigned fontProperties )
472 { setProperties = properties; FontFormat::setProperties = fontProperties; }
473 unsigned &ffSetProperties() { return FontFormat::setProperties; }
474 unsigned compare( ParagraphFormat & );
475 void setFrom( ParagraphFormat &, unsigned, unsigned );
476 void out( MifOutputByteStream &os, unsigned, unsigned,
477 bool excludeCellProperties = true );
478 void out( MifOutputByteStream &os, bool excludeCellProperties = true )
479 { out( os, setProperties, (unsigned)FontFormat::setProperties,
480 excludeCellProperties ); }
481 void updateFrom( ParagraphFormat & );
482 void clearSetProperties() { setProperties = 0; FontFormat::clearSetProperties(); }
483 };
484
485 // DPageNumStyle
486 static const String<char> sArabic;
487 static const String<char> sUCRoman;
488 static const String<char> sLCRoman;
489 static const String<char> sUCAlpha;
490 static const String<char> sLCAlpha;
491
492 // DParity
493 static const String<char> sFirstLeft;
494 static const String<char> sFirstRight;
495
496 struct Document {
497
498 enum { fNone = 0, fDPageSize = 0x1, fDStartPage = 0x2, fDPageNumStyle = 0x4,
499 fDTwoSides = 0x8, fDParity = 0x10, fDMargins = 0x20, fDColumns = 0x40,
500 fDColumnGap = 0x80, fAll = 0xFF };
501 unsigned setProperties;
502
503 Document() : setProperties( fNone ) {}
504
505 // column properties
506 PROPERTY( T_LTRB, DMargins );
507 PROPERTY( T_integer, DColumns );
508 PROPERTY( T_dimension, DColumnGap );
509 PROPERTY( T_WH, DPageSize );
510
511 // pagination
512 PROPERTY( T_integer, DStartPage );
513 PROPERTY( T_keyword, DPageNumStyle );
514 PROPERTY( T_boolean, DTwoSides );
515 PROPERTY( T_keyword, DParity );
516
517 void out( MifOutputByteStream &os );
518 };
519
520 struct Object {
521
522 enum { fNone = 0, fID = 0x1, fPen = 0x2, fFill = 0x4, fPenWidth = 0x8,
523 fObjectNext = 0x10, fObColor = 0x20 };
524 unsigned setProperties;
525
526 Object( T_integer pen = 15, T_integer fill = 15, T_dimension penWidth = 0,
527 const T_tagstring &obColor = sBlack )
528 : setProperties( 0 )
529 { setID( ++IDCnt );
530 setPen( pen ); setFill( fill ); setPenWidth( penWidth ); setObColor( obColor ); }
531
532 static T_ID IDCnt;
533 PROPERTY( T_integer, ID );
534 PROPERTY( T_integer, Pen );
535 PROPERTY( T_integer, Fill );
536 PROPERTY( T_dimension, PenWidth );
537 PROPERTY( T_tagstring, ObColor );
538
539 void outObjectProperties( MifOutputByteStream &os );
540 virtual void out( MifOutputByteStream &os ) = 0;
541 };
542
543 // HeadCap/TailCap
544 static const String<char> sButt;
545 static const String<char> sRound;
546 static const String<char> sSquare;
547
548 struct PolyLine : public Object {
549
550 enum { fHeadCap = fObjectNext << 1, fTailCap = fHeadCap << 1 };
551
552 PolyLine( T_keyword cap, T_integer pen = 15, T_integer fill = 15,
553 T_dimension penWidth = 0,
554 const T_tagstring &obColor = sBlack )
555 : Object( pen, fill, penWidth, obColor ) { setHeadCap( cap ); setTailCap( cap ); }
556
557 PROPERTY( T_keyword, HeadCap );
558 PROPERTY( T_keyword, TailCap );
559 Vector<T_XY> Points;
560
561 void out( MifOutputByteStream &os );
562 };
563
564 struct ImportObject : public Object {
565
566 enum { fImportObFileDI = fObjectNext << 1, fBitMapDpi = fImportObFileDI << 1,
567 fShapeRect = fBitMapDpi << 1, fImportObFixedSize = fShapeRect << 1,
568 fNativeOrigin = fImportObFixedSize << 1 };
569
570 ImportObject( T_pathname importObFileDI, T_LTWH shapeRect,
571 T_boolean importObFixedSize = true, T_integer bitMapDpi = 72 ) : Object()
572 { setImportObFileDI( importObFileDI ); setShapeRect( shapeRect );
573 setImportObFixedSize( importObFixedSize ); setBitMapDpi( bitMapDpi ); }
574
575 PROPERTY( T_pathname, ImportObFileDI );
576 PROPERTY( T_integer, BitMapDpi );
577 PROPERTY( T_LTWH, ShapeRect );
578 PROPERTY( T_boolean, ImportObFixedSize );
579 PROPERTY( T_XY, NativeOrigin );
580
581 void out( MifOutputByteStream &os );
582 };
583
584 // FrameType
585 static const String<char> sInline;
586 static const String<char> sRunIntoParagraph;
587 static const String<char> sBelow;
588
589 // AnchorAlign
590 // Left
591 // Center
592 // Right
593 // Inside
594 // Outside
595
596 struct Frame : public Object {
597
598 enum { fShapeRect = fObjectNext << 1, fFrameType = fShapeRect << 1,
599 fNSOffset = fFrameType << 1, fBLOffset = fNSOffset << 1,
600 fAnchorAlign = fBLOffset << 1 };
601
602 Frame() : Object() {}
603
604 PROPERTY( T_LTWH, ShapeRect );
605 PROPERTY( T_keyword, FrameType );
606 PROPERTY( T_dimension, NSOffset );
607 PROPERTY( T_dimension, BLOffset );
608 PROPERTY( T_keyword, AnchorAlign );
609 Vector<Object*> Objects;
610
611 void out( MifOutputByteStream &os );
612 };
613
614 struct TextRect : public Object {
615
616 enum { fID = fObjectNext << 1, fShapeRect = fID << 1, fTRNumColumns = fShapeRect << 1,
617 fTRColumnGap = fTRNumColumns << 1, fTRColumnBalance = fTRColumnGap << 1 };
618
619 TextRect() : Object() {}
620 TextRect( T_LTWH shapeRect, T_integer tRNumColumns = 1, T_dimension tRColumnGap = 0,
621 bool tRColumnBalance = false )
622 : Object() { setShapeRect( shapeRect ); setTRNumColumns( tRNumColumns );
623 setTRColumnGap( tRColumnGap ); setTRColumnBalance( tRColumnBalance ); }
624
625 PROPERTY( T_LTWH, ShapeRect );
626 PROPERTY( T_integer, TRNumColumns );
627 PROPERTY( T_dimension, TRColumnGap );
628 PROPERTY( T_boolean, TRColumnBalance );
629
630 void out( MifOutputByteStream &os );
631 };
632
633 // PageType
634 static const String<char> sLeftMasterPage;
635 static const String<char> sRightMasterPage;
636 static const String<char> sOtherMasterPage;
637 static const String<char> sBodyPage;
638
639 // PageTag
640 static const String<char> sFirst;
641 // sLeft
642 // sRight
643
644 struct Page {
645
646 enum { fNone = 0, fPageType = 0x1, fPageTag = 0x2, fPageBackground = 0x4 };
647 unsigned setProperties;
648
649 Page( T_keyword pageType, T_tagstring pageTag = sNONE,
650 T_tagstring pageBackground = sNONE )
651 : PageType( pageType ), PageTag( pageTag ), PageBackground( pageBackground ),
652 setProperties( fPageType | fPageTag )
653 { if( PageTag != sNONE ) setProperties |= fPageTag;
654 if( PageBackground != sNONE ) setProperties |= fPageBackground; }
655 Page() : PageType( MifDoc::sRightMasterPage ), setProperties( fPageType ) {}
656
657 PROPERTY( T_keyword, PageType );
658 PROPERTY( T_tagstring, PageTag );
659 PROPERTY( T_tagstring, PageBackground ); // keyword in MIF
660 Vector<TextRect> TextRects;
661
662 void out( MifOutputByteStream &os );
663 };
664
665 struct TagStream {
666
667 enum TagStreamClass { tsTagStream, tsTextFlow, tsCell, tsPara } TagStreamClass;
668
669 TagStream( T_indent osIndent = 2 );
670 ~TagStream();
671
672 T_tagstring InitialPgfTag;
673 bool PgfTagUsed;
674
675 ParagraphFormat &format() { return Format; }
676 MifTmpOutputByteStream &content() { assert( Content != NULL ); return *Content; }
677 void setParagraphFormat( ParagraphFormat &pf ) { Format = pf; }
678
679 protected:
680 MifTmpOutputByteStream *Content;
681 ParagraphFormat Format;
682 };
683
684 struct TextFlow : public TagStream {
685
686 enum { fNone = 0, fTFTag = 0x1, fTFAutoConnect = 0x02 };
687 unsigned setProperties;
688
689 TextFlow() : setProperties( fNone ), TextRectIDUsed( false )
690 { TagStreamClass = tsTextFlow; }
691 TextFlow( const TextRect &textRect, bool body,
692 ParagraphFormat *format = NULL, T_tagstring pgfTag = sNONE );
693
694 T_ID TextRectID; // for ParaLine (not in MIF)
695 bool TextRectIDUsed;
696 PROPERTY( T_tagstring, TFTag );
697 PROPERTY( T_boolean, TFAutoConnect );
698
699 const TextRect *textRect() { assert( TextRect_ != NULL ); return TextRect_; }
700 void out( MifOutputByteStream &os, bool resolveCrossReferences = false );
701
702 protected:
703 const TextRect *TextRect_;
704 };
705
706 struct Para : public TagStream {
707
708 enum { fNone = 0, fPgfTag = 0x1, fParagraphFormat = 0x2 };
709 unsigned setProperties;
710
711 Para( T_indent osIndent = 2 )
712 : TagStream( osIndent ), setProperties( fParagraphFormat ), leaderTabsSet( false )
713 { TagStreamClass = tsPara; }
714
715 static bool currentlyOpened;
716 bool leaderTabsSet;
717 PROPERTY( T_tagstring, PgfTag );
718
719 ParagraphFormat &curFormat() { return CurFormat; }
720
721 void out( MifOutputByteStream &os );
722 void outProlog( MifOutputByteStream &os );
723
724 static void outSimpleProlog( MifOutputByteStream &os );
725 static void outEpilog( MifOutputByteStream &os );
726
727 protected:
728 ParagraphFormat CurFormat;
729
730 };
731
732 struct ParaLine {
733
734 enum { fNone = 0, fTextRectID = 0x1, fATbl = 0x2 };
735 static unsigned setProperties;
736
737 STATIC_PROPERTY( T_ID, TextRectID );
738 STATIC_PROPERTY( T_ID, ATbl );
739
740 static void outProlog( MifOutputByteStream &os );
741 static void outEpilog( MifOutputByteStream &os );
742 };
743
744 struct PgfCatalog {
745
746 Vector<ParagraphFormat> ParaFormats;
747 void out( MifOutputByteStream &os );
748 };
749
750 struct Color {
751
752 enum { fColorTag = 0x1, fColorCyan = 0x2, fColorMagenta = 0x4, fColorYellow = 0x8,
753 fColorBlack = 0x10 };
754 unsigned setProperties;
755
756 Color() : setProperties( 0 ) {}
757 Color( unsigned char red, unsigned char green, unsigned char blue );
758
759 PROPERTY( T_tagstring, ColorTag );
760 PROPERTY( T_percentage, ColorCyan );
761 PROPERTY( T_percentage, ColorMagenta );
762 PROPERTY( T_percentage, ColorYellow );
763 PROPERTY( T_percentage, ColorBlack );
764
765 static const String<char> &key( Color &color );
766 void out( MifOutputByteStream &os ) const;
767 };
768
769 struct ColorCatalog {
770
771 PointerTable<Color*,String<char>,StringHash,Color> Colors;
772 void out( MifOutputByteStream &os );
773 };
774
775 // TblAlignment
776 // Left
777 // Center
778 // Right
779 static const String<char> sInside;
780 static const String<char> sOutside;
781
782 struct Ruling {
783
784 enum { fNone = 0, fRulingTag = 0x1, fRulingPenWidth = 0x2, fRulingGap = 0x4,
785 fRulingPen = 0x8, fRulingLines = 0x10, fRulingColor = 0x20 };
786 unsigned setProperties;
787
788 Ruling() : setProperties( 0 ), RulingPenWidth( 1000 ), RulingGap( 1000 ),
789 RulingPen( 0 ), RulingLines( 1 ) {};
790 Ruling( T_tagstring RulingTag_ )
791 : setProperties( 0 ), RulingPenWidth( 1000 ), RulingGap( 1000 ),
792 RulingPen( 0 ), RulingLines( 1 )
793 { setRulingTag( RulingTag_ ); }
794
795 PROPERTY( T_tagstring, RulingTag );
796 PROPERTY( T_dimension, RulingPenWidth );
797 PROPERTY( T_dimension, RulingGap );
798 PROPERTY( T_tagstring, RulingColor );
799 PROPERTY( T_integer, RulingPen );
800 PROPERTY( T_integer, RulingLines );
801
802 static const String<char> &key( Ruling & );
803 void out( MifOutputByteStream &os ) const;
804 String<char> Key;
805
806 };
807
808 struct RulingCatalog {
809
810 PointerTable<Ruling*,String<char>,StringHash,Ruling> Rulings;
811 void out( MifOutputByteStream &os );
812 };
813
814 struct Cell : public TagStream {
815
816 enum { fNone = 0, fCellLRuling = 0x1, fCellBRuling = 0x2, fCellRRuling = 0x4,
817 fCellTRuling = 0x8, fCellColumns = 0x10, fCellRows = 0x20,
818 fCellFill = 0x40, fCellColor = 0x80 };
819 unsigned setProperties;
820
821 Cell( T_indent osIndent = 12 )
822 : TagStream( osIndent ), setProperties( 0 ) { TagStreamClass = tsCell; }
823
824 PROPERTY( T_integer, CellFill );
825 PROPERTY( T_tagstring, CellColor );
826 PROPERTY( T_tagstring, CellLRuling );
827 PROPERTY( T_tagstring, CellBRuling );
828 PROPERTY( T_tagstring, CellRRuling );
829 PROPERTY( T_tagstring, CellTRuling );
830 PROPERTY( T_integer, CellColumns );
831 PROPERTY( T_integer, CellRows );
832
833 void out( MifOutputByteStream &os, bool resolveCrossReferences = false );
834 };
835
836 struct Row {
837
838 Vector<Cell> Cells;
839
840 void out( MifOutputByteStream &os, bool resolveCrossReferences = false );
841 };
842
843 struct TblColumn {
844
845 enum { fNone = 0, fTblColumnNum = 0x1, fTblColumnWidth = 0x2 };
846 unsigned setProperties;
847
848 TblColumn() : setProperties( 0 ), TblColumnNum( 0 ), TblColumnWidth( 0 ) {};
849 TblColumn( T_integer TblColumnNum_, T_dimension TblColumnWidth_ )
850 : setProperties( 0 )
851 { setTblColumnNum( TblColumnNum_ ); setTblColumnWidth( TblColumnWidth_ ); }
852
853 PROPERTY( T_integer, TblColumnNum );
854 PROPERTY( T_dimension, TblColumnWidth );
855
856 void out( MifOutputByteStream &os );
857 };
858
859 // TblTitlePlacement
860 static const String<char> sNone;
861
862 struct TblFormat {
863
864 enum { fNone = 0, fTblTag = 0x1, fTblLIndent = 0x2, fTblRIndent = 0x4,
865 fTblSpBefore = 0x8, fTblSpAfter = 0x10, fTblAlignment = 0x20,
866 fTblCellMargins = 0x40, fTblWidth = 0x80, fTblTitlePlacement = 0x100,
867 fAll = 0x1ff };
868 unsigned setProperties;
869
870 TblFormat() : setProperties( 0 ) {}
871 TblFormat( T_tagstring TblTag_ ) : setProperties( 0 ) { setTblTag( TblTag_ ); }
872
873 void setDSSSLDefaults() {
874
875 setTblLIndent( 0 );
876 setTblRIndent( 0 );
877 setTblSpBefore( 0 );
878 setTblSpAfter( 0 );
879 setTblAlignment( sLeft );
880 setTblCellMargins( T_LTRB( 0, 0, 0, 0 ) );
881 setTblTitlePlacement( sNone );
882 }
883
884 // basic properties
885 PROPERTY( T_tagstring, TblTag );
886 PROPERTY( T_dimension, TblLIndent );
887 PROPERTY( T_dimension, TblRIndent );
888 PROPERTY( T_dimension, TblSpBefore );
889 PROPERTY( T_dimension, TblSpAfter );
890 PROPERTY( T_keyword, TblAlignment );
891 PROPERTY( T_LTRB, TblCellMargins );
892 PROPERTY( T_keyword, TblTitlePlacement );
893
894 // column properties
895 PROPERTY( T_dimension, TblWidth );
896 Vector<TblColumn> TblColumns;
897
898 void out( MifOutputByteStream &os );
899 };
900
901 struct TblCatalog {
902
903 Vector<TblFormat> TblFormats;
904 void out( MifOutputByteStream &os );
905 };
906
907 // TblTag
908 static const String<char> sDefaultTblFormat;
909
910 struct Tbl {
911
912 enum { fNone = 0, fTblID = 0x1, fTblTag = 0x2, fTblNumColumns = 0x4,
913 fTblColumnWidths = 0x8, fTblFormat = 0x10 };
914 unsigned setProperties;
915
916 Tbl() : setProperties( 0 ), TblIDUsed( false )
917 { setTblID( MifDoc::CurInstance->nextID() ); setTblTag( MifDoc::sDefaultTblFormat ); }
918
919 PROPERTY( T_ID, TblID );
920 PROPERTY( T_tagstring, TblTag );
921 bool TblIDUsed;
922 TblFormat tblFormat;
923
924 // table columns
925 PROPERTY( T_integer, TblNumColumns );
926 VECTOR_OF_PROPERTIES( T_dimension, TblColumnWidth );
927
928 // table rows
929 Vector<Row> TblH;
930 Vector<Row> TblBody;
931 Vector<Row> TblF;
932
933 void out( MifOutputByteStream &os, bool resolveCrossReferences = false );
934 };
935
936 // paragraph formats
937 static const String<char> sPageNumXRefFormatName;
938
939 struct XRefFormat {
940
941 enum { fXRefName = 0x1, fXRefDef = 0x2 };
942 unsigned setProperties;
943
944 XRefFormat() {}
945 XRefFormat( T_string XRefName_, T_string XRefDef_ )
946 { setXRefName( XRefName_ ); setXRefDef( XRefDef_ ); }
947
948 PROPERTY( T_string, XRefName );
949 PROPERTY( T_string, XRefDef );
950
951 void out( MifOutputByteStream &os );
952 };
953
954 static char escapeChar() { return '\x0'; }
955
956 struct CrossRefInfo {
957
958 enum InfoType { PotentialMarker, XRef, HypertextLink } Type;
959 CrossRefInfo() {}
960 CrossRefInfo
961 ( unsigned long groveIndex_, unsigned long elementIndex_, int tagIndent_,
962 InfoType type_, const Char *id, size_t idLen )
963 : groveIndex( groveIndex_ ), elementIndex( elementIndex_ ), tagIndent( tagIndent_ ),
964 Type( type_ ) { if( id != NULL && idLen > 0 ) sgmlId.assign( id, idLen ); }
965 InfoType type() { return Type; }
966 void out( MifOutputByteStream &os );
967 T_string crossRefText() const;
968
969 unsigned long groveIndex;
970 unsigned long elementIndex;
971 int tagIndent;
972 StringC sgmlId;
973 };
974
975 struct XRef {
976
977 enum { fXRefName = 0x1, fXRefSrcFile = 0x2, fXRefText = 0x4, fXRefSrcText };
978 unsigned setProperties;
979
980 XRef() {}
981 XRef( CrossRefInfo &crossRefInfo );
982 XRef( T_tagstring XRefName_, T_string XRefSrcText_, T_string XRefText_,
983 T_pathname XRefSrcFile_ )
984 { setXRefName( XRefName_ ); setXRefSrcText( XRefSrcText_ ); setXRefText( XRefText_ );
985 setXRefSrcFile( XRefSrcFile_ ); }
986
987 PROPERTY( T_tagstring, XRefName );
988 PROPERTY( T_string, XRefSrcText );
989 PROPERTY( T_pathname, XRefSrcFile );
990 PROPERTY( T_string, XRefText );
991
992 void out( MifOutputByteStream &os );
993 };
994
995 struct Marker {
996
997 enum Type { XRef = 9, Index = 2, Hypertext = 8, HypertextLink = 100,
998 HypertextDestination = 101 };
999 enum { fMType = 0x1, fMText = 0x2 };
1000 unsigned setProperties;
1001
1002 Marker() {}
1003 Marker( CrossRefInfo &crossRefInfo, bool linkDestinationMode = false );
1004 Marker( T_string MText_, Type MType_ = XRef )
1005 { setMText( MText_ ); setMType( T_integer( MType_ ) ); }
1006
1007 PROPERTY( T_integer, MType );
1008 PROPERTY( T_string, MText );
1009
1010 void out( MifOutputByteStream &os );
1011 };
1012
1013 struct BookComponent {
1014
1015 BookComponent() : epilogOs( NULL ), pageNumXRefFormatGenerated( false ) {}
1016 BookComponent( MifTmpOutputByteStream *epilogOs );
1017 void commit( const String<CmdLineApp::AppChar> &dirName,
1018 bool resolveCrossReferences = true );
1019
1020 String<CmdLineApp::AppChar> FileName;
1021 Vector<XRefFormat> XRefFormats;
1022 Document document;
1023 ColorCatalog colorCatalog;
1024 PgfCatalog pgfCatalog;
1025 TblCatalog tblCatalog;
1026 Vector<Frame> AFrames;
1027 Vector<Tbl> Tbls;
1028 Vector<Page> Pages;
1029 Vector<TextFlow> TextFlows;
1030 RulingCatalog rulingCatalog;
1031
1032 bool pageNumXRefFormatGenerated;
1033
1034 MifTmpOutputByteStream *epilogOs;
1035 };
1036
1037 struct ElementSet {
1038
1039 enum ReferenceType
1040 { AnyReference = 0xC000, LinkReference = 0x8000, PageReference = 0x4000 };
1041 static unsigned short LINK_TYPE_MASK( ReferenceType refType )
1042 { return (unsigned short)( refType ); }
1043 static const unsigned short BOOK_COMPONENT_INDEX_M() { return 0x3FFF; }
1044 ElementSet();
1045
1046 struct SgmlIdInfo {
1047 SgmlIdInfo( const StringC &sgmlId_, unsigned long groveIndex_ )
1048 : sgmlId( sgmlId_ ), groveIndex( groveIndex_ ), flags( 0 ) {}
1049 StringC sgmlId;
1050 unsigned short flags;
1051 unsigned long groveIndex;
1052 static const StringC &key( SgmlIdInfo &sgmlIdInfo)
1053 { return sgmlIdInfo.sgmlId; }
1054 };
1055
1056 SgmlIdInfo &enforceSgmlId( const StringC &sgmlId, unsigned long groveIndex );
1057 void setReferencedFlag( ReferenceType, unsigned long groveIndex, unsigned long n );
1058 void setReferencedFlag( ReferenceType, unsigned long groveIndex, const StringC &sgmlId );
1059 void setBookComponentIndex( unsigned long groveIndex, unsigned long n, int i );
1060 void setBookComponentIndex( unsigned long groveIndex, const StringC &sgmlId, int i );
1061 bool hasBeenReferenced( ReferenceType, unsigned long groveIndex, unsigned long n ) const;
1062 bool hasBeenReferenced( ReferenceType, unsigned long groveIndex, const StringC &sgmlId );
1063 int bookComponentIndex( unsigned long groveIndex, unsigned long n ) const;
1064 int bookComponentIndex( unsigned long groveIndex, const StringC &sgmlId );
1065
1066 private:
1067 PointerTable<SgmlIdInfo*,StringC,Hash,SgmlIdInfo> SgmlIdInfos;
1068 void add( unsigned long groveIndex, unsigned long n, unsigned short flags );
1069 bool getFlags( unsigned long groveIndex, unsigned long n, unsigned short &result ) const;
1070 Vector<Vector<unsigned short> > Flags;
1071 };
1072
1073 void commit();
1074
1075 void outTagEnd();
1076
1077 void outHexChar( unsigned code, MifOutputByteStream *o = NULL );
1078 void outHexChar( unsigned code, String<char> &targetString );
1079 void outSpecialChar( const String<char> &charName, MifOutputByteStream *o = NULL );
1080 void beginParaLine();
1081 void endParaLine();
1082 void outPageNumber();
1083 void outBreakingPara( T_keyword pgfPlacement );
1084 void outAFrame( T_ID ID, MifOutputByteStream &os );
1085
1086 Vector<BookComponent> &bookComponents() { return BookComponents; };
1087 BookComponent &bookComponent()
1088 { assert( bookComponents().size() > 0 ); return bookComponents().back(); }
1089
1090 void setCurOs( MifOutputByteStream &os ) { curOs = &os; }
1091 MifOutputByteStream &os() { assert( curOs != NULL ); return *curOs; }
1092
1093 void setCurTextFlow( TextFlow *tf ) { CurTextFlow = tf; }
1094 TextFlow *curTextFlow() { return CurTextFlow; }
1095
1096 void setCurCell( Cell *c ) { CurCell = c; }
1097 Cell *curCell() { return CurCell; }
1098
1099 void setCurTblNum( size_t n ) { CurTblNum = n; }
1100 Tbl *curTbl( bool assertNotNull = true )
1101 { if( assertNotNull ) assert( CurTblNum > 0 );
1102 return CurTblNum > 0 ? &bookComponent().Tbls[CurTblNum-1] : (Tbl *)NULL; }
1103
1104 void setCurPara( Para *p ) { CurPara = p; }
1105 Para *curPara( bool assertNotNull = true )
1106 { if( assertNotNull ) assert( CurPara != NULL ); return CurPara; }
1107
1108 void setCurParagraphFormat( ParagraphFormat &pf ) { CurFormat = pf; }
1109 ParagraphFormat &curFormat() { return CurFormat; }
1110
1111 TagStream &curTagStream()
1112 { assert( TagStreamStack.size() > 0 ); return *TagStreamStack.back(); }
1113
1114 void enterTextFlow( TextFlow &textFlow ) { enterTagStream( textFlow ); }
1115 void exitTextFlow() { setCurTextFlow( NULL ); exitTagStream(); }
1116
1117 void enterTableCell( Cell &cell ) { enterTagStream( cell ); }
1118 void exitTableCell() { setCurCell( NULL ); exitTagStream(); }
1119
1120 void enterPara( Para &p ) { enterTagStream( p ); }
1121 void exitPara() { setCurPara( NULL ); exitTagStream(); }
1122
1123 void enterBookComponent();
1124 void exitBookComponent();
1125 void enterTagStream( TagStream &tagStream );
1126 void exitTagStream();
1127 T_ID nextID() { return ++NextID; }
1128
1129 Document &document() { return bookComponent().document; }
1130 PgfCatalog &pgfCatalog() { return bookComponent().pgfCatalog; }
1131 TblCatalog &tblCatalog() { return bookComponent().tblCatalog; }
1132 RulingCatalog &rulingCatalog() { return bookComponent().rulingCatalog; }
1133 ColorCatalog &colorCatalog() { return bookComponent().colorCatalog; }
1134 Vector<Tbl> &tbls() { return bookComponent().Tbls; }
1135 Vector<Page> &pages() { return bookComponent().Pages; }
1136 Vector<TextFlow> &textFlows() { return bookComponent().TextFlows; }
1137 Vector<Frame> &aFrames() { return bookComponent().AFrames; }
1138 ElementSet &elements() { return Elements; }
1139 Vector<CrossRefInfo> &crossRefInfos() { return CrossRefInfos; }
1140
1141 const String<CmdLineApp::AppChar> &rootOutputFileLoc() { return RootOutputFileLoc; }
1142
1143 CmdLineApp *App;
1144
1145 protected:
1146
1147 Vector<CrossRefInfo> CrossRefInfos;
1148 ElementSet Elements;
1149 void switchToTagStream( TagStream &tagStream, bool startWithDefaultPgfFormat = true );
1150
1151 String<CmdLineApp::AppChar> RootOutputFileLoc;
1152 T_ID NextID;
1153
1154 MifOutputByteStream *curOs;
1155
1156 Vector<BookComponent> BookComponents;
1157
1158 size_t CurTblNum;
1159 ParagraphFormat CurFormat;
1160 TextFlow *CurTextFlow;
1161 Cell *CurCell;
1162 Para *CurPara;
1163
1164 Vector<TagStream*> TagStreamStack;
1165 };
1166
1167 class MifOutputByteStream {
1168
1169 OutputByteStream *os;
1170
1171 public:
1172
1173 int CurTagIndent;
1174 static MifDoc::T_indent INDENT;
1175
1176 void indent() { CurTagIndent += 2; }
1177 void undent() { CurTagIndent -= 2; assert( CurTagIndent >= 0 ); }
1178 MifOutputByteStream( MifDoc::T_indent i = 0 )
1179 : os( NULL ), CurTagIndent( i ) {};
1180 MifOutputByteStream( OutputByteStream &os, MifDoc::T_indent i = 0 )
1181 : os( &os ), CurTagIndent( i ) {};
1182 void setStream( OutputByteStream &s ) { os = &s; }
1183 OutputByteStream &stream() { assert( os != NULL ); return *os; }
1184 MifOutputByteStream &operator<<( unsigned n ) { stream() << n; return *this; }
1185 MifOutputByteStream &operator<<( long n ) { stream() << n; return *this; }
1186 MifOutputByteStream &operator<<( char c ) { stream() << c; return *this; }
1187 MifOutputByteStream &operator<<( const char *s ) { stream() << s; return *this; }
1188 #ifdef SP_WIDE_SYSTEM
1189 MifOutputByteStream &operator<<( const String<CmdLineApp::AppChar> &s )
1190 { for( size_t i = 0; i < s.size(); i++ ) stream() << char( s[i] ); return *this; }
1191 #endif
1192 MifOutputByteStream &operator<<( const String<char> &s ) { stream() << s; return *this; }
1193 MifOutputByteStream &operator<<( const MifDoc::T_string &s )
1194 { stream() << '`'; stream() << s; stream() << '\''; return *this; }
1195 MifOutputByteStream &operator<<( const MifDoc::T_percentage &p ) {
1196 char buf[32];
1197 sprintf( buf, "%.6f", p );
1198 stream() << buf;
1199 return *this;
1200 }
1201 MifOutputByteStream &operator<<( const MifDoc::T_dimension &d ) {
1202 char buf[32];
1203 int i;
1204 sprintf( buf, "%li.%.3i%n", long(d)/1000, abs(long(d)%1000), &i );
1205 while( buf[--i] == '0' ) {}; if( buf[i] == '.' ) i--;
1206 buf[i+1] = '\0';
1207 stream() << buf << "pt";
1208 return *this;
1209 }
1210 MifOutputByteStream &operator<<( const MifDoc::CrossRefInfo &cri ) {
1211 Vector<MifDoc::CrossRefInfo> &crossRefInfos = MifDoc::CurInstance->crossRefInfos();
1212 unsigned idx = crossRefInfos.size();
1213 crossRefInfos.resize( crossRefInfos.size() + 1 );
1214 crossRefInfos.back() = cri;
1215 stream() << MifDoc::escapeChar();
1216 stream().sputn( (char*)&idx, sizeof( idx ) );
1217 return *this;
1218 }
1219 MifOutputByteStream &operator<<( const MifDoc::T_LTRB &b )
1220 { *this << b.l << " " << b.t << " " << b.r << " " << b.b; return *this; }
1221 MifOutputByteStream &operator<<( const MifDoc::T_LTWH &b )
1222 { *this << b.l << " " << b.t << " " << b.w << " " << b.h; return *this; }
1223 MifOutputByteStream &operator<<( const MifDoc::T_WH &s )
1224 { *this << s.w << " " << s.h; return *this; }
1225 MifOutputByteStream &operator<<( const MifDoc::T_XY &s )
1226 { *this << s.x << " " << s.y; return *this; }
1227 MifOutputByteStream &operator<<( const MifDoc::T_boolean &b )
1228 { if( bool(b) ) *this << "Yes"; else *this << "No"; return *this; }
1229 MifOutputByteStream &operator<<( const MifDoc::T_indent &i )
1230 { unsigned cnt = (i==INDENT) ? CurTagIndent : unsigned( i );
1231 for( ; cnt; cnt-- ) stream() << ' '; return *this; }
1232 };
1233
1234 class MifTmpOutputByteStream : public TmpOutputByteStream {
1235
1236 MifOutputByteStream os;
1237
1238 public:
1239 MifTmpOutputByteStream( MifDoc::T_indent osIndent = 0 )
1240 : TmpOutputByteStream(), os( osIndent ) { os.setStream( *this ); }
1241 void commit( OutputByteStream &os, bool resolveCrossReferences = false );
1242 void commit( String<char> &str );
1243 MifOutputByteStream &stream() { return os; }
1244 };
1245
1246 class MifFOTBuilder : public SerialFOTBuilder {
1247
1248 public:
1249 MifFOTBuilder( const String<CmdLineApp::AppChar> &fileLoc,
1250 const Ptr<ExtendEntityManager> &, const CharsetInfo &, CmdLineApp *app );
1251 ~MifFOTBuilder() {}
1252 static MifFOTBuilder &curInstance() { assert( CurInstance != NULL ); return *CurInstance; }
1253 static MifFOTBuilder *CurInstance;
1254
1255 struct IndexEntryNIC {
1256 IndexEntryNIC()
1257 : pageNumber( true ), startsPageRange( false ), endsPageRange( false ) {}
1258 StringC sortString;
1259 Vector<StringC> components;
1260 bool pageNumber;
1261 bool startsPageRange;
1262 bool endsPageRange;
1263 };
1264
1265 class MifExtensionFlowObj : public FOTBuilder::ExtensionFlowObj {
1266 public:
1267 virtual void atomic( MifFOTBuilder &, const NodePtr & ) const = 0;
1268 };
1269
1270 class IndexEntryFlowObj : public MifExtensionFlowObj {
1271 public:
1272 void atomic( MifFOTBuilder &fb, const NodePtr & ) const
1273 { fb.indexEntry( nic ); }
1274 bool hasNIC( const StringC &name ) const;
1275 void setNIC( const StringC &name, const Value &value );
1276 ExtensionFlowObj *copy() const { return new IndexEntryFlowObj(*this); }
1277 private:
1278 IndexEntryNIC nic;
1279 };
1280
1281 void extension( const ExtensionFlowObj &fo, const NodePtr & );
1282 void start();
1283 void end();
1284
1285 void startSimplePageSequenceSerial();
1286 void endSimplePageSequenceSerial();
1287 void startSimplePageSequenceHeaderFooter( unsigned );
1288 void endSimplePageSequenceHeaderFooter( unsigned );
1289 void endAllSimplePageSequenceHeaderFooter();
1290
1291 void indexEntry( const IndexEntryNIC & );
1292
1293 void setPageNColumns( long );
1294 void setPageColumnSep( Length );
1295 void setPageBalanceColumns( bool );
1296
1297 void startNode( const NodePtr &, const StringC & );
1298 void endNode();
1299 void currentNodePageNumber( const NodePtr & );
1300
1301 void startLink( const Address & );
1302 void endLink();
1303 void startLineField( const LineFieldNIC & );
1304 void endLineField();
1305 void doStartParagraph( const ParagraphNIC &, bool servesAsWrapper = false,
1306 MifDoc::T_dimension = 0, bool allowNegativeLeading = false );
1307 void startParagraph( const ParagraphNIC &nic ) { doStartParagraph( nic ); }
1308 void doEndParagraph( bool sustainFormatStack = false, bool sustainDisplayStack = false,
1309 bool paragraphBreakTest = true, bool discardThisPara = false );
1310 void endParagraph() { doEndParagraph(); }
1311 void startDisplayGroup( const DisplayGroupNIC & );
1312 void endDisplayGroup();
1313 void characters( const Char *, size_t );
1314 void paragraphBreak( const ParagraphNIC & );
1315 void externalGraphic( const ExternalGraphicNIC & );
1316 void rule( const RuleNIC & );
1317 void pageNumber();
1318 void startScore( Symbol );
1319 void endScore();
1320 void startLeader( const LeaderNIC & );
1321 void endLeader();
1322
1323 void startTable(const TableNIC &);
1324 void endTable();
1325 void startTablePartSerial(const TablePartNIC &);
1326 void endTablePartSerial();
1327 void startTablePartHeader();
1328 void endTablePartHeader();
1329 void startTablePartFooter();
1330 void endTablePartFooter();
1331 void tableColumn(const TableColumnNIC &);
1332 void startTableRow();
1333 void endTableRow();
1334 void startTableCell(const TableCellNIC &);
1335 void endTableCell();
1336
1337 void tableBeforeRowBorder();
1338 void tableAfterRowBorder();
1339 void tableBeforeColumnBorder();
1340 void tableAfterColumnBorder();
1341 void tableCellBeforeRowBorder();
1342 void tableCellAfterRowBorder();
1343 void tableCellBeforeColumnBorder();
1344 void tableCellAfterColumnBorder();
1345 // void setCellBeforeRowMargin(Length);
1346 // void setCellAfterRowMargin(Length);
1347 // void setCellBeforeColumnMargin(Length);
1348 // void setCellAfterColumnMargin(Length);
1349 void setCellBackground( bool );
1350 void setCellRowAlignment( Symbol );
1351 void setFontSize(Length);
1352 void setFontFamilyName( const StringC & );
1353 void setFontWeight( Symbol );
1354 void setFontPosture( Symbol );
1355 void setStartIndent( const LengthSpec & );
1356 void setEndIndent( const LengthSpec & );
1357 void setFirstLineStartIndent( const LengthSpec & );
1358 // void setLastLineEndIndent(const LengthSpec &);
1359 void setLineSpacing( const LengthSpec & );
1360 void setFieldWidth( const LengthSpec & );
1361 void setLines( Symbol );
1362 void setQuadding( Symbol );
1363 void setDisplayAlignment( Symbol );
1364 void setFieldAlign( Symbol );
1365 void setColor( const DeviceRGBColor & );
1366 void setBackgroundColor( const DeviceRGBColor & );
1367 void setBackgroundColor();
1368 void setPageWidth( Length );
1369 void setPageHeight( Length );
1370 void setLeftMargin( Length );
1371 void setRightMargin( Length );
1372 void setTopMargin( Length );
1373 void setBottomMargin( Length );
1374 void setHeaderMargin( Length );
1375 void setFooterMargin( Length );
1376 void setBorderPresent(bool);
1377 void setLineThickness(Length);
1378 void setCellBeforeRowMargin( Length );
1379 void setCellAfterRowMargin( Length );
1380 void setCellBeforeColumnMargin( Length );
1381 void setCellAfterColumnMargin( Length );
1382 void setLineSep(Length);
1383 // void setBoxSizeBefore(Length);
1384 // void setBoxSizeAfter(Length);
1385 void setPositionPointShift( const LengthSpec & );
1386 // void setStartMargin(const LengthSpec &);
1387 // void setEndMargin(const LengthSpec &);
1388 // void setSidelineSep(const LengthSpec &);
1389 // void setAsisWrapIndent(const LengthSpec &);
1390 // void setLineNumberSep(const LengthSpec &);
1391 // void setLastLineJustifyLimit(const LengthSpec &);
1392 // void setJustifyGlyphSpaceMaxAdd(const LengthSpec &);
1393 // void setJustifyGlyphSpaceMaxRemove(const LengthSpec &);
1394 // void setTableCornerRadius(const LengthSpec &);
1395 // void setBoxCornerRadius(const LengthSpec &);
1396 // void setMarginaliaSep(const LengthSpec &);
1397 // void setMinPreLineSpacing(const OptLengthSpec &);
1398 // void setMinPostLineSpacing(const OptLengthSpec &);
1399 void setMinLeading( const OptLengthSpec & );
1400 // void setInhibitLineBreaks(bool);
1401 void setHyphenate( bool );
1402 void setKern( bool );
1403 // void setLigature(bool);
1404 // void setScoreSpaces(bool);
1405 // void setFloatOutMarginalia(bool);
1406 // void setFloatOutSidelines(bool);
1407 // void setFloatOutLineNumbers(bool);
1408 // void setCellBackground(bool);
1409 // void setSpanWeak(bool);
1410 // void setIgnoreRecordEnd(bool);
1411 // void setNumberedLines(bool);
1412 // void setHangingPunct(bool);
1413 // void setBoxOpenEnd(bool);
1414 // void setTruncateLeader(bool);
1415 // void setAlignLeader(bool);
1416 // void setTablePartOmitMiddleHeader(bool);
1417 // void setTablePartOmitMiddleFooter(bool);
1418 void setBorderOmitAtBreak(bool);
1419 // void setPrincipalModeSimultaneous(bool);
1420 // void setMarginaliaKeepWithPrevious(bool);
1421 // void setGridEquidistantRows(bool);
1422 // void setGridEquidistantColumns(bool);
1423 // void setLineJoin(Symbol);
1424 void setLineCap( Symbol );
1425 // void setLineNumberSide(Symbol);
1426 // void setKernMode(Symbol);
1427 void setInputWhitespaceTreatment( Symbol );
1428 // void setFillingDirection(Symbol);
1429 // void setWritingMode(Symbol);
1430 // void setLastLineQuadding(Symbol);
1431 // void setMathDisplayMode(Symbol);
1432 // void setScriptPreAlign(Symbol);
1433 // void setScriptPostAlign(Symbol);
1434 // void setScriptMidSupAlign(Symbol);
1435 // void setScriptMidSubAlign(Symbol);
1436 // void setNumeratorAlign(Symbol);
1437 // void setDenominatorAlign(Symbol);
1438 // void setGridPositionCellType(Symbol);
1439 // void setGridColumnAlignment(Symbol);
1440 // void setGridRowAlignment(Symbol);
1441 // void setBoxType(Symbol);
1442 // void setGlyphAlignmentMode(Symbol);
1443 // void setBoxBorderAlignment(Symbol);
1444 // void setCellRowAlignment(Symbol);
1445 // void setBorderAlignment(Symbol);
1446 // void setSidelineSide(Symbol);
1447 // void setHyphenationKeep(Symbol);
1448 // void setPositionPreference(Symbol);
1449 // void setFontStructure(Symbol);
1450 // void setFontProportionateWidth(Symbol);
1451 // void setCellCrossed(Symbol);
1452 // void setMarginaliaSide(Symbol);
1453 // void setLayer(long);
1454 // void setBackgroundLayer(long);
1455 void setBorderPriority( long );
1456 void setLineRepeat( long );
1457 void setSpan( long );
1458 // void setMinLeaderRepeat(long);
1459 void setHyphenationRemainCharCount( long );
1460 void setHyphenationPushCharCount( long );
1461 void setWidowCount( long );
1462 void setOrphanCount( long );
1463 // void setExpandTabs(long);
1464 void setHyphenationLadderCount( long );
1465 // void setBackgroundTile(PublicId);
1466 // void setLineBreakingMethod(PublicId);
1467 // void setLineCompositionMethod(PublicId);
1468 // void setImplicitBidiMethod(PublicId);
1469 // void setGlyphSubstMethod(PublicId);
1470 // void setGlyphReorderMethod(PublicId);
1471 // void setHyphenationMethod(PublicId);
1472 // void setTableAutoWidthMethod(PublicId);
1473 // void setFontName(PublicId);
1474 void setLanguage (Letter2 );
1475 void setCountry( Letter2 );
1476 // void setEscapementSpaceBefore(const InlineSpace &);
1477 // void setEscapementSpaceAfter(const InlineSpace &);
1478 // void setGlyphSubstTable(const Vector<ConstPtr<GlyphSubstTable> > &);
1479
1480 struct DisplayInfo : public Link {
1481
1482 DisplayInfo( const DisplayNIC &nic, DisplayInfo *parentDs )
1483 : spaceBefore( nic.spaceBefore), spaceAfter( nic.spaceAfter ), keep( nic.keep ),
1484 breakAfter( nic.breakAfter ), breakBefore( nic.breakBefore ),
1485 keepWithPrevious( nic.keepWithPrevious ), keepWithNext( nic.keepWithNext ),
1486 mayViolateKeepBefore( nic.mayViolateKeepBefore ), isParagraph( false ),
1487 mayViolateKeepAfter( nic.mayViolateKeepAfter ), firstParaOutputed( false ),
1488 paragraphClosedInMif( false )
1489 { keepWithinPageInEffect = (nic.keep==symbolPage)
1490 ? true
1491 : (parentDs
1492 ? parentDs->keepWithinPageInEffect
1493 : false ); }
1494
1495 DisplaySpace spaceBefore;
1496 DisplaySpace spaceAfter;
1497 Symbol keep;
1498 Symbol breakBefore;
1499 Symbol breakAfter;
1500 bool keepWithPrevious;
1501 bool keepWithNext;
1502 bool mayViolateKeepBefore;
1503 bool mayViolateKeepAfter;
1504 bool firstParaOutputed;
1505 bool isParagraph;
1506 bool paragraphClosedInMif;
1507
1508 bool keepWithinPageInEffect;
1509 };
1510
1511 struct DisplaySpaceInfo : public Link {
1512
1513 DisplaySpaceInfo( DisplaySpace space_, Symbol breakType_, bool breakIsAfter_ )
1514 : space( space_ ), breakType( breakType_ ), breakIsAfter( breakIsAfter_ ) {}
1515
1516 DisplaySpace space;
1517 Symbol breakType;
1518 bool breakIsAfter;
1519 };
1520
1521 struct EffectiveDisplaySpace {
1522
1523 long nominal;
1524 long min;
1525 long max;
1526 long priority;
1527 bool conditional;
1528 bool force;
1529
1530 EffectiveDisplaySpace() { set(); }
1531 EffectiveDisplaySpace( long) { set(); }
1532
1533 void set( long nominal_ = 0, long min_ = 0, long max_ = 0, long priority_ = 0,
1534 bool conditional_ = true, bool force_ = false )
1535 { nominal = nominal_; min = min_; max = max_; priority = priority_;
1536 conditional = conditional_; force = force_; }
1537 void combine( const EffectiveDisplaySpace );
1538 void clear() { set(); }
1539 };
1540
1541 struct TFotSimplePageSequence {
1542
1543 TFotSimplePageSequence() : BodyTextFlow( NULL ), FirstHeaderTextFlow( NULL ),
1544 FirstFooterTextFlow( NULL ), LeftHeaderTextFlow( NULL ),
1545 LeftFooterTextFlow( NULL ), RightHeaderTextFlow( NULL ),
1546 RightFooterTextFlow( NULL ) {}
1547 MifDoc::TextFlow *BodyTextFlow;
1548 MifDoc::TextFlow *FirstHeaderTextFlow;
1549 MifDoc::TextFlow *FirstFooterTextFlow;
1550 MifDoc::TextFlow *LeftHeaderTextFlow;
1551 MifDoc::TextFlow *LeftFooterTextFlow;
1552 MifDoc::TextFlow *RightHeaderTextFlow;
1553 MifDoc::TextFlow *RightFooterTextFlow;
1554
1555 MifDoc::ParagraphFormat paragraphFormat;
1556
1557 };
1558
1559 struct Border {
1560
1561 Border( bool cellBorder_ = true )
1562 : cellBorder( cellBorder_ ), borderPresent( false ) {}
1563 long borderPriority;
1564 Length lineThickness;
1565 bool borderPresent;
1566 long lineRepeat;
1567 Length lineSep;
1568 bool cellBorder;
1569 MifDoc::T_tagstring color;
1570
1571 MifDoc::T_tagstring makeMifRuling( MifDoc &mifDoc );
1572 void resolve( Border &adjacentBorder );
1573 void setFromFot();
1574 };
1575
1576 struct Column {
1577
1578 Column() : hasWidth( 0 ) {}
1579 bool hasWidth;
1580 TableLengthSpec width;
1581 };
1582
1583 struct Cell {
1584
1585 Cell() : missing( false ), MifCell( new MifDoc::Cell ), OverlappingCell( NULL ),
1586 nRowsSpanned( 1 ), nColumnsSpanned( 1 ), displaySize( 0 ) {}
1587 bool missing;
1588
1589 unsigned nColumnsSpanned;
1590 unsigned nRowsSpanned;
1591 Border beforeRowBorder;
1592 Border afterRowBorder;
1593 Border beforeColumnBorder;
1594 Border afterColumnBorder;
1595 long displaySize;
1596
1597 Cell *OverlappingCell;
1598 MifDoc::Cell &mifCell()
1599 { assert( MifCell != NULL ); return *MifCell; }
1600 void translate( MifDoc::Cell &mifCell, MifDoc &mifDoc );
1601
1602 protected:
1603 MifDoc::Cell *MifCell;
1604 };
1605
1606 struct Row {
1607
1608 Row() {}
1609 Vector<Cell> Cells;
1610
1611 void translate( Vector<MifDoc::Row> &mifRows, MifDoc &mifDoc );
1612 };
1613
1614 struct Table;
1615 struct TablePart {
1616
1617 TablePart()
1618 : MifTableNum( 0 ), ParentTable( NULL ), columnsProcessed( false ),
1619 needsColumnReprocessing( false ) {}
1620
1621 Vector<Column> Columns;
1622 Vector<Row> Header;
1623 Vector<Row> Body;
1624 Vector<Row> Footer;
1625
1626 void translate( MifDoc &mifDoc );
1627 void processColumns();
1628 void normalizeRows();
1629 void begin( Table &parentTable, MifDoc &mifDoc );
1630
1631 MifDoc::Tbl &mifTable( MifDoc &mifDoc )
1632 { assert( MifTableNum > 0 ); return mifDoc.tbls()[MifTableNum-1]; }
1633 Table &parentTable() { assert( ParentTable != NULL ); return *ParentTable; }
1634
1635 size_t MifTableNum;
1636 Table *ParentTable;
1637 bool columnsProcessed;
1638 bool needsColumnReprocessing;
1639 };
1640
1641 struct Table {
1642
1643 Table() : beforeRowBorder( false ), afterRowBorder( false ), beforeColumnBorder( false ),
1644 afterColumnBorder( false ), CurCell( NULL ), CurTablePart( NULL ),
1645 DefaultTblFormatGenerated( false ), NoTablePartsSeen( true ) {}
1646
1647 Vector<TablePart> TableParts;
1648
1649 Border beforeRowBorder;
1650 Border afterRowBorder;
1651 Border beforeColumnBorder;
1652 Border afterColumnBorder;
1653 // TableNIC nic;
1654 Length tableWidth;
1655 Symbol displayAlignment;
1656 Length startIndent;
1657
1658 void resolveBorders( Vector<Row> &rows, bool hasFirstTableRow, bool hasLastTableRow );
1659 void begin( MifDoc &mifDoc );
1660
1661 Vector<Row> &curRows() { assert( CurRows != NULL ); return *CurRows; }
1662 TablePart &curTablePart() { assert( CurTablePart != NULL ); return *CurTablePart; }
1663 Cell &curCell() { assert( CurCell != NULL ); return *CurCell; }
1664
1665 TablePart *CurTablePart;
1666 Cell *CurCell;
1667 Vector<Row> *CurRows;
1668
1669 bool DefaultTblFormatGenerated;
1670 bool NoTablePartsSeen;
1671
1672 };
1673
1674 struct Format : public MifDoc::ParagraphFormat {
1675
1676 Format() : MifDoc::ParagraphFormat(), FotLineSpacingSpec( 12000 ),
1677 FotFirstLineStartIndentSpec( 0 ), FotStartIndentSpec( 0 ),
1678 FotEndIndentSpec( 0 ), FotLanguage( 0 ), FotCurDisplaySize( 0 ),
1679 FotLineThickness( 1000 ), FotBorderPresent( true ), FotLineRepeat( 1 ),
1680 FotLineSep( 1000 ), FotBorderPriority( 0 ),
1681 FotDisplayAlignment( symbolStart ), FotLeftMargin( 1 ), FotRightMargin( 1 ),
1682 FotTopMargin( 0 ), FotBottomMargin( 0 ), FotHeaderMargin( 0 ),
1683 FotFooterMargin( 0 ), FotPageWidth( 72000*8 ),
1684 FotPageHeight( (72000*23)/2 ), FotLineCap( symbolButt ),
1685 FotPositionPointShiftSpec( 0 ), FotMinLeading(),
1686 FotFieldAlign( symbolStart ), FotFieldWidth( 0 ), FotLines( symbolWrap ),
1687 FotInputWhitespaceTreatment( symbolPreserve ), FotPageNColumns( 1 ),
1688 FotPageColumnSep( 72000/2 ), FotSpan( 1 ), FotPageBalanceColumns( false ),
1689 FotCellBackground( false ) {}
1690
1691 LengthSpec FotFirstLineStartIndentSpec;
1692 LengthSpec FotStartIndentSpec;
1693 LengthSpec FotEndIndentSpec;
1694 LengthSpec FotLineSpacingSpec;
1695 LengthSpec FotPositionPointShiftSpec;
1696 LengthSpec FotFieldWidth;
1697 OptLengthSpec FotMinLeading;
1698 long FotCurDisplaySize;
1699 Length FotLineThickness;
1700 Symbol FotLineCap;
1701 long FotBorderPriority;
1702 bool FotBorderPresent;
1703 long FotLineRepeat;
1704 Length FotLineSep;
1705 Symbol FotDisplayAlignment;
1706 Length FotLeftMargin;
1707 Length FotRightMargin;
1708 Length FotTopMargin;
1709 Length FotBottomMargin;
1710 Length FotHeaderMargin;
1711 Length FotFooterMargin;
1712 Length FotPageWidth;
1713 Length FotPageHeight;
1714 Symbol FotFieldAlign;
1715 Symbol FotInputWhitespaceTreatment;
1716 Symbol FotLines;
1717 long FotPageNColumns;
1718 Length FotPageColumnSep;
1719 long FotSpan;
1720 bool FotPageBalanceColumns;
1721 bool FotCellBackground;
1722
1723 MifDoc::T_tagstring MifBackgroundColor;
1724
1725 Letter2 FotLanguage;
1726 Letter2 FotCountry;
1727 void computePgfLanguage();
1728
1729 static const Length INITIAL_PAGE_SIZE() { return 72000*8; }
1730 };
1731
1732 struct NodeInfo {
1733
1734 NodeInfo() {}
1735 NodeInfo( NodePtr node_, unsigned nodeLevel_ )
1736 : node( node_ ), nodeLevel( nodeLevel_ ) {}
1737 NodePtr node;
1738 unsigned nodeLevel;
1739 static unsigned nonEmptyElementsOpened;
1740 static unsigned curNodeLevel;
1741 };
1742
1743 struct LinkInfo {
1744
1745 LinkInfo( MifDoc::CrossRefInfo *crossRefInfo_ = NULL )
1746 : crossRefInfo( crossRefInfo_ ), openedInMif( false ) {}
1747 ~LinkInfo() { if( crossRefInfo != NULL ) delete crossRefInfo; }
1748
1749 bool forcesNoLink() const { return crossRefInfo != NULL ? false : true; }
1750
1751 MifDoc::CrossRefInfo *crossRefInfo;
1752 bool openedInMif;
1753 static unsigned pendingMifClosings;
1754 };
1755
1756 struct SymbolFont {
1757 const char *name;
1758 Char mapping[256];
1759 };
1760
1761 enum { nSymbolFonts = 3 };
1762
1763 void synchronizeFontFormat();
1764 long computeLengthSpec( const LengthSpec &spec ) const;
1765 Format &format() const
1766 { Format *result = formatStack.head(); assert( result != NULL ); return *result; }
1767 Table &curTable() { return CurTable; }
1768 void setCurLeaderStream( MifTmpOutputByteStream *s, bool doDelete = true )
1769 { if( doDelete && CurLeaderStream ) delete CurLeaderStream; CurLeaderStream = s; }
1770 MifTmpOutputByteStream &curLeaderStream()
1771 { assert( CurLeaderStream != NULL ); return *CurLeaderStream; }
1772
1773 CmdLineApp *App;
1774 const CharsetInfo *SystemCharset;
1775 Ptr<ExtendEntityManager> EntityManager;
1776 bool paragraphBreakInEffect;
1777 bool inLeader;
1778 bool lastFlowObjectWasWhitespace;
1779 bool firstHeaderFooter;
1780 bool inSimplePageSequence;
1781 bool bookComponentOpened;
1782 bool bookComponentAvailable;
1783
1784 protected:
1785
1786 TFotSimplePageSequence FotSimplePageSequence;
1787 Table CurTable;
1788
1789 MifDoc::T_pathname systemIdToMifPathname( const StringC &systemId );
1790 bool systemIdToMifPathname( const StringC &systemId, MifDoc::T_pathname & );
1791 int systemIdFilename( const StringC &systemId, StringC &filename );
1792 void initMifBookComponent();
1793 void setupSimplePageSequence();
1794 void beginHeaderFooter( bool header );
1795 void beginHeader() { beginHeaderFooter( true ); }
1796 void beginFooter() { beginHeaderFooter( false ); };
1797 void endHeaderFooter();
1798 void makeEmptyTextFlow( MifDoc::TextRect & );
1799 void checkForParagraphReopening();
1800 void outPendingInlineStatements();
1801 void outString( const Char *s, size_t n, MifTmpOutputByteStream *o = NULL,
1802 bool inParagraph = true, String<char> *targetString = NULL );
1803
1804 MifDoc::Frame &makeAnchoredFrame
1805 ( MifDoc::T_keyword frameType, long width, long height,
1806 MifDoc::T_keyword anchorAlign = MifDoc::sLeft );
1807 void setupHeaderFooterParagraphFormat( MifDoc::ParagraphFormat &,
1808 MifDoc::ParagraphFormat &,
1809 MifDoc::T_dimension );
1810 OutputByteStream &os() { return *outputStream; }
1811
1812 MifDoc mifDoc;
1813 OutputByteStream *outputStream;
1814 MifTmpOutputByteStream *CurLeaderStream;
1815 EffectiveDisplaySpace createEffectiveDisplaySpace( const DisplaySpace &ds ) const;
1816 IList<DisplayInfo> displayStack;
1817 IList<Format> formatStack;
1818 IQueue<DisplaySpaceInfo> displaySpaceQueue;
1819 Vector<NodeInfo> nodeStack;
1820 Vector<LinkInfo> linkStack;
1821 Vector<MifDoc::Marker> indexEntryStack;
1822
1823 Format nextFormat;
1824
1825 Symbol pendingBreak;
1826 EffectiveDisplaySpace pendingEffectiveDisplaySpace;
1827 void processDisplaySpaceStack();
1828
1829 void startDisplay( const DisplayNIC & );
1830 void endDisplay();
1831
1832 // sytem font code from James Clark
1833 enum { CHAR_TABLE_CHAR_BITS = 16 };
1834 enum { CHAR_TABLE_SYMBOL_FLAG = 1U << 31 };
1835 CharMap<Unsigned32> CharTable;
1836
1837 static const SymbolFont SymbolFonts[nSymbolFonts];
1838 static const Char FrameCharsetMap[128];
1839 };
1840
1841 MifFOTBuilder *MifFOTBuilder::CurInstance = NULL;
1842 unsigned MifFOTBuilder::NodeInfo::nonEmptyElementsOpened = 0;
1843 unsigned MifFOTBuilder::NodeInfo::curNodeLevel = 0;
1844 unsigned MifFOTBuilder::LinkInfo::pendingMifClosings = 0;
1845
1846 int operator ==(struct FOTBuilder::DisplayNIC, struct FOTBuilder::DisplayNIC) { return 0; }
1847
1848 void MifFOTBuilder::start() {
1849
1850 NodeInfo::nonEmptyElementsOpened = nodeStack.size();
1851
1852 Format *effectiveFormat = new Format( nextFormat );
1853 if( nextFormat.FSize > 0 )
1854 effectiveFormat->setFDY
1855 ( double( computeLengthSpec( nextFormat.FotPositionPointShiftSpec ) * -100 )
1856 / nextFormat.FSize );
1857
1858 formatStack.insert( effectiveFormat );
1859 }
1860
1861 void MifFOTBuilder::end() {
1862
1863 assert( formatStack.head() != NULL );
1864 delete formatStack.get();
1865
1866 assert( formatStack.head() != NULL );
1867 nextFormat = *formatStack.head();
1868 }
1869
1870 void MifFOTBuilder::Format::computePgfLanguage() {
1871
1872 switch( FotLanguage ) {
1873 case SP_LETTER2( 'E', 'N' ):
1874 switch( FotCountry ) {
1875 case SP_LETTER2( 'G', 'B' ):
1876 PgfLanguage = MifDoc::sUKEnglish;
1877 break;
1878 default:
1879 PgfLanguage = MifDoc::sUSEnglish;
1880 }
1881 break;
1882 case SP_LETTER2( 'D', 'E' ):
1883 switch( FotCountry ) {
1884 case SP_LETTER2( 'C', 'H' ):
1885 PgfLanguage = MifDoc::sSwissGerman;
1886 break;
1887 default:
1888 PgfLanguage = MifDoc::sGerman;
1889 }
1890 case SP_LETTER2( 'F', 'R' ):
1891 switch( FotCountry ) {
1892 case SP_LETTER2( 'C', 'A' ):
1893 PgfLanguage = MifDoc::sCanadianFrench;
1894 break;
1895 default:
1896 PgfLanguage = MifDoc::sFrench;
1897 }
1898 break;
1899 case SP_LETTER2( 'E', 'S' ):
1900 PgfLanguage = MifDoc::sSpanish;
1901 break;
1902 case SP_LETTER2( 'C', 'A' ):
1903 PgfLanguage = MifDoc::sCatalan;
1904 break;
1905 case SP_LETTER2( 'I', 'T' ):
1906 PgfLanguage = MifDoc::sItalian;
1907 break;
1908 case SP_LETTER2( 'P', 'T' ):
1909 PgfLanguage = MifDoc::sPortuguese;
1910 break;
1911 // case SP_LETTER2( '', '' ):
1912 // PgfLanguage = sBrazilian;
1913 // break;
1914 // case SP_LETTER2( '', '' ):
1915 // PgfLanguage = sDanish;
1916 // break;
1917 case SP_LETTER2( 'N', 'L' ):
1918 PgfLanguage = MifDoc::sDutch;
1919 break;
1920 case SP_LETTER2( 'N', 'O' ):
1921 PgfLanguage = MifDoc::sNorwegian;
1922 break;
1923 // case SP_LETTER2( '', '' ):
1924 // PgfLanguage = sNynorsk;
1925 // break;
1926 case SP_LETTER2( 'F', 'I' ):
1927 PgfLanguage = MifDoc::sFinnish;
1928 break;
1929 case SP_LETTER2( 'S', 'V' ):
1930 PgfLanguage = MifDoc::sSwedish;
1931 break;
1932 default:
1933 PgfLanguage = MifDoc::sNoLanguage;
1934 }
1935 }
1936
1937 MifFOTBuilder::MifFOTBuilder( const String<CmdLineApp::AppChar> &fileLoc,
1938 const Ptr<ExtendEntityManager> &entityManager,
1939 const CharsetInfo &systemCharset,
1940 CmdLineApp *app )
1941 : App( app ), EntityManager( entityManager ), SystemCharset( &systemCharset ),
1942 mifDoc( fileLoc, app ), paragraphBreakInEffect( false ), inLeader( false ),
1943 CurLeaderStream( NULL ), CharTable( 0 ), lastFlowObjectWasWhitespace( false ),
1944 pendingBreak( symbolFalse ), firstHeaderFooter( true ), inSimplePageSequence( false ),
1945 bookComponentOpened( false ), bookComponentAvailable( false ) {
1946
1947 CurInstance = this;
1948
1949 nextFormat.setDSSSLDefaults();
1950 nextFormat.FotCurDisplaySize = Format::INITIAL_PAGE_SIZE() - 2;
1951 // 2 is for margins (MIF doesn't accept zero-sized ones)
1952 formatStack.insert( new Format( nextFormat ) );
1953
1954 initMifBookComponent();
1955 bookComponentOpened = true;
1956 bookComponentAvailable = true;
1957
1958 for( int i = 0; i < 128; i++ ) {
1959 Char c = FrameCharsetMap[i];
1960 if( c ) {
1961 if( !CharTable[i+0x80] )
1962 CharTable.setChar( i+0x80, c );
1963 else if ((CharTable[i+0x80] & ((1 << CHAR_TABLE_CHAR_BITS) - 1)) == c)
1964 CharTable.setChar(i+0x80, CharTable[i+0x80] | (1 << (i + CHAR_TABLE_CHAR_BITS)));
1965 }
1966 }
1967
1968 // symbol character code from James Clark
1969 for( int i = 0; i < nSymbolFonts; i++ ) {
1970 for( int j = 0; j < 256; j++ ) {
1971 Char c = SymbolFonts[i].mapping[j];
1972 if( c && !CharTable[c] )
1973 CharTable.setChar( c, j | (i << CHAR_TABLE_CHAR_BITS) | CHAR_TABLE_SYMBOL_FLAG );
1974 }
1975 }
1976 }
1977
1978 void MifFOTBuilder::initMifBookComponent() {
1979
1980 MifDoc::ParagraphFormat defaultParaFormat;
1981 defaultParaFormat.setDSSSLDefaults();
1982 defaultParaFormat.setPgfTag( MifDoc::sDefaultPgfFormat );
1983 mifDoc.pgfCatalog().ParaFormats.push_back( defaultParaFormat );
1984
1985 mifDoc.document().setDPageSize
1986 ( MifDoc::T_WH( MifDoc::T_dimension( format().FotPageWidth ),
1987 MifDoc::T_dimension( format().FotPageHeight ) ) );
1988 mifDoc.document().setDMargins( MifDoc::T_LTRB( 1, 1, 1, 1 ) );
1989 // MIF doesn't accept zeros
1990 mifDoc.document().setDColumns( 1 );
1991 }
1992
1993 long MifFOTBuilder::computeLengthSpec( const LengthSpec &spec ) const {
1994
1995 if( spec.displaySizeFactor == 0.0 ) {
1996 return spec.length;
1997 } else {
1998 double tem = format().FotCurDisplaySize * spec.displaySizeFactor;
1999 return spec.length + long( tem >= 0.0 ? tem +.5 : tem - .5 );
2000 }
2001 }
2002
2003 MifFOTBuilder::EffectiveDisplaySpace
2004 MifFOTBuilder::createEffectiveDisplaySpace( const DisplaySpace &ds ) const {
2005
2006 EffectiveDisplaySpace result;
2007 result.set( computeLengthSpec( ds.nominal ), computeLengthSpec( ds.min ),
2008 computeLengthSpec( ds.max ), ds.priority, ds.conditional, ds.force );
2009 return result;
2010 }
2011
2012 void MifFOTBuilder::EffectiveDisplaySpace::combine( const EffectiveDisplaySpace eds ) {
2013
2014 if( eds.force ) {
2015 if( force ) {
2016 nominal += eds.nominal;
2017 min += eds.min;
2018 max += eds.max;
2019 } else
2020 *this = eds;
2021 } else {
2022 if( eds.priority > priority )
2023 *this = eds;
2024 else {
2025 if( eds.priority == priority ) {
2026 if( eds.nominal > nominal )
2027 *this = eds;
2028 else
2029 if( eds.nominal == nominal ) {
2030 if( eds.min < min ) {
2031 min = eds.min;
2032 }
2033 if( eds.max > max ) {
2034 max = eds.max;
2035 }
2036 }
2037 }
2038 }
2039 }
2040 }
2041
2042 void MifFOTBuilder::synchronizeFontFormat() {
2043
2044 if( mifDoc.curPara( false ) != NULL ) {
2045 // mifDoc.curPara()->curFormat().ffUpdateFrom( format() );
2046 mifDoc.curPara()->curFormat().ffUpdateFrom( nextFormat );
2047 mifDoc.curPara()->curFormat().ffOut( mifDoc.os(), MifDoc::FontFormat::stFont );
2048 } else {
2049 // mifDoc.curFormat().ffUpdateFrom( format() );
2050 mifDoc.curFormat().ffUpdateFrom( nextFormat );
2051 mifDoc.curFormat().ffOut( mifDoc.os(), MifDoc::FontFormat::stFont );
2052 }
2053 outPendingInlineStatements();
2054 }
2055
2056 void MifFOTBuilder::outString
2057 ( const Char *s, size_t n, MifTmpOutputByteStream *o, bool inParagraph,
2058 String<char> *targetString ) {
2059
2060 MifOutputByteStream *outS
2061 = ( o != NULL ) ? &o->stream()
2062 : ( ( targetString != NULL ) ? (MifOutputByteStream *)NULL : &mifDoc.os() );
2063
2064 enum { nStr, nCode, nChar, nNothing, nHardReturn, nSpecialChar } nextOut;
2065 union { const char *str; unsigned long code; char chr; } out;
2066 String<char> out_specialChar;
2067
2068 MifDoc::ParagraphFormat *curPFormat
2069 = inParagraph
2070 ? ( mifDoc.curPara( false ) != NULL ? &mifDoc.curPara()->curFormat() : &mifDoc.curFormat() )
2071 : (MifDoc::ParagraphFormat*)NULL;
2072 MifDoc::T_string paraFFamily;
2073 if( curPFormat != NULL )
2074 paraFFamily = curPFormat->FFamily;
2075 bool stringOpened = false;
2076 int prevSymbolFontNum = 0;
2077 int curSymbolFontNum = 0;
2078 bool thisFlowObjectIsWhitespace;
2079 for( ; n > 0; s++, n-- ) {
2080 thisFlowObjectIsWhitespace = false;
2081 nextOut = nNothing;
2082 switch( *s ) {
2083 case Char( '\n' ): break;
2084 case Char( '\r' ):
2085 if( !inParagraph ) {
2086 out.chr = ' '; nextOut = nChar;
2087 } else {
2088 switch( format().FotLines ) {
2089 case symbolNone:
2090 case symbolWrap:
2091 switch( format().FotInputWhitespaceTreatment ) {
2092 case symbolIgnore: break;
2093 case symbolCollapse:
2094 if( lastFlowObjectWasWhitespace )
2095 break;
2096 case symbolPreserve: default:
2097 out.chr = ' '; nextOut = nChar;
2098 }
2099 break;
2100 default:
2101 nextOut = nHardReturn;
2102 }
2103 thisFlowObjectIsWhitespace = true;
2104 }
2105 break;
2106 case Char( '\t' ):
2107 if( !inParagraph ) {
2108 out.str = "\\t"; nextOut = nStr;
2109 } else {
2110 switch( format().FotInputWhitespaceTreatment ) {
2111 case symbolIgnore: break;
2112 case symbolCollapse:
2113 if( lastFlowObjectWasWhitespace )
2114 break;
2115 case symbolPreserve: default:
2116 out.str = "\\t"; nextOut = nStr;
2117 }
2118 thisFlowObjectIsWhitespace = true;
2119 }
2120 break;
2121 case Char( '>' ): out.str = "\\>"; nextOut = nStr; break;
2122 case Char( '\'' ): out.str = "\\q"; nextOut = nStr; break;
2123 case Char( '`' ): out.str = "\\Q"; nextOut = nStr; break;
2124 case Char( '\\' ): out.str = "\\\\"; nextOut = nStr; break;
2125 case Char( ' ' ):
2126 if( !inParagraph ) {
2127 out.chr = ' '; nextOut = nChar;
2128 } else {
2129 switch( format().FotInputWhitespaceTreatment ) {
2130 case symbolIgnore: break;
2131 case symbolCollapse:
2132 if( lastFlowObjectWasWhitespace )
2133 break;
2134 case symbolPreserve: default:
2135 out.chr = ' '; nextOut = nChar;
2136 }
2137 thisFlowObjectIsWhitespace = true;
2138 }
2139 break;
2140 case 0x00A0:
2141 out_specialChar = MifDoc::sHardSpace; nextOut = nSpecialChar;
2142 break;
2143 case 0x00A2:
2144 out_specialChar = MifDoc::sCent; nextOut = nSpecialChar;
2145 break;
2146 case 0x00A3:
2147 case 0x20A4:
2148 out_specialChar = MifDoc::sPound; nextOut = nSpecialChar;
2149 break;
2150 case 0x00A5:
2151 out_specialChar = MifDoc::sYen; nextOut = nSpecialChar;
2152 break;
2153 case 0x2002:
2154 out_specialChar = MifDoc::sEnSpace; nextOut = nSpecialChar;
2155 break;
2156 case 0x2003:
2157 out_specialChar = MifDoc::sEmSpace; nextOut = nSpecialChar;
2158 break;
2159 case 0x2009:
2160 out_specialChar = MifDoc::sThinSpace; nextOut = nSpecialChar;
2161 break;
2162 case 0x2010:
2163 out_specialChar = MifDoc::sSoftHyphen; nextOut = nSpecialChar;
2164 break;
2165 case 0x2011:
2166 out_specialChar = MifDoc::sHardHyphen; nextOut = nSpecialChar;
2167 break;
2168 case 0x2013:
2169 out_specialChar = MifDoc::sEnDash; nextOut = nSpecialChar;
2170 break;
2171 case 0x2014:
2172 out_specialChar = MifDoc::sEmDash; nextOut = nSpecialChar;
2173 break;
2174 case 0x2020:
2175 out_specialChar = MifDoc::sDagger; nextOut = nSpecialChar;
2176 break;
2177 case 0x2021:
2178 out_specialChar = MifDoc::sDoubleDagger; nextOut = nSpecialChar;
2179 break;
2180 case 0x2022:
2181 out_specialChar = MifDoc::sBullet; nextOut = nSpecialChar;
2182 break;
2183 default:
2184 if( *s >= 0x80 ) {
2185 unsigned long code = CharTable[*s];
2186 if( code & CHAR_TABLE_SYMBOL_FLAG ) {
2187 if( curPFormat != NULL ) {
2188 curSymbolFontNum = ( ( code & ~CHAR_TABLE_SYMBOL_FLAG )
2189 >> CHAR_TABLE_CHAR_BITS ) + 1;
2190 assert( curSymbolFontNum < nSymbolFonts );
2191 out.code = code & 0xff; nextOut = nCode;
2192 }
2193 } else
2194 if( code ) {
2195 out.code = code & 0xff; nextOut = nCode;
2196 }
2197 } else {
2198 out.chr = char( *s ); nextOut = nChar;
2199 }
2200 }
2201
2202 if( nextOut != nNothing ) {
2203 if( curSymbolFontNum != prevSymbolFontNum ) {
2204 if( stringOpened ) {
2205 *outS << "'>";
2206 stringOpened = false;
2207 }
2208 MifDoc::T_string fontFamily( curSymbolFontNum == 0
2209 ? paraFFamily
2210 : MifDoc::T_string(
2211 SymbolFonts[ curSymbolFontNum - 1 ].name ) );
2212 curPFormat->setFFamily( fontFamily );
2213 curPFormat->ffOut( *outS, MifDoc::FontFormat::stFont );
2214 }
2215 if( curPFormat != NULL && !stringOpened ) {
2216 *outS << '\n' << MifOutputByteStream::INDENT << "<String `";
2217 stringOpened = true;
2218 }
2219 switch( nextOut ) {
2220 case nChar:
2221 if( targetString != NULL )
2222 *targetString += out.chr;
2223 else
2224 *outS << out.chr;
2225 break;
2226
2227 case nHardReturn:
2228 if( inParagraph ) {
2229 if( stringOpened ) {
2230 *outS << "'>";
2231 stringOpened = false;
2232 }
2233 mifDoc.outSpecialChar( MifDoc::sHardReturn, outS );
2234 MifDoc::ParaLine::outEpilog( *outS );
2235 MifDoc::ParaLine::outProlog( *outS );
2236 }
2237 break;
2238
2239 case nSpecialChar:
2240 if( inParagraph ) {
2241 if( stringOpened ) {
2242 *outS << "'>";
2243 stringOpened = false;
2244 }
2245 mifDoc.outSpecialChar( out_specialChar, outS );
2246 }
2247 break;
2248
2249 case nCode:
2250 if( targetString != NULL )
2251 mifDoc.outHexChar( out.code, *targetString );
2252 else
2253 mifDoc.outHexChar( out.code, outS ); break;
2254 break;
2255
2256 case nStr:
2257 if( targetString != NULL )
2258 targetString->append( out.str, strlen( out.str ) );
2259 else
2260 *outS << out.str;
2261 break;
2262 case nNothing: break;
2263 }
2264 }
2265
2266 prevSymbolFontNum = curSymbolFontNum;
2267 lastFlowObjectWasWhitespace = thisFlowObjectIsWhitespace;
2268 }
2269
2270 if( stringOpened )
2271 *outS << "'>";
2272
2273 if( curSymbolFontNum != 0 ) {
2274 curPFormat->setFFamily( paraFFamily );
2275 curPFormat->ffOut( *outS, MifDoc::FontFormat::stFont );
2276 curPFormat->ffSetProperties() &= ~MifDoc::FontFormat::fFFamily;
2277 }
2278 }
2279
2280 void MifFOTBuilder::characters( const Char *s, size_t n ) {
2281
2282 checkForParagraphReopening();
2283 if( MifDoc::Para::currentlyOpened ) {
2284 if( inLeader ) {
2285 outString( s, n, &curLeaderStream(), false );
2286 } else {
2287 synchronizeFontFormat();
2288 outString( s, n, NULL, true );
2289 }
2290 }
2291 }
2292
2293 void MifFOTBuilder::checkForParagraphReopening() {
2294
2295 DisplayInfo *curDs = displayStack.head();
2296 // assert( curDs != NULL );
2297 if( curDs != NULL && curDs->paragraphClosedInMif ) {
2298
2299 Format f = format();
2300
2301 f.setPgfWithPrev( curDs->firstParaOutputed ? curDs->keepWithinPageInEffect : false );
2302 f.setPgfWithNext( false ); // TMAI
2303 curDs->firstParaOutputed = true;
2304
2305 processDisplaySpaceStack();
2306 switch( pendingBreak ) {
2307 case symbolPage:
2308 f.setPgfPlacement( MifDoc::sPageTop );
2309 break;
2310 case symbolColumn:
2311 f.setPgfPlacement( MifDoc::sColumnTop );
2312 break;
2313 default:
2314 f.setPgfPlacement( MifDoc::sAnywhere );
2315 }
2316 pendingBreak = symbolFalse;
2317
2318 f.setPgfSpBefore( pendingEffectiveDisplaySpace.nominal );
2319 pendingEffectiveDisplaySpace.clear();
2320 f.setPgfFIndent( nextFormat.PgfLIndent );
2321
2322 MifDoc::Para *p
2323 = new MifDoc::Para( mifDoc.curTagStream().content().stream().CurTagIndent + 4 );
2324 p->setParagraphFormat( mifDoc.curFormat() );
2325 p->format().updateFrom( f );
2326 p->format().FSize = mifDoc.curFormat().FSize;
2327 p->format().ffSetProperties() &= ~MifDoc::FontFormat::fFSize;
2328 Length lineSpacing = computeLengthSpec( f.FotLineSpacingSpec.length );
2329 if( p->format().FSize != lineSpacing )
2330 p->format().setFSize( lineSpacing );
2331 p->curFormat() = p->format();
2332 // assert( mifDoc.curPara( false ) == NULL );
2333 mifDoc.setCurPara( p );
2334 mifDoc.enterPara( *mifDoc.curPara() );
2335
2336 curDs->paragraphClosedInMif = false;
2337 }
2338 }
2339
2340 void MifFOTBuilder::processDisplaySpaceStack() {
2341
2342 pendingBreak = symbolFalse;
2343 EffectiveDisplaySpace effectiveDisplaySpace;
2344 DisplaySpaceInfo *curDSI;
2345 while( !displaySpaceQueue.empty() ) {
2346 curDSI = displaySpaceQueue.get();
2347 if( curDSI->breakType == symbolPage || curDSI->breakType == symbolColumn ) {
2348 effectiveDisplaySpace.clear();
2349 if( pendingBreak != symbolFalse )
2350 mifDoc.outBreakingPara( curDSI->breakType == symbolPage
2351 ? MifDoc::sPageTop : MifDoc::sColumnTop );
2352 pendingBreak = curDSI->breakType;
2353 if( !curDSI->breakIsAfter )
2354 effectiveDisplaySpace.combine( createEffectiveDisplaySpace( curDSI->space ) );
2355 } else
2356 effectiveDisplaySpace.combine( createEffectiveDisplaySpace( curDSI->space ) );
2357 delete curDSI;
2358 }
2359
2360 pendingEffectiveDisplaySpace = effectiveDisplaySpace;
2361 }
2362
2363
2364 void MifFOTBuilder::doStartParagraph
2365 ( const ParagraphNIC &nic, bool servesAsWrapper, MifDoc::T_dimension height,
2366 bool allowNegativeLeading ) {
2367
2368 startDisplay( nic );
2369
2370 DisplayInfo *curDs = displayStack.head();
2371 assert( curDs != NULL );
2372 curDs->isParagraph = true;
2373
2374 nextFormat.setPgfWithPrev( curDs->mayViolateKeepBefore
2375 ? curDs->keepWithPrevious
2376 : ( curDs->firstParaOutputed
2377 ? curDs->keepWithinPageInEffect
2378 : false ) );
2379 nextFormat.setPgfWithNext( curDs->keepWithNext );
2380 curDs->firstParaOutputed = true;
2381
2382 processDisplaySpaceStack();
2383 switch( pendingBreak ) {
2384 case symbolPage:
2385 nextFormat.setPgfPlacement( MifDoc::sPageTop );
2386 break;
2387 case symbolColumn:
2388 nextFormat.setPgfPlacement( MifDoc::sColumnTop );
2389 break;
2390 default:
2391 nextFormat.setPgfPlacement( MifDoc::sAnywhere );
2392 }
2393 pendingBreak = symbolFalse;
2394
2395 Length lineSpacing;
2396 Length extraSpaceBefore = 0;
2397 if( servesAsWrapper ) {
2398 if( height < 2000 ) { // FrameMaker minimum is 2pt
2399 if( allowNegativeLeading )
2400 nextFormat.setPgfLeading( height - 2000 );
2401 else
2402 pendingEffectiveDisplaySpace.nominal
2403 -= ( pendingEffectiveDisplaySpace.nominal > 2000 )
2404 ? 2000 : pendingEffectiveDisplaySpace.nominal;
2405 // try to steal as much as possible from space before
2406 height = 2000;
2407 }
2408 //if( effectiveDisplaySpace.nominal <= 0 )
2409 // extraSpaceBefore = 1; // FrameMaker bug workaround
2410 //nextFormat.setFSize( height );
2411 lineSpacing = height;
2412 nextFormat.setFColor( MifDoc::sWhite );
2413 nextFormat.setPgfLineSpacing( MifDoc::sFixed );
2414 } else {
2415 //nextFormat.setFSize( computeLengthSpec( nextFormat.FotLineSpacingSpec.length ) );
2416 lineSpacing = computeLengthSpec( nextFormat.FotLineSpacingSpec.length );
2417 if( nextFormat.FotMinLeading.hasLength ) // but ignore the actual min-leading value
2418 nextFormat.PgfLineSpacing = MifDoc::sProportional;
2419 else
2420 nextFormat.PgfLineSpacing = MifDoc::sFixed;
2421 }
2422
2423 nextFormat.setPgfSpBefore( pendingEffectiveDisplaySpace.nominal + extraSpaceBefore );
2424 pendingEffectiveDisplaySpace.clear();
2425
2426 nextFormat.setPgfLIndent( computeLengthSpec( nextFormat.FotStartIndentSpec ) );
2427 nextFormat.setPgfFIndent( computeLengthSpec( nextFormat.FotFirstLineStartIndentSpec )
2428 + nextFormat.PgfLIndent );
2429 nextFormat.setPgfRIndent( computeLengthSpec( nextFormat.FotEndIndentSpec ) );
2430
2431 nextFormat.setPgfPlacementStyle
2432 ( nextFormat.FotSpan > 1 ? MifDoc::sStraddle : MifDoc::sNormal );
2433 start();
2434
2435 MifDoc::Para *p
2436 = new MifDoc::Para( mifDoc.curTagStream().content().stream().CurTagIndent + 4 );
2437 p->setParagraphFormat( mifDoc.curFormat() );
2438 p->format().updateFrom( format() );
2439 p->format().FSize = mifDoc.curFormat().FSize;
2440 p->format().ffSetProperties() &= ~MifDoc::FontFormat::fFSize;
2441 if( p->format().FSize != lineSpacing )
2442 p->format().setFSize( lineSpacing );
2443 p->curFormat() = p->format();
2444 // assert( mifDoc.curPara( false ) == NULL );
2445 mifDoc.setCurPara( p );
2446 mifDoc.enterPara( *mifDoc.curPara() );
2447 lastFlowObjectWasWhitespace = false;
2448 outPendingInlineStatements();
2449
2450 // mifDoc.curFormat().out( mifDoc.os() );
2451 // mifDoc.beginParaLine();
2452 }
2453
2454 void MifFOTBuilder::doEndParagraph
2455 ( bool sustainFormatStack, bool sustainDisplayStack, bool paragraphBreakTest,
2456 bool discardThisPara ) {
2457
2458 // mifDoc.endParaLine();
2459 // MifDoc::Para::outEpilog( mifDoc.os() );
2460
2461 DisplayInfo *curDs = displayStack.head();
2462 assert( curDs != NULL );
2463
2464 if( !sustainFormatStack )
2465 end();
2466 if( !sustainDisplayStack )
2467 endDisplay();
2468
2469 if( paragraphBreakTest && paragraphBreakInEffect ) {
2470 paragraphBreakInEffect = false;
2471 end();
2472 }
2473
2474 if( !curDs->paragraphClosedInMif ) {
2475 MifDoc::Para *p = mifDoc.curPara();
2476 mifDoc.exitPara();
2477 if( !discardThisPara ) {
2478 p->out( mifDoc.os() );
2479 mifDoc.curFormat().updateFrom( p->format() );
2480 }
2481 delete p;
2482 }
2483 }
2484
2485 void MifFOTBuilder::startDisplayGroup( const DisplayGroupNIC &nic ) {
2486
2487 startDisplay( nic );
2488 start();
2489 }
2490
2491 void MifFOTBuilder::endDisplayGroup() {
2492
2493 end();
2494 endDisplay();
2495 }
2496
2497 void MifFOTBuilder::startDisplay( const DisplayNIC &nic ) {
2498
2499 if( !inSimplePageSequence ) {
2500 if( !bookComponentOpened ) {
2501 mifDoc.enterBookComponent();
2502 initMifBookComponent();
2503 bookComponentOpened = true;
2504 }
2505 bookComponentAvailable = false;
2506 }
2507
2508 displaySpaceQueue.append
2509 ( new DisplaySpaceInfo( nic.spaceBefore, nic.breakBefore, false ) );
2510
2511 DisplayInfo *di = displayStack.head();
2512 if( di != NULL && di->isParagraph && !di->paragraphClosedInMif ) {
2513 if( mifDoc.curPara()->content().isEmpty() ) {
2514 doEndParagraph( true, true, true, true );
2515 } else
2516 doEndParagraph( true, true );
2517 di->paragraphClosedInMif = true;
2518 }
2519
2520 if( curTable().CurCell != NULL )
2521 nextFormat.FotCurDisplaySize = curTable().CurCell->displaySize;
2522 else if( nextFormat.FotSpan > 1 )
2523 nextFormat.FotCurDisplaySize
2524 = nextFormat.FotPageWidth - nextFormat.FotLeftMargin - nextFormat.FotRightMargin;
2525 else
2526 nextFormat.FotCurDisplaySize
2527 = ( nextFormat.FotPageWidth - nextFormat.FotLeftMargin - nextFormat.FotRightMargin
2528 - nextFormat.FotPageColumnSep * ( nextFormat.FotPageNColumns - 1 ) )
2529 / nextFormat.FotPageNColumns;
2530
2531 displayStack.insert( new DisplayInfo( nic, displayStack.head() ) );
2532 }
2533
2534 void MifFOTBuilder::endDisplay() {
2535
2536 DisplayInfo *di = displayStack.get();
2537
2538 displaySpaceQueue.append
2539 ( new DisplaySpaceInfo( di->spaceAfter, di->breakAfter, true ) );
2540
2541 delete di;
2542 }
2543
2544 void MifFOTBuilder::startSimplePageSequenceSerial() {
2545
2546 inSimplePageSequence = true;
2547 firstHeaderFooter = true;
2548
2549 bool openBookComponent = true;
2550 if( bookComponentOpened ) {
2551 if( bookComponentAvailable ) {
2552 openBookComponent = false;
2553 bookComponentAvailable = false;
2554 } else
2555 mifDoc.exitBookComponent();
2556 }
2557
2558 if( openBookComponent ) {
2559 mifDoc.enterBookComponent();
2560 initMifBookComponent();
2561 bookComponentOpened = true;
2562 bookComponentAvailable = false;
2563 }
2564
2565 nextFormat.FotCurDisplaySize
2566 = ( nextFormat.FotPageWidth - nextFormat.FotLeftMargin - nextFormat.FotRightMargin
2567 - nextFormat.FotPageColumnSep * ( nextFormat.FotPageNColumns - 1 ) )
2568 / nextFormat.FotPageNColumns;
2569
2570 mifDoc.document().setDColumns( nextFormat.FotPageNColumns );
2571 if( nextFormat.FotPageNColumns > 1 )
2572 mifDoc.document().setDColumnGap( nextFormat.FotPageColumnSep );
2573
2574 mifDoc.document().setProperties &= ~MifDoc::Document::fDMargins;
2575
2576 start();
2577
2578 FotSimplePageSequence.paragraphFormat = format();
2579 }
2580
2581 void MifFOTBuilder::endSimplePageSequenceSerial() {
2582
2583 end();
2584 mifDoc.exitTextFlow();
2585 mifDoc.exitBookComponent();
2586 inSimplePageSequence = false;
2587 bookComponentOpened = false;
2588 bookComponentAvailable = false;
2589 }
2590
2591 void MifFOTBuilder::makeEmptyTextFlow( MifDoc::TextRect &textRect ) {
2592
2593 MifDoc::TextFlow &textFlow = *(new MifDoc::TextFlow( textRect, true ));
2594 mifDoc.textFlows().push_back( textFlow );
2595
2596 mifDoc.enterTextFlow( textFlow );
2597 MifDoc::Para::outSimpleProlog( mifDoc.os() );
2598 MifDoc::ParaLine::outProlog( mifDoc.os() );
2599 MifDoc::ParaLine::outEpilog( mifDoc.os() );
2600 MifDoc::Para::outEpilog( mifDoc.os() );
2601 mifDoc.exitTextFlow();
2602 }
2603
2604 void MifFOTBuilder::beginHeaderFooter( bool header ) {
2605
2606 start();
2607
2608 MifDoc::Para p;
2609 p.setPgfTag( header ? MifDoc::sHeader : MifDoc::sFooter );
2610 p.setProperties &= ~MifDoc::Para::fParagraphFormat;
2611 p.outProlog( mifDoc.os() );
2612
2613 MifDoc::FontFormat ff;
2614 ff.setFSize( format().FSize );
2615 ff.out( mifDoc.os(), MifDoc::FontFormat::fFSize, MifDoc::FontFormat::stFont );
2616
2617 mifDoc.beginParaLine();
2618 }
2619
2620 void MifFOTBuilder::endHeaderFooter() {
2621
2622 mifDoc.endParaLine();
2623 MifDoc::Para::outEpilog( mifDoc.os() );
2624
2625 end();
2626 }
2627
2628 void MifFOTBuilder::setupSimplePageSequence() {
2629
2630 MifDoc::Page &firstMasterPage
2631 = *(new MifDoc::Page( MifDoc::sOtherMasterPage, MifDoc::sFirst ));
2632 MifDoc::Page &rightMasterPage
2633 = *(new MifDoc::Page( MifDoc::sRightMasterPage, MifDoc::sRight ));
2634 MifDoc::Page &leftMasterPage
2635 = *(new MifDoc::Page( MifDoc::sLeftMasterPage, MifDoc::sLeft ));
2636 MifDoc::Page &bodyPage
2637 = *(new MifDoc::Page( MifDoc::sBodyPage, MifDoc::sNONE, MifDoc::sFirst ));
2638
2639 MifDoc::T_LTWH bodyRect;
2640 MifDoc::T_LTWH headerRect;
2641 MifDoc::T_LTWH footerRect;
2642
2643 bodyRect.l = format().FotLeftMargin;
2644 bodyRect.t = format().FotTopMargin;
2645 bodyRect.w = format().FotPageWidth - format().FotLeftMargin - format().FotRightMargin;
2646 bodyRect.h = format().FotPageHeight - format().FotTopMargin - format().FotBottomMargin;
2647
2648 headerRect.l = format().FotLeftMargin;
2649 headerRect.t = 0;
2650 headerRect.w = bodyRect.w;
2651 headerRect.h = format().FotTopMargin;
2652
2653 footerRect.l = format().FotLeftMargin;
2654 footerRect.t = format().FotPageHeight - format().FotBottomMargin;
2655
2656 footerRect.w = bodyRect.w;
2657 footerRect.h = format().FotBottomMargin;
2658 {
2659 MifDoc::TextRect &firstBodyTextRect
2660 = *(new MifDoc::TextRect( bodyRect, format().FotPageNColumns, format().FotPageColumnSep,
2661 format().FotPageBalanceColumns ));
2662 MifDoc::TextRect &rightBodyTextRect
2663 = *(new MifDoc::TextRect( bodyRect, format().FotPageNColumns, format().FotPageColumnSep,
2664 format().FotPageBalanceColumns));
2665 MifDoc::TextRect &leftBodyTextRect
2666 = *(new MifDoc::TextRect( bodyRect, format().FotPageNColumns, format().FotPageColumnSep,
2667 format().FotPageBalanceColumns ));
2668 MifDoc::TextRect &bodyTextRect
2669 = *(new MifDoc::TextRect( bodyRect, format().FotPageNColumns, format().FotPageColumnSep,
2670 format().FotPageBalanceColumns ));
2671 MifDoc::TextRect &firstHeaderTextRect = *(new MifDoc::TextRect( headerRect ));
2672 MifDoc::TextRect &rightHeaderTextRect = *(new MifDoc::TextRect( headerRect ));
2673 MifDoc::TextRect &leftHeaderTextRect = *(new MifDoc::TextRect( headerRect ));
2674 MifDoc::TextRect &firstFooterTextRect = *(new MifDoc::TextRect( footerRect ));
2675 MifDoc::TextRect &rightFooterTextRect = *(new MifDoc::TextRect( footerRect ));
2676 MifDoc::TextRect &leftFooterTextRect = *(new MifDoc::TextRect( footerRect ));
2677
2678 firstMasterPage.TextRects.push_back( firstHeaderTextRect );
2679 firstMasterPage.TextRects.push_back( firstBodyTextRect );
2680 firstMasterPage.TextRects.push_back( firstFooterTextRect );
2681
2682 rightMasterPage.TextRects.push_back( rightHeaderTextRect );
2683 rightMasterPage.TextRects.push_back( rightBodyTextRect );
2684 rightMasterPage.TextRects.push_back( rightFooterTextRect );
2685
2686 leftMasterPage.TextRects.push_back( leftHeaderTextRect );
2687 leftMasterPage.TextRects.push_back( leftBodyTextRect );
2688 leftMasterPage.TextRects.push_back( leftFooterTextRect );
2689
2690 bodyPage.TextRects.push_back( bodyTextRect );
2691 mifDoc.pages().push_back( bodyPage );
2692 mifDoc.pages().push_back( firstMasterPage );
2693 mifDoc.pages().push_back( rightMasterPage );
2694 mifDoc.pages().push_back( leftMasterPage );
2695
2696 MifDoc::ParagraphFormat headerPF;
2697 headerPF.setDSSSLDefaults();
2698 MifDoc::ParagraphFormat footerPF;
2699 footerPF.setDSSSLDefaults();
2700 setupHeaderFooterParagraphFormat( headerPF, footerPF, bodyRect.w );
2701
2702 FotSimplePageSequence.BodyTextFlow
2703 = new MifDoc::TextFlow( bodyTextRect, true, &FotSimplePageSequence.paragraphFormat,
2704 MifDoc::sDefaultPgfFormat );
2705 FotSimplePageSequence.FirstHeaderTextFlow
2706 = new MifDoc::TextFlow( firstHeaderTextRect, false, &headerPF, MifDoc::sHeader );
2707 FotSimplePageSequence.FirstFooterTextFlow
2708 = new MifDoc::TextFlow( firstFooterTextRect, false, &footerPF, MifDoc::sFooter );
2709 FotSimplePageSequence.LeftHeaderTextFlow
2710 = new MifDoc::TextFlow( leftHeaderTextRect, false, &headerPF, MifDoc::sHeader );
2711 FotSimplePageSequence.LeftFooterTextFlow
2712 = new MifDoc::TextFlow( leftFooterTextRect, false, &footerPF, MifDoc::sFooter );
2713 FotSimplePageSequence.RightHeaderTextFlow
2714 = new MifDoc::TextFlow( rightHeaderTextRect, false, &headerPF, MifDoc::sHeader );
2715 FotSimplePageSequence.RightFooterTextFlow
2716 = new MifDoc::TextFlow( rightFooterTextRect, false, &footerPF, MifDoc::sFooter );
2717
2718 makeEmptyTextFlow( firstBodyTextRect );
2719 makeEmptyTextFlow( leftBodyTextRect );
2720 makeEmptyTextFlow( rightBodyTextRect );
2721
2722 mifDoc.textFlows().push_back( *FotSimplePageSequence.BodyTextFlow );
2723 mifDoc.textFlows().push_back( *FotSimplePageSequence.FirstHeaderTextFlow );
2724 mifDoc.textFlows().push_back( *FotSimplePageSequence.FirstFooterTextFlow );
2725 mifDoc.textFlows().push_back( *FotSimplePageSequence.LeftHeaderTextFlow );
2726 mifDoc.textFlows().push_back( *FotSimplePageSequence.LeftFooterTextFlow );
2727 mifDoc.textFlows().push_back( *FotSimplePageSequence.RightHeaderTextFlow );
2728 mifDoc.textFlows().push_back( *FotSimplePageSequence.RightFooterTextFlow );
2729
2730 mifDoc.document().setDTwoSides( true );
2731 mifDoc.document().setDParity( MifDoc::sFirstRight );
2732 }
2733
2734 mifDoc.enterTextFlow( *FotSimplePageSequence.BodyTextFlow );
2735 }
2736
2737 void MifFOTBuilder::startSimplePageSequenceHeaderFooter( unsigned hfPart ) {
2738
2739 if( firstHeaderFooter ) { setupSimplePageSequence(); firstHeaderFooter = false; }
2740
2741 MifDoc::TextFlow *curTextFlow;
2742
2743 if( hfPart & firstHF )
2744 if( hfPart & frontHF )
2745 if( hfPart & headerHF )
2746 curTextFlow = FotSimplePageSequence.FirstHeaderTextFlow;
2747 else
2748 curTextFlow = FotSimplePageSequence.FirstFooterTextFlow;
2749 else
2750 return;
2751 else
2752 if( hfPart & frontHF )
2753 if( hfPart & headerHF )
2754 curTextFlow = FotSimplePageSequence.RightHeaderTextFlow;
2755 else
2756 curTextFlow = FotSimplePageSequence.RightFooterTextFlow;
2757 else
2758 if( hfPart & headerHF )
2759 curTextFlow = FotSimplePageSequence.LeftHeaderTextFlow;
2760 else
2761 curTextFlow = FotSimplePageSequence.LeftFooterTextFlow;
2762
2763 mifDoc.enterTextFlow( *curTextFlow );
2764
2765 if( hfPart & (centerHF | rightHF) )
2766 mifDoc.outSpecialChar( MifDoc::sTab );
2767 else // leftHF
2768 (hfPart & headerHF) ? beginHeader() : beginFooter();
2769 }
2770
2771 void MifFOTBuilder::endSimplePageSequenceHeaderFooter( unsigned hfPart ) {
2772
2773 if( hfPart & rightHF && (hfPart & frontHF || !(hfPart & firstHF)) ) {
2774 endHeaderFooter();
2775 }
2776
2777 if( !(hfPart & firstHF) || hfPart & frontHF )
2778 mifDoc.exitTextFlow();
2779 }
2780
2781 void MifFOTBuilder::setupHeaderFooterParagraphFormat
2782 ( MifDoc::ParagraphFormat &hpf, MifDoc::ParagraphFormat &fpf,
2783 MifDoc::T_dimension textRectWidth ) {
2784
2785 MifDoc::TabStop centerTS( MifDoc::sCenter, textRectWidth / 2 );
2786 MifDoc::TabStop rightTS( MifDoc::sRight, textRectWidth );
2787
2788 hpf.setFrom( FotSimplePageSequence.paragraphFormat, 0, MifDoc::FontFormat::fAll );
2789 hpf.TabStops.push_back( centerTS );
2790 hpf.TabStops.push_back( rightTS );
2791 hpf.setProperties |= MifDoc::ParagraphFormat::fTabStops;
2792 fpf = hpf;
2793 hpf.setFSize( ( ( format().FotBottomMargin - format().FotFooterMargin ) * 3 ) / 2 );
2794 fpf.setFSize( ( format().FotHeaderMargin * 3 ) / 2 );
2795 hpf.setPgfTag( MifDoc::sHeader );
2796 fpf.setPgfTag( MifDoc::sFooter );
2797
2798 mifDoc.pgfCatalog().ParaFormats.push_back( hpf );
2799 mifDoc.pgfCatalog().ParaFormats.push_back( fpf );
2800
2801 hpf.clearSetProperties();
2802 fpf.clearSetProperties();
2803 }
2804
2805 void MifFOTBuilder::endAllSimplePageSequenceHeaderFooter() {
2806
2807 // mifDoc.enterTextFlow( *FotSimplePageSequence.BodyTextFlow );
2808 }
2809
2810 inline void MifFOTBuilder::pageNumber() {
2811
2812 mifDoc.outPageNumber();
2813 }
2814
2815 // --------- MifFOTBuilder::Table ---------------------------------------------
2816
2817 void MifFOTBuilder::Table::resolveBorders
2818 ( Vector<Row> &rows, bool hasFirstTableRow, bool hasLastTableRow ) {
2819
2820 bool isFirstRow;
2821 bool isLastRow;
2822 bool isFirstColumn;
2823 bool isLastColumn;
2824 Cell *cell = NULL;
2825 size_t r, c, rr, cc;
2826 bool leftEdge, topEdge;
2827
2828 for( r = 0; r < rows.size(); r++ ) {
2829 for( c = 0; c < rows[r].Cells.size()-1; c++ ) {
2830 cell = &rows[r].Cells[c];
2831 if( cell->OverlappingCell == NULL ) {
2832 for( rr = r; rr < r + cell->nRowsSpanned; rr++ ) {
2833 for( cc = c, leftEdge = true; cc < c + cell->nColumnsSpanned; cc++ ) {
2834 rows[rr].Cells[cc].OverlappingCell = cell;
2835 }
2836 }
2837 }
2838 }
2839 }
2840
2841 for( r = 0; r < rows.size(); r++ ) {
2842 for( c = 0; c < rows[r].Cells.size() - 1; c++ ) {
2843 cell = &rows[r].Cells[c];
2844 if( cell->OverlappingCell == cell ) {
2845 for( rr = r, topEdge = true; rr < r + cell->nRowsSpanned; rr++ ) {
2846 isFirstRow = ( rr == 0 ) ? true : false;
2847 isLastRow = ( rr == rows.size() - 1 ) ? true : false;
2848 for( cc = c, leftEdge = true; cc < c + cell->nColumnsSpanned; cc++ ) {
2849 isFirstColumn = ( cc == 0 ) ? true : false;
2850 isLastColumn = ( cc == rows[rr].Cells.size() - 2 ) ? true : false;
2851
2852 if( leftEdge )
2853 if( isFirstColumn ) {
2854 cell->beforeColumnBorder.resolve( beforeColumnBorder );
2855 } else
2856 cell->beforeColumnBorder.resolve
2857 ( rows[rr].Cells[cc-1].OverlappingCell->afterColumnBorder );
2858
2859 if( topEdge )
2860 if( isFirstRow && hasFirstTableRow )
2861 cell->beforeRowBorder.resolve( beforeRowBorder );
2862 else
2863 if( !isFirstRow )
2864 cell->beforeRowBorder.resolve
2865 ( rows[rr-1].Cells[cc].OverlappingCell->afterRowBorder );
2866
2867 if( isLastColumn )
2868 cell->afterColumnBorder.resolve( afterColumnBorder );
2869
2870 if( isLastRow && hasLastTableRow )
2871 cell->afterRowBorder.resolve( afterRowBorder );
2872
2873 leftEdge = false;
2874 }
2875 topEdge = false;
2876 }
2877 }
2878 }
2879 }
2880 }
2881
2882 void MifFOTBuilder::Table::begin( MifDoc &mifDoc ) {
2883
2884 CurCell = NULL;
2885 NoTablePartsSeen = true;
2886
2887 TableParts.resize( 0 );
2888 TableParts.resize( 1 );
2889 TableParts.back().begin( *this, mifDoc );
2890 }
2891
2892 // --------- MifFOTBuilder::TablePart -----------------------------------------
2893
2894 void MifFOTBuilder::TablePart::begin( Table &parent, MifDoc &mifDoc ) {
2895
2896 Columns.resize( 0 );
2897 Header.resize( 0 );
2898 Body.resize( 0 );
2899 Footer.resize( 0 );
2900
2901 columnsProcessed = false;
2902 needsColumnReprocessing = false;
2903
2904 ParentTable = &parent;
2905 parentTable().CurRows = &Body;
2906 parentTable().CurTablePart = this;
2907
2908 if( MifTableNum == 0 ) {
2909 mifDoc.tbls().resize( mifDoc.tbls().size() + 1 );
2910 MifTableNum = mifDoc.tbls().size();
2911 MifDoc::CurInstance->setCurTblNum( MifTableNum );
2912 }
2913 }
2914
2915 void MifFOTBuilder::TablePart::translate( MifDoc &mifDoc ) {
2916
2917 if( needsColumnReprocessing )
2918 processColumns();
2919
2920 MifDoc::Tbl &mifTbl = mifTable( mifDoc );
2921 if( parentTable().startIndent != 0 ) { // DSSSL default
2922 mifTbl.tblFormat.setTblLIndent( parentTable().startIndent );
2923 mifTbl.setProperties |= MifDoc::Tbl::fTblFormat;
2924 }
2925
2926 if( parentTable().displayAlignment != symbolStart ) {
2927 mifTbl.setProperties |= MifDoc::Tbl::fTblFormat;
2928 MifDoc::T_keyword mifAlignment = MifDoc::sLeft;
2929 switch( parentTable().displayAlignment ) {
2930 case symbolStart: mifAlignment = MifDoc::sLeft; break;
2931 case symbolEnd: mifAlignment = MifDoc::sRight; break;
2932 case symbolCenter: mifAlignment = MifDoc::sCenter; break;
2933 case symbolInside: mifAlignment = MifDoc::sInside; break;
2934 case symbolOutside: mifAlignment = MifDoc::sOutside; break;
2935 default: assert( false );
2936 }
2937 mifTbl.tblFormat.setTblAlignment( mifAlignment );
2938 }
2939
2940 bool putHeaderInBody = Body.size() == 0 && Header.size() > 0;
2941 bool putFooterInBody = !putHeaderInBody && Body.size() == 0 && Footer.size() > 0;
2942 for( size_t i = 0; i < Header.size(); i++ )
2943 Header[i].translate( putHeaderInBody ? mifTbl.TblBody : mifTbl.TblH, mifDoc );
2944 for( size_t i = 0; i < Body.size(); i++)
2945 Body[i].translate( mifTbl.TblBody, mifDoc );
2946 for( size_t i = 0; i < Footer.size(); i++ )
2947 Footer[i].translate( putFooterInBody ? mifTbl.TblBody : mifTbl.TblF, mifDoc );
2948 }
2949
2950 void MifFOTBuilder::TablePart::processColumns() {
2951
2952 MifDoc::Tbl &mifTbl = mifTable( *MifDoc::CurInstance );
2953 mifTbl.setTblNumColumns( 0 );
2954 mifTbl.setTblNumColumns( Columns.size() );
2955 mifTbl.TblColumnWidths.resize( 0 );
2956 mifTbl.TblColumnWidths.resize( Columns.size() );
2957 mifTbl.TblColumnWidthsAreSet();
2958
2959 long totalNonproportionalWidth = 0L;
2960 double totalProportionalUnits = 0.0;
2961 for( size_t i = 0; i < Columns.size(); i++ ) {
2962 if( Columns[i].hasWidth ) {
2963 if( Columns[i].width.tableUnitFactor ) {
2964 totalProportionalUnits += Columns[i].width.tableUnitFactor;
2965 } else {
2966 mifTbl.TblColumnWidths[i]
2967 = MifFOTBuilder::curInstance().computeLengthSpec( Columns[i].width );
2968 totalNonproportionalWidth += mifTbl.TblColumnWidths[i];
2969 }
2970 }
2971 }
2972
2973 double proportionalUnit = 0.0;
2974 if( totalProportionalUnits )
2975 proportionalUnit
2976 = ( parentTable().tableWidth - totalNonproportionalWidth ) / totalProportionalUnits;
2977
2978 for( size_t i = 0; i < Columns.size(); i++ ) {
2979 if( Columns[i].hasWidth ) {
2980 if( Columns[i].width.tableUnitFactor )
2981 mifTbl.TblColumnWidths[i]
2982 = long(proportionalUnit * Columns[i].width.tableUnitFactor);
2983 } else
2984 mifTbl.TblColumnWidths[i] = long(proportionalUnit);
2985 }
2986
2987 columnsProcessed = true;
2988 }
2989
2990 void MifFOTBuilder::TablePart::normalizeRows() {
2991
2992 size_t maxCellsInRow = Columns.size()+1;
2993 Vector<Row> *rows;
2994 for( int step = 0; step < 2; step++ ) {
2995 for( int rowType = 0; rowType < 3; rowType++ ) {
2996 switch( rowType ) {
2997 case 0: rows = &Header; break;
2998 case 1: rows = &Body; break;
2999 default: rows = &Footer;
3000 }
3001 for( size_t r = 0; r < rows->size(); r++ ) {
3002 if( step == 0 ) {
3003 if( (*rows)[r].Cells.size() > 1 ) {
3004 size_t lastCellIdx = (*rows)[r].Cells.size()-2;
3005 Cell &lastCell = (*rows)[r].Cells[lastCellIdx];
3006 if( !lastCell.missing
3007 &&
3008 lastCellIdx+lastCell.nColumnsSpanned+1 > maxCellsInRow )
3009 maxCellsInRow = lastCellIdx+lastCell.nColumnsSpanned+1;
3010 }
3011 } else if( (*rows)[r].Cells.size() < maxCellsInRow )
3012 (*rows)[r].Cells.resize( maxCellsInRow );
3013 }
3014 }
3015 }
3016 }
3017
3018 // --------- MifFOTBuilder::Row -----------------------------------------------
3019
3020 void MifFOTBuilder::Row::translate( Vector<MifDoc::Row> &mifRows, MifDoc &mifDoc ) {
3021
3022 mifRows.resize( mifRows.size() + 1 );
3023 MifDoc::Row &mifRow = mifRows.back();
3024 mifRow.Cells.resize( Cells.size() - 1 );
3025 for( size_t i = 0; i + 1 < Cells.size(); i++ ) {
3026 Cells[i].translate( Cells[i].mifCell(), mifDoc );
3027 mifRow.Cells[i] = Cells[i].mifCell();
3028 }
3029 }
3030
3031 // --------- MifFOTBuilder::Cell ----------------------------------------------
3032
3033 void MifFOTBuilder::Cell::translate( MifDoc::Cell &mifCell, MifDoc &mifDoc ) {
3034
3035 MifDoc::T_tagstring rulingTag;
3036
3037 rulingTag = beforeRowBorder.makeMifRuling( mifDoc );
3038 if( rulingTag.size() )
3039 mifCell.setCellTRuling( rulingTag );
3040
3041 rulingTag = afterRowBorder.makeMifRuling( mifDoc );
3042 if( rulingTag.size() )
3043 mifCell.setCellBRuling( rulingTag );
3044
3045 rulingTag = beforeColumnBorder.makeMifRuling( mifDoc );
3046 if( rulingTag.size() )
3047 mifCell.setCellLRuling( rulingTag );
3048
3049 rulingTag = afterColumnBorder.makeMifRuling( mifDoc );
3050 if( rulingTag.size() )
3051 mifCell.setCellRRuling( rulingTag );
3052 }
3053
3054 // --------- MifFOTBuilder::Border --------------------------------------------
3055
3056 void MifFOTBuilder::Border::setFromFot() {
3057
3058 MifFOTBuilder::Format &f = MifFOTBuilder::curInstance().format();
3059 borderPriority = f.FotBorderPriority;
3060 borderPresent = f.FotBorderPresent;
3061 lineThickness = f.FotLineThickness;
3062 lineRepeat = f.FotLineRepeat;
3063 lineSep = f.FotLineSep;
3064 color = f.FColor;
3065 }
3066
3067 MifDoc::T_tagstring MifFOTBuilder::Border::makeMifRuling( MifDoc &mifDoc ) {
3068
3069 MifDoc::T_tagstring result;
3070
3071 if( borderPresent ) {
3072
3073 MifDoc::Ruling *mifRuling = new MifDoc::Ruling;
3074
3075 mifRuling->setRulingPenWidth( lineThickness );
3076 mifRuling->setRulingLines( lineRepeat >= 2 ? 2 : lineRepeat );
3077 mifRuling->setRulingGap( lineRepeat >= 2 ? lineSep - lineThickness : 0 );
3078 mifRuling->setRulingColor( color );
3079
3080 result = MifDoc::T_tagstring( mifRuling->key( *mifRuling ) );
3081 mifRuling->setRulingTag( result );
3082
3083 if( mifDoc.rulingCatalog().Rulings.lookup( result ) == NULL ) {
3084 mifDoc.rulingCatalog().Rulings.insert( mifRuling );
3085 } else
3086 delete mifRuling;
3087 }
3088
3089 return result;
3090 }
3091
3092 void MifFOTBuilder::Border::resolve( Border &adjacentBorder ) {
3093
3094 if( adjacentBorder.borderPriority > borderPriority
3095 ||
3096 ( adjacentBorder.borderPriority == borderPriority
3097 && !adjacentBorder.cellBorder
3098 && adjacentBorder.borderPresent ) ) {
3099
3100 lineThickness = adjacentBorder.lineThickness;
3101 borderPresent = adjacentBorder.borderPresent;
3102 lineRepeat = adjacentBorder.lineRepeat;
3103 lineSep = adjacentBorder.lineSep;
3104 color = adjacentBorder.color;
3105
3106 if( adjacentBorder.cellBorder )
3107 adjacentBorder.borderPresent = false;
3108 }
3109 }
3110
3111 //-----------------------------------------------------------------------------
3112
3113 void MifFOTBuilder::setFontSize( long n ) {
3114
3115 nextFormat.FSize = n;
3116 }
3117
3118 void MifFOTBuilder::setLineSpacing( const LengthSpec &l ) {
3119
3120 nextFormat.FotLineSpacingSpec = l;
3121 }
3122
3123 void MifFOTBuilder::setFontWeight( Symbol weight ) {
3124
3125 if( weight > symbolMedium ) {
3126 nextFormat.FWeight = MifDoc::sBold;
3127 } else {
3128 nextFormat.FWeight = MifDoc::sRegular;
3129 }
3130 }
3131
3132 void MifFOTBuilder::setFontPosture( Symbol posture ) {
3133
3134 switch( posture ) {
3135
3136 case symbolOblique:
3137 case symbolBackSlantedOblique:
3138 case symbolItalic:
3139 case symbolBackSlantedItalic:
3140
3141 nextFormat.FAngle = MifDoc::sItalic;
3142 break;
3143
3144 default:
3145 nextFormat.FAngle = MifDoc::sRegular;
3146 }
3147 }
3148
3149 inline void MifFOTBuilder::setStartIndent( const LengthSpec &l ) {
3150
3151 nextFormat.FotStartIndentSpec = l;
3152 }
3153
3154 inline void MifFOTBuilder::setEndIndent( const LengthSpec &l ) {
3155
3156 nextFormat.FotEndIndentSpec = l;
3157 }
3158
3159 inline void MifFOTBuilder::setFirstLineStartIndent( const LengthSpec &l ) {
3160
3161 nextFormat.FotFirstLineStartIndentSpec = l;
3162 }
3163
3164 void MifFOTBuilder::setQuadding( Symbol quadding ) {
3165
3166 switch( quadding ) {
3167
3168 case symbolEnd:
3169
3170 nextFormat.PgfAlignment = MifDoc::sRight;
3171 break;
3172
3173 case symbolCenter:
3174
3175 nextFormat.PgfAlignment = MifDoc::sCenter;
3176 break;
3177
3178 case symbolJustify:
3179
3180 nextFormat.PgfAlignment = MifDoc::sLeftRight;
3181 break;
3182
3183 default: // symbolStart
3184 nextFormat.PgfAlignment = MifDoc::sLeft;
3185 }
3186 }
3187
3188 inline void MifFOTBuilder::setKern( bool kern ) {
3189
3190 nextFormat.FPairKern = kern;
3191 }
3192
3193 inline void MifFOTBuilder::setLanguage( Letter2 code ) {
3194
3195 nextFormat.FotLanguage = code;
3196 nextFormat.computePgfLanguage();
3197 }
3198
3199 inline void MifFOTBuilder::setCountry( Letter2 code ) {
3200
3201 nextFormat.FotCountry = code;
3202 nextFormat.computePgfLanguage();
3203 }
3204
3205 inline void MifFOTBuilder::setHyphenate( bool hyphenate ) {
3206
3207 nextFormat.PgfHyphenate = hyphenate;
3208 }
3209
3210 inline void MifFOTBuilder::setHyphenationRemainCharCount( long n ) {
3211
3212 nextFormat.HyphenMinPrefix = n;
3213 }
3214
3215 inline void MifFOTBuilder::setHyphenationPushCharCount( long n ) {
3216
3217 nextFormat.HyphenMinSuffix = n;
3218 }
3219
3220 inline void MifFOTBuilder::setHyphenationLadderCount( long n ) {
3221
3222 nextFormat.HyphenMaxLines = n;
3223 }
3224
3225 void MifFOTBuilder::setFontFamilyName( const StringC &s ) {
3226
3227 nextFormat.FFamily.resize( 0 );
3228 for( size_t i = 0; i < s.size(); i++ )
3229 nextFormat.FFamily += char(s[i]);
3230 }
3231
3232 inline void MifFOTBuilder::setWidowCount( long n ) {
3233
3234 nextFormat.PgfBlockSize = n;
3235 }
3236
3237 inline void MifFOTBuilder::setOrphanCount( long n ) {
3238
3239 nextFormat.PgfBlockSize = n;
3240 }
3241
3242 inline void MifFOTBuilder::setPageWidth( Length pWidth ) {
3243
3244 nextFormat.FotPageWidth = pWidth;
3245 }
3246
3247 inline void MifFOTBuilder::setPageHeight( Length pHeight ) {
3248
3249 nextFormat.FotPageHeight = pHeight;
3250 }
3251
3252 inline void MifFOTBuilder::setLeftMargin( Length leftM ) {
3253
3254 nextFormat.FotLeftMargin = leftM;
3255 }
3256
3257 inline void MifFOTBuilder::setRightMargin( Length rightM ) {
3258
3259 nextFormat.FotRightMargin = rightM;
3260 }
3261
3262 inline void MifFOTBuilder::setTopMargin( Length topM ) {
3263
3264 nextFormat.FotTopMargin = topM;
3265 }
3266
3267 inline void MifFOTBuilder::setBottomMargin( Length bottomM ) {
3268
3269 nextFormat.FotBottomMargin = bottomM;
3270 }
3271
3272 void MifFOTBuilder::setHeaderMargin( Length headerM ) {
3273
3274 nextFormat.FotHeaderMargin = headerM;
3275 }
3276
3277 void MifFOTBuilder::setFooterMargin( Length footerM ) {
3278
3279 nextFormat.FotFooterMargin = footerM;
3280 }
3281
3282 void MifFOTBuilder::setDisplayAlignment( Symbol alignment ) {
3283
3284 nextFormat.FotDisplayAlignment = alignment;
3285 }
3286
3287 //--------- LEADERS -----------------------------------------------------------
3288
3289 void MifFOTBuilder::startLeader( const LeaderNIC & ) {
3290
3291 checkForParagraphReopening();
3292 lastFlowObjectWasWhitespace = false;
3293
3294 mifDoc.outSpecialChar( MifDoc::sTab );
3295 inLeader = true;
3296 setCurLeaderStream( new MifTmpOutputByteStream() );
3297 }
3298
3299 void MifFOTBuilder::endLeader() {
3300
3301 if( !mifDoc.curPara()->leaderTabsSet ) {
3302
3303 String<char> leaderStr;
3304 curLeaderStream().commit( leaderStr );
3305
3306 int numTabs = mifDoc.curFormat().PgfNumTabs + 1;
3307 mifDoc.curFormat().setPgfNumTabs( numTabs );
3308 mifDoc.curPara()->format().TabStops.push_back
3309 ( MifDoc::TabStop( MifDoc::sRight, format().FotCurDisplaySize
3310 - mifDoc.curFormat().PgfRIndent - 1,
3311 MifDoc::T_string( leaderStr ) ) );
3312 mifDoc.curPara()->format().setPgfNumTabs( numTabs );
3313 mifDoc.curPara()->curFormat().setPgfNumTabs( numTabs );
3314 mifDoc.curPara()->format().setProperties |= MifDoc::ParagraphFormat::fTabStops;
3315
3316 mifDoc.curPara()->leaderTabsSet = true;
3317 }
3318
3319 if( CurLeaderStream ) {
3320 delete CurLeaderStream;
3321 CurLeaderStream = NULL;
3322 }
3323 inLeader = false;
3324 lastFlowObjectWasWhitespace = false;
3325 }
3326
3327 //--------- LINE FIELDS -------------------------------------------------------
3328
3329 void MifFOTBuilder::startLineField( const LineFieldNIC & ) {
3330
3331 checkForParagraphReopening();
3332 lastFlowObjectWasWhitespace = false;
3333
3334 Length fieldWidth = computeLengthSpec( nextFormat.FotFieldWidth );
3335 Length firstLineIndent = mifDoc.curPara()->format().PgfFIndent;
3336 bool leadingTab = true;
3337 switch( nextFormat.FotFieldAlign ) {
3338 case symbolStart: default:
3339 mifDoc.curPara()->format().TabStops.push_back
3340 ( MifDoc::TabStop( MifDoc::sLeft, firstLineIndent + fieldWidth ) );
3341 leadingTab = false;
3342 break;
3343 case symbolEnd:
3344 mifDoc.curPara()->format().TabStops.push_back
3345 ( MifDoc::TabStop( MifDoc::sRight, firstLineIndent + fieldWidth ) );
3346 mifDoc.curPara()->format().TabStops.push_back
3347 ( MifDoc::TabStop( MifDoc::sLeft, firstLineIndent + fieldWidth + 1 ) );
3348 break;
3349 case symbolCenter:
3350 mifDoc.curPara()->format().TabStops.push_back
3351 ( MifDoc::TabStop( MifDoc::sCenter, firstLineIndent + fieldWidth / 2 ) );
3352 mifDoc.curPara()->format().TabStops.push_back
3353 ( MifDoc::TabStop( MifDoc::sLeft, firstLineIndent + fieldWidth + 1 ) );
3354 }
3355
3356
3357 int numTabs = mifDoc.curFormat().PgfNumTabs + leadingTab ? 2 : 1;
3358 mifDoc.curFormat().setPgfNumTabs( numTabs );
3359 mifDoc.curPara()->format().setPgfNumTabs( numTabs );
3360 mifDoc.curPara()->curFormat().setPgfNumTabs( numTabs );
3361 mifDoc.curPara()->format().setProperties |= MifDoc::ParagraphFormat::fTabStops;
3362
3363 start();
3364
3365 if( leadingTab )
3366 mifDoc.outSpecialChar( MifDoc::sTab );
3367 }
3368
3369 void MifFOTBuilder::endLineField() {
3370
3371 mifDoc.outSpecialChar( MifDoc::sTab );
3372 end();
3373 lastFlowObjectWasWhitespace = false;
3374 }
3375
3376 //--------- PARAGRAPH BREAKS --------------------------------------------------
3377
3378 void MifFOTBuilder::paragraphBreak( const ParagraphNIC &nic ) {
3379
3380 if( MifDoc::Para::currentlyOpened ) {
3381 if( paragraphBreakInEffect )
3382 doEndParagraph( false, false, false );
3383 else {
3384 doEndParagraph( true, false, false );
3385 paragraphBreakInEffect = true;
3386 }
3387 doStartParagraph( nic );
3388 }
3389 }
3390
3391 //--------- SCORES ------------------------------------------------------------
3392
3393 void MifFOTBuilder::startScore( Symbol scoreType ) {
3394
3395 checkForParagraphReopening();
3396
3397 switch( scoreType ) {
3398 case symbolBefore:
3399 nextFormat.setFOverline( true );
3400 break;
3401 case symbolThrough:
3402 nextFormat.setFStrike( true );
3403 break;
3404 case symbolAfter: default:
3405 nextFormat.setFUnderlining
3406 ( nextFormat.FotLineRepeat > 1 ? MifDoc::sFDouble : MifDoc::sFSingle );
3407 break;
3408 }
3409
3410 start();
3411 }
3412
3413 void MifFOTBuilder::endScore() {
3414
3415 end();
3416 }
3417
3418 //--------- ANCHORED FRAMES (GENERAL) -----------------------------------------
3419
3420 MifDoc::Frame &MifFOTBuilder::makeAnchoredFrame
3421 ( MifDoc::T_keyword frameType, long width, long height, MifDoc::T_keyword anchorAlign ) {
3422
3423 mifDoc.aFrames().resize( mifDoc.aFrames().size() + 1 );
3424 MifDoc::Frame &frame = mifDoc.aFrames().back();
3425
3426 frame.setFrameType( frameType );
3427 frame.setAnchorAlign( anchorAlign );
3428 frame.setShapeRect( MifDoc::T_LTWH( 0, 0, width, height ) );
3429
3430 return frame;
3431 }
3432
3433 //--------- EXTERNAL GRAPHICS -------------------------------------------------
3434
3435 void MifFOTBuilder::externalGraphic( const ExternalGraphicNIC &nic ) {
3436
3437 bool isInline = MifDoc::Para::currentlyOpened ? true : false;
3438
3439 if( !isInline )
3440 startDisplay( nic );
3441 start();
3442
3443 MifDoc::T_pathname mifPathname;
3444 if( systemIdToMifPathname( nic.entitySystemId, mifPathname ) ) {
3445
3446
3447 MifDoc::T_keyword mifAlignment = MifDoc::sLeft;
3448 switch( format().FotDisplayAlignment ) {
3449 case symbolStart: mifAlignment = MifDoc::sLeft; break;
3450 case symbolEnd: mifAlignment = MifDoc::sRight; break;
3451 case symbolCenter: mifAlignment = MifDoc::sCenter; break;
3452 case symbolInside: mifAlignment = MifDoc::sInside; break;
3453 case symbolOutside: mifAlignment = MifDoc::sOutside; break;
3454 default: assert( false );
3455 }
3456
3457 MifDoc::Frame &frame
3458 = makeAnchoredFrame( isInline ? MifDoc::sInline : MifDoc::sBelow,
3459 nic.hasMaxWidth ? computeLengthSpec( nic.maxWidth ) : 72000,
3460 nic.hasMaxHeight ? computeLengthSpec( nic.maxHeight ) : 72000,
3461 mifAlignment );
3462
3463 MifDoc::ImportObject *importObject
3464 = new MifDoc::ImportObject( mifPathname, frame.ShapeRect );
3465 frame.Objects.resize( frame.Objects.size() + 1 );
3466 frame.Objects.back() = importObject;
3467
3468 if( !isInline )
3469 doStartParagraph( nic, true, 0, false );
3470 else
3471 checkForParagraphReopening();
3472 mifDoc.outAFrame( frame.ID, mifDoc.os() );
3473 if( !isInline )
3474 endParagraph();
3475 else
3476 lastFlowObjectWasWhitespace = false;
3477 }
3478
3479 end();
3480 if( !isInline )
3481 endDisplay();
3482 }
3483
3484 enum TComponent { cName, cUp, cRoot, cRootDrive };
3485 void addComponent( MifDoc::T_pathname &target, TComponent cType, StringC &component ) {
3486
3487 target += '<';
3488 target += cType == cName ? 'c' : ( cType == cUp ? 'u' : 'r' );
3489 target += '\\';
3490 target += '>';
3491 if( cType == cName || cType == cRootDrive )
3492 for( size_t i = 0; i < component.size(); i++ )
3493 target += char( component[i] );
3494 }
3495
3496 bool MifFOTBuilder::systemIdToMifPathname
3497 ( const StringC &systemId, MifDoc::T_pathname &mifPathname ) {
3498
3499 StringC filename;
3500 StringC component;
3501 int result;
3502
3503 if( ( result = systemIdFilename( systemId, filename ) ) < 0 ) {
3504 App->message( MifMessages::systemIdNotFilename, StringMessageArg( systemId ) );
3505 return false;
3506 } else {
3507 bool firstComponent = true;
3508 size_t i = 0;
3509 do {
3510 component.resize( 0 );
3511 while( i < filename.size() && filename[i] != '\\' && filename[i] != '/' )
3512 component += char( filename[i++] );
3513 switch( component.size() ) {
3514 case 2:
3515 if( firstComponent && component[1] == ':' )
3516 addComponent( mifPathname, cRootDrive, component );
3517 else
3518 if( component[0] == '.' && component[1] == '.' )
3519 addComponent( mifPathname, cUp, component );
3520 else
3521 goto add_component;
3522 break;
3523 case 1:
3524 if( component[0] != '.' )
3525 goto add_component;
3526 break;
3527 case 0:
3528 if( firstComponent && filename.size() > 0 )
3529 addComponent( mifPathname, cRoot, component );
3530 break;
3531 add_component: default:
3532 addComponent( mifPathname, cName, component );
3533 }
3534 firstComponent = false;
3535 i++;
3536 } while( i < filename.size() );
3537 }
3538
3539 return result == 0 ? false : true;
3540 }
3541
3542 // System Id Resolution from James Clark
3543
3544 // Return -1 if an error should be generated
3545 // FIXME in some cases should copy the entity into a file in the same
3546 // directory as the output file.
3547
3548 int MifFOTBuilder::systemIdFilename(const StringC &systemId, StringC &filename)
3549 {
3550 if (systemId.size() == 0)
3551 return -1;
3552 Owner<InputSource> in(EntityManager->open(systemId,
3553 *SystemCharset,
3554 InputSourceOrigin::make(),
3555 0,
3556 *App));
3557 if (!in)
3558 return 0;
3559 Xchar c = in->get(*App);
3560 StorageObjectLocation soLoc;
3561 ParsedSystemId parsedBuf;
3562 if (c == InputSource::eE && in->accessError()) {
3563 if (!EntityManager->parseSystemId(systemId, *SystemCharset, 0, 0, *App, parsedBuf))
3564 return 0;
3565 if (parsedBuf.size() != 1 || parsedBuf[0].baseId.size())
3566 return 0;
3567 soLoc.storageObjectSpec = &parsedBuf[0];
3568 soLoc.actualStorageId = parsedBuf[0].specId;
3569 }
3570 else {
3571 const Location &loc = in->currentLocation();
3572 if (loc.origin().isNull())
3573 return -1;
3574 const InputSourceOrigin *tem = loc.origin()->asInputSourceOrigin();
3575 if (!tem)
3576 return -1;
3577 const ParsedSystemId *psi
3578 = ExtendEntityManager::externalInfoParsedSystemId(tem->externalInfo());
3579 if (!psi || psi->size() != 1)
3580 return -1;
3581 if (!ExtendEntityManager::externalize(tem->externalInfo(), 0, soLoc))
3582 return -1;
3583 }
3584 if (strcmp(soLoc.storageObjectSpec->storageManager->type(), "OSFILE") != 0)
3585 return -1;
3586 filename = soLoc.actualStorageId;
3587 return 1;
3588 }
3589
3590 //--------- RULES -------------------------------------------------------------
3591
3592 void MifFOTBuilder::rule( const RuleNIC &nic ) {
3593
3594 bool isInline = ( nic.orientation == symbolHorizontal || nic.orientation == symbolVertical )
3595 ? false : true;
3596
3597 if( isInline )
3598 checkForParagraphReopening();
3599
3600 if( !isInline )
3601 startDisplay( nic );
3602 start();
3603
3604 long indentlessDisplaySize
3605 = format().FotCurDisplaySize - computeLengthSpec( format().FotStartIndentSpec )
3606 - computeLengthSpec( format().FotEndIndentSpec );
3607
3608 MifDoc::T_dimension ruleHeight
3609 = format().FotLineThickness + format().FotLineSep * ( format().FotLineRepeat - 1 );
3610 if( ruleHeight < 0 )
3611 ruleHeight = 0;
3612
3613 MifDoc::T_dimension ruleLength;
3614 MifDoc::T_dimension ruleOffset;
3615
3616 if( nic.hasLength && ( ruleLength = computeLengthSpec( nic.length ) ) > 0 ) {
3617 switch( format().FotDisplayAlignment ) {
3618 case symbolStart: default:
3619 ruleOffset = 0;
3620 break;
3621 case symbolCenter:
3622 ruleOffset = ( indentlessDisplaySize - ruleLength ) / 2;
3623 break;
3624 case symbolEnd:
3625 ruleOffset = indentlessDisplaySize - ruleLength;
3626 }
3627 } else {
3628 ruleOffset = 0;
3629 ruleLength = indentlessDisplaySize;
3630 }
3631
3632 MifDoc::Frame &frame
3633 = makeAnchoredFrame( MifDoc::sInline, isInline ? long(ruleLength) : indentlessDisplaySize,
3634 ruleHeight );
3635
3636 if( isInline )
3637 frame.setBLOffset( computeLengthSpec( format().FotPositionPointShiftSpec ) );
3638 else
3639 frame.setBLOffset( -ruleHeight / 2 + 4000 / 3 ); // min font baseline correction
3640
3641 MifDoc::T_keyword capType;
3642 switch( format().FotLineCap ) {
3643 case symbolButt: default: capType = MifDoc::sButt; break;
3644 case symbolRound: capType = MifDoc::sRound; break;
3645 case symbolSquare: capType = MifDoc::sSquare;
3646 }
3647 MifDoc::PolyLine *polyLine;
3648 Length curLineVOffset = format().FotLineThickness / 2;
3649 for( long i = format().FotLineRepeat; i > 0; i--, curLineVOffset += format().FotLineSep ) {
3650
3651 polyLine = new MifDoc::PolyLine( capType, 0, 0, format().FotLineThickness,
3652 format().FColor );
3653 frame.Objects.resize( frame.Objects.size() + 1 );
3654 frame.Objects.back() = polyLine;
3655
3656 polyLine->setHeadCap( capType );
3657 polyLine->setTailCap( capType );
3658 polyLine->Points.resize( polyLine->Points.size() + 1 );
3659 polyLine->Points.back() = MifDoc::T_XY( ruleOffset, curLineVOffset );
3660 polyLine->Points.resize( polyLine->Points.size() + 1 );
3661 polyLine->Points.back() = MifDoc::T_XY( ruleOffset + ruleLength, curLineVOffset );
3662 }
3663
3664 if( !isInline ) doStartParagraph( nic, true, 0, true );
3665 mifDoc.outAFrame( frame.ID, mifDoc.os() );
3666 if( !isInline )
3667 endParagraph();
3668 else
3669 lastFlowObjectWasWhitespace = false;
3670
3671 end();
3672 if( !isInline )
3673 endDisplay();
3674 }
3675
3676 //--------- TABLES ------------------------------------------------------------
3677
3678 void MifFOTBuilder::startTable( const TableNIC &nic ) {
3679
3680 startDisplay( nic );
3681 start();
3682
3683 if( !curTable().DefaultTblFormatGenerated ) {
3684
3685 MifDoc::TblFormat defaultTblFormat( MifDoc::sDefaultTblFormat );
3686 defaultTblFormat.setDSSSLDefaults();
3687 mifDoc.tblCatalog().TblFormats.push_back( defaultTblFormat );
3688 curTable().DefaultTblFormatGenerated = true;
3689 }
3690
3691 Length curStartIndent = computeLengthSpec( format().FotStartIndentSpec );
3692 curTable().startIndent = curStartIndent;
3693
3694 curTable().begin( mifDoc );
3695 // curTable().nic = nic;
3696 curTable().displayAlignment = format().FotDisplayAlignment;
3697
3698 if( nic.widthType == TableNIC::widthExplicit )
3699 curTable().tableWidth = computeLengthSpec( nic.width );
3700 else
3701 curTable().tableWidth
3702 = format().FotCurDisplaySize - curStartIndent
3703 - computeLengthSpec( format().FotEndIndentSpec );
3704
3705
3706 doStartParagraph( nic, true, 0 );
3707 endParagraph();
3708 }
3709
3710 void MifFOTBuilder::endTable() {
3711
3712 bool firstPart, lastPart, hasHeader, hasFooter;
3713 for( size_t i = 0; i < curTable().TableParts.size(); i++ ) {
3714 firstPart = ( i == 0 ) ? true : false;
3715 lastPart = ( i == curTable().TableParts.size() - 1 ) ? true : false;
3716 TablePart &tablePart = curTable().TableParts[i];
3717 tablePart.normalizeRows();
3718 hasHeader = tablePart.Header.size() > 0 ? true : false;
3719 hasFooter = tablePart.Footer.size() > 0 ? true : false;
3720 if( hasHeader )
3721 curTable().resolveBorders( tablePart.Header,
3722 firstPart ? true : false, false );
3723 curTable().resolveBorders( tablePart.Body,
3724 hasHeader ? false : true, hasFooter ? false : true );
3725 if( hasFooter )
3726 curTable().resolveBorders( tablePart.Footer,
3727 false, lastPart ? true : false );
3728 tablePart.translate( mifDoc );
3729 }
3730
3731 MifDoc::CurInstance->setCurTblNum( 0 );
3732
3733 endDisplay();
3734 end();
3735 }
3736
3737 void MifFOTBuilder::tableColumn( const TableColumnNIC &nic ) {
3738
3739 if( nic.columnIndex >= curTable().curTablePart().Columns.size() )
3740 curTable().curTablePart().Columns.resize( nic.columnIndex + 1 );
3741
3742 curTable().curTablePart().Columns[nic.columnIndex].hasWidth = nic.hasWidth;
3743 if( nic.hasWidth ) {
3744 curTable().curTablePart().Columns[nic.columnIndex].width = nic.width;
3745 }
3746 }
3747
3748 void MifFOTBuilder::startTableRow() {
3749
3750 curTable().curRows().resize( curTable().curRows().size() + 1 );
3751 }
3752
3753 void MifFOTBuilder::endTableRow() {
3754
3755 }
3756
3757 void MifFOTBuilder::startTableCell( const TableCellNIC &nic ) {
3758
3759 start();
3760
3761 TablePart &tp = curTable().curTablePart();
3762 if( !tp.columnsProcessed )
3763 tp.processColumns();
3764
3765 Vector<Cell> &Cells = curTable().curRows().back().Cells;
3766 if( nic.columnIndex >= Cells.size() )
3767 Cells.resize( nic.columnIndex + 1 );
3768
3769 Cell &cell = Cells[nic.columnIndex];
3770 curTable().CurCell = &cell;
3771 cell.missing = nic.missing;
3772
3773 if( nic.nColumnsSpanned != 1 ) {
3774 cell.nColumnsSpanned = nic.nColumnsSpanned;
3775 cell.mifCell().setCellColumns( nic.nColumnsSpanned );
3776 }
3777
3778 if( nic.nRowsSpanned != 1 ) {
3779 cell.nRowsSpanned = nic.nRowsSpanned;
3780 cell.mifCell().setCellRows( nic.nRowsSpanned );
3781 }
3782
3783 if( format().FotCellBackground && format().MifBackgroundColor.size() > 0 ) {
3784 cell.mifCell().setCellFill( 0 );
3785 cell.mifCell().setCellColor( format().MifBackgroundColor );
3786 }
3787
3788 long newDisplaySize = 0;
3789 for( size_t i = nic.columnIndex; i < nic.columnIndex + nic.nColumnsSpanned; i++ )
3790 if( i < tp.Columns.size() ) {
3791 if( tp.Columns[i].hasWidth )
3792 newDisplaySize
3793 += computeLengthSpec( tp.Columns[i].width );
3794 } else
3795 if( !nic.missing ) {
3796 App->message( MifMessages::missingTableColumnFlowObject );
3797 // NOTE: at this point there's already a danger of not realizing
3798 // right display space sizes inside cells
3799 tp.Columns.resize( tp.Columns.size() + 1 );
3800 tp.Columns.back().hasWidth = true;
3801 TableLengthSpec tls; tls.tableUnitFactor = 1.0;
3802 tp.Columns.back().width = tls;
3803 tp.needsColumnReprocessing = true;
3804 if( (MifDoc::T_integer)i > tp.mifTable( mifDoc ).TblNumColumns )
3805 tp.mifTable( mifDoc ).setTblNumColumns( i );
3806 }
3807
3808 newDisplaySize -= format().PgfCellMargins.l + format().PgfCellMargins.r;
3809
3810 if( newDisplaySize > 0 )
3811 format().FotCurDisplaySize = newDisplaySize;
3812
3813 cell.displaySize = format().FotCurDisplaySize;
3814 mifDoc.enterTableCell( cell.mifCell() );
3815 }
3816
3817 void MifFOTBuilder::endTableCell() {
3818
3819 mifDoc.exitTableCell();
3820 end();
3821
3822 curTable().CurCell = NULL;
3823 }
3824
3825 void MifFOTBuilder::startTablePartSerial( const TablePartNIC &nic ) {
3826
3827 startDisplay( nic );
3828 start();
3829
3830 if( curTable().NoTablePartsSeen )
3831 curTable().NoTablePartsSeen = false;
3832 else
3833 curTable().TableParts.resize( curTable().TableParts.size() + 1 );
3834
3835 curTable().TableParts.back().begin( curTable(), mifDoc );
3836
3837 doStartParagraph( nic, true, 0 );
3838 endParagraph();
3839 }
3840
3841 void MifFOTBuilder::endTablePartSerial() {
3842
3843 curTable().CurTablePart = NULL;
3844 endDisplay();
3845 end();
3846 }
3847
3848 void MifFOTBuilder::startTablePartHeader() {
3849
3850 curTable().CurRows = &curTable().curTablePart().Header;
3851 }
3852
3853 void MifFOTBuilder::endTablePartHeader() {
3854
3855 curTable().CurRows = &curTable().curTablePart().Body;
3856 }
3857
3858 void MifFOTBuilder::startTablePartFooter() {
3859
3860 curTable().CurRows = &curTable().curTablePart().Footer;
3861 }
3862
3863 void MifFOTBuilder::endTablePartFooter() {
3864
3865 curTable().CurRows = &curTable().curTablePart().Body;
3866 }
3867
3868 void MifFOTBuilder::setCellBeforeRowMargin( Length l ) {
3869
3870 nextFormat.PgfCellMargins.t = l;
3871 }
3872
3873 void MifFOTBuilder::setCellAfterRowMargin( Length l ) {
3874
3875 nextFormat.PgfCellMargins.b = l;
3876 }
3877
3878 void MifFOTBuilder::setCellBeforeColumnMargin( Length l ) {
3879
3880 nextFormat.PgfCellMargins.l = l;
3881 }
3882
3883 void MifFOTBuilder::setCellAfterColumnMargin( Length l ) {
3884
3885 nextFormat.PgfCellMargins.r = l;
3886 }
3887
3888 void MifFOTBuilder::setCellRowAlignment( Symbol alignment ) {
3889
3890 switch( alignment ) {
3891 case symbolEnd: nextFormat.PgfCellAlignment = MifDoc::sBottom; break;
3892 case symbolCenter: nextFormat.PgfCellAlignment = MifDoc::sMiddle; break;
3893 default: nextFormat.PgfCellAlignment = MifDoc::sTop; break;
3894 }
3895 }
3896
3897 //--------- TABLE BORDERS -----------------------------------------------------
3898
3899 void MifFOTBuilder::setBorderPresent( bool b ) {
3900
3901 nextFormat.FotBorderPresent = b;
3902 }
3903
3904 void MifFOTBuilder::setBorderPriority( long p ) {
3905
3906 nextFormat.FotBorderPriority = p;
3907 }
3908
3909 void MifFOTBuilder::setBorderOmitAtBreak(bool) {
3910 }
3911
3912 void MifFOTBuilder::tableBeforeRowBorder() {
3913
3914 start();
3915 curTable().beforeRowBorder.setFromFot();
3916 end();
3917 }
3918
3919 void MifFOTBuilder::tableAfterRowBorder() {
3920
3921 start();
3922 curTable().afterRowBorder.setFromFot();
3923 end();
3924 }
3925
3926 void MifFOTBuilder::tableBeforeColumnBorder() {
3927
3928 start();
3929 curTable().beforeColumnBorder.setFromFot();
3930 end();
3931 }
3932
3933 void MifFOTBuilder::tableAfterColumnBorder() {
3934
3935 start();
3936 curTable().afterColumnBorder.setFromFot();
3937 end();
3938 }
3939
3940 void MifFOTBuilder::tableCellBeforeRowBorder() {
3941
3942 start();
3943 curTable().curCell().beforeRowBorder.setFromFot();
3944 end();
3945 }
3946
3947 void MifFOTBuilder::tableCellAfterRowBorder() {
3948
3949 start();
3950 curTable().curCell().afterRowBorder.setFromFot();
3951 end();
3952 }
3953
3954 void MifFOTBuilder::tableCellBeforeColumnBorder() {
3955
3956 start();
3957 curTable().curCell().beforeColumnBorder.setFromFot();
3958 end();
3959 }
3960
3961 void MifFOTBuilder::tableCellAfterColumnBorder() {
3962
3963 start();
3964 curTable().curCell().afterColumnBorder.setFromFot();
3965 end();
3966 }
3967
3968
3969 //--------- CROSS-REFERENCES, LINKS, AND INDEX-ENTRIES ------------------------
3970
3971 void MifFOTBuilder::outPendingInlineStatements() {
3972
3973 if( linkStack.size() > 1
3974 && linkStack[linkStack.size()-2].openedInMif
3975 && !linkStack[linkStack.size()-2].forcesNoLink() ) {
3976 LinkInfo::pendingMifClosings++;
3977 linkStack[linkStack.size()-2].openedInMif = false;
3978 }
3979
3980 for( ; LinkInfo::pendingMifClosings > 0; LinkInfo::pendingMifClosings-- ) {
3981 MifDoc::Marker marker( MifDoc::T_string( "" ), MifDoc::Marker::Hypertext );
3982 marker.out( mifDoc.os() );
3983 }
3984
3985 if( indexEntryStack.size() > 0 ) {
3986 indexEntryStack.back().out( mifDoc.os() );
3987 indexEntryStack.resize( indexEntryStack.size() - 1 );
3988 }
3989
3990 for( size_t i = 0; i < nodeStack.size(); i++ ) {
3991 unsigned long n;
3992 if( nodeStack[i].node->elementIndex( n ) == accessOK ) {
3993 GroveString id;
3994 nodeStack[i].node->getId( id );
3995 unsigned long groveIndex = nodeStack[i].node->groveIndex();
3996 mifDoc.os() << MifDoc::CrossRefInfo
3997 ( groveIndex, n, mifDoc.os().CurTagIndent,
3998 MifDoc::CrossRefInfo::PotentialMarker, id.data(), id.size() );
3999 if( id.size() > 0 )
4000 mifDoc.elements().setBookComponentIndex
4001 ( groveIndex, StringC( id.data(), id.size() ),
4002 mifDoc.bookComponents().size() - 1 );
4003 else
4004 mifDoc.elements().setBookComponentIndex
4005 ( groveIndex, n, mifDoc.bookComponents().size() - 1 );
4006 }
4007 }
4008 NodeInfo::nonEmptyElementsOpened = 0;
4009 nodeStack.resize(0);
4010
4011 if( linkStack.size() > 0
4012 && !linkStack.back().openedInMif
4013 && !linkStack.back().forcesNoLink() ) {
4014 linkStack.back().crossRefInfo->tagIndent = mifDoc.os().CurTagIndent;
4015 mifDoc.os() << *linkStack.back().crossRefInfo;
4016 linkStack.back().openedInMif = true;
4017 }
4018 }
4019
4020 //--------- LINKS -------------------------------------------------------------
4021
4022 void MifFOTBuilder::startLink( const Address &address ) {
4023
4024 switch( address.type ) {
4025 case Address::resolvedNode: {
4026 unsigned long n;
4027 if( address.node->elementIndex( n ) == accessOK ) {
4028 GroveString id;
4029 address.node->getId( id );
4030 unsigned long groveIndex = address.node->groveIndex();
4031 linkStack.resize( linkStack.size() + 1 );
4032 linkStack.back().crossRefInfo
4033 = new MifDoc::CrossRefInfo
4034 ( groveIndex, n, 0, MifDoc::CrossRefInfo::HypertextLink,
4035 id.data(), id.size() );
4036 if( id.size() > 0 )
4037 mifDoc.elements().setReferencedFlag
4038 ( MifDoc::ElementSet::LinkReference, groveIndex,
4039 StringC( id.data(), id.size() ) );
4040 else
4041 mifDoc.elements().setReferencedFlag
4042 ( MifDoc::ElementSet::LinkReference, groveIndex, n );
4043 }
4044 break; }
4045
4046 case Address::idref: {
4047 const StringC &id = address.params[0];
4048 size_t i;
4049 for( i = 0; i < id.size(); i++ )
4050 if( id[i] == ' ')
4051 break;
4052 linkStack.resize( linkStack.size() + 1 );
4053 linkStack.back().crossRefInfo
4054 = new MifDoc::CrossRefInfo
4055 ( address.node->groveIndex(), 0, 0, MifDoc::CrossRefInfo::HypertextLink,
4056 id.data(), i );
4057 mifDoc.elements().setReferencedFlag
4058 ( MifDoc::ElementSet::LinkReference, address.node->groveIndex(),
4059 StringC( id.data(), i ) );
4060 break; }
4061
4062 case Address::none: default:
4063 linkStack.resize( linkStack.size() + 1 );
4064 }
4065 }
4066
4067 void MifFOTBuilder::endLink() {
4068
4069 assert( linkStack.size() > 0 );
4070 if( linkStack.back().openedInMif )
4071 LinkInfo::pendingMifClosings++;
4072 linkStack.resize( linkStack.size() - 1 );
4073
4074 // MifDoc::Marker marker( MifDoc::T_string( "" ), MifDoc::Marker::Hypertext );
4075 // marker.out( mifDoc.os() );
4076 }
4077
4078 //--------- CROSS-REFERENCES --------------------------------------------------
4079
4080 void MifFOTBuilder::startNode( const NodePtr &node, const StringC &mode ) {
4081
4082 NodeInfo::curNodeLevel++;
4083 if( mode.size() == 0 )
4084 nodeStack.push_back( NodeInfo( node, NodeInfo::curNodeLevel ) );
4085 }
4086
4087 void MifFOTBuilder::endNode() {
4088
4089 if( nodeStack.size() > 0 && nodeStack.back().nodeLevel == NodeInfo::curNodeLevel
4090 && NodeInfo::nonEmptyElementsOpened < nodeStack.size() )
4091 nodeStack.resize( nodeStack.size() - 1 );
4092 NodeInfo::curNodeLevel--;
4093 }
4094
4095 void MifFOTBuilder::currentNodePageNumber( const NodePtr &node ) {
4096
4097 unsigned long n;
4098 if( node->elementIndex( n ) == accessOK ) {
4099 GroveString id;
4100 node->getId( id );
4101 if( !mifDoc.bookComponent().pageNumXRefFormatGenerated ) {
4102 mifDoc.bookComponent().XRefFormats.push_back
4103 ( MifDoc::XRefFormat( MifDoc::sPageNumXRefFormatName, "<$pagenum\\>" ) );
4104 mifDoc.bookComponent().pageNumXRefFormatGenerated = true;
4105 }
4106 unsigned long groveIndex = node->groveIndex();
4107 mifDoc.os() << MifDoc::CrossRefInfo
4108 ( groveIndex, n, mifDoc.os().CurTagIndent,
4109 MifDoc::CrossRefInfo::XRef, id.data(), id.size() );
4110 if( id.size() > 0 )
4111 mifDoc.elements().setReferencedFlag
4112 ( MifDoc::ElementSet::PageReference, groveIndex, StringC( id.data(), id.size() ) );
4113 else
4114 mifDoc.elements().setReferencedFlag
4115 ( MifDoc::ElementSet::PageReference, groveIndex, n );
4116 }
4117 }
4118
4119 //--------- INDEX-ENTRIES -----------------------------------------------------
4120
4121 void MifFOTBuilder::indexEntry( const IndexEntryNIC &nic ) {
4122
4123 MifDoc::T_string mText;
4124 if( nic.components.size() > 0 ) {
4125 if( !nic.pageNumber )
4126 mText += MifDoc::T_string( "<$nopage>" );
4127 if( nic.startsPageRange )
4128 mText += MifDoc::T_string( "<$startrange>" );
4129 if( nic.endsPageRange )
4130 mText += MifDoc::T_string( "<$endrange>" );
4131 bool first = true;
4132 for( size_t i = 0; i < nic.components.size(); first = false, i++ ) {
4133 if( !first ) mText += ':';
4134 for( size_t ii = 0; ii < nic.components[i].size(); ii++ )
4135 mText += char( nic.components[i][ii] );
4136 }
4137 if( nic.sortString.size() > 0 ) {
4138 mText += '[';
4139 for( size_t i = 0; i < nic.sortString.size(); i++ )
4140 mText += char( nic.sortString[i] );
4141 mText += ']';
4142 }
4143 indexEntryStack.resize( indexEntryStack.size() + 1 );
4144 indexEntryStack.back() = MifDoc::Marker( mText, MifDoc::Marker::Index );
4145 }
4146 }
4147
4148 //-----------------------------------------------------------------------------
4149
4150 void MifFOTBuilder::setCellBackground( bool to ) {
4151
4152 nextFormat.FotCellBackground = to;
4153 }
4154
4155 void MifFOTBuilder::setBackgroundColor( const DeviceRGBColor &rgbColor ) {
4156
4157 MifDoc::Color *color = new MifDoc::Color( rgbColor.red, rgbColor.green, rgbColor.blue );
4158 nextFormat.MifBackgroundColor = color->ColorTag;
4159 if( mifDoc.colorCatalog().Colors.lookup( color->ColorTag ) == NULL ) {
4160 mifDoc.colorCatalog().Colors.insert( color );
4161 } else
4162 delete color;
4163 }
4164
4165 void MifFOTBuilder::setBackgroundColor() {
4166
4167 nextFormat.MifBackgroundColor = MifDoc::T_tagstring();
4168 }
4169
4170 void MifFOTBuilder::setColor( const DeviceRGBColor &rgbColor ) {
4171
4172 MifDoc::Color *color = new MifDoc::Color( rgbColor.red, rgbColor.green, rgbColor.blue );
4173 nextFormat.FColor = color->ColorTag;
4174 if( mifDoc.colorCatalog().Colors.lookup( color->ColorTag ) == NULL ) {
4175 mifDoc.colorCatalog().Colors.insert( color );
4176 } else
4177 delete color;
4178 }
4179
4180 void MifFOTBuilder::setSpan( long n ) {
4181
4182 nextFormat.FotSpan = n;
4183 }
4184
4185 void MifFOTBuilder::setPageNColumns( long n ) {
4186
4187 nextFormat.FotPageNColumns = n;
4188 mifDoc.document().setDColumns( n );
4189 }
4190
4191 void MifFOTBuilder::setPageColumnSep( Length l ) {
4192
4193 nextFormat.FotPageColumnSep = l;
4194 mifDoc.document().setDColumnGap( l );
4195 }
4196
4197 void MifFOTBuilder::setPageBalanceColumns( bool b ) {
4198
4199 nextFormat.FotPageBalanceColumns = b;
4200 }
4201
4202 void MifFOTBuilder::setLines( Symbol s ) {
4203
4204 nextFormat.FotLines = s;
4205 }
4206
4207 void MifFOTBuilder::setInputWhitespaceTreatment( Symbol s ) {
4208
4209 nextFormat.FotInputWhitespaceTreatment = s;
4210 }
4211
4212 void MifFOTBuilder::setMinLeading( const OptLengthSpec &ol ) {
4213
4214 nextFormat.FotMinLeading = ol;
4215 }
4216
4217 void MifFOTBuilder::setPositionPointShift( const LengthSpec &l ) {
4218
4219 nextFormat.FotPositionPointShiftSpec = l;
4220 }
4221
4222 void MifFOTBuilder::setLineThickness( Length l ) {
4223
4224 nextFormat.FotLineThickness = l;
4225 }
4226
4227 void MifFOTBuilder::setLineRepeat( long n ) {
4228
4229 nextFormat.FotLineRepeat = n;
4230 }
4231
4232 void MifFOTBuilder::setLineSep( Length l ) {
4233
4234 nextFormat.FotLineSep = l;
4235 }
4236
4237 void MifFOTBuilder::setFieldWidth( const LengthSpec &l ) {
4238
4239 nextFormat.FotFieldWidth = l;
4240 }
4241
4242 void MifFOTBuilder::setLineCap( Symbol s ) {
4243
4244 nextFormat.FotLineCap = s;
4245 }
4246
4247 void MifFOTBuilder::setFieldAlign( Symbol s ) {
4248
4249 nextFormat.FotFieldAlign = s;
4250 }
4251
4252 //---------------------------------------------------------------------------------------------
4253
4254 void MifFOTBuilder::extension( const ExtensionFlowObj &fo, const NodePtr &node ) {
4255
4256 ((const MifExtensionFlowObj &)fo).atomic( *this, node );
4257 }
4258
4259 bool MifFOTBuilder::IndexEntryFlowObj::hasNIC( const StringC &name ) const {
4260
4261 return name == "components" || name == "page-number?" || name == "sort-string"
4262 || name == "starts-page-range?" || name == "ends-page-range?" ;
4263 }
4264
4265 void MifFOTBuilder::IndexEntryFlowObj::setNIC( const StringC &name, const Value &value ) {
4266
4267 if( name == "components" )
4268 value.convertStringList( nic.components );
4269 else if( name == "page-number?" )
4270 value.convertBoolean( nic.pageNumber );
4271 else if( name == "sort-string" ) {
4272 bool hasString;
4273 value.convertBoolean( hasString );
4274 if( hasString )
4275 value.convertString( nic.sortString );
4276 } else if( name == "starts-page-range?" )
4277 value.convertBoolean( nic.startsPageRange );
4278 else if( name == "ends-page-range?" )
4279 value.convertBoolean( nic.endsPageRange );
4280 }
4281
4282 //---------------------------------------------------------------------------------------------
4283
4284 unsigned long StringHash::hash( const String<char> &str ) {
4285
4286 const char *p = str.data();
4287 unsigned long h = 0;
4288 for( size_t n = str.size(); n > 0; n-- )
4289 h = (h << 5) + h + *p++; // from Chris Torek
4290 return h;
4291 }
4292
4293 FOTBuilder *makeMifFOTBuilder( const String<CmdLineApp::AppChar> &fileLoc,
4294 const Ptr<ExtendEntityManager> &entityManager,
4295 const CharsetInfo &systemCharset,
4296 CmdLineApp *app,
4297 const FOTBuilder::Description *&descr) {
4298
4299 MifFOTBuilder::IndexEntryFlowObj *indexEntryFlowObject
4300 = new MifFOTBuilder::IndexEntryFlowObj;
4301
4302 static const FOTBuilder::Extension extensions[] = {
4303 {
4304 "UNREGISTERED::ISOGEN//Flow Object Class::index-entry",
4305 0,
4306 0,
4307 0,
4308 0,
4309 indexEntryFlowObject
4310 },
4311 {
4312 "UNREGISTERED::James Clark//Characteristic::page-n-columns",
4313 0,
4314 0,
4315 (void (FOTBuilder::*)(long))&MifFOTBuilder::setPageNColumns,
4316 0
4317 },
4318 {
4319 "UNREGISTERED::James Clark//Characteristic::page-column-sep",
4320 0,
4321 0,
4322 0,
4323 (void (FOTBuilder::*)(FOTBuilder::Length))&MifFOTBuilder::setPageColumnSep,
4324 },
4325 {
4326 "UNREGISTERED::James Clark//Characteristic::page-balance-columns?",
4327 (void (FOTBuilder::*)(bool))&MifFOTBuilder::setPageBalanceColumns,
4328 0,
4329 0
4330 },
4331 { 0, 0, 0}
4332 };
4333
4334 static const FOTBuilder::Feature features[] = {
4335 { "table", 0},
4336 { "simple-page", 0},
4337 { 0, 0}
4338 };
4339
4340 static const char *media[] = { "print", 0 };
4341
4342 static const FOTBuilder::Description description = {
4343 extensions,
4344 features,
4345 false,
4346 media
4347 };
4348
4349 descr = &description;
4350
4351 return new MifFOTBuilder( fileLoc, entityManager, systemCharset, app );
4352 }
4353
4354 const Char MifFOTBuilder::FrameCharsetMap[] = { // Latin-1 -> Frame Charset
4355 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4356 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4357 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4358 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4359 0x0000, 0x00c1, 0x00a2, 0x00a3, 0x00db, 0x00b4, 0x007c, 0x00a4,
4360 0x00ac, 0x00a9, 0x00bb, 0x00c7, 0x00c2, 0x002d, 0x00a8, 0x00f8,
4361 0x00fb, 0x0000, 0x0000, 0x0000, 0x00ab, 0x0000, 0x00a6, 0x00a5,
4362 0x00fc, 0x0000, 0x00bc, 0x00c8, 0x0000, 0x0000, 0x0000, 0x00c0,
4363 0x00cb, 0x00e7, 0x00e5, 0x00cc, 0x0080, 0x0081, 0x00ae, 0x0082,
4364 0x00e9, 0x0083, 0x00e6, 0x00e9, 0x00ed, 0x00ea, 0x00eb, 0x00ec,
4365 0x0000, 0x0084, 0x00f1, 0x00ee, 0x00ef, 0x00cd, 0x0085, 0x0000,
4366 0x00af, 0x00f4, 0x00f2, 0x00f3, 0x0086, 0x0000, 0x0000, 0x00a7,
4367 0x0088, 0x0087, 0x0089, 0x008b, 0x008a, 0x008c, 0x00be, 0x008d,
4368 0x008f, 0x008e, 0x0090, 0x0091, 0x0093, 0x0092, 0x0094, 0x0095,
4369 0x0000, 0x0096, 0x0098, 0x0097, 0x0099, 0x009b, 0x009a, 0x0000,
4370 0x00bf, 0x009d, 0x009c, 0x009e, 0x009f, 0x0000, 0x0000, 0x00d8
4371 };
4372
4373 const MifFOTBuilder::SymbolFont
4374 MifFOTBuilder::SymbolFonts[MifFOTBuilder::nSymbolFonts] = {
4375 { "Symbol", {
4376 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4377 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4378 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4379 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4380 0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220B,
4381 0x0028, 0x0029, 0x2217, 0x002B, 0x002C, 0x2212, 0x002E, 0x002F,
4382 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
4383 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
4384 0x2245, 0x0391, 0x0392, 0x03A7, 0x2206, 0x0395, 0x03A6, 0x0393,
4385 0x0397, 0x0399, 0x03D1, 0x039A, 0x039B, 0x039C, 0x039D, 0x039F,
4386 0x03A0, 0x0398, 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03C2, 0x2126,
4387 0x039E, 0x03A8, 0x0396, 0x005B, 0x2234, 0x005D, 0x22A5, 0x005F,
4388 0x203E, 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03C6, 0x03B3,
4389 0x03B7, 0x03B9, 0x03D5, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF,
4390 0x03C0, 0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03C9,
4391 0x03BE, 0x03C8, 0x03B6, 0x007B, 0x007C, 0x007D, 0x223C, 0x0000,
4392 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4393 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4394 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4395 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4396 0x0000, 0x03D2, 0x2032, 0x2264, 0x2215, 0x221E, 0x0192, 0x2663,
4397 0x2666, 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193,
4398 0x00B0, 0x00B1, 0x2033, 0x2265, 0x00D7, 0x221D, 0x2202, 0x2022,
4399 0x00F7, 0x2260, 0x2261, 0x2248, 0x2026, 0x0000, 0x0000, 0x21B5,
4400 0x2135, 0x2111, 0x211C, 0x2118, 0x2297, 0x2295, 0x2205, 0x2229,
4401 0x222A, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208, 0x2209,
4402 0x2220, 0x2207, 0x00AE, 0x00A9, 0x2122, 0x220F, 0x221A, 0x22C5,
4403 0x00AC, 0x2227, 0x2228, 0x21D4, 0x21D0, 0x21D1, 0x21D2, 0x21D3,
4404 0x25CA, 0x2329, 0x00AE, 0x00A9, 0x2122, 0x2211, 0x0000, 0x0000,
4405 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4406 0x0000, 0x232A, 0x222B, 0x2320, 0x0000, 0x2321, 0x0000, 0x0000,
4407 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }
4408 },
4409 // I created this table by hand. It's sometimes not obvious what
4410 // the appropriate mapping is (James Clark)
4411 { "Wingdings", {
4412 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4413 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4414 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4415 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4416 0x0000, 0x0000, 0x2702, 0x2701, 0x0000, 0x0000, 0x0000, 0x0000,
4417 0x260e, 0x2706, 0x2709, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4418 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2328,
4419 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2707, 0x270d,
4420 0x0000, 0x270c, 0x0000, 0x0000, 0x0000, 0x261c, 0x261e, 0x261d,
4421 0x261f, 0x0000, 0x263a, 0x0000, 0x2639, 0x0000, 0x2620, 0x0000,
4422 0x0000, 0x2708, 0x263c, 0x0000, 0x2744, 0x0000, 0x271e, 0x0000,
4423 0x2720, 0x2721, 0x262a, 0x262f, 0x0950, 0x2638, 0x2648, 0x2649,
4424 0x264a, 0x264b, 0x264c, 0x264d, 0x264e, 0x264f, 0x2650, 0x2651,
4425 0x2652, 0x2653, 0x0000, 0x0000, 0x25cf, 0x274d, 0x25a0, 0x25a1,
4426 0x0000, 0x2751, 0x2752, 0x0000, 0x0000, 0x25c6, 0x2756, 0x0000,
4427 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4428 0x0000, 0x2780, 0x2781, 0x2782, 0x2783, 0x2784, 0x2785, 0x2786,
4429 0x2787, 0x2788, 0x2789, 0x0000, 0x278a, 0x278b, 0x278c, 0x278d,
4430 0x278e, 0x278f, 0x2790, 0x2791, 0x2792, 0x2793, 0x0000, 0x0000,
4431 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4432 0x0000, 0x25cb, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x25aa,
4433 0x0000, 0x0000, 0x2726, 0x2605, 0x2736, 0x0000, 0x2739, 0x0000,
4434 0x0000, 0x0000, 0x2727, 0x0000, 0x0000, 0x272a, 0x2730, 0x0000,
4435 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4436 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4437 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4438 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x232b, 0x2326, 0x0000,
4439 0x27a2, 0x0000, 0x0000, 0x0000, 0x27b2, 0x0000, 0x0000, 0x0000,
4440 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4441 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4442 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4443 0x0000, 0x0000, 0x25ab, 0x2718, 0x2714, 0x2612, 0x2611, 0x0000 }
4444 },
4445 { "ZapfDingbats", {
4446 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4447 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4448 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4449 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4450 0x0000, 0x2701, 0x2702, 0x2703, 0x2704, 0x260E, 0x2706, 0x2707,
4451 0x2708, 0x2709, 0x261B, 0x261E, 0x270C, 0x270D, 0x270E, 0x270F,
4452 0x2710, 0x2711, 0x2712, 0x2713, 0x2714, 0x2715, 0x2716, 0x2717,
4453 0x2718, 0x2719, 0x271A, 0x271B, 0x271C, 0x271D, 0x271E, 0x271F,
4454 0x2720, 0x2721, 0x2722, 0x2723, 0x2724, 0x2725, 0x2726, 0x2727,
4455 0x2605, 0x2729, 0x272A, 0x272B, 0x272C, 0x272D, 0x272E, 0x272F,
4456 0x2730, 0x2731, 0x2732, 0x2733, 0x2734, 0x2735, 0x2736, 0x2737,
4457 0x2738, 0x2739, 0x273A, 0x273B, 0x273C, 0x273D, 0x273E, 0x273F,
4458 0x2740, 0x2741, 0x2742, 0x2743, 0x2744, 0x2745, 0x2746, 0x2747,
4459 0x2748, 0x2749, 0x274A, 0x274B, 0x0000, 0x274D, 0x25A0, 0x274F,
4460 0x2750, 0x2751, 0x2752, 0x25B2, 0x25BC, 0x25C6, 0x2756, 0x0000,
4461 0x2758, 0x2759, 0x275A, 0x275B, 0x275C, 0x275D, 0x275E, 0x0000,
4462 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4463 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4464 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4465 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
4466 0x0000, 0x2761, 0x2762, 0x2763, 0x2764, 0x2765, 0x2766, 0x2767,
4467 0x2663, 0x2666, 0x2665, 0x2660, 0x2460, 0x2461, 0x2462, 0x2463,
4468 0x2464, 0x2465, 0x2466, 0x2467, 0x2468, 0x2469, 0x2776, 0x2777,
4469 0x2778, 0x2779, 0x277A, 0x277B, 0x277C, 0x277D, 0x277E, 0x277F,
4470 0x2780, 0x2781, 0x2782, 0x2783, 0x2784, 0x2785, 0x2786, 0x2787,
4471 0x2788, 0x2789, 0x278A, 0x278B, 0x278C, 0x278D, 0x278E, 0x278F,
4472 0x2790, 0x2791, 0x2792, 0x2793, 0x2794, 0x2192, 0x2194, 0x2195,
4473 0x2798, 0x2799, 0x279A, 0x279B, 0x279C, 0x279D, 0x279E, 0x279F,
4474 0x27A0, 0x27A1, 0x27A2, 0x27A3, 0x27A4, 0x27A5, 0x27A6, 0x27A7,
4475 0x27A8, 0x27A9, 0x27AA, 0x27AB, 0x27AC, 0x27AD, 0x27AE, 0x27AF,
4476 0x0000, 0x27B1, 0x27B2, 0x27B3, 0x27B4, 0x27B5, 0x27B6, 0x27B7,
4477 0x27B8, 0x27B9, 0x27BA, 0x27BB, 0x27BC, 0x27BD, 0x27BE, 0x0000 }
4478 },
4479 };
4480
4481 // --------- static -----------------------------------------------------------
4482
4483 #define CONST_STRING( symbolName ) \
4484 const String<char> MifDoc::s ## symbolName ( #symbolName, sizeof( #symbolName ) - 1 )
4485
4486 const String<char> MifDoc::sNONE;
4487 const String<char> MifDoc::sSPACE( " ", sizeof( " " ) - 1 );
4488 const String<char> MifDoc::sDefaultTblFormat
4489 ( "Default Tbl Format", sizeof( "Default Tbl Format" ) - 1 );
4490 const String<char> MifDoc::sDefaultPgfFormat
4491 ( "Default Pgf Format", sizeof( "Default Pgf Format" ) - 1 );
4492 const String<char> MifDoc::sTimesNewRoman
4493 ( "Times New Roman", sizeof( "Times New Roman" ) - 1 );
4494 const String<char> MifDoc::sPageNumXRefFormatName
4495 ( "Page Number Format", sizeof( "Page Number Format" ) - 1 );
4496 CONST_STRING( A );
4497 CONST_STRING( Regular );
4498 CONST_STRING( Bold );
4499 CONST_STRING( Italic );
4500 CONST_STRING( FNoUnderlining );
4501 CONST_STRING( FSingle );
4502 CONST_STRING( FDouble );
4503 CONST_STRING( FNumeric );
4504 CONST_STRING( FNormal );
4505 CONST_STRING( FSuperscript );
4506 CONST_STRING( FSubscript );
4507 CONST_STRING( FAsTyped );
4508 CONST_STRING( FSmallCaps );
4509 CONST_STRING( FLowercase );
4510 CONST_STRING( FUppercase );
4511 CONST_STRING( LeftRight );
4512 CONST_STRING( Left );
4513 CONST_STRING( Right );
4514 CONST_STRING( Center );
4515 CONST_STRING( Fixed );
4516 CONST_STRING( Proportional );
4517 CONST_STRING( Top );
4518 CONST_STRING( Middle );
4519 CONST_STRING( Bottom );
4520 CONST_STRING( NoLanguage );
4521 CONST_STRING( USEnglish );
4522 CONST_STRING( UKEnglish );
4523 CONST_STRING( German );
4524 CONST_STRING( SwissGerman );
4525 CONST_STRING( French );
4526 CONST_STRING( CanadianFrench );
4527 CONST_STRING( Spanish );
4528 CONST_STRING( Catalan );
4529 CONST_STRING( Italian );
4530 CONST_STRING( Portuguese );
4531 CONST_STRING( Brazilian );
4532 CONST_STRING( Danish );
4533 CONST_STRING( Dutch );
4534 CONST_STRING( Norwegian );
4535 CONST_STRING( Nynorsk );
4536 CONST_STRING( Finnish );
4537 CONST_STRING( Swedish );
4538 CONST_STRING( LeftMasterPage );
4539 CONST_STRING( RightMasterPage );
4540 CONST_STRING( OtherMasterPage );
4541 CONST_STRING( BodyPage );
4542 CONST_STRING( Decimal );
4543 CONST_STRING( Tab );
4544 CONST_STRING( HardSpace );
4545 CONST_STRING( SoftHyphen );
4546 CONST_STRING( HardHyphen );
4547 CONST_STRING( HardReturn );
4548 CONST_STRING( NumberSpace );
4549 CONST_STRING( ThinSpace );
4550 CONST_STRING( EnSpace );
4551 CONST_STRING( EmSpace );
4552 CONST_STRING( Header );
4553 CONST_STRING( Footer );
4554 CONST_STRING( Arabic );
4555 CONST_STRING( UCRoman );
4556 CONST_STRING( LCRoman );
4557 CONST_STRING( UCAlpha );
4558 CONST_STRING( LCAlpha );
4559 CONST_STRING( FirstLeft );
4560 CONST_STRING( FirstRight );
4561 CONST_STRING( Anywhere );
4562 CONST_STRING( ColumnTop );
4563 CONST_STRING( PageTop );
4564 CONST_STRING( LPageTop );
4565 CONST_STRING( RPageTop );
4566 CONST_STRING( First );
4567 CONST_STRING( Inside );
4568 CONST_STRING( Outside );
4569 CONST_STRING( None );
4570 CONST_STRING( RunIntoParagraph );
4571 CONST_STRING( Inline );
4572 CONST_STRING( Below );
4573 CONST_STRING( Butt );
4574 CONST_STRING( Round );
4575 CONST_STRING( Square );
4576 CONST_STRING( White );
4577 CONST_STRING( Black );
4578 CONST_STRING( Normal );
4579 CONST_STRING( Straddle );
4580 CONST_STRING( Cent );
4581 CONST_STRING( Pound );
4582 CONST_STRING( Yen );
4583 CONST_STRING( EnDash );
4584 CONST_STRING( EmDash );
4585 CONST_STRING( Dagger );
4586 CONST_STRING( DoubleDagger );
4587 CONST_STRING( Bullet);
4588
4589 MifDoc *MifDoc::CurInstance = NULL;
4590
4591 MifDoc::T_ID MifDoc::Object::IDCnt = 0;
4592
4593 MifDoc::T_indent MifOutputByteStream::INDENT = MifDoc::T_indent( 0xFFF );
4594
4595 bool MifDoc::Para::currentlyOpened = false;
4596 unsigned MifDoc::ParaLine::setProperties = 0;
4597 MifDoc::T_ID MifDoc::ParaLine::TextRectID;
4598 MifDoc::T_ID MifDoc::ParaLine::ATbl;
4599
4600 // ----------------------------------------------------------------------------
4601
4602 int operator!=( const MifDoc::T_LTRB &o1, const MifDoc::T_LTRB &o2 ) {
4603
4604 return o1.l != o2.l || o1.t != o2.t || o1.r != o2.r || o1.b != o2.b;
4605 }
4606
4607 // --------- MifTmpOutputByteStream -------------------------------------------
4608
4609 void MifTmpOutputByteStream::commit( OutputByteStream &os, bool resolveCrossReferences ) {
4610
4611 MifOutputByteStream outS( os );
4612 TmpOutputByteStream::Iter iter( *this );
4613 const char *s;
4614 size_t n;
4615
4616 unsigned crossRefInfoIdx;
4617 char *byteDestPtr = NULL;
4618 size_t neededBytesNum = 0;
4619 enum { normal, waitingForCrossRefInfoIdx } state = normal;
4620 while( iter.next( s, n ) ) {
4621 while( n > 0 ) {
4622 switch( state ) {
4623 case waitingForCrossRefInfoIdx: {
4624 int bytesCopiedNum = neededBytesNum > n ? n : neededBytesNum;
4625 memcpy( byteDestPtr, s, bytesCopiedNum );
4626 byteDestPtr += bytesCopiedNum; n -= bytesCopiedNum; s += bytesCopiedNum;
4627 neededBytesNum -= bytesCopiedNum;
4628 if( neededBytesNum == 0 ) {
4629 assert( crossRefInfoIdx < MifDoc::CurInstance->crossRefInfos().size() );
4630 MifDoc::CrossRefInfo &crossRefInfo
4631 = MifDoc::CurInstance->crossRefInfos()[crossRefInfoIdx];
4632 crossRefInfo.out( outS );
4633 state = normal;
4634 } }
4635 break;
4636
4637 case normal:
4638 if( resolveCrossReferences ) {
4639 const char *escapeCharPtr
4640 = (char*)memchr( s, MifDoc::escapeChar(), n );
4641 if( escapeCharPtr != NULL ) {
4642 outS.stream().sputn( s, escapeCharPtr - s);
4643 n -= (escapeCharPtr - s); s = escapeCharPtr; n--; s++;
4644 state = waitingForCrossRefInfoIdx;
4645 byteDestPtr = (char*)&crossRefInfoIdx;
4646 neededBytesNum = sizeof( unsigned );
4647 break;
4648 }
4649 }
4650 outS.stream().sputn( s, n );
4651 n = 0;
4652 }
4653 }
4654 }
4655
4656 assert( neededBytesNum == 0 );
4657 }
4658
4659 void MifTmpOutputByteStream::commit( String<char> &str ) {
4660
4661 TmpOutputByteStream::Iter iter( *this );
4662 const char *s;
4663 size_t n;
4664
4665 while( iter.next( s, n ) ) {
4666 str.append( s, n );
4667 }
4668 }
4669
4670 // --------- MifDoc::T_string -------------------------------------------------
4671
4672 void MifDoc::T_string::escapeSpecialChars() {
4673
4674 T_string newValue;
4675
4676 bool changes = false;
4677 for( size_t i = 0; i < size(); i++ ) {
4678 switch( (*this)[i] ) {
4679 case '\n': case '\r': changes = true; break;
4680 case '\t': newValue.append( "\\t", 2 ); changes = true; break;
4681 case '>': newValue.append( "\\>", 2 ); changes = true; break;
4682 case '\'': newValue.append( "\\q", 2 ); changes = true; break;
4683 case '`': newValue.append( "\\Q", 2 ); changes = true; break;
4684 case '\\': newValue.append( "\\\\", 2 ); changes = true; break;
4685 default:
4686 if( (unsigned)(*this)[i] >= 0x80 ) {
4687 changes = true;
4688 MifDoc::CurInstance->outHexChar( (*this)[i], newValue );
4689 } else
4690 newValue += (*this)[i];
4691 }
4692 }
4693 if( changes )
4694 *this = newValue;
4695 }
4696
4697 // --------- MifDoc::CrossRefInfo ---------------------------------------------
4698
4699 MifDoc::T_string MifDoc::CrossRefInfo::crossRefText() const {
4700
4701 char buf[32];
4702 if( sgmlId.size() > 0 ) {
4703 sprintf( buf, "NODE%lu.", groveIndex );
4704 T_string result( buf );
4705 for( size_t i = 0; i < sgmlId.size(); i++ )
4706 result += char( sgmlId[i] );
4707 return result;
4708 } else {
4709 sprintf( buf, "NODE%lu.%lu", groveIndex, elementIndex );
4710 return T_string( buf );
4711 }
4712 }
4713
4714 void MifDoc::CrossRefInfo::out( MifOutputByteStream &os ) {
4715
4716 switch( type() ) {
4717 case PotentialMarker: {
4718 bool regularMarkerOut = false;
4719 bool linkMarkerOut = false;
4720 if( sgmlId.size() > 0 ) {
4721 if( MifDoc::CurInstance->elements().hasBeenReferenced
4722 ( MifDoc::ElementSet::PageReference, groveIndex, sgmlId ) )
4723 regularMarkerOut = true;
4724 if( MifDoc::CurInstance->elements().hasBeenReferenced
4725 ( MifDoc::ElementSet::LinkReference, groveIndex, sgmlId ) )
4726 linkMarkerOut = true;
4727 } else {
4728 if( MifDoc::CurInstance->elements().hasBeenReferenced
4729 ( MifDoc::ElementSet::PageReference, groveIndex, elementIndex ) )
4730 regularMarkerOut = true;
4731 if( MifDoc::CurInstance->elements().hasBeenReferenced
4732 ( MifDoc::ElementSet::LinkReference, groveIndex, elementIndex ) )
4733 linkMarkerOut = true;
4734 }
4735 if( regularMarkerOut ) {
4736 os.CurTagIndent = tagIndent;
4737 MifDoc::Marker marker( *this );
4738 marker.out( os );
4739 }
4740 if( linkMarkerOut ) {
4741 os.CurTagIndent = tagIndent;
4742 MifDoc::Marker marker( *this, true );
4743 marker.out( os );
4744 } }
4745 break;
4746
4747 case HypertextLink: {
4748 os.CurTagIndent = tagIndent;
4749 MifDoc::Marker marker( *this );
4750 marker.out( os ); }
4751 break;
4752
4753 case XRef: {
4754 os.CurTagIndent = tagIndent;
4755 MifDoc::XRef xRef( *this );
4756 xRef.out( os ); }
4757 break;
4758
4759 default: assert( false );
4760 }
4761 }
4762
4763 // ----------------------------------------------------------------------------
4764
4765 #define CHECK_PROPERTY( propertyName ) \
4766 \
4767 if( setProperties & f ## propertyName ) \
4768 os << '\n' << MifOutputByteStream::INDENT \
4769 << "<" #propertyName " " << propertyName << ">";
4770
4771 #define CHECK_VECTOR_OF_PROPERTIES( propertyName ) \
4772 \
4773 if( setProperties & f ## propertyName ## s) \
4774 for( size_t i = 0; i < propertyName ## s.size(); i++ ) { \
4775 os << '\n' << MifOutputByteStream::INDENT \
4776 << "<" #propertyName " " << propertyName ## s[i] << ">"; \
4777 }
4778
4779 // --------- MifDoc::TagStream ------------------------------------------------
4780
4781 MifDoc::TagStream::TagStream( MifDoc::T_indent osIndent )
4782 : Format(), Content( new MifTmpOutputByteStream( osIndent ) ), PgfTagUsed( false ),
4783 InitialPgfTag( sDefaultPgfFormat ), TagStreamClass( tsTagStream ) {
4784 }
4785
4786 MifDoc::TagStream::~TagStream() {
4787
4788 if( Content )
4789 delete Content;
4790 }
4791
4792 // --------- MifDoc::TextFlow -------------------------------------------------
4793
4794 MifDoc::TextFlow::TextFlow( const TextRect &textRect, bool body, ParagraphFormat *format,
4795 T_tagstring pgfTag )
4796 : TagStream(), TextRectID( textRect.ID ), setProperties( 0 ), TextRectIDUsed( false ),
4797 TextRect_( &textRect ) {
4798
4799 TagStreamClass = tsTextFlow;
4800 InitialPgfTag = pgfTag;
4801
4802 if( format )
4803 Format = *format;
4804
4805 if( body ) {
4806 setTFTag( MifDoc::sA );
4807 setTFAutoConnect( true );
4808 }
4809 }
4810
4811 void MifDoc::TextFlow::out( MifOutputByteStream &os, bool resolveCrossReferences ) {
4812
4813 os << '\n' << MifOutputByteStream::INDENT << "<TextFlow ";
4814 os.indent();
4815 CHECK_PROPERTY( TFTag );
4816 CHECK_PROPERTY( TFAutoConnect );
4817 content().commit( os.stream(), resolveCrossReferences );
4818 os.undent();
4819 os << '\n' << MifOutputByteStream::INDENT << ">";
4820 }
4821
4822
4823 // --------- MifDoc::Color ----------------------------------------------------
4824
4825 MifDoc::Color::Color( unsigned char red, unsigned char green, unsigned char blue )
4826 : setProperties( 0 ) {
4827
4828 char colorTag[64];
4829
4830 sprintf( colorTag, "RGB-%i-%i-%i", int( red ), int( green ), int( blue ) );
4831 setColorTag( T_tagstring( colorTag ) );
4832
4833 if( red >= green && red >= blue ) {
4834 setColorBlack( double( 255 - red ) / 2.55 );
4835 setColorYellow( double( red - blue ) / 2.55 );
4836 setColorMagenta( double( red - green ) / 2.55 );
4837 setColorCyan( 0.0 );
4838 } else
4839 if( green >= red && green >= blue ) {
4840 setColorBlack( double( 255 - green ) / 2.55 );
4841 setColorCyan( double( green - red ) / 2.55 );
4842 setColorYellow( double( green - blue ) / 2.55 );
4843 setColorMagenta( 0.0 );
4844 } else { // blue is largest
4845 setColorBlack( double( 255 - blue ) / 2.55 );
4846 setColorCyan( double( blue - red ) / 2.55 );
4847 setColorMagenta( double( blue - green ) / 2.55 );
4848 setColorYellow( 0.0 );
4849 }
4850 }
4851
4852 void MifDoc::Color::out( MifOutputByteStream &os ) const {
4853
4854 os << '\n' << MifOutputByteStream::INDENT << "<Color ";
4855 os.indent();
4856 CHECK_PROPERTY( ColorTag );
4857 CHECK_PROPERTY( ColorCyan );
4858 CHECK_PROPERTY( ColorMagenta );
4859 CHECK_PROPERTY( ColorYellow );
4860 CHECK_PROPERTY( ColorBlack );
4861 os.undent();
4862 os << '\n' << MifOutputByteStream::INDENT << ">";
4863 }
4864
4865 const String<char> &MifDoc::Color::key( Color &color ) {
4866
4867 return color.ColorTag;
4868 }
4869
4870 // --------- MifDoc::ColorCatalog ---------------------------------------------
4871
4872 void MifDoc::ColorCatalog::out( MifOutputByteStream &os ) {
4873
4874 if( Colors.count() > 0 ) {
4875 os << '\n' << MifOutputByteStream::INDENT << "<ColorCatalog ";
4876 os.indent();
4877
4878 PointerTableIter<Color*,String<char>,StringHash,Color> iter( Colors );
4879 const Color *color;
4880 while( ( color = iter.next() ) != NULL )
4881 color->out( os );
4882
4883 os.undent();
4884 os << '\n' << MifOutputByteStream::INDENT << ">";
4885 }
4886 }
4887
4888 // --------- MifDoc::Ruling ---------------------------------------------------
4889
4890 const String<char> &MifDoc::Ruling::key( Ruling &r ) {
4891
4892 if( r.Key.size() < 1 ) {
4893 char keyStr[ 48 ];
4894 sprintf( keyStr, "Ruling-%li-%li-%li-%li-",
4895 long( r.RulingPenWidth ), long( r.RulingGap ), r.RulingPen, r.RulingLines );
4896 r.Key.assign( keyStr, strlen( keyStr ) );
4897 r.Key += r.RulingColor;
4898 }
4899
4900 return r.Key;
4901 }
4902
4903 void MifDoc::Ruling::out( MifOutputByteStream &os ) const {
4904
4905 os << '\n' << MifOutputByteStream::INDENT << "<Ruling ";
4906 os.indent();
4907 CHECK_PROPERTY( RulingTag );
4908 CHECK_PROPERTY( RulingPenWidth );
4909 CHECK_PROPERTY( RulingGap );
4910 CHECK_PROPERTY( RulingColor );
4911 CHECK_PROPERTY( RulingPen );
4912 CHECK_PROPERTY( RulingLines );
4913 os.undent();
4914 os << '\n' << MifOutputByteStream::INDENT << ">";
4915 }
4916
4917 // --------- MifDoc::RulingCatalog --------------------------------------------
4918
4919 void MifDoc::RulingCatalog::out( MifOutputByteStream &os ) {
4920
4921 if( Rulings.count() > 0 ) {
4922 os << '\n' << MifOutputByteStream::INDENT << "<RulingCatalog ";
4923 os.indent();
4924
4925 PointerTableIter<Ruling*,String<char>,StringHash,Ruling> iter( Rulings );
4926 const Ruling *ruling;
4927 while( ( ruling = iter.next() ) != NULL )
4928 ruling->out( os );
4929
4930 os.undent();
4931 os << '\n' << MifOutputByteStream::INDENT << ">";
4932 }
4933 }
4934
4935 // --------- MifDoc::Cell -----------------------------------------------------
4936
4937 void MifDoc::Cell::out( MifOutputByteStream &os, bool resolveCrossReferences ) {
4938
4939 os << '\n' << MifOutputByteStream::INDENT << "<Cell ";
4940 os.indent();
4941
4942 CHECK_PROPERTY( CellFill );
4943 CHECK_PROPERTY( CellColor );
4944 CHECK_PROPERTY( CellLRuling );
4945 CHECK_PROPERTY( CellBRuling );
4946 CHECK_PROPERTY( CellRRuling );
4947 CHECK_PROPERTY( CellTRuling );
4948 CHECK_PROPERTY( CellColumns );
4949 CHECK_PROPERTY( CellRows );
4950
4951 os << '\n' << MifOutputByteStream::INDENT << "<CellContent ";
4952 os.indent();
4953 content().commit( os.stream(), resolveCrossReferences );
4954 os.undent();
4955 os << '\n' << MifOutputByteStream::INDENT << ">";
4956
4957 os.undent();
4958 os << '\n' << MifOutputByteStream::INDENT << ">";
4959 }
4960
4961 // --------- MifDoc::Row ------------------------------------------------------
4962
4963 void MifDoc::Row::out( MifOutputByteStream &os, bool resolveCrossReferences ) {
4964
4965 os << '\n' << MifOutputByteStream::INDENT << "<Row ";
4966 os.indent();
4967
4968 for( size_t i = 0; i < Cells.size(); i++ ) Cells[i].out( os, resolveCrossReferences );
4969
4970 os.undent();
4971 os << '\n' << MifOutputByteStream::INDENT << ">";
4972 }
4973
4974 // --------- MifDoc::TblColumn ------------------------------------------------
4975
4976 void MifDoc::TblColumn::out( MifOutputByteStream &os ) {
4977
4978 os << '\n' << MifOutputByteStream::INDENT << "<TblFormat ";
4979 os.indent();
4980
4981 CHECK_PROPERTY( TblColumnNum );
4982 CHECK_PROPERTY( TblColumnWidth );
4983
4984 os.undent();
4985 os << '\n' << MifOutputByteStream::INDENT << ">";
4986 }
4987
4988 // --------- MifDoc::TblFormat ------------------------------------------------
4989
4990 void MifDoc::TblFormat::out( MifOutputByteStream &os ) {
4991
4992 os << '\n' << MifOutputByteStream::INDENT << "<TblFormat ";
4993 os.indent();
4994
4995 CHECK_PROPERTY( TblTag );
4996 CHECK_PROPERTY( TblLIndent );
4997 CHECK_PROPERTY( TblRIndent );
4998 CHECK_PROPERTY( TblSpBefore );
4999 CHECK_PROPERTY( TblSpAfter );
5000 CHECK_PROPERTY( TblAlignment );
5001 CHECK_PROPERTY( TblCellMargins );
5002 CHECK_PROPERTY( TblTitlePlacement );
5003 CHECK_PROPERTY( TblWidth );
5004 for( size_t i = 0; i < TblColumns.size(); i++ ) TblColumns[i].out( os );
5005
5006 os.undent();
5007 os << '\n' << MifOutputByteStream::INDENT << ">";
5008 }
5009
5010 // --------- MifDoc::Tbl ------------------------------------------------------
5011
5012 void MifDoc::Tbl::out( MifOutputByteStream &os, bool resolveCrossReferences ) {
5013
5014 os << '\n' << MifOutputByteStream::INDENT << "<Tbl ";
5015 os.indent();
5016 CHECK_PROPERTY( TblID );
5017 CHECK_PROPERTY( TblTag );
5018
5019 if( setProperties & fTblFormat )
5020 tblFormat.out( os );
5021
5022 CHECK_PROPERTY( TblNumColumns );
5023 CHECK_VECTOR_OF_PROPERTIES( TblColumnWidth );
5024
5025 size_t i;
5026
5027 if( TblH.size() ) {
5028 os << '\n' << MifOutputByteStream::INDENT << "<TblH ";
5029 os.indent();
5030 for( i = 0; i < TblH.size(); i++ ) TblH[i].out( os, resolveCrossReferences );
5031 os.undent();
5032 os << '\n' << MifOutputByteStream::INDENT << ">";
5033 }
5034
5035 if( TblBody.size() ) {
5036 os << '\n' << MifOutputByteStream::INDENT << "<TblBody ";
5037 os.indent();
5038 for( i = 0; i < TblBody.size(); i++ ) TblBody[i].out( os, resolveCrossReferences );
5039 os.undent();
5040 os << '\n' << MifOutputByteStream::INDENT << ">";
5041 }
5042
5043 if( TblF.size() ) {
5044 os << '\n' << MifOutputByteStream::INDENT << "<TblF ";
5045 os.indent();
5046 for( i = 0; i < TblF.size(); i++ ) TblF[i].out( os, resolveCrossReferences );
5047 os.undent();
5048 os << '\n' << MifOutputByteStream::INDENT << ">";
5049 }
5050
5051 os.undent();
5052 os << '\n' << MifOutputByteStream::INDENT << ">";
5053 }
5054
5055 // --------- MifDoc::Document -------------------------------------------------
5056
5057 void MifDoc::Document::out( MifOutputByteStream &os ) {
5058
5059 os << '\n' << MifOutputByteStream::INDENT << "<Document ";
5060 os.indent();
5061 CHECK_PROPERTY( DMargins );
5062 CHECK_PROPERTY( DColumns );
5063 CHECK_PROPERTY( DColumnGap );
5064 CHECK_PROPERTY( DPageSize );
5065 CHECK_PROPERTY( DStartPage );
5066 CHECK_PROPERTY( DPageNumStyle );
5067 CHECK_PROPERTY( DTwoSides );
5068 CHECK_PROPERTY( DParity );
5069 os.undent();
5070 os << '\n' << MifOutputByteStream::INDENT << ">";
5071 }
5072
5073 // --------- MifDoc::XRefFormat -----------------------------------------------
5074
5075 void MifDoc::XRefFormat::out( MifOutputByteStream &os ) {
5076
5077 os << '\n' << MifOutputByteStream::INDENT << "<XRefFormat ";
5078 os.indent();
5079 CHECK_PROPERTY( XRefName );
5080 CHECK_PROPERTY( XRefDef );
5081 os.undent();
5082 os << '\n' << MifOutputByteStream::INDENT << ">";
5083 }
5084
5085 // --------- MifDoc::XRef -----------------------------------------------------
5086
5087 MifDoc::XRef::XRef( CrossRefInfo &crossRefInfo ) {
5088
5089 switch( crossRefInfo.type() ) {
5090 case CrossRefInfo::XRef: {
5091 MifDoc::T_pathname targetFileName( "<c\\>" );
5092 int bookComponentIdx
5093 = crossRefInfo.sgmlId.size() > 0
5094 ? MifDoc::CurInstance->elements().bookComponentIndex
5095 ( crossRefInfo.groveIndex, crossRefInfo.sgmlId )
5096 : MifDoc::CurInstance->elements().bookComponentIndex
5097 ( crossRefInfo.groveIndex, crossRefInfo.elementIndex );
5098 targetFileName
5099 += MifDoc::T_pathname
5100 ( MifDoc::CurInstance->bookComponents()[bookComponentIdx].FileName );
5101 setXRefSrcFile( targetFileName );
5102 setXRefName( MifDoc::sPageNumXRefFormatName );
5103 setXRefSrcText( crossRefInfo.crossRefText() );
5104 setXRefText( "000" );
5105 break; }
5106 default: assert( false );
5107 }
5108 }
5109
5110 void MifDoc::XRef::out( MifOutputByteStream &os ) {
5111
5112 os << '\n' << MifOutputByteStream::INDENT << "<XRef ";
5113 os.indent();
5114 CHECK_PROPERTY( XRefName );
5115 if( setProperties & fXRefSrcText )
5116 XRefSrcText.escapeSpecialChars();
5117 CHECK_PROPERTY( XRefSrcText );
5118 CHECK_PROPERTY( XRefSrcFile );
5119 os.undent();
5120 os << '\n' << MifOutputByteStream::INDENT << ">";
5121 if( setProperties & fXRefText )
5122 os << '\n' << MifOutputByteStream::INDENT
5123 << "<String " << XRefText << ">";
5124 os << '\n' << MifOutputByteStream::INDENT << "<XRefEnd>";
5125 }
5126
5127 // --------- MifDoc::Marker ---------------------------------------------------
5128
5129 MifDoc::Marker::Marker( CrossRefInfo &crossRefInfo, bool linkDestinationMode ) {
5130
5131 switch( crossRefInfo.type() ) {
5132 case CrossRefInfo::PotentialMarker:
5133 if( linkDestinationMode ) {
5134 setMType( Hypertext );
5135 setMText( "newlink " );
5136 MText += crossRefInfo.crossRefText();
5137 } else {
5138 setMType( XRef );
5139 setMText( crossRefInfo.crossRefText() );
5140 }
5141 break;
5142
5143 case CrossRefInfo::HypertextLink: {
5144 setMType( Hypertext );
5145 MifDoc::T_pathname targetFileName( "<c>" );
5146 int bookComponentIdx
5147 = crossRefInfo.sgmlId.size() > 0
5148 ? MifDoc::CurInstance->elements().bookComponentIndex
5149 ( crossRefInfo.groveIndex, crossRefInfo.sgmlId )
5150 : MifDoc::CurInstance->elements().bookComponentIndex
5151 ( crossRefInfo.groveIndex, crossRefInfo.elementIndex );
5152 targetFileName
5153 += MifDoc::T_pathname
5154 ( MifDoc::CurInstance->bookComponents()[bookComponentIdx].FileName );
5155 setMText( T_string( "gotolink " ) );
5156 MText += targetFileName;
5157 MText += ':';
5158 MText += crossRefInfo.crossRefText();
5159 break; }
5160
5161 case HypertextDestination:
5162 setMText( T_string( "newlink " ) );
5163 MText += crossRefInfo.crossRefText();
5164 break;
5165
5166 default: assert( false );
5167 }
5168 }
5169
5170 void MifDoc::Marker::out( MifOutputByteStream &os ) {
5171
5172 os << '\n' << MifOutputByteStream::INDENT << "<Marker ";
5173 os.indent();
5174 CHECK_PROPERTY( MType );
5175 if( setProperties & fMText )
5176 MText.escapeSpecialChars();
5177 CHECK_PROPERTY( MText );
5178 os.undent();
5179 os << '\n' << MifOutputByteStream::INDENT << ">";
5180 }
5181
5182 // --------- MifDoc::Object ---------------------------------------------------
5183
5184 void MifDoc::Object::outObjectProperties( MifOutputByteStream &os ) {
5185
5186 CHECK_PROPERTY( ID );
5187 CHECK_PROPERTY( Pen );
5188 CHECK_PROPERTY( Fill );
5189 CHECK_PROPERTY( PenWidth );
5190 CHECK_PROPERTY( ObColor );
5191 }
5192
5193 // --------- MifDoc::PolyLine -------------------------------------------------
5194
5195 void MifDoc::PolyLine::out( MifOutputByteStream &os ) {
5196
5197 os << '\n' << MifOutputByteStream::INDENT << "<PolyLine ";
5198 os.indent();
5199 outObjectProperties( os );
5200 CHECK_PROPERTY( HeadCap );
5201 CHECK_PROPERTY( TailCap );
5202 for( size_t i = 0; i < Points.size(); i++ )
5203 os << '\n' << MifOutputByteStream::INDENT << "<Point " << Points[i] << ">";
5204 os.undent();
5205 os << '\n' << MifOutputByteStream::INDENT << ">";
5206 }
5207
5208 // --------- MifDoc::ImportObject ---------------------------------------------
5209
5210 void MifDoc::ImportObject::out( MifOutputByteStream &os ) {
5211
5212 os << '\n' << MifOutputByteStream::INDENT << "<ImportObject ";
5213 os.indent();
5214 outObjectProperties( os );
5215 CHECK_PROPERTY( ImportObFileDI );
5216 CHECK_PROPERTY( BitMapDpi );
5217 CHECK_PROPERTY( ShapeRect );
5218 CHECK_PROPERTY( ImportObFixedSize );
5219 CHECK_PROPERTY( NativeOrigin );
5220 os.undent();
5221 os << '\n' << MifOutputByteStream::INDENT << ">";
5222 }
5223
5224 // --------- MifDoc::Frame ----------------------------------------------------
5225
5226 void MifDoc::Frame::out( MifOutputByteStream &os ) {
5227
5228 os << '\n' << MifOutputByteStream::INDENT << "<Frame ";
5229 os.indent();
5230 outObjectProperties( os );
5231 CHECK_PROPERTY( ShapeRect );
5232 CHECK_PROPERTY( FrameType );
5233 CHECK_PROPERTY( NSOffset );
5234 CHECK_PROPERTY( BLOffset );
5235 CHECK_PROPERTY( AnchorAlign );
5236 for( size_t i = 0; i < Objects.size(); i++ ) Objects[i]->out( os );
5237 os.undent();
5238 os << '\n' << MifOutputByteStream::INDENT << ">";
5239 }
5240
5241 // --------- MifDoc::TextRect -------------------------------------------------
5242
5243 void MifDoc::TextRect::out( MifOutputByteStream &os ) {
5244
5245 os << '\n' << MifOutputByteStream::INDENT << "<TextRect ";
5246 os.indent();
5247 outObjectProperties( os );
5248 CHECK_PROPERTY( ShapeRect );
5249 CHECK_PROPERTY( TRNumColumns );
5250 CHECK_PROPERTY( TRColumnGap );
5251 CHECK_PROPERTY( TRColumnBalance );
5252 os.undent();
5253 os << '\n' << MifOutputByteStream::INDENT << ">";
5254 }
5255
5256 // --------- MifDoc::Page -----------------------------------------------------
5257
5258 void MifDoc::Page::out( MifOutputByteStream &os ) {
5259
5260 os << '\n' << MifOutputByteStream::INDENT << "<Page ";
5261 os.indent();
5262 CHECK_PROPERTY( PageType );
5263 CHECK_PROPERTY( PageTag );
5264 CHECK_PROPERTY( PageBackground );
5265 for( size_t i = 0; i < TextRects.size(); i++ )
5266 TextRects[i].out( os );
5267 os.undent();
5268 os << '\n' << MifOutputByteStream::INDENT << ">";
5269 }
5270
5271 // --------- MifDoc::TabStop --------------------------------------------------
5272
5273 void MifDoc::TabStop::out( MifOutputByteStream &os ) {
5274
5275 os << '\n' << MifOutputByteStream::INDENT << "<TabStop ";
5276 os.indent();
5277 CHECK_PROPERTY( TSX );
5278 CHECK_PROPERTY( TSType );
5279 CHECK_PROPERTY( TSLeaderStr );
5280 CHECK_PROPERTY( TSDecimalChar );
5281 os.undent();
5282 os << '\n' << MifOutputByteStream::INDENT << ">";
5283 }
5284
5285 // --------- MifDoc::Para -----------------------------------------------------
5286
5287 void MifDoc::Para::out( MifOutputByteStream &os ) {
5288
5289 outProlog( os );
5290 MifDoc::ParaLine::outProlog( os );
5291 content().commit( os.stream() );
5292 MifDoc::ParaLine::outEpilog( os );
5293 outEpilog( os );
5294 }
5295
5296 void MifDoc::Para::outSimpleProlog( MifOutputByteStream &os ) {
5297
5298 currentlyOpened = true;
5299 os << '\n' << MifOutputByteStream::INDENT << "<Para ";
5300 os.indent();
5301 }
5302
5303 void MifDoc::Para::outProlog( MifOutputByteStream &os ) {
5304
5305 currentlyOpened = true;
5306 outSimpleProlog( os );
5307 CHECK_PROPERTY( PgfTag );
5308 if( setProperties & fParagraphFormat )
5309 format().out( os );
5310 }
5311
5312 void MifDoc::Para::outEpilog( MifOutputByteStream &os ) {
5313
5314 os.undent();
5315 os << '\n' << MifOutputByteStream::INDENT << ">";
5316 currentlyOpened = false;
5317 }
5318
5319 // --------- MifDoc::ParaLine -------------------------------------------------
5320
5321 void MifDoc::ParaLine::outProlog( MifOutputByteStream &os ) {
5322
5323 os << '\n' << MifOutputByteStream::INDENT << "<ParaLine ";
5324 os.indent();
5325
5326 MifDoc::TextFlow *tf = MifDoc::CurInstance->curTextFlow();
5327 if( tf != NULL && !tf->TextRectIDUsed ) {
5328 setTextRectID( tf->TextRectID );
5329 CHECK_PROPERTY( TextRectID );
5330 setProperties &= ~fTextRectID;
5331 tf->TextRectIDUsed = true;
5332 }
5333
5334 MifDoc::Tbl *tbl = MifDoc::CurInstance->curTbl( false );
5335 if( tbl != NULL && !tbl->TblIDUsed ) {
5336 setATbl( tbl->TblID );
5337 CHECK_PROPERTY( ATbl );
5338 setProperties &= ~fATbl;
5339 tbl->TblIDUsed = true;
5340 }
5341 }
5342
5343 void MifDoc::ParaLine::outEpilog( MifOutputByteStream &os ) {
5344
5345 os.undent();
5346 os << '\n' << MifOutputByteStream::INDENT << ">";
5347 }
5348
5349
5350 // --------- MifDoc::PgfCatalog -----------------------------------------------
5351
5352 void MifDoc::PgfCatalog::out( MifOutputByteStream &os ) {
5353
5354 os << '\n' << MifOutputByteStream::INDENT << "<PgfCatalog ";
5355 os.indent();
5356 for( size_t i = 0; i < ParaFormats.size(); i++ ) ParaFormats[i].out( os, false );
5357 os.undent();
5358 os << '\n' << MifOutputByteStream::INDENT << ">";
5359 }
5360
5361 // --------- MifDoc::TblCatalog -----------------------------------------------
5362
5363 void MifDoc::TblCatalog::out( MifOutputByteStream &os ) {
5364
5365 if( TblFormats.size() > 0 ) {
5366 os << '\n' << MifOutputByteStream::INDENT << "<TblCatalog ";
5367 os.indent();
5368 for( size_t i = 0; i < TblFormats.size(); i++ ) TblFormats[i].out( os );
5369 os.undent();
5370 os << '\n' << MifOutputByteStream::INDENT << ">";
5371 }
5372 }
5373
5374 // ----------------------------------------------------------------------------
5375
5376 #define COMPARE_PROPERTY( propertyName ) \
5377 \
5378 if( propertyName != f.propertyName ) \
5379 differingProperties |= f ## propertyName;
5380
5381 #define COND_SET_PROPERTY( propertyName ) \
5382 \
5383 if( properties & f ## propertyName ) \
5384 propertyName = f.propertyName;
5385
5386 #define PROPERTY_OUT( propertyName ) \
5387 \
5388 if( properties & f ## propertyName ) \
5389 os << '\n' << MifOutputByteStream::INDENT \
5390 << "<" #propertyName " " << propertyName << ">";
5391
5392 // --------- MifDoc::FontFormat -----------------------------------------------
5393
5394 unsigned MifDoc::FontFormat::compare( FontFormat &f ) {
5395
5396 unsigned differingProperties = 0;
5397
5398 COMPARE_PROPERTY( FFamily );
5399 COMPARE_PROPERTY( FAngle );
5400 COMPARE_PROPERTY( FWeight );
5401 COMPARE_PROPERTY( FVar );
5402 COMPARE_PROPERTY( FSize );
5403 COMPARE_PROPERTY( FColor );
5404 COMPARE_PROPERTY( FUnderlining );
5405 COMPARE_PROPERTY( FOverline );
5406 COMPARE_PROPERTY( FStrike );
5407 COMPARE_PROPERTY( FPosition );
5408 COMPARE_PROPERTY( FPairKern );
5409 COMPARE_PROPERTY( FCase );
5410 COMPARE_PROPERTY( FDX );
5411 COMPARE_PROPERTY( FDY );
5412 COMPARE_PROPERTY( FDW );
5413
5414 return differingProperties;
5415 }
5416
5417 void MifDoc::FontFormat::setFrom( FontFormat &f, unsigned properties ) {
5418
5419 COND_SET_PROPERTY( FFamily );
5420 COND_SET_PROPERTY( FAngle );
5421 COND_SET_PROPERTY( FWeight );
5422 COND_SET_PROPERTY( FVar );
5423 COND_SET_PROPERTY( FSize );
5424 COND_SET_PROPERTY( FColor );
5425 COND_SET_PROPERTY( FUnderlining );
5426 COND_SET_PROPERTY( FOverline );
5427 COND_SET_PROPERTY( FStrike );
5428 COND_SET_PROPERTY( FPosition );
5429 COND_SET_PROPERTY( FPairKern );
5430 COND_SET_PROPERTY( FCase );
5431 COND_SET_PROPERTY( FDX );
5432 COND_SET_PROPERTY( FDY );
5433 COND_SET_PROPERTY( FDW );
5434 }
5435
5436 void MifDoc::FontFormat::out( MifOutputByteStream &os,
5437 unsigned properties,
5438 FontStatement fontStatement ) {
5439
5440 const char *statementName = (fontStatement == stPgfFont) ? "PgfFont" : "Font";
5441
5442 if( properties ) {
5443
5444 os << '\n' << MifOutputByteStream::INDENT << "<" << statementName << " ";
5445 os.indent();
5446
5447 PROPERTY_OUT( FFamily );
5448 PROPERTY_OUT( FAngle );
5449 PROPERTY_OUT( FWeight );
5450 PROPERTY_OUT( FVar );
5451 PROPERTY_OUT( FSize );
5452 PROPERTY_OUT( FColor );
5453 PROPERTY_OUT( FUnderlining );
5454 PROPERTY_OUT( FOverline );
5455 PROPERTY_OUT( FStrike );
5456 PROPERTY_OUT( FPosition );
5457 PROPERTY_OUT( FPairKern );
5458 PROPERTY_OUT( FCase );
5459 PROPERTY_OUT( FDX );
5460 PROPERTY_OUT( FDY );
5461 PROPERTY_OUT( FDW );
5462
5463 os.undent();
5464 os << '\n' << MifOutputByteStream::INDENT << ">";
5465 }
5466 }
5467
5468 void MifDoc::FontFormat::updateFrom( FontFormat &f ) {
5469
5470 unsigned differingProperties = FontFormat::compare( f );
5471 setFrom( f, differingProperties );
5472 setProperties = differingProperties;
5473 }
5474
5475 // --------- MifDoc::ParagraphFormat ------------------------------------------
5476
5477 unsigned MifDoc::ParagraphFormat::compare( ParagraphFormat &f ) {
5478
5479 unsigned differingProperties = 0;
5480
5481 COMPARE_PROPERTY( PgfTag );
5482 COMPARE_PROPERTY( PgfLanguage );
5483 COMPARE_PROPERTY( PgfFIndent );
5484 COMPARE_PROPERTY( PgfLIndent );
5485 COMPARE_PROPERTY( PgfRIndent );
5486 COMPARE_PROPERTY( PgfAlignment );
5487 COMPARE_PROPERTY( PgfSpBefore );
5488 COMPARE_PROPERTY( PgfSpAfter );
5489 COMPARE_PROPERTY( PgfLineSpacing );
5490 COMPARE_PROPERTY( PgfLeading );
5491 COMPARE_PROPERTY( PgfNumTabs );
5492 COMPARE_PROPERTY( PgfPlacement );
5493 COMPARE_PROPERTY( PgfPlacementStyle );
5494 COMPARE_PROPERTY( PgfWithPrev );
5495 COMPARE_PROPERTY( PgfWithNext );
5496 COMPARE_PROPERTY( PgfBlockSize );
5497 COMPARE_PROPERTY( PgfAutoNum );
5498 COMPARE_PROPERTY( PgfNumFormat );
5499 COMPARE_PROPERTY( PgfNumberFont );
5500 COMPARE_PROPERTY( PgfHyphenate );
5501 COMPARE_PROPERTY( HyphenMaxLines );
5502 COMPARE_PROPERTY( HyphenMinPrefix );
5503 COMPARE_PROPERTY( HyphenMinSuffix );
5504 COMPARE_PROPERTY( HyphenMinWord );
5505 COMPARE_PROPERTY( PgfLetterSpace );
5506 COMPARE_PROPERTY( PgfCellAlignment );
5507 COMPARE_PROPERTY( PgfCellMargins );
5508 COMPARE_PROPERTY( PgfCellLMarginFixed );
5509 COMPARE_PROPERTY( PgfCellTMarginFixed );
5510 COMPARE_PROPERTY( PgfCellRMarginFixed );
5511 COMPARE_PROPERTY( PgfCellBMarginFixed );
5512
5513 return differingProperties;
5514 }
5515
5516 void MifDoc::ParagraphFormat::setFrom( ParagraphFormat &f,
5517 unsigned properties,
5518 unsigned fontProperties ) {
5519 COND_SET_PROPERTY( PgfTag );
5520 COND_SET_PROPERTY( PgfLanguage );
5521 COND_SET_PROPERTY( PgfFIndent );
5522 COND_SET_PROPERTY( PgfLIndent );
5523 COND_SET_PROPERTY( PgfRIndent );
5524 COND_SET_PROPERTY( PgfAlignment );
5525 COND_SET_PROPERTY( PgfSpBefore );
5526 COND_SET_PROPERTY( PgfSpAfter );
5527 COND_SET_PROPERTY( PgfLineSpacing );
5528 COND_SET_PROPERTY( PgfLeading );
5529 COND_SET_PROPERTY( PgfNumTabs );
5530 COND_SET_PROPERTY( PgfPlacement );
5531 COND_SET_PROPERTY( PgfPlacementStyle );
5532 COND_SET_PROPERTY( PgfWithPrev );
5533 COND_SET_PROPERTY( PgfWithNext );
5534 COND_SET_PROPERTY( PgfBlockSize );
5535 COND_SET_PROPERTY( PgfAutoNum );
5536 COND_SET_PROPERTY( PgfNumFormat );
5537 COND_SET_PROPERTY( PgfNumberFont );
5538 COND_SET_PROPERTY( PgfHyphenate );
5539 COND_SET_PROPERTY( HyphenMaxLines );
5540 COND_SET_PROPERTY( HyphenMinPrefix );
5541 COND_SET_PROPERTY( HyphenMinSuffix );
5542 COND_SET_PROPERTY( HyphenMinWord );
5543 COND_SET_PROPERTY( PgfLetterSpace );
5544 COND_SET_PROPERTY( PgfCellAlignment );
5545 COND_SET_PROPERTY( PgfCellMargins );
5546 COND_SET_PROPERTY( PgfCellLMarginFixed );
5547 COND_SET_PROPERTY( PgfCellTMarginFixed );
5548 COND_SET_PROPERTY( PgfCellRMarginFixed );
5549 COND_SET_PROPERTY( PgfCellBMarginFixed );
5550
5551 FontFormat::setFrom( f, fontProperties );
5552 }
5553
5554 void MifDoc::ParagraphFormat::out( MifOutputByteStream &os,
5555 unsigned properties,
5556 unsigned fontProperties,
5557 bool excludeCellProperties ) {
5558
5559 bool outPgfTag = false;
5560 T_tagstring pgfTag;
5561
5562 if( !( properties & fPgfTag ) ) {
5563 MifDoc::TagStream &ts = MifDoc::CurInstance->curTagStream();
5564 if( !ts.PgfTagUsed ) {
5565 pgfTag = ts.InitialPgfTag;
5566 outPgfTag = true;
5567 ts.PgfTagUsed = true;
5568 }
5569 }
5570
5571 if( properties != 0 || fontProperties != 0 || outPgfTag ) {
5572
5573 os << '\n' << MifOutputByteStream::INDENT << "<Pgf ";
5574 os.indent();
5575
5576 if( outPgfTag )
5577 os << '\n' << MifOutputByteStream::INDENT << "<PgfTag " << pgfTag << ">";
5578 else
5579 PROPERTY_OUT( PgfTag );
5580
5581 FontFormat::out( os, fontProperties, FontFormat::stPgfFont );
5582
5583 PROPERTY_OUT( PgfLanguage );
5584 PROPERTY_OUT( PgfFIndent );
5585 PROPERTY_OUT( PgfLIndent );
5586 PROPERTY_OUT( PgfRIndent );
5587 PROPERTY_OUT( PgfAlignment );
5588 PROPERTY_OUT( PgfSpBefore );
5589 PROPERTY_OUT( PgfSpAfter );
5590 PROPERTY_OUT( PgfLineSpacing );
5591 PROPERTY_OUT( PgfLeading );
5592
5593 PROPERTY_OUT( PgfNumTabs );
5594 if( properties & fTabStops )
5595 for( size_t i = 0; i < TabStops.size(); i++ ) TabStops[i].out( os );
5596
5597 PROPERTY_OUT( PgfPlacement );
5598 PROPERTY_OUT( PgfPlacementStyle );
5599 PROPERTY_OUT( PgfWithPrev );
5600 PROPERTY_OUT( PgfWithNext );
5601 PROPERTY_OUT( PgfBlockSize );
5602 PROPERTY_OUT( PgfAutoNum );
5603 PROPERTY_OUT( PgfNumFormat );
5604 PROPERTY_OUT( PgfNumberFont );
5605 PROPERTY_OUT( PgfHyphenate );
5606 PROPERTY_OUT( HyphenMaxLines );
5607 PROPERTY_OUT( HyphenMinPrefix );
5608 PROPERTY_OUT( HyphenMinSuffix );
5609 PROPERTY_OUT( HyphenMinWord );
5610 PROPERTY_OUT( PgfLetterSpace );
5611
5612 if( MifDoc::CurInstance->curCell() != NULL || !excludeCellProperties ) {
5613
5614 PROPERTY_OUT( PgfCellAlignment );
5615 PROPERTY_OUT( PgfCellMargins );
5616 PROPERTY_OUT( PgfCellLMarginFixed );
5617 PROPERTY_OUT( PgfCellTMarginFixed );
5618 PROPERTY_OUT( PgfCellRMarginFixed );
5619 PROPERTY_OUT( PgfCellBMarginFixed );
5620 }
5621
5622 os.undent();
5623 os << '\n' << MifOutputByteStream::INDENT << ">";
5624 }
5625 }
5626
5627 void MifDoc::ParagraphFormat::updateFrom( ParagraphFormat &f ) {
5628
5629 FontFormat::updateFrom( f );
5630
5631 unsigned differingProperties = compare( f );
5632 setFrom( f, differingProperties, 0 );
5633 setProperties = differingProperties;
5634 }
5635
5636 // --------- MifDoc::BookComponent --------------------------------------------
5637
5638 MifDoc::BookComponent::BookComponent( MifTmpOutputByteStream *epilogOs )
5639 : epilogOs( epilogOs ), pageNumXRefFormatGenerated( false ) {
5640 }
5641
5642 void MifDoc::BookComponent::commit
5643 ( const String<CmdLineApp::AppChar> &dirName, bool resolveCrossReferences ) {
5644
5645 assert( FileName.size() > 0 );
5646 String<CmdLineApp::AppChar> fileLoc;
5647 fileLoc += dirName; fileLoc += FileName; fileLoc += 0;
5648 FileOutputByteStream outFile;
5649 if( outFile.open( fileLoc.data() ) ) {
5650
5651 MifOutputByteStream os( outFile );
5652
5653 os << "<MIFFile 5.0>";
5654
5655 colorCatalog.out( os );
5656 pgfCatalog.out( os );
5657 rulingCatalog.out( os );
5658
5659 size_t i;
5660 if( AFrames.size() ) {
5661 os << "\n<AFrames ";
5662 os.indent();
5663 for( i = 0; i < AFrames.size(); i++ ) AFrames[i].out( os );
5664 os.undent();
5665 os << '\n' << ">";
5666 }
5667
5668 if( XRefFormats.size() ) {
5669 os << "\n<XRefFormats ";
5670 os.indent();
5671 for( i = 0; i < XRefFormats.size(); i++ ) XRefFormats[i].out( os );
5672 os.undent();
5673 os << '\n' << ">";
5674 }
5675
5676 tblCatalog.out( os );
5677 document.out( os );
5678
5679 if( Tbls.size() ) {
5680 os << "\n<Tbls ";
5681 os.indent();
5682 for( i = 0; i < Tbls.size(); i++ ) Tbls[i].out( os, resolveCrossReferences );
5683 os.undent();
5684 os << '\n' << ">";
5685 }
5686
5687 for( i = 0; i < Pages.size(); i++ ) Pages[i].out( os );
5688 for( i = 0; i < TextFlows.size(); i++ ) TextFlows[i].out( os, resolveCrossReferences );
5689
5690 if( epilogOs )
5691 epilogOs->commit( os.stream(), resolveCrossReferences );
5692
5693 } else {
5694 MifDoc::curInstance().App->message
5695 ( MifMessages::cannotOpenOutputError,
5696 StringMessageArg( MifDoc::curInstance().App->convertInput( fileLoc.data() ) ),
5697 ErrnoMessageArg( errno ) );
5698 return;
5699 }
5700 }
5701
5702 // --------- MifDoc -----------------------------------------------------------
5703
5704 MifDoc::MifDoc( const String<CmdLineApp::AppChar> &fileLoc, CmdLineApp *app )
5705 : App( app ), RootOutputFileLoc( fileLoc ), CurTblNum( 0 ), CurTextFlow( NULL ),
5706 CurCell( NULL ), CurPara( NULL ), NextID( 0 ) {
5707
5708 if( RootOutputFileLoc.size() > 0 && RootOutputFileLoc[RootOutputFileLoc.size()-1] == 0 )
5709 RootOutputFileLoc.resize( RootOutputFileLoc.size() - 1 );
5710
5711 CurInstance = this;
5712 enterBookComponent();
5713 }
5714
5715 MifDoc::~MifDoc() {
5716
5717 commit();
5718 }
5719
5720 void MifDoc::commit() {
5721
5722 String<CmdLineApp::AppChar> outDir = rootOutputFileLoc();
5723 String<CmdLineApp::AppChar> outFileName;
5724
5725 { int i;
5726 for( i = outDir.size() - 1; i >= 0; i-- )
5727 if( outDir[i] == '/' || outDir[i] == '\\' )
5728 break;
5729 if( outDir.size() - (i+1) > 0 )
5730 outFileName.assign( &outDir.data()[i+1], outDir.size() - (i+1) );
5731 outDir.resize( i + 1 ); }
5732
5733 if( BookComponents.size() > 1 ) {
5734 String<CmdLineApp::AppChar> bookFileLoc( rootOutputFileLoc() );
5735 String<CmdLineApp::AppChar> fileNameExt;
5736
5737 { size_t idx;
5738 for( idx = bookFileLoc.size(); idx > 0; idx-- )
5739 if( bookFileLoc[idx-1] == char( '.' ) )
5740 break;
5741 if( idx > 0 && bookFileLoc.size() - idx > 0 )
5742 fileNameExt.assign( &bookFileLoc[idx], bookFileLoc.size() - idx );
5743 else {
5744 fileNameExt += 'm'; fileNameExt += 'i'; fileNameExt += 'f';
5745 } }
5746
5747 String<CmdLineApp::AppChar> fileName;
5748 char idxStr[32];
5749 for( size_t i = 0; i < BookComponents.size(); i++ ) {
5750 fileName.resize( 0 );
5751 sprintf( idxStr, "%u", i+1 );
5752 for( const char *c = idxStr; *c; c++)
5753 fileName += CmdLineApp::AppChar(*c);
5754 fileName += '.'; fileName += fileNameExt;
5755 BookComponents[i].FileName = fileName;
5756 }
5757
5758 bookFileLoc += 0;
5759 FileOutputByteStream bookFile;
5760 if( bookFile.open( bookFileLoc.data() ) ) {
5761
5762 MifOutputByteStream os( bookFile );
5763 os << "<Book 5.0>";
5764 for( size_t i = 0; i < BookComponents.size(); i++ )
5765 os << "\n<BookComponent"
5766 << "\n <FileName `<c\\>" << BookComponents[i].FileName << "\'>"
5767 << "\n>";
5768 } else {
5769
5770 MifDoc::curInstance().App->message
5771 ( MifMessages::cannotOpenOutputError,
5772 StringMessageArg( MifDoc::curInstance().App->convertInput( bookFileLoc.data() ) ),
5773 ErrnoMessageArg( errno ) );
5774 }
5775
5776 } else
5777 if( BookComponents.size() == 1 )
5778 BookComponents[0].FileName = outFileName;
5779
5780 for( size_t i = 0; i < BookComponents.size(); i++ )
5781 BookComponents[i].commit( outDir );
5782 }
5783
5784 void MifDoc::enterBookComponent() {
5785
5786 TagStream *defaultTagStream = new TagStream( MifDoc::T_indent( 0 ) );
5787 enterTagStream( *defaultTagStream );
5788 BookComponent newBookComponent( &defaultTagStream->content() );
5789 bookComponents().push_back( newBookComponent );
5790 }
5791
5792 void MifDoc::exitBookComponent() {
5793
5794 exitTagStream();
5795 }
5796
5797 void MifDoc::outAFrame( T_ID ID, MifOutputByteStream &os ) {
5798
5799 os << '\n' << MifOutputByteStream::INDENT << "<AFrame " << ID << ">";
5800 }
5801
5802 void MifDoc::switchToTagStream( TagStream &tagStream, bool startWithDefaultPgfFormat ) {
5803
5804 if( tagStream.TagStreamClass == TagStream::tsTextFlow )
5805 setCurTextFlow( (MifDoc::TextFlow*)&tagStream );
5806 else
5807 if( tagStream.TagStreamClass == TagStream::tsCell )
5808 setCurCell( (MifDoc::Cell*)&tagStream );
5809
5810 if( tagStream.TagStreamClass == TagStream::tsPara ) {
5811 MifDoc::Para::currentlyOpened = true;
5812 } else
5813 if( startWithDefaultPgfFormat ) {
5814 tagStream.PgfTagUsed = false;
5815 MifDoc::ParagraphFormat defaultPgfFormat;
5816 defaultPgfFormat.setDSSSLDefaults();
5817 setCurParagraphFormat( defaultPgfFormat );
5818 }
5819 setCurOs( tagStream.content().stream() );
5820 }
5821
5822 void MifDoc::enterTagStream( TagStream &tagStream ) {
5823
5824 TagStreamStack.resize( TagStreamStack.size() + 1 );
5825 TagStreamStack.back() = &tagStream;
5826 switchToTagStream( *TagStreamStack.back() );
5827 }
5828
5829 void MifDoc::exitTagStream() {
5830
5831 bool startWithDefaultPgfFormat = true;
5832
5833 assert( TagStreamStack.size() > 0 );
5834 if( TagStreamStack.back()->TagStreamClass == TagStream::tsPara ) {
5835 MifDoc::Para::currentlyOpened = false;
5836 startWithDefaultPgfFormat = false;
5837 }
5838 TagStreamStack.resize( TagStreamStack.size() - 1 );
5839 if( TagStreamStack.size() >= 1 )
5840 switchToTagStream( *TagStreamStack.back(), startWithDefaultPgfFormat );
5841 }
5842
5843 void MifDoc::outTagEnd() { os() << ">"; }
5844
5845 void MifDoc::outHexChar( unsigned code, MifOutputByteStream *o ) {
5846
5847 MifOutputByteStream &outS = ( o != NULL ) ? *o : os();
5848 static const char hex[] = "0123456789abcdef";
5849 outS << "\\x" << hex[(code >> 4) & 0xf] << hex[code & 0xf] << " ";
5850 }
5851
5852 void MifDoc::outHexChar( unsigned code, String<char> &targetString ) {
5853
5854 static const char hex[] = "0123456789abcdef";
5855 targetString += '\\'; targetString += 'x';
5856 targetString += hex[(code >> 4) & 0xf];
5857 targetString += hex[code & 0xf];
5858 targetString += ' ';
5859 }
5860
5861 void MifDoc::outSpecialChar( const String<char> &charName, MifOutputByteStream *o ) {
5862
5863 MifOutputByteStream &outS = ( o != NULL ) ? *o : os();
5864 outS << '\n' << MifOutputByteStream::INDENT << "<Char " << charName << ">";
5865 }
5866
5867 void MifDoc::outBreakingPara( MifDoc::T_keyword pgfPlacement ) {
5868
5869 curFormat().setPgfSpBefore( 0 ),
5870 curFormat().setPgfSpAfter( 0 ),
5871 curFormat().setPgfPlacement( pgfPlacement );
5872 Para::outSimpleProlog( os() );
5873 curFormat().out( os() );
5874 ParaLine::outProlog( os() );
5875 ParaLine::outEpilog( os() );
5876 Para::outEpilog( os() );
5877 }
5878
5879 void MifDoc::beginParaLine() {
5880
5881 MifDoc::ParaLine::outProlog( os() );
5882 }
5883
5884 void MifDoc::endParaLine() {
5885
5886 MifDoc::ParaLine::outEpilog( os() );
5887 }
5888
5889 void MifDoc::outPageNumber() {
5890
5891 os() << '\n' << MifOutputByteStream::INDENT
5892 << "<Variable <VariableName `Current Page #'>>";
5893 }
5894
5895 // --------- MifDoc::ElementSet -----------------------------------------------
5896
5897 MifDoc::ElementSet::ElementSet() {}
5898
5899 int MifDoc::ElementSet::bookComponentIndex( unsigned long groveIndex, unsigned long n ) const {
5900
5901 unsigned short flags;
5902 if( getFlags( groveIndex, n, flags ) )
5903 return int( flags & BOOK_COMPONENT_INDEX_M() );
5904
5905 assert( false );
5906 return 0;
5907 }
5908
5909 int MifDoc::ElementSet::bookComponentIndex
5910 ( unsigned long groveIndex, const StringC &sgmlId ) {
5911
5912 SgmlIdInfo &sgmlIdInfo = enforceSgmlId( sgmlId, groveIndex );
5913 return int( sgmlIdInfo.flags & BOOK_COMPONENT_INDEX_M() );
5914 }
5915
5916 void MifDoc::ElementSet::setBookComponentIndex
5917 ( unsigned long groveIndex, unsigned long n, int i ) {
5918
5919 unsigned short flags = 0;
5920 getFlags( groveIndex, n, flags );
5921 add( groveIndex, n,
5922 ( flags & LINK_TYPE_MASK( AnyReference ) )
5923 | (unsigned short)( i & BOOK_COMPONENT_INDEX_M() ) );
5924 }
5925
5926 void MifDoc::ElementSet::setBookComponentIndex
5927 ( unsigned long groveIndex, const StringC &sgmlId, int i ) {
5928
5929 SgmlIdInfo &sgmlIdInfo = enforceSgmlId( sgmlId, groveIndex );
5930 unsigned short flags = sgmlIdInfo.flags;
5931 sgmlIdInfo.flags = ( flags & LINK_TYPE_MASK( AnyReference ) )
5932 | (unsigned short)( i & BOOK_COMPONENT_INDEX_M() );
5933 }
5934
5935 bool MifDoc::ElementSet::hasBeenReferenced
5936 ( ReferenceType refType, unsigned long groveIndex, unsigned long n ) const {
5937
5938 unsigned short flags = 0;
5939 getFlags( groveIndex, n, flags );
5940 return ( flags & LINK_TYPE_MASK( refType ) ) != 0 ? true : false;
5941 }
5942
5943 bool MifDoc::ElementSet::hasBeenReferenced
5944 ( ReferenceType refType, unsigned long groveIndex, const StringC &sgmlId ) {
5945
5946 SgmlIdInfo &sgmlIdInfo = enforceSgmlId( sgmlId, groveIndex );
5947 return ( sgmlIdInfo.flags & LINK_TYPE_MASK( refType ) ) != 0 ? true : false;
5948 }
5949
5950 MifDoc::ElementSet::SgmlIdInfo &MifDoc::ElementSet::enforceSgmlId
5951 ( const StringC &sgmlId, unsigned long groveIndex ) {
5952
5953 SgmlIdInfo *result = SgmlIdInfos.lookup( sgmlId );
5954 if( result == NULL ) {
5955 result = new SgmlIdInfo( sgmlId, groveIndex );
5956 SgmlIdInfos.insert( result );
5957 }
5958 return *result;
5959 }
5960
5961 void MifDoc::ElementSet::setReferencedFlag
5962 ( ReferenceType refType, unsigned long groveIndex, unsigned long n ) {
5963
5964 assert( refType != AnyReference );
5965 unsigned short flags = 0;
5966 getFlags( groveIndex, n, flags );
5967 add( groveIndex, n, flags | LINK_TYPE_MASK( refType ) );
5968 }
5969
5970 void MifDoc::ElementSet::setReferencedFlag
5971 ( ReferenceType refType, unsigned long groveIndex, const StringC &sgmlId ) {
5972
5973 SgmlIdInfo &sgmlIdInfo = enforceSgmlId( sgmlId, groveIndex );
5974 assert( refType != AnyReference );
5975 sgmlIdInfo.flags |= LINK_TYPE_MASK( refType );
5976 }
5977
5978 void MifDoc::ElementSet::add
5979 ( unsigned long groveIndex, unsigned long n, unsigned short flags ) {
5980
5981 if( groveIndex >= Flags.size() )
5982 Flags.resize( groveIndex + 1 );
5983 Vector<unsigned short> &elems = Flags[groveIndex];
5984 if( n >= elems.size() ) {
5985 for( size_t k = 1 + (n - elems.size()); k > 0; --k )
5986 elems.push_back(0);
5987 }
5988 elems[n] = flags;
5989 }
5990
5991 bool MifDoc::ElementSet::getFlags
5992 ( unsigned long groveIndex, unsigned long n, unsigned short &result ) const {
5993
5994 if( groveIndex < Flags.size() && n < Flags[groveIndex].size() ) {
5995 result = Flags[groveIndex][n];
5996 return true;
5997 } else
5998 return false;
5999 }
6000
6001 #ifdef DSSSL_NAMESPACE
6002 }
6003 #endif
6004
6005 #include "MifFOTBuilder_inst.cxx"
6006
6007 #endif /* JADE_MIF */