21 #include <Cocoa/Cocoa.h>
23 # include <ft2build.h>
24 # include FT_FREETYPE_H
66 namespace Util =
ROOT::MacOSX::Util;
71 void ConvertPointsROOTToCocoa(
Int_t nPoints,
const TPoint *
xy, std::vector<TPoint> &dst,
72 NSObject<X11Drawable> *drawable)
74 assert(nPoints != 0 &&
"ConvertPointsROOTToCocoa, nPoints parameter is 0");
75 assert(xy != 0 &&
"ConvertPointsROOTToCocoa, xy parameter is null");
76 assert(drawable != 0 &&
"ConvertPointsROOTToCocoa, drawable parameter is null");
79 for (
Int_t i = 0; i < nPoints; ++i) {
99 Error(
"TGQuartz",
"TTF::Init() failed");
119 Error(
"TGQuartz",
"TTF::Init() failed");
142 CGContextRef ctx = drawable.fContext;
155 polygon[0].
fX =
x1, polygon[0].
fY = y1;
156 polygon[1].
fX =
x2, polygon[1].
fY = y1;
157 polygon[2].
fX =
x2, polygon[2].
fY = y2;
158 polygon[3].
fX =
x1, polygon[3].
fY = y2;
167 unsigned patternIndex = 0;
175 Error(
"DrawBox",
"SetFillAreaParameters failed");
203 NSObject<X11Drawable> *
const drawable =
209 CGContextRef ctx = drawable.fContext;
224 if (
const TColorGradient *
const gradient = dynamic_cast<const TColorGradient *>(fillColor)) {
228 unsigned patternIndex = 0;
230 Error(
"DrawFillArea",
"SetFillAreaParameters failed");
262 NSObject<X11Drawable> *
const drawable =
267 CGContextRef ctx = drawable.fContext;
298 NSObject<X11Drawable> *
const drawable =
303 CGContextRef ctx = drawable.fContext;
336 NSObject<X11Drawable> *
const drawable =
341 CGContextRef ctx = drawable.fContext;
368 if (!text || !text[0])
374 NSObject<X11Drawable> *
const drawable =
379 CGContextRef ctx = drawable.fContext;
383 CGContextSetTextMatrix(ctx, CGAffineTransformIdentity);
388 if (fontIndex == 12 || fontIndex == 15) {
394 typedef std::vector<UniChar>::size_type size_type;
396 std::vector<UniChar> unichars(std::strlen(text));
397 for (size_type i = 0, len = unichars.size(); i < len; ++i)
398 unichars[i] = 0xF000 + (
unsigned char)text[i];
407 }
catch (
const std::exception &e) {
408 Error(
"DrawText",
"Exception from Quartz::TextLine: %s", e.what());
415 if (!text || !text[0])
419 Error(
"DrawText",
"wchar_t string to draw, but TTF initialization failed");
449 if (!text || !text[0]) {
457 if (fontIndex == 12 || fontIndex == 15) {
458 typedef std::vector<UniChar>::size_type size_type;
460 std::vector<UniChar> unichars(std::strlen(text));
461 for (size_type i = 0, len = unichars.size(); i < len; ++i)
462 unichars[i] = 0xF000 + (
unsigned char)text[i];
464 fPimpl->fFontManager.GetTextBounds(w, h, unichars);
466 fPimpl->fFontManager.GetTextBounds(w, h, text);
491 if (!text || !text[0])
496 if (fontIndex == 12 || fontIndex == 15) {
498 typedef std::vector<UniChar>::size_type size_type;
500 std::vector<UniChar> unichars(std::strlen(text));
501 for (size_type i = 0, len = unichars.size(); i < len; ++i)
502 unichars[i] = 0xF000 + (
unsigned char)text[i];
504 return Int_t(
fPimpl->fFontManager.GetAscent(unichars));
506 return Int_t(
fPimpl->fFontManager.GetAscent(text));
532 if (!text || !text[0])
537 if (fontIndex == 12 || fontIndex == 15) {
539 typedef std::vector<UniChar>::size_type size_type;
541 std::vector<UniChar> unichars(std::strlen(text));
542 for (size_type i = 0, len = unichars.size(); i < len; ++i)
543 unichars[i] = 0xF000 + (
unsigned char)text[i];
545 return Int_t(
fPimpl->fFontManager.GetDescent(unichars));
547 return Int_t(
fPimpl->fFontManager.GetDescent(text));
658 Error(
"SetTextFont",
"TTF is not initialized");
671 Error(
"SetTextFont",
"TTF is not initialized");
686 Error(
"SetTextSize",
"TTF is not initialized");
765 if (x +
int(w) <= 0 || x >=
int(width))
768 if (y +
int(h) <= 0 || y >=
int(height))
790 dstPixmap = (QuartzPixmap *)drawable;
791 else if ([drawable isKindOfClass : [
QuartzView class]] || [drawable isKindOfClass : [
QuartzWindow class]])
792 dstPixmap = ((NSObject<X11Window> *)drawable).fBackBuffer;
796 Error(
"DrawText",
"fSelectedDrawable is neither QuartzPixmap nor a double buffered window");
815 Util::NSScopeGuard<QuartzPixmap> pixmap([[QuartzPixmap alloc] initWithW : w
H : h scaleFactor : 1.
f]);
817 Error(
"DrawText",
"pixmap creation failed");
821 const unsigned char defaultBackgroundPixel[] = {255, 255, 255, 255};
822 Util::ScopedArray<unsigned char> arrayGuard;
831 arrayGuard.Reset([dstPixmap readColorBits : bbox]);
833 if (!arrayGuard.Get()) {
834 Error(
"DrawText",
"problem with reading background pixels");
839 const Int_t xo = x1 < 0 ? -x1 : 0;
840 const Int_t yo = y1 < 0 ? -y1 : 0;
842 for (
int yp = 0; yp < int(bbox.fHeight) && yo + yp <
h; ++yp) {
843 const unsigned char *srcBase = arrayGuard.Get() + bbox.fWidth * yp * 4;
844 for (
int xp = 0; xp < int(bbox.fWidth) && xo + xp < w; ++xp) {
845 const unsigned char *
const pixel = srcBase + xp * 4;
846 [pixmap.Get() putPixel : pixel X : xo + xp Y : yo + yp];
851 [pixmap.Get() addPixel : defaultBackgroundPixel];
854 CGContextRef ctx = drawable.fContext;
857 CGContextSetRGBStrokeColor(ctx, 0., 0., 1., 1.);
861 if (FT_Glyph_To_Bitmap(&glyph->
fImage,
TTF::GetSmoothing() ? ft_render_mode_normal : ft_render_mode_mono, 0, 1 ))
864 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph->
fImage;
865 FT_Bitmap *source = &bitmap->bitmap;
866 const Int_t bx = bitmap->left + xOff;
867 const Int_t by = h - bitmap->top - yOff;
875 [dstPixmap copy : pixmap.Get() area : copyArea withMask : nil clipOrigin : X11::Point() toPoint : dstPoint];
888 assert(pixmap != nil &&
"DrawFTGlyphIntoPixmap, pixmap parameter is nil");
889 assert(source != 0 &&
"DrawFTGlyphIntoPixmap, source parameter is null");
895 if (back ==
ULong_t(-1) && source->width) {
896 const int maxDots = 50000;
897 int dots =
Int_t(source->width * source->rows);
905 for (
int y = 0, dotCnt = 0;
y < int(source->rows);
y++) {
906 for (
int x = 0;
x < int(source->width);
x++) {
908 const unsigned char *
const pixels = pixmap.
fData + (
y + by) * pixmap.
fWidth * 4 + (
x + bx) * 4;
909 r +=
UShort_t(pixels[0] / 255. * 0xffff);
910 g +=
UShort_t(pixels[1] / 255. * 0xffff);
911 b +=
UShort_t(pixels[2] / 255. * 0xffff);
914 if (++dotCnt >= maxDots)
925 if (col[0].fRed == r && col[0].fGreen ==
g && col[0].fBlue == b) {
938 if (fore != col[4].fPixel || back != col[0].fPixel) {
947 for (
int x = 3;
x > 0; --
x) {
957 const unsigned char *s = source->buffer;
958 for (
int y = 0;
y < (int) source->rows; ++
y) {
959 for (
int x = 0;
x < (int) source->width; ++
x) {
960 unsigned char d = *s++ & 0xff;
961 d = ((d + 10) * 5) / 256;
964 if (d &&
x < (
int) source->width) {
965 const UChar_t pixel[] = {
UChar_t(
double(col[d].fRed) / 0xffff * 255),
966 UChar_t(
double(col[d].fGreen) / 0xffff * 255),
967 UChar_t(
double(col[d].fBlue) / 0xffff * 255), 255};
968 [pixmap putPixel : pixel X : bx + x Y : by + y];
974 unsigned char rgba[4] = {};
979 const unsigned char *row = source->buffer;
980 for (
int y = 0;
y < int(source->rows); ++
y) {
982 const unsigned char *s = row;
983 for (
int x = 0;
x < int(source->width); ++
x) {
988 [pixmap putPixel : rgba
X : bx +
x Y : by +
y];
994 row += source->pitch;
1006 if (
value ==
"auto") {
1008 [[NSScreen mainScreen] backingScaleFactor] > 1. ?
fUseAA =
true :
fUseAA =
false;
1009 }
else if (
value ==
"no")
1012 assert(
value ==
"yes" &&
"SetAA, value must be 'yes', 'no' or 'auto'");
1021 assert(calledFrom != 0 &&
"GetSelectedDrawableChecked, calledFrom parameter is null");
1025 if (!drawable.fIsPixmap) {
1027 if ([drawable isKindOfClass : [
QuartzView class]]) {
1028 QuartzView *view = (QuartzView *)drawable;
1030 Error(calledFrom,
"Selected window is not double buffered");
1036 Error(calledFrom,
"Selected drawable is neither a pixmap, nor a double buffered window");
1041 if (!drawable.fContext) {
1042 Error(calledFrom,
"Context is null");
virtual Style_t GetLineStyle() const
virtual Style_t GetFillStyle() const
virtual void SetLineWidth(Width_t lwidth)
static void Init()
Initialise the TrueType fonts interface.
void DrawLine(CGContextRef ctx) const
ClassImp(TGQuartz) namespace X11
virtual void SetMarkerColor(Color_t cindex)
Sets color index "cindex" for markers.
virtual Float_t GetTextMagnitude()
Returns the current font magnification factor.
Bool_t SetFillAreaParameters(CGContextRef ctx, unsigned *patternIndex)
virtual Font_t GetTextFont() const
Namespace for new ROOT classes and functions.
virtual void DrawBox(Int_t x1, Int_t y1, Int_t x2, Int_t y2, EBoxMode mode)
Draws a box between [x1,y1] and [x2,y2] according to the "mode".
std::auto_ptr< ROOT::MacOSX::Details::CocoaPrivate > fPimpl
virtual void DrawText(Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode)
Draws a text string using current font.
virtual void SetTextColor(Color_t cindex)
Sets the color index "cindex" for text.
static Bool_t IsInitialized()
bool AdjustCropArea(const Rectangle &srcRect, Rectangle &cropArea)
virtual void DrawFillArea(Int_t n, TPoint *xy)
Fills area described by the polygon.
virtual Float_t GetTextSize() const
virtual void SetFillStyle(Style_t fstyle)
QuartzPixmap * fBackBuffer
virtual Int_t GetFontDescent() const
Returns the descent of the current font (in pixels.
virtual void QueryColor(Colormap_t cmap, ColorStruct_t &color)
Returns the current RGB value for the pixel in the "color" structure.
std::vector< TPoint > fConvertedPoints
virtual void DrawCellArray(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t nx, Int_t ny, Int_t *ic)
Draws a cell array.
virtual void SetLineWidth(Width_t width)
Sets the line width.
virtual void DrawPolyMarker(Int_t n, TPoint *xy)
Draws "n" markers with the current attributes at position [x,y].
virtual void SetTextFont(Font_t tfont=62)
static const double x2[5]
virtual void SetLineColor(Color_t cindex)
Sets color index "cindex" for drawing lines.
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
virtual void SetOpacity(Int_t percent)
Sets opacity of the current window.
static void SetTextFont(Font_t fontnumber)
Set specified font.
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
virtual void DrawLine(Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Draws a line.
virtual Color_t GetTextColor() const
virtual void SetMarkerColor(Color_t mcolor=1)
static TTGlyph * GetGlyphs()
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual Bool_t AllocColor(Colormap_t cmap, ColorStruct_t &color)
Allocates a read-only colormap entry corresponding to the closest RGB value supported by the hardware...
virtual Window_t GetCurrentWindow() const
pointer to the current internal window used in canvas graphics
virtual void SetTextSize(Float_t textsize)
Sets the current text size to "textsize".
virtual void SetTextAlign(Short_t align=11)
void DrawPolyLine(CGContextRef ctx, Int_t n, TPoint *xy)
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
Drawable_t fSelectedDrawable
virtual void SetLineColor(Color_t lcolor)
virtual Size_t GetMarkerSize() const
void DrawFillArea(CGContextRef ctx, Int_t n, TPoint *xy, Bool_t drawShadow)
virtual void SetFillColor(Color_t fcolor)
virtual void SetMarkerSize(Float_t markersize)
Sets marker size index.
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
char * Strip(const char *str, char c= ' ')
Strip leading and trailing c (blanks by default) from a string.
virtual Color_t GetFillColor() const
static FT_Matrix * GetRotMatrix()
TTF helper class containing glyphs description.
void DrawPolyMarker(CGContextRef ctx, const std::vector< TPoint > &marker, Size_t markerSize, Style_t markerStyle)
void DrawFTGlyphIntoPixmap(void *pixmap, FT_Bitmap *source, ULong_t fore, ULong_t back, Int_t bx, Int_t by)
virtual void SetMarkerStyle(Style_t mstyle=1)
void DrawPolygonWithGradientFill(CGContextRef ctx, const TColorGradient *extendedColor, const CGSize &sizeOfDrawable, Int_t nPoints, const TPoint *xy, Bool_t drawShadow)
virtual void SetFillColor(Color_t cindex)
Sets color index "cindex" for fill areas.
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
virtual Int_t GetFontAscent() const
Returns the ascent of the current font (in pixels).
virtual Color_t GetLineColor() const
virtual void SetMarkerStyle(Style_t markerstyle)
Sets marker style.
lv DrawLine(0.33, 0.0, 0.33, 1.0)
virtual void SetMarkerSize(Size_t msize=1)
int LocalYROOTToCocoa(NSView< X11Window > *parentView, CGFloat yROOT)
static const double x1[5]
virtual ULong_t GetPixel(Color_t cindex)
Returns pixel value associated to specified ROOT color number "cindex".
std::vector< unsigned char > fData
The color creation and management class.
virtual void SetLineStyle(Style_t lstyle)
virtual void SetTextAlign(Short_t talign=11)
Sets the text alignment.
virtual void GetWindowSize(Drawable_t wid, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h)
Returns the location and the size of window "id".
virtual void SetTextFont(Font_t fontnumber)
Sets the current text font number.
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
typedef void((*Func_t)())
void RenderTTFString(Int_t x, Int_t y, ETextMode mode)
virtual Color_t GetMarkerColor() const
Bool_t IsTTFStringVisible(Int_t x, Int_t y, UInt_t w, UInt_t h)
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D. ...
void DrawBox(CGContextRef ctx, Int_t x1, Int_t y1, Int_t x2, Int_t y2, bool hollow)
const size_t kBitsPerByte
virtual void GetTextExtent(UInt_t &w, UInt_t &h, char *text)
Returns the size of the specified character string "mess".
virtual void DrawPolyLine(Int_t n, TPoint *xy)
Draws a line through all points in the list.
virtual void SetTextColor(Color_t tcolor=1)
static void SetTextSize(Float_t textsize)
Set current text size.
void * GetSelectedDrawableChecked(const char *calledFrom) const
virtual void SetTextSize(Float_t tsize=1)
virtual void SetLineStyle(Style_t linestyle)
Sets the line style.
static Int_t GetNumGlyphs()
virtual Style_t GetMarkerStyle() const
virtual Width_t GetLineWidth() const
TColorGradient extends basic TColor.
virtual void SetFillStyle(Style_t style)
Sets fill area style.
This is non-GUI part of TVirtualX interface, implemented for MacOS X, using CoreGraphics (Quartz)...
static const FT_BBox & GetBox()
static Bool_t GetSmoothing()