Bonjour,
J'ai suivi le tutoriel d'Oracle pour écrire des strings sur plusieurs lignes dans un Graphics2D (http://docs.oracle.com/javase/tutori...mulstring.html)
Ca fonctionne très bien. Par contre, j'aimerais faire une rotation de certains degrés de ces strings, et là ça ne fonctionne plus.
Voilà comment je m'y suis pris:
Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 Font fontInfos = new Font("SansSerif", Font.BOLD, (int)(9*_zoomEtat)); g2.setColor(Color.GRAY); for(Forme forme:_metier.getCoordonneesDessin()) { Point2D p = forme.getCoordInfo(); if(p!=null) { double x = p.getX(); double y = p.getY(); x = x-_mapGauche; y = y-_mapHaut; x = (x*_coefX); y = h - (y*_coefY); AffineTransform transform = new AffineTransform(); transform.rotate(Math.toRadians(30)); AttributedString nom = new AttributedString(forme.getNom()); nom.addAttribute(TextAttribute.FONT, fontInfos); nom.addAttribute(TextAttribute.TRANSFORM, new TransformAttribute(transform)); //cette ligne semble ne pas fonctionner AttributedCharacterIterator paragraph = nom.getIterator(); int paragraphStart = paragraph.getBeginIndex(); int paragraphEnd = paragraph.getEndIndex(); LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, g2.getFontRenderContext()); lineMeasurer.setPosition(paragraphStart); float drawPosY = 0; while (lineMeasurer.getPosition() < paragraphEnd) { TextLayout layout = lineMeasurer.nextLayout((float)(100*_zoomEtat)); drawPosY += layout.getAscent(); layout.draw(g2, (float)(x), (float)(y+drawPosY)); drawPosY += layout.getDescent() + layout.getLeading(); } } }
Partager