[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: How to set different fonts into the same StyledText widget?

Thank for the tip. But I think this could help in "Styles" only, meaning for
the text to be bold, normal and italics, but not the font and the size.

I spent time in studying this, may be I could share a little bit.

I am writing an registration application for my friend and I need to output
the data as a word document, which requires setting different fonts, sizes
and underline the text. I found out that the setFont() API in StyledText
will apply to the whole text, no matter what.

then I use GC class to solve this issue and this is API I use:

private void drawText(GC gc, String str, Font font, int start, int end) {

Font oldFont = gc.getFont();

if (oldFont != null)

oldFont.dispose();

gc.setFont(font);

gc.drawText(str, start, end);

}

I am successful in doing what I want, but when it comes to printing it, I
encounter different issues:

1. The DPI for screen and printer need to be scaled and only by converting
the GC into an image I could get the thing scaled =(.

2. The spacing between text is so hard to adjust in the GC pane (by
calculating Font height, width and string length.



reference: 1.
http://dev.eclipse.org/newslists/news.eclipse.tools/msg51811.html

                   2.  Image Analyzer program in SWT examples. (menuPrint()
API)

Johnny



"Paul T. Keyser" <rolarenfan@xxxxxxxxxxxxx> wrote in message
news:3F21BD2D.8FDE7DAE@xxxxxxxxxxxxxxxx
> You need to be using the "StyleRange" interface (rather complicated -- but
the
> javadoc will tell you most of what you need; just note that after you have
set
> a StyleRange of length N, the StyledText widget will behind the scenes
break it
> into N StyleRanges of length 1).
>
> HTH,
> Paul K
>
> Johnny Lo wrote:
>
> > Hi,
> >
> > I need to set differnt fonts and sizes for the text that is set in the
same
> > StyledText widget. But when I call setFont() method it will just apply
the
> > change to the whole text instead of part of the text. Is there any way I
> > could set different fonts and sizes to the text with StyledText widget?
Or
> > should I use TextViewer from JFace?
> >
> > Thanks for helping
> >
> > Johnny
>