protected void drawText(final RenderableText renderableText, final long contentX2) {
    try {

      if (renderableText.getLength() == 0) {
        // This text is empty.
        return;
      }
      if (renderableText.isNodeVisible(getParagraphBounds(), isOverflowX(), isOverflowY())
          == false) {
        return;
      }

      final String text;
      final GlyphList gs = renderableText.getGlyphs();
      final int maxLength = renderableText.computeMaximumTextSize(contentX2);
      text = gs.getText(renderableText.getOffset(), maxLength, getCodePointBuffer());

      if (text.length() > 0) {
        xmlWriter.writeText(characterEntityParser.encodeEntities(text));
        if (text.trim().length() > 0) {
          result = true;
        }
        clearText();
      }
    } catch (final IOException ioe) {
      throw new InvalidReportStateException("Failed to write text", ioe);
    }
  }
  protected void drawComplexText(final RenderableComplexText renderableComplexText) {
    try {

      if (renderableComplexText.getRichText().isEmpty()) {
        // This text is empty.
        return;
      }
      if (renderableComplexText.isNodeVisible(getParagraphBounds(), isOverflowX(), isOverflowY())
          == false) {
        return;
      }

      // iterate through all inline elements
      for (final RichTextSpec.StyledChunk styledChunk :
          renderableComplexText.getRichText().getStyleChunks()) {
        RenderNode node = styledChunk.getOriginatingTextNode();
        InstanceID dummy = node.getInstanceId();
        textExtractorHelper.startInlineBox(
            dummy,
            styledChunk.getOriginalAttributes(),
            styledChunk.getStyleSheet(),
            BoxDefinition.EMPTY);
        if (node instanceof RenderableReplacedContentBox) {
          processRenderableContent((RenderableReplacedContentBox) node);
          result = true;
        } else {
          String text = styledChunk.getText();
          xmlWriter.writeText(characterEntityParser.encodeEntities(text));
          if (text.trim().length() > 0) {
            result = true;
          }
        }
        textExtractorHelper.finishBox(dummy, styledChunk.getOriginalAttributes());
        clearText();
      }
    } catch (final IOException ioe) {
      throw new InvalidReportStateException("Failed to write text", ioe);
    }
  }