TCanvas::Print PNG outputs fraction of figure when canvas size is declared

Note that I am also talking about your small macro example. Like you, I also get non-truncated output, but I can clearly see that their sizes, reported by “identify”, are wrong.

Why are the figures so much taller than mine? Mine look rather square by eye. In addition, have you scaled the resolution down, if you are using a mac? I don’t see the issue at the nominal resolution.

No idea.

I am using an iMac 27 inches with the X11 backend. I did nothing special. Just ran the normal ROOT. I had the truncated output before I did the fix. Now with the fix it is fine,

So what do you suggest I tried on my Mac ?

I did another test … I swapped the lines which produce GIF and PNG and I got another numbers (note that this time, GIF and PNG sizes are equal in interactive mode, but PDF is still wrong and it’s “rotated”):

[...] $ root -l -q png_double_x_axis_title.cxx
(...)
[...] $ identify test1.gif
test1.gif GIF 998x961 998x961+0+0 8-bit PseudoClass 8c 6.67KB 0.000u 0:00.010
[...] $ identify test1.png
test1.png PNG 998x961 998x961+0+0 8-bit DirectClass 11KB 0.000u 0:00.000
[...] $ identify test1.pdf
test1.pdf PDF 842x595 842x595+0+0 16-bit Bilevel DirectClass 63.1KB 0.000u 0:00.000
[...] $ root -b -l -q png_double_x_axis_title.cxx
(...)
[...] $ identify test1.gif
test1.gif GIF 996x1972 996x1972+0+0 8-bit PseudoClass 8c 10.9KB 0.000u 0:00.000
[...] $ identify test1.png
test1.png PNG 996x1972 996x1972+0+0 8-bit DirectClass 16.8KB 0.000u 0:00.000
[...] $ identify test1.pdf
test1.pdf PDF 595x842 595x842+0+0 16-bit Bilevel DirectClass 63.2KB 0.000u 0:00.000

So I did yet another test … I made the PDF creation the first, then PNG, then GIF (note that PDF is not “rotated” in interactive mode any more):

[...] $ root -l -q png_double_x_axis_title.cxx
(...)
[...] $ identify test1.gif
test1.gif GIF 998x961 998x961+0+0 8-bit PseudoClass 8c 6.67KB 0.000u 0:00.010
[...] $ identify test1.png
test1.png PNG 998x961 998x961+0+0 8-bit DirectClass 11KB 0.000u 0:00.000
[...] $ identify test1.pdf
test1.pdf PDF 595x842 595x842+0+0 16-bit Bilevel DirectClass 63.2KB 0.000u 0:00.000
[...] $ root -b -l -q png_double_x_axis_title.cxx
(...)
[...] $ identify test1.gif
test1.gif GIF 996x1972 996x1972+0+0 8-bit PseudoClass 8c 10.9KB 0.000u 0:00.000
[...] $ identify test1.png
test1.png PNG 996x1972 996x1972+0+0 8-bit DirectClass 16.8KB 0.000u 0:00.000
[...] $ identify test1.pdf
test1.pdf PDF 595x842 595x842+0+0 16-bit Bilevel DirectClass 63.2KB 0.000u 0:00.000

And if, in interactive mode, I first try PDF then GIF and finally PNG, then I again get much “higher” GIF (998x1973) but PDF is not “rotated” (PNG remains as it was).

In all cases, pictures are not truncated.

@ksmith maybe you could do such tests, too (and report the outcome here).

Can you try and scale the resolution in Displays as I have done here:


I will do more tests with my Mac to see what the simplest arrangement of monitors is that reproduces the issue. It seems to vanish when I just use a single monitor.

I’ve modified the scripts a bit to make this easier:

void png_double_x_axis_title(std::vector<std::string> extensions={"gif","png","pdf"}){
   TCanvas *c1 = new TCanvas("c1","c1",1000,2000);
   c1->DrawFrame(0.,0.,10.,10.);
   for (auto ext : extensions) {
      c1->Print(("test1."+ext).c_str());
      gSystem->Exec(("identify test1."+ext).c_str());
   }
}

And a script to test all combinations:

{  
   gROOT->ProcessLine(".L png_double_x_axis_title.C");
   std::cout << "gif, png, pdf\n";
   png_double_x_axis_title({"gif", "png", "pdf"});
   std::cout << "gif, pdf, png\n";
   png_double_x_axis_title({"gif", "pdf", "png"});
   std::cout << "png, gif, pdf\n";
   png_double_x_axis_title({"png", "gif", "pdf"});
   std::cout << "png, pdf, gif\n";
   png_double_x_axis_title({"png", "pdf", "gif"});
   std::cout << "pdf, gif, png\n";
   png_double_x_axis_title({"pdf", "gif", "png"});
   std::cout << "pdf, png, gif\n";
   png_double_x_axis_title({"pdf", "png", "gif"});
}

