J'ai un chaîne de caratère que je désinne à l'écran dont, pour certains, j'aimerais faire un traitement particulier (dessin d'un bord plus large).
Donc j'aimerais récupérer la forme de cette sous-chaîne de caratère mais je galère.
Après avoir essayer diverses façon je vous donne celle-ci à titre d'exemple :
Qui a pour outpu :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 for (int t = firstEndpoint; t < secondEndpoint; t++) { TextHitInfo t1 = TextHitInfo.afterOffset(t); System.out.println(tmpLayout); Shape tmpShape = tmpLayout.getCaretShape(t1); System.out.println("Shape ( " + t + ") x : " + tmpShape.getBounds().x); System.out.println("Shape ( " + t + ") size : " + tmpShape.getBounds().getWidth()); tmpShape = tmpAFT.createTransformedShape(tmpShape); resultShape.add(new Area(tmpShape)); }
donc, les Caret que j'obtiens son simplement des formes vide (donc sans épaisseur) avec une position définie.[...]
sun.font.StandardTextSource@bf32c[start:0, len:46, cstart:0, clen:46, chars:"4e 61 72 65 6e 61 69 20 6b 75 74 73 75 20 77 6f 20 68 61 69 74 61 20 69 70 70 6f 20 64 7a 75 64 7a 75 20 6b 61 65 72 75 20 69 74 61 6d 69", level:0, flags:0, font:java.awt.Font[family=Arial,name=Arial,style=bold,size=30], frc:java.awt.font.FontRenderContext@1, cm:sun.font.CoreMetrics@41dd3100]
Shape ( 0) x : 0
Shape ( 0) size : 0.0
sun.font.StandardTextSource@bf32c[start:0, len:46, cstart:0, clen:46, chars:"4e 61 72 65 6e 61 69 20 6b 75 74 73 75 20 77 6f 20 68 61 69 74 61 20 69 70 70 6f 20 64 7a 75 64 7a 75 20 6b 61 65 72 75 20 69 74 61 6d 69", level:0, flags:0, font:java.awt.Font[family=Arial,name=Arial,style=bold,size=30], frc:java.awt.font.FontRenderContext@1, cm:sun.font.CoreMetrics@41dd3100]
Shape ( 1) x : 22
Shape ( 1) size : 0.0
[...]
Help.
Partager