protected void chopTextElement(int availableStretchHeight) {
    ensureTextMeasurer();

    JRStyledText tmpStyledText = getStyledText();

    if (tmpStyledText == null) {
      return;
    }

    if (getTextEnd() == tmpStyledText.getText().length()) {
      return;
    }

    /*   */
    JRMeasuredText measuredText =
        textMeasurer.measure(tmpStyledText, getTextEnd(), availableStretchHeight, canOverflow());

    isLeftToRight = measuredText.isLeftToRight();
    setTextHeight(measuredText.getTextHeight());
    if (getRotation() == ROTATION_NONE) {
      setStretchHeight(
          (int) getTextHeight()
              + getLineBox().getTopPadding().intValue()
              + getLineBox().getBottomPadding().intValue());
    } else {
      setStretchHeight(getHeight());
    }
    setTextStart(getTextEnd());
    setTextEnd(measuredText.getTextOffset());
    setLineBreakOffsets(measuredText.getLineBreakOffsets());
    setTextTruncateSuffix(measuredText.getTextSuffix());
    setLineSpacingFactor(measuredText.getLineSpacingFactor());
    setLeadingOffset(measuredText.getLeadingOffset());
  }
  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();
  }
  public String getText() {
    JRStyledText tmpStyledText = getStyledText();

    if (tmpStyledText == null) {
      return null;
    }

    return tmpStyledText.getText();
  }
  protected void exportStyledText(JRStyledText styledText, Locale locale, boolean startedHyperlink)
      throws IOException {
    String text = styledText.getText();

    int runLimit = 0;

    AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();

    while (runLimit < styledText.length()
        && (runLimit = iterator.getRunLimit()) <= styledText.length()) {
      exportStyledTextRun(
          iterator.getAttributes(),
          text.substring(iterator.getIndex(), runLimit),
          locale,
          startedHyperlink);

      iterator.setIndex(runLimit);
    }
  }
  protected void setPrintText(JRPrintText printText) {
    int startIndex = getTextStart();
    int endIndex = getTextEnd();
    JRStyledText fullStyledText = getStyledText();
    String fullText = fullStyledText.getText();

    boolean keepAllText =
        !canOverflow()
            && JRProperties.getBooleanProperty(
                this, JRTextElement.PROPERTY_PRINT_KEEP_FULL_TEXT, false);
    if (keepAllText) {
      // assert getTextStart() == 0
      if (startIndex != 0) {
        throw new JRRuntimeException("Text start index != 0 on keep all text.");
      }

      if (!JRCommonText.MARKUP_NONE.equals(getMarkup())) {
        // rewrite as styled text
        String styledText = filler.getStyledTextParser().write(fullStyledText);
        printText.setText(styledText);
      } else {
        printText.setText(fullText);
      }

      if (endIndex < fullText.length()) {
        printText.setTextTruncateIndex(new Integer(endIndex));
      }
    } else {
      String printedText;
      if (!JRCommonText.MARKUP_NONE.equals(getMarkup())) {
        printedText = filler.getStyledTextParser().write(fullStyledText, startIndex, endIndex);
      } else {
        printedText = fullText.substring(startIndex, endIndex);
      }
      printText.setText(printedText);
    }

    printText.setTextTruncateSuffix(getTextTruncateSuffix());
    printText.setLineBreakOffsets(getLineBreakOffsets());
  }
  protected void exportPage(JRPrintPage page) throws IOException {
    JRGridLayout layout =
        new JRGridLayout(
            nature,
            page.getElements(),
            jasperPrint.getPageWidth(),
            jasperPrint.getPageHeight(),
            globalOffsetX,
            globalOffsetY,
            null // address
            );

    JRExporterGridCell[][] grid = layout.getGrid();

    CutsInfo xCuts = layout.getXCuts();
    CutsInfo yCuts = layout.getYCuts();

    StringBuffer rowbuffer = null;

    JRPrintElement element = null;
    String text = null;
    boolean isFirstColumn = true;
    for (int y = 0; y < grid.length; y++) {
      rowbuffer = new StringBuffer();

      if (yCuts.isCutNotEmpty(y)) {
        isFirstColumn = true;
        for (int x = 0; x < grid[y].length; x++) {
          if (grid[y][x].getWrapper() != null) {
            element = grid[y][x].getWrapper().getElement();

            if (element instanceof JRPrintText) {
              JRStyledText styledText = getStyledText((JRPrintText) element);
              if (styledText == null) {
                text = "";
              } else {
                text = styledText.getText();
              }

              if (!isFirstColumn) {
                rowbuffer.append(delimiter);
              }
              rowbuffer.append(prepareText(text));
              isFirstColumn = false;
            }
          } else {
            if (xCuts.isCutNotEmpty(x)) {
              if (!isFirstColumn) {
                rowbuffer.append(delimiter);
              }
              isFirstColumn = false;
            }
          }
        }

        if (rowbuffer.length() > 0) {
          writer.write(rowbuffer.toString());
          writer.write(recordDelimiter);
        }
      }
    }

    if (progressMonitor != null) {
      progressMonitor.afterPageExport();
    }
  }