2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 // $XConsortium: CanvasRenderer.hh /main/31 1996/11/26 15:29:35 rcs $
24 #ifndef _CanvasRenderer_hh
25 #define _CanvasRenderer_hh
28 #include "FontCache.hh"
30 // get DtCanvas structure defns
31 #include <Dt/CanvasSegP.h>
33 #include "dti_cc/CC_Stack.h"
35 // Symbol Constants required
36 #define GRAPHIC_attr 0
53 #define FONTCATALOG 16
67 #define STRIKETHROUGH 30
71 #define GRAPHIC_feature 34
77 #define REVERSEVIDEO 40
122 #define ORIENTATION 80
124 #define REND_SYMBOLS 81
126 //-------- External References ---------------------------------
128 extern const char *f_printOrientation;
130 int point2pixel(int size);
135 #include "OnlineRender/SegClientData.hh"
136 #include "OnlineRender/TableDefn.hh"
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 ; }
170 Posn () : f_horiz (_DtCvOPTION_BAD), f_vert (_DtCvOPTION_BAD) {}
171 Posn (Posn &posn) : f_horiz (posn.f_horiz), f_vert (posn.f_vert)
175 unsigned has_position() { return f_horiz || f_vert ; }
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 ; }
184 _dtCvFrmtOption f_horiz ;
185 _dtCvFrmtOption f_vert ;
189 class CanvasRenderer;
194 Layout (CanvasRenderer *);
197 unsigned has_layout(int affix);
199 int aspace () { return f_aspace ; }
200 int aspace (int a) { f_aspace = a ; return a ; }
202 int bspace () { return f_bspace ; }
203 int bspace (int a) { f_bspace = a ; return a ; }
205 int leading () { return f_leading ; }
206 int leading (int a) { f_leading = a ; return a ; }
208 int findent () { return f_findent ; }
209 int findent (int a) { f_findent = a ; return a ; }
211 int rindent () { return f_rindent ; }
212 int rindent (int a) { f_rindent = a ; return a ; }
214 int lindent () { return f_lindent ; }
215 int lindent (int a) { f_lindent = a ; return a ; }
217 _DtCvFrmtOption flow () { return f_flow ; }
218 _DtCvFrmtOption flow (_DtCvFrmtOption f) { f_flow = f; return f ; }
220 _DtCvFrmtOption wrap () { return f_wrap ; }
221 _DtCvFrmtOption wrap (_DtCvFrmtOption f) { f_wrap = f; return f ; }
223 _DtCvFrmtOption justify () { return f_justify ; }
224 _DtCvFrmtOption justify (_DtCvFrmtOption f) { f_justify = f; return f ; }
227 CanvasRenderer* f_renderer;
235 _DtCvFrmtOption f_flow ;
236 _DtCvFrmtOption f_justify ;
237 _DtCvFrmtOption f_wrap ;
250 f_justify(_DtCvOPTION_BAD),
251 f_vjustify(_DtCvOPTION_BAD),
252 f_colsep(CRSEP_NOT_SPECIFIED),
253 f_rowsep(CRSEP_NOT_SPECIFIED),
257 int has_cell() { return f_has_cell ; }
258 int has_cell (int tf){ f_has_cell = tf ; return tf ; }
260 int spanrows () { return f_spanrows ; }
261 int spanrows (int rows) { f_spanrows = rows ; return rows ; }
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; }
270 _DtCvFrmtOption justify() { return f_justify; }
271 _DtCvFrmtOption justify(_DtCvFrmtOption c) { f_justify = c ; return c ; }
273 _DtCvFrmtOption vjustify() { return f_vjustify; }
274 _DtCvFrmtOption vjustify(_DtCvFrmtOption c) { f_vjustify = c ; return c ; }
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; }
281 char char_align(const char *s) {
282 f_char_align = *s; return f_char_align;
284 char char_align() { return f_char_align; }
292 _DtCvFrmtOption f_justify;
293 _DtCvFrmtOption f_vjustify;
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) {}
307 int overline() { return (f_hilite & hilite_overline); }
308 int strikethrough() { return (f_hilite & hilite_strikethrough); }
309 int underline() { return (f_hilite & hilite_underline); }
311 UAS_String& bg_color() { return f_bg_color; }
312 UAS_String& fg_color() { return f_fg_color; }
314 void overline(unsigned int);
315 void strikethrough(unsigned int);
316 void underline(unsigned int);
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; }
324 UAS_String f_bg_color;
325 UAS_String f_fg_color;
326 unsigned int f_hilite;
330 Highlight::overline(unsigned int v)
333 f_hilite |= hilite_overline;
335 f_hilite &= ~hilite_overline;
339 Highlight::strikethrough(unsigned int v)
342 f_hilite |= hilite_strikethrough;
344 f_hilite &= ~hilite_strikethrough;
348 Highlight::underline(unsigned int v)
351 f_hilite |= hilite_underline;
353 f_hilite &= ~hilite_underline;
356 #define LINEBREAK_NONE 0
357 #define LINEBREAK_BEFORE 1
358 #define LINEBREAK_AFTER 2
359 #define LINEBREAK_BOTH (LINEBREAK_BEFORE | LINEBREAK_AFTER)
361 #define PAGEBREAK_NONE 0
362 #define PAGEBREAK_BEFORE 1
363 #define PAGEBREAK_AFTER 2
364 #define PAGEBREAK_BOTH (PAGEBREAK_BEFORE | PAGEBREAK_AFTER)
366 class PartialElementFeatures
368 // element features acceptable by prefix and suffix
370 PartialElementFeatures(CanvasRenderer *);
371 PartialElementFeatures (PartialElementFeatures &);
372 virtual ~PartialElementFeatures();
374 virtual int requires_container(int affix);
375 virtual int ignore_linebreak(int affix);
377 UAS_String font () { return f_font ; }
378 void set_font (const char *f) { f_font = f ; }
380 const unsigned pagebreak() { return f_pagebreak ; }
381 const unsigned pagebreak (unsigned b) { f_pagebreak = b ; return b ; }
383 const unsigned linebreak() { return f_linebreak ; }
384 const unsigned linebreak (unsigned b) { f_linebreak = b ; return b ; }
386 const char *text () { return f_text ; }
387 const char *text(const char *t) { f_text = t ; return t ; }
389 Posn &position() { return f_position ; }
391 Layout &layout () { return f_layout ; }
393 _DtCvSegment *graphic (_DtCvSegment *g) { f_graphic = g ; return g ; }
394 _DtCvSegment *graphic () { return f_graphic ; }
396 Highlight& highlight() { return f_highlight; }
398 enum { baseline, subscript, superscript } ;
399 void subsuper(int v) { f_subsuper = v; }
400 int subsuper() { return f_subsuper; }
402 void ignore(int v) { f_ignore = v; }
403 int ignore() { return f_ignore; }
405 const char *orientation() { return f_orientation ; }
407 const char *orientation(const char * b) {
408 f_printOrientation = b;
417 Highlight f_highlight;
418 unsigned f_linebreak;
419 unsigned f_pagebreak;
422 _DtCvSegment *f_graphic ;
424 const char *f_orientation;
427 class ElementFeatures : public PartialElementFeatures
429 // all the features required to format an element
431 ElementFeatures(CanvasRenderer *);
434 int requires_container(int affix);
435 int ignore_linebreak(int affix);
437 PartialElementFeatures &prefix()
438 { return f_prefix ; }
439 PartialElementFeatures &suffix()
440 { return f_suffix ; }
442 Margins &margin() { return f_margin ; }
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; }
449 TableDefn *table() { return f_table; }
450 TableDefn *table(TableDefn *t) { f_table = t; return f_table; }
452 TGDefn *tgroup() { return f_tgroup ; }
453 TGDefn *tgroup(TGDefn *t) { f_tgroup = t ; return f_tgroup ; }
455 ColFormat *col_format() { return f_colformat ; }
456 ColFormat *col_format (ColFormat *f) { f_colformat = f ; return f ; }
458 Cell &cell() { return f_cell ; }
460 RowDefn* row() { return f_row ; }
461 RowDefn* row(RowDefn* d) { f_row = d ; return d ; }
463 int link_idx () { return f_link_idx ; }
464 int link_idx (int li){ f_link_idx = li; return li ; }
466 char *locator () { return f_locator ; }
467 char *locator(char *l){ f_locator = l ; return l ; }
469 char *xref () { return f_xref ; }
470 char *xref(char *l){ f_xref = l ; return l ; }
475 _DtCvFrmtOption f_border;
480 ColFormat *f_colformat ;
483 PartialElementFeatures f_prefix ;
484 PartialElementFeatures f_suffix ;
486 /* --- olias attributes ---*/
487 char *f_locator ; // if this element is identified with a locator
489 int f_link_idx ; // index of where this guy links to
492 class CanvasRenderer : public Renderer
495 CanvasRenderer(int font_scale);
498 // inherited virtuals to be overridden
499 FeatureSet *initialize();
504 unsigned int BeginElement(const Element &element,
505 const FeatureSet &local,
506 const FeatureSet &complete,
507 const FeatureSet &parentComplete);
509 void data(const char *data, unsigned int size);
510 void _data(const char *data, unsigned int size, Boolean count_vcc);
512 void EndElement(const Symbol &name);
514 friend class Layout; // let Layout to look into leading stacks and level
515 int current_leading();
520 void handle_olias_attributes(ElementFeatures &,
522 const FeatureSet &local,
523 const FeatureSet &complete,
524 const FeatureSet &parentComplete);
526 void setup_container(_DtCvSegment *container,
527 PartialElementFeatures &features,
529 void setup_container(_DtCvSegment *container,
530 ElementFeatures &features);
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**);
552 #ifdef NOTIMPLEMENTED
553 void dofooter(ElementFeatures &return_features, const FeatureSet &, Symbol**);
554 void doheader(ElementFeatures &return_features, const FeatureSet &, Symbol**);
557 void domedia(ElementFeatures &return_features, const FeatureSet &, Symbol**);
558 void dopage(PartialElementFeatures &return_features, const FeatureSet
559 &local, const FeatureSet &complete, Symbol **);
561 void do_unsupported_feature(const Symbol &);
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,
568 void dobreak(PartialElementFeatures &return_features, const FeatureSet
569 &local, const FeatureSet &complete, Symbol **);
571 void do_features(ElementFeatures &return_features,
572 const FeatureSet &local,
573 const FeatureSet &complete,
576 _DtCvSegment *create_container(_DtCvSegment *parent);
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);
587 void setup_cascaded_container (_DtCvSegment*);
588 void setup_cascaded_tgroup_container (_DtCvSegment*, _DtCvSegment*);
589 _DtCvSegment* create_cascaded_container(_DtCvSegment*);
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;
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;
602 char *_dofont(const FeatureSet &, Symbol **);
604 // Virtual Character Count
607 _DtCvSegment *f_current_container ;
608 _DtCvSegment *f_current_displayable ; // for next_disp links
610 TGDefn *f_current_tgroup ; // for building tables
612 UAS_String f_font ; // current font
613 int f_link_idx ; // current link index
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
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
642 const char *f_symbol;
644 // do not destroy ... owned by resolver
645 FeatureSet *f_default_features ;
648 Symbol *f_symbols[REND_SYMBOLS] ;
653 // local Feature symbol table
654 SymbolTable f_symtab ;
657 FontCache f_fontcache ;
659 // default border width
669 #endif /* _CanvasRenderer_hh */
670 /* DO NOT ADD ANY LINES AFTER THIS #endif */