Menu

SWTError on long strings in a GridPrint

2008-03-14
2013-04-10
  • Nobody/Anonymous

    Hi,

    Adding very long teksts without whitespaces to a GridPrint causes this error:

    org.eclipse.swt.SWTError: Unspecified errorIterator net.sf.paperclips.GridIterator@b28980 produced a 126770x3785 piece for a 4468x5801 area.

    The application is unable to recover from the error and terminates.

    Any ideas on how to work around this? If this is a known error, is there a patch available?

    I have tried all kinds of works arounds, such as different grid layouts (preferred, default, grow, etc) and wrapping the grid in BigPrint (which actually removes the SWTError, but causes the text to be printed over many pages, each page only containing about two lines worth of text, centered at the middle of the page.)

    Thanks in advance for any help on this issue.

     
    • Matthew Hall

      Matthew Hall - 2008-03-14

      The first thing I'd suggest is to check out the latest PaperClips sources into your workspace from SVN and see if that fixes the problem.  If so then I should build a new release.  If not, please send me a standalone snippet that demonstrates the problem so I can debug it and see what's going on

      This error is meant to catch custom print classes misbehaving, so imagine my surprise to find out that GridPrint is the culprit!

      Matthew

       
    • Nobody/Anonymous

      Easy enough to reproduce - just add a long text without whitespaces to a grid and BOOM.

       
      • Matthew Hall

        Matthew Hall - 2008-03-18

        Please make this easy on me and submit a standalone snippet that I can just drop in my workspace and run.  I'd like to help you and get this fixed, but I don't have hours to spare hunting this down.

         
    • Nobody/Anonymous

      Matthew,

      The following snippet makes Paperclips bork with the exception explained above. If you change the loop to  i < 10, then it works. Or you can add spaces in the string to make it work as well.

      Hope this helps diagnose the problem.

      ------------------------------SNIPPET--------------------------------

      import net.sf.paperclips.*;
      import net.sf.paperclips.ui.PrintPreview;
      import org.eclipse.swt.SWT;
      import org.eclipse.swt.graphics.Device;
      import org.eclipse.swt.graphics.GC;
      import org.eclipse.swt.widgets.Display;
      import org.eclipse.swt.widgets.Shell;

      public class PaperclipsTest
      {
          public static void main(String[] args)
          {
              DefaultGridLook look = new DefaultGridLook();
              look.setCellSpacing(7, 2);
              GridPrint testGrid = new GridPrint("l:p:n, d:g", look);

              StringBuffer str = new StringBuffer();
              for(int i=0; i < 100; i++)
                  str.append("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
              testGrid.add(new TextPrint(str.toString()));

              PagePrint page = new PagePrint(testGrid);
              PrintJob printJob = new PrintJob("Test", page).setMargins(38);

              Display display = new Display();
              Shell shell = new Shell(display);
              shell.setText("Test GUI");
              shell.setSize(500, 500);

              PrintPreview preview = new PrintPreview(shell, SWT.NULL);
              preview.setPrintJob(printJob);
              preview.setSize(500,500);

              shell.open();
              while (!shell.isDisposed())
              {
                if (!display.readAndDispatch())
                  display.sleep();
              }

              display.dispose();                     
          }
      }

      ------------------------------SNIPPET--------------------------------

       
    • Matthew Hall

      Matthew Hall - 2008-04-01

      Anonymous,

      I found the problem.  GridPrint was miscalculating column widths due to an integer overflow.  I've committed a fix to SVN that should fix the problem.  Please update your workspace with the latest sources and tell me if this fixes things on your side.

      Matthew

       
    • Nobody/Anonymous

      Thanks for fixing this so fast!

      Could you upload a new redistributable as well?

       
      • Matthew Hall

        Matthew Hall - 2008-04-02

        I'll see if I can get that done tonight

         

Log in to post a comment.

MongoDB Logo MongoDB