Skip to content

Commit

Permalink
Implemented no repeat background image
Browse files Browse the repository at this point in the history
  • Loading branch information
sguan-actuate committed Jul 9, 2014
1 parent c353d83 commit 6758698
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 17 deletions.
Expand Up @@ -477,16 +477,43 @@ private void fillRectangleWithImage( ImagePart imageInfo, int x, int y,

public void setBackgroundImg( String relationshipid, int offsetX, int offsetY )
{
setBackgroundImg( relationshipid, offsetX, offsetY, BackgroundImageInfo.REPEAT);
}

public void setBackgroundImg( String relationshipid, int offsetX, int offsetY, int repeatmode )
{
if ( repeatmode < BackgroundImageInfo.NO_REPEAT
|| repeatmode > BackgroundImageInfo.REPEAT
|| repeatmode == BackgroundImageInfo.REPEAT_X
|| repeatmode == BackgroundImageInfo.REPEAT_Y )
{//cases that are not supported: log on exception
return;
}
writer.openTag( "a:blipFill" );
writer.attribute( "dpi", "0" );
writer.attribute( "rotWithShape", "1" );
writer.openTag( "a:blip" );
writer.attribute( "r:embed", relationshipid );
writer.closeTag( "a:blip" );
writer.openTag( "a:tile" );
writer.attribute( "tx", offsetX );
writer.attribute( "ty", offsetY );
writer.closeTag( "a:tile" );

switch ( repeatmode )
{
case BackgroundImageInfo.REPEAT :
writer.openTag( "a:tile" );
writer.attribute( "tx", offsetX );
writer.attribute( "ty", offsetY );
writer.closeTag( "a:tile" );
break;

case BackgroundImageInfo.NO_REPEAT :
writer.openTag( "a:stretch" );
writer.openTag( "a:fillRect" );
writer.attribute( "b", offsetY );
writer.attribute( "r", offsetX );
writer.closeTag( "a:fillRect" );
writer.closeTag( "a:stretch" );
break;
}
writer.closeTag( "a:blipFill" );
}

Expand Down
Expand Up @@ -481,11 +481,30 @@ protected void drawCellBox( CellArea cell )
// String imageUrl = EmitterUtil.getBackgroundImageUrl(
// style,reportDesign );

if ( bgimginfo != null
&& bgimginfo.getRepeatedMode( ) == BackgroundImageInfo.REPEAT )
if ( bgimginfo != null )
{
float offsetY = 0;
float offsetX = 0;
int repeatmode = bgimginfo.getRepeatedMode( );

if ( repeatmode == BackgroundImageInfo.NO_REPEAT )
{
int imgheight = PPTXUtil.pixelToEmu( (int) bgimginfo
.getImageInstance( ).getHeight( ), bgimginfo
.getImageInstance( ).getDpiY( ) );
int imgwidth = PPTXUtil.pixelToEmu( (int) bgimginfo
.getImageInstance( ).getWidth( ), bgimginfo
.getImageInstance( ).getDpiX( ) );
int cellheight = PPTXUtil.convertToEnums( getScaledValue( cell
.getHeight( ) ) );
int cellwidth = PPTXUtil.convertToEnums( getScaledValue( cell
.getWidth( ) ) );
offsetY = PPTXUtil
.parsePercentageOffset( cellheight, imgheight );
offsetX = PPTXUtil.parsePercentageOffset( cellwidth, imgwidth );
}
canvas.setBackgroundImg( canvas.getImageRelationship( bgimginfo ),
0, 0 );
(int) offsetX, (int) offsetY, repeatmode );
}
else if ( backgroundcolor != null )
{
Expand Down Expand Up @@ -618,16 +637,6 @@ private int getX( IContainerArea area )
return getScaledValue( area.getX( ) );
}

private int getHeight( CellArea area )
{
return getScaledValue( area.getHeight( ) );
}

private int getWidth( CellArea area )
{
return getScaledValue( area.getWidth( ) );
}

protected int getScaledValue( int value )
{
return (int) ( value * scale );
Expand Down
Expand Up @@ -46,4 +46,21 @@ public static String parseStyle( int style )

return "solid";
}

public static int pixelToEmu( int pixels, int dpi )
{
if ( dpi == 0 )
return 0;

return pixels * (int) ( (float) 914400 / dpi );

}

public static float parsePercentageOffset( int contianermeasure,
int contianersubmeasure )
{
float diffpercentage = (float) ( contianermeasure - contianersubmeasure )
/ contianermeasure;
return diffpercentage * 100000;
}
}

0 comments on commit 6758698

Please sign in to comment.