30#include <cairomm/context.h>
31#include <cairomm/surface.h>
75 auto c =
gROOT->GetColor(
id);
77 ctx->set_source_rgba(
c->GetRed(),
c->GetGreen(),
c->GetBlue(),
c->GetAlpha());
79 ctx->set_source_rgb(0, 0, 0);
92 if (att.GetLineWidth() <= 0)
96 ctx->set_line_width(att.GetLineWidth());
98 auto style = att.GetLineStyle();
101 std::vector<double> pattern;
107 std::unique_ptr<TObjArray> tokens(patt.
Tokenize(
" "));
108 for (
Int_t j = 0; j < tokens->GetEntries(); j++) {
109 int it = std::stoi(tokens->At(j)->GetName());
110 pattern.emplace_back(0.1 * it * att.GetLineWidth());
114 if (pattern.size() > 1)
115 ctx->set_dash(pattern, 0);
145 Int_t fasi = att.GetFillStyle() % 1000;
165 auto format = Cairo::Surface::Format::A1;
166 auto stride = Cairo::ImageSurface::format_stride_for_width(
format,
width);
168 std::vector<unsigned char> padded_bytes(stride *
height, 0);
169 for (
int row = 0; row <
height; ++row) {
170 padded_bytes[row * stride] = bitmask_bytes[row * 2];
171 padded_bytes[row * stride + 1] = bitmask_bytes[row * 2 + 1];
174 auto mask_surface = Cairo::ImageSurface::create(padded_bytes.data(),
format,
width,
height, stride);
176 auto pattern = Cairo::SurfacePattern::create(mask_surface);
177 pattern->set_extend(Cairo::Pattern::Extend::REPEAT);
209 ctx->move_to(px1, py1);
210 ctx->line_to(px2, py2);
229 ctx->move_to(px1, py1);
230 ctx->line_to(px2, py2);
271 for (
Int_t n = 0;
n < nPoints; ++
n) {
272 auto px =
gPad->XtoAbsPixel(xs[
n]);
273 auto py =
gPad->YtoAbsPixel(ys[
n]);
275 ctx->move_to(px, py);
277 ctx->line_to(px, py);
295 for (
Int_t n = 0;
n < nPoints; ++
n) {
296 auto px =
gPad->XtoAbsPixel(xs[
n]);
297 auto py =
gPad->YtoAbsPixel(ys[
n]);
299 ctx->move_to(px, py);
301 ctx->line_to(px, py);
319 for (
Int_t n = 0;
n < nPoints; ++
n) {
320 auto px =
gPad->XtoAbsPixel(xs[
n]);
321 auto py =
gPad->YtoAbsPixel(ys[
n]);
323 ctx->move_to(px, py);
325 ctx->line_to(px, py);
341 for (
Int_t n = 0;
n < nPoints; ++
n) {
342 auto px =
gPad->XtoAbsPixel(xs[
n]);
343 auto py =
gPad->YtoAbsPixel(ys[
n]);
345 ctx->move_to(px, py);
347 ctx->line_to(px, py);
363 for (
Int_t n = 0;
n < nPoints; ++
n) {
364 auto px =
gPad->UtoAbsPixel(u[
n]);
365 auto py =
gPad->VtoAbsPixel(
v[
n]);
367 ctx->move_to(px, py);
369 ctx->line_to(px, py);
382 if (!ctx || nPoints < 1)
386 Int_t markerSize = 0;
387 std::vector<TPoint> markerShape;
388 auto markerType =
attr.GetMarkerShape(markerSize, markerShape);
391 ctx->set_line_width(markerLineWidth);
395 for (
Int_t n = 0;
n < nPoints; ++
n) {
402 ctx->rectangle(px + 0.5, py + 0.5, 1., 1.);
406 ctx->arc(px, py, markerSize / 2, 0.0, 2.0 *
TMath::Pi());
411 ctx->arc(px, py, markerSize / 2, 0.0, 2.0 *
TMath::Pi());
416 for (
auto &pnt : markerShape)
418 ctx->line_to(px + pnt.fX, py + pnt.fY);
420 ctx->move_to(px + pnt.fX, py + pnt.fY);
425 for (
auto &pnt : markerShape)
427 ctx->line_to(px + pnt.fX, py + pnt.fY);
429 ctx->move_to(px + pnt.fX, py + pnt.fY);
435 for (
size_t i = 0; i < markerShape.size() - 1; i += 2) {
436 ctx->move_to(px + markerShape[i].fX, py + markerShape[i].fY);
437 ctx->line_to(px + markerShape[i+1].fX, py + markerShape[i+1].fY);
438 if (i == markerShape.size() - 2)
441 ctx->stroke_preserve();
446 for (
size_t i = 0; i < markerShape.size() - 2; i += 3) {
447 ctx->move_to(px + markerShape[i].fX, py + markerShape[i].fY);
448 ctx->line_to(px + markerShape[i+1].fX, py + markerShape[i+1].fY);
449 ctx->line_to(px + markerShape[i+2].fX, py + markerShape[i+2].fY);
451 if (i == markerShape.size() - 3)
454 ctx->fill_preserve();
468 drawMarkersHelper<Double_t>(nPoints,
x,
y,
479 drawMarkersHelper<Float_t>(nPoints,
x,
y,
504 Int_t bx = 0, by = 0;
512 auto stride = Cairo::ImageSurface::format_stride_for_width(Cairo::Surface::Format::A8,
width);
513 std::vector<unsigned char>
data(stride * rows, 0);
515 for (
unsigned int row = 0; row < rows; ++row)
516 std::memcpy(
data.data() + row * stride, buffer + row * pitch,
width);
519 Cairo::ImageSurface::create(
data.data(), Cairo::Surface::Format::A8,
width, rows, stride);
521 ctx->mask(surface, px + bx, py + by);
541 int stride = Cairo::ImageSurface::format_stride_for_width(Cairo::Surface::Format::ARGB32,
width);
543 Cairo::RefPtr<Cairo::ImageSurface> surface =
544 Cairo::ImageSurface::create(argbBuffer, Cairo::Surface::Format::ARGB32,
width,
height, stride);
546 ctx->set_source(surface, px, py);
559 ::Error(
"TGtk4PadPainter::FillImageFromPad",
"Provided pad does not belong to the canvas");
565 ::Error(
"TGtk4PadPainter::FillImageFromPad",
"Canvas was not rendered yet");
569 if (cache->get_format() != Cairo::Surface::Format::ARGB32) {
570 ::Error(
"TGtk4PadPainter::FillImageFromPad",
"Wrong internal format of cached image");
574 int width = cache->get_width();
575 int height = cache->get_height();
576 int stride = cache->get_stride();
577 const uint8_t* raw_data = cache->get_data();
586 }
else if (stride ==
width * 4) {
592 std::vector<UChar_t> pixels(
w *
h * 4);
594 for (
int i = 0; i <
h; ++i) {
596 const uint8_t* row_src = raw_data + (i +
y) * stride +
x * 4;
599 auto row_dest = pixels.data() + i *
w * 4;
601 std::copy(row_src, row_src +
w * 4, row_dest);
604 image->FromBitmap(pixels.data(),
w,
h);
const unsigned char gStipples[26][32]
short Color_t
Color number (short)
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
float Float_t
Float 4 bytes (float)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t TPoint TPoint percent
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char y1
void drawMarkersHelper(Int_t nPoints, const T *x, const T *y, const TAttMarker &attr, Cairo::Context *ctx)
Helper function to paint markers.
R__EXTERN TStyle * gStyle
Cairo::Context * GetContext() const
TCanvas * GetCanvas() const
Cairo::ImageSurface * GetCache() const
void SetGtk4Color(Color_t id)
Assign color to cairo context.
void DrawImage(TImage *img, Int_t x, Int_t y, Int_t flags=0) override
Render image on drawable area.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Paint polyline in normalized coordinates.
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override
Paint Polyline.
void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY, Bool_t enableAlphaBlending) override
Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
void ApplyFillBrush()
Complete fill operation - which may include custom pattern handling.
Bool_t SetFillBrush()
Asign fill attributes before drawin shape.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint a simple line.
void DrawTTFglyphs(Int_t x, Int_t y, TTFhandle &ttf, ETextMode mode) override
Render TTF glyphs on drawable area.
Bool_t SetLinePen()
Asign pen attributes to draw line.
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override
Paint filled area.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Paint a simple line in normalized coordinates.
void SaveImage(TVirtualPad *, const char *, Int_t) const override
Produce image.
Bool_t FillImageFromPad(TImage *image, TVirtualPad *pad) const override
extract image from recent drawing
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override
Paint a simple box.
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override
Paint polymarker.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
static Width_t GetMarkerLineWidth(Style_t style)
Internal helper function that returns the line width of the given marker style (0 = filled marker)
An abstract interface to image processing library.
virtual UInt_t * GetArgbArray()
virtual UInt_t GetWidth() const
virtual UInt_t GetHeight() const
Color_t GetMarkerColor() const override
const TAttText & GetAttText() const override
Get text attributes.
const TAttMarker & GetAttMarker() const override
Get marker attributes.
const TAttFill & GetAttFill() const override
Get fill attributes.
TAttFill fAttFill
current fill attributes
Color_t GetTextColor() const override
const TAttLine & GetAttLine() const override
Get line attributes.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
const char * GetLineStyleString(Int_t i=1) const
Return line style string (used by PostScript).
Dynamic handle to work with freetype 2 library.
UInt_t GetNumGlyphs() const
return number of glyphs
Bool_t GetGlyphData(UInt_t n, Int_t &offx, Int_t &offy, UChar_t *&buffer, UInt_t &width, UInt_t &rows, UInt_t &pitch)
Returns data for glyph bitmap Instead direct access to FT_BitmapGlyph one can obtain all relevant fie...
TVirtualPad is an abstract base class for the Pad and Canvas classes.
virtual Int_t UtoAbsPixel(Double_t u) const =0
virtual UInt_t GetPadWidth() const =0
virtual UInt_t GetPadHeight() const =0
virtual Int_t VtoAbsPixel(Double_t v) const =0
virtual TCanvas * GetCanvas() const =0
Namespace for ROOT features in testing.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.