Back to index

texmacs  1.0.7.15
lazy_vstream.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : lazy_vstream.cpp
00004 * DESCRIPTION: Last pass for typesetting vstreams;
00005 *              hyphenation and creation of page items
00006 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00007 *******************************************************************************
00008 * This software falls under the GNU general public license version 3 or later.
00009 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00010 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00011 ******************************************************************************/
00012 
00013 #include "Line/lazy_vstream.hpp"
00014 #include "Boxes/construct.hpp"
00015 #include "Line/lazy_paragraph.hpp"
00016 array<line_item> typeset_concat_or_table (edit_env env, tree t, path ip);
00017 
00018 lazy_vstream_rep::lazy_vstream_rep (
00019   path ip, tree channel2, array<page_item> l2, stack_border sb2):
00020     lazy_rep (LAZY_VSTREAM, ip),
00021     channel (channel2), l (l2), sb (sb2) {}
00022 
00023 lazy_vstream_rep::operator tree () {
00024   return tuple ("vertical stream", channel);
00025 }
00026 
00027 lazy
00028 make_lazy_vstream (edit_env env, tree t, path ip, tree channel) {
00029   SI width, d1, d2, d3, d4, d5, d6, d7;
00030   env->get_page_pars (width, d1, d2, d3, d4, d5, d6, d7);
00031   lazy lz= make_lazy (env, t, ip);
00032   lz= lz->produce (LAZY_VSTREAM, make_format_vstream (width, 0, 0));
00033   lazy_vstream lwvs= (lazy_vstream) lz;
00034   lwvs->channel= channel;
00035   /* Direct modification of y1 and y2 limits should be avoided */
00036   box& tb= lwvs->l[0]->b;
00037   if (tb->y2 < env->fn->y2) tb->y2= env->fn->y2;
00038   box& bb= lwvs->l[N(lwvs->l)-1]->b;
00039   if (bb->y1 > env->fn->y1) bb->y1= env->fn->y1;
00040   /*************************************************************/
00041   return lwvs;
00042 }
00043 
00044 box
00045 format_vstream_as_box (
00046   array<page_item> l, path ip, int vpos, SI depth, SI height)
00047 {
00048   int i, n= N(l);
00049   array<box> lines_bx (n);
00050   array<SI>  lines_ht (n);
00051   for (i=0; i<n; i++) {
00052     page_item item= copy (l[i]);
00053     lines_bx[i]= item->b;
00054     lines_ht[i]= item->spc->def;
00055   }
00056 
00057   box b= stack_box (ip, lines_bx, lines_ht);
00058   SI dy= 0, bot= 0, top= 0;
00059   if (n>0) {
00060     if (vpos>0) dy= b->sy (0);
00061     else if (vpos<0) dy= b->sy (n-1);
00062     else dy= (b->sy (n>>1) + b->sy ((n-1)>>1)) >> 1;
00063     if (depth  > 0) bot= max (0, depth + b[n-1]->y1);
00064     if (height > 0) top= max (0, height- b[0  ]->y2);
00065   }
00066   if (dy != 0) b= move_box (ip, b, 0, -dy);
00067   if ((top != 0) || (bot != 0))
00068     b= resize_box (ip, b, b->x1, b->y1 - bot, b->x2, b->y2 + top);
00069   return b;
00070 }
00071 
00072 box
00073 typeset_as_paragraph (edit_env env, tree t, path ip) {
00074   // cout << "Typeset paragraph " << t << "\n";
00075   lazy_paragraph par (env, ip);
00076   par->a= typeset_concat_or_table (env, t, ip);
00077   par->format_paragraph ();
00078   array<page_item> l= par->sss->l;
00079   return format_vstream_as_box (l, ip, 1, -env->fn->y1, env->fn->y2);
00080 }
00081 
00082 lazy
00083 lazy_vstream_rep::produce (lazy_type request, format fm) {
00084   if (request == type) return this;
00085   if (request == LAZY_BOX) {
00086     int  vpos  = 1;
00087     SI   depth = 0;
00088     SI   height= 0;
00089     if (fm->type == FORMAT_CELL) {
00090       format_cell fc= (format_cell) fm;
00091       vpos  = fc->vpos;
00092       depth = fc->depth;
00093       height= fc->height;
00094     }
00095     box b= format_vstream_as_box (l, ip, vpos, depth, height);
00096     return make_lazy_box (b);
00097   }
00098   return lazy_rep::produce (request, fm);
00099 }