コード例 #1
0
 private void findLeaves(Area root, Vector<Area> dest) {
   if (root.isLeaf()) {
     if (bounds == null || root.getBounds().intersects(bounds)) dest.add(root);
   } else {
     for (int i = 0; i < root.getChildCount(); i++) findLeaves(root.getChildArea(i), dest);
   }
 }
コード例 #2
0
  @Override
  public void apply(AreaTree atree, Area root) {
    Vector<Area> leaves = new Vector<Area>();
    findLeaves(root, leaves);
    sortLeaves(leaves);

    /*System.out.println("MAX:");
    for (int i = 0; i < 50 && i < leaves.size(); i++)
    {
        Area a = leaves.elementAt(i);
        System.out.println(a.getFontSize() + " " + a.getFontWeight() + " " + a);
    }*/

    // find start and end of the title
    float maxsize = leaves.firstElement().getFontSize(); // largest font size
    int maxlen = 0;
    int first = -1;
    int last = -1;
    int cur = 0;
    // find longest text of the maximal font size
    for (Area a : leaves) {
      if (a.getFontSize() == maxsize) {
        final String text = a.getText().trim();
        if (text.length() > maxlen) {
          maxlen = text.length();
          first = cur;
        }
      }
      cur++;
    }
    // expand up
    while (first > 0) {
      Area before = leaves.elementAt(first - 1);
      if (before != null && before.getFontSize() == maxsize) first--;
      else break;
    }
    // expand down
    if (first >= 0) {
      AreaImpl fa = (AreaImpl) leaves.elementAt(first);
      resultBounds = fa.getBounds();
      Rectangular pos = fa.getGridPosition();
      // System.out.println("FIRST: " + fa);
      // find the last index
      last = first;
      for (int i = first + 1; i < leaves.size(); i++) {
        final AreaImpl a = (AreaImpl) leaves.elementAt(i);
        if (a.getFontSize() == maxsize) {
          last = i;
          pos.expandToEnclose(a.getGridPosition());
          fa.joinArea(a, pos, true);
          resultBounds.expandToEnclose(a.getBounds());
        } else break;
      }
      // System.out.println("LAST: " + leaves.elementAt(last));

      fa.addTag(new EswcTag("vtitle"), 0.6f);
    }
    // find short names of the same size
    for (Area a : leaves) {
      if (a.getFontSize() == maxsize) {
        Vector<String> snames = AreaUtils.findShortTitles(a);
        if (!snames.isEmpty()) {
          a.addTag(new EswcTag("vshort"), 0.7f);
          break;
        }
      }
    }
  }