Added checks on rectangle dimensions etc

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3891 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-03-10 13:34:29 +00:00
parent b9dce4ea64
commit 576950e10b
3 changed files with 177 additions and 31 deletions

View file

@ -1,8 +1,19 @@
Wed Mar 10 12:56:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSAffineTransform.m: Improved debug logging.
* Source/NSView.m: Add loads of checks to ensure that you can't set
illegal (negative) dimensions in frame or bounds. Add loads of code
to cope with scaling when bounds dimensions are zero.
Added logged warning if you set bounds dimensions to zero.
Changed debug logging to use the 'NSView' logging level.
Tue Mar 9 19:57:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Tue Mar 9 19:57:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Headers/AppKit/NSParagraphStyle.h: Tidied * Headers/AppKit/NSParagraphStyle.h: Tidied
* Headers/AppKit/NSTextStorage.h: Tidied
* Source/NSParagraphStyle.m: Implemented NSTextTab, NSParagraphStyle, * Source/NSParagraphStyle.m: Implemented NSTextTab, NSParagraphStyle,
and NSMutableParagraphStyle classes. and NSMutableParagraphStyle classes.
* Source/NSTextStorage.m: Added incomplete implementation.
1999-03-08 Adam Fedor <fedor@gnu.org> 1999-03-08 Adam Fedor <fedor@gnu.org>

View file

