Text justification issue with Overlay.drawString

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

Text justification issue with Overlay.drawString

Stein Rørvik
Thanks, text justification in ROIs work correctly now!

Here is another related issue:
I am trying to right justify text drawn with Overlay.drawString, but am unable to do so.
I cannot find any other way to get the text right justified.

See this example macro:

run("Boats (356K)");
TextStr = "This the first line of the text\nThis is line two";
xPos = getWidth/2;
yPos = round(getHeight/7);

setFont("SansSerif", 28, "antialiased");
setColor("red");
setJustification("right");
Overlay.drawString(TextStr, xPos, yPos*1);
//problem: text is not right justified as expected
Overlay.show;

Stein

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


-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
Sent: 10. juli 2018 07:12
To: [hidden email]
Subject: Re: Wrong text justification in ROIs

> On Jul 9, 2018, at 8:45 AM, Stein Rørvik <[hidden email]> wrote:
>
> There is an issue with using Right justified text in ROIs.
> This only works if the fill color is set; it does not work with a transparent fill.
> This macro reproduces the issue; textStr3 is overlaid wrongly:

This bug is fixed in the 1.52e58 daily build.

-wayne


> textXpos = 300;
>
> textStr1 = "Text\nLeft justified";
> textYpos1 = 100;
>
> textStr2 = "Text\nLeft justified";
> textYpos2 = 200;
>
> textStr3 = "Text\nRight justified";
> textYpos3 = 300;
>
> textStr4 = "Text\nRight justified";
> textYpos4 = 400;
>
> run("Boats (356K)");
> setFont("Serif", 36, "antialiased");
>
> makeText(textStr1, textXpos, textYpos1); run("Properties... ",
> "name=test stroke=red justification=Left fill=none");
> Overlay.addSelection(); //correct position
>
> makeText(textStr2, textXpos, textYpos2); run("Properties... ",
> "name=test stroke=red justification=Left fill=blue");
> Overlay.addSelection(); //correct position
>
> makeText(textStr3, textXpos, textYpos3); run("Properties... ",
> "name=test stroke=yellow justification=Right fill=none");
> Overlay.addSelection(); //wrong position
>
> makeText(textStr4, textXpos, textYpos4); run("Properties... ",
> "name=test stroke=yellow justification=Right fill=blue");
> Overlay.addSelection(); //correct position
>
> run("Select None");
> Overlay.show;
> updateDisplay;
>
> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>
> Stein

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Text justification issue with Overlay.drawString

Wayne Rasband-2
> On Jul 12, 2018, at 10:24 AM, Stein Rørvik <[hidden email]> wrote:
>
> Thanks, text justification in ROIs work correctly now!
>
> Here is another related issue:
> I am trying to right justify text drawn with Overlay.drawString, but am unable to do so.
> I cannot find any other way to get the text right justified.

This bug is fixed in the latest ImageJ daily build (1.52f7).

-wayne

> See this example macro:
>
> run("Boats (356K)");
> TextStr = "This the first line of the text\nThis is line two";
> xPos = getWidth/2;
> yPos = round(getHeight/7);
>
> setFont("SansSerif", 28, "antialiased");
> setColor("red");
> setJustification("right");
> Overlay.drawString(TextStr, xPos, yPos*1);
> //problem: text is not right justified as expected
> Overlay.show;
>
> Stein
>
> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>
>
> -----Original Message-----
> From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
> Sent: 10. juli 2018 07:12
> To: [hidden email]
> Subject: Re: Wrong text justification in ROIs
>
>> On Jul 9, 2018, at 8:45 AM, Stein Rørvik <[hidden email]> wrote:
>>
>> There is an issue with using Right justified text in ROIs.
>> This only works if the fill color is set; it does not work with a transparent fill.
>> This macro reproduces the issue; textStr3 is overlaid wrongly:
>
> This bug is fixed in the 1.52e58 daily build.
>
> -wayne
>
>
>> textXpos = 300;
>>
>> textStr1 = "Text\nLeft justified";
>> textYpos1 = 100;
>>
>> textStr2 = "Text\nLeft justified";
>> textYpos2 = 200;
>>
>> textStr3 = "Text\nRight justified";
>> textYpos3 = 300;
>>
>> textStr4 = "Text\nRight justified";
>> textYpos4 = 400;
>>
>> run("Boats (356K)");
>> setFont("Serif", 36, "antialiased");
>>
>> makeText(textStr1, textXpos, textYpos1); run("Properties... ",
>> "name=test stroke=red justification=Left fill=none");
>> Overlay.addSelection(); //correct position
>>
>> makeText(textStr2, textXpos, textYpos2); run("Properties... ",
>> "name=test stroke=red justification=Left fill=blue");
>> Overlay.addSelection(); //correct position
>>
>> makeText(textStr3, textXpos, textYpos3); run("Properties... ",
>> "name=test stroke=yellow justification=Right fill=none");
>> Overlay.addSelection(); //wrong position
>>
>> makeText(textStr4, textXpos, textYpos4); run("Properties... ",
>> "name=test stroke=yellow justification=Right fill=blue");
>> Overlay.addSelection(); //correct position
>>
>> run("Select None");
>> Overlay.show;
>> updateDisplay;
>>
>> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>>
>> Stein

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Text justification issue with Overlay.drawString

