Question

I'm using SWT and want to use gc's drawstring function, but I can't set the word spacing of the font, is there any way to do so? Thanks

Update
I've tried TexetLayout with the code

TextLayout layout = new TextLayout(printer);
layout.setWidth(gc.stringExtent(text).x / 2);
layout.setText(text);
layout.draw(gc, x, y);

FYI, i"m trying to use the printer and gc is constructed with printer too, but I didn't get anything printed on the paper, am I wrong about the use of textlayout, or could you pls provide some code snippet for me to reference?

Was it helpful?

Solution 2

I've found a workaround that may not be perfect, I used Transform's scale to set the width to a certain value and in this way. the word spacing didn't change but the total width of a word is changed which can kind of satisfy me.

OTHER TIPS

GC drawString and drawText don't have any support for this.

You can use GC.textExtent to get the length of text which you could use lay out the text yourself.

The TextLayout class has some support for text justification.

Update: There are a number of examples of using TextLayout here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top