Skip to content

Commit a3ca886

Browse files
authored
Option Title: with title containing tex (#19474)
* Option Title: with title containing tex * Add a UNI Test
1 parent 58e1757 commit a3ca886

File tree

3 files changed

+56
-14
lines changed

3 files changed

+56
-14
lines changed

graf2d/gpad/src/TPad.cxx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5124,6 +5124,9 @@ void TPad::Print(const char *filename, Option_t *option)
51245124
TString opt = !option ? opt_default : option;
51255125
Bool_t image = kFALSE;
51265126

5127+
Bool_t title = kFALSE;
5128+
if (strstr(opt,"Title:")) title = kTRUE;
5129+
51275130
if (!fs1.Length()) {
51285131
psname = GetName();
51295132
psname += opt;
@@ -5141,25 +5144,25 @@ void TPad::Print(const char *filename, Option_t *option)
51415144

51425145
// Save pad/canvas in alternative formats
51435146
TImage::EImageFileTypes gtype = TImage::kUnknown;
5144-
if (strstr(opt, "gif+")) {
5147+
if (!title && strstr(opt, "gif+")) {
51455148
gtype = TImage::kAnimGif;
51465149
image = kTRUE;
5147-
} else if (strstr(opt, "gif")) {
5150+
} else if (!title && strstr(opt, "gif")) {
51485151
gtype = TImage::kGif;
51495152
image = kTRUE;
5150-
} else if (strstr(opt, "png")) {
5153+
} else if (!title && strstr(opt, "png")) {
51515154
gtype = TImage::kPng;
51525155
image = kTRUE;
5153-
} else if (strstr(opt, "jpg")) {
5156+
} else if (!title && strstr(opt, "jpg")) {
51545157
gtype = TImage::kJpeg;
51555158
image = kTRUE;
5156-
} else if (strstr(opt, "tiff")) {
5159+
} else if (!title && strstr(opt, "tiff")) {
51575160
gtype = TImage::kTiff;
51585161
image = kTRUE;
5159-
} else if (strstr(opt, "xpm")) {
5162+
} else if (!title && strstr(opt, "xpm")) {
51605163
gtype = TImage::kXpm;
51615164
image = kTRUE;
5162-
} else if (strstr(opt, "bmp")) {
5165+
} else if (!title && strstr(opt, "bmp")) {
51635166
gtype = TImage::kBmp;
51645167
image = kTRUE;
51655168
}
@@ -5210,32 +5213,32 @@ void TPad::Print(const char *filename, Option_t *option)
52105213
}
52115214

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

52185221
//==============Save pad/canvas as a root file===============================
5219-
if (strstr(opt,"root")) {
5222+
if (!title && strstr(opt,"root")) {
52205223
if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
52215224
return;
52225225
}
52235226

52245227
//==============Save pad/canvas as a XML file================================
5225-
if (strstr(opt,"xml")) {
5228+
if (!title && strstr(opt,"xml")) {
52265229
// Plugin XML driver
52275230
if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
52285231
return;
52295232
}
52305233

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

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

52415244
Bool_t noScreen = kFALSE;
@@ -5276,7 +5279,7 @@ void TPad::Print(const char *filename, Option_t *option)
52765279
}
52775280

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

52825285
Bool_t noScreen = kFALSE;
@@ -5364,7 +5367,7 @@ void TPad::Print(const char *filename, Option_t *option)
53645367
if (!gVirtualPS || mustOpen) {
53655368

53665369
const char *pluginName = "ps"; // Plugin Postscript driver
5367-
if (strstr(opt,"pdf") || strstr(opt,"Title:") || strstr(opt,"EmbedFonts"))
5370+
if (strstr(opt,"pdf") || title || strstr(opt,"EmbedFonts"))
53685371
pluginName = "pdf";
53695372
else if (image)
53705373
pluginName = "image"; // Plugin TImageDump driver

graf2d/gpad/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
# For the list of contributors see $ROOTSYS/README/CREDITS.
66

77
ROOT_ADD_GTEST(TRatioPlot ratioplot.cxx LIBRARIES Gpad)
8+
ROOT_ADD_GTEST(TPad pdftitle.cxx LIBRARIES Gpad)

graf2d/gpad/test/pdftitle.cxx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "gtest/gtest.h"
2+
#include "TSystem.h"
3+
#include "TCanvas.h"
4+
#include "TString.h"
5+
6+
TEST(TPad, PDFTitle)
7+
{
8+
const TString pdfFile = "output.pdf";
9+
10+
// Generate a multi-page PDF with a title
11+
TCanvas c;
12+
c.Print(pdfFile + "("); // Start multi-page PDF
13+
c.Print(pdfFile, "Title:Vertex"); // Add page with title
14+
c.Print(pdfFile + ")"); // Close multi-page PDF
15+
16+
// Check if the file was created successfully
17+
FileStat_t fileStat;
18+
int statCode = gSystem->GetPathInfo(pdfFile, fileStat);
19+
ASSERT_EQ(statCode, 0) << "PDF file was not created.";
20+
21+
// Get the actual size of the generated file
22+
Long64_t actualSize = fileStat.fSize;
23+
24+
// Reference file size in bytes (adjust to match your expected output)
25+
const Long64_t referenceSize = 13601;
26+
const double tolerance = 0.01; // Allow 1% deviation
27+
28+
// Compute acceptable size range
29+
Long64_t minSize = referenceSize * (1.0 - tolerance);
30+
Long64_t maxSize = referenceSize * (1.0 + tolerance);
31+
32+
// Assert that the actual size is within acceptable range
33+
EXPECT_GE(actualSize, minSize) << "PDF file is smaller than expected.";
34+
EXPECT_LE(actualSize, maxSize) << "PDF file is larger than expected.";
35+
36+
// Cleanup: delete the test file
37+
gSystem->Unlink(pdfFile);
38+
}

0 commit comments

Comments
 (0)