mirror of https://github.com/apache/poi.git
add picture height / width to PicturesManager arguments
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1180740 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
822442a75b
commit
f92821eb1c
|
@ -49,6 +49,7 @@ import org.apache.poi.hwpf.usermodel.TableCell;
|
|||
import org.apache.poi.hwpf.usermodel.TableRow;
|
||||
import org.apache.poi.poifs.filesystem.Entry;
|
||||
import org.apache.poi.util.Beta;
|
||||
import org.apache.poi.util.Internal;
|
||||
import org.apache.poi.util.POILogFactory;
|
||||
import org.apache.poi.util.POILogger;
|
||||
import org.w3c.dom.Document;
|
||||
|
@ -672,9 +673,17 @@ public abstract class AbstractWordConverter
|
|||
// usual shape?
|
||||
return;
|
||||
|
||||
float width = officeDrawing.getRectangleRight()
|
||||
- officeDrawing.getRectangleLeft()
|
||||
/ AbstractWordUtils.TWIPS_PER_INCH;
|
||||
float height = ( officeDrawing.getRectangleBottom() - officeDrawing
|
||||
.getRectangleTop() ) / AbstractWordUtils.TWIPS_PER_INCH;
|
||||
|
||||
final PictureType type = PictureType.findMatchingType( pictureData );
|
||||
String path = getPicturesManager().savePicture( pictureData, type,
|
||||
"s" + characterRun.getStartOffset() + "." + type );
|
||||
String path = getPicturesManager()
|
||||
.savePicture( pictureData, type,
|
||||
"s" + characterRun.getStartOffset() + "." + type,
|
||||
width, height );
|
||||
|
||||
processDrawnObject( doc, characterRun, officeDrawing, path, block );
|
||||
}
|
||||
|
@ -778,8 +787,43 @@ public abstract class AbstractWordConverter
|
|||
Element currentBlock, Range textRange, int currentTableLevel,
|
||||
String hyperlink );
|
||||
|
||||
protected void processImage( Element currentBlock, boolean inlined,
|
||||
Picture picture )
|
||||
{
|
||||
PicturesManager fileManager = getPicturesManager();
|
||||
if ( fileManager != null )
|
||||
{
|
||||
final int aspectRatioX = picture.getHorizontalScalingFactor();
|
||||
final int aspectRatioY = picture.getVerticalScalingFactor();
|
||||
|
||||
final float imageWidth = aspectRatioX > 0 ? picture.getDxaGoal()
|
||||
* aspectRatioX / 1000 / AbstractWordUtils.TWIPS_PER_INCH
|
||||
: picture.getDxaGoal() / AbstractWordUtils.TWIPS_PER_INCH;
|
||||
final float imageHeight = aspectRatioY > 0 ? picture.getDyaGoal()
|
||||
* aspectRatioY / 1000 / AbstractWordUtils.TWIPS_PER_INCH
|
||||
: picture.getDyaGoal() / AbstractWordUtils.TWIPS_PER_INCH;
|
||||
|
||||
String url = fileManager.savePicture( picture.getContent(),
|
||||
picture.suggestPictureType(),
|
||||
picture.suggestFullFileName(), imageWidth, imageHeight );
|
||||
|
||||
if ( WordToFoUtils.isNotEmpty( url ) )
|
||||
{
|
||||
processImage( currentBlock, inlined, picture, url );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
processImageWithoutPicturesManager( currentBlock, inlined, picture );
|
||||
|
||||
}
|
||||
|
||||
@Internal
|
||||
protected abstract void processImageWithoutPicturesManager(
|
||||
Element currentBlock, boolean inlined, Picture picture );
|
||||
|
||||
protected abstract void processImage( Element currentBlock,
|
||||
boolean inlined, Picture picture );
|
||||
boolean inlined, Picture picture, String url );
|
||||
|
||||
protected abstract void processLineBreak( Element block,
|
||||
CharacterRun characterRun );
|
||||
|
|
|
@ -38,9 +38,21 @@ public interface PicturesManager
|
|||
*
|
||||
* @param content
|
||||
* picture content
|
||||
* @param pictureType
|
||||
* detected picture type (may be {@link PictureType#UNKNOWN}
|
||||
* @param suggestedName
|
||||
* suggested picture name (based on picture offset in file),
|
||||
* supposed to be unique
|
||||
* @param widthInches
|
||||
* display width in inches (scaled). May be useful for rendering
|
||||
* vector images (such as EMF or WMF)
|
||||
* @param heightInches
|
||||
* display height in inches (scaled). May be useful for rendering
|
||||
* vector images (such as EMF or WMF)
|
||||
* @return path to file that can be used as reference in HTML (img's src) of
|
||||
* XLS FO (fo:external-graphic's src) or <tt>null</tt> if image were
|
||||
* not saved and should not be referenced from result HTML / FO.
|
||||
*/
|
||||
String savePicture( byte[] content, PictureType pictureType, String suggestedName );
|
||||
String savePicture( byte[] content, PictureType pictureType,
|
||||
String suggestedName, float widthInches, float heightInches );
|
||||
}
|
||||
|
|
|
@ -366,49 +366,6 @@ public class WordToFoConverter extends AbstractWordConverter
|
|||
basicLink );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method shall store image bytes in external file and convert it if
|
||||
* necessary. Images shall be stored using PNG format (for bitmap) or SVG
|
||||
* (for vector). Other formats may be not supported by your XSL FO
|
||||
* processor.
|
||||
* <p>
|
||||
* Please note the
|
||||
* {@link WordToFoUtils#setPictureProperties(Picture, Element)} method.
|
||||
*
|
||||
* @param currentBlock
|
||||
* currently processed FO element, like <tt>fo:block</tt>. Shall
|
||||
* be used as parent of newly created
|
||||
* <tt>fo:external-graphic</tt> or
|
||||
* <tt>fo:instream-foreign-object</tt>
|
||||
* @param inlined
|
||||
* if image is inlined
|
||||
* @param picture
|
||||
* HWPF object, contained picture data and properties
|
||||
*/
|
||||
protected void processImage( Element currentBlock, boolean inlined,
|
||||
Picture picture )
|
||||
{
|
||||
PicturesManager fileManager = getPicturesManager();
|
||||
if ( fileManager != null )
|
||||
{
|
||||
String url = fileManager
|
||||
.savePicture( picture.getContent(),
|
||||
picture.suggestPictureType(),
|
||||
picture.suggestFullFileName() );
|
||||
|
||||
if ( WordToFoUtils.isNotEmpty( url ) )
|
||||
{
|
||||
processImage( currentBlock, inlined, picture, url );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// no default implementation -- skip
|
||||
currentBlock.appendChild( foDocumentFacade.document
|
||||
.createComment( "Image link to '"
|
||||
+ picture.suggestFullFileName() + "' can be here" ) );
|
||||
}
|
||||
|
||||
protected void processImage( Element currentBlock, boolean inlined,
|
||||
Picture picture, String url )
|
||||
{
|
||||
|
@ -418,6 +375,16 @@ public class WordToFoConverter extends AbstractWordConverter
|
|||
currentBlock.appendChild( externalGraphic );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processImageWithoutPicturesManager( Element currentBlock,
|
||||
boolean inlined, Picture picture )
|
||||
{
|
||||
// no default implementation -- skip
|
||||
currentBlock.appendChild( foDocumentFacade.document
|
||||
.createComment( "Image link to '"
|
||||
+ picture.suggestFullFileName() + "' can be here" ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processLineBreak( Element block, CharacterRun characterRun )
|
||||
{
|
||||
|
|
|
@ -313,39 +313,10 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
|||
basicLink );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method shall store image bytes in external file and convert it if
|
||||
* necessary. Images shall be stored using PNG format. Other formats may be
|
||||
* not supported by user browser.
|
||||
* <p>
|
||||
* Please note the {@link #processImage(Element, boolean, Picture, String)}.
|
||||
*
|
||||
* @param currentBlock
|
||||
* currently processed HTML element, like <tt>p</tt>. Shall be
|
||||
* used as parent of newly created <tt>img</tt>
|
||||
* @param inlined
|
||||
* if image is inlined
|
||||
* @param picture
|
||||
* HWPF object, contained picture data and properties
|
||||
*/
|
||||
protected void processImage( Element currentBlock, boolean inlined,
|
||||
Picture picture )
|
||||
@Override
|
||||
protected void processImageWithoutPicturesManager( Element currentBlock,
|
||||
boolean inlined, Picture picture )
|
||||
{
|
||||
PicturesManager fileManager = getPicturesManager();
|
||||
if ( fileManager != null )
|
||||
{
|
||||
String url = fileManager
|
||||
.savePicture( picture.getContent(),
|
||||
picture.suggestPictureType(),
|
||||
picture.suggestFullFileName() );
|
||||
|
||||
if ( WordToHtmlUtils.isNotEmpty( url ) )
|
||||
{
|
||||
processImage( currentBlock, inlined, picture, url );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// no default implementation -- skip
|
||||
currentBlock.appendChild( htmlDocumentFacade.document
|
||||
.createComment( "Image link to '"
|
||||
|
|
|
@ -244,8 +244,7 @@ public class WordToTextConverter extends AbstractWordConverter
|
|||
}
|
||||
|
||||
@Override
|
||||
public void processDocumentPart( HWPFDocumentCore wordDocument,
|
||||
Range range )
|
||||
public void processDocumentPart( HWPFDocumentCore wordDocument, Range range )
|
||||
{
|
||||
super.processDocumentPart( wordDocument, range );
|
||||
afterProcess();
|
||||
|
@ -295,6 +294,20 @@ public class WordToTextConverter extends AbstractWordConverter
|
|||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processImage( Element currentBlock, boolean inlined,
|
||||
Picture picture, String url )
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processImageWithoutPicturesManager( Element currentBlock,
|
||||
boolean inlined, Picture picture )
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processLineBreak( Element block, CharacterRun characterRun )
|
||||
{
|
||||
|
|
|
@ -69,7 +69,8 @@ public class TestWordToHtmlConverter extends TestCase
|
|||
wordToHtmlConverter.setPicturesManager( new PicturesManager()
|
||||
{
|
||||
public String savePicture( byte[] content,
|
||||
PictureType pictureType, String suggestedName )
|
||||
PictureType pictureType, String suggestedName,
|
||||
float widthInches, float heightInches )
|
||||
{
|
||||
return suggestedName;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue