コード例 #1
0
 // pre: findLinesWidth carried out and elements sorted in ascending order
 public TextSegment getTopElementMatchingFontsizeAfterSorting() {
   TextSegment retVal = null;
   for (TextSegment s : items) {
     for (CompositeSegment<? extends TextSegment> l : foundLines) {
       if (l.getItems().contains(s)) {
         // if (s.getFontSize() == l.getFontSize())
         if (Utils.within(s.getFontSize(), l.getFontSize(), s.getFontSize() * 0.1f)) return s;
       }
     }
   }
   return retVal;
 }
コード例 #2
0
 // pre: findLinesWidth carried out and elements sorted in ascending order
 public TextSegment getBottomElementMatchingFontsizeAfterSorting() {
   TextSegment retVal = null;
   for (int n = items.size() - 1; n >= 0; n--) {
     TextSegment s = items.get(n);
     for (CompositeSegment<? extends TextSegment> l : foundLines) {
       if (l.getItems().contains(s)) {
         // if (s.getFontSize() == l.getFontSize())
         if (Utils.within(s.getFontSize(), l.getFontSize(), s.getFontSize() * 0.1f)) return s;
       }
     }
   }
   return retVal;
 }
コード例 #3
0
  protected void processLines() {
    if (foundLines.size() > 1) {
      // first find averages

      float avgX1 = 0.0f;
      float avgXcen = 0.0f;
      float avgX2 = 0.0f;
      float afs = 0.0f;
      float als = 0.0f;
      boolean clashingLines = false;

      CompositeSegment<? extends TextSegment> prevLine = null;
      for (CompositeSegment<? extends TextSegment> l : foundLines) {
        avgX1 += l.getX1();
        avgXcen += l.getXmid();
        avgX2 += l.getX2();
        afs += l.getFontSize();

        if (prevLine != null) {
          float lineSpacing = prevLine.getY1() - l.getY1();
          als += lineSpacing;
          if (SegmentUtils.vertIntersect(prevLine, l.getYmid())) clashingLines = true;
        }
        prevLine = l;
      }

      avgX1 /= foundLines.size();
      avgXcen /= foundLines.size();
      avgX2 /= foundLines.size();
      afs /= foundLines.size();
      fontSize = afs;
      als /= (foundLines.size() - 1);

      //    		System.out.println("setting als to: " + als);

      //    		lineSpacing = als;
      lineSpacing = als / afs; // changed 30.10.10

      // now, see if they are within allowed error
      boolean constantX1 = true,
          constantXcen = true,
          constantX2 = true,
          constantfs = true,
          constantls = true;
      float tolerance = afs * 0.5f;
      prevLine = null;
      for (CompositeSegment<? extends TextSegment> l : foundLines) {
        if (!Utils.within(l.getX1(), avgX1, tolerance)) constantX1 = false;
        if (!Utils.within(l.getXmid(), avgXcen, tolerance)) constantXcen = false;
        if (!Utils.within(l.getX2(), avgX2, tolerance)) constantX2 = false;
        if (!Utils.within(l.getFontSize(), afs, afs * 0.1f)) constantfs = false;

        if (prevLine != null) {
          float lineSpacing = prevLine.getY1() - l.getY1();
          if (!Utils.within(lineSpacing, als, afs * 0.2f)) constantls = false;
        }
        prevLine = l;
      }
      if (constantX1 && constantX2) textAlignment = ALIGN_LCR;
      else if (constantX1 && constantXcen) textAlignment = ALIGN_LC;
      else if (constantXcen && constantX2) textAlignment = ALIGN_CR;
      else if (constantX1) textAlignment = ALIGN_L;
      else if (constantXcen) textAlignment = ALIGN_C;
      else if (constantX2) textAlignment = ALIGN_R;
      else textAlignment = ALIGN_NONE;

      if (constantls) constantLS = true;
      else constantLS = false;
      if (constantfs) constantFS = true;
      else constantFS = false;
      if (!clashingLines) uniqueLines = true;
      else uniqueLines = false;

      //    		this.fontSize = afs;
    } else {
      // if singleton, or if no sub-objects etc.
    }
  }