Add missing license headers on *.hh files and others
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / OnlineRender / CanvasRenderer.hh
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 // $XConsortium: CanvasRenderer.hh /main/31 1996/11/26 15:29:35 rcs $
24 #ifndef _CanvasRenderer_hh
25 #define _CanvasRenderer_hh
26
27 #include "Renderer.h"
28 #include "FontCache.hh"
29
30 // get DtCanvas structure defns
31 #include <Dt/CanvasSegP.h>
32
33 #include "dti_cc/CC_Stack.h"
34
35 // Symbol Constants required
36 #define GRAPHIC_attr    0
37 #define INLGRAPHIC      1
38 #define ISMAP           2
39 #define OLID            3
40 #define OLIDREF         4
41 #define REMOTE          5
42 #define TABLE           6
43 #define TERMS           7
44
45 #define ALIGN           8 
46 #define BOTTOM          9 
47 #define LINEBREAK       10
48 #define CHARSETS        11
49 #define SET             12
50 #define BGCOLOR         13
51 #define FGCOLOR         14
52 #define FONT            15
53 #define FONTCATALOG     16
54 #define FONTFAMILY      17
55 #define HIGHLIGHT       18
56 #define IGNORE          19
57 #define LEFT            20
58 #define MARGIN          21
59 #define SUFFIX          22
60 #define PREFIX          23
61 #define PREVIEW         24
62 #define RIGHT           25
63 #define TABSTOPS        26
64 #define CONTENT         27
65 #define TOP             28
66 #define OVERLINE        29
67 #define STRIKETHROUGH   30
68 #define UNDERLINE       31
69 #define WRAP            32
70 #define XLFD            33
71 #define GRAPHIC_feature 34
72 #define FAMILY          35
73 #define WEIGHT          36
74 #define SLANT           37
75 #define SIZE            38
76 #define CHARSET         39
77 #define REVERSEVIDEO    40
78 #define AT              41
79 #define EVERY           42
80 /* ---- */
81 #define POSITION        43
82 #define HORIZ           44
83 #define VERT            45
84 /* ---- */
85 #define LAYOUT          46
86 #define ASPACE          47
87 #define BSPACE          48
88 #define LEADING         49
89 #define FINDENT         50
90 #define LINDENT         51
91 #define RINDENT         52
92 #define FLOW            53
93 #define JUSTIFY         54
94 #define VJUSTIFY        55
95 #define BORDER          56
96 #define THICKNESS       57
97 #define ROW             58
98 #define COLS            59
99 #define COLFORMAT       60
100 #define CHARALIGN       61
101 #define SPANCOLS        62
102 #define MOREROWS        63
103 #define CELL            64
104 #define WIDTH           65
105 #define FALLBACK        66
106 #define FOUNDRY         67
107 #define NAME            68
108 #define DISPLAY         69
109 #define COLREF          70
110 #define SUBSUPER        71
111 #define COLSEP          72
112 #define ROWSEP          73
113 #define TGROUP          74
114 #define FRAME           75
115
116 // print symbols
117
118 #define MEDIA           76
119 #define PAGEBREAK       77
120 #define FOOTERS         78
121 #define HEADERS         79
122 #define ORIENTATION     80
123
124 #define REND_SYMBOLS    81
125
126 //-------- External References ---------------------------------
127
128 extern const char *f_printOrientation;
129
130 int point2pixel(int size);
131
132 class FeatureSet ;
133 class Symbol ;
134
135 #include "OnlineRender/SegClientData.hh"
136 #include "OnlineRender/TableDefn.hh"
137
138 class Margins
139 {
140   
141 public:
142
143   Margins();
144
145   int   has_margins();
146
147   int   first()         { return f_first ; }
148   int   first (int f)   { f_first = f ; return f ; }
149   int   left()          { return f_left ; }
150   int   left (int l)    { f_left = l ; return l ; }
151   int   right()         { return f_right ; }
152   int   right (int r)   { f_right = r ; return r ; }
153   int   top()           { return f_top ; }
154   int   top (int t)     { f_top = t ; return t ; }
155   int   bottom()        { return f_bottom ; }
156   int   bottom (int b)  { f_bottom = b ; return b ; }
157
158   
159 private:
160   int   f_first ;
161   int   f_left  ;
162   int   f_right ;
163   int   f_top ;
164   int   f_bottom ;
165 };
166
167 class Posn
168 {
169 public:
170   Posn () : f_horiz (_DtCvOPTION_BAD), f_vert (_DtCvOPTION_BAD) {}
171   Posn (Posn &posn) : f_horiz (posn.f_horiz), f_vert (posn.f_vert)
172     {}
173
174
175   unsigned has_position()       { return f_horiz || f_vert ; }
176
177   _DtCvFrmtOption horiz ()                      { return f_horiz ; }
178   _DtCvFrmtOption horiz (_DtCvFrmtOption h)     { f_horiz = h ; return h ; }
179   _DtCvFrmtOption vert ()                       { return f_vert ; }
180   _DtCvFrmtOption vert (_DtCvFrmtOption v)      { f_vert = v ; return v ; } 
181
182 private:
183
184   _dtCvFrmtOption       f_horiz ;
185   _dtCvFrmtOption       f_vert ;
186
187 };
188
189 class CanvasRenderer;
190
191 class Layout
192 {
193 public:
194   Layout (CanvasRenderer *);
195   Layout (Layout &);
196
197   unsigned has_layout(int affix);
198
199   int aspace ()         { return f_aspace ; }
200   int aspace (int a)    { f_aspace = a ; return a ; }
201
202   int bspace ()         { return f_bspace ; }
203   int bspace (int a)    { f_bspace = a ; return a ; }
204
205   int leading ()        { return f_leading ; }
206   int leading (int a)   { f_leading = a ; return a ; }
207
208   int findent ()        { return f_findent ; }
209   int findent (int a)   { f_findent = a ; return a ; }
210
211   int rindent ()        { return f_rindent ; }
212   int rindent (int a)   { f_rindent = a ; return a ; }
213
214   int lindent ()        { return f_lindent ; }
215   int lindent (int a)   { f_lindent = a ; return a ; }
216
217   _DtCvFrmtOption       flow ()         { return f_flow ; }
218   _DtCvFrmtOption       flow (_DtCvFrmtOption f)        { f_flow = f; return f ; }
219
220   _DtCvFrmtOption       wrap ()         { return f_wrap ; }
221   _DtCvFrmtOption       wrap (_DtCvFrmtOption f)        { f_wrap = f; return f ; }
222
223   _DtCvFrmtOption       justify ()              { return f_justify ; }
224   _DtCvFrmtOption       justify (_DtCvFrmtOption f)     { f_justify = f; return f ; }
225
226 private:
227   CanvasRenderer* f_renderer;
228   int   f_aspace ;
229   int   f_bspace ;
230   int   f_leading ;
231   int   f_findent ;
232   int   f_rindent ;
233   int   f_lindent ;
234
235   _DtCvFrmtOption       f_flow ;
236   _DtCvFrmtOption       f_justify ;
237   _DtCvFrmtOption       f_wrap ;
238   
239 };
240
241 class Cell
242 {
243 public:
244   Cell() : 
245   f_has_cell (0), 
246   f_spanrows (1),
247   f_colref (NULL),
248   f_colstart (NULL),
249   f_colend (NULL),
250   f_justify(_DtCvOPTION_BAD),
251   f_vjustify(_DtCvOPTION_BAD),
252   f_colsep(CRSEP_NOT_SPECIFIED),
253   f_rowsep(CRSEP_NOT_SPECIFIED),
254   f_char_align('\0')
255     {}
256
257   int   has_cell()      { return f_has_cell ; }
258   int   has_cell (int tf){ f_has_cell = tf ; return tf ; }
259
260   int   spanrows () { return f_spanrows ; }
261   int   spanrows (int rows) { f_spanrows = rows ; return rows ; }
262
263   char *colref(char *r)   { f_colref = r; return r; }
264   char *colref()          { return f_colref; }
265   void  colstart(char* s) { f_colstart = s; }
266   char* colstart()        { return f_colstart; }
267   void  colend(char* s)   { f_colend = s; }
268   char* colend()          { return f_colend; }
269
270   _DtCvFrmtOption justify() { return f_justify; }
271   _DtCvFrmtOption justify(_DtCvFrmtOption c) { f_justify = c ; return c ; }
272
273   _DtCvFrmtOption vjustify() { return f_vjustify; }
274   _DtCvFrmtOption vjustify(_DtCvFrmtOption c) { f_vjustify = c ; return c ; }
275
276   int   colsep() { return f_colsep; }
277   void  colsep(int v) { f_colsep = v; }
278   int   rowsep() { return f_rowsep; }
279   void  rowsep(int v) { f_rowsep = v; }
280
281   char char_align(const char *s) {
282     f_char_align = *s; return f_char_align;
283   }
284   char char_align() { return f_char_align; }
285
286 private:
287   int   f_has_cell ;
288   int   f_spanrows ;
289   char *f_colref ;
290   char *f_colstart ;
291   char *f_colend ;
292   _DtCvFrmtOption f_justify;
293   _DtCvFrmtOption f_vjustify;
294   int   f_colsep;
295   int   f_rowsep;
296   char  f_char_align;
297 };
298
299 class Highlight
300 {
301 public:
302   Highlight() : f_hilite(0) {}
303   Highlight(Highlight& src) : f_bg_color(src.f_bg_color),
304                               f_fg_color(src.f_fg_color),
305                               f_hilite(src.f_hilite) {}
306
307   int overline() { return (f_hilite & hilite_overline); }
308   int strikethrough() { return (f_hilite & hilite_strikethrough); }
309   int underline() { return (f_hilite & hilite_underline); }
310
311   UAS_String& bg_color() { return f_bg_color; }
312   UAS_String& fg_color() { return f_fg_color; }
313
314   void overline(unsigned int);
315   void strikethrough(unsigned int);
316   void underline(unsigned int);
317
318   void bg_color(const char* col) { f_bg_color = col; }
319   void bg_color(UAS_String& col) { f_bg_color = col; }
320   void fg_color(const char* col) { f_fg_color = col; }
321   void fg_color(UAS_String& col) { f_fg_color = col; }
322
323 private:
324   UAS_String f_bg_color;
325   UAS_String f_fg_color;
326   unsigned int f_hilite;
327 };
328
329 inline void
330 Highlight::overline(unsigned int v)
331 {
332     if (v)
333         f_hilite |= hilite_overline;
334     else
335         f_hilite &= ~hilite_overline;
336 }
337
338 inline void
339 Highlight::strikethrough(unsigned int v)
340 {
341     if (v)
342         f_hilite |= hilite_strikethrough;
343     else
344         f_hilite &= ~hilite_strikethrough;
345 }
346
347 inline void
348 Highlight::underline(unsigned int v)
349 {
350     if (v)
351         f_hilite |= hilite_underline;
352     else
353         f_hilite &= ~hilite_underline;
354 }
355
356 #define LINEBREAK_NONE   0
357 #define LINEBREAK_BEFORE 1
358 #define LINEBREAK_AFTER  2
359 #define LINEBREAK_BOTH   (LINEBREAK_BEFORE | LINEBREAK_AFTER)
360
361 #define PAGEBREAK_NONE   0
362 #define PAGEBREAK_BEFORE 1
363 #define PAGEBREAK_AFTER  2
364 #define PAGEBREAK_BOTH   (PAGEBREAK_BEFORE | PAGEBREAK_AFTER)
365
366 class PartialElementFeatures
367 {
368   // element features acceptable by prefix and suffix
369 public:
370   PartialElementFeatures(CanvasRenderer *);
371   PartialElementFeatures (PartialElementFeatures &);
372   virtual ~PartialElementFeatures();
373
374   virtual int requires_container(int affix);
375   virtual int ignore_linebreak(int affix);
376
377   UAS_String font () { return f_font ; }
378   void set_font (const char *f) { f_font = f ; }  
379
380   const unsigned pagebreak()            { return f_pagebreak ; }
381   const unsigned pagebreak (unsigned b) { f_pagebreak = b ; return b ; }
382
383   const unsigned linebreak()            { return f_linebreak ; }
384   const unsigned linebreak (unsigned b) { f_linebreak = b ; return b ; }
385
386   const char *text ()                   { return f_text ; }
387   const char *text(const char *t)       { f_text = t ; return t ; }
388
389   Posn &position()      { return f_position ; } 
390
391   Layout &layout ()     { return f_layout ; }
392
393   _DtCvSegment *graphic (_DtCvSegment *g)       { f_graphic = g ; return g ; }
394   _DtCvSegment *graphic ()                      { return f_graphic ; } 
395
396   Highlight& highlight() { return f_highlight; }
397
398   enum { baseline, subscript, superscript } ;
399   void subsuper(int v)  { f_subsuper = v; }
400   int  subsuper()       { return f_subsuper; }
401
402   void ignore(int v)    { f_ignore = v; }
403   int  ignore()         { return f_ignore; }
404
405   const char *orientation() { return f_orientation ; }
406
407   const char *orientation(const char * b) { 
408       f_printOrientation = b; 
409       f_orientation = b ; 
410       return b ; 
411   }
412
413 private:
414   const char   *f_text ;
415   UAS_String    f_font ;
416   int           f_subsuper;
417   Highlight     f_highlight;
418   unsigned      f_linebreak;
419   unsigned      f_pagebreak;
420   Posn          f_position;
421   Layout        f_layout ;
422   _DtCvSegment *f_graphic ;
423   int           f_ignore;
424   const char   *f_orientation;
425 };
426
427 class ElementFeatures : public PartialElementFeatures
428 {
429   // all the features required to format an element
430 public:
431   ElementFeatures(CanvasRenderer *);
432   ~ElementFeatures();
433
434   int requires_container(int affix);
435   int ignore_linebreak(int affix);
436
437   PartialElementFeatures &prefix()
438     { return f_prefix ; }
439   PartialElementFeatures &suffix()
440     { return f_suffix ; }
441
442   Margins       &margin()       { return f_margin ; }
443
444   _DtCvFrmtOption       border()  { return f_border ; }
445   _DtCvFrmtOption       border(_DtCvFrmtOption b) { f_border = b ; return b ; }
446   int           border_width() { return f_border_width; }
447   void          border_width(int w) { f_border_width = w; }
448
449   TableDefn     *table()        { return f_table; }
450   TableDefn     *table(TableDefn *t) { f_table = t; return f_table; }
451
452   TGDefn        *tgroup()       { return f_tgroup ; }
453   TGDefn        *tgroup(TGDefn *t) { f_tgroup = t ; return f_tgroup ; }
454
455   ColFormat     *col_format()   { return f_colformat ; }
456   ColFormat     *col_format (ColFormat *f) { f_colformat = f ; return f ; }
457
458   Cell          &cell()         { return f_cell ; }
459
460   RowDefn*      row()           { return f_row ; }
461   RowDefn*      row(RowDefn* d) { f_row = d ; return d ; }
462
463   int           link_idx ()     { return f_link_idx ; }
464   int           link_idx (int li){ f_link_idx = li; return li ; }
465
466   char          *locator ()     { return f_locator ; }
467   char          *locator(char *l){ f_locator = l ; return l ; }
468
469   char          *xref ()        { return f_xref ; }
470   char          *xref(char *l){ f_xref = l ; return l ; }
471
472 private:
473   RowDefn*      f_row ;
474
475   _DtCvFrmtOption       f_border;
476   int                   f_border_width;
477
478   TableDefn     *f_table;
479   TGDefn        *f_tgroup ;
480   ColFormat     *f_colformat ;
481   Cell          f_cell ;
482   Margins       f_margin ;
483   PartialElementFeatures        f_prefix ;
484   PartialElementFeatures        f_suffix ;
485
486   /* --- olias attributes ---*/
487   char         *f_locator ; // if this element is identified with a locator
488   char         *f_xref ;
489   int           f_link_idx ; // index of where this guy links to
490 };
491
492 class CanvasRenderer : public Renderer
493 {
494 public:
495   CanvasRenderer(int font_scale);
496   ~CanvasRenderer();
497   
498   // inherited virtuals to be overridden
499   FeatureSet   *initialize();
500
501   void          Begin();
502   void          End();
503
504   unsigned int  BeginElement(const Element     &element,
505                              const FeatureSet  &local,
506                              const FeatureSet  &complete,
507                              const FeatureSet  &parentComplete);
508
509   void          data(const char *data, unsigned int size);
510   void          _data(const char *data, unsigned int size, Boolean count_vcc);
511
512   void          EndElement(const Symbol &name);
513
514   friend class Layout; // let Layout to look into leading stacks and level
515   int current_leading();
516
517   // local stuff 
518
519 private:
520   void  handle_olias_attributes(ElementFeatures &,
521                                 const Element &,
522                                 const FeatureSet &local,
523                                 const FeatureSet &complete,
524                                 const FeatureSet &parentComplete);
525
526   void  setup_container(_DtCvSegment *container,
527                         PartialElementFeatures &features,
528                         int affix);
529   void  setup_container(_DtCvSegment *container,
530                         ElementFeatures &features);
531
532   const char *get_pattern(const char *fallback, const char *weight, const char *slant, int size);
533   void  dofont(PartialElementFeatures   &return_features, const FeatureSet &, Symbol **);
534   void  dofontlist(ElementFeatures      &return_features,const FeatureSet &, Symbol **);
535   void  dounderline(ElementFeatures     &return_features,const FeatureSet &, Symbol **);
536   void  domargin(ElementFeatures        &return_features, const FeatureSet &, Symbol **);
537   void  dowrap(ElementFeatures  &return_features, const FeatureSet &, Symbol **);
538   void  dohighlight(ElementFeatures     &return_features,const FeatureSet &, Symbol **);
539   void  docolor(ElementFeatures &return_features, const FeatureSet &, Symbol **);
540   void  doposition(PartialElementFeatures &return_features, const FeatureSet &, Symbol**);
541   void  doborder(ElementFeatures &return_features, const FeatureSet &, Symbol**);
542   void  dolayout(PartialElementFeatures &return_features, const FeatureSet &local,
543                  const FeatureSet &complete, Symbol**);
544   void  dotable(ElementFeatures &return_features, const FeatureSet &, Symbol**);
545   void  dotgroup(ElementFeatures &return_features, const FeatureSet &, Symbol**);
546   void  docolformat(ElementFeatures &return_features, const FeatureSet &, Symbol**);
547   void  docell(ElementFeatures &return_features, const FeatureSet &, Symbol**);
548   void  dorow(ElementFeatures &return_features, const FeatureSet &, Symbol**);
549
550     // print features
551
552 #ifdef NOTIMPLEMENTED
553   void  dofooter(ElementFeatures &return_features, const FeatureSet &, Symbol**);
554   void  doheader(ElementFeatures &return_features, const FeatureSet &, Symbol**);
555 #endif
556
557   void  domedia(ElementFeatures &return_features, const FeatureSet &, Symbol**);
558   void  dopage(PartialElementFeatures   &return_features, const FeatureSet
559                 &local, const FeatureSet &complete, Symbol **); 
560
561   void  do_unsupported_feature(const Symbol &);
562
563   void  doprefix(ElementFeatures        &return_features, const
564                  FeatureSet &local, const FeatureSet &complete, Symbol**);  
565   void  dosuffix(ElementFeatures        &return_features,const
566                  FeatureSet &local, const FeatureSet &complete,
567                  Symbol**);   
568   void  dobreak(PartialElementFeatures  &return_features, const FeatureSet
569                 &local, const FeatureSet &complete, Symbol **); 
570
571   void do_features(ElementFeatures      &return_features,
572                    const FeatureSet     &local,
573                    const FeatureSet     &complete,
574                    Symbol              **symbols);
575
576   _DtCvSegment *create_container(_DtCvSegment *parent);
577
578   _DtCvSegment *insert_string (_DtCvSegment *container, const char *font, 
579                                const char *data, unsigned int size,
580                                Boolean count_vcc = True);
581   _DtCvSegment *really_insert_string (_DtCvSegment *container, const char *font, 
582                                const char *data, unsigned int size,
583                                Boolean count_vcc = True);
584   _DtCvSegment *insert_literal(_DtCvSegment *container, const char *font,
585                                const char *data, unsigned int size);
586
587   void          setup_cascaded_container (_DtCvSegment*);
588   void          setup_cascaded_tgroup_container (_DtCvSegment*, _DtCvSegment*);
589   _DtCvSegment* create_cascaded_container(_DtCvSegment*);
590
591 private:
592   static const char* const f_hcf_sans;
593   static const char* const f_hcf_serif;
594   static const char* const f_hcf_mono;
595   static const char* const f_hcf_symbol;
596
597   static const char* const f_hcf_weight;
598   static const char* const f_hcf_slant;
599   static const char* const f_hcf_fallback;
600   static const int         f_hcf_size;
601
602   char *_dofont(const FeatureSet &, Symbol **);
603
604   // Virtual Character Count
605   unsigned int  f_vcc ;
606
607   _DtCvSegment *f_current_container ;
608   _DtCvSegment *f_current_displayable ; // for next_disp links
609
610   TGDefn    *f_current_tgroup ; // for building tables
611
612   UAS_String    f_font ;                // current font
613   int           f_link_idx ;            // current link index
614
615   int           f_font_scale ;
616
617   // I have implemented multiple stacks, instead of one stack with a
618   // class or structure, because, with the exception of the suffixes
619   // stack, every other stack contains single word entries, hence no
620   // excessive dynamic memory allocation, and no worries about
621   // releasing the memory at the correct time. This may or may not be
622   // optimal, but was how the incremental development produced
623   // it. This should be simple to change. - brad
624
625   Stack<PartialElementFeatures *> f_suffixes ; // keep track of
626                                                // suffixes to be applied
627   Stack<UAS_String>   f_fstack ;               // font stack
628   Stack<_DtCvSegment *> f_stack ;              // current container
629   Stack<int>            f_link_stack ;         // current link
630   Stack<TableDefn *>    f_table_stack ;        // tables
631   Stack<TGDefn *>       f_tgroup_stack ;       // tgroups
632   Stack<SegClientData*> f_scd_stack;    // highlight info stack
633   Stack<int>            f_subsuper_stack;      // sub/super script
634   Stack<int>            f_ignore_stack;        // ignore state
635   Stack<int>            f_leading_stack;       // leading values
636   Stack<int>            f_leading_level_stack; // leading levels
637
638   // default fonts 
639   const char   *f_sans;
640   const char   *f_serif;
641   const char   *f_mono;
642   const char   *f_symbol;
643
644   // do not destroy ... owned by resolver
645   FeatureSet   *f_default_features ;
646
647   // feature symbols
648   Symbol       *f_symbols[REND_SYMBOLS] ;
649
650   // element symbols 
651   Symbol        fBogusSymbol;
652
653   // local Feature symbol table 
654   SymbolTable   f_symtab ;
655
656   // FontCache 
657   FontCache     f_fontcache ;
658
659   // default border width
660   int   f_border_width;
661
662   int f_level;
663 };
664
665
666
667
668
669 #endif /* _CanvasRenderer_hh */
670 /* DO NOT ADD ANY LINES AFTER THIS #endif */
671
672