Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

31
LINES

< > BotCompany Repo | #1007350 // drawOutlineTextAlongLine

JavaX fragment (include)

1  
import java.awt.geom.*;
2  
3  
static new ThreadLocal<Bool> drawOutlineTextAlongLine_flip;
4  
5  
static void drawOutlineTextAlongLine(Graphics2D g, S text, int x1, int y1, int x2, int y2, int shift, Color fillColor, Color outlineColor) {
6  
  drawOutlineTextAlongLine(g, text, x1, y1, x2, y2, shift, 0, fillColor, outlineColor);
7  
}
8  
9  
static void drawOutlineTextAlongLine(Graphics2D g, S text, int x1, int y1, int x2, int y2, int shift, float yshift, Color fillColor, Color outlineColor) {
10  
  Bool flip = optPar(drawOutlineTextAlongLine_flip);
11  
  if (y2 == y1 && x2 == x1) ++x2;
12  
  
13  
  new AffineTransform tx;
14  
  double angle = Math.atan2(y2-y1, x2-x1);
15  
  if (flip == null)
16  
    flip = abs(angle) > pi()/2;
17  
  if (flip) angle -= pi();
18  
  tx.translate((x1+x2)/2.0, (y1+y2)/2.0);
19  
  tx.rotate(angle);
20  
21  
  FontMetrics fm = g.getFontMetrics();
22  
  // int y = shift+fm.getLeading()+fm.getMaxAscent(); // below
23  
  int y = -shift-fm.getMaxDescent(); // above
24  
  //print("drawText y=" + y + ", shift=" + shift);
25  
  
26  
  AffineTransform old = g.getTransform();
27  
  g.transform(tx);
28  
29  
  drawTextWithOutline(g, text, -fm.stringWidth(text)/2.0f, y+yshift, fillColor, outlineColor);
30  
  g.setTransform(old);
31  
}

Author comment

Began life as a copy of #1007307

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: #1007350
Snippet name: drawOutlineTextAlongLine
Eternal ID of this version: #1007350/12
Text MD5: 4b060d2872e055edf5e7dc444fd8f095
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-11 01:49:37
Source code size: 1187 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 385 / 438
Version history: 11 change(s)
Referenced in: [show references]