Overlay.drawString sometimes use wrong horizontal text justification

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Overlay.drawString sometimes use wrong horizontal text justification

Stein Rørvik
When combining setJustification("Right") and Overlay.drawString(...
sometimes the justification gets wrong, the text is still "Left" adjusted.
This happens with TIF and ZIP files, never with PNG, GIF or AVI.
It happens the same way both with images and stacks.
The images look right on screen, but are wrong when read from files on disk.

Also, it does not always happen. See the below macro.
It usually gets the labels in the TIF and ZIP correct the first time you run it,
but then get wrongly adjusted if you rerun the same macro.

Demo macro; you must run this twice to see the error.
--------

dir = getDirectory("Temp");
run("Close All");

function OpenAnnotateAndSave(format) {
                run("Blobs (25K)");
                setColor("Red");
                setFont("SanSerif", 12);
                setJustification("Right");
                xPos = getWidth - 10;
                yPos = getHeight - 10;
                x = getWidth;
                y = getHeight;
                z = 0;
                toScaled(x,y,z);
                Overlay.drawString("Test String", xPos, yPos);
                Overlay.show;
                if (format == "tif") saveAs("TIF", dir + "blobs-labeled.tif");
                if (format == "zip") saveAs("ZIP", dir + "blobs-labeled.zip");
                if (format == "png") saveAs("PNG", dir + "blobs-labeled.png");
                if (format == "gif") saveAs("GIF", dir + "blobs-labeled.gif");
                close();
}

OpenAnnotateAndSave("tif");
OpenAnnotateAndSave("zip");
OpenAnnotateAndSave("png");
OpenAnnotateAndSave("gif");

open(dir + "blobs-labeled.tif");  //label is left adjusted instead of right
open(dir + "blobs-labeled.zip"); //label is left adjusted instead of right
open(dir + "blobs-labeled.png");               //ok
open(dir + "blobs-labeled.gif"); //ok

run("Tile");

--------
You can also duplicate the above functions on first run to get two rights and two wrongs:

OpenAnnotateAndSave("tif");
OpenAnnotateAndSave("zip");
open(dir + "blobs-labeled.tif");  //ok
open(dir + "blobs-labeled.zip"); //ok

OpenAnnotateAndSave("tif");
OpenAnnotateAndSave("zip");
open(dir + "blobs-labeled.tif");  //label is left adjusted instead of right
open(dir + "blobs-labeled.zip"); //label is left adjusted instead of right

--------


I am using daily build ImageJ 1.52h with Java 1.6 on Windows 7/64-bit.


Stein


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html