home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2001 December / dppcpro1201.iso / Extras / maple / Viewer / WebEQ / MMLViewerInstall.cab / MMLViewerApplet.cab / webeq3 / schema / MScripts.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-05-24  |  5.4 KB  |  213 lines

  1. package webeq3.schema;
  2.  
  3. import java.util.Hashtable;
  4. import webeq3.app.Equation;
  5.  
  6. public abstract class MScripts extends LineBreakRewriter {
  7.    Box base = null;
  8.    Box low = null;
  9.    Box high = null;
  10.    double itc = (double)0.0F;
  11.    int truebasewidth = 0;
  12.    int lspace = 0;
  13.    int rspace = 0;
  14.    int high_ascent = 0;
  15.    int low_descent = 0;
  16.    boolean move_scripts = false;
  17.    boolean stretchy = false;
  18.    private static Hashtable baseCheck = new Hashtable();
  19.  
  20.    public MScripts(Box var1) {
  21.       super(var1);
  22.    }
  23.  
  24.    public MScripts() {
  25.    }
  26.  
  27.    public MScripts(Equation var1) {
  28.       super(var1);
  29.    }
  30.  
  31.    public void size() {
  32.       ((Box)this).setfont(super.depth);
  33.       super.bgcolor = ((Box)this).resolveColor(17);
  34.       super.fgcolor = ((Box)this).resolveColor(4);
  35.       this.base = ((Box)this).getChild(0);
  36.       this.low = ((Box)this).getChild(1);
  37.       this.high = ((Box)this).getChild(2);
  38.       this.setChildDepths();
  39.       this.base.layout();
  40.       this.low.layout();
  41.       this.high.layout();
  42.       super.embellished_op = this.base.embellished_op;
  43.  
  44.       Box var1;
  45.       for(var1 = this.base; this.base_check(var1); var1 = var1.getChild(0)) {
  46.       }
  47.  
  48.       if (var1.isItalic()) {
  49.          this.itc = 0.13;
  50.       }
  51.  
  52.       this.truebasewidth = this.base.getWidth();
  53.       if (this.base.getClass().getName().equals("webeq3.schema.MO")) {
  54.          this.lspace = ((MO)this.base).op.lspace;
  55.          this.rspace = ((MO)this.base).op.rspace;
  56.          this.truebasewidth = this.truebasewidth - this.lspace - this.rspace;
  57.          if (((MO)this.base).op.stretchy) {
  58.             this.stretchy = true;
  59.          }
  60.  
  61.          if (((MO)this.base).op.movescripts) {
  62.             this.move_scripts = true;
  63.          }
  64.  
  65.          if ("true".equals(((Box)this).getAttributeByIndex(21))) {
  66.             this.move_scripts = false;
  67.          }
  68.  
  69.          if (this.base.depth > 0) {
  70.             this.move_scripts = false;
  71.          }
  72.       }
  73.  
  74.       if (this.itc == (double)0.0F && (this.high.isItalic() || this.low.isItalic())) {
  75.          this.truebasewidth += (int)(0.2 * (double)super.xheight);
  76.       }
  77.  
  78.       this.sizeScripts();
  79.    }
  80.  
  81.    public void sizeSubSup() {
  82.       Box var1 = this.low;
  83.       Box var2 = this.high;
  84.       double var3 = (double)0.0F;
  85.       double var5 = (double)0.0F;
  86.       int var7 = var1.getWidth() - (int)(this.itc * (double)this.base.getDescent() + (double)0.5F);
  87.       if (var2.getWidth() + (int)(this.itc * (double)this.base.getAscent()) > var7) {
  88.          var7 = var2.getWidth() + (int)(this.itc * (double)this.base.getAscent() + (double)0.5F);
  89.       }
  90.  
  91.       super.width = this.lspace + this.truebasewidth + var7 + this.rspace + 1;
  92.       if (var1.getHeight() != 0) {
  93.          try {
  94.             var3 = Double.valueOf(((Box)this).getAttributeByIndex(25));
  95.          } catch (NumberFormatException var11) {
  96.          }
  97.  
  98.          if (var3 < 0.35) {
  99.             var3 = 0.35;
  100.          }
  101.  
  102.          this.low_descent = (int)(var3 * (double)super.xheight) + var1.getDescent();
  103.          if (this.base.getClass().getName().equals("webeq3.schema.MI")) {
  104.             if (this.low_descent < this.base.getDescent() - (int)(0.2 * (double)super.xheight)) {
  105.                this.low_descent = this.base.getDescent() + (int)(0.1 * (double)super.xheight);
  106.             }
  107.          } else if (this.low_descent < this.base.getDescent() + (int)(0.1 * (double)super.xheight)) {
  108.             this.low_descent = this.base.getDescent() + (int)(0.1 * (double)super.xheight);
  109.          }
  110.  
  111.          if (this.high.getHeight() != 0) {
  112.             if (this.low.getHeight() - this.low_descent > (int)(0.6 * (double)super.xheight)) {
  113.                this.low_descent = this.low.getHeight() - (int)(0.6 * (double)super.xheight);
  114.             }
  115.          } else if (this.low.getHeight() - this.low_descent > (int)(0.8 * (double)super.xheight)) {
  116.             this.low_descent = this.low.getHeight() - (int)(0.8 * (double)super.xheight);
  117.          }
  118.       }
  119.  
  120.       if (var2.getHeight() != 0) {
  121.          try {
  122.             var5 = Double.valueOf(((Box)this).getAttributeByIndex(26));
  123.          } catch (NumberFormatException var10) {
  124.          }
  125.  
  126.          double var8 = var2.depth >= 3 ? 0.55 : 0.8;
  127.          var8 = var8 > var5 ? var8 : var5;
  128.          this.high_ascent = (int)(var8 * (double)super.xheight) + var2.getAscent();
  129.          if (this.high_ascent < this.base.getAscent() + var2.getAscent() - (int)(0.65 * (double)super.xheight)) {
  130.             this.high_ascent = this.base.getAscent() + var2.getAscent() - (int)(0.65 * (double)super.xheight);
  131.          }
  132.  
  133.          if (var1.getHeight() != 0) {
  134.             if (this.high_ascent - var2.getHeight() < (int)(0.8 * (double)super.xheight)) {
  135.                this.high_ascent = var2.getHeight() + (int)(0.8 * (double)super.xheight);
  136.             }
  137.          } else if (this.high_ascent - var2.getHeight() < (int)((double)0.25F * (double)super.xheight)) {
  138.             this.high_ascent = var2.getHeight() + (int)((double)0.25F * (double)super.xheight);
  139.          }
  140.       }
  141.  
  142.       super.ascent = this.base.getAscent() < this.high_ascent ? this.high_ascent : this.base.getAscent();
  143.       super.descent = this.base.getDescent() < this.low_descent ? this.low_descent : this.base.getDescent();
  144.       super.height = super.ascent + super.descent;
  145.    }
  146.  
  147.    public void sizeUnderOver(int var1, int var2) {
  148.       int var3 = this.truebasewidth / 2;
  149.       int var4 = this.truebasewidth - var3;
  150.       if ((int)((double)(this.low.getWidth() / 2) + this.itc * (double)this.base.getDescent() + (double)0.5F) > var3) {
  151.          var3 = (int)((double)(this.low.getWidth() / 2) + this.itc * (double)this.base.getDescent() + (double)0.5F);
  152.       }
  153.  
  154.       if ((int)((double)(this.low.getWidth() / 2) - this.itc * (double)this.base.getDescent() + (double)0.5F) > var4) {
  155.          var4 = (int)((double)(this.low.getWidth() / 2) - this.itc * (double)this.base.getDescent() + (double)0.5F);
  156.       }
  157.  
  158.       if ((int)((double)(this.high.getWidth() / 2) - this.itc * (double)this.base.getAscent() + (double)0.5F) > var3) {
  159.          var3 = (int)((double)(this.high.getWidth() / 2) - this.itc * (double)this.base.getAscent() + (double)0.5F);
  160.       }
  161.  
  162.       if ((int)((double)(this.high.getWidth() / 2) + this.itc * (double)this.base.getAscent() + (double)0.5F) > var4) {
  163.          var4 = (int)((double)(this.high.getWidth() / 2) + this.itc * (double)this.base.getAscent() + (double)0.5F);
  164.       }
  165.  
  166.       super.width = var3 + var4 + this.lspace + this.rspace;
  167.       super.descent = this.base.getDescent() + this.low.getHeight() + var1;
  168.       super.ascent = this.base.getAscent() + this.high.getHeight() + var2;
  169.       super.height = super.ascent + super.descent;
  170.    }
  171.  
  172.    public void positionUnderOver() {
  173.       int var1 = super.width - this.lspace - this.rspace;
  174.       this.base.setTop(super.ascent - this.base.getAscent());
  175.       this.base.setLeft((var1 - this.truebasewidth) / 2 + this.lspace);
  176.       this.low.setTop(super.height - this.low.getHeight());
  177.       this.low.setLeft((int)((double)((var1 - this.low.getWidth()) / 2) - this.itc * (double)this.base.getDescent() + (double)0.5F) + this.lspace);
  178.       this.high.setTop(0);
  179.       this.high.setLeft((int)((double)((var1 - this.high.getWidth()) / 2) + this.itc * (double)this.base.getAscent() + (double)0.5F) + this.lspace);
  180.    }
  181.  
  182.    public void positionSubSup() {
  183.       this.base.setTop(super.ascent - this.base.getAscent());
  184.       this.base.setLeft(0);
  185.       this.low.setTop(super.ascent + this.low_descent - this.low.getHeight());
  186.       this.low.setLeft(this.lspace + this.truebasewidth - (int)(this.itc * (double)this.low_descent + (double)0.5F));
  187.       this.high.setTop(super.ascent - this.high_ascent);
  188.       this.high.setLeft(this.lspace + this.truebasewidth + (int)(this.itc * (double)this.high_ascent + (double)0.5F));
  189.    }
  190.  
  191.    protected boolean base_check(Box var1) {
  192.       String var2 = var1.getClass().getName();
  193.       return "webeq3.schema.MRow".equals(var2) && var1.embellished_op ? true : baseCheck.containsKey(var2);
  194.    }
  195.  
  196.    abstract void setChildDepths();
  197.  
  198.    abstract void sizeScripts();
  199.  
  200.    public boolean isAtomic() {
  201.       return super.useLinearForm ? super.lb_rewrite.isAtomic() : super.atomic;
  202.    }
  203.  
  204.    static {
  205.       baseCheck.put("webeq3.schema.MSubsup", baseCheck);
  206.       baseCheck.put("webeq3.schema.MSub", baseCheck);
  207.       baseCheck.put("webeq3.schema.MSup", baseCheck);
  208.       baseCheck.put("webeq3.schema.MUnderover", baseCheck);
  209.       baseCheck.put("webeq3.schema.MUnder", baseCheck);
  210.       baseCheck.put("webeq3.schema.MOver", baseCheck);
  211.    }
  212. }
  213.