Пример #1
0
  /**
   * Writes the content of this RtfChunk. First the font information is written, then the content,
   * and then more font information
   */
  public void writeContent(final OutputStream result) throws IOException {
    if (this.background != null) {
      result.write(OPEN_GROUP);
    }

    result.write(font.writeBegin());
    if (superSubScript < 0) {
      result.write(FONT_SUBSCRIPT);
    } else if (superSubScript > 0) {
      result.write(FONT_SUPERSCRIPT);
    }
    if (this.background != null) {
      result.write(HIGHLIGHT);
      result.write(intToByteArray(this.background.getColorNumber()));
    }
    result.write(DELIMITER);
    // .result.write(document.filterSpecialChar(content, false, softLineBreaks ||
    // this.document.getDocumentSettings().isAlwaysGenerateSoftLinebreaks()).getBytes());
    document.filterSpecialChar(
        result,
        content,
        false,
        softLineBreaks || this.document.getDocumentSettings().isAlwaysGenerateSoftLinebreaks());

    if (superSubScript != 0) {
      result.write(FONT_END_SUPER_SUBSCRIPT);
    }
    result.write(font.writeEnd());

    if (this.background != null) {
      result.write(CLOSE_GROUP);
    }
  }
Пример #2
0
 /**
  * Writes the initialisation part of the RtfList
  *
  * @return A byte array containing the initialisation part
  */
 protected byte[] writeListBeginning() {
   ByteArrayOutputStream result = new ByteArrayOutputStream();
   try {
     result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
     if (this.inTable) {
       result.write(RtfParagraph.IN_TABLE);
     }
     switch (this.alignment) {
       case Element.ALIGN_LEFT:
         result.write(RtfParagraphStyle.ALIGN_LEFT);
         break;
       case Element.ALIGN_RIGHT:
         result.write(RtfParagraphStyle.ALIGN_RIGHT);
         break;
       case Element.ALIGN_CENTER:
         result.write(RtfParagraphStyle.ALIGN_CENTER);
         break;
       case Element.ALIGN_JUSTIFIED:
       case Element.ALIGN_JUSTIFIED_ALL:
         result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
         break;
     }
     // .result.write(writeIndentations());
     writeIndentations(result);
     result.write(RtfFont.FONT_SIZE);
     result.write(intToByteArray(fontNumber.getFontSize() * 2));
     if (this.symbolIndent > 0) {
       result.write("\\tx".getBytes());
       result.write(intToByteArray(this.leftIndent));
     }
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
   return result.toByteArray();
 }
Пример #3
0
 /**
  * Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph.
  *
  * @param doc The RtfDocument this RtfParagraph belongs to
  * @param paragraph The Paragraph that this RtfParagraph is based on
  */
 public RtfParagraph(RtfDocument doc, Paragraph paragraph) {
   super(doc);
   RtfFont baseFont = null;
   if (paragraph.getFont() instanceof RtfParagraphStyle) {
     this.paragraphStyle =
         this.document
             .getDocumentHeader()
             .getRtfParagraphStyle(((RtfParagraphStyle) paragraph.getFont()).getStyleName());
     baseFont = this.paragraphStyle;
   } else {
     baseFont = new RtfFont(this.document, paragraph.getFont());
     this.paragraphStyle =
         new RtfParagraphStyle(
             this.document, this.document.getDocumentHeader().getRtfParagraphStyle("Normal"));
     this.paragraphStyle.setAlignment(paragraph.getAlignment());
     this.paragraphStyle.setFirstLineIndent(
         (int) (paragraph.getFirstLineIndent() * RtfElement.TWIPS_FACTOR));
     this.paragraphStyle.setIndentLeft(
         (int) (paragraph.getIndentationLeft() * RtfElement.TWIPS_FACTOR));
     this.paragraphStyle.setIndentRight(
         (int) (paragraph.getIndentationRight() * RtfElement.TWIPS_FACTOR));
     this.paragraphStyle.setSpacingBefore(
         (int) (paragraph.getSpacingBefore() * RtfElement.TWIPS_FACTOR));
     this.paragraphStyle.setSpacingAfter(
         (int) (paragraph.getSpacingAfter() * RtfElement.TWIPS_FACTOR));
     if (paragraph.hasLeading()) {
       this.paragraphStyle.setLineLeading(
           (int) (paragraph.getLeading() * RtfElement.TWIPS_FACTOR));
     }
     this.paragraphStyle.setKeepTogether(paragraph.getKeepTogether());
   }
   for (int i = 0; i < paragraph.size(); i++) {
     Element chunk = (Element) paragraph.get(i);
     if (chunk instanceof Chunk) {
       ((Chunk) chunk).setFont(baseFont.difference(((Chunk) chunk).getFont()));
     } else if (chunk instanceof RtfImage) {
       ((RtfImage) chunks.get(i)).setAlignment(this.paragraphStyle.getAlignment());
     }
     try {
       RtfBasicElement[] rtfElements = doc.getMapper().mapElement(chunk);
       for (int j = 0; j < rtfElements.length; j++) {
         chunks.add(rtfElements[j]);
       }
     } catch (DocumentException de) {
     }
   }
 }
Пример #4
0
  /** Writes the content of the RtfList */
  public void writeContent(final OutputStream result) throws IOException {
    result.write(OPEN_GROUP);
    int itemNr = 0;
    for (int i = 0; i < items.size(); i++) {
      RtfElement rtfElement = (RtfElement) items.get(i);
      if (rtfElement instanceof RtfListItem) {
        itemNr++;
        result.write(writeListBeginning());
        result.write(writeListNumbers());
        result.write(OPEN_GROUP);
        result.write(LIST_TEXT);
        result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
        if (this.inTable) {
          result.write(RtfParagraph.IN_TABLE);
        }
        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(DELIMITER);
        if (this.listType != LIST_TYPE_BULLET) {
          switch (this.listType) {
            case LIST_TYPE_NUMBERED:
              result.write(intToByteArray(itemNr));
              break;
            case LIST_TYPE_UPPER_LETTERS:
              result.write(RomanAlphabetFactory.getUpperCaseString(itemNr).getBytes());
              break;
            case LIST_TYPE_LOWER_LETTERS:
              result.write(RomanAlphabetFactory.getLowerCaseString(itemNr).getBytes());
              break;
            case LIST_TYPE_UPPER_ROMAN:
              result.write(RomanNumberFactory.getUpperCaseString(itemNr).getBytes());
              break;
            case LIST_TYPE_LOWER_ROMAN:
              result.write(RomanNumberFactory.getLowerCaseString(itemNr).getBytes());
              break;
          }
          result.write(LIST_NUMBER_END);
        } else {
          this.document.filterSpecialChar(result, this.bulletCharacter, true, false);
        }
        result.write(TAB);
        result.write(CLOSE_GROUP);
        // .result.write(rtfElement.write());
        rtfElement.writeContent(result);
        if (i < (items.size() - 1) || !this.inTable || this.listLevel > 0) {
          result.write(RtfParagraph.PARAGRAPH);
        }
        result.write("\n".getBytes());
      } else if (rtfElement instanceof RtfList) {
        // .result.write(rtfElement.write());
        rtfElement.writeContent(result);
        result.write("\n".getBytes());
      }
    }
    result.write(CLOSE_GROUP);

    if (!this.inTable) {
      result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
    }
  }
Пример #5
0
 /** 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;
     }
   }
 }