Strange behavior

20 views
Skip to first unread message

edvjacek

unread,
Feb 2, 2010, 1:40:38 PM2/2/10
to SWT PaperClips
Hi,

I have to print together some documents. Each document has some
paragraphs. The paragraphs have various alignment and each paragraph
has various styles. I think my objects hierarchy should look as
follow:

seriesPrint - for set of documents (only one, returned to PrintJob
constructor);
---styledTextPrint - for a document (1 to n in seriesPrint);
------alignPrint - for a justified (LEFT, CENTER or RIGHT) paragraph
(1 to n in styledTextPrint);
---------styledTextPrint - for a paragraph (1 in alignPrint);
------------textPrint - for a text in paragraph (1 to n in
styledTextPrint).

Here is the sample function which returns seriesPrint. There is one
document in the set, the document has one paragraph, justified in
middle, the paragraph has line, the line has two words, the first is
NORMAL, the second is BOLD. Here is my code:

private static Print createPrint() {
SeriesPrint seriesPrint = new SeriesPrint();
StyledTextPrint docStyledTextPrint = new StyledTextPrint();
TextStyle textStyle = new TextStyle().font("Times New Roman", 10,
SWT.NORMAL);
TextStyle textStyleBold = new TextStyle().font("Times New Roman",
10, SWT.BOLD);
StyledTextPrint paragraphStyledTextPrint = new StyledTextPrint();
paragraphStyledTextPrint.append("Normal text", textStyle);
paragraphStyledTextPrint.append(" Bold text", textStyleBold);
AlignPrint alignPrint = new AlignPrint(paragraphStyledTextPrint,
SWT.CENTER, SWT.DEFAULT);
docStyledTextPrint.append(alignPrint);
seriesPrint.add(docStyledTextPrint);
return docStyledTextPrint;
}

Unfortunately I don't see anything in PrintPreview. If I change fonts
to Arial, it works! Strange...

What do I wrong? How should I design such structure? Is there other
way to set alignment in a paragraph?

Thanks,
Jacek

Matthew Hall

unread,
Feb 2, 2010, 3:39:03 PM2/2/10
to swt-pap...@googlegroups.com
Jacek,

I have a few questions to narrow the focus:
- What operating system are you running?
- what version of swt?
- is it only the print preview that comes up blank with times new roman font, or does it also come out blank on the printer?
- have you tried selecting a different printer on the print preview control?  (I.e. Is this a universal problem or only with one particular printer?)
- can you provide a standalone .java snippet that demonstrates the problem?

Matthew


-- Sent from my Palm Pre


--
You received this message because you are subscribed to the Google Groups "SWT PaperClips" group.
To post to this group, send email to swt-pap...@googlegroups.com.
To unsubscribe from this group, send email to swt-paperclip...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/swt-paperclips?hl=en.

edvjacek

unread,
Feb 3, 2010, 4:26:02 AM2/3/10
to SWT PaperClips
Hi Matthew,

my test environment:

