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
6 changes: 5 additions & 1 deletion graf2d/postscript/inc/TSVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class TSVG : public TVirtualPS {
Float_t fXsize; ///< Page size along X
Float_t fYsize; ///< Page size along Y
Int_t fType; ///< Workstation type used to know if the SVG is open
Bool_t fCompact; ///< True when the SVG header is printed
Bool_t fBoundingBox; ///< True when the SVG header is printed
Bool_t fRange; ///< True when a range has been defined
Double_t fYsizeSVG; ///< Page's Y size in SVG units
Expand All @@ -32,7 +33,7 @@ class TSVG : public TVirtualPS {

public:
TSVG();
TSVG(const char *filename, Int_t type=-113);
TSVG(const char *filename, Int_t type=-113, Bool_t compact = kFALSE);
~TSVG() override;

void CellArrayBegin(Int_t W, Int_t H, Double_t x1, Double_t x2, Double_t y1, Double_t y2) override;
Expand All @@ -49,6 +50,7 @@ class TSVG : public TVirtualPS {
void DrawPolyMarker(Int_t n, Double_t *x, Double_t *y) override;
void DrawPS(Int_t n, Float_t *xw, Float_t *yw) override;
void DrawPS(Int_t n, Double_t *xw, Double_t *yw) override;
Bool_t IsCompact() const { return fCompact; }
void Initialize();
void MovePS(Double_t x, Double_t y);
void NewPage() override;
Expand All @@ -72,6 +74,8 @@ class TSVG : public TVirtualPS {
void Text(Double_t, Double_t, const wchar_t *) override {}
void TextNDC(Double_t u, Double_t v, const char *string);
void TextNDC(Double_t, Double_t, const wchar_t *) {}
void WriteReal(Float_t r, Bool_t space=kTRUE) override;

Double_t UtoSVG(Double_t u);
Double_t VtoSVG(Double_t v);
Double_t XtoSVG(Double_t x);
Expand Down
35 changes: 32 additions & 3 deletions graf2d/postscript/src/TSVG.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <fstream>

#include "TROOT.h"
Expand All @@ -33,7 +34,6 @@
Int_t TSVG::fgLineJoin = 0;
Int_t TSVG::fgLineCap = 0;


/** \class TSVG
\ingroup PS

Expand Down Expand Up @@ -81,6 +81,7 @@ TSVG::TSVG() : TVirtualPS()
{
fStream = nullptr;
fType = 0;
fCompact = kFALSE;
gVirtualPS = this;
fBoundingBox = kFALSE;
fRange = kFALSE;
Expand All @@ -99,10 +100,11 @@ TSVG::TSVG() : TVirtualPS()
/// necessary to specify this parameter at creation time because it
/// has a default value (which is ignore in the SVG case).

TSVG::TSVG(const char *fname, Int_t wtype) : TVirtualPS(fname, wtype)
TSVG::TSVG(const char *fname, Int_t wtype, Bool_t compact) : TVirtualPS(fname, wtype)
{
fStream = nullptr;
SetTitle("SVG");
fCompact = compact;
Open(fname, wtype);
}

Expand Down Expand Up @@ -1512,6 +1514,9 @@ void TSVG::Initialize()
PrintStr("@");
PrintStr("</title>@");

if (fCompact)
return;

// Description
PrintStr("<desc>@");
PrintFast(22,"Creator: ROOT Version ");
Expand All @@ -1533,6 +1538,29 @@ void TSVG::Initialize()

}

////////////////////////////////////////////////////////////////////////////////
/// Write float value into output stream
/// In compact form try to store only first 2-3 significant digits

void TSVG::WriteReal(Float_t r, Bool_t space)
{
if (fCompact) {
auto a = std::abs(r);
if (a > 10)
TVirtualPS::WriteInteger(std::lround(r), space);
else if (a < 0.005)
TVirtualPS::WriteReal(r, space);
else {
char str[15];
snprintf(str, 15, (a > 1) ? "%3.1f" : "%5.3f", r);
if(space)
PrintFast(1," ");
PrintStr(str);
}
} else
TVirtualPS::WriteReal(r, space);
}

////////////////////////////////////////////////////////////////////////////////
/// Move to a new position (ix, iy). The move is done in relative coordinates
/// which allows to have short numbers which decrease the size of the file.
Expand Down Expand Up @@ -1792,7 +1820,8 @@ void TSVG::Text(Double_t xx, Double_t yy, const char *chars)
Float_t ftsize;

Int_t font = abs(fTextFont)/10;
if (font > 42 || font < 1) font = 1;
if (font > 15 || font < 1)
font = 1;
if (wh < hh) {
ftsize = fTextSize*fXsize*gPad->GetAbsWNDC();
} else {
Expand Down
Loading