1 | import java.awt.geom.*; |
2 | |
3 | static void drawTextAlongLine(Graphics2D g, S text, int x1, int y1, int x2, int y2, int shift) { |
4 | if (y2 == y1 && x2 == x1) ++x2; |
5 | |
6 | new AffineTransform tx; |
7 | double angle = Math.atan2(y2-y1, x2-x1); |
8 | bool flip = abs(angle) > pi()/2; |
9 | if (flip) angle -= pi(); |
10 | tx.translate((x1+x2)/2.0, (y1+y2)/2.0); |
11 | tx.rotate(angle); |
12 | |
13 | AffineTransform old = g.getTransform(); |
14 | g.setTransform(tx); |
15 | FontMetrics fm = g.getFontMetrics(); |
16 | // int y = shift+fm.getLeading()+fm.getMaxAscent(); // below |
17 | int y = -shift-fm.getMaxDescent(); // above |
18 | g.drawString(text, -fm.stringWidth(text)/2.0f, y); |
19 | g.setTransform(old); |
20 | } |
Began life as a copy of #1007301
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1007307 |
Snippet name: | drawTextAlongLine |
Eternal ID of this version: | #1007307/10 |
Text MD5: | ebf109615ea09580450d72456355fcb1 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-03-15 02:33:38 |
Source code size: | 661 bytes / 20 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 502 / 483 |
Version history: | 9 change(s) |
Referenced in: | [show references] |