- Windows XP Prof.,
- Eclipse for RCP/Plug-in Developers 3.5.1, paperClips 1.0.4
- I've got Snippet7 example from net.sf.paperclips.examples and I've
replaced with my function (I've send it in my last mail) createPrint
function from Snippet7 only,
- I start this test from Eclipse (Run As Java Application),
- on preview I get gray body of preview window,
- when I try to print (both "real" HP-Printer and PDFCreator) I get
the error: Exception in thread "main" org.eclipse.swt.SWTError:
Unspecified errorUnable to layout page 1
- everything works fine when both texts have the same style e.g.
NORMAL or BOLD and font is Times New Roman.
- everything works fine when font is Arial.

I hope this helps you.

Thanks,
Jacek

On 2 Lut, 21:39, "Matthew Hall" <matth...@woodcraftmill.com> wrote:
> Jacek,
>
> I have a few questions to narrow the focus:
> - What operating system are you running?
> - what version of swt?
> - is it only the print preview that comes up blank with times new roman font, or does it also come out blank on the printer?
> - have you tried selecting a different printer on the print preview control?  (I.e. Is this a universal problem or only with one particular printer?)
> - can you provide a standalone .java snippet that demonstrates the problem?
>
> Matthew
>
> -- Sent from my Palm Pre
>

edvjacek

unread,
Feb 22, 2010, 9:24:16 AM2/22/10
to SWT PaperClips
Hi Matthew,

did you check this problem?

Greetings,
Jacek

Matthew Hall

unread,
Feb 22, 2010, 10:54:46 AM2/22/10
to swt-pap...@googlegroups.com
I haven't yet, sorry.  I'll fire this up over lunch and take a look.


Matthew



-- Sent from my Palm Pre

> >                 seriesPrintadd(docStyledTextPrint);

Matthew Hall

unread,
Feb 22, 2010, 3:45:16 PM2/22/10
to SWT PaperClips
Here's what I've found:

StyledTextPrint is not taking font ascent into account when computing
minimum/preferred sizes. This normally isn't a problem, until you
embed a StyledTextPrint inside another print, which is in turn
embedded inside a StyledTextPrint. When the outer STP asks the
AlignPrint for a single chunk of content, it only gives it
alignPrint.minimumSize().y pixels tall. On my machine this is 94
pixels.

Both the TextPrints have 94px minimum height, however because "Normal
text" has a 70px ascent, and "Bold text" has a 71px ascent, the
alignment is off by one pixels and therefore the minimum line height
is actually 95px. This is the source of the mismatch.

One solution is to make StyledTextPrint to take the relative ascents
of its elements into account when calculating the minimum size.
Probably the most direct way to accomodate this is to add a
TextPrintIterator interface analogous to TextPrintPiece so that
iterators may query the ascent of their elements are be intelligent
about these calculations. I've filed Issue 23 for this [1].

Another thing I'm noting is that StyledTextPrint should support text
alignment out of the box, probably by using the TextStyle.align
property as of the beginning of each line as a hint. I've filed Issue
22 for this [2].

Matthew

[1] http://code.google.com/p/swt-paperclips/issues/detail?id=23
[2] http://code.google.com/p/swt-paperclips/issues/detail?id=22

edvjacek

unread,
Feb 23, 2010, 3:25:07 AM2/23/10
to SWT PaperClips
Hi Metthew,

thank you for your investigation. When do you plan release 1.0.5 and
1.1.0? The deadline of my project is end of June...

Greetings,
Jacek

Matthew Hall

unread,
Feb 24, 2010, 9:12:56 AM2/24/10
to swt-pap...@googlegroups.com
I'll look at the alignment part over lunch today.


Matthew



-- Sent from my Palm Pre

edvjacek

unread,
Feb 25, 2010, 7:50:52 AM2/25/10
to SWT PaperClips
Hi,

thank you for the update. I've played a little bit with new code. Your
test code doesn't work as you, and me, expect. After the lines:

styledText.setStyle(normal.align(SWT.CENTER));
styledText.append("Normal text", normal);
styledText.append(" Bold text", bold);

I've got the line justified to the left. I've "found" two workarounds:
1. In the line with "Normal text" I've deleted the style parameter,
now is better;
2. I've deleted the line with setStyle command and I've put as second
parameter in line with "Normal text" normal.align(SWT.CENTER), it's
better too.

The other problem with new code is the CENTER is not now in the middle
of the line but somewhere between CENTER and RIGHT.

I've tested on Windows XP and Eclipse 3.5.1.

Greetings,
Jacek


On 24 Lut, 15:12, "Matthew Hall" <matth...@woodcraftmill.com> wrote:
> I'll look at the alignment part over lunch today.
>
> Matthew
>
> -- Sent from my Palm Pre
>

> edvjacek wrote:
>
> Hi Metthew,
>
> thank you for your investigation. When do you plan release 1.0.5 and
>
> 1.1.0? The deadline of my project is end of June...
>
> Greetings,
>
> Jacek
>

Matthew Hall

unread,
Feb 25, 2010, 10:32:51 AM2/25/10
to swt-pap...@googlegroups.com
Are you using the latest paperclips code in mercurial?


Matthew



-- Sent from my Palm Pre

Matthew Hall

unread,
Feb 25, 2010, 10:41:45 AM2/25/10
to swt-pap...@googlegroups.com
If you pass a TextStyle to append method then the align from that style object is used.  Try:

styledText.append("Normal text", normalalign(SWT.LEFT)); 


Matthew


-- Sent from my Palm Pre

edvjacek

unread,
Feb 25, 2010, 11:40:37 AM2/25/10
to SWT PaperClips
Hi Matthew,

1. yes, I've used the code from mercurial. I use Mercurial plugin for
Eclipse IDE, HgEclipse ver. 1.5.0. You've changed only
StyledTextPrint.java class.
2. yes, this is my "workaround" 2.

Now the really problem is CENTER. Please check in your environment, at
me the text is between CENTER and RIGHT and does not look good.

Greetings,
Jacek

On 25 Lut, 16:41, "Matthew Hall" <matth...@woodcraftmill.com> wrote:
> If you pass a TextStyle to append method then the align from that style object is used.  Try:
>

> styledText.append("Normal text", normal.align(SWT.LEFT)); 


>
> Matthew
>
> -- Sent from my Palm Pre
>
> edvjacek wrote:
>
> Hi,
>
> thank you for the update. I've played a little bit with new code. Your
>
> test code doesn't work as you, and me, expect. After the lines:
>
> styledText.setStyle(normal.align(SWT.CENTER));
>
> styledText.append("Normal text", normal);
>
> styledText.append(" Bold text", bold);
>
> I've got the line justified to the left. I've "found" two workarounds:
>
> 1. In the line with "Normal text" I've deleted the style parameter,
>
> now is better;
>
> 2. I've  deleted the line with setStyle command and I've put as second
>
> parameter in line with "Normal text" normal.align(SWT.CENTER), it's
>
> better too.
>
> The other problem with new code is the CENTER is not now in the middle
>
> of the line but somewhere between CENTER and RIGHT.
>
> I've tested on Windows XP and Eclipse 3.5.1.
>
> Greetings,
>
> Jacek
>

> On 24 Lut, 15:12, "Matthew Hall" &lt;matth...@woodcraftmill.com> wrote:
>
> > I'll look at the alignment part over lunch today.
>
> > Matthew
>
> > -- Sent from my Palm Pre
>
> > edvjacek wrote:
>
> > Hi Metthew,
>
> > thank you for your investigation. When do you plan release 1.0.5 and
>
> > 1.1.0? The deadline of my project is end of June...
>
> > Greetings,
>
> > Jacek
>

Matthew Hall

unread,
Feb 25, 2010, 12:54:33 PM2/25/10
to swt-pap...@googlegroups.com
Please send your print code block and a pdf if possible




-- Sent from my Palm Pre

edvjacek

unread,
Feb 25, 2010, 1:09:06 PM2/25/10
to SWT PaperClips
Hi Matthew,

my createPrint is very easy:

public static Print createPrint() {


SeriesPrint seriesPrint = new SeriesPrint();

TextStyle normal = new TextStyle().font("Times New Roman", 10,
SWT.NORMAL);
TextStyle bold = normal.fontStyle(SWT.BOLD);
StyledTextPrint styledText = new StyledTextPrint();
styledText.append("Normal text", normal.align(SWT.CENTER));


styledText.append(" Bold text", bold);

seriesPrint.add(styledText);
return seriesPrint;
}

What I get in PdfCreator I send you now per email.

Greetings,
Jacek

On 25 Lut, 18:54, "Matthew Hall" <matth...@woodcraftmill.com> wrote:
> Please send your print code block and a pdf if possible
>
> -- Sent from my Palm Pre
>

> edvjacek wrote:
>
> Hi Matthew,
>
> 1. yes, I've used the code from mercurial. I use Mercurial plugin for
>
> Eclipse IDE, HgEclipse ver. 1.5.0. You've changed only
>
> StyledTextPrint.java class.
>
> 2. yes, this is my "workaround" 2.
>
> Now the really problem is CENTER. Please check in your environment, at
>
> me the text is between CENTER and RIGHT and does not look good.
>
> Greetings,
>
> Jacek
>

> On 25 Lut, 16:41, "Matthew Hall" &lt;matth...@woodcraftmill.com> wrote:
>
>
>
> > If you pass a TextStyle to append method then the align from that style object is used.  Try:
>
> > styledText.append("Normal text", normal.align(SWT.LEFT)); 
>
> > Matthew
>
> > -- Sent from my Palm Pre
>
> > edvjacek wrote:
>
> > Hi,
>
> > thank you for the update. I've played a little bit with new code. Your
>
> > test code doesn't work as you, and me, expect. After the lines:
>
> > styledText.setStyle(normal.align(SWT.CENTER));
>
> > styledText.append("Normal text", normal);
>
> > styledText.append(" Bold text", bold);
>
> > I've got the line justified to the left. I've "found" two workarounds:
>
> > 1. In the line with "Normal text" I've deleted the style parameter,
>
> > now is better;
>
> > 2. I've  deleted the line with setStyle command and I've put as second
>
> > parameter in line with "Normal text" normal.align(SWT.CENTER), it's
>
> > better too.
>
> > The other problem with new code is the CENTER is not now in the middle
>
> > of the line but somewhere between CENTER and RIGHT.
>
> > I've tested on Windows XP and Eclipse 3.5.1.
>
> > Greetings,
>
> > Jacek
>

> > On 24 Lut, 15:12, "Matthew Hall" &amp;lt;matth...@woodcraftmill.com> wrote:
>
> > > I'll look at the alignment part over lunch today.
>
> > > Matthew
>
> > > -- Sent from my Palm Pre
>
> > > edvjacek wrote:
>
> > > Hi Metthew,
>
> > > thank you for your investigation. When do you plan release 1.0.5 and
>
> > > 1.1.0? The deadline of my project is end of June...
>
> > > Greetings,
>
> > > Jacek
>

Matthew Hall

unread,
Feb 25, 2010, 3:09:53 PM2/25/10
to SWT PaperClips
Ok, try again now, changeset 59bc73fae994

Matthew

> > For more options, visit this group athttp://groups.google.com/group/swt-paperclips?hl=en.- Hide quoted text -
>
> - Show quoted text -

edvjacek

unread,
Feb 26, 2010, 10:23:26 AM2/26/10
to SWT PaperClips
Hi Matthew,

now looks good :). SWT.CENTER is in the middle of the line.

I've changed my structure: instead of old:

seriesPrint - for set of documents (only one, returned to PrintJob
constructor);
---styledTextPrint - for a document (1 to n in seriesPrint);
------alignPrint - for a justified (LEFT, CENTER or RIGHT) paragraph
(1 to n in styledTextPrint);
---------styledTextPrint - for a paragraph (1 in alignPrint);
------------textPrint - for a text in paragraph (1 to n in
styledTextPrint)

Now I'm using:

seriesPrint - for set of documents (only one, returned to PrintJob
constructor);
---styledTextPrint - for a document (1 to n in seriesPrint);

------textPrint - for a justified (LEFT, CENTER or RIGHT) paragraph (1
to n in styledTextPrint);

Thanks,
Jacek

> > > For more options, visit this group athttp://groups.google.com/group/swt-paperclips?hl=en.-Hide quoted text -

Reply all
Reply to author
Forward
0 new messages