1 // TeXFotBuilder.cxx: a Generic TeX backend for Jade
2 // Written by David Megginson <dmeggins@microstar.com>
3 // With changes from Sebastian Rahtz <s.rahtz@elsevier.co.uk>
4 // Last Modification: August 6th, 1998
5 
6 // Table Support: Kathleen Marszalek <kmarszal@watarts.uwaterloo.ca>
7 // Version: 1.0b7
8 // Last Modification: July 7th, 1998
9 
10 #include "config.h"
11 #include "TeXFOTBuilder.h"
12 #include "TeXMessages.h"
13 #include "MessageArg.h"
14 #include "TmpOutputByteStream.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #undef TEXDEBUG
18 #undef NDEBUG
19 
20 #define OUTLINES
21 #undef DEBUG_OUTLINES
22 #ifdef DEBUG_OUTLINES
23 #include <iostream.h>
24 #endif
25 #include <assert.h>
26 
27 #ifdef DSSSL_NAMESPACE
28 namespace DSSSL_NAMESPACE {
29 #endif
30 
31 // --------- TeXTmpOutputByteStream ------------------------------------------
32 
33 struct TeXTmpOutputByteStream : public TmpOutputByteStream {
TeXTmpOutputByteStreamDSSSL_NAMESPACE::TeXTmpOutputByteStream34   TeXTmpOutputByteStream() : TmpOutputByteStream() {}
35   void commit( OutputByteStream &os ) const;
36 };
37 
38 // ----------------------------------------------------------------------------
39 
40 struct LengthInPoints {
LengthInPointsDSSSL_NAMESPACE::LengthInPoints41   LengthInPoints( long l_ ) : l( l_ ) {}
42   long l;
43 };
44 
commit(OutputByteStream & os) const45 void TeXTmpOutputByteStream::commit( OutputByteStream &os ) const {
46 
47   TmpOutputByteStream::Iter iter( *this );
48   const char *s;
49   size_t n;
50 
51   while( iter.next( s, n ) ) {
52     os.sputn( s, n );
53   }
54 }
55 // --------- TeXFOTBuilder ----------------------------------------------------
56 
57 
58 class TeXFOTBuilder : public SerialFOTBuilder {
59 public:
60 #ifdef TEXDEBUG
curInstance()61   static TeXFOTBuilder &curInstance() { assert( CurInstance != NULL ); return *CurInstance; }
62   // used for testing only: otherwise code is re-entrant
63 #endif
64   struct PageFloatNIC {
65     ~PageFloatNIC();
66     StringC placement;
67   };
68   class TeXExtensionFlowObj : public FOTBuilder::ExtensionFlowObj {
69   public:
70     virtual void atomic(TeXFOTBuilder &, const NodePtr &) const = 0;
71   };
72   class TeXCompoundExtensionFlowObj : public FOTBuilder::CompoundExtensionFlowObj {
73   public:
74     virtual void start(TeXFOTBuilder &, const NodePtr &) const = 0;
75     virtual void end(TeXFOTBuilder &) const = 0;
76   };
77   class PageFloatFlowObj : public TeXCompoundExtensionFlowObj {
start(TeXFOTBuilder & fotb,const NodePtr &) const78     void start(TeXFOTBuilder &fotb, const NodePtr &) const {
79       fotb.startPageFloat(nic_);
80     }
end(TeXFOTBuilder & fotb) const81     void end(TeXFOTBuilder &fotb) const {
82       fotb.endPageFloat();
83     }
hasNIC(const StringC & name) const84     bool hasNIC(const StringC &name) const {
85       return name == "placement" ;
86     }
setNIC(const StringC &,const Value & value)87     void setNIC(const StringC &, const Value &value) {
88       value.convertString(nic_.placement);
89       }
copy() const90     ExtensionFlowObj *copy() const { return new PageFloatFlowObj(*this); }
91   public:
PageFloatFlowObj()92     PageFloatFlowObj() {}
93   private:
94     PageFloatNIC nic_;
95     StringC name_;
96     StringC placement;
97   };
98   class PageFootnoteFlowObj : public TeXCompoundExtensionFlowObj {
start(TeXFOTBuilder & fotb,const NodePtr &) const99     void start(TeXFOTBuilder &fotb, const NodePtr &) const {
100       fotb.startPageFootnote();
101     }
end(TeXFOTBuilder & fotb) const102     void end(TeXFOTBuilder &fotb) const {
103       fotb.endPageFootnote();
104     }
copy() const105     ExtensionFlowObj *copy() const { return new PageFootnoteFlowObj(*this); }
106   public:
PageFootnoteFlowObj()107     PageFootnoteFlowObj() {}
108   private:
109   };
110   //////////////////////////////////////////////////////////////////////
111   // Constructor and destructor.
112   //////////////////////////////////////////////////////////////////////
113 
114   TeXFOTBuilder(OutputByteStream *, Messenger *mgr);
115   ~TeXFOTBuilder();
116   //// Needed for heading levels
117 
118   //////////////////////////////////////////////////////////////////////
119   // Atomic flow objects
120   //////////////////////////////////////////////////////////////////////
121   void extension(const ExtensionFlowObj &fo, const NodePtr &);
122   void startExtensionSerial(const CompoundExtensionFlowObj &fo, const NodePtr &nd);
123   void endExtensionSerial(const CompoundExtensionFlowObj &fo);
124   void start();
125   void end();
126   void charactersFromNode(const NodePtr &, const Char *, size_t);
127   void setPreserveSdata(bool);
128   void startPageFloat(const PageFloatNIC &);
129   void endPageFloat();
130   void setPageFloatNIC(const PageFloatNIC &);
131   void startPageFootnote();
132   void endPageFootnote();
133 
134   void characters(const Char *, size_t);
135   void character(const CharacterNIC &);
136   void paragraphBreak(const ParagraphNIC &);
137   void externalGraphic(const ExternalGraphicNIC &);
138   void rule(const RuleNIC &);
139   void alignmentPoint();
140   void pageNumber();
141   void formattingInstruction(const StringC &);
142   void tableColumn(const TableColumnNIC &);
143   void tableCellBeforeRowBorder();
144   void tableCellAfterRowBorder();
145   void tableCellBeforeColumnBorder();
146   void tableCellAfterColumnBorder();
147 
148   void fractionBar();
149   void radicalRadical(const CharacterNIC &);
150   void radicalRadicalDefaulted();
151   void currentNodePageNumber(const NodePtr &);
152 
153   //////////////////////////////////////////////////////////////////////
154   // Non-atomic flow objects
155   //////////////////////////////////////////////////////////////////////
156 
157   void startSequence();
158   void endSequence();
159   void startLineField(const LineFieldNIC &);
160   void endLineField();
161   void startParagraph(const ParagraphNIC &);
162   void endParagraph();
163   void startDisplayGroup(const DisplayGroupNIC &);
164   void endDisplayGroup();
165   void startScroll();
166   void endScroll();
167   void startScore(Char);
168   void startScore(const LengthSpec &);
169   void startScore(Symbol);
170   void endScore();
171   void startLeader(const LeaderNIC &);
172   void endLeader();
173   void startSideline();
174   void endSideline();
175   void startBox(const BoxNIC &);
176   void endBox();
177   // Tables
178   void startTable(const TableNIC &);
179   void endTable();
180   // A call for each border is made immediately
181   // after startTable(), each preceded by any appropriate set*() calls.
182   void tableBeforeRowBorder();
183   void tableAfterRowBorder();
184   void tableBeforeColumnBorder();
185   void tableAfterColumnBorder();
186   void startTablePartSerial(const TablePartNIC &);
187   void endTablePartSerial();
188   void startTableRow();
189   void endTableRow();
190   void startTableCell(const TableCellNIC &);
191   void endTableCell();
192   void startSimplePageSequenceSerial();
193   void endSimplePageSequenceSerial();
194   // Headers and footers are treated like a separate port.
195   void startSimplePageSequenceHeaderFooter(unsigned);
196   void endSimplePageSequenceHeaderFooter(unsigned);
197   // page-number sosofo
198 
199   void startTablePartHeader();
200   void endTablePartHeader();
201   void startTablePartFooter();
202   void endTablePartFooter();
203   void startMathSequence();
204   void endMathSequence();
205   void startFractionSerial();
206   void endFractionSerial();
207   void startFractionNumerator();
208   void endFractionNumerator();
209   void startFractionDenominator();
210   void endFractionDenominator();
211   void startUnmath();
212   void endUnmath();
213   void startSuperscript();
214   void endSuperscript();
215   void startSubscript();
216   void endSubscript();
217   void startScriptSerial();
218   void endScriptSerial();
219   void startScriptPreSup();
220   void endScriptPreSup();
221   void startScriptPreSub();
222   void endScriptPreSub();
223   void startScriptPostSup();
224   void endScriptPostSup();
225   void startScriptPostSub();
226   void endScriptPostSub();
227   void startScriptMidSup();
228   void endScriptMidSup();
229   void startScriptMidSub();
230   void endScriptMidSub();
231   void startMarkSerial();
232   void endMarkSerial();
233   void startMarkOver();
234   void endMarkOver();
235   void startMarkUnder();
236   void endMarkUnder();
237   void startFenceSerial();
238   void endFenceSerial();
239   void startFenceOpen();
240   void endFenceOpen();
241   void startFenceClose();
242   void endFenceClose();
243   void startRadicalSerial();
244   void endRadicalSerial();
245   void startRadicalDegree();
246   void endRadicalDegree();
247   void startMathOperatorSerial();
248   void endMathOperatorSerial();
249   void startMathOperatorOperator();
250   void endMathOperatorOperator();
251   void startMathOperatorLowerLimit();
252   void endMathOperatorLowerLimit();
253   void startMathOperatorUpperLimit();
254   void endMathOperatorUpperLimit();
255   void startGrid(const GridNIC &);
256   void endGrid();
257   void startGridCell(const GridCellNIC &);
258   void endGridCell();
259   void startNode(const NodePtr &, const StringC &);
260   void endNode();
261   void startLink(const Address &);
262   void endLink();
263 
264 
265   //////////////////////////////////////////////////////////////////////
266   // Inherited characteristics
267   // Set the value of the characteristic for the next flow object.
268   // Inherited characteristics that are not explicitly set have
269   // the same value as the parent flow object.
270   //////////////////////////////////////////////////////////////////////
271 
272   void setFontSize(Length);
273   void setFontFamilyName(const StringC &);
274   void setFontWeight(Symbol);
275   void setFontPosture(Symbol);
276   void setStartIndent(const LengthSpec &);
277   void setEndIndent(const LengthSpec &);
278   void setFirstLineStartIndent(const LengthSpec &);
279   void setLastLineEndIndent(const LengthSpec &);
280   void setLineSpacing(const LengthSpec &);
281   void setFieldWidth(const LengthSpec &);
282   void setMarginaliaSep(const LengthSpec &);
283   void setLines(Symbol);
284   void setQuadding(Symbol);
285   void setDisplayAlignment(Symbol);
286   void setFieldAlign(Symbol);
287   void setColor(const DeviceRGBColor &);
288   void setBackgroundColor(); // background of #f
289   void setBackgroundColor(const DeviceRGBColor &);
290   void setBorderPresent(bool);
291   void setLineThickness(Length);
292   void setCellBeforeRowMargin(Length);
293   void setCellAfterRowMargin(Length);
294   void setCellBeforeColumnMargin(Length);
295   void setCellAfterColumnMargin(Length);
296   void setLineSep(Length);
297   void setBoxSizeBefore(Length);
298   void setBoxSizeAfter(Length);
299   void setPositionPointShift(const LengthSpec &);
300   void setStartMargin(const LengthSpec &);
301   void setEndMargin(const LengthSpec &);
302   void setSidelineSep(const LengthSpec &);
303   void setAsisWrapIndent(const LengthSpec &);
304   void setLineNumberSep(const LengthSpec &);
305   void setLastLineJustifyLimit(const LengthSpec &);
306   void setJustifyGlyphSpaceMaxAdd(const LengthSpec &);
307   void setJustifyGlyphSpaceMaxRemove(const LengthSpec &);
308   void setTableCornerRadius(const LengthSpec &);
309   void setBoxCornerRadius(const LengthSpec &);
310   void setInhibitLineBreaks(bool);
311   void setHyphenate(bool);
312   void setKern(bool);
313   void setLigature(bool);
314   void setScoreSpaces(bool);
315   void setFloatOutMarginalia(bool);
316   void setFloatOutSidelines(bool);
317   void setFloatOutLineNumbers(bool);
318   void setCellBackground(bool);
319   void setSpanWeak(bool);
320   void setIgnoreRecordEnd(bool);
321   void setNumberedLines(bool);
322   void setHangingPunct(bool);
323   void setBoxOpenEnd(bool);
324   void setTruncateLeader(bool);
325   void setAlignLeader(bool);
326   void setTablePartOmitMiddleHeader(bool);
327   void setTablePartOmitMiddleFooter(bool);
328   void setBorderOmitAtBreak(bool);
329   void setPrincipalModeSimultaneous(bool);
330   void setMarginaliaKeepWithPrevious(bool);
331   void setLineJoin(Symbol);
332   void setLineCap(Symbol);
333   void setLineNumberSide(Symbol);
334   void setKernMode(Symbol);
335   void setInputWhitespaceTreatment(Symbol);
336   void setFillingDirection(Symbol);
337   void setWritingMode(Symbol);
338   void setLastLineQuadding(Symbol);
339   void setMathDisplayMode(Symbol);
340   void setBoxType(Symbol);
341   void setGlyphAlignmentMode(Symbol);
342   void setBoxBorderAlignment(Symbol);
343   void setCellRowAlignment(Symbol);
344   void setBorderAlignment(Symbol);
345   void setSidelineSide(Symbol);
346   void setHyphenationKeep(Symbol);
347   void setFontStructure(Symbol);
348   void setFontProportionateWidth(Symbol);
349   void setCellCrossed(Symbol);
350   void setMarginaliaSide(Symbol);
351   void setLayer(long);
352   void setBackgroundLayer(long);
353   void setBorderPriority(long);
354   void setLineRepeat(long);
355   void setSpan(long);
356   void setMinLeaderRepeat(long);
357   void setHyphenationRemainCharCount(long);
358   void setHyphenationPushCharCount(long);
359   void setWidowCount(long);
360   void setOrphanCount(long);
361   // 0 means #f
362   void setExpandTabs(long);
363   void setHyphenationLadderCount(long);
364   // public id or #f
365   void setBackgroundTile(PublicId);
366   void setLineBreakingMethod(PublicId);
367   void setLineCompositionMethod(PublicId);
368   void setImplicitBidiMethod(PublicId);
369   void setGlyphSubstMethod(PublicId);
370   void setGlyphReorderMethod(PublicId);
371   void setHyphenationMethod(PublicId);
372   void setTableAutoWidthMethod(PublicId);
373   void setFontName(PublicId);
374   // Two-letter code
375   void setLanguage(Letter2);
376   void setCountry(Letter2);
377   // For simple page sequence
378   void setPageWidth(Length);
379   void setPageHeight(Length);
380   void setLeftMargin(Length);
381   void setRightMargin(Length);
382   void setTopMargin(Length);
383   void setBottomMargin(Length);
384   void setHeaderMargin(Length);
385   void setFooterMargin(Length);
386 
387   void setPageNumberRestart(bool);
388   void setPageNumberFormat(const StringC &);
389   void setPageNColumns(long);
390   void setPageColumnSep(Length);
391   void setPageBalanceColumns(bool);
392   void setPageTwoSide(bool);
393   void setTwoSideStartOnRight(bool);
394   void setGridRowSep(Length);
395   void setGridColumnSep(Length);
396   void setSubscriptDepth(Length);
397   void setSuperscriptHeight(Length);
398   void setUnderMarkDepth(Length);
399   void setOverMarkHeight(Length);
400   void setHeadingLevel(long);
401 
402   void setMinPreLineSpacing(const OptLengthSpec &);
403   void setMinPostLineSpacing(const OptLengthSpec &);
404   void setMinLeading(const OptLengthSpec &);
405   void setScriptPreAlign(Symbol);
406   void setScriptPostAlign(Symbol);
407   void setScriptMidSupAlign(Symbol);
408   void setScriptMidSubAlign(Symbol);
409   void setNumeratorAlign(Symbol);
410   void setDenominatorAlign(Symbol);
411   void setGridPositionCellType(Symbol);
412   void setGridColumnAlignment(Symbol);
413   void setGridRowAlignment(Symbol);
414   void setGridEquidistantRows(bool);
415   void setGridEquidistantColumns(bool);
416   void setEscapementSpaceBefore(const InlineSpace &);
417   void setEscapementSpaceAfter(const InlineSpace &);
418   void setInlineSpaceSpace(const OptInlineSpace &);
419   void setGlyphSubstTable(const Vector<ConstPtr<GlyphSubstTable> > &tables);
420 
startDisplay(const DisplayNIC &)421   void startDisplay( const DisplayNIC & ) {};
endDisplay()422   void endDisplay() {};
423 
424   enum FotObjectClassType { oc_Unknown, oc_Cell };
425 
426   enum { lengthUnspecified = LONG_MAX };
427 //  static const Length lengthUnspecified = LONG_MAX;
428 
429   struct Format {
430 
FormatDSSSL_NAMESPACE::TeXFOTBuilder::Format431     Format() : FotCurDisplaySize( 0 ),
432                FotLineThickness( 1000 ),
433                FotLineCap( symbolButt ),
434                FotBorderPriority( 0 ),
435                FotBorderPresent( true ),
436                FotLineRepeat( 1 ),
437                FotLines( symbolWrap ),
438                FotLineSep( 1000 ),
439                FotDisplayAlignment( symbolNotApplicable ),
440                FotCellRowAlignment( symbolNotApplicable ),
441                FotStartIndentSpec( 0 ),
442                FotEndIndentSpec( 0 ),
443                FotLeftMargin( 1 ),
444                FotRightMargin( 1 ),
445                FotPageWidth( 72000*8 ),
446                FotPageNColumns( 1 ),
447                FotPageColumnSep( 72000/2 ),
448                FotSpan( 1 ),
449                FotCellBeforeColumnMargin( lengthUnspecified ),
450                FotCellAfterColumnMargin( lengthUnspecified ),
451 	       FotCellBackground(false),
452                FotObjectClass( oc_Unknown ) {}
453 
454     long                 FotCurDisplaySize;
455     Length               FotLineThickness;
456     Symbol               FotLineCap;
457     long                 FotBorderPriority;
458     bool                 FotBorderPresent;
459     long                 FotLineRepeat;
460     Length               FotLineSep;
461     Symbol		 FotLines;
462     Symbol               FotDisplayAlignment;
463     Symbol               FotCellRowAlignment;
464     LengthSpec           FotStartIndentSpec;
465     LengthSpec           FotEndIndentSpec;
466     Length               FotLeftMargin;
467     Length               FotRightMargin;
468     Length               FotPageWidth;
469     long                 FotPageNColumns;
470     Length               FotPageColumnSep;
471     long                 FotSpan;
472     bool		 FotCellBackground;
473     DeviceRGBColor	 FotBackgroundColor;
474     Length               FotCellBeforeColumnMargin;
475     Length               FotCellAfterColumnMargin;
476     FotObjectClassType   FotObjectClass;
477 
INITIAL_PAGE_SIZEDSSSL_NAMESPACE::TeXFOTBuilder::Format478     static const Length INITIAL_PAGE_SIZE() { return 72000*8; }
479   };
480 
481   struct CompoundFotElement;
482   struct FotElement {
483 
FotElementDSSSL_NAMESPACE::TeXFOTBuilder::FotElement484     FotElement(  CompoundFotElement *parent = NULL )
485      : Parent( parent ), SiblingSeqIdx( -1 ) {}
486     String<char> Characteristics;
487 
outDSSSL_NAMESPACE::TeXFOTBuilder::FotElement488     virtual void out( OutputByteStream &stream ) const
489      { outProlog( stream ); outContent( stream ); outEpilog( stream ); }
490     virtual void open( TeXFOTBuilder &builder );
491     virtual void close( TeXFOTBuilder &builder );
492     virtual bool isAtomic() const = 0;
493     virtual const char *name() const = 0;
parentDSSSL_NAMESPACE::TeXFOTBuilder::FotElement494     CompoundFotElement *parent() const { return Parent; }
nodeInfoEpilogDSSSL_NAMESPACE::TeXFOTBuilder::FotElement495     String<char> &nodeInfoEpilog() { return NodeInfoEpilog; }
setParentDSSSL_NAMESPACE::TeXFOTBuilder::FotElement496     void setParent( CompoundFotElement *parent ) { Parent = parent; }
497     virtual FotElement *lastClosed_() = 0;
498     virtual FotElement *currentlyOpen_() = 0;
setSiblingSeqIdxDSSSL_NAMESPACE::TeXFOTBuilder::FotElement499     void setSiblingSeqIdx( int idx ) { SiblingSeqIdx = idx; }
siblingSeqIdxDSSSL_NAMESPACE::TeXFOTBuilder::FotElement500     int siblingSeqIdx() const { assert( SiblingSeqIdx > -1 ); return SiblingSeqIdx; }
501 
502    protected:
503     int SiblingSeqIdx;
504     CompoundFotElement* Parent;
505     String<char> NodeInfoProlog;
506     String<char> NodeInfoEpilog;
507 
outContentDSSSL_NAMESPACE::TeXFOTBuilder::FotElement508     virtual void outContent( OutputByteStream & ) const {};
509     virtual void outProlog( OutputByteStream &stream ) const = 0;
510     virtual void outEpilog( OutputByteStream &stream ) const = 0;
511   };
512 
513   struct FotElementState {
FotElementStateDSSSL_NAMESPACE::TeXFOTBuilder::FotElementState514     FotElementState() : EnforcingStructure( true ), IsOpen( false ) {}
enforcingStructureDSSSL_NAMESPACE::TeXFOTBuilder::FotElementState515     bool enforcingStructure() { return IsOpen && EnforcingStructure; }
516 
517     bool EnforcingStructure;
518     bool IsOpen;
519     String<char> CurNodeInfoProlog;
520   };
521 
522   struct AtomicFotElement : public FotElement {
523 
AtomicFotElementDSSSL_NAMESPACE::TeXFOTBuilder::AtomicFotElement524     AtomicFotElement( CompoundFotElement *parent = NULL ) : FotElement( parent ) {}
isAtomicDSSSL_NAMESPACE::TeXFOTBuilder::AtomicFotElement525     virtual bool isAtomic() const { return true; }
lastClosed_DSSSL_NAMESPACE::TeXFOTBuilder::AtomicFotElement526     virtual FotElement *lastClosed_() { return NULL; };
currentlyOpen_DSSSL_NAMESPACE::TeXFOTBuilder::AtomicFotElement527     virtual FotElement *currentlyOpen_() { return this; }
528 
529    protected:
outPrologDSSSL_NAMESPACE::TeXFOTBuilder::AtomicFotElement530     virtual void outProlog( OutputByteStream &stream ) const
531      { stream << NodeInfoProlog << "\\insert" << name() << "%\n{" << Characteristics << '}'; }
outEpilogDSSSL_NAMESPACE::TeXFOTBuilder::AtomicFotElement532     virtual void outEpilog( OutputByteStream &stream ) const
533      { stream << '}' << NodeInfoEpilog; }
534   };
535 
536   struct CompoundFotElement : public FotElement {
537 
CompoundFotElementDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement538     CompoundFotElement( CompoundFotElement *parent = NULL )
539      : FotElement( parent ), CurrentlyOpenChildIdx( -1 ),
540        LastClosedChildIdx( -1 ) {}
isAtomicDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement541     virtual bool isAtomic() const { return false; }
openDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement542     virtual void open( TeXFOTBuilder &builder )
543       { FotElement::open( builder ); builder.pushOs( &PreContent ); };
closeDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement544     virtual void close( TeXFOTBuilder &builder )
545       { builder.popOs(); FotElement::close( builder ); };
childJustClosedDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement546     virtual void childJustClosed( FotElement &child )
547      { CurrentlyOpenChildIdx = -1; LastClosedChildIdx = child.siblingSeqIdx(); };
childJustOpenedDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement548     virtual void childJustOpened( FotElement &child )
549      { CurrentlyOpenChildIdx = child.siblingSeqIdx(); };
550     virtual FotElement &child( size_t idx ) = 0;
lastClosedDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement551     static FotElement *lastClosed( CompoundFotElement &treeRoot )
552      { return treeRoot.currentlyOpen( treeRoot )
553         ? treeRoot.currentlyOpen( treeRoot )->lastClosed_() : (FotElement*)NULL; }
currentlyOpenDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement554     static FotElement *currentlyOpen( CompoundFotElement &treeRoot ) {
555       return treeRoot.currentlyOpen_();
556     }
currentlyOpen_DSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement557     virtual FotElement *currentlyOpen_()
558      { return CurrentlyOpenChildIdx > -1
559         ? child( (size_t)CurrentlyOpenChildIdx ).currentlyOpen_() : this; }
lastClosed_DSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement560     virtual FotElement *lastClosed_()
561      { return LastClosedChildIdx > -1
562         ? &child( (size_t)LastClosedChildIdx )
563         : ( parent() ? parent()->lastClosed_() : (FotElement*)NULL ); }
564 
565    protected:
outPrologDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement566     virtual void outProlog( OutputByteStream &stream ) const {
567       #ifdef TEXDEBUG
568        stream <<  "\nELEMENT\n" << "\nPRO\n" << NodeInfoProlog << "\nEND_PRO\n" << "\\" << name() << "%\n{" << Characteristics << '}';
569       #else
570        stream <<  NodeInfoProlog << "\\" << name() << "%\n{" << Characteristics << '}';
571       #endif
572 
573       PreContent.commit( stream );
574      }
outEpilogDSSSL_NAMESPACE::TeXFOTBuilder::CompoundFotElement575     virtual void outEpilog( OutputByteStream &stream ) const {
576       #ifdef TEXDEBUG
577         stream << "\\end" << name() << "{}" << "\nEPI\n" << NodeInfoEpilog << "\nEND_EPI\nEND_ELEMENT\n" ;
578       #else
579         stream << "\\end" << name() << "{}" << NodeInfoEpilog << "%\n" ;
580       #endif
581     }
582 
583     int CurrentlyOpenChildIdx;
584     int LastClosedChildIdx;
585     TeXTmpOutputByteStream PreContent;
586   };
587 
588   struct Border : public AtomicFotElement {
589 
BorderDSSSL_NAMESPACE::TeXFOTBuilder::Border590     Border( CompoundFotElement *parent = NULL, bool cellBorder_ = true )
591      : AtomicFotElement( parent ), cellBorder( cellBorder_ ), borderPresent( false ) {}
592     long   borderPriority;
593     Length lineThickness;
594     bool   borderPresent;
595     long   lineRepeat;
596     Length lineSep;
597     bool   cellBorder;
598 
599     void resolve( Border &adjacentBorder );
600     void setFromFot( TeXFOTBuilder &builder );
601   };
602 
603   struct CellBeforeRowBorder : public Border {
CellBeforeRowBorderDSSSL_NAMESPACE::TeXFOTBuilder::CellBeforeRowBorder604     CellBeforeRowBorder( CompoundFotElement *parent = NULL ) : Border( parent ) {}
nameDSSSL_NAMESPACE::TeXFOTBuilder::CellBeforeRowBorder605     virtual const char *name() const { return "TableCellBeforeRowBorder"; }
606   };
607   struct CellAfterRowBorder : public Border {
CellAfterRowBorderDSSSL_NAMESPACE::TeXFOTBuilder::CellAfterRowBorder608     CellAfterRowBorder( CompoundFotElement *parent = NULL ) : Border( parent ) {}
nameDSSSL_NAMESPACE::TeXFOTBuilder::CellAfterRowBorder609     virtual const char *name() const { return "TableCellAfterRowBorder"; }
610   };
611   struct CellBeforeColumnBorder : public Border {
CellBeforeColumnBorderDSSSL_NAMESPACE::TeXFOTBuilder::CellBeforeColumnBorder612     CellBeforeColumnBorder( CompoundFotElement *parent = NULL ) : Border( parent ) {}
nameDSSSL_NAMESPACE::TeXFOTBuilder::CellBeforeColumnBorder613     virtual const char *name() const { return "TableCellBeforeColumnBorder"; }
614   };
615   struct CellAfterColumnBorder : public Border {
CellAfterColumnBorderDSSSL_NAMESPACE::TeXFOTBuilder::CellAfterColumnBorder616     CellAfterColumnBorder( CompoundFotElement *parent = NULL ) : Border( parent ) {}
nameDSSSL_NAMESPACE::TeXFOTBuilder::CellAfterColumnBorder617     virtual const char *name() const { return "TableCellAfterColumnBorder"; }
618   };
619   struct TableBeforeRowBorder : public Border {
TableBeforeRowBorderDSSSL_NAMESPACE::TeXFOTBuilder::TableBeforeRowBorder620     TableBeforeRowBorder( CompoundFotElement *parent = NULL ) : Border( parent, false ) {}
nameDSSSL_NAMESPACE::TeXFOTBuilder::TableBeforeRowBorder621     virtual const char *name() const { return "TableBeforeRowBorder"; }
622   };
623   struct TableAfterRowBorder : public Border {
TableAfterRowBorderDSSSL_NAMESPACE::TeXFOTBuilder::TableAfterRowBorder624     TableAfterRowBorder( CompoundFotElement *parent = NULL ) : Border( parent, false ) {}
nameDSSSL_NAMESPACE::TeXFOTBuilder::TableAfterRowBorder625     virtual const char *name() const { return "TableAfterRowBorder"; }
626   };
627   struct TableBeforeColumnBorder : public Border {
TableBeforeColumnBorderDSSSL_NAMESPACE::TeXFOTBuilder::TableBeforeColumnBorder628     TableBeforeColumnBorder( CompoundFotElement *parent = NULL ) : Border( parent, false ) {}
nameDSSSL_NAMESPACE::TeXFOTBuilder::TableBeforeColumnBorder629     virtual const char *name() const { return "TableBeforeColumnBorder"; }
630   };
631   struct TableAfterColumnBorder : public Border {
TableAfterColumnBorderDSSSL_NAMESPACE::TeXFOTBuilder::TableAfterColumnBorder632     TableAfterColumnBorder( CompoundFotElement *parent = NULL ) : Border( parent, false ) {}
nameDSSSL_NAMESPACE::TeXFOTBuilder::TableAfterColumnBorder633     virtual const char *name() const { return "TableAfterColumnBorder"; }
634   };
635 
636   struct Column {
637 
ColumnDSSSL_NAMESPACE::TeXFOTBuilder::Column638     Column() : hasWidth( 0 ), computedWidth( 0 ), defaultTeXLeftBorder( 0 ),
639 	       defaultTeXRightBorder( 0 ), displayAlignment( symbolStart ),
640 	       isExplicit( false ), displaySize(0),
641 	       defaultCellBeforeColumnMargin( 0 ),
642 	       defaultCellAfterColumnMargin( 0 ) {}
643     bool isExplicit;
644     bool hasWidth;
645     TableLengthSpec width;
646     long computedWidth;
647     long displaySize;
648     Symbol displayAlignment;
649     int defaultTeXLeftBorder; // also used as column border count;
650     int defaultTeXRightBorder; //
651     bool defaultCellBackground;
652     Length defaultCellBeforeColumnMargin;
653     Length defaultCellAfterColumnMargin;
654   };
655 
656   struct TablePart;
657   struct Cell : public CompoundFotElement {
658 
CellDSSSL_NAMESPACE::TeXFOTBuilder::Cell659     Cell( CompoundFotElement *parent = NULL )
660      : CompoundFotElement( parent ), missing( false ), OverlappingCell( NULL ),
661        nRowsSpanned( 1 ), nColumnsSpanned( 1 ), displaySize( 0 ),
662        beforeRowBorder(), afterRowBorder(), beforeColumnBorder(),
663        afterColumnBorder(), TeXTableRowIdx( -1 ), TeXTableColumnIdx(-1),
664        needsTeXColumnOverride(false),
665        beforeColumnMargin( lengthUnspecified ),
666        effectiveBeforeColumnMargin( lengthUnspecified ),
667        afterColumnMargin( lengthUnspecified ),
668        effectiveAfterColumnMargin( lengthUnspecified ),
669        effectiveAlignment( symbolStart ),
670        rowAlignment( symbolNotApplicable ),
671        cellBackground(false) {}
672 
673     bool missing;
674     int TeXTableRowIdx;
675     int TeXTableColumnIdx;
676     unsigned nColumnsSpanned;
677     unsigned nRowsSpanned;
678     CellBeforeRowBorder beforeRowBorder;
679     CellAfterRowBorder afterRowBorder;
680     CellBeforeColumnBorder beforeColumnBorder;
681     CellAfterColumnBorder afterColumnBorder;
682     bool needsTeXColumnOverride;
683     Length beforeColumnMargin;
684     Length effectiveBeforeColumnMargin;
685     Length afterColumnMargin;
686     Length effectiveAfterColumnMargin;
687     Symbol rowAlignment;
688     Symbol effectiveAlignment;
689     long displaySize;
690     bool cellBackground;
691     DeviceRGBColor backgroundColor;
692 
693     Cell *OverlappingCell;
contentDSSSL_NAMESPACE::TeXFOTBuilder::Cell694     OutputByteStream &content() { return Content; }
openDSSSL_NAMESPACE::TeXFOTBuilder::Cell695     virtual void open( TeXFOTBuilder &builder )
696      { builder.pushFotElementState();
697        CompoundFotElement::open( builder );
698        builder.pushOs( &Content );
699        builder.curFotElementState().EnforcingStructure = false; }
closeDSSSL_NAMESPACE::TeXFOTBuilder::Cell700     virtual void close( TeXFOTBuilder &builder )
701      { builder.popOs();
702        CompoundFotElement::close( builder );
703        builder.popFotElementState(); }
nameDSSSL_NAMESPACE::TeXFOTBuilder::Cell704     virtual const char *name() const { return "TableCell"; }
705     bool singleRowBeforeRowBorderPresent() const;
706     bool singleRowAfterRowBorderPresent() const;
707     bool singleColumnBeforeColumnBorderPresent() const;
708     bool singleColumnAfterColumnBorderPresent() const;
709     void computeOverridingTeXColumnBorders( TablePart &tablePart );
710     void computeEffectiveTeXCellWidth( TablePart &tablePart );
711     void computeEffectiveTeXColumnMargins( TablePart &tablePart );
712     void computeTeXRowSpanFiller( TablePart &tablePart );
713 
isOverlappedDSSSL_NAMESPACE::TeXFOTBuilder::Cell714     bool isOverlapped() const { return OverlappingCell == this ? false : true; }
childDSSSL_NAMESPACE::TeXFOTBuilder::Cell715     virtual FotElement &child( size_t ) { assert( false ); return *this; }
716 
717    protected:
718     virtual void outProlog( OutputByteStream &stream ) const;
719     virtual void outEpilog( OutputByteStream &stream ) const;
outContentDSSSL_NAMESPACE::TeXFOTBuilder::Cell720     void outContent( OutputByteStream &stream ) const
721       { if ( !isOverlapped() ) Content.commit( stream ); }
722     TeXTmpOutputByteStream Content;
723   };
724 
725   struct Row : public CompoundFotElement {
726 
RowDSSSL_NAMESPACE::TeXFOTBuilder::Row727     Row( CompoundFotElement *parent = NULL ) : CompoundFotElement( parent ) {}
nameDSSSL_NAMESPACE::TeXFOTBuilder::Row728     virtual const char *name() const { return "TableRow"; }
729     Vector<Cell> Cells;
730     static void outVerticalBorders
731       ( const Row *upperRow, const Row *lowerRow, OutputByteStream &stream );
childDSSSL_NAMESPACE::TeXFOTBuilder::Row732     virtual FotElement &child( size_t idx )
733      { assert( idx < Cells.size() ); return Cells[idx]; }
734 
735    protected:
736     void outContent( OutputByteStream &stream ) const;
737   };
738 
739   struct Table;
740   struct TablePart : public CompoundFotElement {
741 
TablePartDSSSL_NAMESPACE::TeXFOTBuilder::TablePart742     TablePart( CompoundFotElement *parent = NULL )
743      : CompoundFotElement( parent ), columnsProcessed( false ),
744        needsColumnReprocessing( false ), isExplicit( true ) {}
745 
746     bool isExplicit;
747 
748     Vector<Column> Columns;
749     String<char> HeaderProlog;
750     Vector<Row> Header;
751     String<char> HeaderEpilog;
752     Vector<Row> Body;
753     String<char> FooterProlog;
754     Vector<Row> Footer;
755     String<char> FooterEpilog;
756 
757     void processColumns( TeXFOTBuilder &builder );
758     void computeOverridingTeXCharacteristics();
759     void normalizeRows();
760     void begin();
761 
parentTableDSSSL_NAMESPACE::TeXFOTBuilder::TablePart762     Table &parentTable() const
763      { assert( Parent != NULL ); return *(Table*)Parent; }
nameDSSSL_NAMESPACE::TeXFOTBuilder::TablePart764     virtual const char *name() const { return "TablePart"; }
765     virtual FotElement &child( size_t idx );
766 
767     bool columnsProcessed;
768     bool needsColumnReprocessing;
769 
770    protected:
outPrologDSSSL_NAMESPACE::TeXFOTBuilder::TablePart771     virtual void outProlog( OutputByteStream &stream ) const
772      { if( isExplicit ) CompoundFotElement::outProlog( stream ); }
outEpilogDSSSL_NAMESPACE::TeXFOTBuilder::TablePart773     virtual void outEpilog( OutputByteStream &stream ) const
774      { if( isExplicit ) CompoundFotElement::outEpilog( stream ); }
775     Row &siblingSeqIdxToRow( int idx ) const;
776     void outContent( OutputByteStream &stream ) const;
777   };
778 
779   struct Table : public CompoundFotElement {
780 
TableDSSSL_NAMESPACE::TeXFOTBuilder::Table781     Table(  CompoundFotElement *parent = NULL )
782      : CompoundFotElement( parent ), beforeRowBorder(), afterRowBorder(),
783        beforeColumnBorder(), afterColumnBorder(), CurCell( NULL ),
784        displayAlignment( symbolStart ), CurTablePart( NULL ),
785        NoTablePartsSeen( true ) {}
786 
787     Vector<TablePart> TableParts;
788 
789     TableBeforeRowBorder beforeRowBorder;
790     TableAfterRowBorder afterRowBorder;
791     TableBeforeColumnBorder beforeColumnBorder;
792     TableAfterColumnBorder afterColumnBorder;
793     Length tableWidth;
794     Symbol displayAlignment;
795     Length startIndent;
796 
nameDSSSL_NAMESPACE::TeXFOTBuilder::Table797     virtual const char *name() const { return "Table"; }
childDSSSL_NAMESPACE::TeXFOTBuilder::Table798     virtual FotElement &child( size_t idx )
799      { assert( idx < TableParts.size() ); return TableParts[idx]; }
800     void resolveBorders( Vector<Row> *preceedingRows,
801                          Vector<Row> &rows,
802                          Vector<Row> *followingRows,
803                          unsigned startingRowIdx,
804                          bool hasFirstTableRow, bool hasLastTableRow );
805     void begin();
openDSSSL_NAMESPACE::TeXFOTBuilder::Table806     virtual void open( TeXFOTBuilder &builder )
807      { builder.pushFotElementState();
808        CompoundFotElement::open( builder );
809        builder.curFotElementState().EnforcingStructure = true; }
closeDSSSL_NAMESPACE::TeXFOTBuilder::Table810     virtual void close( TeXFOTBuilder &builder )
811      { CompoundFotElement::close( builder );
812        builder.popFotElementState(); }
813     void end( TeXFOTBuilder &builder );
814 
curRowsDSSSL_NAMESPACE::TeXFOTBuilder::Table815     Vector<Row> &curRows() { assert( CurRows != NULL ); return *CurRows; }
curTablePartDSSSL_NAMESPACE::TeXFOTBuilder::Table816     TablePart &curTablePart() { assert( CurTablePart != NULL ); return *CurTablePart; }
curCellDSSSL_NAMESPACE::TeXFOTBuilder::Table817     Cell &curCell() { assert( CurCell != NULL ); return *CurCell; }
818 
819     TablePart *CurTablePart;
820     Cell *CurCell;
821     Vector<Row> *CurRows;
822 
823     bool NoTablePartsSeen;
824 
825   protected:
826     void outContent( OutputByteStream &stream ) const;
827   };
828 
829   long computeLengthSpec( const LengthSpec &spec ) const;
curFormat() const830   const Format &curFormat() const { assert( FormatStack.size() > 0 ); return FormatStack.back(); }
curTable()831   Table &curTable() { assert( TableStack.size() > 0 );
832 		      return TableStack.back(); }
curFotElementState()833   FotElementState &curFotElementState()
834     { assert( FotElementStateStack_.size() > 0 );
835       return FotElementStateStack_.back(); }
pushFotElementState()836   void pushFotElementState()
837     { FotElementStateStack_.resize(FotElementStateStack_.size() + 1 ); }
popFotElementState()838   void popFotElementState()
839     { assert( FotElementStateStack_.size() > 0 );
840       FotElementStateStack_.resize(FotElementStateStack_.size() - 1 ); }
841 
842   void pushOs( OutputByteStream *to );
843   void popOs();
844 
845   void elementStart( FotObjectClassType objectClassType );
846 
847   OutputByteStream *fileout_;
848 private:
849 				// Variables.
850   Vector<OutputByteStream *> osStack_;
851   StrOutputByteStream stringout_;
852   Messenger *mgr_;
853   bool preserveSdata_;
854   int inMath_;
855 
856 #ifdef OUTLINES
needToCollect()857   int needToCollect() {return inHeading_;}
858 
859   void addHeadedText(const Char * s, size_t n);
860   void addHeadedText(const StringC p);
861 
862   struct ParHead {
ParHeadDSSSL_NAMESPACE::TeXFOTBuilder::ParHead863     ParHead() : isHeaded_(false),level_(0),previous_(0){}
ParHeadDSSSL_NAMESPACE::TeXFOTBuilder::ParHead864     ParHead(bool h): isHeaded_(h),level_(0),previous_(0){}
ParHeadDSSSL_NAMESPACE::TeXFOTBuilder::ParHead865     ParHead(bool h,long l) : isHeaded_(h),level_(l),previous_(0){}
866 
867     bool isHeaded_;
868     long level_;
869     StringC  headingText_;
870     size_t previous_;
871   };
872 
873   StringC protectedChar_; //for special tex Chars
874 
875   bool headingSet_;
876   bool inHeading_;
877   StringC return_;
878   Vector<ParHead> parStack_;
879   size_t  lastHeaded_;
880 #endif
881   Vector<size_t> DisplayBoxLevels;
882   Vector<Format> FormatStack;
883 
884   Format NextFormat;
885   Vector<Table> TableStack;
886   Vector<FotElementState> FotElementStateStack_;
887 
888 				// Functions.
889   OutputByteStream &os();
890   void insertAtomic(const char *name);
891   void insertAtomic(FotElement &fotElement);
892   void startGroup(FotElement &fotElement);
893   void startGroup(const char *name, String<char> *output = NULL );
894   void endGroup(const char *name, String<char> *output = NULL );
895   void closeopenBrace(const char *name, String<char> *output = NULL );
896   void startBrace(const char *name, String<char> *output = NULL );
897   void endBrace(const char *name, String<char> *output = NULL );
898   void startSimpleGroup(const char *name, String<char> *output = NULL );
899   void endSimpleGroup(String<char> *output = NULL);
endGroup()900   void endGroup() {};
901 
902   void setlength(const char *,Length);
903   void set(const char *,const StringC &);
904   void set(const char *,const GroveString &);
905   void set(const char *,Symbol);
906   void set(const char *,const LengthSpec &);
907   void set(const char *,double);
908   void set(const char *,const DeviceRGBColor &);
909   void set(const char *,bool);
910   void set(const char *,long);
911   void set(const char *,long unsigned int);
set(const char * name,unsigned int n)912   void set(const char *name,unsigned int n) {
913     set(name, (unsigned long)n);
914   }
915   void set(const char *,PublicId);
916   void setletter2(const char *,Letter2);
917   void set(const char *,const DisplaySpace &);
918   void set(const char *,const GlyphId &);
919 
920   void set(const char *,const OptLengthSpec &);
921   void set(const char *,const InlineSpace &);
922   void set(const char *,const OptInlineSpace &);
923 
924   // Structures for non-inherited characteristics,
925   // in the order specified in style/FOTBuilder.h.
926 
927   void setDisplayNIC(const DisplayNIC &);
928   void setInlineNIC(const InlineNIC &);
929   void setDisplayGroupNIC(const DisplayGroupNIC &);
930   void setExternalGraphicNIC(const ExternalGraphicNIC &);
931   void setBoxNIC(const BoxNIC &);
932   void setRuleNIC(const RuleNIC &);
933   void setLeaderNIC(const LeaderNIC &);
934   void setParagraphNIC(const ParagraphNIC &);
935   void setCharacterNIC(const CharacterNIC &);
936   void setLineFieldNIC(const LineFieldNIC &);
937   void setTableNIC(const TableNIC &);
938   void setTablePartNIC(const TablePartNIC &);
939   void setTableColumnNIC(const TableColumnNIC &);
940   void setTableCellNIC(const TableCellNIC &);
941   void setGridNIC(const GridNIC &);
942   void setGridCellNIC(const GridCellNIC &);
943 
944   void dumpInherited();
945 
946   void message(const MessageType0 &);
947   static ParHead& top(Vector<ParHead>& s);
948   static ParHead* ptrTop(Vector<ParHead>& s);
949   static void pop(Vector<ParHead>& s);
950   static void push(Vector<ParHead>& s, ParHead p);
951 };
952 
953 #ifdef OUTLINES
954 // Stack Utilities
955 
956 TeXFOTBuilder::ParHead&
top(Vector<TeXFOTBuilder::ParHead> & s)957 TeXFOTBuilder::top (Vector<TeXFOTBuilder::ParHead> &s) {
958   //cerr << "top" <<s.back().level_<<'\n';
959   return s.back();
960 }
961 
962 TeXFOTBuilder::ParHead*
ptrTop(Vector<TeXFOTBuilder::ParHead> & s)963 TeXFOTBuilder::ptrTop (Vector<TeXFOTBuilder::ParHead> &s) {
964   //cerr << "top" <<s.back().level_<<'\n';
965   return &(s.back());
966 }
967 
968 void
pop(Vector<TeXFOTBuilder::ParHead> & s)969 TeXFOTBuilder::pop(Vector<TeXFOTBuilder::ParHead> &s){
970   //cerr << "popping" <<'\n';
971   s.resize(s.size() - 1);
972 }
973 
974 void
push(Vector<TeXFOTBuilder::ParHead> & s,TeXFOTBuilder::ParHead p)975 TeXFOTBuilder::push(Vector<TeXFOTBuilder::ParHead> &s,TeXFOTBuilder::ParHead p ){
976   //cerr << "pushing" <<p.level_<<'\n';
977   s.push_back(p);
978 }
979 
addHeadedText(const Char * s,size_t n)980 void TeXFOTBuilder::addHeadedText(const Char * s, size_t n){
981   if (top(parStack_).isHeaded_){
982     top(parStack_).headingText_.append(s,n);
983   }
984   else{
985     assert(((top(parStack_).previous_)) >= 0);
986     parStack_[top(parStack_).previous_].headingText_.append(s,n);
987   }
988 }
989 
addHeadedText(const StringC p)990 void TeXFOTBuilder::addHeadedText(const  StringC p){
991   if (top(parStack_).isHeaded_){
992     top(parStack_).headingText_ += p;
993   }
994   else{
995     assert(((top(parStack_).previous_)) >= 0);
996     parStack_[top(parStack_).previous_].headingText_ += p;
997   }
998 }
999 #endif
1000 
1001 #ifdef TEXDEBUG
1002   TeXFOTBuilder *TeXFOTBuilder::CurInstance = NULL;
1003 #endif
1004 
1005 // --------- OutputByteStream operators --------------------------------------
1006 
operator <<(OutputByteStream & os,LengthInPoints length)1007 OutputByteStream &operator<<( OutputByteStream &os, LengthInPoints length ) {
1008 
1009   char buf[32];
1010   int i;
1011   sprintf( buf, "%li.%.3i%n", long(length.l)/1000, abs(long(length.l)%1000), &i );
1012   while( buf[--i] == '0' ) {}; if( buf[i] == '.' ) i--;
1013     buf[i+1] = '\0';
1014   os << buf << "\\p@";
1015   return os;
1016 }
1017 
1018 // --------- TeXFOTBuilder::FotElement ---------------------------------------
1019 
open(TeXFOTBuilder & builder)1020 void TeXFOTBuilder::FotElement::open( TeXFOTBuilder &builder ) {
1021   builder.curFotElementState().IsOpen = true;
1022   if( parent() )
1023     parent()->childJustOpened( *this );
1024 
1025   if( builder.curFotElementState().CurNodeInfoProlog.size() > 0 ) {
1026     NodeInfoProlog = builder.curFotElementState().CurNodeInfoProlog;
1027     builder.curFotElementState().CurNodeInfoProlog.resize( 0 );
1028   }
1029 }
1030 
close(TeXFOTBuilder & builder)1031 void TeXFOTBuilder::FotElement::close( TeXFOTBuilder &builder ) {
1032   if( parent() )
1033     parent()->childJustClosed( *this );
1034   else
1035     builder.curFotElementState().IsOpen = false;
1036 }
1037 
lastClosed_()1038 TeXFOTBuilder::FotElement *TeXFOTBuilder::FotElement::lastClosed_() {
1039 
1040   return parent() ? parent()->lastClosed_() : (FotElement*)NULL;
1041 }
1042 
1043 // --------- TeXFOTBuilder Standard Display/Element Handling -----------------
1044 
elementStart(FotObjectClassType objectClassType)1045 void TeXFOTBuilder::elementStart( FotObjectClassType objectClassType ) {
1046   NextFormat.FotObjectClass = objectClassType;
1047   FormatStack.push_back( NextFormat );
1048 }
1049 
start()1050 void TeXFOTBuilder::start() {
1051   NextFormat.FotObjectClass = oc_Unknown;
1052   FormatStack.push_back( NextFormat );
1053 }
1054 
end()1055 void TeXFOTBuilder::end() {
1056   assert( FormatStack.size() > 0 );
1057   FormatStack.resize( FormatStack.size()-1 );
1058 
1059   assert( FormatStack.size() > 0 );
1060   NextFormat = FormatStack.back();
1061 }
1062 
1063 // --------- TeXFOTBuilder Misc ----------------------------------------------
1064 
computeLengthSpec(const LengthSpec & spec) const1065 long TeXFOTBuilder::computeLengthSpec( const LengthSpec &spec ) const {
1066 
1067     if( spec.displaySizeFactor == 0.0 ) {
1068         return spec.length;
1069     } else {
1070         double tem = curFormat().FotCurDisplaySize * spec.displaySizeFactor;
1071         return spec.length + long( tem >= 0.0 ? tem +.5 : tem - .5 );
1072     }
1073 }
1074 
1075 // --------- TeXFOTBuilder::Table ---------------------------------------------
1076 
resolveBorders(Vector<Row> * preceedingRows,Vector<Row> & rows,Vector<Row> *,unsigned startingRowIdx,bool hasFirstTableRow,bool hasLastTableRow)1077 void TeXFOTBuilder::Table::resolveBorders
1078  ( Vector<Row> *preceedingRows, Vector<Row> &rows,
1079    Vector<Row> *, unsigned startingRowIdx, bool hasFirstTableRow,
1080    bool hasLastTableRow ) {
1081 
1082     bool isFirstRow;
1083     bool isLastRow;
1084     bool isFirstColumn;
1085     bool isLastColumn;
1086     Cell *cell = NULL;
1087     size_t r, c, rr, cc;
1088     bool leftEdge, topEdge;
1089 
1090     #ifdef TEXDEBUG
1091       *TeXFOTBuilder::curInstance().fileout_ << "RESOLVING_BORDERS\n";
1092     #endif
1093 
1094     for( r = 0; r < rows.size(); r++ ) {
1095       for( c = 0; c < rows[r].Cells.size()-1; c++ ) {
1096         cell = &rows[r].Cells[c];
1097         if( cell->OverlappingCell == NULL ) {
1098           for( rr = r; rr < r + cell->nRowsSpanned; rr++ ) {
1099             for( cc = c, leftEdge = true; cc < c + cell->nColumnsSpanned; cc++ ) {
1100               rows[rr].Cells[cc].OverlappingCell = cell;
1101               rows[rr].Cells[cc].TeXTableRowIdx = rr + startingRowIdx;
1102               rows[rr].Cells[cc].TeXTableColumnIdx = cc;
1103             }
1104           }
1105         }
1106       }
1107     }
1108 
1109     for( r = 0; r < rows.size(); r++ ) {
1110         #ifdef TEXDEBUG
1111           *TeXFOTBuilder::curInstance().fileout_ << "ROW " << r << "\n";
1112         #endif
1113         for( c = 0; c < rows[r].Cells.size() - 1; c++ ) {
1114             #ifdef TEXDEBUG
1115               *TeXFOTBuilder::curInstance().fileout_ << "    COL " << c << "\n";
1116             #endif
1117             cell = &rows[r].Cells[c];
1118             if( cell->OverlappingCell == cell ) {
1119                 for( rr = r, topEdge = true; rr < r + cell->nRowsSpanned; rr++ ) {
1120                     isFirstRow = ( rr == 0 ) ? true : false;
1121                     isLastRow = ( rr == rows.size() - 1 ) ? true : false;
1122                     for( cc = c, leftEdge = true; cc < c + cell->nColumnsSpanned; cc++ ) {
1123                         isFirstColumn = ( cc == 0 ) ? true : false;
1124                         isLastColumn = ( cc == rows[rr].Cells.size() - 2 ) ? true : false;
1125 
1126                         if( leftEdge )
1127                             if( isFirstColumn ) {
1128                                 #ifdef TEXDEBUG
1129                                   *TeXFOTBuilder::curInstance().fileout_
1130                                    << "LEFT_TABLE_BORDER_RES \n";
1131                                 #endif
1132                                 cell->beforeColumnBorder.resolve( beforeColumnBorder );
1133                             } else
1134                                 cell->beforeColumnBorder.resolve
1135                                  ( rows[rr].Cells[cc-1].OverlappingCell->afterColumnBorder );
1136 
1137                         if( topEdge )
1138                             if( isFirstRow && hasFirstTableRow )
1139                                 cell->beforeRowBorder.resolve( beforeRowBorder );
1140                             else
1141                                 if( !isFirstRow )
1142                                     cell->beforeRowBorder.resolve
1143                                      ( rows[rr-1].Cells[cc].OverlappingCell->afterRowBorder );
1144                                 else if( preceedingRows != NULL ) {
1145                                     assert( preceedingRows->size() > 0 );
1146                                     cell->beforeRowBorder.resolve
1147                                      ( (*preceedingRows)[preceedingRows->size()-1].Cells[cc]
1148                                         .OverlappingCell->afterRowBorder );
1149                                 }
1150 
1151                         if( isLastColumn )
1152                             cell->afterColumnBorder.resolve( afterColumnBorder );
1153 
1154                         if( isLastRow && hasLastTableRow )
1155                             cell->afterRowBorder.resolve( afterRowBorder );
1156 
1157                         leftEdge = false;
1158                     }
1159                     topEdge = false;
1160                 }
1161             }
1162         }
1163     }
1164 }
1165 
begin()1166 void TeXFOTBuilder::Table::begin() {
1167 
1168     CurCell = NULL;
1169     NoTablePartsSeen = true;
1170 
1171     TableParts.resize( 0 );
1172     TableParts.resize( 1 );
1173     TableParts.back().setSiblingSeqIdx( 0 );
1174     TableParts.back().setParent( this );
1175     TableParts.back().begin();
1176 }
1177 
end(TeXFOTBuilder & builder)1178 void TeXFOTBuilder::Table::end( TeXFOTBuilder &builder ) {
1179 
1180   bool firstPart, lastPart, hasHeader, hasBody, hasFooter;
1181   for( size_t i = 0; i < TableParts.size(); i++ ) {
1182       firstPart = ( i == 0 ) ? true : false;
1183       lastPart = ( i == TableParts.size() - 1 ) ? true : false;
1184       TablePart &tablePart = TableParts[i];
1185       tablePart.normalizeRows();
1186       hasHeader = tablePart.Header.size() > 0 ? true : false;
1187       hasBody = tablePart.Body.size() > 0 ? true : false;
1188       hasFooter = tablePart.Footer.size() > 0 ? true : false;
1189       if( hasHeader )
1190           resolveBorders( (Vector<Row>*)NULL,
1191                           tablePart.Header,
1192                           hasBody ? &tablePart.Body : (Vector<Row>*)NULL,
1193                           0, firstPart ? true : false, false );
1194       resolveBorders( hasHeader ? &tablePart.Header : (Vector<Row>*)NULL,
1195                       tablePart.Body,
1196                       hasFooter ? &tablePart.Footer : (Vector<Row>*)NULL,
1197                       tablePart.Header.size(), hasHeader ? false : true,
1198                       hasFooter ? false : true );
1199       if( hasFooter )
1200           resolveBorders( hasBody ? &tablePart.Body : (Vector<Row>*)NULL,
1201                           tablePart.Footer,
1202                           (Vector<Row>*)NULL,
1203                           tablePart.Header.size() + tablePart.Body.size(),
1204                           false, lastPart ? true : false );
1205 
1206       if( tablePart.needsColumnReprocessing )
1207         tablePart.processColumns( builder );
1208 
1209       tablePart.computeOverridingTeXCharacteristics();
1210   }
1211 }
1212 
outContent(OutputByteStream & stream) const1213 void TeXFOTBuilder::Table::outContent( OutputByteStream &stream ) const {
1214 
1215   for( size_t i = 0; i < TableParts.size(); i++ )
1216       TableParts[i].out( stream );
1217 };
1218 
1219 // --------- TeXFOTBuilder::TablePart -----------------------------------------
1220 
begin()1221 void TeXFOTBuilder::TablePart::begin() {
1222 
1223     Columns.resize( 0 );
1224     Header.resize( 0 );
1225     Body.resize( 0 );
1226     Footer.resize( 0 );
1227 
1228     columnsProcessed = false;
1229     needsColumnReprocessing = false;
1230 
1231     parentTable().CurRows = &Body;
1232     parentTable().CurTablePart = this;
1233 }
1234 
child(size_t idx)1235 TeXFOTBuilder::FotElement &TeXFOTBuilder::TablePart::child( size_t idx ) {
1236 
1237   if( idx < Header.size() )
1238     return Header[idx];
1239 
1240   idx -= Header.size();
1241   if( idx < Body.size() )
1242     return Body[idx];
1243 
1244   assert( idx < Footer.size() );
1245   idx -= Body.size();
1246   return Footer[idx];
1247 }
1248 
computeOverridingTeXCharacteristics()1249 void TeXFOTBuilder::TablePart::computeOverridingTeXCharacteristics() {
1250 
1251   Vector<Row> *rows;
1252   for( int step = 0; step < 3; step++ ) {
1253     switch( step ) {
1254       case 0: rows = &Header; break;
1255       case 1: rows = &Body; break;
1256       default: rows = &Footer;
1257     }
1258     for( size_t r = 0; r < rows->size(); r++ ) {
1259       if( (*rows)[r].Cells.size()-1 > Columns.size() )
1260         Columns.resize( (*rows)[r].Cells.size()-1 );
1261       for( size_t c = 0; c < (*rows)[r].Cells.size()-1; c++ ) {
1262         if( (*rows)[r].Cells[c].singleColumnBeforeColumnBorderPresent() )
1263           Columns[c].defaultTeXLeftBorder++;
1264         if( (*rows)[r].Cells[c].singleColumnAfterColumnBorderPresent() )
1265           Columns[c].defaultTeXRightBorder++;
1266       }
1267     }
1268   }
1269 
1270   #ifdef TEXDEBUG
1271     for( int step = 0; step < 3; step++ ) {
1272       switch( step ) {
1273         case 0: rows = &Header; break;
1274         case 1: rows = &Body; break;
1275         default: rows = &Footer;
1276       }
1277       for( size_t r = 0; r < rows->size(); r++ ) {
1278         *TeXFOTBuilder::curInstance().fileout_
1279          << "\nROW " << ( step == 0 ? "Header" : ( step == 1 ? "Body" : "Footer" ) ) << "\n";
1280         for( size_t c = 0; c < (*rows)[r].Cells.size()-1; c++ ) {
1281           *TeXFOTBuilder::curInstance().fileout_
1282            << "\n    CELL " << c
1283            << " LB: " << (*rows)[r].Cells[c].beforeColumnBorder.borderPresent
1284            << " RB: " << (*rows)[r].Cells[c].beforeColumnBorder.borderPresent
1285            << " OVERLAPPED: "
1286            << ( (*rows)[r].Cells[c].isOverlapped() ? "YES" : "NO" ) << "\n";
1287         }
1288       }
1289     }
1290   #endif
1291 
1292   size_t TeXTableRowsNum = Header.size() + Body.size() + Footer.size();
1293   for( size_t c = 0; c < Columns.size(); c++ ) {
1294     Columns[c].defaultTeXLeftBorder
1295      = ((size_t)Columns[c].defaultTeXLeftBorder)*2 >= TeXTableRowsNum ? 1 : 0;
1296     Columns[c].defaultTeXRightBorder
1297       = ((size_t)Columns[c].defaultTeXRightBorder)*2 >= TeXTableRowsNum ? 1 : 0;
1298   }
1299 
1300   for( int step = 0; step < 3; step++ ) {
1301     switch( step ) {
1302       case 0: rows = &Header; break;
1303       case 1: rows = &Body; break;
1304       default: rows = &Footer;
1305     }
1306     for( size_t r = 0; r < rows->size(); r++ ) {
1307       for( size_t c = 0; c < (*rows)[r].Cells.size()-1; c++ ) {
1308         if( !(*rows)[r].Cells[c].isOverlapped() ) {
1309           (*rows)[r].Cells[c].computeOverridingTeXColumnBorders( *this );
1310         } else {
1311 	  (*rows)[r].Cells[c].computeTeXRowSpanFiller( *this );
1312 	}
1313       }
1314     }
1315   }
1316 }
1317 
processColumns(TeXFOTBuilder & builder)1318 void TeXFOTBuilder::TablePart::processColumns( TeXFOTBuilder &builder ) {
1319 
1320   long totalNonproportionalWidth = 0L;
1321   double totalProportionalUnits = 0.0;
1322   size_t nonWidthCellsNum = 0;
1323   for( size_t i = 0; i < Columns.size(); i++ ) {
1324     if( Columns[i].hasWidth ) {
1325       if( Columns[i].width.tableUnitFactor ) {
1326         totalProportionalUnits += Columns[i].width.tableUnitFactor;
1327       } else {
1328         Columns[i].computedWidth = builder.computeLengthSpec( Columns[i].width );
1329         totalNonproportionalWidth += Columns[i].computedWidth;
1330       }
1331     } else
1332       nonWidthCellsNum++;
1333   }
1334 
1335   if( totalProportionalUnits > 0 )
1336     totalProportionalUnits += nonWidthCellsNum;
1337   // cannot predict width of some cells, but their width is needed to
1338   // compute widths of proportional cells - force non-with cells to be 1 table-unit
1339 
1340   double proportionalUnit = 0.0;
1341   if( totalProportionalUnits )
1342       proportionalUnit
1343        = ( parentTable().tableWidth - totalNonproportionalWidth ) / totalProportionalUnits;
1344 
1345   for( size_t i = 0; i < Columns.size(); i++ ) {
1346       if( Columns[i].hasWidth ) {
1347           if( Columns[i].width.tableUnitFactor )
1348               Columns[i].computedWidth
1349                = long(proportionalUnit * Columns[i].width.tableUnitFactor);
1350       } else if( totalProportionalUnits > 0 )
1351           Columns[i].computedWidth = long(proportionalUnit);
1352   }
1353 
1354   // Compute display size of the column
1355   for( size_t i = 0; i < Columns.size(); i++ ) {
1356     if (Columns[i].computedWidth > 0) {
1357       Columns[i].displaySize = Columns[i].computedWidth;
1358       if (Columns[i].defaultCellBeforeColumnMargin != lengthUnspecified)
1359 	Columns[i].displaySize -= Columns[i].defaultCellBeforeColumnMargin;
1360 
1361       if (Columns[i].defaultCellAfterColumnMargin != lengthUnspecified)
1362 	Columns[i].displaySize -= Columns[i].defaultCellAfterColumnMargin;
1363     }
1364   }
1365 
1366   columnsProcessed = true;
1367 }
1368 
outContent(OutputByteStream & stream) const1369 void TeXFOTBuilder::TablePart::outContent( OutputByteStream &stream ) const {
1370 
1371   stream << "\\TeXTable%\n{" << LengthInPoints( parentTable().tableWidth )
1372          << "}{" << Columns.size() << "}{";
1373 
1374   for( size_t i = 0; i < Columns.size(); i++ ) {
1375     #ifdef TEXDEBUG
1376       stream << "\nCOLUMN " << i << " DEF_LEFT_B: " <<  Columns[i].defaultTeXLeftBorder
1377              << " DEF_RIGHT_B: " <<  Columns[i].defaultTeXRightBorder << "\n";
1378     #endif
1379     if( i == 0 && Columns[i].defaultTeXLeftBorder )
1380       stream << '|';
1381 
1382     //Cell before margin
1383     if( Columns[i].computedWidth > 0 ) {
1384       char alignment;
1385       switch( Columns[i].displayAlignment ) {
1386         case symbolOutside:
1387         case symbolEnd:
1388 	  alignment =  'U';
1389           break;
1390         case symbolCenter:
1391 	  alignment = 'Y';
1392 	  break;
1393         case symbolInside:
1394         case symbolStart:
1395         default:
1396 	  alignment = 'T';
1397           break;
1398       }
1399       stream << alignment << '{'
1400 	     << LengthInPoints(Columns[i].defaultCellBeforeColumnMargin)
1401 	     << "}{" << LengthInPoints( Columns[i].displaySize )
1402 	     << "}{"
1403 	     << LengthInPoints(Columns[i].defaultCellAfterColumnMargin)
1404 	     << '}';
1405     } else {
1406       stream << "@{\\hspace{"
1407 	     << LengthInPoints(Columns[i].defaultCellBeforeColumnMargin)
1408 	     << "}}";
1409 
1410       switch( Columns[i].displayAlignment ) {
1411         case symbolOutside:
1412         case symbolEnd:     stream << 'r'; break;
1413         case symbolCenter:  stream << 'c'; break;
1414         case symbolInside:
1415         case symbolStart:
1416         default:            stream << 'l'; break;
1417       }
1418       stream << "@{\\hspace{"
1419 	     << LengthInPoints(Columns[i].defaultCellAfterColumnMargin)
1420 	     << "}}";
1421     }
1422     if( Columns[i].defaultTeXRightBorder )
1423       stream << '|';
1424   }
1425   stream << "}%\n";
1426 
1427   stream << HeaderProlog;
1428   const Row *recentRow = NULL;
1429   for( size_t i = 0; i < Header.size(); i++ ) {
1430     Row::outVerticalBorders( recentRow, &Header[i], stream );
1431     Header[i].out( stream );
1432     recentRow = &Header[i];
1433   }
1434   stream << HeaderEpilog;
1435 
1436   for( size_t i = 0; i < Body.size(); i++ ) {
1437     Row::outVerticalBorders( recentRow, &Body[i], stream );
1438     Body[i].out( stream );
1439     recentRow = &Body[i];
1440   }
1441 
1442   stream << FooterProlog;
1443   for( size_t i = 0; i < Footer.size(); i++ ) {
1444     Row::outVerticalBorders( recentRow, &Footer[i], stream );
1445     Footer[i].out( stream );
1446     recentRow = &Footer[i];
1447   }
1448   stream << FooterEpilog;
1449 
1450   if( recentRow )
1451     Row::outVerticalBorders( recentRow, NULL, stream );
1452 
1453   stream << "\\endTeXTable" << "{}%\n";
1454 }
1455 
normalizeRows()1456 void TeXFOTBuilder::TablePart::normalizeRows() {
1457 
1458   size_t maxCellsInRow = Columns.size()+1;
1459   Vector<Row> *rows;
1460   for( int step = 0; step < 2; step++ ) {
1461     for( int rowType = 0; rowType < 3; rowType++ ) {
1462       switch( rowType ) {
1463         case 0: rows = &Header; break;
1464         case 1: rows = &Body; break;
1465         default: rows = &Footer;
1466       }
1467       for( size_t r = 0; r < rows->size(); r++ ) {
1468         if( step == 0 ) {
1469           if( (*rows)[r].Cells.size() > 1 ) {
1470             size_t lastCellIdx = (*rows)[r].Cells.size()-2;
1471             Cell &lastCell = (*rows)[r].Cells[lastCellIdx];
1472             if( !lastCell.missing
1473                   &&
1474                 lastCellIdx+lastCell.nColumnsSpanned+1 > maxCellsInRow )
1475               maxCellsInRow = lastCellIdx+lastCell.nColumnsSpanned+1;
1476           }
1477         } else if( (*rows)[r].Cells.size() < maxCellsInRow )
1478           (*rows)[r].Cells.resize( maxCellsInRow );
1479       }
1480     }
1481   }
1482 }
1483 
1484 // --------- TeXFOTBuilder::Row -----------------------------------------------
1485 
outContent(OutputByteStream & stream) const1486 void TeXFOTBuilder::Row::outContent( OutputByteStream &stream ) const {
1487 
1488   bool first = true;
1489   for( size_t i = 0; i + 1 < Cells.size(); i++ ) {
1490     /* Output the overlapped cells in a row span but not
1491        those in a column span.
1492 
1493        If the overlapping cell is both row and column spanning
1494        only output the first cell in the row.
1495     */
1496     bool outputCell = !Cells[i].isOverlapped() ||
1497       (Cells[i].OverlappingCell->nRowsSpanned > 1 &&
1498        Cells[i].OverlappingCell->TeXTableColumnIdx == i);
1499 
1500     if( !first ) {
1501       if (outputCell)
1502 	stream << "&";
1503     }
1504     else
1505       first = false;
1506     if (outputCell)
1507       Cells[i].out( stream );
1508   }
1509 }
1510 
1511 
outVerticalBorders(const TeXFOTBuilder::Row * upperRow,const TeXFOTBuilder::Row * lowerRow,OutputByteStream & stream)1512 void TeXFOTBuilder::Row::outVerticalBorders
1513  ( const TeXFOTBuilder::Row *upperRow,
1514    const TeXFOTBuilder::Row *lowerRow, OutputByteStream &stream ) {
1515 
1516   assert( upperRow != NULL || lowerRow != NULL );
1517   size_t colNum = upperRow ? upperRow->Cells.size()-1 : lowerRow->Cells.size()-1;
1518   int borderStartIdx = -1;
1519   int borderEndIdx;
1520   for( size_t i = 0; i < colNum; i++ ) {
1521     #ifdef TEXDEBUG
1522       stream << "\nROW: " << "COL " << i << " " <<
1523        ( ( ( upperRow && upperRow->Cells[i].singleRowAfterRowBorderPresent() )
1524            ||
1525           ( lowerRow && lowerRow->Cells[i].singleRowBeforeRowBorderPresent() ) )
1526           ? "Border" : "No Border" );
1527     #endif
1528     if( ( upperRow && upperRow->Cells[i].singleRowAfterRowBorderPresent() )
1529          ||
1530         ( lowerRow && lowerRow->Cells[i].singleRowBeforeRowBorderPresent() ) ) {
1531       if( borderStartIdx < 0 )
1532         borderStartIdx = i;
1533       if( i == colNum-1 ) {
1534         borderEndIdx = i;
1535         goto OUT_BORDER;
1536       }
1537    } else if( borderStartIdx > -1 ) {
1538       borderEndIdx = i-1;
1539       goto OUT_BORDER;
1540    }
1541    continue;
1542 
1543     OUT_BORDER:
1544       if( borderStartIdx == 0 && i == colNum-1 )
1545         stream << "\\Hline%\n";
1546       else
1547         stream << "\\Cline{" << borderStartIdx+1 << '-' << borderEndIdx+1 << "}%\n";
1548       borderStartIdx = -1;
1549   }
1550 }
1551 
1552 // --------- TeXFOTBuilder::Cell ----------------------------------------------
1553 
outProlog(OutputByteStream & stream) const1554 void TeXFOTBuilder::Cell::outProlog( OutputByteStream &stream ) const
1555 {
1556   if ( nColumnsSpanned > 1 || needsTeXColumnOverride ||
1557        (rowAlignment != symbolNotApplicable &&
1558 	rowAlignment != symbolStart ) ||
1559        cellBackground )
1560   {
1561     char color_buf[32];
1562     if ( cellBackground ) {
1563       double r,g,b;
1564       r = (double)backgroundColor.red   / 255.0;
1565       g = (double)backgroundColor.green / 255.0;
1566       b = (double)backgroundColor.blue  / 255.0;
1567       sprintf( color_buf, "{%.2f, %.2f, %.2f}", r, g, b );
1568     }
1569     else
1570       strcpy( color_buf, "");
1571 
1572     stream << "\\TeXTableCell{" << nColumnsSpanned << "}{";
1573 
1574     if( beforeColumnBorder.borderPresent )
1575       stream << '|';
1576 
1577     if (displaySize) {
1578       char alignment;
1579       switch( effectiveAlignment ) {
1580       case symbolOutside:
1581       case symbolEnd:
1582 	switch (rowAlignment) {
1583 	case symbolOutside:
1584 	case symbolEnd:
1585 	  alignment = cellBackground ? '3' : 'M';
1586 	  break;
1587 	case symbolCenter:
1588 	  alignment = cellBackground ? '6' : 'J';
1589 	  break;
1590 	case symbolInside:
1591 	case symbolStart:
1592 	default:
1593 	  alignment = cellBackground ? '9' : 'U';
1594 	  break;
1595 	}
1596 	break;
1597       case symbolCenter:
1598 	switch (rowAlignment) {
1599 	case symbolOutside:
1600 	case symbolEnd:
1601 	  alignment = cellBackground ? '2' : 'N';
1602 	  break;
1603 	case symbolCenter:
1604 	  alignment = cellBackground ? '5' : 'H';
1605 	  break;
1606 	case symbolInside:
1607 	case symbolStart:
1608 	default:
1609 	  alignment = cellBackground ? '8' : 'Y';
1610 	  break;
1611 	}
1612 	break;
1613       case symbolInside:
1614       case symbolStart:
1615       default:
1616 	switch (rowAlignment) {
1617 	case symbolOutside:
1618 	case symbolEnd:
1619 	  alignment = cellBackground ? '1' : 'B';
1620 	  break;
1621 	case symbolCenter:
1622 	  alignment = cellBackground ? '4' : 'G';
1623 	  break;
1624 	case symbolInside:
1625 	case symbolStart:
1626 	default:
1627 	  alignment = cellBackground ? '7' : 'T';
1628 	  break;
1629 	}
1630 	break;
1631       }
1632       stream << alignment
1633 	     << '{' << LengthInPoints(effectiveBeforeColumnMargin)
1634 	     << "}{" << LengthInPoints(displaySize) << "}{"
1635 	     << LengthInPoints(effectiveAfterColumnMargin)
1636 	     << '}' << color_buf;
1637     }
1638     else {
1639       //cell-before-margin
1640       stream << "@{\\hspace{" << LengthInPoints(effectiveBeforeColumnMargin)
1641 	     << "}}";
1642       if ( cellBackground )
1643 	stream << ">{\\columncolor[rgb]" << color_buf << "}";
1644 
1645       switch (rowAlignment) {
1646       case symbolOutside:
1647       case symbolEnd:
1648 	stream << 'r';
1649 	break;
1650       case symbolCenter:
1651 	stream << 'c';
1652 	break;
1653       case symbolInside:
1654       case symbolStart:
1655       default:
1656 	stream << 'l';
1657 	break;
1658       }
1659       //cell-after-margin
1660       stream << "@{\\hspace{" << LengthInPoints(effectiveAfterColumnMargin)
1661 	     << "}}";
1662     }
1663 
1664     if( afterColumnBorder.borderPresent )
1665       stream << '|';
1666 
1667     stream << "}%\n{%\n";
1668   }
1669 
1670   CompoundFotElement::outProlog( stream );
1671 }
1672 
outEpilog(OutputByteStream & stream) const1673 void TeXFOTBuilder::Cell::outEpilog( OutputByteStream &stream ) const {
1674 
1675   CompoundFotElement::outEpilog( stream );
1676   if ( nColumnsSpanned > 1 || needsTeXColumnOverride ||
1677        (rowAlignment != symbolNotApplicable &&
1678 	rowAlignment != symbolStart ) ||
1679        cellBackground )
1680     stream << "}%\n";
1681 }
1682 
computeOverridingTeXColumnBorders(TablePart & tablePart)1683 void TeXFOTBuilder::Cell::computeOverridingTeXColumnBorders( TablePart &tablePart ) {
1684 
1685   StrOutputByteStream str;
1686 
1687   if( tablePart.Columns[TeXTableColumnIdx].defaultTeXLeftBorder
1688        != beforeColumnBorder.borderPresent )
1689     str << "\\def\\TeXTableCellBeforeColumnBorder{"  << beforeColumnBorder.borderPresent << '}';
1690 
1691   if( tablePart.Columns[TeXTableColumnIdx+nColumnsSpanned-1].defaultTeXRightBorder
1692        != afterColumnBorder.borderPresent )
1693     str << "\\def\\TeXTableCellAfterColumnBorder{"  << afterColumnBorder.borderPresent << '}';
1694 
1695   String<char> s;
1696   str.extractString( s );
1697   Characteristics += s;
1698 }
1699 
computeTeXRowSpanFiller(TablePart & tablePart)1700 void TeXFOTBuilder::Cell::computeTeXRowSpanFiller( TablePart &tablePart ) {
1701 
1702   StrOutputByteStream str;
1703 
1704   if ( isOverlapped() && OverlappingCell->nRowsSpanned > 1 )
1705   {
1706     // This isn't output automatically for overlapped cell
1707     str << "\\def\\ColumnIndex{" << TeXTableColumnIdx <<'}';
1708     str << "\\def\\TeXRowSpanFiller{1}";
1709   }
1710 
1711   String<char> s;
1712   str.extractString( s );
1713   Characteristics += s;
1714 }
1715 
computeEffectiveTeXColumnMargins(TablePart & tablePart)1716 void TeXFOTBuilder::Cell::computeEffectiveTeXColumnMargins( TablePart &tablePart ) {
1717   effectiveBeforeColumnMargin = beforeColumnMargin != lengthUnspecified
1718     ? beforeColumnMargin :
1719     tablePart.Columns[TeXTableColumnIdx].defaultCellBeforeColumnMargin;
1720   if( effectiveBeforeColumnMargin != lengthUnspecified &&
1721       (tablePart.Columns[TeXTableColumnIdx].defaultCellBeforeColumnMargin
1722        != effectiveBeforeColumnMargin || nColumnsSpanned > 1) )
1723     needsTeXColumnOverride = true;
1724 
1725 
1726   effectiveAfterColumnMargin = afterColumnMargin != lengthUnspecified
1727     ? afterColumnMargin :
1728     tablePart.Columns[TeXTableColumnIdx].defaultCellAfterColumnMargin;
1729   if( effectiveAfterColumnMargin != lengthUnspecified &&
1730       (tablePart.Columns[TeXTableColumnIdx].defaultCellAfterColumnMargin
1731        != effectiveAfterColumnMargin || nColumnsSpanned > 1) )
1732     needsTeXColumnOverride = true;
1733 }
1734 
computeEffectiveTeXCellWidth(TablePart & tablePart)1735 void TeXFOTBuilder::Cell::computeEffectiveTeXCellWidth( TablePart &tablePart )
1736 {
1737   displaySize = 0;
1738   for (unsigned i = 0; i < nColumnsSpanned; i++ )
1739     displaySize += tablePart.Columns[TeXTableColumnIdx + i].computedWidth;
1740 
1741   if (displaySize)
1742     displaySize -= effectiveBeforeColumnMargin + effectiveAfterColumnMargin;
1743 }
1744 
singleRowBeforeRowBorderPresent() const1745 bool TeXFOTBuilder::Cell::singleRowBeforeRowBorderPresent() const {
1746 
1747   assert( OverlappingCell != NULL );
1748   if( OverlappingCell->TeXTableRowIdx == TeXTableRowIdx )
1749     return OverlappingCell->beforeRowBorder.borderPresent;
1750   else
1751     return false;
1752 }
1753 
singleRowAfterRowBorderPresent() const1754 bool TeXFOTBuilder::Cell::singleRowAfterRowBorderPresent() const {
1755 
1756   assert( OverlappingCell != NULL );
1757   assert( TeXTableRowIdx > -1 );
1758   if( OverlappingCell->TeXTableRowIdx + OverlappingCell->nRowsSpanned
1759        == ((unsigned)TeXTableRowIdx)+1 )
1760     return OverlappingCell->afterRowBorder.borderPresent;
1761   else
1762     return false;
1763 }
1764 
singleColumnBeforeColumnBorderPresent() const1765 bool TeXFOTBuilder::Cell::singleColumnBeforeColumnBorderPresent() const {
1766 
1767   assert( OverlappingCell != NULL );
1768   assert( TeXTableRowIdx > -1 );
1769   if( OverlappingCell->TeXTableColumnIdx
1770        == TeXTableColumnIdx )
1771     return OverlappingCell->beforeColumnBorder.borderPresent;
1772   else
1773     return false;
1774 }
1775 
singleColumnAfterColumnBorderPresent() const1776 bool TeXFOTBuilder::Cell::singleColumnAfterColumnBorderPresent() const {
1777 
1778   assert( OverlappingCell != NULL );
1779   if( OverlappingCell->TeXTableColumnIdx + (int)OverlappingCell->nColumnsSpanned
1780        == TeXTableColumnIdx+1 )
1781     return OverlappingCell->afterColumnBorder.borderPresent;
1782   else
1783     return false;
1784 }
1785 
1786 // --------- TeXFOTBuilder::Border --------------------------------------------
1787 
setFromFot(TeXFOTBuilder & builder)1788 void TeXFOTBuilder::Border::setFromFot( TeXFOTBuilder &builder ) {
1789 
1790   const TeXFOTBuilder::Format &f = builder.curFormat();
1791   borderPriority = f.FotBorderPriority;
1792   borderPresent = f.FotBorderPresent;
1793   lineThickness = f.FotLineThickness;
1794   lineRepeat = f.FotLineRepeat;
1795   lineSep  = f.FotLineSep;
1796 }
1797 
resolve(Border & adjacentBorder)1798 void TeXFOTBuilder::Border::resolve( Border &adjacentBorder ) {
1799 
1800   if( adjacentBorder.borderPriority > borderPriority
1801      ||
1802     (   adjacentBorder.borderPriority == borderPriority
1803      && !adjacentBorder.cellBorder
1804      && adjacentBorder.borderPresent ) ) {
1805 
1806     lineThickness = adjacentBorder.lineThickness;
1807     borderPresent = adjacentBorder.borderPresent;
1808     lineRepeat = adjacentBorder.lineRepeat;
1809     lineSep = adjacentBorder.lineSep;
1810 
1811     if( adjacentBorder.cellBorder )
1812         adjacentBorder.borderPresent = false;
1813   }
1814 
1815   #ifdef TEXDEBUG
1816     *TeXFOTBuilder::curInstance().fileout_
1817      << "RESOLVE_RESULT: " << borderPresent << "\n";
1818   #endif
1819 }
1820 
1821 // --------- End Tables -------------------------------------------------------
1822 
1823 #define MAYBESET(name,value,default) (value!=default?(set(name,value),0):0)
1824 
1825 //
1826 // Get the current output stream.
1827 //
1828 inline
os()1829 OutputByteStream &TeXFOTBuilder::os()
1830 {
1831   return  *(osStack_.back());
1832 }
1833 
1834 void
pushOs(OutputByteStream * to)1835 TeXFOTBuilder::pushOs(OutputByteStream *to)
1836 {
1837   osStack_.push_back( to );
1838 }
1839 
1840 void
popOs()1841 TeXFOTBuilder::popOs()
1842 {
1843   assert( osStack_.size() > 0 );
1844   osStack_.resize( osStack_.size() - 1);
1845 }
1846 
1847 //
1848 // Define an output operator for StringC
1849 //
1850 // FIXME This won't work for Unicode characters.
1851 
operator <<(OutputByteStream & os,const StringC & s)1852 static OutputByteStream &operator<<(OutputByteStream &os, const StringC &s)
1853 {
1854   for (size_t i = 0; i < s.size(); i++)
1855     os << char(s[i]);
1856   return os;
1857 }
1858 
1859 
1860 //
1861 // Define an output operator for GroveString
1862 //
operator <<(OutputByteStream & os,const GroveString & s)1863 static OutputByteStream &operator<<(OutputByteStream &os, const GroveString &s)
1864 {
1865   for (size_t i = 0; i < s.size(); i++)
1866     os << char(s[i]);
1867   return os;
1868 }
1869 
operator <<(OutputByteStream & os,double d)1870 static OutputByteStream &operator<<(OutputByteStream &os, double d)
1871 {
1872   char buf[64];
1873   sprintf(buf, "%g", d);
1874   return os << buf;
1875 }
1876 
makeTeXFOTBuilder(OutputByteStream * os,Messenger * mgr,const FOTBuilder::Extension * & ext)1877 FOTBuilder *makeTeXFOTBuilder(OutputByteStream *os, Messenger *mgr,
1878 			      const FOTBuilder::Extension *&ext)
1879 {
1880   static const TeXFOTBuilder::PageFloatFlowObj pageFloat;
1881   static const TeXFOTBuilder::PageFootnoteFlowObj pageFootnote;
1882   static const FOTBuilder::Extension extensions[] = {
1883     {
1884       "UNREGISTERED::Sebastian Rahtz//Flow Object Class::page-float",
1885       0,
1886       0,
1887       0,
1888       0,
1889       &pageFloat
1890     },
1891     {
1892       "UNREGISTERED::Sebastian Rahtz//Flow Object Class::page-footnote",
1893       0,
1894       0,
1895       0,
1896       0,
1897       &pageFootnote
1898     },
1899     {
1900       "UNREGISTERED::James Clark//Characteristic::page-number-format",
1901       0,
1902       (void (FOTBuilder::*)(const StringC &))&TeXFOTBuilder::setPageNumberFormat,
1903       0,
1904       0
1905     },
1906     {
1907       "UNREGISTERED::James Clark//Characteristic::page-number-restart?",
1908       (void (FOTBuilder::*)(bool))&TeXFOTBuilder::setPageNumberRestart,
1909       0,
1910       0
1911     },
1912     {
1913       "UNREGISTERED::James Clark//Characteristic::page-n-columns",
1914       0,
1915       0,
1916       (void (FOTBuilder::*)(long))&TeXFOTBuilder::setPageNColumns,
1917       0
1918     },
1919     {
1920       "UNREGISTERED::James Clark//Characteristic::page-column-sep",
1921       0,
1922       0,
1923       0,
1924       (void (FOTBuilder::*)(FOTBuilder::Length))&TeXFOTBuilder::setPageColumnSep,
1925     },
1926     {
1927       "UNREGISTERED::James Clark//Characteristic::page-balance-columns?",
1928       (void (FOTBuilder::*)(bool))&TeXFOTBuilder::setPageBalanceColumns,
1929       0,
1930       0
1931     },
1932     {
1933       "UNREGISTERED::OpenJade//Characteristic::page-two-side?",
1934       (void (FOTBuilder::*)(bool))&TeXFOTBuilder::setPageTwoSide,
1935       0,
1936       0
1937     },
1938     {
1939       "UNREGISTERED::OpenJade//Characteristic::two-side-start-on-right?",
1940       (void (FOTBuilder::*)(bool))&TeXFOTBuilder::setTwoSideStartOnRight,
1941       0,
1942       0
1943     },
1944     {
1945       "UNREGISTERED::James Clark//Characteristic::subscript-depth",
1946       0,
1947       0,
1948       0,
1949       (void (FOTBuilder::*)(FOTBuilder::Length))&TeXFOTBuilder::setSubscriptDepth,
1950     },
1951     {
1952       "UNREGISTERED::James Clark//Characteristic::over-mark-height",
1953       0,
1954       0,
1955       0,
1956       (void (FOTBuilder::*)(FOTBuilder::Length))&TeXFOTBuilder::setOverMarkHeight,
1957     },
1958     {
1959       "UNREGISTERED::James Clark//Characteristic::under-mark-depth",
1960       0,
1961       0,
1962       0,
1963       (void (FOTBuilder::*)(FOTBuilder::Length))&TeXFOTBuilder::setUnderMarkDepth,
1964     },
1965     {
1966       "UNREGISTERED::James Clark//Characteristic::superscript-height",
1967       0,
1968       0,
1969       0,
1970       (void (FOTBuilder::*)(FOTBuilder::Length))&TeXFOTBuilder::setSuperscriptHeight,
1971     },
1972     {
1973       "UNREGISTERED::James Clark//Characteristic::grid-row-sep",
1974       0,
1975       0,
1976       0,
1977       (void (FOTBuilder::*)(FOTBuilder::Length))&TeXFOTBuilder::setGridRowSep,
1978     },
1979     {
1980       "UNREGISTERED::James Clark//Characteristic::grid-column-sep",
1981       0,
1982       0,
1983       0,
1984       (void (FOTBuilder::*)(FOTBuilder::Length))&TeXFOTBuilder::setGridColumnSep,
1985     },
1986     {
1987       "UNREGISTERED::James Clark//Characteristic::heading-level",
1988       0,
1989       0,
1990       (void (FOTBuilder::*)(long))&TeXFOTBuilder::setHeadingLevel,
1991       0
1992     },
1993     {
1994       "UNREGISTERED::James Clark//Characteristic::preserve-sdata?",
1995       (void (FOTBuilder::*)(bool))&TeXFOTBuilder::setPreserveSdata,
1996       0,
1997       0,
1998       0,
1999       0
2000     },
2001 
2002     { 0, 0, 0}
2003   };
2004   ext = extensions;
2005   return new TeXFOTBuilder(os, mgr);
2006 }
2007 
2008 ////////////////////////////////////////////////////////////////////////
2009 // Constructor and Destructor
2010 ////////////////////////////////////////////////////////////////////////
2011 
TeXFOTBuilder(OutputByteStream * o,Messenger * mgr)2012 TeXFOTBuilder::TeXFOTBuilder(OutputByteStream *o, Messenger *mgr)
2013 : fileout_(o), mgr_(mgr), preserveSdata_(1)
2014 #ifdef OUTLINES
2015 ,inHeading_(0),headingSet_(0),lastHeaded_(0)
2016 #endif
2017 ,inMath_(0)
2018 {
2019   #ifdef TEXDEBUG
2020     CurInstance = this;
2021   #endif
2022   NextFormat.FotCurDisplaySize = Format::INITIAL_PAGE_SIZE();
2023   FormatStack.push_back( NextFormat );
2024   pushFotElementState();
2025   pushOs(o);
2026   os() << "\\FOT{3}";
2027 #ifdef OUTLINES
2028   return_ += Char('\n');
2029   protectedChar_ += Char('\\');
2030   protectedChar_ += Char('?');
2031 #endif
2032 }
2033 
~TeXFOTBuilder()2034 TeXFOTBuilder::~TeXFOTBuilder()
2035 {
2036   os() << "\\endFOT{}";
2037 }
2038 
2039 //////////////////////////////////////////////////////////////////////
2040 // Atomic flow objects
2041 //////////////////////////////////////////////////////////////////////
2042 #ifdef OUTLINES
2043 //FIXME Que faire avec les characteres > 256
2044 #endif
characters(const Char * s,size_t n)2045 void TeXFOTBuilder::characters(const Char *s, size_t n)
2046 {
2047   for (; n > 0; n--, s++) {
2048 				// Since TeX has only 256 characters
2049 				// by default, two-byte characters
2050 				// will need special treatment.
2051     if (*s > 255) {
2052       //      set("Ch",(unsigned long)(*s));
2053       // insertAtomic("Character");
2054       //
2055       // Don't complicate matters, just give the character!
2056        os() << "\\Character{" << (unsigned long)(*s) << "}";
2057     } else {
2058 				// Otherwise, check for special
2059 				// TeX escapes.
2060       switch(*s) {
2061       default:
2062 	os() << char(*s);
2063 #ifdef OUTLINES
2064 	if (needToCollect()){
2065 	  addHeadedText(s,1);
2066 	  //top(parStack_).headingText_.append(s,1);
2067 	}
2068 #endif
2069 	break;
2070       case ' ':
2071       case '\t':
2072 	if ( NextFormat.FotLines == symbolAsis )
2073 	  os() << '~';
2074 	else
2075 	  os() << char(*s);
2076 #ifdef OUTLINES
2077 	if (needToCollect()){
2078 	  addHeadedText(s,1);
2079 	  //top(parStack_).headingText_.append(s,1);
2080 	}
2081 #endif
2082 	break;
2083       case '\\':
2084       case '^':
2085       case '_':
2086       case '~':
2087 	os() << "\\char" << int(*s) << "{}";
2088 #ifdef OUTLINES
2089 	if (needToCollect()){
2090 	  addHeadedText(s,1);
2091 	  //top(parStack_).headingText_.append(s,1);
2092 	}
2093 #endif
2094 	break;
2095       case '{':
2096       case '}':
2097       case '$':
2098       case '&':
2099       case '#':
2100       case '%':
2101 	os() << "\\" << char(*s);
2102 #ifdef OUTLINES
2103 	if (needToCollect()){
2104 	  protectedChar_[1]=*s;
2105 	  addHeadedText(protectedChar_);
2106 	  //top(parStack_).headingText_ += protectedChar_;
2107 	}
2108 #endif
2109 	break;
2110       case '\r':
2111 	os() << '\n';
2112 #ifdef OUTLINES
2113 	if (needToCollect()){
2114 	  addHeadedText(return_);
2115 	  //top(parStack_).headingText_ += return_;
2116 	}
2117 #endif
2118 	break;
2119       case '\n':
2120 	break;
2121       case '-':
2122       case '<':
2123       case '>':
2124         os() << char(*s);
2125 	if (!inMath_)
2126           os() << "\\/"; // break ligatures
2127         break;
2128       }
2129     }
2130   }
2131 }
2132 
character(const CharacterNIC & nic)2133 void TeXFOTBuilder::character(const CharacterNIC &nic)
2134 {
2135   setCharacterNIC(nic);
2136   //  insertAtomic("Character");
2137   dumpInherited();
2138   os() << "\\Character{" << (unsigned long)(nic.ch) << "}";
2139 }
2140 
paragraphBreak(const ParagraphNIC & nic)2141 void TeXFOTBuilder::paragraphBreak(const ParagraphNIC &nic)
2142 {
2143   setParagraphNIC(nic);
2144   insertAtomic("ParagraphBreak");
2145 }
2146 
externalGraphic(const ExternalGraphicNIC & nic)2147 void TeXFOTBuilder::externalGraphic(const ExternalGraphicNIC &nic)
2148 {
2149   setExternalGraphicNIC(nic);
2150   insertAtomic("ExternalGraphic");
2151 }
2152 
rule(const RuleNIC & nic)2153 void TeXFOTBuilder::rule(const RuleNIC &nic)
2154 {
2155   setRuleNIC(nic);
2156   insertAtomic("Rule");
2157 }
2158 
alignmentPoint()2159 void TeXFOTBuilder::alignmentPoint()
2160 {
2161   insertAtomic("AlignmentPoint");
2162 }
2163 
2164 // page-number sosofo
pageNumber()2165 void TeXFOTBuilder::pageNumber()
2166 {
2167   insertAtomic("PageNumber");
2168 }
2169 
formattingInstruction(const StringC & instr)2170 void TeXFOTBuilder::formattingInstruction (const StringC &instr)
2171 {
2172   os() << instr;
2173 }
2174 
tableColumn(const TableColumnNIC & nic)2175 void TeXFOTBuilder::tableColumn(const TableColumnNIC &nic)
2176 {
2177   setTableColumnNIC(nic);
2178 
2179   if( nic.columnIndex >= curTable().curTablePart().Columns.size() )
2180     curTable().curTablePart().Columns.resize( nic.columnIndex + 1 );
2181 
2182   Column &col = curTable().curTablePart().Columns[nic.columnIndex];
2183 
2184   col.isExplicit = true;
2185   col.hasWidth = nic.hasWidth;
2186   if( nic.hasWidth )
2187       col.width = nic.width;
2188 
2189   if ( curFormat().FotDisplayAlignment != symbolNotApplicable )
2190       col.displayAlignment = curFormat().FotDisplayAlignment;
2191   if ( curFormat().FotCellBeforeColumnMargin != lengthUnspecified )
2192     col.defaultCellBeforeColumnMargin = curFormat().FotCellBeforeColumnMargin;
2193   if ( curFormat().FotCellAfterColumnMargin != lengthUnspecified )
2194     col.defaultCellAfterColumnMargin = curFormat().FotCellAfterColumnMargin;
2195 
2196   insertAtomic("TableColumn");
2197 }
2198 
tableCellBeforeRowBorder()2199 void TeXFOTBuilder::tableCellBeforeRowBorder()
2200 {
2201   start();
2202   curTable().curCell().beforeRowBorder.setFromFot( *this );
2203   insertAtomic( curTable().curCell().beforeRowBorder );
2204   end();
2205 }
2206 
tableCellAfterRowBorder()2207 void TeXFOTBuilder::tableCellAfterRowBorder()
2208 {
2209   start();
2210   curTable().curCell().afterRowBorder.setFromFot( *this );
2211   insertAtomic( curTable().curCell().afterRowBorder );
2212   end();
2213 }
2214 
tableCellBeforeColumnBorder()2215 void TeXFOTBuilder::tableCellBeforeColumnBorder()
2216 {
2217   start();
2218   curTable().curCell().beforeColumnBorder.setFromFot( *this );
2219   insertAtomic( curTable().curCell().beforeColumnBorder );
2220   end();
2221 }
2222 
tableCellAfterColumnBorder()2223 void TeXFOTBuilder::tableCellAfterColumnBorder()
2224 {
2225   start();
2226   curTable().curCell().afterColumnBorder.setFromFot( *this );
2227   insertAtomic( curTable().curCell().afterColumnBorder );
2228   end();
2229 }
2230 
fractionBar()2231 void TeXFOTBuilder::fractionBar()
2232 {
2233   insertAtomic("FractionBar");
2234 }
2235 
radicalRadical(const CharacterNIC & c)2236 void TeXFOTBuilder::radicalRadical(const CharacterNIC &c)
2237 {
2238   setCharacterNIC(c);
2239   insertAtomic("RadicalRadical");
2240 }
2241 
radicalRadicalDefaulted()2242 void TeXFOTBuilder::radicalRadicalDefaulted()
2243 {
2244   insertAtomic("RadicalRadicalDefaulted");
2245 }
2246 
currentNodePageNumber(const NodePtr & node)2247 void TeXFOTBuilder::currentNodePageNumber(const NodePtr &node)
2248 {
2249   GroveString id;
2250   unsigned long ei;
2251 
2252   // FIX ME!
2253   // Only PARTIALLY supported -- I currently allow cross-references
2254   // only to elements.
2255   if (node->getId(id) == accessOK) {
2256     set("Label",id);
2257   } else if (node->elementIndex(ei) == accessOK) {
2258     set("Element",ei);
2259   } else {
2260     message(TeXMessages::unsupportedPageNumberNonElement);
2261     return;
2262   }
2263   unsigned long g = node->groveIndex();
2264   if (g) {
2265     set("GroveIndex",g);
2266   }
2267   insertAtomic("CurrentNodePageNumber");
2268 }
2269 
2270 
2271 //////////////////////////////////////////////////////////////////////
2272 // Non-atomic flow objects
2273 //////////////////////////////////////////////////////////////////////
2274 
startSequence()2275 void TeXFOTBuilder::startSequence()
2276 {
2277   start();
2278   if( !curFotElementState().enforcingStructure() )
2279     startGroup("Seq");
2280 }
2281 
endSequence()2282 void TeXFOTBuilder::endSequence()
2283 {
2284   if( !curFotElementState().enforcingStructure() )
2285     endGroup("Seq");
2286   end();
2287 }
2288 
startLineField(const LineFieldNIC & nic)2289 void TeXFOTBuilder::startLineField(const LineFieldNIC &nic)
2290 {
2291   start();
2292   setLineFieldNIC(nic);
2293   startGroup("LineField");
2294 }
2295 
endLineField()2296 void TeXFOTBuilder::endLineField()
2297 {
2298   endGroup("LineField");
2299   end();
2300 }
2301 
startParagraph(const ParagraphNIC & nic)2302 void TeXFOTBuilder::startParagraph(const ParagraphNIC &nic)
2303 {
2304   startDisplay( nic );
2305   start();
2306   setParagraphNIC(nic);
2307 #ifdef OUTLINES
2308   if (headingSet_){
2309     startGroup("HeadPar");
2310     headingSet_=0;
2311     inHeading_=1;
2312     top(parStack_).previous_=lastHeaded_;
2313     lastHeaded_=parStack_.size() - 1 ;
2314     //assert(lastHeaded_!=0);
2315   }
2316   else{
2317     ParHead par(0);
2318     startGroup("Par");
2319     push(parStack_,par);
2320     top(parStack_).previous_=lastHeaded_;
2321   }
2322 #else
2323   startGroup("Par");
2324 #endif
2325 }
2326 
endParagraph()2327 void TeXFOTBuilder::endParagraph()
2328 {
2329   //FIXME : when (headed (level n) (headed level (+ n 1)))
2330   // text for level N+1 is emitted before text for level n
2331   // and outliens are out of sync.
2332 #ifdef OUTLINES
2333   if (top(parStack_).isHeaded_){
2334     //cerr << "Writing\n";
2335     //cerr << "length : "<<top(parStack_).headingText_.size();
2336     os() << "\\def\\HeadingText{%\n"
2337 	 << top(parStack_).headingText_
2338 	 <<"}%\n";
2339     endGroup("HeadPar");
2340     //    headingText_.resize(0);
2341     inHeading_=0;
2342 
2343   }
2344   else{
2345     //cerr << "Non Writing\n";
2346     endGroup("Par");
2347   }
2348   lastHeaded_=top(parStack_).previous_;
2349   pop(parStack_);
2350 #else
2351   endDisplay();
2352 #endif
2353   end();
2354   endDisplay();
2355 }
startDisplayGroup(const DisplayGroupNIC & nic)2356 void TeXFOTBuilder::startDisplayGroup(const DisplayGroupNIC &nic)
2357 {
2358   startDisplay( nic );
2359   start();
2360   setDisplayGroupNIC(nic);
2361   startGroup("DisplayGroup");
2362 }
2363 
endDisplayGroup()2364 void TeXFOTBuilder::endDisplayGroup()
2365 {
2366   endGroup("DisplayGroup");
2367   end();
2368   endDisplay();
2369 }
2370 
startScroll()2371 void TeXFOTBuilder::startScroll()
2372 {
2373   start();
2374   startGroup("Scroll");
2375 }
2376 
endScroll()2377 void TeXFOTBuilder::endScroll()
2378 {
2379   endGroup("Scroll");
2380   end();
2381 }
2382 
startScore(Char ch)2383 void TeXFOTBuilder::startScore(Char ch)
2384 {
2385   start();
2386   set("ScoreCharacter",(unsigned long)ch);
2387   startGroup("Score");
2388 }
2389 
startScore(const LengthSpec & len)2390 void TeXFOTBuilder::startScore(const LengthSpec &len)
2391 {
2392   start();
2393   set("ScoreLength",len);
2394   startGroup("Score");
2395 }
2396 
startScore(Symbol type)2397 void TeXFOTBuilder::startScore(Symbol type)
2398 {
2399   start();
2400   set("ScoreType",type);
2401   startGroup("Score");
2402 }
2403 
endScore()2404 void TeXFOTBuilder::endScore()
2405 {
2406   endGroup("Score");
2407   end();
2408 }
2409 
startLeader(const LeaderNIC & nic)2410 void TeXFOTBuilder::startLeader(const LeaderNIC &nic)
2411 {
2412   start();
2413   setLeaderNIC(nic);
2414   startGroup("Leader");
2415 }
2416 
endLeader()2417 void TeXFOTBuilder::endLeader()
2418 {
2419   endGroup("Leader");
2420   end();
2421 }
2422 
startSideline()2423 void TeXFOTBuilder::startSideline()
2424 {
2425   start();
2426   startGroup("SideLine");
2427 }
2428 
endSideline()2429 void TeXFOTBuilder::endSideline()
2430 {
2431   endGroup("SideLine");
2432   end();
2433 }
2434 
startBox(const BoxNIC & nic)2435 void TeXFOTBuilder::startBox(const BoxNIC &nic)
2436 {
2437   if( nic.isDisplay ) {
2438     DisplayBoxLevels.push_back( FormatStack.size() );
2439     startDisplay(nic);
2440   }
2441   start();
2442   setBoxNIC(nic);
2443   startGroup("BOX");
2444 }
2445 
endBox()2446 void TeXFOTBuilder::endBox()
2447 {
2448   endGroup("BOX");
2449   end();
2450   if( DisplayBoxLevels.size() > 0 && DisplayBoxLevels.back() == FormatStack.size() ) {
2451     DisplayBoxLevels.resize( DisplayBoxLevels.size() - 1 );
2452     endDisplay();
2453   }
2454 }
2455 
2456 // Tables
startTable(const TableNIC & nic)2457 void TeXFOTBuilder::startTable(const TableNIC &nic)
2458 {
2459   #ifdef TEXDEBUG
2460     *fileout_ << "\nTABLE_START\n";
2461   #endif
2462   TableStack.resize( TableStack.size() + 1 );
2463   startDisplay( nic );
2464   start();
2465 
2466   setTableNIC(nic);
2467 
2468   Length curStartIndent = computeLengthSpec( curFormat().FotStartIndentSpec );
2469   curTable().startIndent = curStartIndent;
2470 
2471   startGroup( curTable() );
2472   curTable().open( *this);
2473   curTable().begin();
2474   if ( curFormat().FotDisplayAlignment != symbolNotApplicable )
2475       curTable().displayAlignment = curFormat().FotDisplayAlignment;
2476 
2477   if( nic.widthType == TableNIC::widthExplicit )
2478       curTable().tableWidth = computeLengthSpec( nic.width );
2479   else
2480       curTable().tableWidth
2481        = curFormat().FotCurDisplaySize - curStartIndent
2482           - computeLengthSpec( curFormat().FotEndIndentSpec );
2483 
2484   curTable().curTablePart().open( *this );
2485 }
2486 
endTable()2487 void TeXFOTBuilder::endTable()
2488 {
2489   assert( TableStack.size() > 0 );
2490   #ifdef TEXDEBUG
2491     *fileout_ << "\nTABLE_END\n";
2492   #endif
2493 
2494   if( curTable().NoTablePartsSeen ) {
2495     curTable().curTablePart().close( *this );
2496     curTable().curTablePart().isExplicit = false;
2497   }
2498 
2499   curTable().end( *this );
2500   curTable().close( *this );
2501   curTable().out( os() );
2502 
2503   endGroup();
2504   end();
2505   endDisplay();
2506 
2507   TableStack.resize( TableStack.size() - 1 );
2508 }
2509 
2510 // A call for each border is made immediately
2511 // after startTable(), each preceded by any appropriate set*() calls.
tableBeforeRowBorder()2512 void TeXFOTBuilder::tableBeforeRowBorder()
2513 {
2514   start();
2515   curTable().beforeRowBorder.setFromFot( *this );
2516   insertAtomic( curTable().beforeRowBorder );
2517   end();
2518 }
2519 
tableAfterRowBorder()2520 void TeXFOTBuilder::tableAfterRowBorder()
2521 {
2522   start();
2523   curTable().afterRowBorder.setFromFot( *this );
2524   insertAtomic( curTable().afterRowBorder );
2525   end();
2526 }
2527 
tableBeforeColumnBorder()2528 void TeXFOTBuilder::tableBeforeColumnBorder()
2529 {
2530   start();
2531   curTable().beforeColumnBorder.setFromFot( *this );
2532   insertAtomic( curTable().beforeColumnBorder );
2533   end();
2534 }
2535 
tableAfterColumnBorder()2536 void TeXFOTBuilder::tableAfterColumnBorder()
2537 {
2538   start();
2539   curTable().afterColumnBorder.setFromFot( *this );
2540   insertAtomic( curTable().afterColumnBorder );
2541   end();
2542 }
2543 
startTablePartSerial(const TablePartNIC & nic)2544 void TeXFOTBuilder::startTablePartSerial(const TablePartNIC &nic)
2545 {
2546   #ifdef TEXDEBUG
2547     *fileout_ << "\nTABLE_PART_START\n";
2548   #endif
2549 
2550   startDisplay( nic );
2551   start();
2552 
2553   setTablePartNIC(nic);
2554 
2555   if( curTable().NoTablePartsSeen ) {
2556       curTable().NoTablePartsSeen = false;
2557       /* begin() was arleady called from Table() and
2558 	 open() was called from startTable() */
2559   }
2560   else {
2561       curTable().TableParts.resize( curTable().TableParts.size()+1 );
2562       curTable().TableParts.back().setSiblingSeqIdx( curTable().TableParts.size()-1 );
2563       curTable().TableParts.back().setParent( &curTable() );
2564 
2565       curTable().TableParts.back().begin();
2566       curTable().TableParts.back().open( *this );
2567   }
2568 
2569   startGroup( curTable().curTablePart() );
2570 }
2571 
endTablePartSerial()2572 void TeXFOTBuilder::endTablePartSerial()
2573 {
2574   curTable().curTablePart().close( *this );
2575   curTable().CurTablePart = NULL;
2576   endGroup();
2577   end();
2578   endDisplay();
2579 
2580   #ifdef TEXDEBUG
2581     *fileout_ << "\nTABLE_PART_END\n";
2582   #endif
2583 }
2584 
startTableRow()2585 void TeXFOTBuilder::startTableRow()
2586 {
2587   #ifdef TEXDEBUG
2588     *fileout_ << "\nTABLE_ROW_START\n";
2589   #endif
2590 
2591   curTable().curRows().resize( curTable().curRows().size() + 1 );
2592   curTable().curRows().back().setSiblingSeqIdx( curTable().curRows().size()-1 );
2593   curTable().curRows().back().setParent( &curTable().curTablePart() );
2594   startGroup( curTable().curRows().back() );
2595   curTable().curRows().back().open( *this );
2596 }
2597 
endTableRow()2598 void TeXFOTBuilder::endTableRow()
2599 {
2600   curTable().curRows().back().close( *this );
2601   endGroup();
2602 
2603   #ifdef TEXDEBUG
2604     *fileout_ << "\nTABLE_ROW_END\n";
2605   #endif
2606 }
2607 
2608 /*
2609  * FIXME: We are getting one extra table cell in each
2610  * row whic nic.missing set . What is this ???
2611  */
startTableCell(const TableCellNIC & nic)2612 void TeXFOTBuilder::startTableCell(const TableCellNIC &nic)
2613 {
2614   #ifdef TEXDEBUG
2615     *fileout_ << "\nTABLE_CELL_START index: " << nic.columnIndex
2616               << " missing: " << nic.missing << "\n";
2617   #endif
2618 
2619   setTableCellNIC(nic);
2620 
2621   TablePart &tp = curTable().curTablePart();
2622   if( !tp.columnsProcessed )
2623       tp.processColumns( *this );
2624 
2625   Vector<Cell> &Cells = curTable().curRows().back().Cells;
2626   { size_t curSize = Cells.size();
2627     if( nic.columnIndex >= curSize ) {
2628         Cells.resize( nic.columnIndex + 1 );
2629         for( size_t i = curSize; i < Cells.size(); i++ )
2630           Cells[i].setSiblingSeqIdx( i );
2631     }
2632   }
2633 
2634   Cell &cell = Cells[nic.columnIndex];
2635   curTable().CurCell = &cell;
2636   cell.missing = nic.missing;
2637   cell.setParent( &curTable().curRows().back() );
2638 
2639   if( nic.nColumnsSpanned != 1 )
2640       cell.nColumnsSpanned = nic.nColumnsSpanned;
2641 
2642   if( nic.nRowsSpanned != 1 )
2643       cell.nRowsSpanned = nic.nRowsSpanned;
2644 
2645   for( size_t i = nic.columnIndex; i < nic.columnIndex + nic.nColumnsSpanned; i++ )
2646   {
2647     if( i >= tp.Columns.size() && !nic.missing ) {
2648       tp.Columns.resize( tp.Columns.size() + 1 );
2649       tp.Columns.back().hasWidth = false;
2650       tp.Columns.back().isExplicit = false;
2651       tp.columnsProcessed = false;
2652     }
2653   }
2654   // We may need reprocessing
2655   if( !tp.columnsProcessed )
2656       tp.processColumns( *this );
2657 
2658   if ( !nic.missing ) {
2659     if ( NextFormat.FotCellRowAlignment != symbolNotApplicable )
2660       cell.rowAlignment = NextFormat.FotCellRowAlignment;
2661     if ( NextFormat.FotCellBeforeColumnMargin != lengthUnspecified )
2662       cell.beforeColumnMargin = NextFormat.FotCellBeforeColumnMargin;
2663     if ( NextFormat.FotCellAfterColumnMargin != lengthUnspecified )
2664       cell.afterColumnMargin = NextFormat.FotCellAfterColumnMargin;
2665 
2666     if (NextFormat.FotCellBackground) {
2667       cell.cellBackground = true;
2668       cell.backgroundColor = NextFormat.FotBackgroundColor;
2669     }
2670 
2671     cell.TeXTableColumnIdx = nic.columnIndex;
2672     cell.effectiveAlignment = tp.Columns[nic.columnIndex].displayAlignment;
2673     cell.computeEffectiveTeXColumnMargins( tp );
2674     cell.computeEffectiveTeXCellWidth( tp );
2675 
2676     NextFormat.FotCurDisplaySize = cell.displaySize;
2677   }
2678 
2679   elementStart( oc_Cell );
2680   startGroup( cell );
2681   cell.open( *this );
2682 }
2683 
endTableCell()2684 void TeXFOTBuilder::endTableCell()
2685 {
2686   curTable().curCell().close( *this );
2687   curTable().CurCell = NULL;
2688   endGroup();
2689   end();
2690 
2691   #ifdef TEXDEBUG
2692     *fileout_ << "\nTABLE_CELL_END\n";
2693   #endif
2694 }
2695 
startSimplePageSequenceSerial()2696 void TeXFOTBuilder::startSimplePageSequenceSerial()
2697 {
2698   NextFormat.FotCurDisplaySize
2699    = ( NextFormat.FotPageWidth - NextFormat.FotLeftMargin - NextFormat.FotRightMargin
2700         - NextFormat.FotPageColumnSep * ( NextFormat.FotPageNColumns - 1 ) )
2701       / NextFormat.FotPageNColumns;
2702 
2703   start();
2704   startGroup("SpS");
2705 }
2706 
endSimplePageSequenceSerial()2707 void TeXFOTBuilder::endSimplePageSequenceSerial()
2708 {
2709   endGroup("SpS");
2710   end();
2711 }
2712 
2713 // These aren't real flow objects, so handle them a little
2714 // differently.
startSimplePageSequenceHeaderFooter(unsigned flags)2715 void TeXFOTBuilder::startSimplePageSequenceHeaderFooter(unsigned flags)
2716 {
2717   os() << "\n\\SpS";
2718   if ((flags & (firstHF|otherHF)) == firstHF)
2719     os() << "First";
2720   else
2721     os() << "Other";
2722   if ((flags & (frontHF|backHF)) == frontHF)
2723     os() << "Front";
2724   else
2725     os() << "Back";
2726   switch (flags & (leftHF|centerHF|rightHF)) {
2727   case leftHF:
2728     os() << "Left";
2729     break;
2730   case centerHF:
2731     os() << "Center";
2732     break;
2733   case rightHF:
2734     os() << "Right";
2735     break;
2736   }
2737   if ((flags & (headerHF|footerHF)) == headerHF)
2738     os() << "Header";
2739   else
2740     os() << "Footer";
2741   os() << "%\n{";
2742 }
2743 
endSimplePageSequenceHeaderFooter(unsigned)2744 void TeXFOTBuilder::endSimplePageSequenceHeaderFooter(unsigned)
2745 {
2746   endSimpleGroup();
2747 }
2748 
startTablePartHeader()2749 void TeXFOTBuilder::startTablePartHeader()
2750 {
2751   curTable().CurRows = &curTable().curTablePart().Header;
2752   startGroup( "TablePartHeader", &curTable().curTablePart().HeaderProlog );
2753 }
2754 
endTablePartHeader()2755 void TeXFOTBuilder::endTablePartHeader()
2756 {
2757   curTable().CurRows = &curTable().curTablePart().Body;
2758   endGroup( "TablePartHeader", &curTable().curTablePart().HeaderEpilog );
2759 }
2760 
startTablePartFooter()2761 void TeXFOTBuilder::startTablePartFooter()
2762 {
2763   curTable().CurRows = &curTable().curTablePart().Footer;
2764   startGroup( "TablePartFooter", &curTable().curTablePart().FooterProlog );
2765 }
2766 
endTablePartFooter()2767 void TeXFOTBuilder::endTablePartFooter()
2768 {
2769   curTable().CurRows = &curTable().curTablePart().Body;
2770   endGroup( "TablePartFooter", &curTable().curTablePart().FooterEpilog );
2771 }
2772 
startMathSequence()2773 void TeXFOTBuilder::startMathSequence()
2774 {
2775   inMath_++;
2776   startGroup("MathSeq");
2777 }
2778 
endMathSequence()2779 void TeXFOTBuilder::endMathSequence()
2780 {
2781   endGroup("MathSeq");
2782   inMath_++;
2783 }
2784 
startFractionSerial()2785 void TeXFOTBuilder::startFractionSerial()
2786 {
2787   startGroup("FractionSerial");
2788 }
2789 
endFractionSerial()2790 void TeXFOTBuilder::endFractionSerial()
2791 {
2792   endGroup("FractionSerial");
2793 }
2794 
startFractionNumerator()2795 void TeXFOTBuilder::startFractionNumerator()
2796 {
2797   startGroup("FractionNumerator");
2798 }
2799 
endFractionNumerator()2800 void TeXFOTBuilder::endFractionNumerator()
2801 {
2802   endGroup("FractionNumerator");
2803 }
2804 
startFractionDenominator()2805 void TeXFOTBuilder::startFractionDenominator()
2806 {
2807   startGroup("FractionDenominator");
2808 }
2809 
endFractionDenominator()2810 void TeXFOTBuilder::endFractionDenominator()
2811 {
2812   endGroup("FractionDenominator");
2813 }
2814 
startUnmath()2815 void TeXFOTBuilder::startUnmath()
2816 {
2817   startBrace("Unmath");
2818 }
2819 
endUnmath()2820 void TeXFOTBuilder::endUnmath()
2821 {
2822   endBrace("Unmath");
2823 }
2824 
startSuperscript()2825 void TeXFOTBuilder::startSuperscript()
2826 {
2827    startBrace("Superscript");
2828 }
2829 
endSuperscript()2830 void TeXFOTBuilder::endSuperscript()
2831 {
2832   endBrace("Superscript");
2833 }
2834 
startSubscript()2835 void TeXFOTBuilder::startSubscript()
2836 {
2837   startBrace("Subscript");
2838 }
2839 
endSubscript()2840 void TeXFOTBuilder::endSubscript()
2841 {
2842   endBrace("Subscript");
2843 }
startScriptSerial()2844 void TeXFOTBuilder::startScriptSerial()
2845 {
2846   startBrace("ScriptSerial");
2847 }
2848 
endScriptSerial()2849 void TeXFOTBuilder::endScriptSerial()
2850 {
2851 }
2852 
startScriptPreSup()2853 void TeXFOTBuilder::startScriptPreSup()
2854 {
2855   closeopenBrace("ScriptPreSup"); // ends brace started in startScript Serial
2856 }
2857 
endScriptPreSup()2858 void TeXFOTBuilder::endScriptPreSup()
2859 {
2860   endSimpleGroup();
2861 }
2862 
startScriptPreSub()2863 void TeXFOTBuilder::startScriptPreSub()
2864 {
2865   startSimpleGroup("ScriptPreSub");
2866 }
2867 
endScriptPreSub()2868 void TeXFOTBuilder::endScriptPreSub()
2869 {
2870   endSimpleGroup();
2871 }
2872 
startScriptPostSup()2873 void TeXFOTBuilder::startScriptPostSup()
2874 {
2875   startSimpleGroup("ScriptPostSup");
2876 }
2877 
endScriptPostSup()2878 void TeXFOTBuilder::endScriptPostSup()
2879 {
2880   endSimpleGroup();
2881 }
2882 
startScriptPostSub()2883 void TeXFOTBuilder::startScriptPostSub()
2884 {
2885   startSimpleGroup("ScriptPostSub");
2886 }
2887 
endScriptPostSub()2888 void TeXFOTBuilder::endScriptPostSub()
2889 {
2890   endSimpleGroup();
2891 }
2892 
startScriptMidSup()2893 void TeXFOTBuilder::startScriptMidSup()
2894 {
2895   startSimpleGroup("ScriptMidSup");
2896 }
2897 
endScriptMidSup()2898 void TeXFOTBuilder::endScriptMidSup()
2899 {
2900   endSimpleGroup();
2901 }
2902 
startScriptMidSub()2903 void TeXFOTBuilder::startScriptMidSub()
2904 {
2905   startSimpleGroup("ScriptMidSub");
2906 }
2907 
endScriptMidSub()2908 void TeXFOTBuilder::endScriptMidSub()
2909 {
2910   endSimpleGroup();
2911 }
2912 
startMarkSerial()2913 void TeXFOTBuilder::startMarkSerial()
2914 {
2915   startGroup("MarkSerial");
2916 }
2917 
endMarkSerial()2918 void TeXFOTBuilder::endMarkSerial()
2919 {
2920   endGroup("MarkSerial");
2921 }
2922 
startMarkOver()2923 void TeXFOTBuilder::startMarkOver()
2924 {
2925   startGroup("MarkOver");
2926 }
2927 
endMarkOver()2928 void TeXFOTBuilder::endMarkOver()
2929 {
2930   endGroup("MarkOver");
2931 }
2932 
startMarkUnder()2933 void TeXFOTBuilder::startMarkUnder()
2934 {
2935   startGroup("MarkUnder");
2936 }
2937 
endMarkUnder()2938 void TeXFOTBuilder::endMarkUnder()
2939 {
2940   endGroup("MarkUnder");
2941 }
2942 
startFenceSerial()2943 void TeXFOTBuilder::startFenceSerial()
2944 {
2945   startBrace("FenceSerial");
2946 }
2947 
endFenceSerial()2948 void TeXFOTBuilder::endFenceSerial()
2949 {
2950     //  endGroup("FenceSerial");
2951 }
2952 
startFenceOpen()2953 void TeXFOTBuilder::startFenceOpen()
2954 {
2955   // Extra closing brace for end of fence body
2956   closeopenBrace("FenceOpen");
2957 }
2958 
endFenceOpen()2959 void TeXFOTBuilder::endFenceOpen()
2960 {
2961   endSimpleGroup();
2962 }
2963 
startFenceClose()2964 void TeXFOTBuilder::startFenceClose()
2965 {
2966   startSimpleGroup("FenceClose");
2967 }
2968 
endFenceClose()2969 void TeXFOTBuilder::endFenceClose()
2970 {
2971   endSimpleGroup();
2972 }
2973 
startRadicalSerial()2974 void TeXFOTBuilder::startRadicalSerial()
2975 {
2976   startGroup("RadicalSerial");
2977 }
2978 
endRadicalSerial()2979 void TeXFOTBuilder::endRadicalSerial()
2980 {
2981   endGroup("RadicalSerial");
2982 }
2983 
startRadicalDegree()2984 void TeXFOTBuilder::startRadicalDegree()
2985 {
2986   startGroup("RadicalDegree");
2987 }
2988 
endRadicalDegree()2989 void TeXFOTBuilder::endRadicalDegree()
2990 {
2991   endGroup("RadicalDegree");
2992 }
2993 
startMathOperatorSerial()2994 void TeXFOTBuilder::startMathOperatorSerial()
2995 {
2996   startGroup("MathOperatorSerial");
2997 }
2998 
endMathOperatorSerial()2999 void TeXFOTBuilder::endMathOperatorSerial()
3000 {
3001   endGroup("MathOperatorSerial");
3002 }
3003 
startMathOperatorOperator()3004 void TeXFOTBuilder::startMathOperatorOperator()
3005 {
3006   startGroup("MathOperatorOperator");
3007 }
3008 
endMathOperatorOperator()3009 void TeXFOTBuilder::endMathOperatorOperator()
3010 {
3011   endGroup("MathOperatorOperator");
3012 }
3013 
startMathOperatorLowerLimit()3014 void TeXFOTBuilder::startMathOperatorLowerLimit()
3015 {
3016   startGroup("MathOperatorLowerLimit");
3017 }
3018 
endMathOperatorLowerLimit()3019 void TeXFOTBuilder::endMathOperatorLowerLimit()
3020 {
3021   endGroup("MathOperatorLowerLimit");
3022 }
3023 
startMathOperatorUpperLimit()3024 void TeXFOTBuilder::startMathOperatorUpperLimit()
3025 {
3026   startGroup("MathOperatorUpperLimit");
3027 }
3028 
endMathOperatorUpperLimit()3029 void TeXFOTBuilder::endMathOperatorUpperLimit()
3030 {
3031   endGroup("MathOperatorUpperLimit");
3032 }
3033 
startGrid(const GridNIC & nic)3034 void TeXFOTBuilder::startGrid(const GridNIC &nic)
3035 {
3036   setGridNIC(nic);
3037   startGroup("Grid");
3038 }
3039 
endGrid()3040 void TeXFOTBuilder::endGrid()
3041 {
3042   endGroup("Grid");
3043 }
3044 
startGridCell(const GridCellNIC & nic)3045 void TeXFOTBuilder::startGridCell(const GridCellNIC &nic)
3046 {
3047   setGridCellNIC(nic);
3048   startGroup("GridCell");
3049 }
3050 
endGridCell()3051 void TeXFOTBuilder::endGridCell()
3052 {
3053   endGroup("GridCell");
3054 }
3055 
startNode(const NodePtr & node,const StringC & processingMode)3056 void TeXFOTBuilder::startNode(const NodePtr &node,
3057 			      const StringC &processingMode)
3058 {
3059   GroveString id;
3060   unsigned long ei;
3061 
3062   if (node->getId(id) == accessOK) {
3063     set("Label",id);
3064   }
3065   else if (node->elementIndex(ei) == accessOK) {
3066     set("Element", ei);
3067   }
3068   unsigned long g = node->groveIndex();
3069   if (g) {
3070     set("GroveIndex", g);
3071   }
3072   if (processingMode.size()) {
3073     set("ProcessingMode", processingMode);
3074   }
3075 
3076   if( curFotElementState().enforcingStructure() ) {
3077     startGroup( "Node", &(curFotElementState().CurNodeInfoProlog) );
3078     #ifdef TEXDEBUG
3079       *fileout_ << "\nSTART_NODE " << ei << "\n";
3080     #endif
3081   } else
3082     startGroup("Node");
3083 }
3084 
endNode()3085 void TeXFOTBuilder::endNode()
3086 {
3087   if( curFotElementState().enforcingStructure() ) {
3088     curFotElementState().CurNodeInfoProlog.resize( 0 );
3089     FotElement *lastClosed = CompoundFotElement::lastClosed( curTable() );
3090     if( lastClosed != NULL )
3091       endGroup( "Node", &lastClosed->nodeInfoEpilog() );
3092     #ifdef TEXDEBUG
3093       *fileout_ << "\nEND_NODE\n";
3094     #endif
3095   } else
3096     endGroup("Node");
3097 }
3098 
startLink(const Address & addr)3099 void TeXFOTBuilder::startLink(const Address &addr)
3100 {
3101   GroveString id;
3102   unsigned long ei;
3103 
3104   // FIX ME!
3105   // This needs a lot of work -- for now, it supports only links to
3106   // elements.
3107 
3108   switch (addr.type) {
3109   case Address::none:
3110     break;
3111   case Address::resolvedNode:
3112     if (addr.node->getId(id) == accessOK) {
3113       set("Label",id);
3114     } else if (addr.node->elementIndex(ei) == accessOK) {
3115       set("Element", ei);
3116     }
3117     else {
3118       message(TeXMessages::unsupportedLinkNonElement);
3119     }
3120     break;
3121   case Address::idref:
3122 				// just the first IDREF for now
3123     set("Label",addr.params[0]);
3124     break;
3125   case Address::entity:
3126     message(TeXMessages::unsupportedLinkEntity);
3127     break;
3128   case Address::sgmlDocument:
3129     message(TeXMessages::unsupportedLinkSgmlDoc);
3130     break;
3131   case Address::hytimeLinkend:
3132     message(TeXMessages::unsupportedLinkHyTime);
3133     break;
3134   case Address::tei:
3135     message(TeXMessages::unsupportedLinkTei);
3136     break;
3137   case Address::html:
3138     message(TeXMessages::unsupportedLinkHtml);
3139     break;
3140   }
3141   if (addr.node) {
3142     unsigned long g = addr.node->groveIndex();
3143     if (g) {
3144       set("GroveIndex",g);
3145     }
3146   }
3147   startGroup("Link");
3148 }
3149 
endLink()3150 void TeXFOTBuilder::endLink()
3151 {
3152   endGroup("Link");
3153 }
3154 
3155 /////////////////////////////////////////////////////////////////////
3156 // Inherited characteristics
3157 // Set the value of the characteristic for the next flow object.
3158 // Inherited characteristics that are not explicitly set have
3159 // the same value as the parent flow object.
3160 //////////////////////////////////////////////////////////////////////
3161 
setFontSize(Length size)3162 void TeXFOTBuilder::setFontSize(Length size)
3163 {
3164   setlength("fSize",size);
3165 }
3166 
setFontFamilyName(const StringC & name)3167 void TeXFOTBuilder::setFontFamilyName(const StringC &name)
3168 {
3169   stringout_ << "\\def\\fFamName{";
3170   for (size_t i = 0; i < name.size(); i++)
3171     {
3172       switch(name[i]) {
3173       case ' ':
3174 	stringout_ << '-';
3175         break;
3176       default:
3177 	stringout_ << char(name[i]);
3178 	break;
3179        }
3180       }
3181       stringout_ << "}";
3182 }
3183 
setFontWeight(Symbol weight)3184 void TeXFOTBuilder::setFontWeight(Symbol weight)
3185 {
3186   set("fWeight",weight);
3187 }
3188 
setFontPosture(Symbol posture)3189 void TeXFOTBuilder::setFontPosture(Symbol posture)
3190 {
3191   set("fPosture",posture);
3192 }
3193 
setStartIndent(const LengthSpec & indent)3194 void TeXFOTBuilder::setStartIndent(const LengthSpec &indent)
3195 {
3196   NextFormat.FotStartIndentSpec = indent;
3197   set("StartIndent",indent);
3198 }
3199 
setEndIndent(const LengthSpec & indent)3200 void TeXFOTBuilder::setEndIndent(const LengthSpec &indent)
3201 {
3202   NextFormat.FotEndIndentSpec = indent;
3203   set("EndIndent",indent);
3204 }
3205 
setFirstLineStartIndent(const LengthSpec & indent)3206 void TeXFOTBuilder::setFirstLineStartIndent(const LengthSpec &indent)
3207 {
3208   set("FirstLineStartIndent",indent);
3209 }
3210 
setLastLineEndIndent(const LengthSpec & indent)3211 void TeXFOTBuilder::setLastLineEndIndent(const LengthSpec &indent)
3212 {
3213   set("LastLineEndIndent",indent);
3214 }
3215 
setLineSpacing(const LengthSpec & spacing)3216 void TeXFOTBuilder::setLineSpacing(const LengthSpec &spacing)
3217 {
3218   set("LineSpacing",spacing);
3219 }
3220 
setFieldWidth(const LengthSpec & width)3221 void TeXFOTBuilder::setFieldWidth(const LengthSpec &width)
3222 {
3223   set("FieldWidth",width);
3224 }
3225 
setMarginaliaSep(const LengthSpec & sep)3226 void TeXFOTBuilder::setMarginaliaSep(const LengthSpec &sep)
3227 {
3228   set("MarginaliaSep",sep);
3229 }
3230 
setLines(Symbol lines)3231 void TeXFOTBuilder::setLines(Symbol lines)
3232 {
3233   NextFormat.FotLines = lines;
3234   set("Lines",lines);
3235 }
3236 
setQuadding(Symbol quadding)3237 void TeXFOTBuilder::setQuadding(Symbol quadding)
3238 {
3239   set("Quadding",quadding);
3240 }
3241 
setDisplayAlignment(Symbol align)3242 void TeXFOTBuilder::setDisplayAlignment(Symbol align)
3243 {
3244   NextFormat.FotDisplayAlignment = align;
3245   set("DisplayAlignment",align);
3246 }
3247 
setFieldAlign(Symbol align)3248 void TeXFOTBuilder::setFieldAlign(Symbol align)
3249 {
3250   set("FieldAlign",align);
3251 }
3252 
setColor(const DeviceRGBColor & color)3253 void TeXFOTBuilder::setColor(const DeviceRGBColor &color)
3254 {
3255   set("Color",color);
3256 }
3257 
setBackgroundColor()3258 void TeXFOTBuilder::setBackgroundColor()
3259 {
3260   set("BackgroundColor",symbolFalse);
3261 }
3262 
setBackgroundColor(const DeviceRGBColor & color)3263 void TeXFOTBuilder::setBackgroundColor(const DeviceRGBColor &color)
3264 {
3265   NextFormat.FotBackgroundColor = color;
3266   set("BackgroundColor",color);
3267 }
3268 
setBorderPresent(bool flag)3269 void TeXFOTBuilder::setBorderPresent(bool flag)
3270 {
3271   NextFormat.FotBorderPresent = flag;
3272   set("BorderPresent",flag);
3273 }
3274 
setLineThickness(Length thickness)3275 void TeXFOTBuilder::setLineThickness(Length thickness)
3276 {
3277   NextFormat.FotLineThickness = thickness;
3278   setlength("LineThickness",thickness);
3279 }
3280 
setCellBeforeRowMargin(Length margin)3281 void TeXFOTBuilder::setCellBeforeRowMargin(Length margin)
3282 {
3283   setlength("CellBeforeRowMargin",margin);
3284 }
3285 
setCellAfterRowMargin(Length margin)3286 void TeXFOTBuilder::setCellAfterRowMargin(Length margin)
3287 {
3288   setlength("CellAfterRowMargin",margin);
3289 }
3290 
setCellBeforeColumnMargin(Length margin)3291 void TeXFOTBuilder::setCellBeforeColumnMargin(Length margin)
3292 {
3293   NextFormat.FotCellBeforeColumnMargin = margin;
3294   setlength("CellBeforeColumnMargin",margin);
3295 }
3296 
setCellAfterColumnMargin(Length margin)3297 void TeXFOTBuilder::setCellAfterColumnMargin(Length margin)
3298 {
3299   NextFormat.FotCellAfterColumnMargin = margin;
3300   setlength("CellAfterColumnMargin",margin);
3301 }
3302 
setLineSep(Length sep)3303 void TeXFOTBuilder::setLineSep(Length sep)
3304 {
3305   NextFormat.FotLineSep = sep;
3306   setlength("LineSep",sep);
3307 }
3308 
setBoxSizeBefore(Length size)3309 void TeXFOTBuilder::setBoxSizeBefore(Length size)
3310 {
3311   setlength("BoxSizeBefore",size);
3312 }
3313 
setBoxSizeAfter(Length size)3314 void TeXFOTBuilder::setBoxSizeAfter(Length size)
3315 {
3316   setlength("BoxSizeAfter",size);
3317 }
3318 
setPositionPointShift(const LengthSpec & shift)3319 void TeXFOTBuilder::setPositionPointShift(const LengthSpec &shift)
3320 {
3321   set("PositionPointShift",shift);
3322 }
3323 
setStartMargin(const LengthSpec & margin)3324 void TeXFOTBuilder::setStartMargin(const LengthSpec &margin)
3325 {
3326   set("StartMargin",margin);
3327 }
3328 
setEndMargin(const LengthSpec & margin)3329 void TeXFOTBuilder::setEndMargin(const LengthSpec &margin)
3330 {
3331   set("EndMargin",margin);
3332 }
3333 
setSidelineSep(const LengthSpec & sep)3334 void TeXFOTBuilder::setSidelineSep(const LengthSpec &sep)
3335 {
3336   set("SidelineSep",sep);
3337 }
3338 
setAsisWrapIndent(const LengthSpec & indent)3339 void TeXFOTBuilder::setAsisWrapIndent(const LengthSpec &indent)
3340 {
3341   set("AsisWrapIndent",indent);
3342 }
3343 
setLineNumberSep(const LengthSpec & sep)3344 void TeXFOTBuilder::setLineNumberSep(const LengthSpec &sep)
3345 {
3346   set("LineNumberSep",sep);
3347 }
3348 
setLastLineJustifyLimit(const LengthSpec & limit)3349 void TeXFOTBuilder::setLastLineJustifyLimit(const LengthSpec &limit)
3350 {
3351   set("LastLineJustifyLimit",limit);
3352 }
3353 
setJustifyGlyphSpaceMaxAdd(const LengthSpec & max)3354 void TeXFOTBuilder::setJustifyGlyphSpaceMaxAdd(const LengthSpec &max)
3355 {
3356   set("JustifyGlyphSpaceMaxAdd",max);
3357 }
3358 
setJustifyGlyphSpaceMaxRemove(const LengthSpec & max)3359 void TeXFOTBuilder::setJustifyGlyphSpaceMaxRemove(const LengthSpec &max)
3360 {
3361   set("JustifyGlyphSpaceMaxRemove",max);
3362 }
3363 
setTableCornerRadius(const LengthSpec & radius)3364 void TeXFOTBuilder::setTableCornerRadius(const LengthSpec &radius)
3365 {
3366   set("TableCornerRadius",radius);
3367 }
3368 
setBoxCornerRadius(const LengthSpec & radius)3369 void TeXFOTBuilder::setBoxCornerRadius(const LengthSpec &radius)
3370 {
3371   set("BoxCornerRadius",radius);
3372 }
3373 
setInhibitLineBreaks(bool flag)3374 void TeXFOTBuilder::setInhibitLineBreaks(bool flag)
3375 {
3376   set("InhibitLineBreaks",flag);
3377 }
3378 
setHyphenate(bool flag)3379 void TeXFOTBuilder::setHyphenate(bool flag)
3380 {
3381   set("Hyphenate",flag);
3382 }
3383 
setKern(bool flag)3384 void TeXFOTBuilder::setKern(bool flag)
3385 {
3386   set("Kern",flag);
3387 }
3388 
setLigature(bool flag)3389 void TeXFOTBuilder::setLigature(bool flag)
3390 {
3391   set("Ligature",flag);
3392 }
3393 
setScoreSpaces(bool flag)3394 void TeXFOTBuilder::setScoreSpaces(bool flag)
3395 {
3396   set("ScoreSpaces",flag);
3397 }
3398 
setFloatOutMarginalia(bool flag)3399 void TeXFOTBuilder::setFloatOutMarginalia(bool flag)
3400 {
3401   set("FloatOutMarginalia",flag);
3402 }
3403 
setFloatOutSidelines(bool flag)3404 void TeXFOTBuilder::setFloatOutSidelines(bool flag)
3405 {
3406   set("FloatOutSidelines",flag);
3407 }
3408 
setFloatOutLineNumbers(bool flag)3409 void TeXFOTBuilder::setFloatOutLineNumbers(bool flag)
3410 {
3411   set("FloatOutLineNumbers",flag);
3412 }
3413 
setCellBackground(bool flag)3414 void TeXFOTBuilder::setCellBackground(bool flag)
3415 {
3416   NextFormat.FotCellBackground = flag;
3417   set("CellBackground",flag);
3418 }
3419 
setSpanWeak(bool flag)3420 void TeXFOTBuilder::setSpanWeak(bool flag)
3421 {
3422   set("SpanWeak",flag);
3423 }
3424 
setIgnoreRecordEnd(bool flag)3425 void TeXFOTBuilder::setIgnoreRecordEnd(bool flag)
3426 {
3427   set("IgnoreRecordEnd",flag);
3428 }
3429 
setNumberedLines(bool flag)3430 void TeXFOTBuilder::setNumberedLines(bool flag)
3431 {
3432   set("NumberedLines",flag);
3433 }
3434 
setHangingPunct(bool flag)3435 void TeXFOTBuilder::setHangingPunct(bool flag)
3436 {
3437   set("HangingPunct",flag);
3438 }
3439 
setBoxOpenEnd(bool flag)3440 void TeXFOTBuilder::setBoxOpenEnd(bool flag)
3441 {
3442   set("BoxOpenEnd",flag);
3443 }
3444 
setTruncateLeader(bool flag)3445 void TeXFOTBuilder::setTruncateLeader(bool flag)
3446 {
3447   set("TruncateLeader",flag);
3448 }
3449 
setAlignLeader(bool flag)3450 void TeXFOTBuilder::setAlignLeader(bool flag)
3451 {
3452   set("AlignLeader",flag);
3453 }
3454 
setTablePartOmitMiddleHeader(bool flag)3455 void TeXFOTBuilder::setTablePartOmitMiddleHeader(bool flag)
3456 {
3457   set("TablePartOmitMiddleHeader",flag);
3458 }
3459 
setTablePartOmitMiddleFooter(bool flag)3460 void TeXFOTBuilder::setTablePartOmitMiddleFooter(bool flag)
3461 {
3462   set("TablePartOmitMiddleFooter",flag);
3463 }
3464 
setBorderOmitAtBreak(bool flag)3465 void TeXFOTBuilder::setBorderOmitAtBreak(bool flag)
3466 {
3467   set("BorderOmitAtBreak",flag);
3468 }
3469 
setPrincipalModeSimultaneous(bool flag)3470 void TeXFOTBuilder::setPrincipalModeSimultaneous(bool flag)
3471 {
3472   set("PrincipalModeSimultaneous",flag);
3473 }
3474 
setMarginaliaKeepWithPrevious(bool flag)3475 void TeXFOTBuilder::setMarginaliaKeepWithPrevious(bool flag)
3476 {
3477   set("MarginaliaKeepWithPrevious",flag);
3478 }
3479 
setLineJoin(Symbol join)3480 void TeXFOTBuilder::setLineJoin(Symbol join)
3481 {
3482   set("LineJoin",join);
3483 }
3484 
setLineCap(Symbol cap)3485 void TeXFOTBuilder::setLineCap(Symbol cap)
3486 {
3487   NextFormat.FotLineCap = cap;
3488   set("LineCap",cap);
3489 }
3490 
setLineNumberSide(Symbol side)3491 void TeXFOTBuilder::setLineNumberSide(Symbol side)
3492 {
3493   set("LineNumberSide",side);
3494 }
3495 
setKernMode(Symbol mode)3496 void TeXFOTBuilder::setKernMode(Symbol mode)
3497 {
3498   set("KernMode",mode);
3499 }
3500 
setInputWhitespaceTreatment(Symbol treatment)3501 void TeXFOTBuilder::setInputWhitespaceTreatment(Symbol treatment)
3502 {
3503   set("InputWhitespaceTreatment",treatment);
3504 }
3505 
setFillingDirection(Symbol direction)3506 void TeXFOTBuilder::setFillingDirection(Symbol direction)
3507 {
3508   set("FillingDirection",direction);
3509 }
3510 
setWritingMode(Symbol mode)3511 void TeXFOTBuilder::setWritingMode(Symbol mode)
3512 {
3513   set("WritingMode",mode);
3514 }
3515 
setLastLineQuadding(Symbol quadding)3516 void TeXFOTBuilder::setLastLineQuadding(Symbol quadding)
3517 {
3518   set("LastLineQuadding",quadding);
3519 }
3520 
setMathDisplayMode(Symbol mode)3521 void TeXFOTBuilder::setMathDisplayMode(Symbol mode)
3522 {
3523   set("MathDisplayMode",mode);
3524 }
3525 
setBoxType(Symbol type)3526 void TeXFOTBuilder::setBoxType(Symbol type)
3527 {
3528   set("BoxType",type);
3529 }
3530 
setGlyphAlignmentMode(Symbol mode)3531 void TeXFOTBuilder::setGlyphAlignmentMode(Symbol mode)
3532 {
3533   set("GlyphAlignmentMode",mode);
3534 }
3535 
setBoxBorderAlignment(Symbol align)3536 void TeXFOTBuilder::setBoxBorderAlignment(Symbol align)
3537 {
3538   set("BoxBorderAlignment",align);
3539 }
3540 
setCellRowAlignment(Symbol align)3541 void TeXFOTBuilder::setCellRowAlignment(Symbol align)
3542 {
3543   NextFormat.FotCellRowAlignment = align;
3544   set("CellRowAlignment",align);
3545 }
3546 
setBorderAlignment(Symbol align)3547 void TeXFOTBuilder::setBorderAlignment(Symbol align)
3548 {
3549   set("BorderAlignment",align);
3550 }
3551 
setSidelineSide(Symbol side)3552 void TeXFOTBuilder::setSidelineSide(Symbol side)
3553 {
3554   set("SidelineSide",side);
3555 }
3556 
setHyphenationKeep(Symbol keep)3557 void TeXFOTBuilder::setHyphenationKeep(Symbol keep)
3558 {
3559   set("HyphenationKeep",keep);
3560 }
3561 
setFontStructure(Symbol structure)3562 void TeXFOTBuilder::setFontStructure(Symbol structure)
3563 {
3564   set("fStructure",structure);
3565 }
3566 
setFontProportionateWidth(Symbol width)3567 void TeXFOTBuilder::setFontProportionateWidth(Symbol width)
3568 {
3569   set("fProportionateWidth",width);
3570 }
3571 
setCellCrossed(Symbol crossed)3572 void TeXFOTBuilder::setCellCrossed(Symbol crossed)
3573 {
3574   set("CellCrossed",crossed);
3575 }
3576 
setMarginaliaSide(Symbol side)3577 void TeXFOTBuilder::setMarginaliaSide(Symbol side)
3578 {
3579   set("MarginaliaSide",side);
3580 }
3581 
setLayer(long n)3582 void TeXFOTBuilder::setLayer(long n)
3583 {
3584   set("Layer",n);
3585 }
3586 
setBackgroundLayer(long n)3587 void TeXFOTBuilder::setBackgroundLayer(long n)
3588 {
3589   set("BackgroundLayer",n);
3590 }
3591 
setBorderPriority(long n)3592 void TeXFOTBuilder::setBorderPriority(long n)
3593 {
3594   NextFormat.FotBorderPriority = n;
3595   set("BorderPriority",n);
3596 }
3597 
setLineRepeat(long n)3598 void TeXFOTBuilder::setLineRepeat(long n)
3599 {
3600   NextFormat.FotLineRepeat = n;
3601   set("LineRepeat",n);
3602 }
3603 
setSpan(long n)3604 void TeXFOTBuilder::setSpan(long n)
3605 {
3606   NextFormat.FotSpan = n;
3607   NextFormat.FotCurDisplaySize
3608     = NextFormat.FotPageWidth - NextFormat.FotLeftMargin - NextFormat.FotRightMargin;
3609   set("Span",n);
3610 }
3611 
setMinLeaderRepeat(long n)3612 void TeXFOTBuilder::setMinLeaderRepeat(long n)
3613 {
3614   set("MinLeaderRepeat",n);
3615 }
3616 
setHyphenationRemainCharCount(long n)3617 void TeXFOTBuilder::setHyphenationRemainCharCount(long n)
3618 {
3619   set("HyphenationRemainCharCount",n);
3620 }
3621 
setHyphenationPushCharCount(long n)3622 void TeXFOTBuilder::setHyphenationPushCharCount(long n)
3623 {
3624   set("HyphenationPushCharCount",n);
3625 }
3626 
setWidowCount(long n)3627 void TeXFOTBuilder::setWidowCount(long n)
3628 {
3629   set("WidowCount",n);
3630 }
3631 
setOrphanCount(long n)3632 void TeXFOTBuilder::setOrphanCount(long n)
3633 {
3634   set("OrphanCount",n);
3635 }
3636 
3637 // 0 means #f
setExpandTabs(long n)3638 void TeXFOTBuilder::setExpandTabs(long n)
3639 {
3640   set("ExpandTabs",n);
3641 }
3642 
setHyphenationLadderCount(long n)3643 void TeXFOTBuilder::setHyphenationLadderCount(long n)
3644 {
3645   set("HyphenationLadderCount",n);
3646 }
3647 
3648 // public id or #f
setBackgroundTile(PublicId id)3649 void TeXFOTBuilder::setBackgroundTile(PublicId id)
3650 {
3651   set("BackgroundTile",id);
3652 }
3653 
setLineBreakingMethod(PublicId id)3654 void TeXFOTBuilder::setLineBreakingMethod(PublicId id)
3655 {
3656   set("LineBreakingMethod",id);
3657 }
3658 
setLineCompositionMethod(PublicId id)3659 void TeXFOTBuilder::setLineCompositionMethod(PublicId id)
3660 {
3661   set("LineCompositionMethod",id);
3662 }
3663 
setImplicitBidiMethod(PublicId id)3664 void TeXFOTBuilder::setImplicitBidiMethod(PublicId id)
3665 {
3666   set("ImplicitBidiMethod",id);
3667 }
3668 
setGlyphSubstMethod(PublicId id)3669 void TeXFOTBuilder::setGlyphSubstMethod(PublicId id)
3670 {
3671   set("GlyphSubstMethod",id);
3672 }
3673 
setGlyphReorderMethod(PublicId id)3674 void TeXFOTBuilder::setGlyphReorderMethod(PublicId id)
3675 {
3676   set("GlyphReorderMethod",id);
3677 }
3678 
setHyphenationMethod(PublicId id)3679 void TeXFOTBuilder::setHyphenationMethod(PublicId id)
3680 {
3681   set("HyphenationMethod",id);
3682 }
3683 
setTableAutoWidthMethod(PublicId id)3684 void TeXFOTBuilder::setTableAutoWidthMethod(PublicId id)
3685 {
3686   set("TableAutoWidthMethod",id);
3687 }
3688 
setFontName(PublicId id)3689 void TeXFOTBuilder::setFontName(PublicId id)
3690 {
3691   set("fName",id);
3692 }
3693 
3694 // Two-letter code
setLanguage(Letter2 language)3695 void TeXFOTBuilder::setLanguage(Letter2 language)
3696 {
3697   setletter2("Language",language);
3698 }
3699 
setCountry(Letter2 country)3700 void TeXFOTBuilder::setCountry(Letter2 country)
3701 {
3702   setletter2("Country",country);
3703 }
3704 
3705 // For simple page sequence
setPageWidth(Length width)3706 void TeXFOTBuilder::setPageWidth(Length width)
3707 {
3708   NextFormat.FotPageWidth = width;
3709   setlength("PageWidth",width);
3710 }
3711 
setPageHeight(Length height)3712 void TeXFOTBuilder::setPageHeight(Length height)
3713 {
3714   setlength("PageHeight",height);
3715 }
3716 
setLeftMargin(Length margin)3717 void TeXFOTBuilder::setLeftMargin(Length margin)
3718 {
3719   NextFormat.FotLeftMargin = margin;
3720   setlength("LeftMargin",margin);
3721 }
3722 
setRightMargin(Length margin)3723 void TeXFOTBuilder::setRightMargin(Length margin)
3724 {
3725   NextFormat.FotRightMargin = margin;
3726   setlength("RightMargin",margin);
3727 }
3728 
setTopMargin(Length margin)3729 void TeXFOTBuilder::setTopMargin(Length margin)
3730 {
3731   setlength("TopMargin",margin);
3732 }
3733 
setBottomMargin(Length margin)3734 void TeXFOTBuilder::setBottomMargin(Length margin)
3735 {
3736   setlength("BottomMargin",margin);
3737 }
3738 
setHeaderMargin(Length margin)3739 void TeXFOTBuilder::setHeaderMargin(Length margin)
3740 {
3741   setlength("HeaderMargin",margin);
3742 }
3743 
setFooterMargin(Length margin)3744 void TeXFOTBuilder::setFooterMargin(Length margin)
3745 {
3746   setlength("FooterMargin",margin);
3747 }
3748 
3749 				// New inherited characteristics
3750 				// added 1 March/97 with math support.
setMinPreLineSpacing(const OptLengthSpec & len)3751 void TeXFOTBuilder::setMinPreLineSpacing(const OptLengthSpec &len)
3752 {
3753   set("MinPreLineSpacing",len);
3754 }
3755 
3756 
setMinPostLineSpacing(const OptLengthSpec & len)3757 void TeXFOTBuilder::setMinPostLineSpacing(const OptLengthSpec &len)
3758 {
3759   set("MinPostLineSpacing",len);
3760 }
3761 
3762 
setMinLeading(const OptLengthSpec & len)3763 void TeXFOTBuilder::setMinLeading(const OptLengthSpec &len)
3764 {
3765   set("MinLeading",len);
3766 }
3767 
3768 
setScriptPreAlign(Symbol sym)3769 void TeXFOTBuilder::setScriptPreAlign(Symbol sym)
3770 {
3771   set("ScriptPreAlign",sym);
3772 }
3773 
3774 
setScriptPostAlign(Symbol sym)3775 void TeXFOTBuilder::setScriptPostAlign(Symbol sym)
3776 {
3777   set("ScriptPostAlign",sym);
3778 }
3779 
3780 
setScriptMidSupAlign(Symbol sym)3781 void TeXFOTBuilder::setScriptMidSupAlign(Symbol sym)
3782 {
3783   set("ScriptMidSupAlign",sym);
3784 }
3785 
3786 
setScriptMidSubAlign(Symbol sym)3787 void TeXFOTBuilder::setScriptMidSubAlign(Symbol sym)
3788 {
3789   set("ScriptMidSubAlign",sym);
3790 }
3791 
3792 
setNumeratorAlign(Symbol sym)3793 void TeXFOTBuilder::setNumeratorAlign(Symbol sym)
3794 {
3795   set("NumeratorAlign",sym);
3796 }
3797 
3798 
setDenominatorAlign(Symbol sym)3799 void TeXFOTBuilder::setDenominatorAlign(Symbol sym)
3800 {
3801   set("DenominatorAlign",sym);
3802 }
3803 
3804 
setGridPositionCellType(Symbol sym)3805 void TeXFOTBuilder::setGridPositionCellType(Symbol sym)
3806 {
3807   set("GridPositionCellType",sym);
3808 }
3809 
3810 
setGridColumnAlignment(Symbol sym)3811 void TeXFOTBuilder::setGridColumnAlignment(Symbol sym)
3812 {
3813   set("GridColumnAlignment",sym);
3814 }
3815 
3816 
setGridRowAlignment(Symbol sym)3817 void TeXFOTBuilder::setGridRowAlignment(Symbol sym)
3818 {
3819   set("GridRowAlignment",sym);
3820 }
3821 
3822 
setGridEquidistantRows(bool flag)3823 void TeXFOTBuilder::setGridEquidistantRows(bool flag)
3824 {
3825   set("GridEquidistantRows",flag);
3826 }
3827 
3828 
setGridEquidistantColumns(bool flag)3829 void TeXFOTBuilder::setGridEquidistantColumns(bool flag)
3830 {
3831   set("GridEquidistantColumns",flag);
3832 }
3833 
3834 
setEscapementSpaceBefore(const InlineSpace & space)3835 void TeXFOTBuilder::setEscapementSpaceBefore(const InlineSpace &space)
3836 {
3837   set("EscapementSpaceBefore",space);
3838 }
3839 
3840 
setEscapementSpaceAfter(const InlineSpace & space)3841 void TeXFOTBuilder::setEscapementSpaceAfter(const InlineSpace &space)
3842 {
3843   set("EscapementSpaceAfter",space);
3844 }
3845 
3846 
setInlineSpaceSpace(const OptInlineSpace & space)3847 void TeXFOTBuilder::setInlineSpaceSpace(const OptInlineSpace &space)
3848 {
3849   set("InlineSpaceSpace",space);
3850 }
3851 
3852 
setGlyphSubstTable(const Vector<ConstPtr<GlyphSubstTable>> &)3853 void TeXFOTBuilder::setGlyphSubstTable(const Vector<ConstPtr<GlyphSubstTable> > &)
3854 {
3855   // FIX ME!
3856   message(TeXMessages::unsupportedGlyphSubstTable);
3857   // set("GlyphSubstTable",tables);
3858 }
3859 
3860 ////////////////////////////////////////////////////////////////////////
3861 // Private member functions.
3862 ////////////////////////////////////////////////////////////////////////
3863 
3864 //
3865 // Insert an atomic flow object.
3866 //
insertAtomic(const char * name)3867 void TeXFOTBuilder::insertAtomic(const char *name)
3868 {
3869   os() << "\\insert" << name << "%\n{";
3870   dumpInherited();
3871   os() << '}';
3872 }
3873 
insertAtomic(TeXFOTBuilder::FotElement & fotElement)3874 void TeXFOTBuilder::insertAtomic( TeXFOTBuilder::FotElement &fotElement )
3875 {
3876   stringout_.extractString( fotElement.Characteristics );
3877 }
3878 
3879 //
3880 // Start a non-atomic flow object.
3881 //
startGroup(const char * name,String<char> * output)3882 void TeXFOTBuilder::startGroup(const char *name, String<char> *output )
3883 {
3884   if( output ) {
3885     String<char> s;
3886     stringout_.extractString( s );
3887     StrOutputByteStream out;
3888     out << "\\" << name << "%\n{" << s << '}';
3889     out.extractString( s );
3890     *output += s;
3891   } else {
3892     os() << "\\" << name << "%\n{";
3893     dumpInherited();
3894     os() << '}';
3895   }
3896 }
3897 
startGroup(TeXFOTBuilder::FotElement & fotElement)3898 void TeXFOTBuilder::startGroup( TeXFOTBuilder::FotElement &fotElement ) {
3899 
3900   stringout_.extractString( fotElement.Characteristics );
3901 }
3902 
3903 //
3904 // Start a non-atomic flow object, with the content delimited by braces,
3905 // but no macro name at all; we just emit all the characteristics in
3906 // the stream after the brace.
3907 //
startSimpleGroup(const char * name,String<char> * output)3908 void TeXFOTBuilder::startSimpleGroup(const char *name, String<char> *output )
3909 {
3910   if( output ) {
3911     String<char> s;
3912     stringout_.extractString( s );
3913     StrOutputByteStream out;
3914     out << "%\n{" << s ;
3915     out.extractString( s );
3916     *output += s;
3917   } else {
3918     os() << "%\n{";
3919     dumpInherited();
3920   }
3921 }
3922 
3923 //
3924 // End with just a closing brace
3925 //
endSimpleGroup(String<char> * output)3926 void TeXFOTBuilder::endSimpleGroup(String<char> *output )
3927 {
3928   if( output ) {
3929     StrOutputByteStream out;
3930     out << "}";
3931     String<char> s;
3932     out.extractString( s );
3933     *output += s;
3934   }
3935   else
3936     os() << "}";
3937 }
3938 //
3939 // Stop and start a brace, but note characteristics
3940 //
closeopenBrace(const char * name,String<char> * output)3941 void TeXFOTBuilder::closeopenBrace(const char *name, String<char> *output )
3942 {
3943   if( output ) {
3944     String<char> s;
3945     stringout_.extractString( s );
3946     StrOutputByteStream out;
3947     out << "}{" << s ;
3948     out.extractString( s );
3949     *output += s;
3950   } else {
3951     os() << "}{";
3952     dumpInherited();
3953   }
3954 }
3955 //
3956 // Start a non-atomic flow object, with the content delimited by braces
3957 //
startBrace(const char * name,String<char> * output)3958 void TeXFOTBuilder::startBrace(const char *name, String<char> *output )
3959 {
3960   if( output ) {
3961     String<char> s;
3962     stringout_.extractString( s );
3963     StrOutputByteStream out;
3964     out << "\\" << name << "%\n{" << s << "}{";
3965     out.extractString( s );
3966     *output += s;
3967   } else {
3968     os() << "\\" << name << "%\n{";
3969     dumpInherited();
3970     os() << "}{";
3971   }
3972 }
3973 
3974 //
3975 // End a non-atomic flow object with just a closing brace
3976 //
endBrace(const char * name,String<char> * output)3977 void TeXFOTBuilder::endBrace(const char *name, String<char> *output )
3978 {
3979   if( output ) {
3980     StrOutputByteStream out;
3981     out << "}";
3982     String<char> s;
3983     out.extractString( s );
3984     *output += s;
3985   }
3986   else
3987     os() << "}";
3988 }
3989 
3990 //
3991 // End a non-atomic flow object.
3992 //
endGroup(const char * name,String<char> * output)3993 void TeXFOTBuilder::endGroup(const char *name, String<char> *output )
3994 {
3995   if( output ) {
3996     StrOutputByteStream out;
3997     out << "\\end" << name << "{}";
3998     String<char> s;
3999     out.extractString( s );
4000     *output += s;
4001   }
4002   else
4003     os() << "\\end" << name << "{}";
4004 }
4005 
4006 //
4007 // Set a Length (needs a different name to avoid conflict
4008 // with long.
4009 //
setlength(const char * name,Length size)4010 void TeXFOTBuilder::setlength(const char *name,Length size)
4011 {
4012   stringout_ << "\\def\\" << name << "%\n{"
4013 	      << float(size/1000.0)
4014 	      << "\\p@}";
4015 }
4016 
4017 //
4018 // Set a StringC.
4019 //
set(const char * name,const StringC & value)4020 void TeXFOTBuilder::set(const char *name,const StringC &value)
4021 {
4022   stringout_ << "\\def\\" << name << "%\n{"
4023 	      << value
4024 	      << '}';
4025 }
4026 
4027 //
4028 // Set a GroveString
4029 //
set(const char * name,const GroveString & value)4030 void TeXFOTBuilder::set(const char *name,const GroveString &value)
4031 {
4032   stringout_ << "\\def\\" << name << "%\n{"
4033 	      << value
4034 	      << '}';
4035 }
4036 
4037 //
4038 // Set a Symbol.
4039 //
set(const char * name,Symbol sym)4040 void TeXFOTBuilder::set(const char *name,Symbol sym)
4041 {
4042   const char * symbolName = "";
4043 
4044   switch (sym) {
4045   case symbolFalse:
4046     symbolName = "false";
4047     break;
4048   case symbolTrue:
4049     symbolName = "true";
4050     break;
4051   case symbolNotApplicable:
4052     symbolName = "notapplicable";
4053     break;
4054   case symbolUltraCondensed:
4055     symbolName = "ultracondensed";
4056     break;
4057   case symbolExtraCondensed:
4058     symbolName = "extracondensed";
4059     break;
4060   case symbolCondensed:
4061     symbolName = "condensed";
4062     break;
4063   case symbolSemiCondensed:
4064     symbolName = "semicondensed";
4065     break;
4066   case symbolUltraLight:
4067     symbolName = "ultralight";
4068     break;
4069   case symbolExtraLight:
4070     symbolName = "extralight";
4071     break;
4072   case symbolLight:
4073     symbolName = "light";
4074     break;
4075   case symbolSemiLight:
4076     symbolName = "semilight";
4077     break;
4078   case symbolMedium:
4079     symbolName = "medium";
4080     break;
4081   case symbolSemiExpanded:
4082     symbolName = "semiexpanded";
4083     break;
4084   case symbolExpanded:
4085     symbolName = "expanded";
4086     break;
4087   case symbolExtraExpanded:
4088     symbolName = "extraexpanded";
4089     break;
4090   case symbolUltraExpanded:
4091     symbolName = "ultraexpanded";
4092     break;
4093   case symbolSemiBold:
4094     symbolName = "semibold";
4095     break;
4096   case symbolBold:
4097     symbolName = "bold";
4098     break;
4099   case symbolExtraBold:
4100     symbolName = "extrabold";
4101     break;
4102   case symbolUltraBold:
4103     symbolName = "ultrabold";
4104     break;
4105   case symbolUpright:
4106     symbolName = "upright";
4107     break;
4108   case symbolOblique:
4109     symbolName = "oblique";
4110     break;
4111   case symbolBackSlantedOblique:
4112     symbolName = "backslantedoblique";
4113     break;
4114   case symbolItalic:
4115     symbolName = "italic";
4116     break;
4117   case symbolBackSlantedItalic:
4118     symbolName = "backslanteditalic";
4119     break;
4120   case symbolStart:
4121     symbolName = "start";
4122     break;
4123   case symbolEnd:
4124     symbolName = "end";
4125     break;
4126   case symbolCenter:
4127     symbolName = "center";
4128     break;
4129   case symbolJustify:
4130     symbolName = "justify";
4131     break;
4132   case symbolSpreadInside:
4133     symbolName = "spreadinside";
4134     break;
4135   case symbolSpreadOutside:
4136     symbolName = "spreadoutside";
4137     break;
4138   case symbolPageInside:
4139     symbolName = "pageinside";
4140     break;
4141   case symbolPageOutside:
4142     symbolName = "pageoutside";
4143     break;
4144   case symbolWrap:
4145     symbolName = "wrap";
4146     break;
4147   case symbolAsis:
4148     symbolName = "asis";
4149     break;
4150   case symbolAsisWrap:
4151     symbolName = "asiswrap";
4152     break;
4153   case symbolAsisTruncate:
4154     symbolName = "asistruncate";
4155     break;
4156   case symbolNone:
4157     symbolName = "none";
4158     break;
4159   case symbolBefore:
4160     symbolName = "before";
4161     break;
4162   case symbolThrough:
4163     symbolName = "through";
4164     break;
4165   case symbolAfter:
4166     symbolName = "after";
4167     break;
4168   case symbolTopToBottom:
4169     symbolName = "toptobottom";
4170     break;
4171   case symbolLeftToRight:
4172     symbolName = "lefttoright";
4173     break;
4174   case symbolBottomToTop:
4175     symbolName = "bottomtotop";
4176     break;
4177   case symbolRightToLeft:
4178     symbolName = "righttoleft";
4179     break;
4180   case symbolInside:
4181     symbolName = "inside";
4182     break;
4183   case symbolOutside:
4184     symbolName = "outside";
4185     break;
4186   case symbolHorizontal:
4187     symbolName = "horizontal";
4188     break;
4189   case symbolVertical:
4190     symbolName = "vertical";
4191     break;
4192   case symbolEscapement:
4193     symbolName = "escapement";
4194     break;
4195   case symbolLineProgression:
4196     symbolName = "lineprogression";
4197     break;
4198   case symbolMath:
4199     symbolName = "math";
4200     break;
4201   case symbolOrdinary:
4202     symbolName = "ordinary";
4203     break;
4204   case symbolOperator:
4205     symbolName = "operator";
4206     break;
4207   case symbolBinary:
4208     symbolName = "binary";
4209     break;
4210   case symbolRelation:
4211     symbolName = "relation";
4212     break;
4213   case symbolOpening:
4214     symbolName = "opening";
4215     break;
4216   case symbolClosing:
4217     symbolName = "closing";
4218     break;
4219   case symbolPunctuation:
4220     symbolName = "punctuation";
4221     break;
4222   case symbolInner:
4223     symbolName = "inner";
4224     break;
4225   case symbolSpace:
4226     symbolName = "space";
4227     break;
4228   case symbolPage:
4229     symbolName = "page";
4230     break;
4231   case symbolPageRegion:
4232     symbolName = "pageregion";
4233     break;
4234   case symbolColumnSet:
4235     symbolName = "columnset";
4236     break;
4237   case symbolColumn:
4238     symbolName = "column";
4239     break;
4240   case symbolMax:
4241     symbolName = "max";
4242     break;
4243   case symbolMaxUniform:
4244     symbolName = "maxuniform";
4245     break;
4246   case symbolMiter:
4247     symbolName = "miter";
4248     break;
4249   case symbolRound:
4250     symbolName = "round";
4251     break;
4252   case symbolBevel:
4253     symbolName = "bevel";
4254     break;
4255   case symbolButt:
4256     symbolName = "butt";
4257     break;
4258   case symbolSquare:
4259     symbolName = "square";
4260     break;
4261   case symbolLoose:
4262     symbolName = "loose";
4263     break;
4264   case symbolNormal:
4265     symbolName = "normal";
4266     break;
4267   case symbolKern:
4268     symbolName = "kern";
4269     break;
4270   case symbolTight:
4271     symbolName = "tight";
4272     break;
4273   case symbolTouch:
4274     symbolName = "touch";
4275     break;
4276   case symbolPreserve:
4277     symbolName = "preserve";
4278     break;
4279   case symbolCollapse:
4280     symbolName = "collapse";
4281     break;
4282   case symbolIgnore:
4283     symbolName = "ignore";
4284     break;
4285   case symbolRelative:
4286     symbolName = "relative";
4287     break;
4288   case symbolDisplay:
4289     symbolName = "display";
4290     break;
4291   case symbolInline:
4292     symbolName = "inline";
4293     break;
4294   case symbolBorder:
4295     symbolName = "border";
4296     break;
4297   case symbolBackground:
4298     symbolName = "background";
4299     break;
4300   case symbolBoth:
4301     symbolName = "both";
4302     break;
4303   case symbolBase:
4304     symbolName = "base";
4305     break;
4306   case symbolFont:
4307     symbolName = "font";
4308     break;
4309   case symbolTop:
4310     symbolName = "top";
4311     break;
4312   case symbolBottom:
4313     symbolName = "bottom";
4314     break;
4315   case symbolSpread:
4316     symbolName = "spread";
4317     break;
4318   case symbolSolid:
4319     symbolName = "solid";
4320     break;
4321   case symbolOutline:
4322     symbolName = "outline";
4323     break;
4324   case symbolWith:
4325     symbolName = "with";
4326     break;
4327   case symbolAgainst:
4328     symbolName = "against";
4329     break;
4330   case symbolForce:
4331     symbolName = "force";
4332     break;
4333   case symbolIndependent:
4334     symbolName = "independent";
4335     break;
4336   case symbolPile:
4337     symbolName = "pile";
4338     break;
4339   case symbolSupOut:
4340     symbolName = "supout";
4341     break;
4342   case symbolSubOut:
4343     symbolName = "subout";
4344     break;
4345   case symbolLeadEdge:
4346     symbolName = "leadedge";
4347     break;
4348   case symbolTrailEdge:
4349     symbolName = "trailedge";
4350     break;
4351   case symbolExplicit:
4352     symbolName = "explicit";
4353     break;
4354   case symbolRowMajor:
4355     symbolName = "rowmajor";
4356     break;
4357   case symbolColumnMajor:
4358     symbolName = "columnmajor";
4359     break;
4360   }
4361 
4362   stringout_ << "\\def\\" << name << "%\n{" << symbolName << '}';
4363 }
4364 
4365 //
4366 // Set a LengthSpec.
4367 //
set(const char * name,const LengthSpec & spec)4368 void TeXFOTBuilder::set(const char *name,const LengthSpec &spec)
4369 {
4370   stringout_ << "\\def\\" << name << "%\n{"
4371 	      << float(spec.length/1000.0)
4372 	      << "\\p@}";
4373   stringout_ << "\\def\\" << name << "Factor%\n{"
4374 	      << spec.displaySizeFactor
4375 	      << '}';
4376 }
4377 
4378 //
4379 // Set a double.
4380 //
set(const char * name,double n)4381 void TeXFOTBuilder::set(const char *name,double n)
4382 {
4383   stringout_ << "\\def\\" << name << "%\n{" << n << '}';
4384 }
4385 
4386 //
4387 // Set a DeviceRGBColor.
4388 //
set(const char * name,const DeviceRGBColor & color)4389 void TeXFOTBuilder::set(const char *name, const DeviceRGBColor &color)
4390 {
4391   stringout_ << "\\def\\" << name << "Red%\n{" << int(color.red) << '}';
4392   stringout_ << "\\def\\" << name << "Green%\n{" << int(color.green) << '}';
4393   stringout_ << "\\def\\" << name << "Blue%\n{" << int(color.blue) << '}';
4394 }
4395 
4396 //
4397 // Set a bool.
4398 //
set(const char * name,bool flag)4399 void TeXFOTBuilder::set(const char *name,bool flag)
4400 {
4401   stringout_ << "\\def\\" << name << "%\n{"
4402 	      << (flag ? 1 : 0)
4403 	      << '}';
4404 }
4405 
4406 //
4407 // Set a long.
4408 //
set(const char * name,long n)4409 void TeXFOTBuilder::set(const char *name,long n)
4410 {
4411   stringout_ << "\\def\\" << name << "%\n{" << n << '}';
4412 }
4413 
4414 //
4415 // Set an unsigned long.
4416 //
set(const char * name,long unsigned int n)4417 void TeXFOTBuilder::set(const char *name,long unsigned int n)
4418 {
4419   stringout_ << "\\def\\" << name << "%\n{" << n << '}';
4420 }
4421 
4422 //
4423 // Set a PublicId.
4424 //
set(const char * name,PublicId id)4425 void TeXFOTBuilder::set(const char *name,PublicId id)
4426 {
4427   stringout_ << "\\def\\" << name << "%\n{" << id << '}';
4428 }
4429 
4430 //
4431 // Set a Letter2.
4432 //
setletter2(const char * name,Letter2 code)4433 void TeXFOTBuilder::setletter2(const char *name,Letter2 code)
4434 {
4435   char letter1 = (code & 0xff00) >> 8;
4436   char letter2 = (code & 0xff);
4437   stringout_ << "\\def\\" << name << "%\n{" << letter1 << letter2 << '}';
4438 }
4439 
4440 //
4441 // This one is a problem because it duplications functionality from
4442 // above.
4443 //
set(const char * name,const DisplaySpace & space)4444 void TeXFOTBuilder::set(const char *name,const DisplaySpace &space)
4445 {
4446   if (space.nominal.length != 0 || space.min.length != 0
4447       || space.max.length != 0) {
4448     stringout_ << "\\def\\" << name << "Nom%\n{"
4449 		<< (space.nominal.length/1000.0) << "\\p@}";
4450     if (space.nominal.displaySizeFactor != 0)
4451       stringout_ << "\\def\\" << name << "NomFactor%\n{"
4452 		  << space.nominal.displaySizeFactor << '}';
4453     if (space.min.length != 0)
4454       stringout_ << "\\def\\" << name << "Min%\n{"
4455 		  << (space.min.length/1000.0) << "\\p@}";
4456     if (space.min.displaySizeFactor != 0)
4457       stringout_ << "\\def\\" << name << "MinFactor%\n{"
4458 		  << space.min.displaySizeFactor << '}';
4459     if (space.max.length != 0)
4460       stringout_ << "\\def\\" << name << "Max%\n{"
4461 		  << (space.max.length/1000.0) << "\\p@}";
4462     if (space.max.displaySizeFactor != 0)
4463       stringout_ << "\\def\\" << name << "MaxFactor%\n{"
4464 		  << space.max.displaySizeFactor << '}';
4465     if (space.priority != 0)
4466       stringout_ << "\\def\\" << name << "Priority%\n{"
4467 		  << space.priority << '}';
4468     if (space.conditional)
4469       stringout_ << "\\def\\" << name << "Conditional%\n{"
4470 		  << (space.conditional ? 1 : 0) << '}';
4471     if (space.force)
4472       stringout_ << "\\def\\" << name << "Force%\n{"
4473 		  << (space.force ? 1 : 0) << '}';
4474   }
4475 }
4476 
set(const char * name,const GlyphId & glyphId)4477 void TeXFOTBuilder::set(const char *name,const GlyphId &glyphId)
4478 {
4479   stringout_ << "\\def\\" << name << "%\n{";
4480   if (glyphId.publicId) {
4481     stringout_ << glyphId.publicId;
4482     if (glyphId.suffix)
4483       stringout_ << "::" << glyphId.suffix;
4484   }
4485   stringout_ << '}';
4486 }
4487 
set(const char * name,const OptLengthSpec & spec)4488 void TeXFOTBuilder::set(const char *name,const OptLengthSpec &spec)
4489 {
4490   if (spec.hasLength) {
4491     set(name,spec.length);
4492   }
4493 }
4494 
set(const char * name,const OptInlineSpace & spec)4495 void TeXFOTBuilder::set(const char *name,const OptInlineSpace &spec)
4496 {
4497   if (spec.hasSpace) {
4498     set(name,spec.space);
4499   }
4500 }
4501 
4502 // This one is also a problem because it duplicates functionality.
set(const char * name,const InlineSpace & space)4503 void TeXFOTBuilder::set(const char *name,const InlineSpace &space)
4504 {
4505   if (space.nominal.length != 0 || space.min.length != 0
4506       || space.max.length != 0) {
4507     stringout_ << "\\def\\" << name << "Nom%\n{"
4508 		<< (space.nominal.length/1000.0) << "\\p@}";
4509     if (space.nominal.displaySizeFactor != 0)
4510       stringout_ << "\\def\\" << name << "NomFactor%\n{"
4511 		  << space.nominal.displaySizeFactor << '}';
4512     if (space.min.length != 0)
4513       stringout_ << "\\def\\" << name << "Min%\n{"
4514 		  << (space.min.length/1000.0) << "\\p@}";
4515     if (space.min.displaySizeFactor != 0)
4516       stringout_ << "\\def\\" << name << "MinFactor%\n{"
4517 		  << space.min.displaySizeFactor << '}';
4518     if (space.max.length != 0)
4519       stringout_ << "\\def\\" << name << "Max%\n{"
4520 		  << (space.max.length/1000.0) << "\\p@}";
4521     if (space.max.displaySizeFactor != 0)
4522       stringout_ << "\\def\\" << name << "MaxFactor%\n{"
4523 		  << space.max.displaySizeFactor << '}';
4524   }
4525 }
4526 
4527 //
4528 // Structures for non-inherited characters, in the order specified
4529 // in /style/FOTBuilder.h.
4530 //
4531 
setDisplayNIC(const DisplayNIC & nic)4532 void TeXFOTBuilder::setDisplayNIC(const DisplayNIC &nic)
4533 {
4534   set("sb",nic.spaceBefore);
4535   set("sa",nic.spaceAfter);
4536   MAYBESET("PositionPreference",nic.positionPreference,symbolFalse);
4537   MAYBESET("Keep",nic.keep,symbolFalse);
4538   MAYBESET("BreakBefore",nic.breakBefore,symbolFalse);
4539   MAYBESET("BreakAfter",nic.breakAfter,symbolFalse);
4540   MAYBESET("KeepWithPrevious",nic.keepWithPrevious,symbolFalse);
4541   MAYBESET("KeepWithNext",nic.keepWithNext,symbolFalse);
4542   MAYBESET("MayViolateKeepBefore",nic.mayViolateKeepBefore,symbolFalse);
4543   MAYBESET("MayViolateKeepAfter",nic.mayViolateKeepAfter,symbolFalse);
4544 }
4545 
setInlineNIC(const InlineNIC & nic)4546 void TeXFOTBuilder::setInlineNIC(const InlineNIC &nic)
4547 {
4548   MAYBESET("BreakBeforePriority",nic.breakBeforePriority,0);
4549   MAYBESET("BreakAfterPriority",nic.breakAfterPriority,0);
4550 }
4551 
setDisplayGroupNIC(const DisplayGroupNIC & nic)4552 void TeXFOTBuilder::setDisplayGroupNIC(const DisplayGroupNIC &nic)
4553 {
4554   setDisplayNIC(nic);
4555   if (nic.hasCoalesceId)
4556     set("CoalesceId",nic.coalesceId);
4557 }
4558 
setExternalGraphicNIC(const ExternalGraphicNIC & nic)4559 void TeXFOTBuilder::setExternalGraphicNIC(const ExternalGraphicNIC &nic)
4560 {
4561   setDisplayNIC(nic);
4562   setInlineNIC(nic);
4563 
4564   MAYBESET("IsDisplay",nic.isDisplay,symbolFalse);
4565   MAYBESET("ScaleType",nic.scaleType,symbolMaxUniform);
4566   if (nic.scaleType == symbolFalse) {
4567     set("ScaleX",nic.scale[0]);
4568     set("ScaleY",nic.scale[1]);
4569   }
4570   set("EntitySystemId",nic.entitySystemId);
4571   set("NotationSystemId",nic.notationSystemId);
4572   if(nic.hasMaxWidth)
4573     set("MaxWidth",nic.maxWidth);
4574   if (nic.hasMaxHeight)
4575     set("MaxHeight",nic.maxHeight);
4576   if (!nic.isDisplay) {
4577     set("EscapementDirection",nic.escapementDirection);
4578     set("PositionPointX",nic.positionPointX);
4579     set("PositionPointY",nic.positionPointY);
4580   }
4581 }
4582 
setBoxNIC(const BoxNIC & nic)4583 void TeXFOTBuilder::setBoxNIC(const BoxNIC &nic)
4584 {
4585   setDisplayNIC(nic);
4586   setInlineNIC(nic);
4587 				// BoxNIC
4588   MAYBESET("IsDisplay",nic.isDisplay,symbolFalse);
4589 }
4590 
setRuleNIC(const RuleNIC & nic)4591 void TeXFOTBuilder::setRuleNIC(const RuleNIC &nic)
4592 {
4593   setDisplayNIC(nic);
4594   setInlineNIC(nic);
4595 				// Rule NIC
4596   set("Orientation",nic.orientation);
4597   if (nic.hasLength)
4598     set("Length",nic.length);
4599 }
4600 
setLeaderNIC(const LeaderNIC & nic)4601 void TeXFOTBuilder::setLeaderNIC(const LeaderNIC &nic)
4602 {
4603   setInlineNIC(nic);
4604   if (nic.hasLength)
4605     set("Length",nic.length);
4606 }
4607 
setParagraphNIC(const ParagraphNIC & nic)4608 void TeXFOTBuilder::setParagraphNIC(const ParagraphNIC &nic)
4609 {
4610   setDisplayNIC(nic);
4611 }
4612 
setCharacterNIC(const CharacterNIC & nic)4613 void TeXFOTBuilder::setCharacterNIC(const CharacterNIC &nic)
4614 {
4615 #if 1
4616   if (nic.valid) {
4617     set("Ch",(unsigned long)nic.ch);
4618     set("GlyphId",nic.glyphId);
4619     set("BreakBeforePriority",nic.breakBeforePriority);
4620     set("MathClass",nic.mathClass);
4621     set("MathFontPosture",nic.mathFontPosture);
4622     stringout_ << "\\def\\Script%\n{" << nic.script+29 << '}';
4623     set("IsDropAfterLineBreak",nic.isDropAfterLineBreak);
4624     set("IsDropUnlessBeforeLineBreak",nic.isDropUnlessBeforeLineBreak);
4625     set("IsPunct",nic.isPunct);
4626     set("IsInputWhiteSpace",nic.isInputWhitespace);
4627     set("IsInputTab",nic.isInputTab);
4628     set("IsRecordEnd",nic.isRecordEnd);
4629     set("IsSpace",nic.isSpace);
4630   }
4631 #else
4632   if (nic.specifiedC & (1 << CharacterNIC::cChar))
4633     set("Ch",(unsigned long)nic.ch);
4634   if (nic.specifiedC & (1 << CharacterNIC::cGlyphId))
4635     set("GlyphId",nic.glyphId);
4636   if (nic.specifiedC & (1 << CharacterNIC::cBreakBeforePriority))
4637     set("BreakBeforePriority",nic.breakBeforePriority);
4638   if (nic.specifiedC & (1 << CharacterNIC::cBreakAfterPriority))
4639     set("BreakAfterPriority",nic.breakAfterPriority);
4640   if (nic.specifiedC & (1 << CharacterNIC::cMathClass))
4641     set("MathClass",nic.mathClass);
4642   if (nic.specifiedC & (1 << CharacterNIC::cMathFontPosture))
4643     set("MathFontPosture",nic.mathFontPosture);
4644   if (nic.specifiedC & (1 << CharacterNIC::cScript))
4645     set("Script",(long unsigned int)nic.script);
4646   if (nic.specifiedC & (1 << CharacterNIC::cIsDropAfterLineBreak))
4647     set("IsDropAfterLineBreak",nic.isDropAfterLineBreak);
4648   if (nic.specifiedC & (1 << CharacterNIC::cIsDropUnlessBeforeLineBreak))
4649     set("IsDropUnlessBeforeLineBreak",nic.isDropUnlessBeforeLineBreak);
4650   if (nic.specifiedC & (1 << CharacterNIC::cIsPunct))
4651     set("IsPunct",nic.isPunct);
4652   if (nic.specifiedC & (1 << CharacterNIC::cIsInputWhitespace))
4653     set("IsInputWhiteSpace",nic.isInputWhitespace);
4654   if (nic.specifiedC & (1 << CharacterNIC::cIsInputTab))
4655     set("IsInputTab",nic.isInputTab);
4656   if (nic.specifiedC & (1 << CharacterNIC::cIsRecordEnd))
4657     set("IsRecordEnd",nic.isRecordEnd);
4658   if (nic.specifiedC & (1 << CharacterNIC::cIsSpace))
4659     set("IsSpace",nic.isSpace);
4660 #endif
4661   MAYBESET("StretchFactor",nic.stretchFactor,1.0);
4662 }
4663 
setLineFieldNIC(const LineFieldNIC & nic)4664 void TeXFOTBuilder::setLineFieldNIC(const LineFieldNIC &nic)
4665 {
4666   setInlineNIC(nic);
4667 }
4668 
setTableNIC(const TableNIC & nic)4669 void TeXFOTBuilder::setTableNIC(const TableNIC &nic)
4670 {
4671   setDisplayNIC(nic);
4672 				// TableNIC
4673   switch (nic.widthType) {
4674   case TableNIC::widthFull:
4675     set("TableWidth","full");
4676     break;
4677   case TableNIC::widthMinimum:
4678     set("TableWidth","minimum");
4679     break;
4680   case TableNIC::widthExplicit:
4681     set("TableWidth",nic.width);
4682     break;
4683   }
4684 }
4685 
setTablePartNIC(const TablePartNIC & nic)4686 void TeXFOTBuilder::setTablePartNIC(const TablePartNIC &nic)
4687 {
4688   setDisplayNIC(nic);
4689 }
4690 
setTableColumnNIC(const TableColumnNIC & nic)4691 void TeXFOTBuilder::setTableColumnNIC(const TableColumnNIC &nic)
4692 {
4693   MAYBESET("ColumnIndex",long(nic.columnIndex),0);
4694   MAYBESET("NColumnsSpanned",long(nic.nColumnsSpanned),1);
4695   if (nic.hasWidth)
4696     set("Width",nic.width);
4697 }
4698 
setTableCellNIC(const TableCellNIC & nic)4699 void TeXFOTBuilder::setTableCellNIC(const TableCellNIC &nic)
4700 {
4701   // FIX ME!
4702   // does not deal with "missing" bool yet.
4703   MAYBESET("ColumnIndex",long(nic.columnIndex),0);
4704   MAYBESET("NColumnsSpanned",long(nic.nColumnsSpanned),1);
4705   MAYBESET("NRowsSpanned",long(nic.nRowsSpanned),1);
4706 }
4707 
setGridNIC(const GridNIC & nic)4708 void TeXFOTBuilder::setGridNIC(const GridNIC &nic)
4709 {
4710   set("NColumns",nic.nColumns);
4711   set("NRows",nic.nRows);
4712 }
4713 
setGridCellNIC(const GridCellNIC & nic)4714 void TeXFOTBuilder::setGridCellNIC(const GridCellNIC &nic)
4715 {
4716   set("ColumnNumber",nic.columnNumber);
4717   set("RowNumber",nic.rowNumber);
4718 }
4719 
4720 
4721 // Dump all accumulated inherited characteristics.
4722 
dumpInherited()4723 void TeXFOTBuilder::dumpInherited()
4724 {
4725   String<char> tem;
4726   stringout_.extractString(tem);
4727   os() << tem;
4728 }
4729 
message(const MessageType0 & msg)4730 void TeXFOTBuilder::message(const MessageType0 &msg)
4731 {
4732   mgr_->message(msg);
4733 }
4734 
setPageNumberFormat(const StringC & name)4735 void TeXFOTBuilder::setPageNumberFormat(const StringC &name)
4736 {
4737   set("PageNumberFormat",name);
4738 }
4739 
setPageNColumns(long n)4740 void TeXFOTBuilder::setPageNColumns(long n)
4741 {
4742   NextFormat.FotPageNColumns = n;
4743   set("PageNColumns",n);
4744 }
4745 
setPageColumnSep(Length w)4746 void TeXFOTBuilder::setPageColumnSep(Length w)
4747 {
4748   NextFormat.FotPageColumnSep = w;
4749   setlength("PageColumnSep",w);
4750 }
4751 
setPageBalanceColumns(bool flag)4752 void TeXFOTBuilder::setPageBalanceColumns(bool flag)
4753 {
4754  set("PageBalanceColumns",flag);
4755 }
4756 
setPageTwoSide(bool flag)4757 void TeXFOTBuilder::setPageTwoSide(bool flag)
4758 {
4759   set("PageTwoSide",flag);
4760 }
4761 
setTwoSideStartOnRight(bool flag)4762 void TeXFOTBuilder::setTwoSideStartOnRight(bool flag)
4763 {
4764   set("TwoSideStartOnRight",flag);
4765 }
4766 
setSubscriptDepth(Length w)4767 void TeXFOTBuilder::setSubscriptDepth(Length w)
4768 {
4769  setlength("SubScriptDepth",w);
4770 }
4771 
setOverMarkHeight(Length w)4772 void TeXFOTBuilder::setOverMarkHeight(Length w)
4773 {
4774  setlength("OverMarkHeight",w);
4775 }
4776 
setUnderMarkDepth(Length w)4777 void TeXFOTBuilder::setUnderMarkDepth(Length w)
4778 {
4779  setlength("UnderMarkDepth",w);
4780 }
4781 
setSuperscriptHeight(Length w)4782 void TeXFOTBuilder::setSuperscriptHeight(Length w)
4783 {
4784  setlength("SuperscriptHeight",w);
4785 }
4786 
setGridRowSep(Length w)4787 void TeXFOTBuilder::setGridRowSep(Length  w)
4788 {
4789  setlength("GridRowsep",w);
4790 }
4791 
setGridColumnSep(Length w)4792 void TeXFOTBuilder::setGridColumnSep(Length w)
4793 {
4794  setlength("GridColumnSep",w);
4795 }
4796 
setHeadingLevel(long n)4797 void TeXFOTBuilder::setHeadingLevel(long n)
4798 {
4799 #ifdef OUTLINES
4800   if ((n >=1) && (n <=9)){
4801     ParHead par(1,n);
4802     headingSet_=1;
4803     push(parStack_,par);
4804     set("HeadingLevel",n);
4805   }
4806 #else
4807   set("HeadingLevel",n);
4808 #endif
4809 }
4810 
setPageNumberRestart(bool flag)4811 void TeXFOTBuilder::setPageNumberRestart(bool flag)
4812 {
4813  set("PageNumberRestart",flag);
4814 }
4815 
startPageFloat(const PageFloatNIC & nic)4816 void TeXFOTBuilder::startPageFloat(const PageFloatNIC &nic)
4817 {
4818   setPageFloatNIC(nic);
4819   startGroup("PageFloat");
4820 }
4821 
endPageFloat()4822 void TeXFOTBuilder::endPageFloat()
4823 {
4824   endGroup("PageFloat");
4825 }
4826 
startPageFootnote()4827 void TeXFOTBuilder::startPageFootnote()
4828 {
4829   startBrace("PageFootnote");
4830 }
4831 
endPageFootnote()4832 void TeXFOTBuilder::endPageFootnote()
4833 {
4834   endBrace("PageFootnote");
4835 }
4836 
setPageFloatNIC(const PageFloatNIC & nic)4837 void TeXFOTBuilder::setPageFloatNIC(const PageFloatNIC &nic)
4838 {
4839   set("placement",nic.placement);
4840 }
4841 
~PageFloatNIC()4842 TeXFOTBuilder::PageFloatNIC::~PageFloatNIC()
4843 {
4844 }
4845 
extension(const ExtensionFlowObj & fo,const NodePtr & nd)4846 void TeXFOTBuilder::extension(const ExtensionFlowObj &fo, const NodePtr &nd)
4847 {
4848   ((const TeXExtensionFlowObj &)fo).atomic(*this, nd);
4849 }
4850 
startExtensionSerial(const CompoundExtensionFlowObj & fo,const NodePtr & nd)4851 void TeXFOTBuilder::startExtensionSerial(const CompoundExtensionFlowObj &fo, const NodePtr &nd)
4852 {
4853   ((const TeXCompoundExtensionFlowObj &)fo).start(*this, nd);
4854 }
4855 
endExtensionSerial(const CompoundExtensionFlowObj & fo)4856 void TeXFOTBuilder::endExtensionSerial(const CompoundExtensionFlowObj &fo)
4857 {
4858   ((const TeXCompoundExtensionFlowObj &)fo).end(*this);
4859 }
4860 
setPreserveSdata(bool b)4861 void TeXFOTBuilder::setPreserveSdata(bool b)
4862 {
4863   preserveSdata_ = b;
4864 }
4865 
charactersFromNode(const NodePtr & nd,const Char * s,size_t n)4866 void TeXFOTBuilder::charactersFromNode(const NodePtr &nd, const Char *s, size_t n)
4867 {
4868   GroveString name;
4869   if (preserveSdata_ && n == 1 && nd->getEntityName(name) == accessOK)
4870     os() << "\\Entity{" << name << '}';
4871   else
4872     TeXFOTBuilder::characters(s, n);
4873 }
4874 
4875 #ifdef DSSSL_NAMESPACE
4876 }
4877 #endif
4878 
4879 #include "TeXFOTBuilder_inst.cxx"
4880