1
void multiLine (int x, int y, String label, Graphics2D g) {
AffineTransform fontAT = new AffineTransform();
Font theFont = g.getFont();
fontAT.rotate(-Math.PI/2);
Font theDerivedFont = theFont.deriveFont(fontAT);
g.setFont(theDerivedFont);
AttributedString attrStr = new AttributedString(label);
// Get iterator for string:
AttributedCharacterIterator characterIterator = attrStr.getIterator();
// Get font context from graphics:
FontRenderContext fontRenderContext = g.getFontRenderContext();
// Create measurer:
LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator,
fontRenderContext);
while (measurer.getPosition() < characterIterator.getEndIndex()) {
TextLayout textLayout = measurer.nextLayout(200);
y += textLayout.getAscent(); //Have tried changing y to x
textLayout.draw(g, x, y);
y += textLayout.getDescent() + textLayout.getLeading(); //Have tried changing y to x
}
g.setFont(theFont);
}
我期待這樣做可以垂直打印行,但它不會,關於如何解決此問題的任何想法。使用graphics2D包裝/旋轉圖像上的文本
這輸出文本水平包裝。
編輯:更改了問題,以正確反映我正在嘗試實現的目標
它現在做了什麼?看起來你正在畫水平線。 – Khalos 2010-11-04 07:32:59
是的,它繪製了水平線。 – kal 2010-11-04 07:33:59