|
ROOT
Reference Guide |
|
Go to the documentation of this file.
21 #include <Cocoa/Cocoa.h>
23 # include <ft2build.h>
24 # include FT_FREETYPE_H
59 void 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");
132 CGContextRef ctx = drawable.fContext;
145 polygon[0].
fX =
x1, polygon[0].
fY = y1;
146 polygon[1].
fX =
x2, polygon[1].
fY = y1;
147 polygon[2].
fX =
x2, polygon[2].
fY = y2;
148 polygon[3].
fX =
x1, polygon[3].
fY = y2;
157 unsigned patternIndex = 0;
165 Error(
"DrawBox",
"SetFillAreaParameters failed");
199 CGContextRef ctx = drawable.fContext;
208 if (drawable.fScaleFactor > 1.) {
210 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
223 unsigned patternIndex = 0;
225 Error(
"DrawFillArea",
"SetFillAreaParameters failed");
253 ::Warning(
"DrawLine",
"Invalid view/window for XOR-mode");
271 CGContextRef ctx = drawable.fContext;
307 CGContextRef ctx = drawable.fContext;
323 if (drawable.fScaleFactor > 1.)
324 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
350 CGContextRef ctx = drawable.fContext;
366 if (drawable.fScaleFactor > 1.)
367 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
372 if (markerstyle == 1 || markerstyle == 6 || markerstyle == 7) {
373 CGContextSetLineJoin(ctx, kCGLineJoinMiter);
374 CGContextSetLineCap(ctx, kCGLineCapButt);
376 CGContextSetLineJoin(ctx, kCGLineJoinRound);
377 CGContextSetLineCap(ctx, kCGLineCapRound);
383 CGContextSetLineJoin(ctx, kCGLineJoinMiter);
384 CGContextSetLineCap(ctx, kCGLineCapButt);
406 CGContextRef ctx = drawable.fContext;
410 CGContextSetTextMatrix(ctx, CGAffineTransformIdentity);
415 if (fontIndex == 12 || fontIndex == 15) {
421 typedef std::vector<UniChar>::size_type size_type;
423 std::vector<UniChar> unichars(std::strlen(
text));
424 for (size_type i = 0, len = unichars.size(); i < len; ++i)
425 unichars[i] = 0xF000 + (
unsigned char)
text[i];
434 }
catch (
const std::exception &
e) {
435 Error(
"DrawText",
"Exception from Quartz::TextLine: %s",
e.what());
446 Error(
"DrawText",
"wchar_t string to draw, but TTF initialization failed");
484 if (fontIndex == 12 || fontIndex == 15) {
485 typedef std::vector<UniChar>::size_type size_type;
487 std::vector<UniChar> unichars(std::strlen(
text));
488 for (size_type i = 0, len = unichars.size(); i < len; ++i)
489 unichars[i] = 0xF000 + (
unsigned char)
text[i];
491 fPimpl->fFontManager.GetTextBounds(w,
h, unichars);
523 if (fontIndex == 12 || fontIndex == 15) {
525 typedef std::vector<UniChar>::size_type size_type;
527 std::vector<UniChar> unichars(std::strlen(
text));
528 for (size_type i = 0, len = unichars.size(); i < len; ++i)
529 unichars[i] = 0xF000 + (
unsigned char)
text[i];
531 return Int_t(
fPimpl->fFontManager.GetAscent(unichars));
564 if (fontIndex == 12 || fontIndex == 15) {
566 typedef std::vector<UniChar>::size_type size_type;
568 std::vector<UniChar> unichars(std::strlen(
text));
569 for (size_type i = 0, len = unichars.size(); i < len; ++i)
570 unichars[i] = 0xF000 + (
unsigned char)
text[i];
572 return Int_t(
fPimpl->fFontManager.GetDescent(unichars));
685 Error(
"SetTextFont",
"TTF is not initialized");
698 Error(
"SetTextFont",
"TTF is not initialized");
713 Error(
"SetTextSize",
"TTF is not initialized");
792 if (
x +
int(w) <= 0 ||
x >=
int(
width))
795 if (
y +
int(
h) <= 0 ||
y >=
int(height))
818 else if ([drawable isKindOfClass : [
QuartzView class]] || [drawable isKindOfClass : [
QuartzWindow class]])
823 Error(
"DrawText",
"fSelectedDrawable is neither QuartzPixmap nor a double buffered window");
844 Error(
"DrawText",
"pixmap creation failed");
848 const unsigned char defaultBackgroundPixel[] = {255, 255, 255, 255};
858 arrayGuard.
Reset([dstPixmap readColorBits : bbox]);
860 if (!arrayGuard.
Get()) {
861 Error(
"DrawText",
"problem with reading background pixels");
867 const Int_t yo = y1 < 0 ? -y1 : 0;
869 for (
int yp = 0; yp <
int(bbox.fHeight) && yo + yp <
h; ++yp) {
870 const unsigned char *srcBase = arrayGuard.
Get() + bbox.fWidth * yp * 4;
871 for (
int xp = 0; xp <
int(bbox.fWidth) && xo + xp < w; ++xp) {
872 const unsigned char *
const pixel = srcBase + xp * 4;
873 [pixmap.
Get() putPixel : pixel X : xo + xp Y : yo + yp];
878 [pixmap.
Get() addPixel : defaultBackgroundPixel];
881 CGContextRef ctx = drawable.fContext;
884 CGContextSetRGBStrokeColor(ctx, 0., 0., 1., 1.);
888 if (FT_Glyph_To_Bitmap(&glyph->
fImage,
TTF::GetSmoothing() ? ft_render_mode_normal : ft_render_mode_mono, 0, 1 ))
891 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph->
fImage;
892 FT_Bitmap *source = &bitmap->bitmap;
893 const Int_t bx = bitmap->left + xOff;
894 const Int_t by =
h - bitmap->top - yOff;
902 [dstPixmap copy : pixmap.
Get() area : copyArea withMask : nil clipOrigin :
X11::Point() toPoint : dstPoint];
915 assert(pixmap != nil &&
"DrawFTGlyphIntoPixmap, pixmap parameter is nil");
916 assert(source != 0 &&
"DrawFTGlyphIntoPixmap, source parameter is null");
922 if (back ==
ULong_t(-1) && source->width) {
923 const int maxDots = 50000;
924 int dots =
Int_t(source->width * source->rows);
932 for (
int y = 0, dotCnt = 0;
y <
int(source->rows);
y++) {
933 for (
int x = 0;
x <
int(source->width);
x++) {
935 const unsigned char *
const pixels = pixmap.
fData + (
y + by) * pixmap.
fWidth * 4 + (
x + bx) * 4;
936 r +=
UShort_t(pixels[0] / 255. * 0xffff);
937 g +=
UShort_t(pixels[1] / 255. * 0xffff);
938 b +=
UShort_t(pixels[2] / 255. * 0xffff);
941 if (++dotCnt >= maxDots)
952 if (col[0].fRed ==
r && col[0].fGreen ==
g && col[0].fBlue ==
b) {
965 if (fore != col[4].fPixel || back != col[0].fPixel) {
974 for (
int x = 3;
x > 0; --
x) {
984 const unsigned char *
s = source->buffer;
985 for (
int y = 0;
y < (
int) source->rows; ++
y) {
986 for (
int x = 0;
x < (
int) source->width; ++
x) {
987 unsigned char d = *
s++ & 0xff;
988 d = ((
d + 10) * 5) / 256;
991 if (
d &&
x < (
int) source->width) {
993 UChar_t(
double(col[
d].fGreen) / 0xffff * 255),
994 UChar_t(
double(col[
d].fBlue) / 0xffff * 255), 255};
995 [pixmap putPixel : pixel X : bx +
x Y : by +
y];
1001 unsigned char rgba[4] = {};
1004 unsigned char d = 0;
1006 const unsigned char *row = source->buffer;
1007 for (
int y = 0;
y <
int(source->rows); ++
y) {
1009 const unsigned char *
s = row;
1010 for (
int x = 0;
x <
int(source->width); ++
x) {
1015 [pixmap putPixel : rgba X : bx +
x Y : by +
y];
1021 row += source->pitch;
1033 if (value ==
"auto") {
1034 [[NSScreen mainScreen] backingScaleFactor] > 1. ?
fUseAA = true :
fUseAA =
false;
1035 }
else if (value ==
"no")
1038 assert(value ==
"yes" &&
"SetAA, value must be 'yes', 'no' or 'auto'");
1042 if (valuefa ==
"auto") {
1043 [[NSScreen mainScreen] backingScaleFactor] > 1. ?
fUseFAAA = true :
fUseFAAA =
false;
1044 }
else if (valuefa ==
"no")
1047 assert(valuefa ==
"yes" &&
"SetAA, value must be 'yes', 'no' or 'auto'");
1056 assert(calledFrom != 0 &&
"GetSelectedDrawableChecked, calledFrom parameter is null");
1057 assert(
fSelectedDrawable >
fPimpl->GetRootWindowID() &&
"GetSelectedDrawableChecked, bad drawable is selected");
1060 if (!drawable.fIsPixmap) {
1062 if ([drawable isKindOfClass : [
QuartzView class]]) {
1065 Error(calledFrom,
"Selected window is not double buffered");
1071 Error(calledFrom,
"Selected drawable is neither a pixmap, nor a double buffered window");
1076 if (!drawable.fContext) {
1077 Error(calledFrom,
"Context is null");
virtual void SetTextFont(Font_t fontnumber)
Sets the current text font number.
UShort_t fBlue
blue component (0..65535)
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
std::vector< unsigned char > fData
TTF helper class containing glyphs description.
ULong_t fPixel
color pixel value (index in color table)
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.
Bool_t IsTTFStringVisible(Int_t x, Int_t y, UInt_t w, UInt_t h)
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
static void Init()
Initialise the TrueType fonts interface.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Short_t Max(Short_t a, Short_t b)
FT_Glyph fImage
glyph image
QuartzPixmap * fBackBuffer
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
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".
virtual Color_t GetTextColor() const
Return the text color.
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
virtual Size_t GetMarkerSize() const
Return the marker size.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
static Width_t GetMarkerLineWidth(Style_t style)
Internal helper function that returns the line width of the given marker style (0 = filled marker)
void DrawLine(CGContextRef ctx) const
Short_t fTextAlign
Text alignment.
virtual ULong_t GetPixel(Color_t cindex)
Returns pixel value associated to specified ROOT color number "cindex".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
static void SetTextSize(Float_t textsize)
Set current text size.
include TDocParser_001 C image html pict1_TDocParser_001 png width
static constexpr double s
static void SetTextFont(Font_t fontnumber)
Set specified font.
virtual void SetMarkerColor(Color_t cindex)
Sets color index "cindex" for markers.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
DerivedType * Get() const
virtual Style_t GetMarkerStyle() const
Return the marker style.
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 Float_t GetTextMagnitude()
Returns the current font magnification factor.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
void DrawFillArea(CGContextRef ctx, Int_t n, TPoint *xy, Bool_t drawShadow)
virtual Float_t GetTextSize() const
Return the text size.
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.
static FT_Matrix * GetRotMatrix()
static Bool_t GetSmoothing()
void DrawPolygonWithGradientFill(CGContextRef ctx, const TColorGradient *extendedColor, const CGSize &sizeOfDrawable, Int_t nPoints, const TPoint *xy, Bool_t drawShadow)
TColorGradient extends basic TColor.
virtual void SetMarkerStyle(Style_t markerstyle)
Sets marker style.
static const double x1[5]
virtual void QueryColor(Colormap_t cmap, ColorStruct_t &color)
Returns the current RGB value for the pixel in the "color" structure.
This is non-GUI part of TVirtualX interface, implemented for MacOS X, using CoreGraphics (Quartz).
std::vector< TPoint > fConvertedPoints
virtual Int_t GetFontDescent() const
Returns the descent of the current font (in pixels.
virtual void DrawLine(Drawable_t wid, GContext_t gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
virtual void SetTextSize(Float_t textsize)
Sets the current text size to "textsize".
virtual Font_t GetTextFont() const
Return the text font.
The color creation and management class.
virtual Color_t GetLineColor() const
Return the line color.
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D.
virtual Int_t GetFontAscent() const
Returns the ascent of the current font (in pixels).
virtual Window_t GetCurrentWindow() const
pointer to the current internal window used in canvas graphics
Double_t Floor(Double_t x)
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
std::unique_ptr< ROOT::MacOSX::Details::CocoaPrivate > fPimpl
virtual Style_t GetLineStyle() const
Return the line style.
UShort_t fGreen
green component (0..65535)
UShort_t fRed
red component (0..65535)
virtual void SetTextAlign(Short_t talign=11)
Sets the text alignment.
Bool_t SetFillAreaParameters(CGContextRef ctx, unsigned *patternIndex)
int LocalYROOTToCocoa(NSView< X11Window > *parentView, CGFloat yROOT)
virtual void DrawPolyMarker(Int_t n, TPoint *xy)
Draws "n" markers with the current attributes at position [x,y].
void DrawPolyMarker(CGContextRef ctx, const std::vector< TPoint > &marker, Size_t markerSize, Style_t markerStyle)
lv DrawLine(0.33, 0.0, 0.33, 1.0)
QuartzWindow * fQuartzWindow
virtual Style_t GetFillStyle() const
Return the fill area style.
virtual void SetMarkerSize(Float_t markersize)
Sets marker size index.
virtual Color_t GetMarkerColor() const
Return the marker color.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void DrawBox(CGContextRef ctx, Int_t x1, Int_t y1, Int_t x2, Int_t y2, bool hollow)
typedef void((*Func_t)())
virtual void SetLineWidth(Width_t width)
Sets the line width.
static TTGlyph * GetGlyphs()
static Style_t GetMarkerStyleBase(Style_t style)
Internal helper function that returns the corresponding marker style with line width 1 for the given ...
virtual void SetLineColor(Color_t cindex)
Sets color index "cindex" for drawing lines.
void RenderTTFString(Int_t x, Int_t y, ETextMode mode)
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
void DrawPolyLine(CGContextRef ctx, Int_t n, TPoint *xy)
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual void SetOpacity(Int_t percent)
Sets opacity of the current window.
bool AdjustCropArea(const Rectangle &srcRect, Rectangle &cropArea)
void DrawFTGlyphIntoPixmap(void *pixmap, FT_Bitmap *source, ULong_t fore, ULong_t back, Int_t bx, Int_t by)
void * GetSelectedDrawableChecked(const char *calledFrom) const
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 void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetLineStyle(Style_t linestyle)
Sets the line style.
static Bool_t IsInitialized()
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
static const double x2[5]
virtual Color_t GetFillColor() const
Return the fill area color.
static Int_t GetNumGlyphs()
const ULong_t kBitsPerByte
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
virtual Width_t GetLineWidth() const
Return the line width.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetTextColor(Color_t cindex)
Sets the color index "cindex" for text.
static const FT_BBox & GetBox()
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
virtual void GetTextExtent(UInt_t &w, UInt_t &h, char *text)
Returns the size of the specified character string "mess".
virtual void DrawFillArea(Int_t n, TPoint *xy)
Fills area described by the polygon.
virtual void SetFillStyle(Style_t style)
Sets fill area style.
Drawable_t fSelectedDrawable
virtual void DrawPolyLine(Int_t n, TPoint *xy)
Draws a line through all points in the list.
virtual void SetFillColor(Color_t cindex)
Sets color index "cindex" for fill areas.