Back to index

texmacs  1.0.7.15
formatter.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : formatter.cpp
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 #include "formatter.hpp"
00015 #include "Format/format.hpp"
00016 
00017 int format_count= 0;
00018 int lazy_count= 0;
00019 
00020 /******************************************************************************
00021 * Standard formatting types
00022 ******************************************************************************/
00023 
00024 format
00025 make_format_none () {
00026   return tm_new<format_none_rep> ();
00027 }
00028 
00029 format
00030 make_format_width (SI width) {
00031   return tm_new<format_width_rep> (width);
00032 }
00033 
00034 format
00035 make_format_cell (SI width, int vpos, SI depth, SI height) {
00036   return tm_new<format_cell_rep> (width, vpos, depth, height);
00037 }
00038 
00039 format
00040 make_format_vstream (SI w, array<line_item> bef, array<line_item> aft) {
00041   return tm_new<format_vstream_rep> (w, bef, aft);
00042 }
00043 
00044 /*
00045 format
00046 make_query_width () {
00047   return tm_new<format_none_rep> (QUERY_WIDTH);
00048 }
00049 */
00050 
00051 format
00052 make_query_vstream_width (array<line_item> bef, array<line_item> aft) {
00053   return tm_new<query_vstream_width_rep> (bef, aft);
00054 }
00055 
00056 /******************************************************************************
00057 * The lazy class
00058 ******************************************************************************/
00059 
00060 lazy
00061 lazy_rep::produce (lazy_type request, format fm) {
00062   if (request == type) return this;
00063 
00064   if ((request == LAZY_BOX) && (fm->type == FORMAT_CELL)) {
00065     format_cell fc= (format_cell) fm;
00066     lazy tmp= produce (LAZY_VSTREAM, make_format_vstream (fc->width, 0, 0));
00067     return tmp->produce (request, fm);
00068   }
00069 
00070   if ((request == LAZY_BOX) && (fm->type == FORMAT_WIDTH)) {
00071     format_width fw= (format_width) fm;
00072     lazy tmp= produce (LAZY_VSTREAM, make_format_vstream (fw->width, 0, 0));
00073     return tmp->produce (request, fm);
00074   }
00075 
00076   cout << "\nThe lazy structure was " << ((tree) (*this)) << "\n";
00077   cout << "The format was " << ((tree) fm) << "\n";
00078   FAILED ("invalid production");
00079   return lazy ();
00080 }
00081 
00082 format
00083 lazy_rep::query (lazy_type request, format fm) {
00084   (void) request;
00085   cout << "\nThe lazy structure was " << ((tree) (*this)) << "\n";
00086   cout << "The format was " << ((tree) fm) << "\n";
00087   FAILED ("invalid query");
00088   return format ();
00089 }
00090 
00091 void
00092 lazy_rep::append (lazy lz) {
00093   (void) lz;
00094   cout << "\nThe lazy structure was " << ((tree) (*this)) << "\n";
00095   FAILED ("lazy structure is not a stream");
00096 }
00097 
00098 struct lazy_box_rep: public lazy_rep {
00099   box b;
00100   lazy_box_rep (box b2): lazy_rep (LAZY_BOX, b2->ip), b (b2) {}
00101   operator tree () { return (tree) b; }
00102 };
00103 
00104 struct lazy_box {
00105   EXTEND_NULL(lazy,lazy_box);
00106 };
00107 EXTEND_NULL_CODE(lazy,lazy_box);
00108 
00109 lazy::operator box () {
00110   lazy lz= rep->produce (LAZY_BOX, make_format_none ());
00111   lazy_box lb= (lazy_box) lz;
00112   return lb->b;
00113 }
00114 
00115 lazy
00116 make_lazy_box (box b) {
00117   return tm_new<lazy_box_rep> (b);
00118 }