Used by the Recorder for recording the text tool.
(String cmd, ImagePlus imp)
| 555 | |
| 556 | /** Used by the Recorder for recording the text tool. */ |
| 557 | public String getMacroCode(String cmd, ImagePlus imp) { |
| 558 | String code = ""; |
| 559 | boolean script = Recorder.scriptMode(); |
| 560 | boolean addSelection = cmd.startsWith("Add"); |
| 561 | if (script && !addSelection) |
| 562 | code += "ip = imp.getProcessor();\n"; |
| 563 | if (script) { |
| 564 | String str = "Font.PLAIN"; |
| 565 | if (style==Font.BOLD) |
| 566 | str = "Font.BOLD"; |
| 567 | else if (style==Font.ITALIC) |
| 568 | str = "Font.ITALIC"; |
| 569 | code += "font = new Font(\""+name+"\", "+str+", "+size+");\n"; |
| 570 | if (addSelection) |
| 571 | return getAddSelectionScript(code); |
| 572 | code += "ip.setFont(font);\n"; |
| 573 | } else { |
| 574 | String options = ""; |
| 575 | if (style==Font.BOLD) |
| 576 | options += "bold"; |
| 577 | if (style==Font.ITALIC) |
| 578 | options += " italic"; |
| 579 | if (antialiasedText) |
| 580 | options += " antialiased"; |
| 581 | if (options.equals("")) |
| 582 | options = "plain"; |
| 583 | code += "setFont(\""+name+"\", "+size+", \""+options+"\");\n"; |
| 584 | } |
| 585 | ImageProcessor ip = imp.getProcessor(); |
| 586 | ip.setFont(new Font(name, style, size)); |
| 587 | FontMetrics metrics = ip.getFontMetrics(); |
| 588 | int fontHeight = metrics.getHeight(); |
| 589 | if (script) |
| 590 | code += "ip.setColor(new Color("+getColorArgs(getStrokeColor())+"));\n"; |
| 591 | else |
| 592 | code += "setColor(\""+Colors.colorToString(getStrokeColor())+"\");\n"; |
| 593 | if (addSelection) { |
| 594 | code += "Overlay.drawString(\""+text()+"\", "+this.x+", "+(this.y+fontHeight)+", "+getAngle()+");\n"; |
| 595 | code += "Overlay.show();\n"; |
| 596 | } else { |
| 597 | code += (script?"ip.":"")+"drawString(\""+text()+"\", "+this.x+", "+(this.y+fontHeight)+");\n"; |
| 598 | if (script) |
| 599 | code += "imp.updateAndDraw();\n"; |
| 600 | else |
| 601 | code += "//makeText(\""+text()+"\", "+this.x+", "+(this.y+fontHeight)+");\n"; |
| 602 | } |
| 603 | return (code); |
| 604 | } |
| 605 | |
| 606 | private String text() { |
| 607 | String text = ""; |
nothing calls this directly
no test coverage detected