Example #1
0
  public boolean addWord(WordInfo wi) {
    double nlh = wi.getLineHeight();
    if (nlh <= lineHeight) return insertWord(wi);
    fr.newLineHeight(nlh);

    if (!updateRangeInfo()) {
      if (lineHeight > 0) // restore old LH
      fr.newLineHeight(lineHeight);
      return false;
    }

    if (!insertWord(wi)) {
      if (lineHeight > 0) // Failure, restore old line Height.
      setLineHeight(lineHeight);
      return false;
    }

    // Success, word fits on line.
    lineHeight = nlh;
    if (wi.getAscent() > ascent) ascent = wi.getAscent();
    if (wi.getDescent() > descent) descent = wi.getDescent();
    hLeading = (nlh - (ascent + descent)) / 2;
    baseline = (float) (fr.getCurrentY() + hLeading + ascent);
    return true;
  }
Example #2
0
  /**
   * This method updates the line height and recalculates the available flow ranges for the line.
   */
  public boolean setLineHeight(double lh) {
    fr.newLineHeight(lh);

    if (updateRangeInfo()) {
      lineHeight = lh;
      return true;
    }

    // restore line height.
    if (lineHeight > 0) fr.newLineHeight(lineHeight);
    return false;
  }
Example #3
0
 public LineInfo(FlowRegions fr, BlockInfo bi, boolean paraStart) {
   this.fr = fr;
   this.bi = bi;
   this.lineHeight = bi.getLineHeight();
   this.ascent = bi.getAscent();
   this.descent = bi.getDescent();
   this.hLeading = (lineHeight - (ascent + descent)) / 2;
   this.baseline = (float) (fr.getCurrentY() + hLeading + ascent);
   this.paraStart = paraStart;
   this.paraEnd = false;
   if (lineHeight > 0) {
     fr.newLineHeight(lineHeight);
     updateRangeInfo();
   }
 }
Example #4
0
  protected boolean updateRangeInfo() {
    fr.resetRange();
    int nr = fr.getNumRangeOnLine();
    if (nr == 0) return false;

    numRanges = nr;

    if (ranges == null) {
      rangeAdv = new double[numRanges];
      ranges = new double[2 * numRanges];
    } else if (numRanges > rangeAdv.length) {
      int sz = 2 * rangeAdv.length;
      if (sz < numRanges) sz = numRanges;
      rangeAdv = new double[sz];
      ranges = new double[2 * sz];
    }

    for (int r = 0; r < numRanges; r++) {
      double[] rangeBounds = fr.nextRange();
      // System.err.println("RG["+r+"]: [" +
      //                    rangeBounds[0] + "," + rangeBounds[1] +"]");
      double r0 = rangeBounds[0];
      if (r == 0) {
        double delta = bi.getLeftMargin();
        if (paraStart) {
          double indent = bi.getIndent();
          // Limit indent to the amount of margin we have.
          if (delta < -indent) delta = 0;
          else delta += indent;
        }
        r0 += delta;
      }

      double r1 = rangeBounds[1];
      if (r == numRanges - 1) r1 -= bi.getRightMargin();
      ranges[2 * r] = r0;
      ranges[2 * r + 1] = r1;
    }

    return true;
  }
Example #5
0
 public boolean gotoY(double y) {
   if (fr.gotoY(y)) return true;
   if (lineHeight > 0) updateRangeInfo();
   this.baseline = (float) (fr.getCurrentY() + hLeading + ascent);
   return false;
 }
Example #6
0
 public double getCurrentY() {
   return fr.getCurrentY();
 }