@Test( expected = IllegalArgumentException.class ) public void splitBy_ThrowsException_WhenParameterIsNonPositive() throws Exception { RenderableText text = createText( "1" ); text.splitBy( 0 ); }
@Override public RenderableText[] splitBy( long widthOfFirst ) { if ( widthOfFirst <= 0 ) { throw new IllegalArgumentException( String.format( "Illegal width: %d. Only text nodes with non-zero width are not allowed!", widthOfFirst ) ); } if ( widthOfFirst >= getMinimumWidth() ) { throw new IllegalStateException( String.format( "Split width (%d) should be less than the component's minimum width (%d)!", widthOfFirst, getMinimumWidth() ) ); } if ( !getStyleSheet().getBooleanStyleProperty( TextStyleKeys.WORDBREAK ) ) { return null; } final int last = offset + length; final GlyphList glyphs = getGlyphs(); int index = offset; long currentWidth = 0; while ( index < last && currentWidth <= widthOfFirst ) { currentWidth += convert( glyphs.getGlyph( index ).getWidth() ); index++; } index--; if ( index == offset ) { return null; } RenderableText first = (RenderableText) derive( true ); int firstLength = index - offset; first.initialize( glyphs, offset, firstLength, baselineInfo, script, forceLinebreak ); RenderableText rest = (RenderableText) derive( true ); rest.initialize( glyphs, index, length - firstLength, baselineInfo, script, forceLinebreak ); RenderableText[] pair = { first, rest }; RenderBox parent = getParent(); if ( parent != null ) { parent.replaceChilds( this, pair ); } return pair; }
RenderableText extends RenderNode implements SplittableRenderNode { @Override public RenderableText[] splitBy( long widthOfFirst ) { if ( widthOfFirst <= 0 ) { throw new IllegalArgumentException( String.format( "Illegal width: %d. Only text nodes with non-zero width are not allowed!", widthOfFirst ) ); } if ( widthOfFirst >= getMinimumWidth() ) { throw new IllegalStateException( String.format( "Split width (%d) should be less than the component's minimum width (%d)!", widthOfFirst, getMinimumWidth() ) ); } if ( !getStyleSheet().getBooleanStyleProperty( TextStyleKeys.WORDBREAK ) ) { return null; } final int last = offset + length; final GlyphList glyphs = getGlyphs(); int index = offset; long currentWidth = 0; while ( index < last && currentWidth <= widthOfFirst ) { currentWidth += convert( glyphs.getGlyph( index ).getWidth() ); index++; } index--; if ( index == offset ) { return null; } RenderableText first = (RenderableText) derive( true ); int firstLength = index - offset; first.initialize( glyphs, offset, firstLength, baselineInfo, script, forceLinebreak ); RenderableText rest = (RenderableText) derive( true ); rest.initialize( glyphs, index, length - firstLength, baselineInfo, script, forceLinebreak ); RenderableText[] pair = { first, rest }; RenderBox parent = getParent(); if ( parent != null ) { parent.replaceChilds( this, pair ); } return pair; } }
RenderableText extends RenderNode implements SplittableRenderNode { @Override public RenderableText[] splitBy( long widthOfFirst ) { if ( widthOfFirst <= 0 ) { throw new IllegalArgumentException( String.format( "Illegal width: %d. Only text nodes with non-zero width are not allowed!", widthOfFirst ) ); } if ( widthOfFirst >= getMinimumWidth() ) { throw new IllegalStateException( String.format( "Split width (%d) should be less than the component's minimum width (%d)!", widthOfFirst, getMinimumWidth() ) ); } if ( !getStyleSheet().getBooleanStyleProperty( TextStyleKeys.WORDBREAK ) ) { return null; } final int last = offset + length; final GlyphList glyphs = getGlyphs(); int index = offset; long currentWidth = 0; while ( index < last && currentWidth <= widthOfFirst ) { currentWidth += convert( glyphs.getGlyph( index ).getWidth() ); index++; } index--; if ( index == offset ) { return null; } RenderableText first = (RenderableText) derive( true ); int firstLength = index - offset; first.initialize( glyphs, offset, firstLength, baselineInfo, script, forceLinebreak ); RenderableText rest = (RenderableText) derive( true ); rest.initialize( glyphs, index, length - firstLength, baselineInfo, script, forceLinebreak ); RenderableText[] pair = { first, rest }; RenderBox parent = getParent(); if ( parent != null ) { parent.replaceChilds( this, pair ); } return pair; } RenderableText( final StyleSheet layoutContext, final ElementType elementType, final InstanceID instanceID,
      final ReportAttributeMap<Object> attributes, final ExtendedBaselineInfo baselineInfo, final GlyphList glyphs,
      final int offset, final int length, final int script, final boolean forceLinebreak ); }
