@Test public void testCreateCorrectBaselineInfoCorrect() throws Exception { PowerMockito.mockStatic( TextUtility.class ); when(TextUtility.createPaddedBaselineInfo( anyInt(), any(FontMetrics.class), any(BaselineInfo.class) )).thenCallRealMethod(); long maxHeight = (long) 15000; FontMetrics fontMetrics = mock( FontMetrics.class ); when( fontMetrics.getMaxHeight() ).thenReturn( maxHeight ); when( fontMetrics.getMaxAscent() ).thenReturn( (long) 7500 ); when( fontMetrics.getMaxDescent() ).thenReturn( (long) 7500 ); BaselineInfo baseLineInfo = new BaselineInfo(); baseLineInfo.setDominantBaseline(BaselineInfo.MIDDLE); when( fontMetrics.getBaselines( anyInt(), any(BaselineInfo.class))).thenReturn( baseLineInfo ); DefaultExtendedBaselineInfo baseLine = (DefaultExtendedBaselineInfo)TextUtility.createPaddedBaselineInfo( 'x', fontMetrics, null ); Assert.assertTrue( baseLine.getBaselines()[ExtendedBaselineInfo.AFTER_EDGE] >= RenderableText.convert(maxHeight) ); }
public static ExtendedBaselineInfo createPaddedBaselineInfo( final int codepoint, final FontMetrics fontMetrics, final BaselineInfo reusableBaselineInfo ) { if ( fontMetrics == null ) { throw new NullPointerException( "FontMetrics cannot be null" ); } final BaselineInfo baselineInfo = fontMetrics.getBaselines( codepoint, reusableBaselineInfo ); final int dominantBaseline = TextUtility.translateBaselines( baselineInfo.getDominantBaseline() ); final long underlinePosition = fontMetrics.getUnderlinePosition(); final long strikeThroughPosition = fontMetrics.getStrikeThroughPosition(); final long fontSize = fontMetrics.getMaxHeight(); final long threshold = (long) ( fontSize * 1.005 ); final long safeFontSize = (long) ( fontSize * 1.3 ); final long totalAscentAndDescent = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent(); if ( fontSize < totalAscentAndDescent && totalAscentAndDescent < threshold ) { return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, safeFontSize, safeFontSize, underlinePosition, strikeThroughPosition ); } return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, fontSize, fontSize, underlinePosition, strikeThroughPosition ); }
TextUtility { public static ExtendedBaselineInfo createPaddedBaselineInfo( final int codepoint, final FontMetrics fontMetrics, final BaselineInfo reusableBaselineInfo ) { if ( fontMetrics == null ) { throw new NullPointerException( "FontMetrics cannot be null" ); } final BaselineInfo baselineInfo = fontMetrics.getBaselines( codepoint, reusableBaselineInfo ); final int dominantBaseline = TextUtility.translateBaselines( baselineInfo.getDominantBaseline() ); final long underlinePosition = fontMetrics.getUnderlinePosition(); final long strikeThroughPosition = fontMetrics.getStrikeThroughPosition(); final long fontSize = fontMetrics.getMaxHeight(); final long threshold = (long) ( fontSize * 1.005 ); final long safeFontSize = (long) ( fontSize * 1.3 ); final long totalAscentAndDescent = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent(); if ( fontSize < totalAscentAndDescent && totalAscentAndDescent < threshold ) { return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, safeFontSize, safeFontSize, underlinePosition, strikeThroughPosition ); } return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, fontSize, fontSize, underlinePosition, strikeThroughPosition ); } }
TextUtility { public static ExtendedBaselineInfo createPaddedBaselineInfo( final int codepoint, final FontMetrics fontMetrics, final BaselineInfo reusableBaselineInfo ) { if ( fontMetrics == null ) { throw new NullPointerException( "FontMetrics cannot be null" ); } final BaselineInfo baselineInfo = fontMetrics.getBaselines( codepoint, reusableBaselineInfo ); final int dominantBaseline = TextUtility.translateBaselines( baselineInfo.getDominantBaseline() ); final long underlinePosition = fontMetrics.getUnderlinePosition(); final long strikeThroughPosition = fontMetrics.getStrikeThroughPosition(); final long fontSize = fontMetrics.getMaxHeight(); final long threshold = (long) ( fontSize * 1.005 ); final long safeFontSize = (long) ( fontSize * 1.3 ); final long totalAscentAndDescent = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent(); if ( fontSize < totalAscentAndDescent && totalAscentAndDescent < threshold ) { return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, safeFontSize, safeFontSize, underlinePosition, strikeThroughPosition ); } return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, fontSize, fontSize, underlinePosition, strikeThroughPosition ); } private  TextUtility(); }
TextUtility { public static ExtendedBaselineInfo createPaddedBaselineInfo( final int codepoint, final FontMetrics fontMetrics, final BaselineInfo reusableBaselineInfo ) { if ( fontMetrics == null ) { throw new NullPointerException( "FontMetrics cannot be null" ); } final BaselineInfo baselineInfo = fontMetrics.getBaselines( codepoint, reusableBaselineInfo ); final int dominantBaseline = TextUtility.translateBaselines( baselineInfo.getDominantBaseline() ); final long underlinePosition = fontMetrics.getUnderlinePosition(); final long strikeThroughPosition = fontMetrics.getStrikeThroughPosition(); final long fontSize = fontMetrics.getMaxHeight(); final long threshold = (long) ( fontSize * 1.005 ); final long safeFontSize = (long) ( fontSize * 1.3 ); final long totalAscentAndDescent = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent(); if ( fontSize < totalAscentAndDescent && totalAscentAndDescent < threshold ) { return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, safeFontSize, safeFontSize, underlinePosition, strikeThroughPosition ); } return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, fontSize, fontSize, underlinePosition, strikeThroughPosition ); } private  TextUtility(); static ExtendedBaselineInfo createBaselineInfo( final int codepoint, final FontMetrics fontMetrics,
      final BaselineInfo reusableBaselineInfo ); static ExtendedBaselineInfo createPaddedBaselineInfo( final int codepoint, final FontMetrics fontMetrics,
                                                         final BaselineInfo reusableBaselineInfo ); }
