문제

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?

도움이 되었습니까?

해결책 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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top