Back to index

texmacs  1.0.7.15
rubber_boxes.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : rubber.cpp
00004 * DESCRIPTION: boxes whose dimensions are (partially) set by the user.
00005 *                - empty and plain boxes
00006 *                - parenthesis boxes
00007 *                - overline and underline like boxes
00008 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00009 *******************************************************************************
00010 * This software falls under the GNU general public license version 3 or later.
00011 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00012 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00013 ******************************************************************************/
00014 
00015 #include "boxes.hpp"
00016 
00017 /*****************************************************************************/
00018 // Bracket types from  ../math-mode/math-macros.hpp
00019 /*****************************************************************************/
00020 
00021 #define Lbracket        1011
00022 #define Lcrochet        1012
00023 #define Langular        1013
00024 #define Laccolade       1014
00025 #define Rbracket        1021
00026 #define Rcrochet        1022
00027 #define Rangular        1023
00028 #define Raccolade       1024
00029 #define Voidbr          1030
00030 #define Absolute        1031
00031 
00032 /*****************************************************************************/
00033 // Empty boxes
00034 /*****************************************************************************/
00035 
00036 struct empty_box_rep: public box_rep {
00037   empty_box_rep (path ip, int x1b, int y1b, int x2b, int y2b): box_rep (ip) {
00038     x3=x4=y3=y4=0; x1= x1b; y1=y1b; x2=x2b; y2=y2b; }
00039   operator tree () { return "empty"; }
00040   void display (renderer ren) { (void) ren; }
00041 };
00042 
00043 struct marker_box_rep: public box_rep {
00044   int pos;
00045   box ref;
00046   marker_box_rep (path ip2, int x1b, int y1b, int x2b, int y2b, box ref2):
00047     box_rep (is_accessible (ip2)? ip2->next: ip2),
00048     pos (is_accessible (ip2)? ip2->item: 0), ref (ref2) {
00049       x3= x4= y3= y4= 0; x1= x1b; y1= y1b; x2= x2b; y2= y2b; }
00050   operator tree () { return "marker"; }
00051   void display (renderer ren) { (void) ren; }
00052   path find_box_path (SI x, SI y, SI delta, bool force) {
00053     (void) x; (void) y; (void) delta; (void) force; return path (0); }
00054   path find_lip () {
00055     return is_accessible (ip)? descend (ip, pos): ip; }
00056   path find_rip () {
00057     return is_accessible (ip)? descend (ip, pos): ip; }
00058   path find_right_box_path () {
00059     return path (0); }
00060   path find_box_path (path p, bool& found) {
00061     found= !is_nil (p) && is_accessible (ip);
00062     return path (0); }
00063   path find_tree_path (path bp) {
00064     if (is_accessible (ip)) return reverse (descend (ip, pos));
00065     else return reverse (descend_decode (ip, 0)); }
00066   cursor find_cursor (path bp) {
00067     (void) bp; return cursor (0, 0, 0, y1, y2); }
00068   selection find_selection (path lbp, path rbp) {
00069     return selection (rectangles (),
00070                     find_tree_path (lbp), find_tree_path (rbp)); }
00071   SI sub_lo_base (int level) { return min (y1, ref->sub_lo_base (level)); }
00072   SI sub_hi_lim (int level) { return ref->sub_hi_lim (level); }
00073   SI sup_lo_lim (int level) { return ref->sup_lo_lim (level); }
00074   SI sup_lo_base (int level) { return ref->sup_lo_base (level); }
00075   SI sup_hi_lim (int level) { return max (y2, ref->sup_hi_lim (level)); }
00076 };
00077 
00078 /*****************************************************************************/
00079 // Brackets
00080 /*****************************************************************************/
00081 
00082 struct bracket_box_rep: public box_rep {
00083   int br_type;
00084   color col;
00085   SI penw;
00086 
00087   bracket_box_rep (path ip, int br_type2, SI penw, color c, SI y1b, SI y2b);
00088   operator tree () { return "bracket"; }
00089   void display (renderer ren);
00090 };
00091 
00092 SI
00093 bracket_width (int br_type, SI height, SI penw) {
00094   switch (br_type) {
00095   case Lbracket:
00096   case Rbracket:
00097   case Lcrochet:
00098   case Rcrochet:
00099   case Laccolade:
00100   case Raccolade:
00101   case Langular:
00102   case Rangular:
00103     {
00104       SI ref_size  = penw/2;
00105       double factor= sqrt (((double) height) / ((double) ref_size));
00106       if (factor<2) factor=2;
00107       factor=factor*1.412;
00108       return (2*penw) + ((SI) (((double) height)/factor));
00109     }
00110   case Absolute:
00111     return 2*penw;
00112   case Voidbr:
00113   default:
00114     return 0;
00115   }
00116 }
00117 
00118 bracket_box_rep::bracket_box_rep (path ip, int br_type2, SI penw2, color c,
00119                               SI y1b, SI y2b): box_rep (ip) {
00120   br_type= br_type2;
00121   penw   = penw2;
00122   col    = c;
00123   x1 = x3 = 0;
00124   x2 = x4 = bracket_width (br_type, y2b- y1b, penw);
00125   y1 = y3 = y1b;
00126   y2 = y4 = y2b;
00127 }
00128 
00129 void
00130 draw_bracket (renderer ren, int br_type, SI x, SI y, SI w, SI h, SI lw) {
00131   x+=lw; w-=2*lw;
00132   y+=lw; h-=2*lw;
00133   switch (br_type) {
00134   case Lbracket:
00135     {
00136       int i;
00137       SI ww= (SI) (((double) w) / (1.0- sqrt (0.5)));
00138       SI hh= (SI) (((double) h) / sqrt (2.0));
00139       SI ox= x+ ww;
00140       SI oy= y+ (h>>1);
00141       ren->set_line_style (PIXEL);
00142       for (i=0; i<lw; i+=PIXEL)
00143        ren->arc (ox-ww+i, oy-hh, ox+ww-i, oy+hh, 135<<6, 90<<6);
00144     }
00145     break;
00146   case Rbracket:
00147     {
00148       int i;
00149       SI ww= (SI) (((double) w) / (1.0- sqrt (0.5)));
00150       SI hh= (SI) (((double) h) / sqrt (2.0));
00151       SI ox= x+ w- ww;
00152       SI oy= y+ (h>>1);
00153       ren->set_line_style (PIXEL);
00154       for (i=0; i<lw; i+=PIXEL)
00155        ren->arc (ox-ww+i, oy-hh, ox+ww-i, oy+hh, -(45<<6), 90<<6);
00156     }
00157     break;
00158   case Lcrochet:
00159     ren->line (x, y, x, y+h);
00160     ren->line (x, y, x+w, y);
00161     ren->line (x, y+h, x+w, y+h);
00162     break;
00163   case Rcrochet:
00164     ren->line (x+w, y, x+w, y+h);
00165     ren->line (x, y, x+w, y);
00166     ren->line (x, y+h, x+w, y+h);
00167     break;
00168   case Laccolade:
00169   case Raccolade:
00170     {
00171       SI d = w>>1;
00172       SI ox= x+ (w>>1);
00173       SI oy= y+ (h>>1);
00174       // SI xx= x+ w;
00175       SI yy= y+ h;
00176       ren->line (ox, y+d-PIXEL, ox, oy-d);
00177       ren->line (ox, oy+d-PIXEL, ox, yy-d);
00178       if (br_type==Laccolade) {
00179        ren->arc (ox, yy-w, ox+w, yy, 90<<6, 90<<6);
00180        ren->arc (ox-w, oy, ox, oy+w, 270<<6, 90<<6);
00181        ren->arc (ox-w, oy-w, ox, oy, 0, 90<<6);
00182        ren->arc (ox, y, ox+w, y+w, 180<<6, 90<<6);
00183       }
00184       else {
00185        ren->arc (ox-w, yy-w, ox, yy, 0, 90<<6);
00186        ren->arc (ox, oy, ox+w, oy+w, 180<<6, 90<<6);
00187        ren->arc (ox, oy-w, ox+w, oy, 90<<6, 90<<6);
00188        ren->arc (ox-w, y, ox, y+w, 270<<6, 90<<6);
00189       }
00190     }
00191     break;
00192   case Langular:
00193     ren->line (x, y+(h>>1), x+w, y);
00194     ren->line (x, y+(h>>1), x+w, y+h);
00195     break;
00196   case Rangular:
00197     ren->line (x+w, y+(h>>1), x, y);
00198     ren->line (x+w, y+(h>>1), x, y+h);
00199     break;
00200   case Absolute:
00201     ren->line (x, y, x, y+h);
00202     break;
00203   }
00204 }
00205 
00206 void
00207 bracket_box_rep::display (renderer ren) {
00208   ren->set_line_style (penw);
00209   ren->set_color (col);
00210   draw_bracket (ren, br_type, 0, y1, x2, y2-y1, penw);
00211 }
00212 
00213 /*****************************************************************************/
00214 // box construction routines
00215 /*****************************************************************************/
00216 
00217 box
00218 empty_box (path ip, int x1, int y1, int x2, int y2) {
00219   return tm_new<empty_box_rep> (ip, x1, y1, x2, y2);
00220 }
00221 
00222 box
00223 marker_box (path ip, int x1, int y1, int x2, int y2, box ref) {
00224   return tm_new<marker_box_rep> (ip, x1, y1, x2, y2, ref);
00225 }
00226 
00227 box
00228 bracket_box (path ip, int br_type, SI penw, color col, SI y1, SI y2) {
00229   return tm_new<bracket_box_rep> (ip, br_type, penw, col, y1, y2);
00230 }