Java Code Examples for java.awt.font.TextLayout#toString()

The following examples show how to use java.awt.font.TextLayout#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextLayoutUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static String toString(TextLayout textLayout) {
    return toStringShort(textLayout) + "; " + // NOI18N
            textLayout.toString();
}
 
Example 2
Source File: TextDocumentWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void drawComplexText( final RenderNode node ) {
  final RenderableComplexText renderableComplexText = (RenderableComplexText) node;

  // The text node that is printed will overlap with the ellipse we need to print.
  if ( renderableComplexText.isNodeVisible( drawArea ) == false ) {
    return;
  }
  if ( renderableComplexText.getRawText().length() == 0 ) {
    // This text is empty.
    return;
  }

  final String text;
  TextLayout textLayout = renderableComplexText.getTextLayout();
  String debugInfo = textLayout.toString();
  String startPos =
      debugInfo.substring( debugInfo.indexOf( "[start:" ), debugInfo.indexOf( ", len:" ) ).replace( "[start:", "" );
  int startPosIntValue = -1;

  try {
    startPosIntValue = Integer.parseInt( startPos );
  } catch ( NumberFormatException e ) {
    // do nothing
  }

  // workaround for line breaking (since the text cannot be extracted directly from textLayout as stream or String)
  // in order to avoid duplicates of same source raw text on multiple lines
  if ( ( renderableComplexText.getRawText().length() > textLayout.getCharacterCount() ) && startPosIntValue >= 0 ) {
    text =
        renderableComplexText.getRawText().substring( startPosIntValue,
            textLayout.getCharacterCount() + startPosIntValue );
  } else {
    text = renderableComplexText.getRawText();
  }

  final int x =
      PlainTextPage.correctedDivisionFloor( ( renderableComplexText.getX() - drawArea.getX() ),
          characterWidthInMicroPoint );
  final int y =
      PlainTextPage.correctedDivisionFloor( ( renderableComplexText.getY() - drawArea.getY() ),
          characterHeightInMicroPoint );
  int w = text.length();

  // filter out results that do not belong to the current physical page
  if ( x + w > plainTextPage.getWidth() ) {
    w = Math.max( 0, plainTextPage.getWidth() - x );
  }
  if ( w == 0 ) {
    return;
  }
  if ( y < 0 ) {
    return;
  }
  if ( y >= plainTextPage.getHeight() ) {
    return;
  }

  plainTextPage.addTextChunk( x, y, w, text, renderableComplexText.getStyleSheet() );
}