public void draw(Graphics2D g2, float x, float y) {
   startDraw(g2, x, y);
   float xPos = x;
   for (Box box : children) {
     box.draw(g2, xPos, y + box.shift);
     xPos += box.getWidth();
   }
   endDraw(g2);
 }
 private void recalculate(Box b) {
   curPos += b.getWidth();
   width = Math.max(width, curPos);
   height =
       Math.max((children.size() == 0 ? Float.NEGATIVE_INFINITY : height), b.height - b.shift);
   depth = Math.max((children.size() == 0 ? Float.NEGATIVE_INFINITY : depth), b.depth + b.shift);
 }
Exemple #3
0
  public Box createBox(TeXEnvironment env) {
    TeXFont tf = env.getTeXFont();
    int style = env.getStyle();

    // set base in cramped style
    Box b = (base == null ? new StrutBox(0, 0, 0, 0) : base.createBox(env.crampStyle()));

    float u = b.getWidth();
    float s = 0;
    if (base instanceof CharSymbol) s = tf.getSkew(((CharSymbol) base).getCharFont(tf), style);

    // retrieve best Char from the accent symbol
    Char ch = tf.getChar(accent.getName(), style);
    while (tf.hasNextLarger(ch)) {
      Char larger = tf.getNextLarger(ch, style);
      if (larger.getWidth() <= u) ch = larger;
      else break;
    }

    // calculate delta
    float delta = Math.min(b.getHeight(), tf.getXHeight(style, ch.getFontCode()));

    // create vertical box
    VerticalBox vBox = new VerticalBox();

    // accent
    Box y;
    float italic = ch.getItalic();
    if (italic > TeXFormula.PREC) {
      y = new HorizontalBox(new CharBox(ch));
      y.add(new StrutBox(italic, 0, 0, 0));
    } else y = new CharBox(ch);

    // if diff > 0, center accent, otherwise center base
    float diff = (u - y.getWidth()) / 2;
    y.setShift(s + (diff > 0 ? diff : 0));
    if (diff < 0) b = new HorizontalBox(b, y.getWidth(), TeXConstants.ALIGN_CENTER);
    vBox.add(y);

    // kern
    vBox.add(new StrutBox(0, -delta, 0, 0));
    // base
    vBox.add(b);

    // set height and depth vertical box
    float total = vBox.getHeight() + vBox.getDepth(), d = b.getDepth();
    vBox.setDepth(d);
    vBox.setHeight(total - d);
    return vBox;
  }
 public HorizontalBox(Box b, float w, int alignment) {
   float rest = w - b.getWidth();
   if (alignment == TeXConstants.ALIGN_CENTER) {
     StrutBox s = new StrutBox(rest / 2, 0, 0, 0);
     add(s);
     add(b);
     add(s);
   } else if (alignment == TeXConstants.ALIGN_LEFT) {
     add(b);
     add(new StrutBox(rest, 0, 0, 0));
   } else if (alignment == TeXConstants.ALIGN_RIGHT) {
     add(new StrutBox(rest, 0, 0, 0));
     add(b);
   }
 }
 public final void add(Box b) {
   recalculate(b);
   super.add(b);
 }