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;
// 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 );
}
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 );
*
* @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 );
}
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 )
{
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 )
{
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 '"
}
@Override
- public void processDocumentPart( HWPFDocumentCore wordDocument,
- Range range )
+ public void processDocumentPart( HWPFDocumentCore wordDocument, Range range )
{
super.processDocumentPart( wordDocument, range );
afterProcess();
// 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 )
{
wordToHtmlConverter.setPicturesManager( new PicturesManager()
{
public String savePicture( byte[] content,
- PictureType pictureType, String suggestedName )
+ PictureType pictureType, String suggestedName,
+ float widthInches, float heightInches )
{
return suggestedName;
}