Exemplo n.º 1
0
 /**
  * Returns a device independent representation of the receiver.
  *
  * @return the PathData for the receiver
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  *
  * @see PathData
  */
 public PathData getPathData() {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   int count = handle.elementCount();
   int pointCount = 0, typeCount = 0;
   byte[] types = new byte[count];
   float[] pointArray = new float[count * 6];
   int points = OS.malloc(3 * NSPoint.sizeof);
   if (points == 0) SWT.error(SWT.ERROR_NO_HANDLES);
   NSPoint pt = new NSPoint();
   for (int i = 0; i < count; i++) {
     int element = handle.elementAtIndex_associatedPoints_(i, points);
     switch (element) {
       case OS.NSMoveToBezierPathElement:
         types[typeCount++] = SWT.PATH_MOVE_TO;
         OS.memmove(pt, points, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         break;
       case OS.NSLineToBezierPathElement:
         types[typeCount++] = SWT.PATH_LINE_TO;
         OS.memmove(pt, points, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         break;
       case OS.NSCurveToBezierPathElement:
         types[typeCount++] = SWT.PATH_CUBIC_TO;
         OS.memmove(pt, points, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         OS.memmove(pt, points + NSPoint.sizeof, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         OS.memmove(pt, points + NSPoint.sizeof + NSPoint.sizeof, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         break;
       case OS.NSClosePathBezierPathElement:
         types[typeCount++] = SWT.PATH_CLOSE;
         break;
     }
   }
   OS.free(points);
   if (pointCount != pointArray.length) {
     float[] temp = new float[pointCount];
     System.arraycopy(pointArray, 0, temp, 0, pointCount);
     pointArray = temp;
   }
   PathData data = new PathData();
   data.types = types;
   data.points = pointArray;
   return data;
 }
Exemplo n.º 2
0
 /**
  * Adds to the receiver the pattern of glyphs generated by drawing the given string using the
  * given font starting at the point (x, y).
  *
  * @param string the text to use
  * @param x the x coordinate of the starting point
  * @param y the y coordinate of the starting point
  * @param font the font to use
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the font is null
  *       <li>ERROR_INVALID_ARGUMENT - if the font has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public void addString(String string, float x, float y, Font font) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   NSString str = NSString.stringWith(string);
   NSTextStorage textStorage = ((NSTextStorage) new NSTextStorage().alloc());
   textStorage.initWithString_(str);
   NSLayoutManager layoutManager = (NSLayoutManager) new NSLayoutManager().alloc().init();
   NSTextContainer textContainer = (NSTextContainer) new NSTextContainer().alloc();
   NSSize size = new NSSize();
   size.width = Float.MAX_VALUE;
   size.height = Float.MAX_VALUE;
   textContainer.initWithContainerSize(size);
   textStorage.addLayoutManager(layoutManager);
   layoutManager.addTextContainer(textContainer);
   NSRange range = new NSRange();
   range.length = str.length();
   textStorage.beginEditing();
   textStorage.addAttribute(OS.NSFontAttributeName(), font.handle, range);
   textStorage.endEditing();
   range = layoutManager.glyphRangeForTextContainer(textContainer);
   if (range.length != 0) {
     int glyphs = OS.malloc(4 * range.length * 2);
     layoutManager.getGlyphs(glyphs, range);
     NSBezierPath path = NSBezierPath.bezierPath();
     NSPoint point = new NSPoint();
     point.x = x;
     point.y = y;
     path.moveToPoint(point);
     path.appendBezierPathWithGlyphs(glyphs, range.length, font.handle);
     NSAffineTransform transform = NSAffineTransform.transform();
     transform.scaleXBy(1, -1);
     transform.translateXBy(0, -((2 * y) + textStorage.size().height));
     path.transformUsingAffineTransform(transform);
     OS.free(glyphs);
     handle.appendBezierPath(path);
   }
   textContainer.release();
   layoutManager.release();
   textStorage.release();
 }
Exemplo n.º 3
0
 static boolean isExecutable(String fileName) {
   long /*int*/ ptr = OS.malloc(1);
   NSString path = NSString.stringWith(fileName);
   boolean result = false;
   NSFileManager manager = NSFileManager.defaultManager();
   if (manager.fileExistsAtPath(path, ptr)) {
     byte[] isDirectory = new byte[1];
     OS.memmove(isDirectory, ptr, 1);
     if (isDirectory[0] == 0 && manager.isExecutableFileAtPath(path)) {
       NSWorkspace ws = NSWorkspace.sharedWorkspace();
       NSString type = ws.typeOfFile(path, 0);
       result =
           type != null
               && (ws.type(type, NSString.stringWith("public.unix-executable"))
                   || //$NON-NLS-1$
                   OS.UTTypeEqual(
                       type.id, NSString.stringWith("public.shell-script").id)); // $NON-NLS-1$
     }
   }
   OS.free(ptr);
   return result;
 }