Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added many missing features to NSGeometry #468

Merged
merged 6 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
2024-11-19 Richard Frith-Macdonald <rfm@gnu.org>

* GSMime: fixed buffer overrun in rare circumstances when decoding
an encoded word in a header.
fix to cope with dealloc of uninitialised instances of GSMimeSMTPClient
* GSTLS: clean up used resources on exit
* NSCharacterSet: Fix retain count of cached character sets
* NSDateFormatter: fix to cope with dealloc of uninitialised instances
* NSFileManager: fix leak of enumerator when enumerating files at
a directory specified by URL
* NSHTTPCookie: fix buffer overrun parsing cookie header fields
* NSInvocation: fix leak of type information memory when passing
general struct argument/return values
* NSNumberFormatter: fix to cope with dealloc of uninitialised instances
* NSOperation: fix to cope with dealloc of uninitialised instances
* NSPredicate: fix leaks of keypath and set expressions
also fix leak of objects if exception occurs while scanning predicate
string
* NSPropertyList: fix leaks if exception occurs while parsing
* NSRegularExpression: fix leaks if exception occurs while parsing
* NSString: fix lead in dataUsingEncoding:allowLossyConversion:
* NSTimeZone: fix retain cycle in absolute time zones
fix leak of ICU calendar in -localizedName:locale:
* NSURL: fix leaks when initialising with unparseable string etc
* Testcases: fix many leaks so that most tests run to completion
without any leaked memory.

2024-11-19 Matvii Jarosh <matviijarosh@gmail.com>

* Header/Foundation/NSGeometry.h: fixed NSRectEdge and
NSAlignmentOptions enums.

2024-11-18 Matvii Jarosh <matviijarosh@gmail.com>

* Source/NSGeometry.m: added NSIntegralRectWithOptions function.
* Header/Foundation/NSGeometry.h: Fixed incompatible NSRectEdge,
added enum NSAlignmentOptions, added NSRectFromCGRect,
NSRectToCGRect, NSPointFromCGPoint, NSPointToCGPoint,
NSSizeFromCGSize and NSSizeToCGSizea functions.
* MISSING:

2024-11-14 Richard Frith-Macdonald <rfm@gnu.org>

* Source/NSBundle.m: Restructure a bit to expose resource lookup
Expand Down
140 changes: 136 additions & 4 deletions Headers/Foundation/NSGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ typedef NSRect *NSRectArray;
typedef NSRect *NSRectPointer;
#endif

enum
typedef NS_ENUM(NSUInteger, NSRectEdge)
{
NSMinXEdge = 0,
NSMinYEdge = 1,
Expand All @@ -113,8 +113,72 @@ enum
NSMaxYEdge
}
</example>
*/
typedef NSUInteger NSRectEdge;
<p>NSRectEdge</p>*/
// typedef NSUInteger NSRectEdge;
/** A value representing the alignment process
<example>
{
NSAlignMinXInward,
NSAlignMinYInward,
NSAlignMaxXInward,
NSAlignMaxYInward,
NSAlignWidthInward,
NSAlignHeightInward,
NSAlignMinXOutward,
NSAlignMinYOutward,
NSAlignMaxXOutward,
NSAlignMaxYOutward,
NSAlignWidthOutward,
NSAlignHeightOutward,
NSAlignMinXNearest,
NSAlignMinYNearest,
NSAlignMaxXNearest,
NSAlignMaxYNearest,
NSAlignWidthNearest,
NSAlignHeightNearest,
NSAlignRectFlipped,
NSAlignAllEdgesInward,
NSAlignAllEdgesOutward,
NSAlignAllEdgesNearest
}
</example>
<p>NSAlignmentOptions</p>*/
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
typedef NS_ENUM(unsigned long long, NSAlignmentOptions)
{
NSAlignMinXInward = 1ULL << 0,
NSAlignMinYInward = 1ULL << 1,
NSAlignMaxXInward = 1ULL << 2,
NSAlignMaxYInward = 1ULL << 3,
NSAlignWidthInward = 1ULL << 4,
NSAlignHeightInward = 1ULL << 5,
NSAlignMinXOutward = 1ULL << 8,
NSAlignMinYOutward = 1ULL << 9,
NSAlignMaxXOutward = 1ULL << 10,
NSAlignMaxYOutward = 1ULL << 11,
NSAlignWidthOutward = 1ULL << 12,
NSAlignHeightOutward = 1ULL << 13,
NSAlignMinXNearest = 1ULL << 16,
NSAlignMinYNearest = 1ULL << 17,
NSAlignMaxXNearest = 1ULL << 18,
NSAlignMaxYNearest = 1ULL << 19,
NSAlignWidthNearest = 1ULL << 20,
NSAlignHeightNearest = 1ULL << 21,
NSAlignRectFlipped = 1ULL << 63,
NSAlignAllEdgesInward = NSAlignMinXInward
| NSAlignMaxXInward
| NSAlignMinYInward
| NSAlignMaxYInward,
NSAlignAllEdgesOutward = NSAlignMinXOutward
| NSAlignMaxXOutward
| NSAlignMinYOutward
| NSAlignMaxYOutward,
NSAlignAllEdgesNearest = NSAlignMinXNearest
| NSAlignMaxXNearest
| NSAlignMinYNearest
| NSAlignMaxYNearest
};
#endif