TextUtility { public static ExtendedBaselineInfo createPaddedBaselineInfo( final int codepoint, final FontMetrics fontMetrics, final BaselineInfo reusableBaselineInfo ) { if ( fontMetrics == null ) { throw new NullPointerException( "FontMetrics cannot be null" ); } final BaselineInfo baselineInfo = fontMetrics.getBaselines( codepoint, reusableBaselineInfo ); final int dominantBaseline = TextUtility.translateBaselines( baselineInfo.getDominantBaseline() ); final long underlinePosition = fontMetrics.getUnderlinePosition(); final long strikeThroughPosition = fontMetrics.getStrikeThroughPosition(); final long fontSize = fontMetrics.getMaxHeight(); final long threshold = (long) ( fontSize * 1.005 ); final long safeFontSize = (long) ( fontSize * 1.3 ); final long totalAscentAndDescent = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent(); if ( fontSize < totalAscentAndDescent && totalAscentAndDescent < threshold ) { return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, safeFontSize, safeFontSize, underlinePosition, strikeThroughPosition ); } return new DefaultExtendedBaselineInfo( dominantBaseline, baselineInfo, 0, 0, fontSize, fontSize, underlinePosition, strikeThroughPosition ); } private  TextUtility(); static ExtendedBaselineInfo createBaselineInfo( final int codepoint, final FontMetrics fontMetrics,
      final BaselineInfo reusableBaselineInfo ); static ExtendedBaselineInfo createPaddedBaselineInfo( final int codepoint, final FontMetrics fontMetrics,
                                                         final BaselineInfo reusableBaselineInfo );  }