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) {
79 : fUseAA(true), fUseFAAA(false)
89 Error(
"TGQuartz",
"TTF::Init() failed");
101 fUseAA(true), fUseFAAA(false)
109 Error(
"TGQuartz",
"TTF::Init() failed");
126 ::Warning(
"DrawLine",
"Invalid view/window for XOR-mode");
154 polygon[0].
fX =
x1, polygon[0].
fY =
y1;
155 polygon[1].
fX =
x2, polygon[1].
fY =
y1;
156 polygon[2].
fX =
x2, polygon[2].
fY =
y2;
157 polygon[3].
fX =
x1, polygon[3].
fY =
y2;
166 unsigned patternIndex = 0;
174 Error(
"DrawBox",
"SetFillAreaParameters failed");
217 if (drawable.fScaleFactor > 1.) {
219 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
232 unsigned patternIndex = 0;
234 Error(
"DrawFillArea",
"SetFillAreaParameters failed");
262 ::Warning(
"DrawLine",
"Invalid view/window for XOR-mode");
333 if (drawable.fScaleFactor > 1.)
334 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
376 if (drawable.fScaleFactor > 1.)
377 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
383 CGContextSetLineJoin(ctx, kCGLineJoinMiter);
384 CGContextSetLineCap(ctx, kCGLineCapButt);
386 CGContextSetLineJoin(ctx, kCGLineJoinRound);
387 CGContextSetLineCap(ctx, kCGLineCapRound);
393 CGContextSetLineJoin(ctx, kCGLineJoinMiter);
394 CGContextSetLineCap(ctx, kCGLineCapButt);
420 CGContextSetTextMatrix(ctx, CGAffineTransformIdentity);
425 if (fontIndex == 12 || fontIndex == 15) {
431 typedef std::vector<UniChar>::size_type size_type;
433 std::vector<UniChar> unichars(std::strlen(
text));
434 for (size_type i = 0,
len = unichars.size(); i <
len; ++i)
435 unichars[i] = 0xF000 + (
unsigned char)
text[i];
444 }
catch (
const std::exception &
e) {
445 Error(
"DrawText",
"Exception from Quartz::TextLine: %s",
e.what());
456 Error(
"DrawText",
"wchar_t string to draw, but TTF initialization failed");
494 if (fontIndex == 12 || fontIndex == 15) {
495 typedef std::vector<UniChar>::size_type size_type;
497 std::vector<UniChar> unichars(std::strlen(
text));
498 for (size_type i = 0,
len = unichars.size(); i <
len; ++i)
499 unichars[i] = 0xF000 + (
unsigned char)
text[i];
501 fPimpl->fFontManager.GetTextBounds(
w,
h, unichars);
533 if (fontIndex == 12 || fontIndex == 15) {
535 typedef std::vector<UniChar>::size_type size_type;
537 std::vector<UniChar> unichars(std::strlen(
text));
538 for (size_type i = 0,
len = unichars.size(); i <
len; ++i)
539 unichars[i] = 0xF000 + (
unsigned char)
text[i];
541 return Int_t(
fPimpl->fFontManager.GetAscent(unichars));
574 if (fontIndex == 12 || fontIndex == 15) {
576 typedef std::vector<UniChar>::size_type size_type;
578 std::vector<UniChar> unichars(std::strlen(
text));
579 for (size_type i = 0,
len = unichars.size(); i <
len; ++i)
580 unichars[i] = 0xF000 + (
unsigned char)
text[i];
582 return Int_t(
fPimpl->fFontManager.GetDescent(unichars));
695 Error(
"SetTextFont",
"TTF is not initialized");
708 Error(
"SetTextFont",
"TTF is not initialized");
723 Error(
"SetTextSize",
"TTF is not initialized");
802 if (
x +
int(
w) <= 0 ||
x >=
int(
width))
828 else if ([drawable isKindOfClass : [
QuartzView class]] || [drawable isKindOfClass : [
QuartzWindow class]])
833 Error(
"DrawText",
"fSelectedDrawable is neither QuartzPixmap nor a double buffered window");
854 Error(
"DrawText",
"pixmap creation failed");
858 const unsigned char defaultBackgroundPixel[] = {255, 255, 255, 255};
868 arrayGuard.
Reset([dstPixmap readColorBits : bbox]);
870 if (!arrayGuard.
Get()) {
871 Error(
"DrawText",
"problem with reading background pixels");
879 for (
int yp = 0; yp <
int(bbox.
fHeight) && yo + yp <
h; ++yp) {
880 const unsigned char *srcBase = arrayGuard.
Get() + bbox.
fWidth * yp * 4;
881 for (
int xp = 0; xp <
int(bbox.
fWidth) && xo + xp <
w; ++xp) {
882 const unsigned char *
const pixel = srcBase + xp * 4;
883 [pixmap.
Get() putPixel :
pixel X : xo + xp Y : yo + yp];
888 [pixmap.
Get() addPixel : defaultBackgroundPixel];
894 CGContextSetRGBStrokeColor(ctx, 0., 0., 1., 1.);
898 if (FT_Glyph_To_Bitmap(&glyph->
fImage,
TTF::GetSmoothing() ? ft_render_mode_normal : ft_render_mode_mono, 0, 1 ))
902 FT_Bitmap *source = &
bitmap->bitmap;
912 [dstPixmap copy : pixmap.
Get() area : copyArea withMask : nil clipOrigin :
X11::Point() toPoint : dstPoint];
925 assert(pixmap != nil &&
"DrawFTGlyphIntoPixmap, pixmap parameter is nil");
926 assert(source != 0 &&
"DrawFTGlyphIntoPixmap, source parameter is null");
932 if (back ==
ULong_t(-1) && source->width) {
933 const int maxDots = 50000;
934 int dots =
Int_t(source->width * source->rows);
942 for (
int y = 0, dotCnt = 0;
y <
int(source->rows);
y++) {
943 for (
int x = 0;
x <
int(source->width);
x++) {
945 const unsigned char *
const pixels = pixmap.
fData + (
y + by) * pixmap.
fWidth * 4 + (
x + bx) * 4;
946 r +=
UShort_t(pixels[0] / 255. * 0xffff);
947 g +=
UShort_t(pixels[1] / 255. * 0xffff);
948 b +=
UShort_t(pixels[2] / 255. * 0xffff);
951 if (++dotCnt >= maxDots)
962 if (col[0].fRed ==
r && col[0].fGreen ==
g && col[0].fBlue ==
b) {
975 if (fore != col[4].fPixel || back != col[0].fPixel) {
984 for (
int x = 3;
x > 0; --
x) {
994 const unsigned char *s = source->buffer;
995 for (
int y = 0;
y < (
int) source->rows; ++
y) {
996 for (
int x = 0;
x < (
int) source->width; ++
x) {
997 unsigned char d = *s++ & 0xff;
998 d = ((
d + 10) * 5) / 256;
1001 if (
d &&
x < (
int) source->width) {
1003 UChar_t(
double(col[
d].fGreen) / 0xffff * 255),
1004 UChar_t(
double(col[
d].fBlue) / 0xffff * 255), 255};
1005 [pixmap putPixel :
pixel X : bx +
x Y : by +
y];
1011 unsigned char rgba[4] = {};
1014 unsigned char d = 0;
1016 const unsigned char *row = source->buffer;
1017 for (
int y = 0;
y <
int(source->rows); ++
y) {
1019 const unsigned char *s = row;
1020 for (
int x = 0;
x <
int(source->width); ++
x) {
1025 [pixmap putPixel : rgba
X : bx +
x Y : by +
y];
1031 row += source->pitch;
1043 if (
value ==
"auto") {
1044 [[NSScreen mainScreen] backingScaleFactor] > 1. ?
fUseAA = true :
fUseAA =
false;
1045 }
else if (
value ==
"no")
1048 assert(
value ==
"yes" &&
"SetAA, value must be 'yes', 'no' or 'auto'");
1052 if (valuefa ==
"auto") {
1053 [[NSScreen mainScreen] backingScaleFactor] > 1. ?
fUseFAAA = true :
fUseFAAA =
false;
1054 }
else if (valuefa ==
"no")
1057 assert(valuefa ==
"yes" &&
"SetAA, value must be 'yes', 'no' or 'auto'");
1066 assert(calledFrom != 0 &&
"GetSelectedDrawableChecked, calledFrom parameter is null");
1067 assert(
fSelectedDrawable >
fPimpl->GetRootWindowID() &&
"GetSelectedDrawableChecked, bad drawable is selected");
1070 if (!drawable.fIsPixmap) {
1072 if ([drawable isKindOfClass : [
QuartzView class]]) {
1075 Error(calledFrom,
"Selected window is not double buffered");
1081 Error(calledFrom,
"Selected drawable is neither a pixmap, nor a double buffered window");
1086 if (!drawable.fContext) {
1087 Error(calledFrom,
"Context is null");
constexpr ULong_t kBitsPerByte
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 GetWindowSize
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void pixel
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 r
Option_t Option_t markerstyle
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 UChar_t len
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 bitmap
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t textsize
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint xy
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 height
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
DerivedType * Get() const
void DrawLine(CGContextRef ctx) const
virtual Color_t GetFillColor() const
Return the fill area color.
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.
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 Width_t GetMarkerLineWidth(Style_t style)
Internal helper function that returns the line width of the given marker style (0 = filled marker)
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
static Style_t GetMarkerStyleBase(Style_t style)
Internal helper function that returns the corresponding marker style with line width 1 for the given ...
virtual Float_t GetTextSize() const
Return the text size.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual Font_t GetTextFont() const
Return the text font.
virtual Color_t GetTextColor() const
Return the text color.
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.
Short_t fTextAlign
Text alignment.
TColorGradient extends basic TColor.
The color creation and management class.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D.
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...
Window_t GetCurrentWindow() const override
pointer to the current internal window used in canvas graphics
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.
Drawable_t fSelectedDrawable
ULong_t GetPixel(Color_t cindex) override
Returns pixel value associated to specified ROOT color number "cindex".
This is non-GUI part of TVirtualX interface, implemented for MacOS X, using CoreGraphics (Quartz).
void SetLineWidth(Width_t width) override
Set the line width.
Bool_t IsTTFStringVisible(Int_t x, Int_t y, UInt_t w, UInt_t h)
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 RenderTTFString(Int_t x, Int_t y, ETextMode mode)
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 SetTextColor(Color_t cindex) override
Set the text color.
void * GetSelectedDrawableChecked(const char *calledFrom) const
void SetMarkerStyle(Style_t markerstyle) override
Set the marker style.
void DrawFTGlyphIntoPixmap(void *pixmap, FT_Bitmap *source, ULong_t fore, ULong_t back, Int_t bx, Int_t by)
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".
std::vector< TPoint > fConvertedPoints
void SetTextAlign(Short_t talign=11) override
Set the text alignment.
void SetLineColor(Color_t cindex) override
Set the line color.
void SetTextFont(Font_t fontnumber) override
Set the text font.
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 SetTextSize(Float_t textsize) override
Set the text size.
void SetLineStyle(Style_t linestyle) override
Set the line style.
Int_t GetFontDescent() const override
Returns the descent of the current font (in pixels.
void DrawPolyMarker(Int_t n, TPoint *xy) override
Draws "n" markers with the current attributes at position [x,y].
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.
TTF helper class containing glyphs description.
FT_Glyph fImage
glyph image
static Bool_t IsInitialized()
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
static void Init()
Initialise the TrueType fonts interface.
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
static void SetTextFont(Font_t fontnumber)
Set specified font.
static TTGlyph * GetGlyphs()
static Int_t GetNumGlyphs()
static const FT_BBox & GetBox()
static Bool_t GetSmoothing()
static void SetTextSize(Float_t textsize)
Set current text size.
static FT_Matrix * GetRotMatrix()
std::vector< unsigned char > fData
QuartzPixmap * fBackBuffer
QuartzWindow * fQuartzWindow
NSView< X11Window > * fContentView
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
int LocalYROOTToCocoa(NSView< X11Window > *parentView, CGFloat yROOT)
bool AdjustCropArea(const Rectangle &srcRect, Rectangle &cropArea)
void DrawFillArea(CGContextRef ctx, Int_t n, TPoint *xy, Bool_t drawShadow)
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)
void DrawPolyMarker(CGContextRef ctx, const std::vector< TPoint > &marker, Size_t markerSize, Style_t markerStyle)
Bool_t SetFillColor(CGContextRef ctx, Color_t colorIndex)
Bool_t SetFillAreaParameters(CGContextRef ctx, unsigned *patternIndex)
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.
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)