Esempio n. 1
0
 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);
 }
Esempio n. 2
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;
  }