Esempio n. 1
0
 public void inheritListSettings(int listNumber, int listLevel) {
   for (RtfBasicElement rtfElement : chunks) {
     if (rtfElement instanceof RtfList) {
       ((RtfList) rtfElement).setListNumber(listNumber);
       ((RtfList) rtfElement).setListLevel(listLevel);
       ((RtfList) rtfElement).setParent(this.parentList);
     }
   }
 }
Esempio n. 2
0
 public boolean writeDefinition(OutputStream out) throws IOException {
   for (RtfBasicElement rtfElement : chunks) {
     if (rtfElement instanceof RtfList) {
       RtfList rl = (RtfList) rtfElement;
       rl.writeDefinition(out);
       return (true);
     }
   }
   return (false);
 }
Esempio n. 3
0
 protected void correctIndentation() {
   for (RtfBasicElement rtfElement : chunks) {
     if (rtfElement instanceof RtfList) {
       ((RtfList) rtfElement).correctIndentation();
     }
   }
 }
 /** Writes the definition part of this list level */
 public void writeDefinition(final OutputStream result) throws IOException {
   result.write(OPEN_GROUP);
   result.write(LIST_LEVEL);
   result.write(LIST_LEVEL_TYPE);
   switch (this.listType) {
     case LIST_TYPE_BULLET:
       result.write(intToByteArray(23));
       break;
     case LIST_TYPE_NUMBERED:
       result.write(intToByteArray(0));
       break;
     case LIST_TYPE_UPPER_LETTERS:
       result.write(intToByteArray(3));
       break;
     case LIST_TYPE_LOWER_LETTERS:
       result.write(intToByteArray(4));
       break;
     case LIST_TYPE_UPPER_ROMAN:
       result.write(intToByteArray(1));
       break;
     case LIST_TYPE_LOWER_ROMAN:
       result.write(intToByteArray(2));
       break;
   }
   result.write(LIST_LEVEL_TYPE_NEW);
   switch (this.listType) {
     case LIST_TYPE_BULLET:
       result.write(intToByteArray(23));
       break;
     case LIST_TYPE_NUMBERED:
       result.write(intToByteArray(0));
       break;
     case LIST_TYPE_UPPER_LETTERS:
       result.write(intToByteArray(3));
       break;
     case LIST_TYPE_LOWER_LETTERS:
       result.write(intToByteArray(4));
       break;
     case LIST_TYPE_UPPER_ROMAN:
       result.write(intToByteArray(1));
       break;
     case LIST_TYPE_LOWER_ROMAN:
       result.write(intToByteArray(2));
       break;
   }
   result.write(LIST_LEVEL_ALIGNMENT);
   result.write(intToByteArray(0));
   result.write(LIST_LEVEL_ALIGNMENT_NEW);
   result.write(intToByteArray(0));
   result.write(LIST_LEVEL_START_AT);
   result.write(intToByteArray(1));
   result.write(OPEN_GROUP);
   result.write(LIST_LEVEL_TEXT);
   if (this.listType != LIST_TYPE_BULLET) {
     result.write(LIST_LEVEL_STYLE_NUMBERED_BEGIN);
     if (listLevel < 10) {
       result.write(intToByteArray(0));
     }
     result.write(intToByteArray(listLevel));
     result.write(LIST_LEVEL_STYLE_NUMBERED_END);
   } else {
     result.write(LIST_LEVEL_STYLE_BULLETED_BEGIN);
     this.document.filterSpecialChar(result, this.bulletCharacter, false, false);
     result.write(LIST_LEVEL_STYLE_BULLETED_END);
   }
   result.write(CLOSE_GROUP);
   result.write(OPEN_GROUP);
   result.write(LIST_LEVEL_NUMBERS_BEGIN);
   if (this.listType != LIST_TYPE_BULLET) {
     result.write(LIST_LEVEL_NUMBERS_NUMBERED);
   }
   result.write(LIST_LEVEL_NUMBERS_END);
   result.write(CLOSE_GROUP);
   result.write(RtfFontList.FONT_NUMBER);
   if (this.listType != LIST_TYPE_BULLET) {
     result.write(intToByteArray(fontNumber.getFontNumber()));
   } else {
     result.write(intToByteArray(fontBullet.getFontNumber()));
   }
   // .result.write(writeIndentations());
   writeIndentations(result);
   result.write(LIST_LEVEL_SYMBOL_INDENT);
   result.write(intToByteArray(this.leftIndent));
   result.write(CLOSE_GROUP);
   result.write("\n".getBytes());
   for (int i = 0; i < items.size(); i++) {
     RtfElement rtfElement = (RtfElement) items.get(i);
     if (rtfElement instanceof RtfList) {
       RtfList rl = (RtfList) rtfElement;
       // .result.write(((RtfList) rtfElement).writeDefinition());
       rl.writeDefinition(result);
       break;
     } else if (rtfElement instanceof RtfListItem) {
       RtfListItem rli = (RtfListItem) rtfElement;
       // .byte[] data = rli.writeDefinition();
       // .if(data.length > 0) {
       // .    result.write(data);
       // .    break;
       // .}
       if (rli.writeDefinition(result)) break;
     }
   }
 }
  /**
   * Constructs a new RtfList for the specified List.
   *
   * @param doc The RtfDocument this RtfList belongs to
   * @param list The List this RtfList is based on
   */
  public RtfList(RtfDocument doc, List list) {
    super(doc);

    this.listNumber = document.getDocumentHeader().getListNumber(this);

    this.items = new ArrayList();
    if (list.getSymbolIndent() > 0 && list.getIndentationLeft() > 0) {
      this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1);
      this.leftIndent =
          (int) ((list.getIndentationLeft() + list.getSymbolIndent()) * RtfElement.TWIPS_FACTOR);
    } else if (list.getSymbolIndent() > 0) {
      this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1);
      this.leftIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR);
    } else if (list.getIndentationLeft() > 0) {
      this.firstIndent = 0;
      this.leftIndent = (int) (list.getIndentationLeft() * RtfElement.TWIPS_FACTOR);
    } else {
      this.firstIndent = 0;
      this.leftIndent = 0;
    }
    this.rightIndent = (int) (list.getIndentationRight() * RtfElement.TWIPS_FACTOR);
    this.symbolIndent =
        (int) ((list.getSymbolIndent() + list.getIndentationLeft()) * RtfElement.TWIPS_FACTOR);

    if (list instanceof RomanList) {
      if (list.isLowercase()) {
        this.listType = LIST_TYPE_LOWER_ROMAN;
      } else {
        this.listType = LIST_TYPE_UPPER_ROMAN;
      }
    } else if (list.isNumbered()) {
      this.listType = LIST_TYPE_NUMBERED;
    } else if (list.isLettered()) {
      if (list.isLowercase()) {
        this.listType = LIST_TYPE_LOWER_LETTERS;
      } else {
        this.listType = LIST_TYPE_UPPER_LETTERS;
      }
    }

    for (int i = 0; i < list.getItems().size(); i++) {
      try {
        Element element = (Element) list.getItems().get(i);
        if (element.type() == Element.CHUNK) {
          element = new ListItem((Chunk) element);
        }
        if (element instanceof ListItem) {
          this.alignment = ((ListItem) element).getAlignment();
        }
        RtfBasicElement rtfElement = doc.getMapper().mapElement(element);
        if (rtfElement instanceof RtfList) {
          ((RtfList) rtfElement).setListNumber(listNumber);
          ((RtfList) rtfElement).setListLevel(listLevel + 1);
          ((RtfList) rtfElement).setParent(this);
        } else if (rtfElement instanceof RtfListItem) {
          ((RtfListItem) rtfElement).setParent(this);
          ((RtfListItem) rtfElement).inheritListSettings(listNumber, listLevel + 1);
        }
        items.add(rtfElement);
      } catch (DocumentException de) {
        de.printStackTrace();
      }
    }

    if (this.listLevel == 0) {
      correctIndentation();
    }

    fontNumber =
        new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0)));
    if (list.getSymbol() != null
        && list.getSymbol().getFont() != null
        && !list.getSymbol().getContent().startsWith("-")
        && list.getSymbol().getContent().length() > 0) {
      // only set this to bullet symbol is not default
      this.fontBullet = new RtfFont(document, list.getSymbol().getFont());
      this.bulletCharacter = list.getSymbol().getContent().substring(0, 1);
    } else {
      this.fontBullet =
          new RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
    }
  }