Skip to content
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
36 changes: 20 additions & 16 deletions graf2d/gpad/src/TPad.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4959,7 +4959,8 @@ static Bool_t ContainsTImage(TList *li)
/// generated in some loop one needs to detect the special cases of first
/// and last page and then munge the argument to Print() accordingly.
///
/// The "[" and "]" can be used instead of "(" and ")".
/// The "[" and "]" can be used instead of "(" and ")" to open / close without
/// actual printing.
///
/// Example:
/// ~~~ {.cpp}
Expand Down Expand Up @@ -5019,6 +5020,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 @@ -5036,25 +5040,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 @@ -5105,32 +5109,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 @@ -5171,7 +5175,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 @@ -5259,7 +5263,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 Expand Up @@ -7023,7 +7027,7 @@ TObject *TPad::WaitPrimitive(const char *pname, const char *emode)
TObject *obj = nullptr;
Bool_t testlast = kFALSE;
Bool_t hasname = pname && (strlen(pname) > 0);
if (!pname[0] && !emode[0]) testlast = kTRUE;
if ((!pname || !pname[0]) && (!emode || !emode[0])) testlast = kTRUE;
if (testlast) gROOT->SetEditorMode();
while (!gSystem->ProcessEvents() && gROOT->GetSelectedPad() && gPad) {
if (gROOT->GetEditorMode() == 0) {
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