The output:

$ root -q all_choices.C 

Processing all_choices.C...
gif, png, pdf
Info in <TCanvas::Print>: GIF file test1.gif has been created
test1.gif GIF 998x1820 998x1820+0+0 8-bit sRGB 256c 17259B 0.000u 0:00.019
Info in <TCanvas::Print>: file test1.png has been created
test1.png PNG 998x1820 998x1820+0+0 8-bit sRGB 28848B 0.000u 0:00.009
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 9287B 0.000u 0:00.000
gif, pdf, png
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: GIF file test1.gif has been created
test1.gif GIF 998x1820 998x1820+0+0 8-bit sRGB 256c 17259B 0.000u 0:00.019
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 9287B 0.000u 0:00.000
Info in <TCanvas::Print>: file test1.png has been created
test1.png PNG 998x1820 998x1820+0+0 8-bit sRGB 28848B 0.000u 0:00.009
png, gif, pdf
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: file test1.png has been created
test1.png PNG 998x1820 998x1820+0+0 8-bit sRGB 28848B 0.000u 0:00.009
Info in <TCanvas::Print>: GIF file test1.gif has been created
test1.gif GIF 998x1820 998x1820+0+0 8-bit sRGB 256c 17259B 0.000u 0:00.000
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 9287B 0.000u 0:00.000
png, pdf, gif
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: file test1.png has been created
test1.png PNG 998x1820 998x1820+0+0 8-bit sRGB 28848B 0.000u 0:00.009
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 9287B 0.000u 0:00.000
Info in <TCanvas::Print>: GIF file test1.gif has been created
test1.gif GIF 998x1820 998x1820+0+0 8-bit sRGB 256c 17259B 0.000u 0:00.000
pdf, gif, png
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 9287B 0.000u 0:00.000
Info in <TCanvas::Print>: GIF file test1.gif has been created
test1.gif GIF 998x1820 998x1820+0+0 8-bit sRGB 256c 17259B 0.000u 0:00.009
Info in <TCanvas::Print>: file test1.png has been created
test1.png PNG 998x1820 998x1820+0+0 8-bit sRGB 28848B 0.000u 0:00.009
pdf, png, gif
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 9287B 0.000u 0:00.000
Info in <TCanvas::Print>: file test1.png has been created
test1.png PNG 998x1820 998x1820+0+0 8-bit sRGB 28848B 0.000u 0:00.019
Info in <TCanvas::Print>: GIF file test1.gif has been created
test1.gif GIF 998x1820 998x1820+0+0 8-bit sRGB 256c 17259B 0.000u 0:00.009
$ root -b -q all_choices.C 

Processing all_choices.C...
gif, png, pdf
Info in <TCanvas::Print>: gif file test1.gif has been created
test1.gif GIF 996x1972 996x1972+0+0 8-bit sRGB 8c 10707B 0.000u 0:00.000
Info in <TCanvas::Print>: png file test1.png has been created
test1.png PNG 996x1972 996x1972+0+0 8-bit sRGB 16420B 0.000u 0:00.000
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 8877B 0.000u 0:00.000
gif, pdf, png
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: gif file test1.gif has been created
test1.gif GIF 996x1972 996x1972+0+0 8-bit sRGB 8c 10707B 0.000u 0:00.000
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 8877B 0.000u 0:00.000
Info in <TCanvas::Print>: png file test1.png has been created
test1.png PNG 996x1972 996x1972+0+0 8-bit sRGB 16420B 0.000u 0:00.009
png, gif, pdf
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: png file test1.png has been created
test1.png PNG 996x1972 996x1972+0+0 8-bit sRGB 16420B 0.000u 0:00.009
Info in <TCanvas::Print>: gif file test1.gif has been created
test1.gif GIF 996x1972 996x1972+0+0 8-bit sRGB 8c 10707B 0.000u 0:00.000
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 8877B 0.000u 0:00.000
png, pdf, gif
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: png file test1.png has been created
test1.png PNG 996x1972 996x1972+0+0 8-bit sRGB 16420B 0.000u 0:00.000
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 8877B 0.000u 0:00.000
Info in <TCanvas::Print>: gif file test1.gif has been created
test1.gif GIF 996x1972 996x1972+0+0 8-bit sRGB 8c 10707B 0.000u 0:00.009
pdf, gif, png
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 8877B 0.000u 0:00.000
Info in <TCanvas::Print>: gif file test1.gif has been created
test1.gif GIF 996x1972 996x1972+0+0 8-bit sRGB 8c 10707B 0.000u 0:00.000
Info in <TCanvas::Print>: png file test1.png has been created
test1.png PNG 996x1972 996x1972+0+0 8-bit sRGB 16420B 0.000u 0:00.009
pdf, png, gif
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c1
Info in <TCanvas::Print>: pdf file test1.pdf has been created
test1.pdf PDF 595x842 595x842+0+0 16-bit sRGB 8877B 0.000u 0:00.000
Info in <TCanvas::Print>: png file test1.png has been created
test1.png PNG 996x1972 996x1972+0+0 8-bit sRGB 16420B 0.000u 0:00.009
Info in <TCanvas::Print>: gif file test1.gif has been created
test1.gif GIF 996x1972 996x1972+0+0 8-bit sRGB 8c 10707B 0.000u 0:00.000

