Back to index

texmacs  1.0.7.15
table.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : table.hpp
00004 * DESCRIPTION: Tables and cells of tables
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef TABLE_H
00013 #define TABLE_H
00014 #include "typesetter.hpp"
00015 #include "formatter.hpp"
00016 #include "Format/line_item.hpp"
00017 #include "Format/page_item.hpp"
00018 #include "Format/stack_border.hpp"
00019 
00020 class cell;
00021 class table;
00022 
00023 class table_rep: public concrete_struct {
00024 protected:
00025   hashmap<string,tree> var;   // formatting variables
00026 
00027 public:
00028   edit_env env;               // the environment
00029   int      status;            // 0: table, 1: decoration, 2: subtable
00030   int      i0;                // origin row
00031   int      j0;                // origin column
00032   path     ip;                // the corresponding source location
00033   box      b;                 // the resulting box
00034   SI       x1;                // left limit of box    (for subtables)
00035   SI       y1;                // bottom limit of box  (for subtables)
00036   SI       x2;                // right limit of box   (for subtables)
00037   SI       y2;                // top limit of box     (for subtables)
00038 
00039   cell**   T;                 // the cells of the table
00040   int      nr_rows;           // the number of rows
00041   int      nr_cols;           // the number of columns
00042   SI*      mw;                // widths of columns
00043   SI*      lw;                // left widths of columns
00044   SI*      rw;                // right widths of columns
00045 
00046   SI       width;             // the (suggested) width of the table
00047   SI       height;            // the (suggested) height of the table
00048   SI       lsep;              // left padding around table
00049   SI       rsep;              // right padding around table
00050   SI       bsep;              // bottom padding around table
00051   SI       tsep;              // top padding around table
00052   SI       lborder;           // left border width
00053   SI       rborder;           // right border width
00054   SI       bborder;           // bottom border width
00055   SI       tborder;           // top border width
00056   string   hmode;             // how to interpret the width 
00057   string   vmode;             // how to interpret the height
00058   string   halign;            // horizontal alignment
00059   string   valign;            // vertical alignment
00060   string   hyphen;            // vertical hypenation
00061   int      row_origin;        // row span (not yet implemented)
00062   int      col_origin;        // column span (not yet implemented)
00063 
00064   table_rep (edit_env env, int status, int i0, int j0);
00065   ~table_rep ();
00066   void display (bool flag= true);
00067 
00068   void typeset (tree t, path ip);
00069   void typeset_table (tree fm, tree t, path ip);
00070   void typeset_row (int i, tree fm, tree t, path ip);
00071   void format_table (tree fm);
00072   void format_item (tree with);
00073   void handle_decorations ();
00074   void handle_span ();
00075   void merge_borders ();
00076   void compute_width (SI& tmw, SI& tlw, SI& trw);
00077   void compute_widths (SI* Mw, SI* Lw, SI* Rw, bool large);
00078   void compute_horizontal_parts (double* parts);
00079   void position_columns ();
00080   void compute_height (SI& mh, SI& bh, SI& th);
00081   void compute_heights (SI* mh, SI* bh, SI* th);
00082   void compute_vertical_parts (double* parts);
00083   void position_rows ();
00084   void finish_horizontal ();
00085   void finish ();
00086   array<box> var_finish ();
00087 
00088   friend class lazy_table_rep;
00089 };
00090 
00091 class table {
00092   CONCRETE_NULL(table);
00093   inline table (edit_env env, int status= 0, int i0= 0, int j0= 0):
00094     rep (tm_new<table_rep> (env, status, i0, j0)) {}
00095 };
00096 CONCRETE_NULL_CODE(table);
00097 
00098 class cell_rep: public concrete_struct {
00099 protected:
00100   hashmap<string,tree> var;   // formatting variables
00101 
00102 public:
00103   edit_env env;               // the environment
00104   path     ip;                // source location of cell
00105   lazy     lz;                // lazily typesetted cell
00106   box      b;                 // the resulting box
00107   SI       xoff;              // xoffset after positioning of the columns
00108   SI       yoff;              // yoffset after positioning of the rows
00109   SI       x1;                // lower left coordinate of cell
00110   SI       y1;                // upper left coordinate of cell
00111   SI       x2;                // lower right coordinate of cell
00112   SI       y2;                // upper right coordinate of cell
00113   SI       shift;             // shift when tables may be hyphenated
00114 
00115   tree     decoration;        // decoration
00116   tree     bg;                // background color or pattern
00117   bool     orientation;       // portrait or landscape
00118   SI       width;             // the width of the cell
00119   SI       height;            // the height of the cell
00120   double   hpart;             // part in unused horizontal space
00121   double   vpart;             // part in unused vertical space
00122   SI       lsep;              // left padding
00123   SI       rsep;              // right padding
00124   SI       bsep;              // bottom padding
00125   SI       tsep;              // top padding
00126   SI       lborder;           // left border width
00127   SI       rborder;           // right border width
00128   SI       bborder;           // bottom border width
00129   SI       tborder;           // top border width
00130   string   hmode;             // how to interpret the width 
00131   string   vmode;             // how to interpret the height
00132   string   halign;            // horizontal alignment
00133   string   valign;            // vertical alignment
00134   string   vcorrect;          // vertical limits correction
00135   string   hyphen;            // horizontal hyphenation
00136   int      row_span;          // row span
00137   int      col_span;          // column span
00138   table    D;                 // potential decoration
00139   table    T;                 // potential subtable
00140 
00141   cell_rep (edit_env env);
00142 
00143   void typeset (tree fm, tree t, path ip);
00144   void format_cell (tree fm);
00145   void format_item (tree with);
00146   void compute_width (SI& mw, SI& lw, SI& rw, bool large);
00147   void compute_height (SI& mh, SI& bh, SI& th);
00148   void position_horizontally (SI offset, SI mw, SI lw, SI rw);
00149   void position_vertically (SI offset, SI mh, SI bh, SI th);
00150   void finish_horizontal ();
00151   void finish ();
00152 };
00153 
00154 class cell {
00155   CONCRETE_NULL(cell);
00156   inline cell (edit_env env): rep (tm_new<cell_rep> (env)) {}
00157 };
00158 CONCRETE_NULL_CODE(cell);
00159 
00160 #endif // defined TABLE_H