Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TDocDirective.cxx
Go to the documentation of this file.
1#include "TDocDirective.h"
2
3#include "TApplication.h"
4#include "TClass.h"
5#include "TDocInfo.h"
6#include "TDocOutput.h"
7#include "TDocParser.h"
8#include "TError.h"
9#include "THtml.h"
10#include "TInterpreter.h"
11#include "TLatex.h"
12#include "TMacro.h"
13#include "TObjString.h"
14#include "TObjArray.h"
15#include "TPRegexp.h"
16#include "TROOT.h"
17#include "TSystem.h"
18#include "TVirtualPad.h"
19#include "TVirtualMutex.h"
20#include "TVirtualX.h"
21#include <typeinfo>
22#include <fstream>
23#include <sstream>
24#include <cstdlib>
25
26//______________________________________________________________________________
27//
28// When THtml parses documentation (through TDocParser), it checks for special
29// words ("begin_something", "end_something", where the begin and end are the
30// significant part). THtml then searches for a TDocDirective which can handle
31// these tags ("whatever" in the example), passes the text enclosed by these
32// tags to the directive, which in turn processes it.
33//
34// That way, HTML, latex, and C++ macros can be processed by THtml, e.g. to
35// generate plain HTML or GIF pictures. The classes reposinsible for parsing
36// that are TDocHtmlDirective, TDocLatexDirective, and TDocMacroDirective,
37// respecively.
38//
39// Directives can have optional parameters; these are passed as paranthesis
40// enclosed, comma delimited name=value pairs; see SetParameters().
41//
42// You can implement your own directive simply by deriving from TDocDirective;
43// the tag corresponds to TDocDirective's name (e.g. "HTML" for "begin_html" /
44// "end_html").
45//______________________________________________________________________________
46
48
49////////////////////////////////////////////////////////////////////////////////
50/// Delete all output generated by the directive beginning
51/// with Name() and ending with ext
52
53void TDocDirective::DeleteOutputFiles(const char* ext) const
54{
55 TString basename;
56 GetName(basename);
57 basename += "_";
58 TString dirname(GetOutputDir());
59 void* hDir = gSystem->OpenDirectory(dirname);
60 const char* entry = 0;
61 while ((entry = gSystem->GetDirEntry(hDir))) {
62 TString sEntry(entry);
63 if (sEntry.BeginsWith(basename) && isdigit(sEntry[basename.Length()]) && (!ext || sEntry.EndsWith(ext)))
64 gSystem->Unlink((dirname + "/" + entry).Data());
65 }
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Get the full name, based on fName, fTitle, fDocParser's tag.
71
73{
74 name = fName;
76 name += "_";
77 TString outfilename;
79 outfilename = gSystem->BaseName(outfilename);
80 Ssiz_t posExt = outfilename.Last('.');
81 outfilename.Remove(posExt, outfilename.Length() - posExt);
82 name += outfilename;
83 }
84 if (GetTitle() && strlen(GetTitle())) {
85 name += "_";
86 name += GetTitle();
87 }
88 if (fCounter != -1) {
89 name += "_";
90 name += fCounter;
91 }
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Get the directory for documentation output.
96
97const char* TDocDirective::GetOutputDir() const
98{
99 return fHtml ? fHtml->GetOutputDir().Data() : 0;
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// Given a string containing parameters in params,
104/// we call AddParameter() for each of them.
105/// This function splits the parameter names and
106/// extracts their values if they are given.
107/// Parameters are separated by ",", values are
108/// separated from parameter names by "=".
109/// params being
110/// a = "a, b, c", b='d,e'
111/// will issue two calls to AddParameter(), one for
112/// a with value "a, b, c" and one for b with value
113/// "d,e" (each without the quotation marks).
114
115void TDocDirective::SetParameters(const char* params)
116{
117 fParameters = params;
118
119 if (!fParameters.Length())
120 return;
121
122 TString param;
123 Ssiz_t pos = 0;
124 while (fParameters.Tokenize(param, pos, ",")) {
125 param = param.Strip(TString::kBoth);
126 if (!param.Length())
127 continue;
128
129 Ssiz_t posAssign = param.Index('=');
130 if (posAssign != kNPOS) {
131 TString value(param(posAssign + 1, param.Length()));
132 value = value.Strip(TString::kBoth);
133 if (value[0] == '\'')
134 value = value.Strip(TString::kBoth, '\'');
135 else if (value[0] == '"')
136 value = value.Strip(TString::kBoth, '"');
137 param.Remove(posAssign, param.Length());
138 param = param.Strip(TString::kBoth);
139 AddParameter(param, value);
140 } else {
141 param = param.Strip(TString::kBoth);
142 AddParameter(param, 0);
143 }
144 }
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Set the parser, and fDocOutput, fHtml from that
149
151{
152 fDocParser = parser;
153 fDocOutput = parser ? parser->GetDocOutput() : 0;
155}
156
157
158//______________________________________________________________________________
159//
160// Process a "begin_html" / "end_html" block. Stop linking keywords and simply
161// copy the text enclosed by the directive to the output HTML file.
162//______________________________________________________________________________
163
165
166////////////////////////////////////////////////////////////////////////////////
167/// Add a line of HTML
168
170{
171 if (line.Start() == -1) return;
172
173 TPRegexp pretag("</?[pP][rR][eE][ >]");
174 TSubString iLine(line);
175 Ssiz_t posPre = iLine.String().Index(pretag, iLine.Start());
176 if (posPre == kNPOS)
177 fText += line;
178 else {
179 // remove <pre> in fVerbatim environments, and
180 // </pre> in !fVerbatim environments.
181 while (posPre != kNPOS && posPre > 0) {
182 Bool_t isOpen = line[posPre + 1 - line.Start()] != '/';
183 Ssiz_t posClose = iLine.String().Index(">", posPre);
184 if (posClose ==kNPOS) break; // aka oops.
185 Ssiz_t len = posClose - posPre;
186
187 if (fVerbatim) {
188 if (isOpen) {
189 // skip
190 fText += iLine.String()(iLine.Start(), posPre - iLine.Start());
191 } else {
192 // write it out
193 fText += iLine.String()(iLine.Start(), posPre + len - iLine.Start());
195 }
196 } else {
197 if (!isOpen) {
198 // skip
199 fText += iLine.String()(iLine.Start(), posPre - iLine.Start());
200 } else {
201 // write it out
202 fText += iLine.String()(iLine.Start(), posPre + len - iLine.Start());
204 }
205 }
206
207 iLine = iLine.String()(posPre + len, iLine.Length());
208 posPre = iLine.String().Index(pretag, iLine.Start());
209 }
210
211 fText += iLine;
212 }
213 fText += "\n";
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Set result to the HTML code that was passed in via AddLine().
218/// Prepend a closing </pre>, append an opening <pre>
219
221{
222 result = "</pre><!-- TDocHtmlDirective start -->";
223 result += fText + "<!-- TDocHtmlDirective end --><pre>";
224 return kTRUE;
225}
226
227
228
229//______________________________________________________________________________
230//
231// Process a "begin_macro" / "end_macro" block. The block can be a file name
232// or a CINT script (i.e. even ".x file.C" is allowed). See AddParameter() for
233// supported options. Example (the quotes prevent THtml from expanding the
234// example):
235//
236// "BEGIN_MACRO"
237// .x $ROOTSYS/tutorials/hsimple.C
238// "END_MACRO"
239//
240// The macro is meant to create an object that can be saved as a GIF file by
241// calling object->SaveAs(outputfile.gif). The macro is expected to return that
242// object as a TObject*; if it does not, gPad is used and saved. The object
243// is deleted by TDocMacroDirective once saved.
244//______________________________________________________________________________
245
247
248////////////////////////////////////////////////////////////////////////////////
249/// Destructor
250
252{
253 delete fMacro;
254}
255
256////////////////////////////////////////////////////////////////////////////////
257
260 Long_t ret = gROOT->ProcessLine(TString(".x ") + what, &error);
261 Int_t sleepCycles = 50; // 50 = 5 seconds
262 while (error == TInterpreter::kProcessing && --sleepCycles > 0)
263 gSystem->Sleep(100);
264
265 gSystem->ProcessEvents(); // in case ret needs to handle some events first
266
267 if (error != TInterpreter::kNoError) {
268 ::Error("TDocMacroDirective::HandleDirective_Macro",
269 "Error processing macro for %s!", out.Data());
270 return;
271 }
272 if (!ret) {
273 return;
274 }
275
276 // Something with a vtable
277 const TObject* objRet = (const TObject*)ret;
278 try {
279 typeid(*objRet).name(); // needed to test whether ret is indeed an object with a vtable!
280 objRet = dynamic_cast<const TObject*>(objRet);
281 }
282 catch (...) {
283 objRet = 0;
284 }
285
286 if (!objRet) {
287 return;
288 }
289
290 if (gDebug > 3)
291 ::Info("TDocMacroDirective::HandleDirective_Macro",
292 "Saving returned %s to file %s.",
293 objRet->IsA()->GetName(), out.Data());
294
295 if (!gROOT->IsBatch()) {
296 // to get X11 to sync :-( gVirtualX->Update()/Sync() don't do it
297 gSystem->Sleep(1000);
298 gVirtualX->Update(0);
299 gVirtualX->Update(1);
300 }
301
303 if (!gROOT->IsBatch()) {
304 gVirtualX->Update(0);
305 gVirtualX->Update(1);
306 }
307
308 objRet->SaveAs(out);
309 gSystem->ProcessEvents(); // SaveAs triggers an event
310
311#ifdef R__BEPAEPSTLICHERALSDERPAPST
312 // ensure objRet is not e.g. the TGMainFrame of a new TCanvas: require padSave == gPad
313 if (objRet != gPad && padSave == gPad) {
314 delete objRet;
315 }
316#endif
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Add a macro line.
321/// Lines ending on "*HIDE*" will be executed as part of the
322/// macro, but not shown in the source tab if the parameter
323/// source is supplied.
324
326{
327 if (!fMacro) {
329 GetName(name);
330 fMacro = new TMacro(name);
331 }
332
333 // return if no line - or if there was an intentinal line-break,
334 // i.e. an empty line
335 if (line.Start() == -1 && const_cast<TSubString&>(line).String().Length()) return;
336
337 TString sLine(line);
338 fMacro->AddLine(sLine);
339 fIsFilename &= !sLine.Contains('{');
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// Create the input file for SubProcess().
344
346 if (!fIsFilename) {
347 TString fileSysName;
348 GetName(fileSysName);
349 fileSysName += ".C";
351 fMacro->SaveSource(fileSysName);
352 return fileSysName;
353 }
354
355 // We have a filename; find it and build the invocation.
356 TString filename;
357 TIter iLine(fMacro->GetListOfLines());
358 while (filename.Length() == 0)
359 filename = ((TObjString*)iLine())->String().Strip(TString::kBoth);
360
361 TString macroPath;
362 TString modulename;
363 if (GetHtml() && GetDocParser()) {
366 else GetDocParser()->GetCurrentModule(modulename);
367 }
368 if (modulename.Length()) {
369 GetHtml()->GetModuleMacroPath(modulename, macroPath);
370 } else macroPath = gSystem->pwd();
371
372 const char* pathDelimiter = ":"; // use ":" even on windows
373 TObjArray* arrDirs(macroPath.Tokenize(pathDelimiter));
374 TIter iDir(arrDirs);
375 TObjString* osDir = nullptr;
376 macroPath = "";
377 TString filenameDirPart = gSystem->GetDirName(filename);
378 filenameDirPart.Prepend('/'); // as dir delimiter, not as root dir
379 while ((osDir = (TObjString*)iDir())) {
380 if (osDir->String().EndsWith("\\"))
381 osDir->String().Remove(osDir->String().Length() - 1);
382 osDir->String() += filenameDirPart;
383 macroPath += osDir->String() + pathDelimiter;
384 }
385
386 TString plusplus;
387 while (filename.EndsWith("+")) {
388 plusplus += '+';
389 filename.Remove(filename.Length() - 1);
390 }
391
392 TString params;
393 if (filename.EndsWith(")")) {
394 Ssiz_t posOpen = filename.Last('(');
395 if (posOpen != kNPOS) {
396 params = filename(posOpen, filename.Length());
397 filename.Remove(posOpen, filename.Length());
398 }
399 }
400
401 TString fileSysName(gSystem->BaseName(filename));
402 if (!gSystem->FindFile(macroPath, fileSysName)) {
403 Error("GetResult", "Cannot find macro '%s' in path '%s'!",
404 gSystem->BaseName(filename), macroPath.Data());
405 return "";
406 }
407 fileSysName += params;
408 fileSysName += plusplus;
409
410
411 if (fShowSource) {
412 // copy macro into fMacro - before running it, in case the macro blocks its file
413 std::ifstream ifMacro(fileSysName);
416 while (ifMacro) {
417 if (!line.ReadLine(ifMacro, kFALSE) || ifMacro.eof())
418 break;
420 }
421 }
422 return fileSysName;
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// Get the result (i.e. an HTML img tag) for the macro invocation.
427/// If fShowSource is set, a second tab will be created which shows
428/// the source.
429
431{
432 if (!fMacro)
433 return kFALSE;
434
435 if (!fMacro->GetListOfLines()
436 || !fMacro->GetListOfLines()->First()) {
437 Warning("GetResult", "Empty directive found!");
438 return kTRUE;
439 }
440
441 R__LOCKGUARD(GetHtml()->GetMakeClassMutex());
442
443 if (gDebug > 3)
444 Info("HandleDirective_Macro", "executing macro \"%s\" with %d lines.",
446
447 Bool_t wasBatch = gROOT->IsBatch();
448 Bool_t wantBatch = kFALSE;
449 if (!wasBatch && !fNeedGraphics)
450 wantBatch = kTRUE;
451 else if (fNeedGraphics) {
452 if (fHtml->IsBatch()) {
453 Warning("GetResult()", "Will not initialize the graphics system; skipping macro %s!", GetName());
454 result = "";
455 return kFALSE;
456 }
457 }
458
459 TString outFileName;
460 {
461 GetName(outFileName);
462 GetDocOutput()->NameSpace2FileName(outFileName);
463 outFileName += ".gif";
464 outFileName.ReplaceAll(" ", "_");
465 gSystem->PrependPathName(GetOutputDir(), outFileName);
466 }
467
468 TString subProcInputFile = CreateSubprocessInputFile();
469 if (!subProcInputFile.Length()) return kFALSE;
470
471 subProcInputFile.ReplaceAll("\\", "\\\\");
472 subProcInputFile.ReplaceAll("\"", "\\\"");
473 TString invoc("root.exe -l -q ");
474 if (wantBatch) {
475 invoc += "-b ";
476 }
477 invoc += "-e 'TDocMacroDirective::SubProcess(\""
478 + subProcInputFile + "\",\"" + outFileName + "\");'";
479 gSystem->Unlink(outFileName);
480 Int_t exitCode = gSystem->Exec(invoc.Data());
481
482 if (exitCode && gDebug > 0) {
483 Info("GetResult()", "Subprocess exited with status %d\n", exitCode);
484 } else if (!fIsFilename) {
485 // we have created the input file.
486 gSystem->Unlink(subProcInputFile);
487 }
488
489 if (!gSystem->AccessPathName(outFileName)) {
490 // Output file was created
491 result = "<span class=\"macro\"><img class=\"macro\" alt=\"output of ";
492 result += outFileName;
493
494 result += "\" title=\"MACRO\" src=\"";
495 result += gSystem->BaseName(outFileName);
496 result += "\" /></span>";
497 }
498
499 if (fShowSource) {
500 // convert the macro source
501 TIter iLine(fMacro->GetListOfLines());
502 TObjString* osLine = 0;
503 std::stringstream ssRaw;
504 while ((osLine = (TObjString*)iLine()))
505 ssRaw << osLine->String() << std::endl;
506
507 TDocParser *dparser = 0;
508 if (GetDocParser()->GetCurrentClass())
509 dparser = new TDocParser(*(TClassDocOutput*)GetDocOutput(), GetDocParser()->GetCurrentClass());
510 else dparser = new TDocParser(*GetDocOutput());
511 std::stringstream ssConverted;
512 dparser->Convert(ssConverted, ssRaw, "./", kTRUE /*code*/, kFALSE /*process directives*/);
513 delete dparser;
514
517 while (!ssConverted.fail()) {
518 if (!line.ReadLine(ssConverted, kFALSE) || ssConverted.eof())
519 break;
521 }
522
523 TString id(gSystem->BaseName(outFileName));
524 id = id(0, id.Length()-4); // remove ".gif"
525 // TODO: we need an accessible version of the source, i.e. visible w/o javascript
526 TString tags("</pre><div class=\"tabs\">\n"
527 "<a id=\"" + id + "_A0\" class=\"tabsel\" href=\"" + gSystem->BaseName(outFileName) + "\" onclick=\"javascript:return SetDiv('" + id + "',0);\">Picture</a>\n"
528 "<a id=\"" + id + "_A1\" class=\"tab\" href=\"#\" onclick=\"javascript:return SetDiv('" + id + "',1);\">Source</a>\n"
529 "<br /></div><div class=\"tabcontent\">\n"
530 "<div id=\"" + id + "_0\" class=\"tabvisible\">" + result + "</div>\n"
531 "<div id=\"" + id + "_1\" class=\"tabhidden\"><div class=\"listing\"><pre class=\"code\">");
532 iLine.Reset();
533 osLine = 0;
534 while ((osLine = (TObjString*) iLine()))
535 if (!TString(osLine->String().Strip()).EndsWith("*HIDE*"))
536 tags += osLine->String() + "\n";
537 if (tags.EndsWith("\n"))
538 tags.Remove(tags.Length()-1); // trailing line break
539 tags += "</pre></div></div><div class=\"clear\"></div></div><pre>";
540 result = tags;
541 // Protect the nested comments from being stripped by a
542 // TDocParser::ProcessComment() in the call stack.
543 result.ReplaceAll("<span class=\"comment\">", "<span class=\"codecomment\">");
544 }
545
546 return kTRUE;
547}
548
549////////////////////////////////////////////////////////////////////////////////
550/// Setting fNeedGraphics if name is "GUI",
551/// setting fShowSource if name is "SOURCE"
552
553void TDocMacroDirective::AddParameter(const TString& name, const char* /*value=0*/)
554{
555 if (!name.CompareTo("gui", TString::kIgnoreCase))
557 else if (!name.CompareTo("source", TString::kIgnoreCase))
559 else Warning("AddParameter", "Unknown option %s!", name.Data());
560}
561
562
563
564namespace {
565 Float_t gLinePadding = 10.; //px
566 Float_t gColumnPadding = 10.; //px
567
568 class TLatexLine {
569 private:
570 std::vector<Float_t> fWidths;
571 Float_t fHeight;
572 TObjArray* fColumns; // of TObjString*
573
574 public:
575 TLatexLine(TObjArray* columns = 0):
576 fHeight(0.), fColumns(columns) { if (columns) fWidths.resize(Size());}
577
578 Float_t& Width(UInt_t col) {return fWidths[col];}
579 Float_t& Height() {return fHeight;}
580 TString* operator[](Int_t column) {
581 if (fColumns && fColumns->GetEntriesFast() > column)
582 return &(((TObjString*)fColumns->At(column))->String());
583 return 0;
584 }
585 UInt_t Size() const { return fColumns ? fColumns->GetEntries() : 0; }
586 void Delete() { delete fColumns; }
587 };
588}
589
590//______________________________________________________________________________
591//
592// Handle a "Begin_Latex"/"End_Latex" directive.
593// called as
594// "Begin_Latex(fontsize=10, separator='=,', rseparator='=|,', align=lcl)"
595// will create and include a TLatex-processed image, with a given fontsize
596// in pixels (defaults to 16). If (r)separator is given, the formulas on the
597// following lines will be grouped into columns; a new column starts with
598// (regexp) match of the separator; by default there is only one column.
599// separator matches any character, rseparator matches as regexp with one
600// column per pattern match. Only one of separator or rseparator can be given.
601// align defines the alignment for each columns; be default, all columns
602// are right aligned. NOTE that the column separator counts as a column itself!
603//______________________________________________________________________________
604
605
607
608////////////////////////////////////////////////////////////////////////////////
609/// Destructor
610
612{
614 delete fLatex;
615 delete fBBCanvas;
617}
618
619////////////////////////////////////////////////////////////////////////////////
620/// Add a latex line
621
623{
624 if (line.Length() == 0)
625 return;
626
627 if (!fLatex) {
629 GetName(name);
630 fLatex = new TMacro(name);
631 }
632
633 TString sLine(line);
634 GetDocParser()->Strip(sLine);
635 if (sLine.Length() == 0)
636 return;
637
638 fLatex->AddLine(sLine);
639}
640
641////////////////////////////////////////////////////////////////////////////////
642/// Create a gif file named filename from a latex expression in fLatex.
643/// Called when "Begin_Latex"/"End_Latex" is processed.
644
645void TDocLatexDirective::CreateLatex(const char* filename)
646{
647 if (!fLatex
649 || !fLatex->GetListOfLines()->First())
650 return;
651
652 R__LOCKGUARD(GetHtml()->GetMakeClassMutex());
653
654 TVirtualPad* oldPad = gPad;
655
656 Bool_t wasBatch = gROOT->IsBatch();
657 if (!wasBatch)
658 gROOT->SetBatch();
659
660 const Float_t canvSize = 1200.;
661 if (!fBBCanvas)
662 // add magic batch vs. gui canvas sizes (4, 28)
663 fBBCanvas = (TVirtualPad*)gROOT->ProcessLineFast(
664 Form("new TCanvas(\"R__TDocLatexDirective_BBCanvas\",\"fBBCanvas\",%g,%g);", -(canvSize + 4.), canvSize + 28.));
665 if (!fBBCanvas) {
666 Error("CreateLatex", "Cannot create a TCanvas via the interpreter!");
667 return;
668 }
671
673
674 std::list<TLatexLine> latexLines;
675 std::vector<Float_t> maxWidth(20);
676 UInt_t numColumns = 0;
677 Float_t totalHeight = gLinePadding;
678
679 TLatex latex;
680 latex.SetTextFont(43);
682 latex.SetTextAlign(12);
683
684 // calculate positions
685 TIter iterLine(fLatex->GetListOfLines());
686 TObjString* line = 0;
687 TPRegexp regexp;
688 if (fSeparator.Length()) {
689 if (fSepIsRegexp)
690 regexp = TPRegexp(fSeparator);
691 } else fSepIsRegexp = kFALSE;
692
693 while ((line = (TObjString*) iterLine())) {
694 const TString& str = line->String();
695 TObjArray* split = 0;
696 if (!fSepIsRegexp) {
697 split = new TObjArray();
698 split->SetOwner();
699 }
700 if (!fSeparator.Length())
701 split->Add(new TObjString(str));
702 else {
703 if (fSepIsRegexp)
704 split = regexp.MatchS(str);
705 else {
706 Ssiz_t prevStart = 0;
707 for (Ssiz_t pos = 0; pos < str.Length(); ++pos) {
708 if (fSeparator.Index(str[pos]) != kNPOS) {
709 split->Add(new TObjString(TString(str(prevStart, pos - prevStart))));
710 split->Add(new TObjString(TString(str(pos, 1))));
711 prevStart = pos + 1;
712 }
713 }
714 split->Add(new TObjString(TString(str(prevStart, str.Length() - prevStart))));
715 }
716 }
717
718 latexLines.push_back(TLatexLine(split));
719 if (numColumns < (UInt_t)split->GetEntries())
720 numColumns = split->GetEntries();
721
722 Float_t heightLine = -1.;
723 for (UInt_t col = 0; col < (UInt_t)split->GetEntries(); ++col) {
724 Float_t widthLatex = 0.;
725 Float_t heightLatex = 0.;
726 TString* strCol = latexLines.back()[col];
727 if (strCol)
728 GetBoundingBox(latex, *strCol, widthLatex, heightLatex);
729 if (heightLine < heightLatex) heightLine = heightLatex;
730 if (maxWidth.size() < col)
731 maxWidth.resize(col * 2);
732 if (maxWidth[col] < widthLatex)
733 maxWidth[col] = widthLatex;
734 latexLines.back().Width(col) = widthLatex;
735 }
736 latexLines.back().Height() = heightLine;
737 totalHeight += heightLine + gLinePadding;
738 } // while next line
739
740 std::vector<Float_t> posX(numColumns + 1);
741 for (UInt_t col = 0; col <= numColumns; ++col) {
742 if (col == 0) posX[col] = gColumnPadding;
743 else posX[col] = posX[col - 1] + maxWidth[col - 1] + gColumnPadding;
744 }
745 Float_t totalWidth = posX[numColumns];
746
747 // draw
748 fBBCanvas->Clear();
749 fBBCanvas->cd();
750 Float_t padSizeX = totalWidth;
751 Float_t padSizeY = totalHeight + 8.;
752 // add magic batch vs. gui canvas sizes (4, 28) + rounding
753 TVirtualPad* padImg = (TVirtualPad*)gROOT->ProcessLineFast(
754 Form("new TCanvas(\"R__TDocLatexDirective_padImg\",\"padImg\",-(Int_t)%g,(Int_t)%g);",
755 padSizeX + 4.5, padSizeY + 28.5));
756 padImg->SetBorderMode(0);
757 padImg->SetFillColor(kWhite);
758 padImg->cd();
759
760 Float_t posY = 0.;
761 for (std::list<TLatexLine>::iterator iLine = latexLines.begin();
762 iLine != latexLines.end(); ++iLine) {
763 posY += iLine->Height()/2. + gLinePadding;
764 for (UInt_t iCol = 0; iCol < iLine->Size(); ++iCol) {
765 TString* str = (*iLine)[iCol];
766 if (!str) continue;
767 char align = 'l';
768 if ((UInt_t)fAlignment.Length() > iCol)
769 align = fAlignment[(Int_t)iCol];
770 Float_t x = posX[iCol];
771 switch (align) {
772 case 'l': break;
773 case 'r': x += maxWidth[iCol] - iLine->Width(iCol); break;
774 case 'c': x += 0.5*(maxWidth[iCol] - iLine->Width(iCol)); break;
775 default:
776 if (iLine == latexLines.begin())
777 Error("CreateLatex", "Invalid alignment character '%c'!", align);
778 }
779 latex.DrawLatex( x / padSizeX, 1. - posY / padSizeY, str->Data());
780 }
781 posY += iLine->Height()/2.;
782 }
783
784 padImg->Print(filename);
785
786 // delete the latex objects
787 for (std::list<TLatexLine>::iterator iLine = latexLines.begin();
788 iLine != latexLines.end(); ++iLine) {
789 iLine->Delete();
790 }
791
792 delete padImg;
793
794 if (!wasBatch)
796
797 gPad = oldPad;
798}
799
800////////////////////////////////////////////////////////////////////////////////
801/// Determines the bounding box for text as height and width.
802/// Assumes that we are in batch mode.
803
805{
806 UInt_t uiWidth = 0;
807 UInt_t uiHeight = 0;
808 fBBCanvas->cd();
809 latex.SetText(0.1, 0.5, text);
810 latex.GetBoundingBox(uiWidth, uiHeight);
811
812 width = uiWidth;
813 height = uiHeight;
814}
815
816////////////////////////////////////////////////////////////////////////////////
817/// Get the list of lines as TObjStrings
818
820{
821 return fLatex ? fLatex->GetListOfLines() : 0;
822}
823
824////////////////////////////////////////////////////////////////////////////////
825/// convert fLatex to a gif by creating a TLatex, drawing it on a
826/// temporary canvas, and saving that to a filename in the output
827/// directory.
828
830{
831 TString filename;
832 GetName(filename);
833 filename.ReplaceAll(" ", "_");
834 const TString& firstLine = ((TObjString*)fLatex->GetListOfLines()->First())->String();
835 TString latexFilename(firstLine);
836 for (Ssiz_t namepos = 0; namepos < latexFilename.Length(); ++namepos)
837 if (!GetDocParser()->IsWord(latexFilename[namepos])) {
838 latexFilename.Remove(namepos, 1);
839 --namepos;
840 }
841 filename += "_";
842 filename += latexFilename;
843
844 GetDocOutput()->NameSpace2FileName(filename);
845 filename += ".gif";
846
847 TString altText(firstLine);
849 altText.ReplaceAll("\"", "&quot;");
850 result = "<span class=\"latex\"><img class=\"latex\" alt=\"";
851 result += altText;
852 result += "\" title=\"LATEX\" src=\"";
853 result += filename;
854 result += "\" /></span>";
855
857
858 if (gDebug > 3)
859 Info("HandleDirective_Latex", "Writing Latex \"%s\" to file %s.",
860 fLatex->GetName(), filename.Data());
861
862 CreateLatex(filename);
863
864 return kTRUE;
865}
866
867////////////////////////////////////////////////////////////////////////////////
868/// Parse fParameters, setting fFontSize, fAlignment, and fSeparator
869
870void TDocLatexDirective::AddParameter(const TString& name, const char* value /*=0*/)
871{
872 if (!name.CompareTo("fontsize", TString::kIgnoreCase)) {
873 if (!value || !value[0])
874 Error("AddParameter", "Option \"fontsize\" needs a value!");
875 else fFontSize = atol(value);
876 } else if (!name.CompareTo("separator", TString::kIgnoreCase)) {
877 if (!value || !value[0])
878 Error("AddParameter", "Option \"separator\" needs a value!");
879 else fSeparator = value;
880 } else if (!name.CompareTo("align", TString::kIgnoreCase)) {
881 if (!value || !value[0])
882 Error("AddParameter", "Option \"align\" needs a value!");
883 else fAlignment = value;
884 } else
885 Warning("AddParameter", "Unknown option %s!", name.Data());
886}
const Ssiz_t kNPOS
Definition RtypesCore.h:115
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:92
long Long_t
Definition RtypesCore.h:54
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
@ kWhite
Definition Rtypes.h:65
include TDocParser_001 C image html pict1_TDocParser_001 png width
XFontStruct * id
Definition TGX11.cxx:109
char name[80]
Definition TGX11.cxx:110
Int_t gDebug
Definition TROOT.cxx:590
#define gROOT
Definition TROOT.h:406
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#define R__LOCKGUARD(mutex)
#define gPad
#define gVirtualX
Definition TVirtualX.h:338
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:41
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:45
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:46
virtual Int_t GetEntries() const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
TDocParser * fDocParser
TDocOutput * fDocOutput
virtual void AddParameter(const TString &, const char *=0)
TDocParser * GetDocParser() const
const char * GetName() const
Returns name of object.
virtual void DeleteOutputFiles(const char *ext) const
Delete all output generated by the directive beginning with Name() and ending with ext.
THtml * GetHtml() const
TString fParameters
void SetParameters(const char *params)
Given a string containing parameters in params, we call AddParameter() for each of them.
TDocOutput * GetDocOutput() const
void SetParser(TDocParser *parser)
Set the parser, and fDocOutput, fHtml from that.
friend class TDocParser
const char * GetOutputDir() const
Get the directory for documentation output.
virtual void AddLine(const TSubString &line)
Add a line of HTML.
virtual Bool_t GetResult(TString &result)
Set result to the HTML code that was passed in via AddLine().
virtual void CreateLatex(const char *filename)
Create a gif file named filename from a latex expression in fLatex.
virtual ~TDocLatexDirective()
Destructor.
virtual void AddLine(const TSubString &line)
Add a latex line.
TList * GetListOfLines() const
Get the list of lines as TObjStrings.
virtual Bool_t GetResult(TString &result)
convert fLatex to a gif by creating a TLatex, drawing it on a temporary canvas, and saving that to a ...
virtual void AddParameter(const TString &name, const char *value=0)
Parse fParameters, setting fFontSize, fAlignment, and fSeparator.
virtual void GetBoundingBox(TLatex &latex, const char *text, Float_t &width, Float_t &height)
Determines the bounding box for text as height and width.
TVirtualPad * fBBCanvas
virtual Bool_t GetResult(TString &result)
Get the result (i.e.
virtual void AddLine(const TSubString &line)
Add a macro line.
virtual ~TDocMacroDirective()
Destructor.
TString CreateSubprocessInputFile()
Create the input file for SubProcess().
virtual void AddParameter(const TString &name, const char *value=0)
Setting fNeedGraphics if name is "GUI", setting fShowSource if name is "SOURCE".
static void SubProcess(const TString &what, const TString &out)
virtual void NameSpace2FileName(TString &name)
Replace "::" in name by "__" Replace "<", ">", " ", ",", "~", "=" in name by "_" Replace "A::X<A::Y>"...
virtual const char * ReplaceSpecialChars(char c)
Replace ampersand, less-than and greater-than character, writing to out.
THtml * GetHtml()
Definition TDocOutput.h:90
static Bool_t Strip(TString &s)
strips ' ', tabs, and newlines from both sides of str
void GetCurrentModule(TString &out_module) const
Return the name of module for which sources are currently parsed.
void Convert(std::ostream &out, std::istream &in, const char *relpath, Bool_t isCode, Bool_t interpretDirectives)
Parse text file "in", add links etc, and write output to "out".
TDocOutput * GetDocOutput() const
Definition TDocParser.h:173
TClass * GetCurrentClass() const
Definition TDocParser.h:171
void GetModuleMacroPath(const TString &module, TString &out_path) const
Definition THtml.h:324
Bool_t IsBatch() const
Definition THtml.h:353
virtual void GetHtmlFileName(TClass *classPtr, TString &filename) const
Return real HTML filename.
Definition THtml.cxx:2001
virtual void GetModuleNameForClass(TString &module, TClass *cl) const
Return the module name for a given class.
Definition THtml.cxx:1540
const TString & GetOutputDir(Bool_t createDir=kTRUE) const
Return the output directory as set by SetOutputDir().
Definition THtml.cxx:2177
void Reset()
To draw Mathematical Formula.
Definition TLatex.h:18
void GetBoundingBox(UInt_t &w, UInt_t &h, Bool_t angle=kFALSE)
Return text size in pixels.
Definition TLatex.cxx:2553
TLatex * DrawLatex(Double_t x, Double_t y, const char *text)
Make a copy of this object with the new parameters And copy object attributes.
Definition TLatex.cxx:1927
A doubly linked list.
Definition TList.h:44
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:659
Class supporting a collection of lines with C++ code.
Definition TMacro.h:31
virtual TObjString * AddLine(const char *text)
Add line with text in the list of lines of this macro.
Definition TMacro.cxx:141
void SaveSource(FILE *fp)
Save macro source in file pointer fp.
Definition TMacro.cxx:383
TList * GetListOfLines() const
Definition TMacro.h:51
TString fName
Definition TNamed.h:32
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
An array of TObjects.
Definition TObjArray.h:37
Int_t GetEntriesFast() const
Definition TObjArray.h:64
void Add(TObject *obj)
Definition TObjArray.h:74
Int_t GetEntries() const
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const
Definition TObjArray.h:166
Collectable string class.
Definition TObjString.h:28
TString & String()
Definition TObjString.h:48
Mother of all ROOT objects.
Definition TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save this object in the file specified by filename.
Definition TObject.cxx:601
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:893
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:867
TObjArray * MatchS(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
Returns a TObjArray of matched substrings as TObjString's.
Definition TPRegexp.cxx:370
Basic string class.
Definition TString.h:136
Ssiz_t Length() const
Definition TString.h:410
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2197
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1126
const char * Data() const
Definition TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:692
@ kBoth
Definition TString.h:267
@ kIgnoreCase
Definition TString.h:268
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:912
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2217
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:615
TString & Prepend(const char *cs)
Definition TString.h:661
TString & Remove(Ssiz_t pos)
Definition TString.h:673
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:639
A zero length substring is legal.
Definition TString.h:82
TString & String()
Definition TString.h:121
Ssiz_t Start() const
Definition TString.h:120
Ssiz_t Length() const
Definition TString.h:119
const char * pwd()
Definition TSystem.h:422
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:844
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition TSystem.cxx:835
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1534
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:654
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1079
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1294
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition TSystem.cxx:852
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:933
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:438
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:417
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1030
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1379
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Definition TSystem.cxx:1480
virtual void SetText(Double_t x, Double_t y, const char *text)
Definition TText.h:74
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual void SetBatch(Bool_t batch=kTRUE)=0
void Print(const char *filename="") const override=0
This method must be overridden when a class wants to print itself.
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual void SetBorderMode(Short_t bordermode)=0
void Clear(Option_t *option="") override=0
TText * text
TLine * line
Double_t x[n]
Definition legend1.C:17
const char * String
Definition TXMLSetup.cxx:94
const char * Size
Definition TXMLSetup.cxx:56
static const char * what
Definition stlLoader.cc:6