Back to index

texmacs  1.0.7.15
formatter.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : formatter.hpp
00004 * DESCRIPTION: formatting trees in a lazy way.
00005 *              extra formatting done is by calling 'produce'
00006 *              with new formatting information as a parameter
00007 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00008 *******************************************************************************
00009 * This software falls under the GNU general public license version 3 or later.
00010 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00011 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00012 ******************************************************************************/
00013 
00014 #ifndef FORMATTER_H
00015 #define FORMATTER_H
00016 #include "boxes.hpp"
00017 #include "env.hpp"
00018 
00019 enum format_type {
00020   FORMAT_NONE, FORMAT_CELL, FORMAT_WIDTH, FORMAT_VSTREAM,
00021   QUERY_WIDTH, QUERY_VSTREAM_WIDTH
00022 };
00023 
00024 enum lazy_type {
00025   LAZY_DOCUMENT, LAZY_PARAGRAPH, LAZY_SURROUND,
00026   LAZY_CANVAS, LAZY_ORNAMENT,
00027   LAZY_CONCAT, LAZY_TABLE, LAZY_ATOM,
00028   LAZY_BOX, LAZY_HSTREAM, LAZY_HDONE, LAZY_VSTREAM, LAZY_VDONE, LAZY_PAGES
00029 };
00030 
00031 /******************************************************************************
00032 * The format class
00033 ******************************************************************************/
00034 
00035 extern int format_count;
00036 struct format;
00037 struct format_rep: public abstract_struct {
00038   format_type type;
00039 
00040   inline  format_rep (format_type t): type (t) {
00041     TM_DEBUG (format_count++); }
00042   inline  virtual ~format_rep () {
00043     TM_DEBUG (format_count--); }
00044 
00045   virtual operator tree () = 0;
00046   virtual bool equal (format fm) = 0;
00047 };
00048 
00049 struct format {
00050   ABSTRACT_NULL(format);            
00051   inline operator tree () { return (tree) (*rep); }
00052   inline bool operator == (format fm) { return rep->equal (fm); }
00053   inline bool operator != (format fm) { return !rep->equal (fm); }
00054 };
00055 ABSTRACT_NULL_CODE(format);
00056 
00057 format make_format_none ();
00058 format make_format_cell (SI width, int vpos, SI depth, SI height);
00059 format make_format_width (SI width);
00060 
00061 /******************************************************************************
00062 * The lazy class
00063 ******************************************************************************/
00064 
00065 extern int lazy_count;
00066 struct lazy;
00067 struct lazy_rep: public abstract_struct {
00068   lazy_type type;  // the lazy type
00069   path ip;         // source location
00070 
00071   inline  lazy_rep (lazy_type type2, path ip2): type (type2), ip (ip2) {
00072     TM_DEBUG (lazy_count++); }
00073   inline  virtual ~lazy_rep () {
00074     TM_DEBUG (lazy_count--); }
00075 
00076   virtual operator tree () = 0;
00077   virtual void append (lazy lz);
00078   virtual lazy produce (lazy_type request, format fm);
00079     // further format the lazy structure using 'fm',
00080     // and produce a lazy structure of type 'request'
00081   virtual format query (lazy_type request, format fm);
00082     // retrieve formatting information as a function of 'fm'
00083     // before production of a lazy structure of type 'request'
00084 };
00085 
00086 struct lazy {
00087   ABSTRACT_NULL(lazy);            
00088   operator box ();
00089   inline operator tree () { return (tree) (*rep); }
00090   inline void operator << (lazy lz) { rep->append (lz); }
00091   inline bool operator == (lazy lz) { return rep == lz.rep; }
00092   inline bool operator != (lazy lz) { return rep != lz.rep; }
00093   inline friend tm_ostream& operator << (tm_ostream& out, lazy lz) {
00094     return out << ((tree) lz); }
00095 };
00096 ABSTRACT_NULL_CODE(lazy);
00097 lazy make_lazy (edit_env env, tree t, path ip);
00098 lazy make_lazy_box (box b);
00099 
00100 #endif // defined FORMATTER_H