public void exportText(TableBuilder tableBuilder, JRPrintText text, JRExporterGridCell gridCell)
      throws IOException {
    tableBuilder.buildCellHeader(
        styleCache.getCellStyle(gridCell), gridCell.getColSpan(), gridCell.getRowSpan());

    JRStyledText styledText = getStyledText(text);

    int textLength = 0;

    if (styledText != null) {
      textLength = styledText.length();
    }

    tempBodyWriter.write("<text:p text:style-name=\"");
    tempBodyWriter.write(styleCache.getParagraphStyle(text));
    tempBodyWriter.write("\">");
    insertPageAnchor();
    if (text.getAnchorName() != null) {
      exportAnchor(JRStringUtil.xmlEncode(text.getAnchorName()));
    }

    boolean startedHyperlink = startHyperlink(text, true);

    if (textLength > 0) {
      exportStyledText(styledText, getTextLocale(text), startedHyperlink);
    }

    if (startedHyperlink) {
      endHyperlink(true);
    }

    tempBodyWriter.write("</text:p>\n");

    tableBuilder.buildCellFooter();
  }
  protected void exportFrame(
      TableBuilder tableBuilder, JRPrintFrame frame, JRExporterGridCell gridCell)
      throws IOException, JRException {
    tableBuilder.buildCellHeader(
        styleCache.getCellStyle(gridCell), gridCell.getColSpan(), gridCell.getRowSpan());

    boolean appendBackcolor =
        frame.getModeValue() == ModeEnum.OPAQUE
            && (backcolor == null || frame.getBackcolor().getRGB() != backcolor.getRGB());

    if (appendBackcolor) {
      setBackcolor(frame.getBackcolor());
    }

    try {
      JRGridLayout layout = gridCell.getLayout();
      JRPrintElementIndex frameIndex =
          new JRPrintElementIndex(reportIndex, pageIndex, gridCell.getWrapper().getAddress());
      exportGrid(layout, frameIndex);
    } finally {
      if (appendBackcolor) {
        restoreBackcolor();
      }
    }

    tableBuilder.buildCellFooter();
  }
  protected void exportStyledTextRun(
      Map<AttributedCharacterIterator.Attribute, Object> attributes,
      String text,
      Locale locale,
      boolean startedHyperlink)
      throws IOException {
    String textSpanStyleName = styleCache.getTextSpanStyle(attributes, text, locale);

    tempBodyWriter.write("<text:span");
    tempBodyWriter.write(" text:style-name=\"" + textSpanStyleName + "\"");
    tempBodyWriter.write(">");

    boolean localHyperlink = false;

    if (!startedHyperlink) {
      JRPrintHyperlink hyperlink = (JRPrintHyperlink) attributes.get(JRTextAttribute.HYPERLINK);
      if (hyperlink != null) {
        localHyperlink = startHyperlink(hyperlink, true);
      }
    }

    if (text != null) {
      tempBodyWriter.write(
          Utility.replaceNewLineWithLineBreak(
              JRStringUtil.xmlEncode(text))); // FIXMEODT try something nicer for replace
    }

    if (localHyperlink) {
      endHyperlink(true);
    }

    tempBodyWriter.write("</text:span>");
  }
