Skip to content

Option Title: with title containing tex #19474

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

Merged
merged 2 commits into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions graf2d/gpad/src/TPad.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5123,6 +5123,9 @@ void TPad::Print(const char *filename, Option_t *option)
TString opt = !option ? opt_default : option;
Bool_t image = kFALSE;

Bool_t title = kFALSE;
if (strstr(opt,"Title:")) title = kTRUE;

if (!fs1.Length()) {
psname = GetName();
psname += opt;
Expand All @@ -5140,25 +5143,25 @@ void TPad::Print(const char *filename, Option_t *option)

// Save pad/canvas in alternative formats
TImage::EImageFileTypes gtype = TImage::kUnknown;
if (strstr(opt, "gif+")) {
if (!title && strstr(opt, "gif+")) {
gtype = TImage::kAnimGif;
image = kTRUE;
} else if (strstr(opt, "gif")) {
} else if (!title && strstr(opt, "gif")) {
gtype = TImage::kGif;
image = kTRUE;
} else if (strstr(opt, "png")) {
} else if (!title && strstr(opt, "png")) {
gtype = TImage::kPng;
image = kTRUE;
} else if (strstr(opt, "jpg")) {
} else if (!title && strstr(opt, "jpg")) {
gtype = TImage::kJpeg;
image = kTRUE;
} else if (strstr(opt, "tiff")) {
} else if (!title && strstr(opt, "tiff")) {
gtype = TImage::kTiff;
image = kTRUE;
} else if (strstr(opt, "xpm")) {
} else if (!title && strstr(opt, "xpm")) {
gtype = TImage::kXpm;
image = kTRUE;
} else if (strstr(opt, "bmp")) {
} else if (!title && strstr(opt, "bmp")) {
gtype = TImage::kBmp;
image = kTRUE;
}
Expand Down Expand Up @@ -5209,32 +5212,32 @@ void TPad::Print(const char *filename, Option_t *option)
}

//==============Save pad/canvas as a C++ script==============================
if (strstr(opt,"cxx")) {
if (!title && strstr(opt,"cxx")) {
GetCanvas()->SaveSource(psname, "");
return;
}

//==============Save pad/canvas as a root file===============================
if (strstr(opt,"root")) {
if (!title && strstr(opt,"root")) {
if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
return;
}

//==============Save pad/canvas as a XML file================================
if (strstr(opt,"xml")) {
if (!title && strstr(opt,"xml")) {
// Plugin XML driver
if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
return;
}

//==============Save pad/canvas as a JSON file================================
if (strstr(opt,"json")) {
if (!title && strstr(opt,"json")) {
if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
return;
}

//==============Save pad/canvas as a SVG file================================
if (strstr(opt,"svg")) {
if (!title && strstr(opt,"svg")) {
gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);

Bool_t noScreen = kFALSE;
Expand Down Expand Up @@ -5275,7 +5278,7 @@ void TPad::Print(const char *filename, Option_t *option)
}

//==============Save pad/canvas as a TeX file================================
if (strstr(opt,"tex") || strstr(opt,"Standalone")) {
if (!title && (strstr(opt,"tex") || strstr(opt,"Standalone"))) {
gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);

Bool_t noScreen = kFALSE;
Expand Down Expand Up @@ -5363,7 +5366,7 @@ void TPad::Print(const char *filename, Option_t *option)
if (!gVirtualPS || mustOpen) {

const char *pluginName = "ps"; // Plugin Postscript driver
if (strstr(opt,"pdf") || strstr(opt,"Title:") || strstr(opt,"EmbedFonts"))
if (strstr(opt,"pdf") || title || strstr(opt,"EmbedFonts"))
pluginName = "pdf";
else if (image)
pluginName = "image"; // Plugin TImageDump driver
Expand Down
1 change: 1 addition & 0 deletions graf2d/gpad/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# For the list of contributors see $ROOTSYS/README/CREDITS.

ROOT_ADD_GTEST(TRatioPlot ratioplot.cxx LIBRARIES Gpad)
ROOT_ADD_GTEST(TPad pdftitle.cxx LIBRARIES Gpad)
38 changes: 38 additions & 0 deletions graf2d/gpad/test/pdftitle.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "gtest/gtest.h"
#include "TSystem.h"
#include "TCanvas.h"
#include "TString.h"

TEST(TPad, PDFTitle)
{
const TString pdfFile = "output.pdf";

// Generate a multi-page PDF with a title
TCanvas c;
c.Print(pdfFile + "("); // Start multi-page PDF
c.Print(pdfFile, "Title:Vertex"); // Add page with title
c.Print(pdfFile + ")"); // Close multi-page PDF

// Check if the file was created successfully
FileStat_t fileStat;
int statCode = gSystem->GetPathInfo(pdfFile, fileStat);
ASSERT_EQ(statCode, 0) << "PDF file was not created.";

// Get the actual size of the generated file
Long64_t actualSize = fileStat.fSize;

// Reference file size in bytes (adjust to match your expected output)
const Long64_t referenceSize = 13601;
const double tolerance = 0.01; // Allow 1% deviation

// Compute acceptable size range
Long64_t minSize = referenceSize * (1.0 - tolerance);
Long64_t maxSize = referenceSize * (1.0 + tolerance);

// Assert that the actual size is within acceptable range
EXPECT_GE(actualSize, minSize) << "PDF file is smaller than expected.";
EXPECT_LE(actualSize, maxSize) << "PDF file is larger than expected.";

// Cleanup: delete the test file
gSystem->Unlink(pdfFile);
}
Loading