RenderableText extends RenderNode implements SplittableRenderNode { @Override public RenderableText[] splitBy( long widthOfFirst ) { if ( widthOfFirst <= 0 ) { throw new IllegalArgumentException( String.format( "Illegal width: %d. Only text nodes with non-zero width are not allowed!", widthOfFirst ) ); } if ( widthOfFirst >= getMinimumWidth() ) { throw new IllegalStateException( String.format( "Split width (%d) should be less than the component's minimum width (%d)!", widthOfFirst, getMinimumWidth() ) ); } if ( !getStyleSheet().getBooleanStyleProperty( TextStyleKeys.WORDBREAK ) ) { return null; } final int last = offset + length; final GlyphList glyphs = getGlyphs(); int index = offset; long currentWidth = 0; while ( index < last && currentWidth <= widthOfFirst ) { currentWidth += convert( glyphs.getGlyph( index ).getWidth() ); index++; } index--; if ( index == offset ) { return null; } RenderableText first = (RenderableText) derive( true ); int firstLength = index - offset; first.initialize( glyphs, offset, firstLength, baselineInfo, script, forceLinebreak ); RenderableText rest = (RenderableText) derive( true ); rest.initialize( glyphs, index, length - firstLength, baselineInfo, script, forceLinebreak ); RenderableText[] pair = { first, rest }; RenderBox parent = getParent(); if ( parent != null ) { parent.replaceChilds( this, pair ); } return pair; } RenderableText( final StyleSheet layoutContext, final ElementType elementType, final InstanceID instanceID,
      final ReportAttributeMap<Object> attributes, final ExtendedBaselineInfo baselineInfo, final GlyphList glyphs,
      final int offset, final int length, final int script, final boolean forceLinebreak ); int getNodeType(); boolean isNormalTextSpacing(); boolean isForceLinebreak(); GlyphList getGlyphs(); int getOffset(); int getLength(); String getRawText(); boolean isEmpty(); boolean isDiscardable(); ExtendedBaselineInfo getBaselineInfo(); int getScript(); @Override long getMinimumWidth(); long getPreferredWidth(); String toString(); static long convert( final long fontMetricsValue ); int computeMaximumTextSize( final long contentX2 ); @Override RenderableText[] splitBy( long widthOfFirst ); }
RenderableText extends RenderNode implements SplittableRenderNode { @Override public RenderableText[] splitBy( long widthOfFirst ) { if ( widthOfFirst <= 0 ) { throw new IllegalArgumentException( String.format( "Illegal width: %d. Only text nodes with non-zero width are not allowed!", widthOfFirst ) ); } if ( widthOfFirst >= getMinimumWidth() ) { throw new IllegalStateException( String.format( "Split width (%d) should be less than the component's minimum width (%d)!", widthOfFirst, getMinimumWidth() ) ); } if ( !getStyleSheet().getBooleanStyleProperty( TextStyleKeys.WORDBREAK ) ) { return null; } final int last = offset + length; final GlyphList glyphs = getGlyphs(); int index = offset; long currentWidth = 0; while ( index < last && currentWidth <= widthOfFirst ) { currentWidth += convert( glyphs.getGlyph( index ).getWidth() ); index++; } index--; if ( index == offset ) { return null; } RenderableText first = (RenderableText) derive( true ); int firstLength = index - offset; first.initialize( glyphs, offset, firstLength, baselineInfo, script, forceLinebreak ); RenderableText rest = (RenderableText) derive( true ); rest.initialize( glyphs, index, length - firstLength, baselineInfo, script, forceLinebreak ); RenderableText[] pair = { first, rest }; RenderBox parent = getParent(); if ( parent != null ) { parent.replaceChilds( this, pair ); } return pair; } RenderableText( final StyleSheet layoutContext, final ElementType elementType, final InstanceID instanceID,
      final ReportAttributeMap<Object> attributes, final ExtendedBaselineInfo baselineInfo, final GlyphList glyphs,
      final int offset, final int length, final int script, final boolean forceLinebreak ); int getNodeType(); boolean isNormalTextSpacing(); boolean isForceLinebreak(); GlyphList getGlyphs(); int getOffset(); int getLength(); String getRawText(); boolean isEmpty(); boolean isDiscardable(); ExtendedBaselineInfo getBaselineInfo(); int getScript(); @Override long getMinimumWidth(); long getPreferredWidth(); String toString(); static long convert( final long fontMetricsValue ); int computeMaximumTextSize( final long contentX2 ); @Override RenderableText[] splitBy( long widthOfFirst );  }