Ejemplo n.º 4
0
 /**
  * Merge given style attributes with cached style.
  *
  * @param currentStyle Current (cached) style index, 0 if none.
  * @param numberingFormat Numbering format.
  * @param font Font attributes.
  * @param fill Fill attributes.
  * @param border Border attributes.
  * @param alignment Alignment attributes.
  * @return Cached style index.
  */
 int mergeAndCacheStyle(
     int currentStyle,
     String numberingFormat,
     Font font,
     Fill fill,
     Border border,
     Alignment alignment) {
   return styleCache.mergeAndCacheStyle(
       currentStyle, numberingFormat, font, fill, border, alignment);
 }
  protected void exportRectangle(
      TableBuilder tableBuilder, JRPrintRectangle rectangle, JRExporterGridCell gridCell)
      throws IOException {
    JRLineBox box = new JRBaseLineBox(null);
    JRPen pen = box.getPen();
    pen.setLineColor(rectangle.getLinePen().getLineColor());
    pen.setLineStyle(rectangle.getLinePen().getLineStyleValue());
    pen.setLineWidth(rectangle.getLinePen().getLineWidth());

    gridCell.setBox(box); // CAUTION: only some exporters set the cell box

    tableBuilder.buildCellHeader(
        styleCache.getCellStyle(gridCell), gridCell.getColSpan(), gridCell.getRowSpan());
    tableBuilder.buildCellFooter();
  }
  private void exportEmptyCell(JRExporterGridCell gridCell, int emptyCellColSpan)
      throws IOException {
    tempBodyWriter.write("<table:table-cell");
    // tempBodyWriter.write(" office:value-type=\"string\"");
    //		if (gridCell == null)
    //		{
    //			tempBodyWriter.write(" table:style-name=\"empty-cell\"");
    //		}
    //		else
    {
      tempBodyWriter.write(" table:style-name=\"" + styleCache.getCellStyle(gridCell) + "\"");
    }
    if (emptyCellColSpan > 1) {
      tempBodyWriter.write(" table:number-columns-spanned=\"" + emptyCellColSpan + "\"");
    }
    tempBodyWriter.write("/>\n");

    exportOccupiedCells(emptyCellColSpan - 1);
  }
  protected void exportReportToOasisZip(OutputStream os) throws JRException, IOException {
    OasisZip oasisZip =
        new FileBufferedOasisZip(((JROpenDocumentExporterNature) nature).getOpenDocumentNature());

    ExportZipEntry tempBodyEntry = new FileBufferedZipEntry(null);
    ExportZipEntry tempStyleEntry = new FileBufferedZipEntry(null);

    tempBodyWriter = tempBodyEntry.getWriter();
    tempStyleWriter = tempStyleEntry.getWriter();

    styleCache = new StyleCache(tempStyleWriter, fontMap, getExporterKey());

    Writer stylesWriter = oasisZip.getStylesEntry().getWriter();

    StyleBuilder styleBuilder = new StyleBuilder(jasperPrintList, stylesWriter);
    styleBuilder.build();

    stylesWriter.close();

    for (reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++) {
      setJasperPrint(jasperPrintList.get(reportIndex));

      List<JRPrintPage> pages = jasperPrint.getPages();
      if (pages != null && pages.size() > 0) {
        if (isModeBatch) {
          startPageIndex = 0;
          endPageIndex = pages.size() - 1;
        }

        JRPrintPage page = null;
        for (pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++) {
          if (Thread.interrupted()) {
            throw new JRException("Current thread interrupted.");
          }

          page = pages.get(pageIndex);

          exportPage(page);
        }
      }
    }

    tempBodyWriter.flush();
    tempStyleWriter.flush();

    tempBodyWriter.close();
    tempStyleWriter.close();

    /*   */
    ContentBuilder contentBuilder =
        new ContentBuilder(
            oasisZip.getContentEntry(),
            tempStyleEntry,
            tempBodyEntry,
            styleCache.getFontFaces(),
            ((JROpenDocumentExporterNature) nature).getOpenDocumentNature());
    contentBuilder.build();

    tempStyleEntry.dispose();
    tempBodyEntry.dispose();

    if ((imagesToProcess != null && imagesToProcess.size() > 0)) {
      for (Iterator<JRPrintElementIndex> it = imagesToProcess.iterator(); it.hasNext(); ) {
        JRPrintElementIndex imageIndex = it.next();

        JRPrintImage image = getImage(jasperPrintList, imageIndex);
        JRRenderable renderer = image.getRenderer();
        if (renderer.getType() == JRRenderable.TYPE_SVG) {
          renderer =
              new JRWrappingSvgRenderer(
                  renderer,
                  new Dimension(image.getWidth(), image.getHeight()),
                  ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null);
        }

        oasisZip.addEntry( // FIXMEODT optimize with a different implementation of entry
            new FileBufferedZipEntry(
                "Pictures/" + getImageName(imageIndex), renderer.getImageData()));
      }
    }

    oasisZip.zipEntries(os);

    oasisZip.dispose();
  }
Ejemplo n.º 8
0
 /**
  * Cache shading color for alternate rows.
  *
  * @param fill Fill pattern attributes.
  * @return Cached fill pattern index.
  */
 int cacheAlternateShadingFillColor(Fill fill) {
   return styleCache.cacheDxf(fill);
 }