How do I find out what back end I am using?

When you stat ROOT if the X11 icon appears in the dock then you are using the X11 backend.
32

Exit it to make sure it restarts.

Note that with the cocoa backend the image were never truncated.
I will check now if, with the changes of resolution you suggested, I get the truncation…

I have set up the resolution as you suggested. I ran the macro:

void png_double_x_axis_title(){
   TCanvas *c1 = new TCanvas("c1","c1",0,0,1000,2000);
   c1->DrawFrame(0.,0.,10.,10.);
   c1->Print("test1.gif");
   c1->Print("test1.png");
   c1->Print("test1.pdf");
}

With ROOT 6.11/01 using the X11 and Cocoa backends both in interactive and batch modes. In all cases the gif and png files generated try this macro are not truncated.

I must be using the Cocoa back end then.

After further troubleshooting I can simplify my monitor setup and still reproduce the error. If I use the following setup I have the issue:

Monitor Dimension Rotation
1 3360 x 1890 (scaled down from 3840x1920) 0
3 1920 x 1080 270

The error only occurred when the canvas was created on Monitor 1. If I removed the scaling of monitor 1 the issue goes away, if I remove the rotation of monitor 3 (I kept the same numbers as above) the issue goes away. If I try an alternate rotated monitor (swap 3 for 4 not the same resolution) I don’t have the issue.

It seems I have stumbled into a very unique setup that causes problem and thus is hard to reproduce. Meanwhile @Wile_E_Coyote also reports the issue, but on a single monitor setup and on the X11 backend (if I understood correctly):

I’m not sure where to go from here except to have you come for a visit and check it out (too bad I’m so far away). Or have you find monitors of the same dimensions and see if you can reproduce the issue there.

So it seems we are looking at completely different problems. I saw, on a single monitor, an issue with the X11 version of ROOT. This version had a syncing problem when generated the png image. This is what I fixed for a single monitor. The cocoa version did not have any problem for me. So it is normal you do not see any improvement with the fix I did because it affected the X11 version only.

Yes it is hard to debug for me as I have only one monitor. …

I found a small extra screen and can reproduce your issue with root/cocoa. I managed to get a wrong png.

Note it is really a Cocoa issue. The X11 version on Mac does not have this problem.

If the image is generated from the TCanvas menu then it works.

1 Like

I found that I do not need to rotate the small screen to get the truncated picture. It is enough to have my terminal window on that screen. Then I run root from there. The graphics window appears on the iMac large screen and then the png is the truncated one I posted. If I run in batch with the same configuration all is fine (of course).

Well that is step in the right direction. I’m glad you were finally able to reproduce it.

@ksmith
I just committed the fix in the ROOT master. I can back port it to earlier an version if you want to test it. As it is a very specific problem affecting a very number of people I will back port only if you request it. If you are happy reinstalling the master I won’t back port it.

Agreed this is a very specific case and most likely won’t need to be back ported. @Wile_E_Coyote may want the fix moved to ROOT 5 though? I will test the master and let you know the result. (I wrote up a long message as I thought this was in reply to Xcode 9, I’m glad I stopped and read the topic title first.)

Note that in my last tests (here and here), I was always having non-truncated pictures, just their sizes depended on the used sequence of Print commands.

Yes I know. Unfortunately this thread is mixing several things not related … We fixed @ksmith problem with Mac and 2 screens. Now I will look at the two “here” you are talking about.

I do not think he is on Mac …

The original issue reported is now solved. I have marked the topic as such. Thank you for putting in the extended effort to fix this very strange edge case.

You’re welcome :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.