if (roi.subPixelResolution()) { Rectangle2D fb = roi.getFloatBounds(); roi2 = new TextRoi(fb.getX(), fb.getY(), fb.getWidth(), fb.getHeight(), new String(text), font); } else roi2 = new TextRoi(r.x, r.y, r.width, r.height, new String(text), font); roi2.setStrokeColor(roi.getStrokeColor()); roi2.setFillColor(roi.getFillColor()); roi2.setName(getRoiName()); roi2.setJustification(justification); roi2.setDrawStringMode(drawStringMode); roi2.setAngle(angle); return roi2;
void saveTextRoi(TextRoi roi) { Font font = roi.getCurrentFont(); String fontName = font.getName(); int size = font.getSize(); int drawStringMode = roi.getDrawStringMode()?1024:0; int style = font.getStyle() + roi.getJustification()*256+drawStringMode; String text = roi.getText(); float angle = (float)roi.getAngle(); int angleLength = 4; int fontNameLength = fontName.length(); int textLength = text.length(); int textRoiDataLength = 16+fontNameLength*2+textLength*2 + angleLength; byte[] data2 = new byte[HEADER_SIZE+HEADER2_SIZE+textRoiDataLength+roiNameSize+roiPropsSize]; System.arraycopy(data, 0, data2, 0, HEADER_SIZE); data = data2; putShort(RoiDecoder.SUBTYPE, RoiDecoder.TEXT); putInt(HEADER_SIZE, size); putInt(HEADER_SIZE+4, style); putInt(HEADER_SIZE+8, fontNameLength); putInt(HEADER_SIZE+12, textLength); for (int i=0; i<fontNameLength; i++) putShort(HEADER_SIZE+16+i*2, fontName.charAt(i)); for (int i=0; i<textLength; i++) putShort(HEADER_SIZE+16+fontNameLength*2+i*2, text.charAt(i)); int hdr2Offset = HEADER_SIZE+textRoiDataLength; //ij.IJ.log("saveTextRoi: "+HEADER_SIZE+" "+textRoiDataLength+" "+fontNameLength+" "+textLength); putFloat(hdr2Offset-angleLength, angle); putHeader2(roi, hdr2Offset); }
private String getAddSelectionScript(String code) { code += "roi = new TextRoi("+x+", "+y+", \""+text()+"\", font);\n"; code += "roi.setStrokeColor(new Color("+getColorArgs(getStrokeColor())+"));\n"; if (getFillColor()!=null) code += "roi.setFillColor(new Color("+getColorArgs(getFillColor())+"));\n"; if (getAngle()!=0.0) code += "roi.setAngle("+getAngle()+");\n"; code += "overlay.add(roi);\n"; return code; }
/** Draws the text on the screen, clipped to the ROI. */ public void draw(Graphics g) { if (IJ.debugMode) IJ.log("draw: "+theText[0]+" "+width+","+height); if (Interpreter.isBatchMode() && ic!=null && ic.getDisplayList()!=null) return; if (newFont || width==1) updateBounds(g); Color c = getStrokeColor(); setStrokeColor(getColor()); super.draw(g); // draw the rectangle setStrokeColor(c); double mag = getMagnification(); int sx = screenXD(getXBase()); int sy = screenYD(getYBase()); int swidth = (int)((bounds!=null?bounds.width:width)*mag); int sheight = (int)((bounds!=null?bounds.height:height)*mag); Rectangle r = null; if (angle!=0.0) drawText(g); else { r = g.getClipBounds(); g.setClip(sx, sy, swidth, sheight); drawText(g); if (r!=null) g.setClip(r.x, r.y, r.width, r.height); } }
TextRoi textRoi = roi!=null&&(roi instanceof TextRoi)?(TextRoi)roi:null; String fillc = "None"; TextRoi.setDefaultFillColor(null); TextRoi.setDefaultAngle(0.0); if (textRoi!=null) { Font font = textRoi.getCurrentFont(); fontSize = font.getSize(); angle = (int)textRoi.getAngle(); style = font.getStyle(); justification = textRoi.getJustification(); Color c = textRoi.getStrokeColor(); if (c!=null) color=c; fillc = Colors.colorToString2(textRoi.getFillColor()); antialiased = textRoi.getAntialiased();
int shape, int c, int z, int t) { store.setLabelX(roi.getPolygon().getBounds().getX(), roiNum, shape); store.setLabelY(roi.getPolygon().getBounds().getY(), roiNum, shape); store.setLabelText(roi.getText().trim(), roiNum, shape); store.setLabelFontSize(new Length(roi.getCurrentFont().getSize(), UNITS.PIXEL), roiNum, shape); if (c >= 0) { store.setLabelTheT(unwrap(t), roiNum, shape); if (roi.getStrokeWidth() > 0) { store.setLabelStrokeWidth(new Length((roi.getStrokeWidth()), UNITS.PIXEL), roiNum, shape); if (roi.getStrokeColor() != null) { store.setLabelStrokeColor(toOMExmlColor(roi.getStrokeColor()) , roiNum, shape); if (roi.getFillColor() != null) { store.setLabelFillColor(toOMExmlColor(roi.getFillColor()) , roiNum, shape);
if (isText) { TextRoi troi = (TextRoi)roi; Font font = troi.getCurrentFont(); strokeWidth = font.getSize(); angle = troi.getAngle(); justification = troi.getJustification(); antialias = troi.getAntialiased(); if (isText) { TextRoi troi = (TextRoi)roi; Font font = troi.getCurrentFont(); if ((int)strokeWidth!=font.getSize()) { font = new Font(font.getName(), font.getStyle(), (int)strokeWidth); troi.setCurrentFont(font); troi.setAngle(angle); if (justification!=troi.getJustification()) troi.setJustification(justification); troi.setAntialiased(antialias); } else roi.setStrokeWidth((float)strokeWidth);
colorName = colorName2; TextRoi.setFont(font, fontSize, style, antialiased); TextRoi.setGlobalJustification(justification); Color fillColor = Colors.decode(fillc, null); TextRoi.setDefaultFillColor(fillColor); TextRoi.setDefaultAngle(angle); if (textRoi!=null) { textRoi.setAngle(angle); textRoi.setJustification(justification); textRoi.setFillColor(fillColor); textRoi.setAntialiased(antialiased);
double overlayDrawString(ImagePlus imp) { addDrawingToOverlay(imp); String text = getFirstString(); int x = (int)getNextArg(); int y = (int)getNextArg(); double angle = 0.0; if (interp.nextToken()==',') angle = getLastArg(); else interp.getRightParen(); Font font = this.font; boolean nullFont = font==null; if (nullFont) font = imp.getProcessor().getFont(); TextRoi roi = new TextRoi(text, x, y, font); // use drawString() compatible constructor if (!nullFont && !antialiasedText) roi.setAntialiased(false); roi.setAngle(angle); roi.setJustification(justification); addRoi(imp, roi); return Double.NaN; }
roi = new TextRoi((int) xi, (int) yi, Integer.toString(label)); roi.setStrokeColor(Color.BLUE); overlay.add(roi);
TextRoi label = new TextRoi(todisplay, x + 5, yLabel + fontHeight/2, font); label.setStrokeColor(c); overlay.add(label, CALIBRATION_BAR);
protected void handleMouseUp(int screenX, int screenY) { super.handleMouseUp(screenX, screenY); if (width<5 && height<5 && imp!=null && previousRoi==null) { int ox = ic!=null?ic.offScreenX(screenX):screenX; int oy = ic!=null?ic.offScreenY(screenY):screenY; TextRoi roi = new TextRoi(ox, oy, line1a); roi.setStrokeColor(Toolbar.getForegroundColor()); roi.firstChar = true; imp.setRoi(roi); return; } else if (firstMouseUp) { updateBounds(null); updateText(); firstMouseUp = false; } if (width<5 || height<5) imp.deleteRoi(); }
defaultColor = color; if (rpRoi instanceof TextRoi) { font = ((TextRoi)rpRoi).getCurrentFont(); justification = ((TextRoi)rpRoi).getJustification(); roi.setImage(imp); if (font!=null) ((TextRoi)roi).setCurrentFont(font); ((TextRoi)roi).setJustification(justification); roi.setImage(null); if (fillColor!=null) roi.setFillColor(fillColor); if (roi!=null && (roi instanceof TextRoi)) { ((TextRoi)roi).setCurrentFont(font); ((TextRoi)roi).setJustification(justification);
code += "font = new Font(\""+name+"\", "+str+", "+size+");\n"; if (addSelection) return getAddSelectionScript(code); code += "ip.setFont(font);\n"; } else { int fontHeight = metrics.getHeight(); if (script) code += "ip.setColor(new Color("+getColorArgs(getStrokeColor())+"));\n"; else code += "setColor(\""+Colors.colorToString(getStrokeColor())+"\");\n"; if (addSelection) { code += "Overlay.drawString(\""+text()+"\", "+x+", "+(y+fontHeight)+", "+getAngle()+");\n"; code += "Overlay.show();\n"; } else { code += (script?"ip.":"")+"drawString(\""+text()+"\", "+x+", "+(y+fontHeight)+");\n"; if (script) code += "imp.updateAndDraw();\n"; else code += "//makeText(\""+text()+"\", "+x+", "+(y+fontHeight)+");\n";
if (!hyperstack) text = IJ.pad(i,4); TextRoi roi = new TextRoi(5, yloc-28, text, font); roi.setStrokeColor(Color.white); if (hyperstack || c>1) roi.setPosition(channel, slice, frame); else roi.setPosition(i); overlay.add(roi); ip.drawString(text, 5, yloc+27); "and to enable/disable channels.\n"; font = new Font("SansSerif", Font.PLAIN, imp.getWidth()>399?14:12); roi = new TextRoi(25, yloc, msg, font); roi.setStrokeColor(Color.white); roi.setPosition(0, 1, 1); overlay.add(roi);
private Roi createTextRoi(TextOverlay overlay) { RectangleRegionOfInterest region = overlay.getRegionOfInterest(); double x = region.getOrigin(0); double y = region.getOrigin(1); TextRoi roi = new TextRoi(x, y, overlay.getText()); switch (overlay.getJustification()) { case LEFT: roi.setJustification(TextRoi.LEFT); break; case CENTER: roi.setJustification(TextRoi.CENTER); break; case RIGHT: roi.setJustification(TextRoi.RIGHT); break; default: break; } assignPropertiesToRoi(roi, overlay); return roi; }
private Overlay createTextOverlay(final Roi roi) { assert roi instanceof TextRoi; final TextRoi tRoi = (TextRoi) roi; final Double bounds = tRoi.getFloatBounds(); final double x = bounds.x; final double y = bounds.y; final TextOverlay overlay = new TextOverlay(getContext(), x, y, tRoi.getText()); switch (tRoi.getJustification()) { case TextRoi.LEFT: overlay.setJustification(Justification.LEFT); break; case TextRoi.CENTER: overlay.setJustification(Justification.CENTER); break; case TextRoi.RIGHT: overlay.setJustification(Justification.RIGHT); break; default: break; } assignPropertiesToOverlay(overlay, roi); return overlay; }
void makeText() { String text = getFirstString(); int x = (int)getNextArg(); int y = (int)getLastArg(); ImagePlus imp = getImage(); Font font = this.font; boolean nullFont = font==null; if (nullFont) font = imp.getProcessor().getFont(); TextRoi roi = new TextRoi(x, y, text, font); if (!nullFont) roi.setAntialiased(antialiasedText); imp.setRoi(roi); }
break; case Toolbar.TEXT: roi = new TextRoi(sx, sy, this); ((TextRoi)roi).setPreviousRoi(previousRoi); break; case Toolbar.POINT: