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
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
>
did you check this problem?
Greetings,
Jacek
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
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
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
>
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" <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
>
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" <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
> > For more options, visit this group athttp://groups.google.com/group/swt-paperclips?hl=en.- Hide quoted text -
>
> - Show quoted text -
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 -