You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2008/09/10 23:58:55 UTC

DO NOT REPLY [Bug 45776] New: [PATCH] Fix corrupt file problem using TextRun.setText

https://issues.apache.org/bugzilla/show_bug.cgi?id=45776

           Summary: [PATCH] Fix corrupt file problem using TextRun.setText
           Product: POI
           Version: unspecified
          Platform: PC
        OS/Version: Mac OS X 10.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSLF
        AssignedTo: dev@poi.apache.org
        ReportedBy: djboulia@gmail.com


Created an attachment (id=22552)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=22552)
input test case powerpoint file

See the attached file testcase1in.ppt as the input file to the following test
code which tries to substitute the string $$DATE$$ with the current date/time:

package pptMaker;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.model.*;

/**
 * Test file to take an input file, change its contents based on a predefined
template
 * string, and write the output
 */

public class ModifyDate {

        public static final String _inputPPTFile =
"/Users/djboulia/Downloads/testcase1in.ppt";
        public static final String _outputPPTFile =
"/Users/djboulia/Downloads/testcase1out.ppt";

        /**
         * @param args
         */
        public static void main(String[] args) throws IOException {
                 SlideShow ppt = new SlideShow(new
HSLFSlideShow(_inputPPTFile));

                 //get slides 
                  Slide[] slide = ppt.getSlides();
                  for (int i = 0; i < slide.length; i++){
                        System.out.println( "Slide " + i);

                    Shape[] sh = slide[i].getShapes();
                    for (int j = 0; j < sh.length; j++){
                      //name of the shape
                      String name = sh[j].getShapeName();

                      //shapes's anchor which defines the position of this
shape in the slide
                      java.awt.Rectangle anchor = sh[j].getAnchor();

                      if (sh[j] instanceof Line){
                        Line line = (Line)sh[j];
                        //work with Line
                        System.out.println( "Found a Line!");
                      } else if (sh[j] instanceof AutoShape){
                        AutoShape shape = (AutoShape)sh[j];
                        //work with AutoShape
                        System.out.println( "Found an AutoShape!");
                      } else if (sh[j] instanceof TextBox){
                        TextBox shape = (TextBox)sh[j];
                        //work with TextBox
                        String str = shape.getText();

                        System.out.println( "Found a TextBox!");
                        System.out.println( str );

                        if (str.indexOf("$$DATE$$") >=0 ) {
                            System.out.println( "Found $$DATE$$!!" );
                            java.util.Date now = new java.util.Date();
                            str = str.replaceAll("[$][$]DATE[$][$]",
now.toString());

                                        if (str.compareTo(shape.getText())!=0)
{
                                                shape.setText( str );
                                        }
                            System.out.println( "Replacement string is " + str
); 
                        }

                      } else if (sh[j] instanceof Picture){
                        Picture shape = (Picture)sh[j];
                        //work with Picture
                        System.out.println( "Found a Picture!");

                      } else {
                          System.out.println("Found unknown shape: "+name);
                      }
                    }
                  }

            //save changes in a new file
            FileOutputStream out = new FileOutputStream(_outputPPTFile);
            ppt.write(out);
            out.close();

        }

}

Running this on poi-3.1 results in a corrupt PowerPoint file.  (Loading it in
Office 2004 on the Mac results in a blank page.)

After some investigation, it appears that there are cases where
TextRun.changeRichTextRun incorrectly calculates the new length of the
paragraph properties when called via setRawText.

The proposed patch resets the size of the paragraph and character properties to
the correct length when setRawText is called which avoids the problem in
changeRichTextRun.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 45776] [PATCH] Fix corrupt file problem using TextRun.setText

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45776

Andreas Beeker <an...@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Andreas Beeker <an...@gmx.de> ---
Thank you for the patch.

Applied with SVN ver r1554077

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 45776] [PATCH] Fix corrupt file problem using TextRun.setText

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45776





--- Comment #1 from Don Boulia <dj...@gmail.com>  2008-09-10 14:59:50 PST ---
Created an attachment (id=22553)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=22553)
patch for TextRun.setRawText


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org