@ -29,6 +29,7 @@
#include <math.h> #include <math.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSException.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <AppKit/config.h> #include <AppKit/config.h>
@ -124,7 +125,7 @@ static NSAffineTransformStruct identityTransform = {
float det; float det;
det = A * D - B * C; det = A * D - B * C;
if (!det) if (det == 0)
{ {
NSLog (@"error: determinant of matrix is 0!"); NSLog (@"error: determinant of matrix is 0!");
return; return;
@ -137,7 +138,8 @@ static NSAffineTransformStruct identityTransform = {
newTX = (-D * TX + C * TY) / det; newTX = (-D * TX + C * TY) / det;
newTY = (B * TX - A * TY) / det; newTY = (B * TX - A * TY) / det;
NSDebugLog (@"inverse of matrix ((%f, %f) (%f, %f) (%f, %f))\n" NSDebugLLog(@"NSAffineTransform",
@"inverse of matrix ((%f, %f) (%f, %f) (%f, %f))\n"
@"is ((%f, %f) (%f, %f) (%f, %f))", @"is ((%f, %f) (%f, %f) (%f, %f))",
A, B, C, D, TX, TY, A, B, C, D, TX, TY,
newA, newB, newC, newD, newTX, newTY); newA, newB, newC, newD, newTX, newTY);

View file

@ -82,7 +82,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
flip = [matrixClass new]; flip = [matrixClass new];
[flip setTransformStruct: ats]; [flip setTransformStruct: ats];
NSDebugLog(@"Initialize NSView class\n"); NSDebugLLog(@"NSView", @"Initialize NSView class\n");
[self setVersion: 1]; [self setVersion: 1];
} }
} }
@ -108,6 +108,9 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
[super init]; // super is NSResponder [super init]; // super is NSResponder
NSAssert(frameRect.size.width >= 0 && frameRect.size.height >= 0,
@"illegal frame dimensions supplied");
frame = frameRect; // Set frame rectangle frame = frameRect; // Set frame rectangle
bounds.origin = NSZeroPoint; // Set bounds rectangle bounds.origin = NSZeroPoint; // Set bounds rectangle
bounds.size = frame.size; bounds.size = frame.size;
@ -393,6 +396,9 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
NSSize old_size = frame.size; NSSize old_size = frame.size;
NSAssert(frameRect.size.width >= 0 && frameRect.size.height >= 0,
@"illegal frame dimensions supplied");
if (coordinates_valid) if (coordinates_valid)
(*invalidateImp)(self, invalidateSel); (*invalidateImp)(self, invalidateSel);
frame = frameRect; frame = frameRect;
@ -423,6 +429,8 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
NSSize old_size = frame.size; NSSize old_size = frame.size;
NSAssert(newSize.width >= 0 && newSize.height >= 0,
@"illegal frame dimensions supplied");
if (coordinates_valid) if (coordinates_valid)
(*invalidateImp)(self, invalidateSel); (*invalidateImp)(self, invalidateSel);
frame.size = bounds.size = newSize; frame.size = bounds.size = newSize;
@ -469,20 +477,44 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (void) scaleUnitSquareToSize: (NSSize)newSize - (void) scaleUnitSquareToSize: (NSSize)newSize
{ {
float sx;
float sy;
NSAssert(newSize.width > 0 && newSize.height > 0, @"illegal size supplied");
if (coordinates_valid) if (coordinates_valid)
(*invalidateImp)(self, invalidateSel); (*invalidateImp)(self, invalidateSel);
if (!newSize.width)
newSize.width = 1;
if (!newSize.height)
newSize.height = 1;
bounds.size.width = frame.size.width / newSize.width; bounds.size.width = frame.size.width / newSize.width;
bounds.size.height = frame.size.height / newSize.height; bounds.size.height = frame.size.height / newSize.height;
is_rotated_or_scaled_from_base = YES; is_rotated_or_scaled_from_base = YES;
[boundsMatrix scaleBy: frame.size.width / bounds.size.width if (bounds.size.width == 0)
: frame.size.height / bounds.size.height]; {
if (frame.size.width == 0)
sx = 1;
else
sx = FLT_MAX;
}
else
{
sx = frame.size.width / bounds.size.width;
}
if (bounds.size.height == 0)
{
if (frame.size.height == 0)
sy = 1;
else
sy = FLT_MAX;
}
else
{
sy = frame.size.height / bounds.size.height;
}
[boundsMatrix scaleBy: sx : sy];
if (post_bounds_changes) if (post_bounds_changes)
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
@ -494,15 +526,39 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
float sx, sy; float sx, sy;
NSAssert(aRect.size.width >= 0 && aRect.size.height >= 0,
@"illegal bounds dimensions supplied");
if (coordinates_valid) if (coordinates_valid)
(*invalidateImp)(self, invalidateSel); (*invalidateImp)(self, invalidateSel);
if (aRect.size.width <= 0 || aRect.size.height <= 0)
[NSException raise: NSInvalidArgumentException
format: @"illegal bounds size supplied"];
bounds = aRect; bounds = aRect;
[boundsMatrix setFrameOrigin: NSMakePoint(-bounds.origin.x,-bounds.origin.y)]; [boundsMatrix setFrameOrigin: NSMakePoint(-bounds.origin.x,-bounds.origin.y)];
sx = frame.size.width / bounds.size.width;
sy = frame.size.height / bounds.size.height; if (bounds.size.width == 0)
{
if (frame.size.width == 0)
sx = 1;
else
sx = FLT_MAX;
}
else
{
sx = frame.size.width / bounds.size.width;
}
if (bounds.size.height == 0)
{
if (frame.size.height == 0)
sy = 1;
else
sy = FLT_MAX;
}
else
{
sy = frame.size.height / bounds.size.height;
}
[boundsMatrix scaleTo: sx : sy]; [boundsMatrix scaleTo: sx : sy];
if (sx != 1 || sy != 1) if (sx != 1 || sy != 1)
@ -532,14 +588,48 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
float sx, sy; float sx, sy;
NSAssert(newSize.width >= 0 && newSize.height >= 0,
@"illegal bounds dimensions supplied");
if (coordinates_valid) if (coordinates_valid)
(*invalidateImp)(self, invalidateSel); {
if (newSize.width <= 0 || newSize.height <= 0) (*invalidateImp)(self, invalidateSel);
[NSException raise: NSInvalidArgumentException }
format: @"illegal bounds size supplied"]; if (newSize.width == 0)
bounds.size = newSize; {
sx = frame.size.width / bounds.size.width; NSLog(@"[NSView -setBoundsSize:] zero width supplied");
sy = frame.size.height / bounds.size.height; }
if (newSize.height == 0)
{
NSLog(@"[NSView -setBoundsSize:] zero height supplied");
}
bounds.size = newSize;
if (bounds.size.width == 0)
{
if (frame.size.width == 0)
sx = 1;
else
sx = FLT_MAX;
}
else
{
sx = frame.size.width / bounds.size.width;
}
if (bounds.size.height == 0)
{
if (frame.size.height == 0)
sy = 1;
else
sy = FLT_MAX;
}
else
{
sy = frame.size.height / bounds.size.height;
}
[boundsMatrix scaleTo: sx : sy]; [boundsMatrix scaleTo: sx : sy];
if (sx != 1 || sy != 1) if (sx != 1 || sy != 1)
@ -578,7 +668,27 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (NSRect) centerScanRect: (NSRect)aRect - (NSRect) centerScanRect: (NSRect)aRect
{ {
return NSZeroRect; NSAffineTransform *matrix;
/*
* Hmm - we assume that the windows coordinate system is centered on the
* pixels of the screen - this may not be correct of course.
* Plus - this is all pretty meaningless is we are not in a window!
*/
matrix = [self _matrixToWindow];
aRect.origin = [matrix pointInMatrixSpace: aRect.origin];
aRect.size = [matrix sizeInMatrixSpace: aRect.size];
aRect.origin.x = floor(aRect.origin.x);
aRect.origin.y = floor(aRect.origin.y);
aRect.size.width = floor(aRect.size.width);
aRect.size.height = floor(aRect.size.height);
matrix = [self _matrixFromWindow];
aRect.origin = [matrix pointInMatrixSpace: aRect.origin];
aRect.size = [matrix sizeInMatrixSpace: aRect.size];
return aRect;
} }
- (NSPoint) convertPoint: (NSPoint)aPoint fromView: (NSView*)aView - (NSPoint) convertPoint: (NSPoint)aPoint fromView: (NSView*)aView
@ -845,8 +955,32 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if (changedSize && is_rotated_or_scaled_from_base) if (changedSize && is_rotated_or_scaled_from_base)
{ {
float sx = frame.size.width / bounds.size.width; float sx;
float sy = frame.size.height / bounds.size.height; float sy;
if (bounds.size.width == 0)
{
if (frame.size.width == 0)
sx = 1;
else
sx = FLT_MAX;
}
else
{
sx = frame.size.width / bounds.size.width;
}
if (bounds.size.height == 0)
{
if (frame.size.height == 0)
sy = 1;
else
sy = FLT_MAX;
}
else
{
sy = frame.size.height / bounds.size.height;
}
[boundsMatrix scaleTo: sx : sy]; [boundsMatrix scaleTo: sx : sy];
} }
@ -1071,9 +1205,8 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if (!window) if (!window)
return; return;
if (!boundsMatrix || !frameMatrix) if (coordinates_valid == NO)
NSLog (@"warning: %@ %p does not have it's PS matrices configured!", [self _rebuildCoordinates];
NSStringFromClass(isa), self);
[self lockFocus]; [self lockFocus];
[self drawRect: aRect]; [self drawRect: aRect];
@ -1569,7 +1702,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
NSDebugLog(@"NSView: start encoding\n"); NSDebugLLog(@"NSView", @"NSView: start encoding\n");
[aCoder encodeRect: frame]; [aCoder encodeRect: frame];
[aCoder encodeRect: bounds]; [aCoder encodeRect: bounds];
[aCoder encodeConditionalObject: super_view]; [aCoder encodeConditionalObject: super_view];
@ -1583,14 +1716,14 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &disable_autodisplay]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &disable_autodisplay];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &post_frame_changes]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &post_frame_changes];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &autoresize_subviews]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &autoresize_subviews];
NSDebugLog(@"NSView: finish encoding\n"); NSDebugLLog(@"NSView", @"NSView: finish encoding\n");
} }
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {
[super initWithCoder: aDecoder]; [super initWithCoder: aDecoder];
NSDebugLog(@"NSView: start decoding\n"); NSDebugLLog(@"NSView", @"NSView: start decoding\n");
frame = [aDecoder decodeRect]; frame = [aDecoder decodeRect];
bounds = [aDecoder decodeRect]; bounds = [aDecoder decodeRect];
super_view = [aDecoder decodeObject]; super_view = [aDecoder decodeObject];
@ -1604,7 +1737,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &disable_autodisplay]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &disable_autodisplay];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &post_frame_changes]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &post_frame_changes];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &autoresize_subviews]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &autoresize_subviews];
NSDebugLog(@"NSView: finish decoding\n"); NSDebugLLog(@"NSView", @"NSView: finish decoding\n");
return self; return self;
} }