2001-12-17 16:51:51 +00:00
|
|
|
|
/** <title>NSParagraphStyle</title>
|
1998-09-01 13:23:23 +00:00
|
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
|
<abstract>NSParagraphStyle and NSMutableParagraphStyle hold paragraph style
|
|
|
|
|
information NSTextTab holds information about a single tab stop</abstract>
|
1998-09-01 13:23:23 +00:00
|
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
|
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
Date March 1999
|
1998-09-01 13:23:23 +00:00
|
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
|
If not, write to the Free Software Foundation,
|
2005-05-26 02:52:46 +00:00
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1998-09-01 13:23:23 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-02-15 17:15:50 +00:00
|
|
|
|
/* To keep the allocation counts valid when swizzling the class in
|
|
|
|
|
[NSMutableParagraphStyle -copyWithZone:]. */
|
|
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
|
|
2003-01-26 17:57:39 +00:00
|
|
|
|
#include <Foundation/NSException.h>
|
2003-06-13 15:01:12 +00:00
|
|
|
|
#include "AppKit/NSParagraphStyle.h"
|
1998-09-01 13:23:23 +00:00
|
|
|
|
|
|
|
|
|
@implementation NSTextTab
|
1999-03-09 20:34:33 +00:00
|
|
|
|
|
|
|
|
|
- (id) copyWithZone: (NSZone*)aZone
|
|
|
|
|
{
|
|
|
|
|
if (NSShouldRetainWithZone(self, aZone) == YES)
|
2000-12-07 00:23:45 +00:00
|
|
|
|
return RETAIN(self);
|
1999-03-09 20:34:33 +00:00
|
|
|
|
return NSCopyObject(self, 0, aZone);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithType: (NSTextTabType)type location: (float)loc
|
|
|
|
|
{
|
|
|
|
|
self = [super init];
|
2000-12-12 21:14:00 +00:00
|
|
|
|
_tabStopType = type;
|
|
|
|
|
_location = loc;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 21:38:49 +00:00
|
|
|
|
- (NSComparisonResult) compare: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
float loc;
|
|
|
|
|
|
|
|
|
|
if (anObject == self)
|
|
|
|
|
return NSOrderedSame;
|
|
|
|
|
if (anObject == nil || ([anObject isKindOfClass: self->isa] == NO))
|
|
|
|
|
return NSOrderedAscending;
|
2000-12-12 21:14:00 +00:00
|
|
|
|
loc = ((NSTextTab*)anObject)->_location;
|
2002-11-02 23:17:23 +00:00
|
|
|
|
if (_location < loc)
|
1999-03-09 21:38:49 +00:00
|
|
|
|
return NSOrderedAscending;
|
2002-11-02 23:17:23 +00:00
|
|
|
|
else if (_location > loc)
|
1999-03-09 21:38:49 +00:00
|
|
|
|
return NSOrderedDescending;
|
|
|
|
|
else
|
|
|
|
|
return NSOrderedSame;
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
- (unsigned) hash
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
unsigned val = (unsigned)_location;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
|
2000-12-12 21:14:00 +00:00
|
|
|
|
val ^= (unsigned)_tabStopType;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isEqual: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
if (anObject == self)
|
|
|
|
|
return YES;
|
|
|
|
|
if ([anObject isKindOfClass: self->isa] == NO)
|
|
|
|
|
return NO;
|
2000-12-12 21:14:00 +00:00
|
|
|
|
else if (((NSTextTab*)anObject)->_tabStopType != _tabStopType)
|
1999-03-09 20:34:33 +00:00
|
|
|
|
return NO;
|
2000-12-12 21:14:00 +00:00
|
|
|
|
else if (((NSTextTab*)anObject)->_location != _location)
|
1999-03-09 20:34:33 +00:00
|
|
|
|
return NO;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (float) location
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _location;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSTextTabType) tabStopType
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _tabStopType;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
1998-09-01 13:23:23 +00:00
|
|
|
|
@implementation NSParagraphStyle
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
static NSParagraphStyle *defaultStyle = nil;
|
|
|
|
|
|
|
|
|
|
+ (NSParagraphStyle*) defaultParagraphStyle
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
1999-03-09 20:34:33 +00:00
|
|
|
|
if (defaultStyle == nil)
|
|
|
|
|
{
|
|
|
|
|
NSParagraphStyle *style = [[self alloc] init];
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 12; i++)
|
|
|
|
|
{
|
|
|
|
|
NSTextTab *tab;
|
|
|
|
|
|
2000-12-12 21:14:00 +00:00
|
|
|
|
/* FIXME: (i * 1) ? */
|
1999-03-09 20:34:33 +00:00
|
|
|
|
tab = [[NSTextTab alloc] initWithType: NSLeftTabStopType
|
2000-12-12 21:14:00 +00:00
|
|
|
|
location: (i * 1) * 28.0];
|
|
|
|
|
[style->_tabStops addObject: tab];
|
2000-12-07 00:23:45 +00:00
|
|
|
|
RELEASE(tab);
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
2000-12-12 21:14:00 +00:00
|
|
|
|
defaultStyle = style;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
return defaultStyle;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-26 16:51:21 +00:00
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
if (self == [NSParagraphStyle class])
|
|
|
|
|
{
|
|
|
|
|
/* Set the class version to 2, as the writing direction is now
|
|
|
|
|
stored in the encoding */
|
|
|
|
|
[self setVersion: 2];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSWritingDirection) defaultWritingDirectionForLanguage: (NSString*) language
|
|
|
|
|
{
|
2004-05-12 14:54:08 +00:00
|
|
|
|
static NSArray *rightToLeft;
|
|
|
|
|
NSWritingDirection writingDirection;
|
|
|
|
|
NSString *langCode = nil;
|
|
|
|
|
|
|
|
|
|
/* If language is 5/6 characters long with underscore in the middle,
|
|
|
|
|
treat it as ISO language-region format. */
|
|
|
|
|
if ([language length] == 5 && [language characterAtIndex: 2] == '_')
|
|
|
|
|
langCode = [language substringToIndex: 2];
|
|
|
|
|
else if ([language length] == 6 && [language characterAtIndex: 3] == '_')
|
|
|
|
|
langCode = [language substringToIndex: 3];
|
|
|
|
|
/* Else if it's just two or three chars long, treat as ISO 639 code. */
|
|
|
|
|
else if ([language length] == 2 || [language length] == 3)
|
|
|
|
|
langCode = language;
|
|
|
|
|
|
|
|
|
|
if (!rightToLeft)
|
|
|
|
|
// Holds languages whose current scripts are written right to left.
|
|
|
|
|
rightToLeft = [[NSArray alloc] initWithObjects: @"ar", @"ara", @"arc",
|
|
|
|
|
@"chi", @"fa", @"fas", @"he", @"heb", @"iw",
|
|
|
|
|
@"ji", @"kas", @"ks", @"ku", @"kur", @"pa",
|
|
|
|
|
@"pan", @"per" @"ps", @"pus", @"sd", @"snd",
|
|
|
|
|
@"syr", @"tk", @"tmh", @"tuk", @"ug",
|
|
|
|
|
@"uig", @"ur," @"urd", @"yi", @"yid", @"zh",
|
|
|
|
|
@"zho", nil];
|
|
|
|
|
if ([rightToLeft containsObject: langCode] == YES)
|
|
|
|
|
writingDirection = NSWritingDirectionRightToLeft;
|
|
|
|
|
else // If it's not RTL, assume LTR.
|
|
|
|
|
writingDirection = NSWritingDirectionLeftToRight;
|
|
|
|
|
|
|
|
|
|
return writingDirection;
|
2003-04-26 16:51:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
- (void) dealloc
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
1999-03-09 20:34:33 +00:00
|
|
|
|
if (self == defaultStyle)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Argh - attempt to dealloc the default paragraph style!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2000-12-12 21:14:00 +00:00
|
|
|
|
RELEASE (_tabStops);
|
1999-03-09 20:34:33 +00:00
|
|
|
|
[super dealloc];
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
- (id) init
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
1999-03-09 20:34:33 +00:00
|
|
|
|
self = [super init];
|
2000-12-12 21:14:00 +00:00
|
|
|
|
_alignment = NSNaturalTextAlignment;
|
|
|
|
|
_firstLineHeadIndent = 0.0;
|
|
|
|
|
_headIndent = 0.0;
|
|
|
|
|
_lineBreakMode = NSLineBreakByWordWrapping;
|
|
|
|
|
_lineSpacing = 0.0;
|
|
|
|
|
_maximumLineHeight = 0.0;
|
|
|
|
|
_minimumLineHeight = 0.0;
|
|
|
|
|
_paragraphSpacing = 0.0;
|
|
|
|
|
_tailIndent = 0.0;
|
2003-04-26 16:51:21 +00:00
|
|
|
|
_baseDirection = NSWritingDirectionNaturalDirection;
|
2000-12-12 21:14:00 +00:00
|
|
|
|
_tabStops = [[NSMutableArray allocWithZone: [self zone]]
|
|
|
|
|
initWithCapacity: 12];
|
1999-03-09 20:34:33 +00:00
|
|
|
|
return self;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
1999-03-09 20:34:33 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* "Leading": distance between the bottom of one line fragment and top
|
|
|
|
|
* of next (applied between lines in the same container).
|
|
|
|
|
* Can't be negative. This value is included in the line fragment
|
|
|
|
|
* heights in layout manager.
|
|
|
|
|
*/
|
|
|
|
|
- (float) lineSpacing
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _lineSpacing;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
/*
|
|
|
|
|
* Distance between the bottom of this paragraph and top of next.
|
|
|
|
|
*/
|
|
|
|
|
- (float) paragraphSpacing
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _paragraphSpacing;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
- (NSTextAlignment) alignment
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _alignment;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
/*
|
|
|
|
|
* The following values are relative to the appropriate margin
|
|
|
|
|
* (depending on the paragraph direction)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Distance from margin to front edge of paragraph
|
|
|
|
|
*/
|
|
|
|
|
- (float) headIndent
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _headIndent;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Distance from margin to back edge of paragraph; if negative or 0,
|
|
|
|
|
* from other margin
|
|
|
|
|
*/
|
|
|
|
|
- (float) tailIndent
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _tailIndent;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
/*
|
|
|
|
|
* Distance from margin to edge appropriate for text direction
|
|
|
|
|
*/
|
|
|
|
|
- (float) firstLineHeadIndent
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _firstLineHeadIndent;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
/*
|
|
|
|
|
* Distance from margin to tab stops
|
|
|
|
|
*/
|
|
|
|
|
- (NSArray *) tabStops
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return AUTORELEASE ([_tabStops copyWithZone: NSDefaultMallocZone ()]);
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
/*
|
|
|
|
|
* Line height is the distance from bottom of descenders to to
|
|
|
|
|
* of ascenders; basically the line fragment height. Does not include
|
|
|
|
|
* lineSpacing (which is added after this computation).
|
|
|
|
|
*/
|
|
|
|
|
- (float) minimumLineHeight
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _minimumLineHeight;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
/*
|
|
|
|
|
* 0 implies no maximum.
|
|
|
|
|
*/
|
|
|
|
|
- (float) maximumLineHeight
|
1998-09-01 13:23:23 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _maximumLineHeight;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
- (NSLineBreakMode) lineBreakMode
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return _lineBreakMode;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-26 16:51:21 +00:00
|
|
|
|
- (NSWritingDirection) baseWritingDirection
|
|
|
|
|
{
|
|
|
|
|
return _baseDirection;
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)aZone
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
if (NSShouldRetainWithZone (self, aZone) == YES)
|
|
|
|
|
return RETAIN (self);
|
1999-03-09 20:34:33 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSParagraphStyle *c;
|
|
|
|
|
|
2000-12-12 21:14:00 +00:00
|
|
|
|
c = (NSParagraphStyle*)NSCopyObject (self, 0, aZone);
|
|
|
|
|
c->_tabStops = [_tabStops mutableCopyWithZone: aZone];
|
1999-03-09 20:34:33 +00:00
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) mutableCopyWithZone: (NSZone*)aZone
|
|
|
|
|
{
|
|
|
|
|
NSMutableParagraphStyle *c;
|
|
|
|
|
|
1999-03-09 21:38:49 +00:00
|
|
|
|
c = [[NSMutableParagraphStyle allocWithZone: aZone] init];
|
1999-03-09 20:34:33 +00:00
|
|
|
|
[c setParagraphStyle: self];
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
2006-10-15 08:34:47 +00:00
|
|
|
|
if ([aCoder allowsKeyedCoding])
|
1999-03-09 20:34:33 +00:00
|
|
|
|
{
|
2006-06-04 16:31:30 +00:00
|
|
|
|
// TODO_NIB: Determine keys for NSParagraphStyle, if there are any.
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
2006-06-04 16:31:30 +00:00
|
|
|
|
else
|
2003-04-26 16:51:21 +00:00
|
|
|
|
{
|
2006-06-04 16:31:30 +00:00
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(NSTextAlignment) at: &_alignment];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(NSLineBreakMode)
|
|
|
|
|
at: &_lineBreakMode];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(float) at: &_firstLineHeadIndent];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(float) at: &_headIndent];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(float) at: &_lineSpacing];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(float) at: &_maximumLineHeight];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(float) at: &_minimumLineHeight];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(float) at: &_paragraphSpacing];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(float) at: &_tailIndent];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tab stops don't conform to NSCoding - so we do it the long way.
|
|
|
|
|
*/
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
|
|
|
|
|
_tabStops = [[NSMutableArray alloc] initWithCapacity: count];
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
float locations[count];
|
|
|
|
|
NSTextTabType types[count];
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
[aCoder decodeArrayOfObjCType: @encode(float)
|
|
|
|
|
count: count
|
|
|
|
|
at: locations];
|
|
|
|
|
[aCoder decodeArrayOfObjCType: @encode(NSTextTabType)
|
|
|
|
|
count: count
|
|
|
|
|
at: types];
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
NSTextTab *tab;
|
|
|
|
|
|
|
|
|
|
tab = [NSTextTab alloc];
|
|
|
|
|
tab = [tab initWithType: types[i] location: locations[i]];
|
|
|
|
|
[_tabStops addObject: tab];
|
|
|
|
|
RELEASE (tab);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([aCoder versionForClassName: @"NSParagraphStyle"] >= 2)
|
|
|
|
|
{
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(int) at: &_baseDirection];
|
|
|
|
|
}
|
2003-04-26 16:51:21 +00:00
|
|
|
|
}
|
1999-03-09 20:34:33 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
2006-10-15 08:34:47 +00:00
|
|
|
|
if ([aCoder allowsKeyedCoding])
|
1999-03-09 20:34:33 +00:00
|
|
|
|
{
|
2006-06-04 16:31:30 +00:00
|
|
|
|
// TODO_NIB: Determine keys for NSParagraphStyle, if there are any.
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(NSTextAlignment) at: &_alignment];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(NSLineBreakMode)
|
|
|
|
|
at: &_lineBreakMode];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_firstLineHeadIndent];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_headIndent];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_lineSpacing];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_maximumLineHeight];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_minimumLineHeight];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_paragraphSpacing];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_tailIndent];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tab stops don't conform to NSCoding - so we do it the long way.
|
|
|
|
|
*/
|
|
|
|
|
count = [_tabStops count];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
|
|
|
|
|
if (count > 0)
|
1999-03-09 20:34:33 +00:00
|
|
|
|
{
|
2006-06-04 16:31:30 +00:00
|
|
|
|
float locations[count];
|
|
|
|
|
NSTextTabType types[count];
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
NSTextTab *tab = [_tabStops objectAtIndex: i];
|
|
|
|
|
|
|
|
|
|
locations[i] = [tab location];
|
|
|
|
|
types[i] = [tab tabStopType];
|
|
|
|
|
}
|
|
|
|
|
[aCoder encodeArrayOfObjCType: @encode(float)
|
|
|
|
|
count: count
|
|
|
|
|
at: locations];
|
|
|
|
|
[aCoder encodeArrayOfObjCType: @encode(NSTextTabType)
|
|
|
|
|
count: count
|
|
|
|
|
at: types];
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
2006-06-04 16:31:30 +00:00
|
|
|
|
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(int) at: &_baseDirection];
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
|
2003-02-23 23:05:43 +00:00
|
|
|
|
- (BOOL) isEqual: (id)aother
|
|
|
|
|
{
|
|
|
|
|
NSParagraphStyle *other = aother;
|
|
|
|
|
if (other == self)
|
|
|
|
|
return YES;
|
|
|
|
|
if ([other isKindOfClass: [NSParagraphStyle class]] == NO)
|
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
|
|
#define C(x) if (x != other->x) return NO
|
|
|
|
|
C(_lineSpacing);
|
|
|
|
|
C(_paragraphSpacing);
|
|
|
|
|
C(_headIndent);
|
|
|
|
|
C(_tailIndent);
|
|
|
|
|
C(_firstLineHeadIndent);
|
|
|
|
|
C(_minimumLineHeight);
|
|
|
|
|
C(_maximumLineHeight);
|
|
|
|
|
C(_alignment);
|
|
|
|
|
C(_lineBreakMode);
|
2003-04-26 16:51:21 +00:00
|
|
|
|
C(_baseDirection);
|
2003-02-23 23:05:43 +00:00
|
|
|
|
#undef C
|
|
|
|
|
|
|
|
|
|
return [_tabStops isEqualToArray: other->_tabStops];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned int) hash
|
|
|
|
|
{
|
|
|
|
|
return _alignment + _lineBreakMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1998-09-01 13:23:23 +00:00
|
|
|
|
@end
|
1999-03-09 20:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSMutableParagraphStyle
|
|
|
|
|
|
|
|
|
|
+ (NSParagraphStyle*) defaultParagraphStyle
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
return AUTORELEASE ([[NSParagraphStyle defaultParagraphStyle] mutableCopy]);
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setLineSpacing: (float)aFloat
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
NSAssert (aFloat >= 0.0, NSInvalidArgumentException);
|
|
|
|
|
_lineSpacing = aFloat;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setParagraphSpacing: (float)aFloat
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
NSAssert (aFloat >= 0.0, NSInvalidArgumentException);
|
|
|
|
|
_paragraphSpacing = aFloat;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setAlignment: (NSTextAlignment)newAlignment
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
_alignment = newAlignment;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setFirstLineHeadIndent: (float)aFloat
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
NSAssert (aFloat >= 0.0, NSInvalidArgumentException);
|
|
|
|
|
_firstLineHeadIndent = aFloat;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setHeadIndent: (float)aFloat
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
NSAssert (aFloat >= 0.0, NSInvalidArgumentException);
|
|
|
|
|
_headIndent = aFloat;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setTailIndent: (float)aFloat
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
_tailIndent = aFloat;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setLineBreakMode: (NSLineBreakMode)mode
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
_lineBreakMode = mode;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setMinimumLineHeight: (float)aFloat
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
NSAssert (aFloat >= 0.0, NSInvalidArgumentException);
|
|
|
|
|
_minimumLineHeight = aFloat;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setMaximumLineHeight: (float)aFloat
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
NSAssert (aFloat >= 0.0, NSInvalidArgumentException);
|
|
|
|
|
_maximumLineHeight = aFloat;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-26 16:51:21 +00:00
|
|
|
|
- (void) setBaseWritingDirection: (NSWritingDirection)direction
|
|
|
|
|
{
|
2006-11-20 16:20:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* FIXME there is some confusion regarding natural writing direction.
|
|
|
|
|
*
|
|
|
|
|
* this method is documented as setting
|
|
|
|
|
* NSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft
|
|
|
|
|
* based on the users language preferences.
|
|
|
|
|
* when encountering NSWritingDirectionNaturalDirection
|
|
|
|
|
*
|
|
|
|
|
* NSWritingDirectionNatural constant is documented as using the
|
|
|
|
|
* unicode bidi algorithm.
|
|
|
|
|
*
|
|
|
|
|
* no idea what the constant name or behaviour actually is.
|
|
|
|
|
*/
|
2003-04-26 16:51:21 +00:00
|
|
|
|
_baseDirection = direction;
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 21:38:49 +00:00
|
|
|
|
- (void) addTabStop: (NSTextTab*)anObject
|
1999-03-09 20:34:33 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
unsigned count = [_tabStops count];
|
1999-03-09 21:38:49 +00:00
|
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
[_tabStops addObject: anObject];
|
1999-03-09 21:38:49 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
while (count-- > 0)
|
|
|
|
|
{
|
|
|
|
|
NSTextTab *tab;
|
|
|
|
|
|
2000-12-12 21:14:00 +00:00
|
|
|
|
tab = [_tabStops objectAtIndex: count];
|
1999-03-09 21:38:49 +00:00
|
|
|
|
if ([tab compare: anObject] != NSOrderedDescending)
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
[_tabStops insertObject: anObject atIndex: count + 1];
|
1999-03-09 21:38:49 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-12-12 21:14:00 +00:00
|
|
|
|
[_tabStops insertObject: anObject atIndex: 0];
|
1999-03-09 21:38:49 +00:00
|
|
|
|
}
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 21:38:49 +00:00
|
|
|
|
- (void) removeTabStop: (NSTextTab*)anObject
|
1999-03-09 20:34:33 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
unsigned i = [_tabStops indexOfObject: anObject];
|
1999-03-09 21:38:49 +00:00
|
|
|
|
|
|
|
|
|
if (i != NSNotFound)
|
2000-12-12 21:14:00 +00:00
|
|
|
|
[_tabStops removeObjectAtIndex: i];
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setTabStops: (NSArray *)array
|
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
if (array != _tabStops)
|
1999-03-09 20:34:33 +00:00
|
|
|
|
{
|
2000-12-12 21:14:00 +00:00
|
|
|
|
[_tabStops removeAllObjects];
|
|
|
|
|
[_tabStops addObjectsFromArray: array];
|
|
|
|
|
[_tabStops sortUsingSelector: @selector(compare:)];
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setParagraphStyle: (NSParagraphStyle*)obj
|
|
|
|
|
{
|
|
|
|
|
NSMutableParagraphStyle *p = (NSMutableParagraphStyle*)obj;
|
|
|
|
|
|
1999-03-09 21:38:49 +00:00
|
|
|
|
if (p == self)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Can add tab stops without sorting as we know they are already sorted. */
|
2000-12-12 21:14:00 +00:00
|
|
|
|
[_tabStops removeAllObjects];
|
|
|
|
|
[_tabStops addObjectsFromArray: p->_tabStops];
|
1999-03-09 21:38:49 +00:00
|
|
|
|
|
2000-12-12 21:14:00 +00:00
|
|
|
|
_alignment = p->_alignment;
|
|
|
|
|
_firstLineHeadIndent = p->_firstLineHeadIndent;
|
|
|
|
|
_headIndent = p->_headIndent;
|
|
|
|
|
_lineBreakMode = p->_lineBreakMode;
|
|
|
|
|
_lineSpacing = p->_lineSpacing;
|
|
|
|
|
_maximumLineHeight = p->_maximumLineHeight;
|
|
|
|
|
_minimumLineHeight = p->_minimumLineHeight;
|
|
|
|
|
_paragraphSpacing = p->_paragraphSpacing;
|
|
|
|
|
_tailIndent = p->_tailIndent;
|
2003-04-26 16:51:21 +00:00
|
|
|
|
_baseDirection = p->_baseDirection;
|
1999-03-09 20:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)aZone
|
|
|
|
|
{
|
|
|
|
|
NSMutableParagraphStyle *c;
|
|
|
|
|
|
|
|
|
|
c = (NSMutableParagraphStyle*)NSCopyObject (self, 0, aZone);
|
2003-02-15 17:15:50 +00:00
|
|
|
|
GSDebugAllocationRemove(c->isa, c);
|
2003-01-26 19:21:40 +00:00
|
|
|
|
c->isa = [NSParagraphStyle class];
|
2003-02-15 17:15:50 +00:00
|
|
|
|
GSDebugAllocationAdd(c->isa, c);
|
2003-01-26 19:21:40 +00:00
|
|
|
|
c->_tabStops = [_tabStops mutableCopyWithZone: aZone];
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-09 20:34:33 +00:00
|
|
|
|
@end
|