Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 0 deletions graf2d/postscript/inc/TSVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TSVG : public TVirtualPS {

static Int_t fgLineJoin; ///< Appearance of joining lines
static Int_t fgLineCap; ///< Appearance of line caps
static Bool_t fgCompact; ///< compact SVG format with integer values and no desc/defs

public:
TSVG();
Expand Down Expand Up @@ -72,6 +73,11 @@ 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;

static void SetCompact(Bool_t on = kTRUE);
static Bool_t IsCompact();

Double_t UtoSVG(Double_t u);
Double_t VtoSVG(Double_t v);
Double_t XtoSVG(Double_t x);
Expand Down
37 changes: 36 additions & 1 deletion 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 @@ -32,7 +33,7 @@

Int_t TSVG::fgLineJoin = 0;
Int_t TSVG::fgLineCap = 0;

Bool_t TSVG::fgCompact = kFALSE;

/** \class TSVG
\ingroup PS
Expand Down Expand Up @@ -1512,6 +1513,9 @@ void TSVG::Initialize()
PrintStr("@");
PrintStr("</title>@");

if (fgCompact)
return;

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

}

////////////////////////////////////////////////////////////////////////////////
/// Write real value into output stream
/// In compact form only integer value will be written

void TSVG::WriteReal(Float_t r, Bool_t space)
{
if (fgCompact)
TVirtualPS::WriteInteger(std::lround(r), space);
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 @@ -2064,3 +2080,22 @@ void TSVG::DrawPS(Int_t, Float_t *, Float_t *)
{
Warning("TSVG::DrawPS", "not yet implemented");
}

////////////////////////////////////////////////////////////////////////////////
/// Set compact mode for svg output
/// If enabled - discards creation of <desc> and <defs> section in the SVG file
/// Also all float values will be rounded to nearest integer values
/// Produced SVG file potentially can have artifacts but let create much smaller SVG files

void TSVG::SetCompact(Bool_t on)
{
fgCompact = on;
}

////////////////////////////////////////////////////////////////////////////////
/// Returns compact mode for svg output

Bool_t TSVG::IsCompact()
{
return fgCompact;
}
Loading