Beispiel #1
0
 /**
  * @return a list of constituent zones. The list holds the logical reading-order if a
  *     ReadingOrderResolver was run on the original document.
  */
 public List<BxZone> asZones() {
   List<BxZone> ret = new ArrayList<BxZone>();
   for (BxPage page : asPages()) {
     ret.addAll(page.getZones());
   }
   return ret;
 }
Beispiel #2
0
 public BxDocument addPage(BxPage page) {
   if (page != null) {
     page.setId(Integer.toString(this.curPageNumber++));
     page.setParent(this);
     this.pages.add(page);
   }
   return this;
 }
  private BxPage parsePageNode(Element elem) {
    BxPage page = new BxPage();

    double minX = 0, minY = 0, maxX = 0, maxY = 0;
    boolean started = false;

    List<Element> e = getChildren("Zone", elem);
    for (Element zo : e) {
      BxZone zon = parseZoneNode(zo);
      page.addZone(zon);

      BxBounds zoneBounds = zon.getBounds();
      if (!started) {
        minX = zoneBounds.getX();
        minY = zoneBounds.getY();
        maxX = zoneBounds.getX() + zoneBounds.getWidth();
        maxY = zoneBounds.getY() + zoneBounds.getHeight();
        started = true;
      }

      if (zoneBounds.getX() < minX) {
        minX = zoneBounds.getX();
      }
      if (zoneBounds.getX() + zoneBounds.getWidth() > maxX) {
        maxX = zoneBounds.getX() + zoneBounds.getWidth();
      }
      if (zoneBounds.getY() < minY) {
        minY = zoneBounds.getY();
      }
      if (zoneBounds.getY() + zoneBounds.getHeight() > maxY) {
        maxY = zoneBounds.getY() + zoneBounds.getHeight();
      }
    }

    Collections.sort(
        page.getZones(),
        new Comparator() {

          @Override
          public int compare(Object t, Object t1) {
            BxZone z1 = (BxZone) t;
            BxZone z2 = (BxZone) t1;
            int ret = Double.compare(z1.getBounds().getY(), z2.getBounds().getY());
            if (ret == 0) {
              ret = Double.compare(z1.getBounds().getX(), z2.getBounds().getX());
            }
            return ret;
          }
        });
    return page.setBounds(new BxBounds(minX, minY, maxX - minX, maxY - minY));
  }
 private void appendPage(Document doc, Element parent, BxPage page, Object... hints)
     throws TransformationException {
   Element node = doc.createElement("Page");
   appendPropertyIfNotNull(doc, node, "PageID", page.getId());
   appendProperty(doc, node, "PageType", "");
   appendProperty(doc, node, "PageNumber", "");
   appendProperty(doc, node, "PageColumns", "");
   appendPropertyIfNotNull(doc, node, "PageNext", page.getNextId());
   appendProperty(doc, node, "PageZones", "");
   for (BxZone zone : page.getZones()) {
     appendZone(doc, node, zone, hints);
   }
   parent.appendChild(node);
 }