Changeset 1632 for trunk/docx4j/src/main


Ignore:
Timestamp:
08/01/11 13:53:24 (10 months ago)
Author:
jharrop
Message:

Antoine's patch of 28 July: for a picture content control, if it has a size use that, but respect the aspect ratio of the image being injected.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/model/datastorage/BindingHandler.java

    r1449 r1632  
    1919import org.apache.commons.codec.binary.Base64; 
    2020import org.apache.log4j.Logger; 
     21import org.apache.xmlgraphics.image.loader.ImageSize; 
    2122import org.docx4j.XmlUtils; 
    2223import org.docx4j.dml.wordprocessingDrawing.Inline; 
     
    315316                        try { 
    316317                                cxl = Long.parseLong(cx); 
    317                                 cyl = Long.parseLong(cx); 
     318                                cyl = Long.parseLong(cy); 
    318319                        } catch (Exception e) {} 
    319                         if (cxl==0 || cxl==0) { 
     320                        if (cxl==0 || cyl==0) { 
    320321                                // Let BPAI work out size 
    321322                                log.debug("image size - from image"); 
     
    325326                                // Use existing size 
    326327                                log.debug("image size - from content control size"); 
     328                    // Respect aspect ratio of injected image 
     329                    ImageSize size = imagePart.getImageInfo().getSize(); 
     330                    double ratio = (double) size.getHeightPx() / (double) size.getWidthPx(); 
     331                    log.debug("fit ratio: " + ratio); 
     332                    if (ratio > 1) { 
     333                        cxl =  (long)((double) cyl / ratio); 
     334                    } else { 
     335                        cyl =  (long)((double) cxl * ratio); 
     336                    } 
    327337                                inline = imagePart.createImageInline( filenameHint, altText,  
    328338                                                id1, id2, cxl, cyl, false);                              
Note: See TracChangeset for help on using the changeset viewer.