21#include <Cocoa/Cocoa.h>
24# include FT_FREETYPE_H
59void ConvertPointsROOTToCocoa(
Int_t nPoints,
const TPoint *xy, std::vector<TPoint> &dst,
62 assert(nPoints != 0 &&
"ConvertPointsROOTToCocoa, nPoints parameter is 0");
63 assert(xy != 0 &&
"ConvertPointsROOTToCocoa, xy parameter is null");
64 assert(drawable != 0 &&
"ConvertPointsROOTToCocoa, drawable parameter is null");
66 const auto scaleFactor = drawable.fScaleFactor;
69 for (
Int_t i = 0; i < nPoints; ++i) {
70 dst[i].fX =
SCoord_t(xy[i].fX * scaleFactor);
83 Error(
"TGQuartz",
"TTFhandle::Init() failed");
96 Error(
"TGQuartz",
"TTFhandle::Init() failed");
109 if ([drawable0 isDirectDraw]) {
110 if (!drawable0.fIsPixmap) {
113 ::Warning(
"DrawBoxW",
"Invalid view/window for XOR-mode");
142 polygon[0].
fX = x1, polygon[0].
fY = y1;
143 polygon[1].
fX = x2, polygon[1].
fY = y1;
144 polygon[2].
fX = x2, polygon[2].
fY = y2;
145 polygon[3].
fX = x1, polygon[3].
fY = y2;
150 const bool isHollow = mode ==
kHollow || attfill.GetFillStyle() / 1000 == 2;
154 unsigned patternIndex = 0;
157 Error(
"DrawBoxW",
"Can not find color for index %d",
int(attline.GetLineColor()));
162 Error(
"DrawBoxW",
"SetFillAreaParameters failed");
195 if ([drawable0 isDirectDraw])
213 if (drawable.fScaleFactor > 1.) {
215 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
218 const TColor *
const fillColor =
gROOT->GetColor(attfill.GetFillColor());
220 Error(
"DrawFillAreaW",
"Could not find TColor for index %d", attfill.GetFillColor());
228 unsigned patternIndex = 0;
230 Error(
"DrawFillAreaW",
"SetFillAreaParameters failed");
262 if ([drawable0 isDirectDraw]) {
263 if (!drawable0.fIsPixmap) {
266 ::Warning(
"DrawLineW",
"Invalid view/window for XOR-mode");
288 Error(
"DrawLineW",
"Could not set line color for index %d",
int(attline.GetLineColor()));
320 if ([drawable0 isDirectDraw])
335 Error(
"DrawPolyLineW",
"Could not find TColor for index %d", attline.GetLineColor());
345 if (drawable.fScaleFactor > 1.)
346 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
370 for(
Int_t i = 0; i < 2*
n; i += 2)
382 if ([drawable0 isDirectDraw])
397 Error(
"DrawPolyMarker",
"Could not find TColor for index %d", attmark.GetMarkerColor());
407 if (drawable.fScaleFactor > 1.)
408 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
413 if (markerstyle == 1 || markerstyle == 6 || markerstyle == 7) {
414 CGContextSetLineJoin(ctx, kCGLineJoinMiter);
415 CGContextSetLineCap(ctx, kCGLineCapButt);
417 CGContextSetLineJoin(ctx, kCGLineJoinRound);
418 CGContextSetLineCap(ctx, kCGLineCapRound);
424 CGContextSetLineJoin(ctx, kCGLineJoinMiter);
425 CGContextSetLineCap(ctx, kCGLineCapButt);
450 std::vector<UniChar> unichars(std::strlen(
text));
451 for (std::size_t i = 0; i < unichars.size(); ++i)
452 unichars[i] = 0xF000 + (
unsigned char)
text[i];
464 if ([drawable0 isDirectDraw])
472 if (atttext.GetTextSize() < 1.5)
483 CGContextSetTextMatrix(ctx, CGAffineTransformIdentity);
486 if (CTFontRef currentFont =
fPimpl->fFontManager.SelectFont(atttext.GetTextFont(),
kScale * atttext.GetTextSize())) {
487 const unsigned fontIndex = atttext.GetTextFont() / 10;
488 if (fontIndex == 12 || fontIndex == 15) {
498 }
catch (
const std::exception &
e) {
499 Error(
"DrawTextW",
"Exception from Quartz::TextLine: %s",
e.what());
518 Error(
"DrawTextW",
"wchar_t string to draw, but TTF initialization failed");
526 if ([drawable0 isDirectDraw])
537 if (att.GetTextSize() < 1.5)
550 Int_t txalh = att.GetTextAlign() / 10;
551 Int_t txalv = att.GetTextAlign() % 10;
552 FT_Vector align_vect;
573 align_vect.x = align_vect.x >> 6;
574 align_vect.y = align_vect.y >> 6;
582 else if ([drawable isKindOfClass : [
QuartzView class]] || [drawable isKindOfClass : [
QuartzWindow class]])
587 Error(
"DrawTextW",
"fSelectedDrawable is neither QuartzPixmap nor a double buffered window");
600 if (w <= 0 ||
h <= 0)
603 const Int_t x1 =
x - xOff - align_vect.x;
604 const Int_t y1 =
y + yOff + align_vect.y -
h;
606 UInt_t width = 0, height = 0;
618 Error(
"DrawTextW",
"pixmap creation failed");
622 const unsigned char defaultBackgroundPixel[] = {255, 255, 255, 255};
632 arrayGuard.
Reset([dstPixmap readColorBits : bbox]);
634 if (!arrayGuard.
Get()) {
635 Error(
"DrawTextW",
"problem with reading background pixels");
640 const Int_t xo = x1 < 0 ? -x1 : 0;
641 const Int_t yo = y1 < 0 ? -y1 : 0;
643 for (
int yp = 0; yp <
int(bbox.fHeight) && yo + yp <
h; ++yp) {
644 const unsigned char *srcBase = arrayGuard.
Get() + bbox.fWidth * yp * 4;
645 for (
int xp = 0; xp <
int(bbox.fWidth) && xo + xp < w; ++xp) {
646 const unsigned char *
const pixel = srcBase + xp * 4;
647 [pixmap.
Get() putPixel : pixel
X : xo + xp Y : yo + yp];
652 [pixmap.
Get() addPixel : defaultBackgroundPixel];
658 CGContextSetRGBStrokeColor(ctx, 0., 0., 1., 1.);
662 const Int_t bx = bitmap->left + xOff;
663 const Int_t by =
h - bitmap->top - yOff;
672 [dstPixmap copy : pixmap.
Get() area : copyArea withMask : nil clipOrigin :
X11::Point() toPoint : dstPoint];
700 if (fontIndex == 12 || fontIndex == 15) {
703 fPimpl->fFontManager.GetTextBounds(fontref, w,
h, unichars);
705 fPimpl->fFontManager.GetTextBounds(fontref, w,
h,
text);
721 const unsigned fontIndex = font / 10;
722 if (fontIndex == 12 || fontIndex == 15) {
725 fPimpl->fFontManager.GetTextBounds(fontref, w,
h, unichars);
727 fPimpl->fFontManager.GetTextBounds(fontref, w,
h,
text);
749 return Int_t(
fPimpl->fFontManager.GetAscent(fontref));
767 if (fontIndex == 12 || fontIndex == 15) {
770 return Int_t(
fPimpl->fFontManager.GetAscent(fontref, unichars));
785 return Int_t(
fPimpl->fFontManager.GetDescent(fontref));
803 if (fontIndex == 12 || fontIndex == 15) {
806 return Int_t(
fPimpl->fFontManager.GetDescent(fontref, unichars));
823 const unsigned fontIndex = font / 10;
825 a =
fPimpl->fFontManager.GetAscent(fontref);
826 d =
fPimpl->fFontManager.GetDescent(fontref);
827 }
else if (fontIndex == 12 || fontIndex == 15) {
830 a =
fPimpl->fFontManager.GetAscent(fontref, unichars);
831 d =
fPimpl->fFontManager.GetDescent(fontref, unichars);
834 d =
fPimpl->fFontManager.GetDescent(fontref,
text);
967 Error(
"SetTextFont",
"Direct TTF font setting not supported");
1053 auto source = (FT_Bitmap *) _source;
1054 assert(pixmap != nil &&
"DrawFTGlyph, pixmap parameter is nil");
1055 assert(source != nil &&
"DrawFTGlyph, source parameter is null");
1069 for (
unsigned y = 0;
y < source->rows;
y++) {
1070 for (
unsigned x = 0;
x < source->width;
x++) {
1071 if (
x + bx < pixmap.fWidth &&
y + by < pixmap.fHeight) {
1072 const unsigned char *
const pixels = pixmap.fData + (
y + by) * pixmap.fWidth * 4 + (
x + bx) * 4;
1073 r +=
UShort_t(pixels[0] / 255. * 0xffff);
1074 g +=
UShort_t(pixels[1] / 255. * 0xffff);
1075 b +=
UShort_t(pixels[2] / 255. * 0xffff);
1076 if (++dotCnt >= maxDots)
1102 for (
int x = 3;
x > 0; --
x) {
1111 const unsigned char *s = source->buffer;
1112 for (
unsigned y = 0;
y < source->rows; ++
y) {
1113 for (
unsigned x = 0;
x < source->width; ++
x) {
1114 unsigned char d = (((*s++ & 0xff) + 10) * 5) / 256;
1119 UChar_t(
double(col[
d].fGreen) / 0xffff * 255),
1120 UChar_t(
double(col[
d].fBlue) / 0xffff * 255), 255};
1121 [pixmap putPixel : pixel
X : bx +
x Y : by +
y];
1127 unsigned char rgba[4] = {};
1130 unsigned char d = 0;
1132 const unsigned char *row = source->buffer;
1133 for (
unsigned y = 0;
y < source->rows; ++
y) {
1135 const unsigned char *s = row;
1136 for (
unsigned x = 0;
x < source->width; ++
x) {
1141 [pixmap putPixel : rgba
X : bx +
x Y : by +
y];
1147 row += source->pitch;
1159 if (value ==
"auto") {
1160 [[NSScreen mainScreen] backingScaleFactor] > 1. ?
fUseAA = true :
fUseAA =
false;
1161 }
else if (value ==
"no")
1164 assert(value ==
"yes" &&
"SetAA, value must be 'yes', 'no' or 'auto'");
1168 if (valuefa ==
"auto") {
1169 [[NSScreen mainScreen] backingScaleFactor] > 1. ?
fUseFAAA = true :
fUseFAAA =
false;
1170 }
else if (valuefa ==
"no")
1173 assert(valuefa ==
"yes" &&
"SetAA, value must be 'yes', 'no' or 'auto'");
1184 if (!drawable || !drawable.attFill)
1186 return *drawable.attFill;
1194 if (!drawable || !drawable.attLine)
1196 return *drawable.attLine;
1204 if (!drawable || !drawable.attMarker)
1206 return *drawable.attMarker;
1214 if (!drawable || !drawable.attText)
1216 return *drawable.attText;
1222 assert(calledFrom != 0 &&
"GetDrawableChecked, calledFrom parameter is null");
1228 if (!drawable.fIsPixmap) {
1230 if ([drawable isKindOfClass : [
QuartzView class]]) {
1233 Error(calledFrom,
"Selected window is not double buffered");
1239 Error(calledFrom,
"Selected drawable is neither a pixmap, nor a double buffered window");
1244 if (!drawable.fContext) {
1245 Error(calledFrom,
"Context is null");
Handle_t WinContext_t
Window drawing context.
Handle_t Drawable_t
Drawable handle.
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short).
int Int_t
Signed integer 4 bytes (int).
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
constexpr ULong_t kBitsPerByte
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
short Width_t
Line width (short).
bool Bool_t
Boolean (0=false, 1=true) (bool).
short Font_t
Font number (short).
short Short_t
Signed Short integer 2 bytes (short).
double Double_t
Double 8 bytes.
short SCoord_t
Screen coordinates (short).
short Color_t
Color number (short).
short Style_t
Style number (short).
float Float_t
Float 4 bytes (float).
std::vector< UniChar > quartz_get_greek_unicars(const char *text)
DerivedType * Get() const
void DrawLine(CGContextRef ctx) const
virtual Color_t GetFillColor() const
Return the fill area color.
void Copy(TAttFill &attfill) const
virtual Style_t GetFillStyle() const
Return the fill area style.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual Color_t GetLineColor() const
Return the line color.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual Width_t GetLineWidth() const
Return the line width.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual Style_t GetLineStyle() const
Return the line style.
void Copy(TAttLine &attline) const
virtual Style_t GetMarkerStyle() const
Return the marker style.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
virtual Color_t GetMarkerColor() const
Return the marker color.
virtual Size_t GetMarkerSize() const
Return the marker size.
static Style_t GetMarkerStyleBase(Style_t style)
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
void Copy(TAttMarker &attmarker) const
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
static Width_t GetMarkerLineWidth(Style_t style)
virtual Float_t GetTextSize() const
Return the text size.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual Short_t GetTextAlign() const
Return the text alignment.
virtual Font_t GetTextFont() const
Return the text font.
virtual Color_t GetTextColor() const
Return the text color.
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
virtual Float_t GetTextAngle() const
Return the text angle.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
void Copy(TAttText &atttext) const
TColorGradient extends basic TColor.
void GetWindowSize(Drawable_t wid, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h) override
Returns the location and the size of window "id".
Bool_t AllocColor(Colormap_t cmap, ColorStruct_t &color) override
Allocates a read-only colormap entry corresponding to the closest RGB value supported by the hardware...
std::unique_ptr< ROOT::MacOSX::Details::CocoaPrivate > fPimpl
!
void QueryColor(Colormap_t cmap, ColorStruct_t &color) override
Returns the current RGB value for the pixel in the "color" structure.
WinContext_t GetSelectedContext()
Drawable_t fSelectedDrawable
ULong_t GetPixel(Color_t cindex) override
Returns pixel value associated to specified ROOT color number "cindex".
void SetLineWidth(Width_t width) override
Set the line width.
TAttMarker & GetAttMarker(WinContext_t wctxt)
void SetAttLine(WinContext_t wctxt, const TAttLine &att) override
Set line attributes for specified window.
void DrawFTGlyph(void *pixmap, void *source, ULong_t fore, ULong_t back, Int_t bx, Int_t by)
void SetMarkerColor(Color_t cindex) override
Set the marker color.
void SetFillStyle(Style_t style) override
Set the fill area style.
void SetOpacity(Int_t percent) override
Sets opacity of the current window.
void SetFillColor(Color_t cindex) override
Set the fill area color.
void DrawPolyLine(Int_t n, TPoint *xy) override
Draws a line through all points in the list.
Float_t GetTextMagnitude() override
Returns the current font magnification factor.
void SetAttText(WinContext_t wctxt, const TAttText &att) override
Set text attributes for specified window.
void DrawFillArea(Int_t n, TPoint *xy) override
Fills area described by the polygon.
void DrawText(Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode) override
Draws a text string using current font.
void DrawLine(Int_t x1, Int_t y1, Int_t x2, Int_t y2) override
Draws a line.
void DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode) override
Draw text on specified window.
void SetTextColor(Color_t cindex) override
Set the text color.
Bool_t GetTextExtentA(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const char *mess) override
Returns the size of the specified character string "mess" for font and size.
void SetMarkerStyle(Style_t markerstyle) override
Set the marker style.
void DrawBox(Int_t x1, Int_t y1, Int_t x2, Int_t y2, EBoxMode mode) override
Draws a box between [x1,y1] and [x2,y2] according to the "mode".
void SetAttFill(WinContext_t wctxt, const TAttFill &att) override
Set fill attributes for specified window.
std::vector< TPoint > fConvertedPoints
void SetTextAlign(Short_t talign=11) override
Set the text alignment.
TAttText & GetAttText(WinContext_t wctxt)
void SetLineColor(Color_t cindex) override
Set the line color.
void SetTextFont(Font_t fontnumber) override
Set the text font.
void SetAttMarker(WinContext_t wctxt, const TAttMarker &att) override
Set marker attributes for specified window.
void GetTextExtent(UInt_t &w, UInt_t &h, char *text) override
Returns the size of the specified character string "mess".
Int_t GetFontAscent() const override
Returns the ascent of the current font (in pixels).
void SetMarkerSize(Float_t markersize) override
Set the marker size.
void DrawCellArray(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t nx, Int_t ny, Int_t *ic) override
Draws a cell array.
void DrawLinesSegmentsW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw line segments on specified window.
void SetTextSize(Float_t textsize) override
Set the text size.
Bool_t GetFontAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const char *mess) override
Returns ascent/descent for specified character string "mess" with font and size.
void DrawPolyMarkerW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw poly marker on specified window.
void DrawLineW(WinContext_t wctxt, Int_t x1, Int_t y1, Int_t x2, Int_t y2) override
Draw line on specified window.
void DrawPolyLineW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw poly line on specified window.
void SetLineStyle(Style_t linestyle) override
Set the line style.
TAttFill & GetAttFill(WinContext_t wctxt)
Int_t GetFontDescent() const override
Returns the descent of the current font (in pixels.
void DrawBoxW(WinContext_t wctxt, Int_t x1, Int_t y1, Int_t x2, Int_t y2, EBoxMode mode) override
Draw box on specified window.
void SetOpacityW(WinContext_t wctxt, Int_t percent) override
Set opactity for specified window.
void DrawPolyMarker(Int_t n, TPoint *xy) override
Draws "n" markers with the current attributes at position [x,y].
void * GetPixmapDrawable(void *drawable0, const char *calledFrom) const
void DrawFillAreaW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw fill area on specified window.
TAttLine & GetAttLine(WinContext_t wctxt)
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Dynamic handle to work with freetype 2 library.
Bool_t SetTextSize(Float_t textsize)
Set current text size.
void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
const FT_BBox & GetBox() const
void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
FT_BitmapGlyph GetGlyphBitmap(UInt_t n, Bool_t smooth=kFALSE)
Return bitmap for specified glyph.
UInt_t GetNumGlyphs() const
void SetTextFont(Font_t fontnumber)
Set specified font.
void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
static Bool_t GetSmoothing()
FT_Matrix * GetRotMatrix() const
static void SetSmoothing(Bool_t state)
QuartzPixmap * fBackBuffer
QuartzWindow * fQuartzWindow
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
int LocalYROOTToCocoa(NSView< X11Window > *parentView, CGFloat yROOT)
bool AdjustCropArea(const Rectangle &srcRect, Rectangle &cropArea)
void DrawPolyLine(CGContextRef ctx, Int_t n, TPoint *xy)
void DrawBox(CGContextRef ctx, Int_t x1, Int_t y1, Int_t x2, Int_t y2, bool hollow)
Bool_t SetLineColor(CGContextRef ctx, Color_t colorIndex)
Bool_t SetFillAreaParameters(CGContextRef ctx, unsigned *patternIndex, const TAttFill &attfill)
void DrawFillArea(CGContextRef ctx, Int_t n, TPoint *xy, Bool_t drawShadow, const TAttFill &attfill)
void DrawPolyMarker(CGContextRef ctx, const std::vector< TPoint > &marker, Size_t markerSize, Style_t markerStyle)
Bool_t SetFillColor(CGContextRef ctx, Color_t colorIndex)
void DrawPolygonWithGradientFill(CGContextRef ctx, const TColorGradient *extendedColor, const CGSize &sizeOfDrawable, Int_t nPoints, const TPoint *xy, Bool_t drawShadow)
void DrawLine(CGContextRef ctx, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
void SetLineWidth(CGContextRef ctx, Int_t width)
void SetLineStyle(CGContextRef ctx, Int_t lstyle)
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
ULong_t fPixel
color pixel value (index in color table)
UShort_t fRed
red component (0..65535)
UShort_t fGreen
green component (0..65535)
UShort_t fBlue
blue component (0..65535)