Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printed SVG image contains newline cutting through XML tags #9514

Closed
1 task done
ShamrockLee opened this issue Jan 7, 2022 · 5 comments · Fixed by #14590 · May be fixed by #9518
Closed
1 task done

Printed SVG image contains newline cutting through XML tags #9514

ShamrockLee opened this issue Jan 7, 2022 · 5 comments · Fixed by #14590 · May be fixed by #9518

Comments

@ShamrockLee
Copy link
Contributor

ShamrockLee commented Jan 7, 2022

  • Checked for duplicates

Describe the bug

When plotting to SVG file the way

hist->Draw();
gPad->Print("hist.svg");

The produced SVG file is occasionally broken due to the newline character being inserted to the middle of the closing XML tag.

The error might be caused by certain kind of 250-character-per-line limit.

Expected behavior

The newline should be inserted somewhere before the closing XML tag.

Please don't remove all the new lines just to workaround this bug. It is great to have readable SVG outputs.

To Reproduce

  1. Prepare the reproduction code
    Reproduce.C
#include<TCanvas.h>
#include<TPad.h>
#include<TFile.h>
#include<TH1.h>

void Reproduce(const char *pathFileIn="hsimple.root") {
  TCanvas::MakeDefCanvas();
  TFile *tfIn = TFile::Open(pathFileIn);
  TH1* hpxLongTitle = static_cast<TH1*>(tfIn->Get<TH1>("hpx")->Clone("hpxLongTitle"));
  hpxLongTitle->SetTitle("SupercalifragilisticexpialidociousHonorificabilitudinitatibusFloccinaucinihilipilificationFreeSesquipedalianTitleOnTheSupercalifragilisticexpialidociousHonorificabilitudinitatibusFloccinaucinihilipilificationFreeHist");
  hpxLongTitle->Draw();
  gPad->Print("hpxLongTitle.svg");
  tfIn->Close();
}

int main(int argc, char* argv[]) {
  if ( argc > 1 ) {
    Reproduce(argv[1]);
  } else {
    Reproduce();
  }
}
  1. Run by
$ root -l -q 'Reproduce.C++("path/to/hsimple.root")'
or by
$ g++ $(root-config --glibs --cflags) -o Reproduce.o Reproduce.C
$ ./Reproduce.o "path/to/hsimple.root"
  1. See the generated hpxLongTitle.svg
  2. Open with a text editor and scroll to the bottom (pressing G for vim)
  3. See the broken XML tag

Setup

  1. ROOT Version: 6.25/01, built for linuxx8664gcc on Jan 01 1980, 00:00:00
  2. Operating System: NixOS
  3. Build with Nix package manager from master, revision 7821ed1

Additional context

The actual content of that supercali-title in my use case is a JSON string without any space character.

The generated SVG file (add the .txt suffix to workaround GitHub's limitation):
hpxLongTitle.svg.txt

@ShamrockLee ShamrockLee added the bug label Jan 7, 2022
@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Jan 7, 2022

In

core/base/src/TVirtualPS.cxx

There goes

const Int_t kMaxBuffer = 250;

@dpiparo
Copy link
Member

dpiparo commented Feb 3, 2024

This is not an area where I would call myself an expert, by far. However, I have a naive observation: wouldn't the fix just consist in raising the limit of kMaxBuffer to something far higher than 250 and maybe add a check to that number to stop the svg production if the string is longer than that limit?

@vepadulano vepadulano added the fixathon This issue can be tackled at a ROOT fixathon label Feb 5, 2024
@couet
Copy link
Member

couet commented Feb 5, 2024

Fix here: #14590

@couet couet removed the fixathon This issue can be tackled at a ROOT fixathon label Feb 5, 2024
@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 5, 2024

Cool!

@couet
Copy link
Member

couet commented Mar 20, 2024

PR Merged

@guitargeek guitargeek added this to Issues in Fixed in 6.32.00 via automation Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment