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
3 changes: 3 additions & 0 deletions core/base/inc/TVirtualPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class TVirtualPS : public TNamed, public TAttLine, public TAttFill, public TAttM
char *fBuffer{nullptr}; // File buffer
const char *fImplicitCREsc{nullptr}; // Escape symbol before enforced new line

Bool_t OpenStream(const char *fname, Bool_t binary = kFALSE);
void CloseStream();

public:
TVirtualPS();
TVirtualPS(const char *filename, Int_t type=-111);
Expand Down
39 changes: 38 additions & 1 deletion core/base/src/TVirtualPS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,46 @@ TVirtualPS::TVirtualPS(const char *name, Int_t)

TVirtualPS::~TVirtualPS()
{
if (fBuffer) delete [] fBuffer;
if (fBuffer)
delete [] fBuffer;
}

////////////////////////////////////////////////////////////////////////////////
/// Open output stream

Bool_t TVirtualPS::OpenStream(const char *fname, Bool_t binary)
{
CloseStream();

auto flags = std::ofstream::out;
#ifdef R__WIN32
if (binary)
flags = flags | std::ofstream::binary;
#else
(void) binary;
#endif

fStream = new std::ofstream(fname, flags);
if (!fStream || !fStream->good()) {
delete fStream;
fStream = nullptr;
return kFALSE;
}

return kTRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// Close existing stream

void TVirtualPS::CloseStream()
{
if (fStream) {
fStream->close();
delete fStream;
fStream = nullptr;
}
}

////////////////////////////////////////////////////////////////////////////////
/// Output the string str in the output buffer
Expand Down
3 changes: 2 additions & 1 deletion graf2d/asimage/inc/TASImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TASImage : public TImage {
inline Int_t Idx(Int_t idx);
void FillRectangleInternal(UInt_t col, Int_t x, Int_t y, UInt_t width, UInt_t height);
void DrawTextTTF(Int_t x, Int_t y, const char *text, Int_t size, UInt_t color, const char *font_name, Float_t angle);
void DrawGlyph(void *bitmap, UInt_t color, Int_t x, Int_t y);
void DrawGlyph(void *bitmap, UInt_t color, Int_t x, Int_t y, TVirtualPad *clippad = nullptr, Int_t offx = 0, Int_t offy = 0);
void SetDefaults();
void CreateThumbnail();
void DestroyImage();
Expand Down Expand Up @@ -138,6 +138,7 @@ class TASImage : public TImage {
const char *color = nullptr, const char *font = "fixed", EText3DType type = TImage::kPlain,
const char *fore_file = nullptr, Float_t angle = 0) override;
void DrawText(TText *text, Int_t x = 0, Int_t y = 0) override;
void DrawTextOnPad(TText *text, Int_t x = 0, Int_t y = 0, TVirtualPad *pad = nullptr, Int_t offx = 0, Int_t offy = 0) override;

// Vector graphics
void BeginPaint(Bool_t fast = kTRUE) override;
Expand Down
57 changes: 35 additions & 22 deletions graf2d/asimage/src/TASImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5616,11 +5616,8 @@ void TASImage::DrawWideLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2,
////////////////////////////////////////////////////////////////////////////////
/// Draw glyph bitmap.

void TASImage::DrawGlyph(void *bitmap, UInt_t color, Int_t bx, Int_t by)
void TASImage::DrawGlyph(void *bitmap, UInt_t color, Int_t bx, Int_t by, TVirtualPad *clippad, Int_t offx, Int_t offy)
{
if (!InitImage("DrawGlyph")) {
return;
}
static UInt_t col[5];
Int_t x, y, yy, y0, xx;
Bool_t has_alpha = (color & 0xff000000) != 0xff000000;
Expand Down Expand Up @@ -5674,15 +5671,15 @@ void TASImage::DrawGlyph(void *bitmap, UInt_t color, Int_t bx, Int_t by)
yy = y0;
ARGB32 acolor;

Int_t clipx1=0, clipx2=0, clipy1=0, clipy2=0;
Int_t clipx1 = 0, clipx2 = 0, clipy1 = 0, clipy2 = 0;
Bool_t noClip = kTRUE;

if (gPad) {
if (clippad) {
Float_t is = gStyle->GetImageScaling();
clipx1 = gPad->XtoAbsPixel(gPad->GetX1())*is;
clipx2 = gPad->XtoAbsPixel(gPad->GetX2())*is;
clipy1 = gPad->YtoAbsPixel(gPad->GetY1())*is;
clipy2 = gPad->YtoAbsPixel(gPad->GetY2())*is;
clipx1 = clippad->XtoAbsPixel(clippad->GetX1())*is - offx;
clipx2 = clippad->XtoAbsPixel(clippad->GetX2())*is - offx;
clipy1 = clippad->YtoAbsPixel(clippad->GetY1())*is - offy;
clipy2 = clippad->YtoAbsPixel(clippad->GetY2())*is - offy;
noClip = kFALSE;
}

Expand Down Expand Up @@ -5719,27 +5716,38 @@ void TASImage::DrawGlyph(void *bitmap, UInt_t color, Int_t bx, Int_t by)

void TASImage::DrawText(TText *text, Int_t x, Int_t y)
{
if (!text) return;
if (!gPad)
if (gPad)
DrawTextOnPad(text, x, y, gPad, 0, 0);
}


////////////////////////////////////////////////////////////////////////////////
/// Draw text at the pixel position (x,y) checking clip on pad.

void TASImage::DrawTextOnPad(TText *text, Int_t x, Int_t y, TVirtualPad *pad, Int_t offx, Int_t offy)
{
if (!text)
return;
if (!InitImage("DrawText")) {
if (!InitImage("DrawTextOnPad"))
return;
}

if (!TTF::IsInitialized()) TTF::Init();
TTF::Init();

// set text font
TTF::SetTextFont(text->GetTextFont());

Int_t wh = gPad->XtoPixel(gPad->GetX2());
Int_t hh = gPad->YtoPixel(gPad->GetY1());
Int_t wh = 100, hh = 100;
if (pad) {
wh = pad->XtoPixel(pad->GetX2());
hh = pad->YtoPixel(pad->GetY1());
}

// set text size
Float_t ttfsize;
if (wh < hh) {
ttfsize = text->GetTextSize()*wh;
ttfsize = text->GetTextSize() * wh;
} else {
ttfsize = text->GetTextSize()*hh;
ttfsize = text->GetTextSize() * hh;
}
TTF::SetTextSize(ttfsize*kScale);

Expand Down Expand Up @@ -5847,8 +5855,10 @@ void TASImage::DrawText(TText *text, Int_t x, Int_t y)
Int_t bx = x - ftal.x + bitmap->left;
Int_t by = y + ftal.y - bitmap->top;

DrawGlyph(source, color, bx, by);
DrawGlyph(source, color, bx, by, pad, offx, offy);
}

TTF::CleanupGlyphs();
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -5857,7 +5867,10 @@ void TASImage::DrawText(TText *text, Int_t x, Int_t y)
void TASImage::DrawTextTTF(Int_t x, Int_t y, const char *text, Int_t size,
UInt_t color, const char *font_name, Float_t angle)
{
if (!TTF::IsInitialized()) TTF::Init();
if (!InitImage("DrawTextTTF"))
return;

TTF::Init();

TTF::SetTextFont(font_name);
TTF::SetTextSize(size);
Expand Down Expand Up @@ -6749,5 +6762,5 @@ Bool_t TASImage::SetJpegDpi(const char *name, UInt_t set)
Int_t TASImage::Idx(Int_t idx)
{
// The size of arrays like fImage->alt.argb32 is fImage->width*fImage->height
return TMath::Min(idx,(Int_t)(fImage->width*fImage->height));
return TMath::Max(0, TMath::Min(idx,(Int_t)(fImage->width*fImage->height)));
}
10 changes: 5 additions & 5 deletions graf2d/cocoa/src/TGQuartz.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ void ConvertPointsROOTToCocoa(Int_t nPoints, const TPoint *xy, std::vector<TPoin
{
//Default ctor.


if (!TTF::IsInitialized())
TTF::Init();
TTF::Init();

//I do not know why TTF::Init returns void and I have to check IsInitialized() again.
if (!TTF::IsInitialized())
Expand All @@ -100,8 +98,8 @@ void ConvertPointsROOTToCocoa(Int_t nPoints, const TPoint *xy, std::vector<TPoin
fUseAA(true), fUseFAAA(false)
{
//Constructor.
if (!TTF::IsInitialized())
TTF::Init();

TTF::Init();

//I do not know why TTF::Init returns void and I have to check IsInitialized() again.
if (!TTF::IsInitialized())
Expand Down Expand Up @@ -535,6 +533,8 @@ void ConvertPointsROOTToCocoa(Int_t nPoints, const TPoint *xy, std::vector<TPoin

AlignTTFString(wctxt);
RenderTTFString(wctxt, x, y, mode);

TTF::CleanupGlyphs();
}

//______________________________________________________________________________
Expand Down
1 change: 1 addition & 0 deletions graf2d/graf/inc/TImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ friend TImage operator/(const TImage &i1, const TImage &s2);
const char * /*color*/ = nullptr, const char * /*font*/ = "fixed",
EText3DType /*type*/ = TImage::kPlain, const char * /*fore_file*/ = nullptr, Float_t /*angle*/ = 0) { }
virtual void DrawText(TText * /*text*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0) { }
virtual void DrawTextOnPad(TText * /*text*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0, TVirtualPad * /* pad */ = nullptr, Int_t /* offx */ = 0, Int_t /* offy */ = 0);
virtual void FillPolygon(UInt_t /*npt*/, TPoint * /*ppt*/, const char * /*col*/ = "#000000",
const char * /*stipple*/ = nullptr, UInt_t /*w*/ = 16, UInt_t /*h*/ = 16) {}
virtual void FillPolygon(UInt_t /*npt*/, TPoint * /*ppt*/, TImage * /*tile*/) {}
Expand Down
1 change: 1 addition & 0 deletions graf2d/graf/inc/TTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ TTF helper class containing glyphs description.
static void PrepareString(const char *string);
static void PrepareString(const wchar_t *string);
static void SetRotationMatrix(Float_t angle);
static void CleanupGlyphs();

public:
TTF() { }
Expand Down
11 changes: 11 additions & 0 deletions graf2d/graf/src/TImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,16 @@ TImage *TImage::Open(char **data)
}


////////////////////////////////////////////////////////////////////////////////
/// Draw text on specified pad, check pad clipping rules

void TImage::DrawTextOnPad(TText *text, Int_t x, Int_t y, TVirtualPad *, Int_t, Int_t)
{
// call simple DrawText to ensure minimal backward compatibility

DrawText(text, x, y);
}


TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }
45 changes: 39 additions & 6 deletions graf2d/graf/src/TTF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ TTF::~TTF()

void TTF::Init()
{
if (fgInit)
return;

fgInit = kTRUE;

// initialize FTF library
Expand All @@ -80,13 +83,21 @@ void TTF::Init()

void TTF::Cleanup()
{
if (!fgInit) return;
if (!fgInit)
return;

CleanupGlyphs();

for (int i = 0; i < fgFontCount; i++) {
delete [] fgFontName[i];
fgFontName[i] = nullptr;

FT_Done_Face(fgFace[i]);
}
if (fgRotMatrix) delete fgRotMatrix;
if (fgRotMatrix) {
delete fgRotMatrix;
fgRotMatrix = nullptr;
}
FT_Done_FreeType(fgLibrary);

fgInit = kFALSE;
Expand Down Expand Up @@ -152,7 +163,7 @@ void TTF::ComputeTrailingBlanksWidth(Int_t n)

void TTF::GetTextExtent(UInt_t &w, UInt_t &h, char *text)
{
if (!fgInit) Init();
Init();

SetRotationMatrix(0);
PrepareString(text);
Expand All @@ -161,27 +172,29 @@ void TTF::GetTextExtent(UInt_t &w, UInt_t &h, char *text)
Int_t Yoff = 0; if (fgCBox.yMin < 0) Yoff = -fgCBox.yMin;
w = fgCBox.xMax + Xoff + GetTrailingBlanksWidth();
h = fgCBox.yMax + Yoff;
CleanupGlyphs();
}

////////////////////////////////////////////////////////////////////////////////
/// Get advance (a) when text is horizontal.

void TTF::GetTextAdvance(UInt_t &a, char *text)
{
if (!fgInit) Init();
Init();

SetRotationMatrix(0);
PrepareString(text);
LayoutGlyphs();
a = GetWidth()>>6;
a = GetWidth() >> 6;
CleanupGlyphs();
}

////////////////////////////////////////////////////////////////////////////////
/// Get width (w) and height (h) when text is horizontal.

void TTF::GetTextExtent(UInt_t &w, UInt_t &h, wchar_t *text)
{
if (!fgInit) Init();
Init();

SetRotationMatrix(0);
PrepareString(text);
Expand All @@ -190,6 +203,7 @@ void TTF::GetTextExtent(UInt_t &w, UInt_t &h, wchar_t *text)
Int_t Yoff = 0; if (fgCBox.yMin < 0) Yoff = -fgCBox.yMin;
w = fgCBox.xMax + Xoff + GetTrailingBlanksWidth();
h = fgCBox.yMax + Yoff;
CleanupGlyphs();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -265,6 +279,25 @@ void TTF::LayoutGlyphs()
}
}

////////////////////////////////////////////////////////////////////////////////
/// Remove temporary data created by LayoutGlyphs

void TTF::CleanupGlyphs()
{
TTGlyph* glyph = fgGlyphs;

for (int n = 0; n < fgNumGlyphs; n++, glyph++) {
// clear existing image if there is one
if (glyph->fImage) {
FT_Done_Glyph(glyph->fImage);
glyph->fImage = nullptr;
}
}

fgNumGlyphs = 0;
}


////////////////////////////////////////////////////////////////////////////////
/// Put the characters in "string" in the "glyphs" array.

Expand Down
10 changes: 10 additions & 0 deletions graf2d/postscript/inc/TImageDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class TImageDump : public TVirtualPS {
protected:
TImage *fImage{nullptr}; ///< Image
Int_t fType{0}; ///< PostScript workstation type
Int_t fX0{0}, fY0{0}; ///< offset of selected pad to canvas

std::vector<UInt_t> fCellArrayColors;
Int_t fCellArrayW{0};
Int_t fCellArrayH{0};
Int_t fCellArrayX1{0};
Int_t fCellArrayX2{0};
Int_t fCellArrayY1{0};
Int_t fCellArrayY2{0};
UInt_t fCellArrayIdx{0};

Int_t XtoPixel(Double_t x);
Int_t YtoPixel(Double_t y);
Expand Down
Loading
Loading