Bill Christens-Barry-2
In reply to this post by Stein Rørvik
Using ImageJ 1.52f8 on MacOS 10.12.6, I've added several lines to Stein's example code to show a different, perhaps related issue:

run("Boats (356K)");
TextStr = "This the first line of the text\nThis is line two";
xPos = getWidth/2;
yPos = round(getHeight/7);

setFont("SansSerif", 28, "antialiased");
setColor("red");
setJustification("right");
Overlay.drawString(TextStr, xPos, yPos*1);
//problem: text is not right justified as expected
Overlay.show;

//additional lines to illustrate a different issue
run("To ROI Manager");
run("Hide Overlay");
roiManager("Select", 0);
// problem: only first line of text is displayed in the image selection

Only the first line of the text that was drawn in the overlay appears in the selection now created in the image.

Bill Christens-Barry

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Text justification issue with Overlay.drawString

Stein Rørvik
In reply to this post by Wayne Rasband-2
Thanks,

The text is now right-aligned but the overall horizontal placement of the text is not correctly aligned.

It seems that the horizontal alignment is according to the start of the text at the first line, not the right edge of the text.

See this demo macro; textStr4 is not placed in the expected position.
One would expect right justified text to be aligned from the right edge of text bounding box.
textStr1 and textStr2 (using makeText instead of drawstring) is therefore correctly aligned.

close("boats*");
textXpos = 300;

textStr1 = "Text 1\nLeft justified";
textYpos1 = 100;

textStr2 = "Text 2\nRight justified";
textYpos2 = 200;

textStr3 = "Text 3\nLeft justified";
textYpos3 = 350;

textStr4 = "Text 4\nRight justified";
textYpos4 = 450;

run("Boats (356K)");
setFont("Serif", 36, "antialiased");

makeText(textStr1, textXpos, textYpos1);
run("Properties... ", "name=test stroke=red justification=Left fill=none");
Overlay.addSelection();
//correct ROI alignment, both text and ROI is left aligned

makeText(textStr2, textXpos, textYpos2);
run("Properties... ", "name=test stroke=red justification=Right fill=none");
Overlay.addSelection();
//correct ROI alignment, both text and ROI is right aligned

setColor("yellow");

setJustification("left");
Overlay.drawString(textStr3, textXpos, textYpos3);
//text is correctly aligned

setJustification("right");
Overlay.drawString(textStr4, textXpos, textYpos4);
//text is aligned according to start of first character instead of the edge of the text bounding box

Overlay.show;
//add helper line to show the expected X alignment position
makeLine(textXpos, 0, textXpos, getHeight);


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

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
Sent: 27. juli 2018 05:11
To: [hidden email]
Subject: Re: Text justification issue with Overlay.drawString

> On Jul 12, 2018, at 10:24 AM, Stein Rørvik <[hidden email]> wrote:
>
> Thanks, text justification in ROIs work correctly now!
>
> Here is another related issue:
> I am trying to right justify text drawn with Overlay.drawString, but am unable to do so.
> I cannot find any other way to get the text right justified.

This bug is fixed in the latest ImageJ daily build (1.52f7).

-wayne

