Skip to content

Commit 89e19ee

Browse files
committed
Introduce compact form for SVG output
In compact form <desc> and <defs> section are excluded. Also all float values rounded and stored as integer. Such rounding potentially can have side effects, but let create much smaller files.
1 parent 3f8c86e commit 89e19ee

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

graf2d/postscript/inc/TSVG.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TSVG : public TVirtualPS {
2929

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

3334
public:
3435
TSVG();
@@ -72,6 +73,11 @@ class TSVG : public TVirtualPS {
7273
void Text(Double_t, Double_t, const wchar_t *) override {}
7374
void TextNDC(Double_t u, Double_t v, const char *string);
7475
void TextNDC(Double_t, Double_t, const wchar_t *) {}
76+
void WriteReal(Float_t r, Bool_t space=kTRUE) override;
77+
78+
static void SetCompact(Bool_t on = kTRUE);
79+
static Bool_t IsCompact();
80+
7581
Double_t UtoSVG(Double_t u);
7682
Double_t VtoSVG(Double_t v);
7783
Double_t XtoSVG(Double_t x);

graf2d/postscript/src/TSVG.cxx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <cstdlib>
1717
#include <cstring>
1818
#include <cctype>
19+
#include <cmath>
1920
#include <fstream>
2021

2122
#include "TROOT.h"
@@ -32,7 +33,7 @@
3233

3334
Int_t TSVG::fgLineJoin = 0;
3435
Int_t TSVG::fgLineCap = 0;
35-
36+
Bool_t TSVG::fgCompact = kFALSE;
3637

3738
/** \class TSVG
3839
\ingroup PS
@@ -1512,6 +1513,9 @@ void TSVG::Initialize()
15121513
PrintStr("@");
15131514
PrintStr("</title>@");
15141515

1516+
if (fgCompact)
1517+
return;
1518+
15151519
// Description
15161520
PrintStr("<desc>@");
15171521
PrintFast(22,"Creator: ROOT Version ");
@@ -1533,6 +1537,18 @@ void TSVG::Initialize()
15331537

15341538
}
15351539

1540+
////////////////////////////////////////////////////////////////////////////////
1541+
/// Write real value into output stream
1542+
/// In compact form only integer value will be written
1543+
1544+
void TSVG::WriteReal(Float_t r, Bool_t space)
1545+
{
1546+
if (fgCompact)
1547+
TVirtualPS::WriteInteger(std::lround(r), space);
1548+
else
1549+
TVirtualPS::WriteReal(r, space);
1550+
}
1551+
15361552
////////////////////////////////////////////////////////////////////////////////
15371553
/// Move to a new position (ix, iy). The move is done in relative coordinates
15381554
/// which allows to have short numbers which decrease the size of the file.
@@ -2064,3 +2080,22 @@ void TSVG::DrawPS(Int_t, Float_t *, Float_t *)
20642080
{
20652081
Warning("TSVG::DrawPS", "not yet implemented");
20662082
}
2083+
2084+
////////////////////////////////////////////////////////////////////////////////
2085+
/// Set compact mode for svg output
2086+
/// If enabled - discards creation of <desc> and <defs> section in the SVG file
2087+
/// Also all float values will be rounded to nearest integer values
2088+
/// Produced SVG file potentially can have artifacts but let create much smaller SVG files
2089+
2090+
void TSVG::SetCompact(Bool_t on)
2091+
{
2092+
fgCompact = on;
2093+
}
2094+
2095+
////////////////////////////////////////////////////////////////////////////////
2096+
/// Returns compact mode for svg output
2097+
2098+
Bool_t TSVG::IsCompact()
2099+
{
2100+
return fgCompact;
2101+
}

0 commit comments

Comments
 (0)