/**
<example>{
Expand Down Expand Up @@ -195,7 +259,7 @@ NSMakeSize(CGFloat w, CGFloat h)

GS_GEOM_SCOPE NSRect
NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h) GS_GEOM_ATTR;

/** Returns an NSRect having point of origin (x, y) and size {w, h}. */
GS_GEOM_SCOPE NSRect
NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h)
Expand All @@ -209,6 +273,68 @@ NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h)
return rect;
}

#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
GS_GEOM_SCOPE NSRect
NSRectFromCGRect(CGRect rect) GS_GEOM_ATTR;

/** Return an NSRect from CGRect. **/
GS_GEOM_SCOPE NSRect
NSRectFromCGRect(CGRect rect)
{
return (NSRect)rect;
}

GS_GEOM_SCOPE CGRect
NSRectToCGRect(NSRect rect) GS_GEOM_ATTR;

/** Return an CGRect from NSRect. **/
GS_GEOM_SCOPE CGRect
NSRectToCGRect(NSRect rect)
{
return (CGRect)rect;
}

GS_GEOM_SCOPE NSPoint
NSPointFromCGPoint(CGPoint point) GS_GEOM_ATTR;

/** Return an NSPoint from CGPoint **/
GS_GEOM_SCOPE NSPoint
NSPointFromCGPoint(CGPoint point)
{
return (NSPoint)point;
}

GS_GEOM_SCOPE CGPoint
NSPointToCGPoint(NSPoint point) GS_GEOM_ATTR;

/** Return an CGPoint from NSPoint **/
GS_GEOM_SCOPE CGPoint
NSPointToCGPoint(NSPoint point)
{
return (CGPoint)point;
}

GS_GEOM_SCOPE NSSize
NSSizeFromCGSize(CGSize size) GS_GEOM_ATTR;

/** Return an NSSize from CGSize **/
GS_GEOM_SCOPE NSSize
NSSizeFromCGSize(CGSize size)
{
return (NSSize)size;
}

GS_GEOM_SCOPE CGSize
NSSizeToCGSize(NSSize size) GS_GEOM_ATTR;

/** Return an CGSize from NSSize **/
GS_GEOM_SCOPE CGSize
NSSizeToCGSize(NSSize size)
{
return (CGSize)size;
}
#endif

/** Constructs NSEdgeInsets. **/
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
GS_GEOM_SCOPE NSEdgeInsets
Expand Down Expand Up @@ -382,6 +508,12 @@ NSDivideRect(NSRect aRect,
GS_EXPORT NSRect
NSIntegralRect(NSRect aRect);

/** Returns a rectangle obtained by expanding aRect minimally
* so that all four of its defining components are integers,
* using the specified alignment options to control rounding behavior. */
GS_EXPORT NSRect
NSIntegralRectWithOptions(NSRect aRect, NSAlignmentOptions options);

/** Compute a Third Rectangle from Two Rectangles... **/

GS_GEOM_SCOPE NSRect
Expand Down
11 changes: 0 additions & 11 deletions MISSING
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,8 @@ NSGeometry:
<Foundation/NSValue.h>
<Foundation/NSCoder.h>

incompatible NSRectEdge
NSAlignmentOptions

@class NSString

NSRectFromCGRect()
NSRectToCGRect()
NSPointFromCGPoint()
NSPointToCGPoint()
NSSizeFromCGSize()
NSSizeToCGSize()
NSIntegralRectWithOptions()

@interface NSValue (NSValueGeometryExtensions)
@interface NSCoder (NSGeometryCoding)
@interface NSCoder (NSGeometryKeyedCoding)
Expand Down
45 changes: 44 additions & 1 deletion Source/NSGeometry.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,50 @@ static BOOL GSMacOSXCompatibleGeometry(void)
return rect;
}

NSRect
NSIntegralRectWithOptions(NSRect aRect, NSAlignmentOptions options)
{
NSRect rect;
CGFloat maxX, maxY;

if (NSIsEmptyRect(aRect))
return NSMakeRect(0, 0, 0, 0);

if (options & NSAlignMinXInward)
rect.origin.x = ceil(NSMinX(aRect));
else if (options & NSAlignMinXOutward)
rect.origin.x = floor(NSMinX(aRect));
else
rect.origin.x = round(NSMinX(aRect));

if (options & NSAlignMinYInward)
rect.origin.y = ceil(NSMinY(aRect));
else if (options & NSAlignMinYOutward)
rect.origin.y = floor(NSMinY(aRect));
else
rect.origin.y = round(NSMinY(aRect));

if (options & NSAlignMaxXInward)
maxX = floor(NSMaxX(aRect));
else if (options & NSAlignMaxXOutward)
maxX = ceil(NSMaxX(aRect));
else
maxX = round(NSMaxX(aRect));

if (options & NSAlignMaxYInward)
maxY = floor(NSMaxY(aRect));
else if (options & NSAlignMaxYOutward)
maxY = ceil(NSMaxY(aRect));
else
maxY = round(NSMaxY(aRect));

rect.size.width = maxX - rect.origin.x;
rect.size.height = maxY - rect.origin.y;

return rect;
}


void
NSDivideRect(NSRect aRect,
NSRect *slice,
Expand Down Expand Up @@ -508,4 +552,3 @@ read our strings (Both GNUstep and Mac OS X can read these as well). */
&& almostEqual(e1.right, e2.right)
);
}

Loading