> See this example macro:
>
> run("Boats (356K)");
> TextStr = "This the first line of the text\nThis is line two"; xPos =
> getWidth/2; yPos = round(getHeight/7);
>
> setFont("SansSerif", 28, "antialiased"); setColor("red");
> setJustification("right"); Overlay.drawString(TextStr, xPos, yPos*1);
> //problem: text is not right justified as expected Overlay.show;
>
> Stein
>
> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>
>
> -----Original Message-----
> From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne
> Rasband
> Sent: 10. juli 2018 07:12
> To: [hidden email]
> Subject: Re: Wrong text justification in ROIs
>
>> On Jul 9, 2018, at 8:45 AM, Stein Rørvik <[hidden email]> wrote:
>>
>> There is an issue with using Right justified text in ROIs.
>> This only works if the fill color is set; it does not work with a transparent fill.
>> This macro reproduces the issue; textStr3 is overlaid wrongly:
>
> This bug is fixed in the 1.52e58 daily build.
>
> -wayne
>
>
>> textXpos = 300;
>>
>> textStr1 = "Text\nLeft justified";
>> textYpos1 = 100;
>>
>> textStr2 = "Text\nLeft justified";
>> textYpos2 = 200;
>>
>> textStr3 = "Text\nRight justified";
>> textYpos3 = 300;
>>
>> textStr4 = "Text\nRight justified";
>> textYpos4 = 400;
>>
>> run("Boats (356K)");
>> setFont("Serif", 36, "antialiased");
>>
>> makeText(textStr1, textXpos, textYpos1); run("Properties... ",
>> "name=test stroke=red justification=Left fill=none");
>> Overlay.addSelection(); //correct position
>>
>> makeText(textStr2, textXpos, textYpos2); run("Properties... ",
>> "name=test stroke=red justification=Left fill=blue");
>> Overlay.addSelection(); //correct position
>>
>> makeText(textStr3, textXpos, textYpos3); run("Properties... ",
>> "name=test stroke=yellow justification=Right fill=none");
>> Overlay.addSelection(); //wrong position
>>
>> makeText(textStr4, textXpos, textYpos4); run("Properties... ",
>> "name=test stroke=yellow justification=Right fill=blue");
>> Overlay.addSelection(); //correct position
>>
>> run("Select None");
>> Overlay.show;
>> updateDisplay;
>>
>> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>>
>> Stein

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Text justification issue with Overlay.drawString

Stein Rørvik
In reply to this post by Bill Christens-Barry-2
I tested this on Windows and saw the same issue.
If you try to resize the ROI by expanding it downwards, the missing text appears.
So the problem is apparently that the ROI size does not take into account that the text is multi-line.

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Bill Christens-Barry
Sent: 28. juli 2018 14:40
To: [hidden email]
Subject: Re: Text justification issue with Overlay.drawString

Using ImageJ 1.52f8 on MacOS 10.12.6, I've added several lines to Stein's example code to show a different, perhaps related issue:

run("Boats (356K)");
TextStr = "This the first line of the text\nThis is line two"; xPos = getWidth/2; yPos = round(getHeight/7);

setFont("SansSerif", 28, "antialiased"); setColor("red"); setJustification("right"); Overlay.drawString(TextStr, xPos, yPos*1);
//problem: text is not right justified as expected Overlay.show;

//additional lines to illustrate a different issue run("To ROI Manager"); run("Hide Overlay"); roiManager("Select", 0); // problem: only first line of text is displayed in the image selection

Only the first line of the text that was drawn in the overlay appears in the selection now created in the image.

Bill Christens-Barry

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Text justification issue with Overlay.drawString

Wayne Rasband-2
In reply to this post by Stein Rørvik
> On Jul 12, 2018, at 10:24 AM, Stein Rørvik <[hidden email]> wrote:
>
> Thanks, text justification in ROIs work correctly now!
>
> Here is another related issue:
> I am trying to right justify text drawn with Overlay.drawString, but am unable to do so.
> I cannot find any other way to get the text right justified.

This bug is fixed in the latest ImageJ daily build (1.52f23).

-wayne

> See this example macro:
>
> run("Boats (356K)");
> TextStr = "This the first line of the text\nThis is line two";
> xPos = getWidth/2;
> yPos = round(getHeight/7);
>
> setFont("SansSerif", 28, "antialiased");
> setColor("red");
> setJustification("right");
> Overlay.drawString(TextStr, xPos, yPos*1);
> //problem: text is not right justified as expected
> Overlay.show;
>
> Stein
>
> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>
>
> -----Original Message-----
> From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
> Sent: 10. juli 2018 07:12
> To: [hidden email]
> Subject: Re: Wrong text justification in ROIs
>
>> On Jul 9, 2018, at 8:45 AM, Stein Rørvik <[hidden email]> wrote:
>>
>> There is an issue with using Right justified text in ROIs.
>> This only works if the fill color is set; it does not work with a transparent fill.
>> This macro reproduces the issue; textStr3 is overlaid wrongly:
>
> This bug is fixed in the 1.52e58 daily build.
>
> -wayne
>
>
>> textXpos = 300;
>>
>> textStr1 = "Text\nLeft justified";
>> textYpos1 = 100;
>>
>> textStr2 = "Text\nLeft justified";
>> textYpos2 = 200;
>>
>> textStr3 = "Text\nRight justified";
>> textYpos3 = 300;
>>
>> textStr4 = "Text\nRight justified";
>> textYpos4 = 400;
>>
>> run("Boats (356K)");
>> setFont("Serif", 36, "antialiased");
>>
>> makeText(textStr1, textXpos, textYpos1); run("Properties... ",
>> "name=test stroke=red justification=Left fill=none");
>> Overlay.addSelection(); //correct position
>>
>> makeText(textStr2, textXpos, textYpos2); run("Properties... ",
>> "name=test stroke=red justification=Left fill=blue");
>> Overlay.addSelection(); //correct position
>>
>> makeText(textStr3, textXpos, textYpos3); run("Properties... ",
>> "name=test stroke=yellow justification=Right fill=none");
>> Overlay.addSelection(); //wrong position
>>
>> makeText(textStr4, textXpos, textYpos4); run("Properties... ",
>> "name=test stroke=yellow justification=Right fill=blue");
>> Overlay.addSelection(); //correct position
>>
>> run("Select None");
>> Overlay.show;
>> updateDisplay;
>>
>> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>>
>> Stein

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Text justification issue with Overlay.drawString

Stein Rørvik
I have now tested daily build 1.52f25 and this and the other issues I posted recently (import failing silently, wrong 1-column result display) are now all resolved.

Thanks!

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
Sent: 19. august 2018 02:27
To: [hidden email]
Subject: Re: Text justification issue with Overlay.drawString

> On Jul 12, 2018, at 10:24 AM, Stein Rørvik <[hidden email]> wrote:
>
> Thanks, text justification in ROIs work correctly now!
>
> Here is another related issue:
> I am trying to right justify text drawn with Overlay.drawString, but am unable to do so.
> I cannot find any other way to get the text right justified.

This bug is fixed in the latest ImageJ daily build (1.52f23).

-wayne

> See this example macro:
>
> run("Boats (356K)");
> TextStr = "This the first line of the text\nThis is line two"; xPos =
> getWidth/2; yPos = round(getHeight/7);
>
> setFont("SansSerif", 28, "antialiased"); setColor("red");
> setJustification("right"); Overlay.drawString(TextStr, xPos, yPos*1);
> //problem: text is not right justified as expected Overlay.show;
>
> Stein
>
> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>
>
> -----Original Message-----
> From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne
> Rasband
> Sent: 10. juli 2018 07:12
> To: [hidden email]
> Subject: Re: Wrong text justification in ROIs
>
>> On Jul 9, 2018, at 8:45 AM, Stein Rørvik <[hidden email]> wrote:
>>
>> There is an issue with using Right justified text in ROIs.
>> This only works if the fill color is set; it does not work with a transparent fill.
>> This macro reproduces the issue; textStr3 is overlaid wrongly:
>
> This bug is fixed in the 1.52e58 daily build.
>
> -wayne
>
>
>> textXpos = 300;
>>
>> textStr1 = "Text\nLeft justified";
>> textYpos1 = 100;
>>
>> textStr2 = "Text\nLeft justified";
>> textYpos2 = 200;
>>
>> textStr3 = "Text\nRight justified";
>> textYpos3 = 300;
>>
>> textStr4 = "Text\nRight justified";
>> textYpos4 = 400;
>>
>> run("Boats (356K)");
>> setFont("Serif", 36, "antialiased");
>>
>> makeText(textStr1, textXpos, textYpos1); run("Properties... ",
>> "name=test stroke=red justification=Left fill=none");
>> Overlay.addSelection(); //correct position
>>
>> makeText(textStr2, textXpos, textYpos2); run("Properties... ",
>> "name=test stroke=red justification=Left fill=blue");
>> Overlay.addSelection(); //correct position
>>
>> makeText(textStr3, textXpos, textYpos3); run("Properties... ",
>> "name=test stroke=yellow justification=Right fill=none");
>> Overlay.addSelection(); //wrong position
>>
>> makeText(textStr4, textXpos, textYpos4); run("Properties... ",
>> "name=test stroke=yellow justification=Right fill=blue");
>> Overlay.addSelection(); //correct position
>>
>> run("Select None");
>> Overlay.show;
>> updateDisplay;
>>
>> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>>
>> Stein

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

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