Merge in text-system-branch.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15718 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-01-26 19:21:40 +00:00
parent 3c890f8d74
commit 9407b0bfca
27 changed files with 9939 additions and 7646 deletions

112
ChangeLog
View file

@ -1,3 +1,115 @@
2003-01-26 19:17 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/GSFontInfo.h, Headers/gnustep/gui/NSFont.h,
Headers/gnustep/gui/NSLayoutManager.h, Headers/gnustep/gui/NSText.h,
Headers/gnustep/gui/NSTextContainer.h,
Headers/gnustep/gui/NSTextStorage.h,
Headers/gnustep/gui/NSTextView.h, Source/GNUmakefile,
Source/GSFontInfo.m, Source/GSTextStorage.m, Source/NSFont.m,
Source/NSLayoutManager.m, Source/NSParagraphStyle.m,
Source/NSSecureTextField.m, Source/NSText.m,
Source/NSTextContainer.m, Source/NSTextStorage.m,
Source/NSTextView.m, Headers/gnustep/gui/GSHorizontalTypesetter.h,
Headers/gnustep/gui/GSLayoutManager.h,
Headers/gnustep/gui/GSLayoutManager_internal.h,
Headers/gnustep/gui/GSTypesetter.h, Source/GSHorizontalTypesetter.m,
Source/GSLayoutManager.m, Source/GSTypesetter.m,
Source/NSTextView_actions.m: Merge in text-system-branch with the new
implementation of the text system.
2002-12-13 02:00 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/NSText.h, Headers/gnustep/gui/NSTextView.h,
Source/NSText.m, Source/NSTextView.m: Moved ivars from NSText to
NSTextView. Added or updated documentation for many methods. Marked
primitive and non-openstep methods.
* Source/GSHorizontalTypesetter.m, Source/GSLayoutManager.m,
Source/GSTextStorage.m, Source/NSTextContainer.m,
Source/NSTextStorage.m: Cleaned up includes.
2002-12-01 13:27 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/GSLayoutManager_internal.h,
Source/GSLayoutManager.m: Clean ups. Remove some old stuff. Add
some more comments.
2002-11-26 16:37 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/GSTypesetter.h, Source/GSTypesetter.m,
Source/GSHorizontalTypesetter.m: Remove
-baselineOffsetInLayoutManager:glyphIndex: method. Cleanups. Changed
to conform to coding standards.
2002-11-26 16:29 Alexander Malmberg <alexander@malmberg.org>
* Source/NSLayoutManager.m: Changed to conform to coding
standards. Cleanups.
2002-11-26 15:41 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/GSLayoutManager_internal.h,
Source/GSLayoutManager.m: Changed to conform to coding standards.
Cleanups. Moved some more NSTextView references to NSLayoutManager.
Use _run_cache_attributes::, _run_copy_attributes::, and
_run_free_attributes: methods instead of functions.
(-_run_cache_attributes::): Ask typesetter for font to use and call
-substituteFontForFont:.
* Source/NSLayoutManager.m: Moved NSTextView references here.
2002-11-26 12:52 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/GSFontInfo.h, Headers/gnustep/gui/NSFont.h,
Source/GSFontInfo.m, Source/NSFont.m: Add proper handling of
screen/printer fonts. Changes the backend GSFontInfo interface.
2002-11-24 20:58 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/NSMenu.h: Declare NSMutableArray.
2002-11-24 01:10 Alexander Malmberg <alexander@malmberg.org>
* Source/NSSpellChecker (-_launchSpellCheckerForLanguage:): Don't
pass the error message through printf expansion twice.
2002-11-24 00:56 Alexander Malmberg <alexander@malmberg.org>
* Source/GSFontInfo.m (-defaultLineHeightForFont): Round the linegap
to whole points.
2002-11-23 22:55 Alexander Malmberg <alexander@malmberg.org>
* Source/NSSecureTextField: Update to work with new text system.
2002-11-23 22:30 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/NSTextContainer.h,
Headers/gnustep/gui/NSTextStorage.h Source/NSTextStorage.m: Use
GSLayoutManager instead of NSLayoutManager in these classes.
2002-11-23 21:40 Alexander Malmberg <alexander@malmberg.org>
* Source/NSParagraphStyle ([NSMutableParagraphStyle -copyWithZone:]):
Implement.
2002-11-23 21:31 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/GSHorizontalTypesetter.h,
Headers/gnustep/gui/GSLayoutManager.h,
Headers/gnustep/gui/GSLayoutManager_internal.h,
Headers/gnustep/gui/GSTypesetter.h, Source/GSHorizontalTypesetter.m,
Source/GSLayoutManager.m, Source/GSTypesetter.m,
Headers/gnustep/gui/NSLayoutManager.h, Source/GNUmakefile,
Source/NSLayoutManager.m: Add the new text system.
2002-11-23 18:45 Alexander Malmberg <alexander@malmberg.org>
* Source/NSTextContainer: Implement -lineFragmentRectForProposedRect:
sweepDirection:movementDirection:remainingRect:.
2003-01-26 18:54 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/NSParagraphStyle.h,

View file

@ -76,7 +76,8 @@
+ (void) setDefaultClass: (Class)defaultClass;
+ (GSFontInfo*) fontInfoForFontName: (NSString*)fontName
matrix: (const float *)fmatrix;
matrix: (const float *)fmatrix
screenFont: (BOOL)screenFont;
+ (int) weightForString: (NSString *)weightString;
+ (NSString *) stringForWeight: (int)weight;

View file

@ -0,0 +1,75 @@
/*
GSHorizontalTypesetter.h
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Alexander Malmberg <alexander@malmberg.org>
Date: 2002
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,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GNUstep_H_GSHorizontalTypesetter
#define _GNUstep_H_GSHorizontalTypesetter
#include <AppKit/GSTypesetter.h>
@class NSLock;
@class GSLayoutManager, NSTextContainer, NSTextStorage;
@class NSDictionary;
@class NSParagraphStyle, NSFont;
@interface GSHorizontalTypesetter : GSTypesetter
{
NSLock *lock;
GSLayoutManager *curLayoutManager;
NSTextContainer *curTextContainer;
NSTextStorage *curTextStorage;
unsigned int curGlyph;
NSPoint curPoint;
NSParagraphStyle *curParagraphStyle;
NSRange paragraphRange; /* characters */
NSDictionary *curAttributes;
NSRange attributeRange; /* characters */
struct
{
BOOL explicit_kern;
float kern;
float baseline_offset;
int superscript;
} attributes;
NSFont *curFont;
NSRange fontRange; /* glyphs */
struct GSHorizontalTypesetter_glyph_cache_s *cache;
unsigned int cache_base, cache_size, cache_length;
BOOL at_end;
}
+(GSHorizontalTypesetter *) sharedInstance;
@end
#endif

View file

@ -0,0 +1,292 @@
/*
GSLayoutManager.h
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Alexander Malmberg <alexander@malmberg.org>
Date: 2002
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,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GNUstep_H_GSLayoutManager
#define _GNUstep_H_GSLayoutManager
#include <Foundation/NSObject.h>
#include <Foundation/NSGeometry.h>
#include <AppKit/NSFont.h>
@class GSTypesetter;
@class NSTextStorage,NSTextContainer;
typedef enum
{
NSGlyphInscribeBase = 0,
NSGlyphInscribeBelow = 1,
NSGlyphInscribeAbove = 2,
NSGlyphInscribeOverstrike = 3,
NSGlyphInscribeOverBelow = 4
} NSGlyphInscription;
@interface GSLayoutManager : NSObject
{
@protected
NSTextStorage *_textStorage;
id _delegate;
BOOL usesScreenFonts;
BOOL backgroundLayoutEnabled;
BOOL showsInvisibleCharacters;
BOOL showsControlCharacters;
GSTypesetter *typesetter;
/* Glyph storage */
/* Skip list of runs */
struct GSLayoutManager_glyph_run_head_s *glyphs;
/* number of runs created from existing text (ie. not as a result of
stuff being invalidated) */
int glyph_num_end_runs;
/* Layout storage */
/* OPT: This is just a simple implementation that should let me figure out
how it's supposed to work. It's functional and correct, but it isn't fast. */
int layout_glyph, layout_char;
struct GSLayoutManager_textcontainer_s *textcontainers;
int num_textcontainers;
NSRect extra_rect, extra_used_rect;
NSTextContainer *extra_textcontainer;
/* For -rectArrayForGlyphRange:... */
NSRect *rect_array;
int rect_array_size;
}
- (NSTextStorage *) textStorage;
- (void) setTextStorage: (NSTextStorage *)aTextStorage;
- (void) replaceTextStorage: (NSTextStorage *)newTextStorage;
- (id) delegate;
- (void) setDelegate: (id)aDelegate;
- (void) setBackgroundLayoutEnabled: (BOOL)flag;
- (BOOL) backgroundLayoutEnabled;
- (void) setShowsInvisibleCharacters: (BOOL)flag;
- (BOOL) showsInvisibleCharacters;
- (void) setShowsControlCharacters: (BOOL)flag;
- (BOOL) showsControlCharacters;
/** Font handling **/
- (BOOL) usesScreenFonts;
- (void) setUsesScreenFonts: (BOOL)flag;
- (NSFont *) substituteFontForFont: (NSFont *)originalFont;
/*
(?)
Sent by the NSTextStorage. mask tells us if attributes or characters (or
both) have been changed. range is the range of directly modified
characters. invalidatedRange is the range of characters affected by the
changes (contains range but may be larger due to eg. attribute fixing).
If characters have been edited, lengthChange has the text length delta.
*/
- (void) textStorage: (NSTextStorage *)aTextStorage
edited: (unsigned int)mask
range: (NSRange)range
changeInLength: (int)lengthChange
invalidatedRange: (NSRange)invalidatedRange;
@end
@interface GSLayoutManager (glyphs)
/** Glyph handling **/
/*
Mark the glyphs for the characters in aRange as invalid. lengthChange
is the text length delta. If not NULL, the range of characters actually
affected (_after_ the change) will be returned in actualRange.
*/
- (void) invalidateGlyphsForCharacterRange: (NSRange)aRange
changeInLength: (int)lengthChange
actualCharacterRange: (NSRange *)actualRange;
/*
These are internal methods and should _not_ be called.
*/
- (void) insertGlyph: (NSGlyph)aGlyph
atGlyphIndex: (unsigned int)glyphIndex
characterIndex: (unsigned int)charIndex;
- (void) replaceGlyphAtIndex: (unsigned int)glyphIndex
withGlyph: (NSGlyph)newGlyph;
- (void) deleteGlyphsInRange: (NSRange)aRange;
- (void) setCharacterIndex: (unsigned int)charIndex
forGlyphAtIndex: (unsigned int)glyphIndex;
/* Returns total number of glyphs. */
- (unsigned int) numberOfGlyphs;
/* Returns the glyph at glyphIndex or raises an NSRangeException if the
index is invalid (past the end of the glyphs). */
- (NSGlyph) glyphAtIndex: (unsigned int)glyphIndex;
/* Returns the glyph at glyphIndex and sets isValidIndex to YES if the index
is valid. Otherwise, the return value is arbitrary and isValidIndex is set
to NO. */
- (NSGlyph) glyphAtIndex: (unsigned int)glyphIndex
isValidIndex: (BOOL *)isValidIndex;
/* Copies displayed glyphs to glyphArray for glyphRange. Returns the number
of glyphs actually copied to the array. NSRangeException of the range is
invalid (extends beyond the end of glyphs). */
- (unsigned int) getGlyphs: (NSGlyph *)glyphArray
range: (NSRange)glyphRange;
/* Return the first character for the glyph at glyphIndex.
(NSRangeException?) */
- (unsigned int) characterIndexForGlyphAtIndex: (unsigned int)glyphIndex;
/* Returns the range of glyphs for the characters in charRange. If
actualRange isn't NULL, the exact range of characters for the glyphs in the
returned range is returned there. */
- (NSRange) glyphRangeForCharacterRange: (NSRange)charRange
actualCharacterRange: (NSRange *)actualCharRange;
/* Returns the range of characters for the glyphs in glyphRange. Returns
the actual glyphs for the characters in the range in actualGlyphRange, if
it isn't NULL. */
- (NSRange) characterRangeForGlyphRange: (NSRange)glyphRange
actualGlyphRange: (NSRange *)actualGlyphRange;
/* These can be used to set arbitrary tags on individual glyphs.
Non-negative tags are reserved. You must provide storage yourself (by
subclassing). */
- (void) setIntAttribute: (int)attributeTag
value: (int)anInt
forGlyphAtIndex: (unsigned int)glyphIndex;
- (int) intAttribute: (int)attributeTag
forGlyphAtIndex: (unsigned int)glyphIndex;
- (void) setAttachmentSize: (NSSize)attachmentSize
forGlyphRange: (NSRange)glyphRange; /* not OPENSTEP */
/* Returns the font actually used for a range of glyphs. This isn't
necessarily the font specified by NSFontAttributeName; both the typesetter
and the layout manager can substitute a different font (the typesetter might
eg. substitute a smaller font for sub-/super-scripted text, and the layout
manager might be substituting screen fonts. */
- (NSFont *) effectiveFontForGlyphAtIndex: (unsigned int)glyphIndex
range: (NSRange *)range; /* GNUstep extension */
- (void) setDrawsOutsideLineFragment: (BOOL)flag
forGlyphAtIndex: (unsigned int)glyphIndex;
- (BOOL) drawsOutsideLineFragmentForGlyphAtIndex: (unsigned int) glyphIndex;
- (void) setNotShownAttribute: (BOOL)flag
forGlyphAtIndex: (unsigned int)glyphIndex;
- (BOOL) notShownAttributeForGlyphAtIndex: (unsigned int) glyphIndex;
@end
@interface GSLayoutManager (layout)
/** Text containers **/
- (NSArray *) textContainers;
- (void) addTextContainer: (NSTextContainer *)container;
- (void) insertTextContainer: (NSTextContainer*)aTextContainer
atIndex: (unsigned int)index;
- (void) removeTextContainerAtIndex: (unsigned int)index;
- (void) textContainerChangedGeometry: (NSTextContainer *)aContainer;
/** Layout **/
- (void) invalidateLayoutForCharacterRange: (NSRange)aRange
isSoft: (BOOL)flag
actualCharacterRange: (NSRange *)actualRange;
- (void) setTextContainer: (NSTextContainer *)aTextContainer
forGlyphRange: (NSRange)glyphRange;
- (void) setLineFragmentRect: (NSRect)fragmentRect
forGlyphRange: (NSRange)glyphRange
usedRect: (NSRect)usedRect;
- (void) setLocation: (NSPoint)location
forStartOfGlyphRange: (NSRange)glyphRange;
- (NSTextContainer *) textContainerForGlyphAtIndex: (unsigned int)glyphIndex
effectiveRange: (NSRange *)effectiveRange;
- (NSRect) lineFragmentRectForGlyphAtIndex: (unsigned int)glyphIndex
effectiveRange: (NSRange *)effectiveGlyphRange;
- (NSRect) lineFragmentUsedRectForGlyphAtIndex: (unsigned int)glyphIndex
effectiveRange: (NSRange *)effectiveGlyphRange;
/* Extension, but without this, there's no way to get the starting locations
of the nominally spaced glyphs. */
- (NSRange) rangeOfNominallySpacedGlyphsContainingIndex:(unsigned int)glyphIndex
startLocation: (NSPoint *)p;
- (NSRange) rangeOfNominallySpacedGlyphsContainingIndex:(unsigned int)glyphIndex;
/* The union of all line frag rects' used rects. (TODO: shouldn't this be
just the union of all the line frag rects?) */
- (NSRect) usedRectForTextContainer: (NSTextContainer *)container;
- (NSRange) glyphRangeForTextContainer: (NSTextContainer *)container;
- (unsigned int) firstUnlaidCharacterIndex;
- (unsigned int) firstUnlaidGlyphIndex;
- (void) getFirstUnlaidCharacterIndex: (unsigned int *)charIndex
glyphIndex: (unsigned int *)glyphIndex;
@end
#endif

View file

@ -0,0 +1,269 @@
/*
GSLayoutManager_internal.h
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Alexander Malmberg <alexander@malmberg.org>
Date: 2002
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,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GNUstep_H_GSLayoutManager_internal
#define _GNUstep_H_GSLayoutManager_internal
#include <AppKit/GSLayoutManager.h>
/*
TODO:
Since temporary attributes are set for _character_ ranges and not _glyph_
ranges, a bunch of things could be simplified here (in particular, a
character can't be in several runs anymore, so there's no need to worry
about that or search over run boundaries).
(2002-11-27): All comments should be clarified now.
*/
/* Logarithmic time for lookups et al for up to 2^SKIP_LIST_DEPTH runs.
Only the head may actually have the maximum level. */
/* OPT: tweak */
#define SKIP_LIST_DEPTH 15
#define SKIP_LIST_LEVEL_PROBABILITY 2
typedef struct GSLayoutManager_glyph_run_head_s
{
struct GSLayoutManager_glyph_run_head_s *next;
/* char_length must always be accurate. glyph_length is the number of
valid glyphs counting from the start. For a level 0 head, it's the number
of glyphs in that run. */
int glyph_length,char_length;
/* Glyph generation is complete for all created runs. */
unsigned int complete:1;
} glyph_run_head_t;
typedef struct
{
NSGlyph g;
/* This if the offset for the first character this glyph
is mapped to; it is mapped to all characters between it and the next
character explicitly mapped to a glyph.
The char_offset must be strictly increasing for all glyphs; if reordering
is necessary, the mapping will have to be range to range. (Eg. if you
have characters 'ab' mapped to glyphs 'AB', reordered to 'BA', then the
range 'ab' will be mapped to the range 'BA'. */
int char_offset:21; /* This could be made a lot smaller, if necessary */
unsigned int drawsOutsideLineFragment:1;
unsigned int isNotShown:1;
unsigned int inscription:3;
/* 3 unused */
} glyph_t;
@class NSParagraphStyle;
@class NSColor;
@class NSTextAttachment;
typedef struct GSLayoutManager_glyph_run_s
{
glyph_run_head_t head;
glyph_run_head_t *prev;
/* Zero-based, so it's really the number of heads in addition to the
one included in glyph_run_t. */
int level;
/* All glyph-generation-affecting attributes are same as last run. This
doesn't have to be set if a run is continued, but if it is set, it must
be correct (it is (will, someday) be used to merge small runs created
by repeated inserts in a small range; not merging when we can merge
doesn't cost much, but merging when we shouldn't would mess up attributes
for those runs).
*/
unsigned int continued:1;
/* Bidirectional-level, as per the unicode bidirectional algorithm
(unicode standard annex #9). Only valid if glyphs have been generated
(in particular, runs for which glyphs haven't been generated may not be
all at the same level). */
/* TODO2: these aren't filled in or used anywhere yet */
unsigned int bidi_level:6;
/* Font for this run. */
NSFont *font;
int ligature;
/* YES if there's an explicit kern attribute. Currently, ligatures aren't
used when explicit kerning is available (TODO). */
BOOL explicit_kern;
glyph_t *glyphs;
} glyph_run_t;
@interface GSLayoutManager (backend)
-(unsigned int) _findSafeBreakMovingBackwardFrom: (unsigned int)ch;
-(unsigned int) _findSafeBreakMovingForwardFrom: (unsigned int)ch;
-(void) _generateGlyphsForRun: (glyph_run_t *)run at: (unsigned int)pos;
@end
/* All positions and lengths in glyphs */
typedef struct
{
unsigned int pos,length;
NSPoint p;
} linefrag_point_t;
typedef struct
{
NSRect rect,used_rect;
unsigned int pos,length;
linefrag_point_t *points;
int num_points;
} linefrag_t;
typedef struct GSLayoutManager_textcontainer_s
{
NSTextContainer *textContainer;
BOOL started,complete;
unsigned int pos,length;
linefrag_t *linefrags;
int num_linefrags;
} textcontainer_t;
@interface GSLayoutManager (glyphs_helpers)
-(void) _run_cache_attributes: (glyph_run_t *)r : (NSDictionary *)attributes;
-(void) _run_copy_attributes: (glyph_run_t *)dst : (const glyph_run_t *)src;
-(void) _run_free_attributes: (glyph_run_t *)r;
-(void) _initGlyphs;
-(void) _freeGlyphs;
-(void) _glyphDumpRuns;
-(void) _generateGlyphsUpToCharacter: (unsigned int)last;
-(void) _generateGlyphsUpToGlyph: (unsigned int)last;
-(glyph_run_t *) _glyphForCharacter: (unsigned int)target
index: (unsigned int *)rindex
positions: (unsigned int *)rpos : (unsigned int *)rcpos;
@end
@interface GSLayoutManager (layout_helpers)
-(void) _freeLayout;
-(void) _invalidateLayoutFromContainer: (int)idx;
-(void) _doLayout; /* TODO: this is just a hack until proper incremental layout is done */
-(void) _doLayoutToGlyph: (unsigned int)glyphIndex;
-(void) _doLayoutToContainer: (int)cindex;
@end
/* Some helper macros */
/* r is a run, pos and cpos are the glyph and character positions of the
run, i is the glyph index in the run. */
/* Steps forward to the next glyph. If there is no next glyph, r will be
the last run and i==r->head.glyph_length. */
#define GLYPH_STEP_FORWARD(r,i,pos,cpos) \
{ \
i++; \
while (i==r->head.glyph_length) \
{ \
if (!r->head.next || !r->head.next->complete) \
{ \
if (cpos+r->head.char_length==[_textStorage length]) \
break; \
[self _generateGlyphsUpToCharacter: cpos+r->head.char_length]; \
} \
pos+=r->head.glyph_length; \
cpos+=r->head.char_length; \
r=(glyph_run_t *)r->head.next; \
i=0; \
} \
}
/* Steps backward to the previous glyph. If there is no previous glyph, r
will be the first glyph and i==-1. */
#define GLYPH_STEP_BACKWARD(r,i,pos,cpos) \
{ \
i--; \
while (i<0 && r->prev) \
{ \
r=(glyph_run_t *)r->prev; \
pos-=r->head.glyph_length; \
cpos-=r->head.char_length; \
i=r->head.glyph_length-1; \
} \
}
/* OPT: can do better than linear scan? */
/* Scans forward from glyph i in run r (with positions pos and cpos) while
condition holds. r, i, pos, and cpos must be simple variables. When done, r,
i, pos, and cpos will be set for the first glyph for which the condition
doesn't hold. If there is no such glyph, r is the last run and
i==r->head.glyph_length. */
#define GLYPH_SCAN_FORWARD(r,i,pos,cpos,condition) \
{ \
while (condition) \
{ \
GLYPH_STEP_FORWARD(r,i,pos,cpos) \
if (i==r->head.glyph_length) \
break; \
} \
}
/* Scan backward. r, i, pos, and cpos will be set to the first glyph for
which condition doesn't hold. If there is no such glyph, r is the first run
and i==-1. */
#define GLYPH_SCAN_BACKWARD(r,i,pos,cpos,condition) \
{ \
while (condition) \
{ \
GLYPH_STEP_BACKWARD(r,i,pos,cpos) \
if (i==-1) \
break; \
} \
}
glyph_run_t *GSLayoutManager_run_for_glyph_index(unsigned int glyphIndex,
glyph_run_head_t *glyphs,unsigned int *glyph_pos,unsigned int *char_pos);
#define run_for_glyph_index GSLayoutManager_run_for_glyph_index
#endif

View file

@ -0,0 +1,160 @@
/*
GSTypesetter.h
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Alexander Malmberg <alexander@malmberg.org>
Date: 2002
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,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GNUstep_H_GSTypesetter
#define _GNUstep_H_GSTypesetter
#include <Foundation/NSObject.h>
#include <Foundation/NSRange.h>
#include <Foundation/NSGeometry.h>
@class GSLayoutManager;
@class NSTextContainer;
@class NSFont;
/* This class is abstract. */
/* This isn't final. It will probably change. If you want to sub-class,
you'll have to update your code when things change (or wait until it's
done). */
@interface GSTypesetter : NSObject
/*
???
GSTypesetter's implementation returns NSMakeSize(0,0).
*/
+ (NSSize) printingAdjustmentsInLayoutManager: (GSLayoutManager *)layoutManager
forNominallySpacedGlyphRange: (NSRange)glyphRange
packedGlyphs: (const unsigned char *)glyphs
count: (unsigned)packedGlyphCount;
/*
Returns a thread-safe shared GSTypesetter (a GSHorizontalTypesetter
instance in practice, at least when this is done).
*/
+(GSTypesetter *) sharedSystemTypesetter;
/*
Returns the font that should be used for the given attributes.
GSTypesetter's implementation returns the value of NSFontAttribute, or
[NSFont userFontOfSize: 0] if there is no such value.
Subclasses can use this to make the font picked depend on other attributes,
eg. to automatically use a smaller size for subscripts and superscripts.
{Provide context?}
*/
-(NSFont *) fontForCharactersWithAttributes: (NSDictionary *)attributes;
/*
Lay out glyphs means that, for each glyph laid out in one call, the following
things need to be done:
-setTextContainer:forGlyphRange:
1. Set the text container for the glyph.
-setLineFragmentRect:forGlyphRange:usedRect:
2. Set the line fragment rectangle for the glyph.
-setLocation:forStartOfGlyphRange:
3. Set the position for the glyph (directly, or indirectly by setting the
starting position for a range of nominally spaced glyphs containing the
glyph).
It should also set the drawsOutsideLineFragment and notShownAttribute if
they are YES (they are set to NO by -setTextContainer:forGlyphRange:).
(TODO: good?)
*/
/*
Lay out glyphs, starting at glyphIndex, in textContainer.
The line fragment rectangle for the previous line fragment in this
textContainer, or NSZeroRect if there are none, is in previousLineFragRect.
The index of the first glyph not laid out should be returned in
nextGlyphIndex (which may _not_ be NULL). If all glyphs have been laid out,
set it to [layoutManager numberOfGlyphs].
howMany is the number of requested line fragment rectangles. The typesetter
should try to create approximately this many and then stop. If it is 0, the
typesetter should fill the entire text container.
Returns:
0 did some layout, nothing special happened
1 text container is full
2 all glyphs have been laid out
Subclasses need to implement this method.
{Too much context?}
*/
-(int) layoutGlyphsInLayoutManager: (GSLayoutManager *)layoutManager
inTextContainer: (NSTextContainer *)textContainer
startingAtGlyphIndex: (unsigned int)glyphIndex
previousLineFragmentRect: (NSRect)previousLineFragRect
nextGlyphIndex: (unsigned int *)nextGlyphIndex
numberOfLineFragments: (unsigned int)howMany;
/*
Used to relayout soft-invalidated glyphs.
glyphRange is a range of glyphs that were laid out in lineFragRect.
The previous line fragment rectangle is previousLineFragRect, in
textContainer.
If the glyphs in lineFragRect don't need to be laid out again (ie. if they
can be laid out in the same place as before, or if the line fragment
rectangle can be shifted to a new position without disturbing the glyphs in
it), the method should return YES and place a (possibly shifted) line
fragment rectangle for the glyphs in lineFragRect, and the textContainer
for the line fragment rectangle in textContainer.
If the glyphs need to be laid out from scratch, it should return NO. The
layout manager then needs to call layoutGlyphsIn... to lay the glyphs out
again.
GSTypesetter's implementation returns NO.
*/
-(BOOL) relayoutGlyphsInLayoutManager: (GSLayoutManager *)layoutManager
glyphRange: (NSRange)glyphRange
lineFragmentRect: (NSRect *)lineFragRect
textContainer: (NSTextContainer **)textContainer
previousLineFragmentRect: (NSRect)previousLineFragRect;
@end
#endif

View file

@ -65,6 +65,7 @@ APPKIT_EXPORT const float*NSFontIdentityMatrix;
NSString *fontName;
float matrix[6];
BOOL matrixExplicitlySet;
BOOL screenFont;
id fontInfo;
void *_fontRef;

View file

@ -1,79 +1,38 @@
/* -*-objc-*-
/*
NSLayoutManager.h
An NSLayoutManager stores glyphs, attributes, and layout information
generated from a NSTextStorage by a NSTextLayout. It can map between
ranges of unichars in the NSTextStorage and ranges of glyphs within
itself. It understands and keeps track of two types of range
invalidation. A character range can need glyphs generated for it or
it can need its glyphs laid out.
Copyright (C) 2002 Free Software Foundation, Inc.
When a NSLayoutManager is asked for information which would require
knowledge of glyphs or layout which is not currently available, the
NSLayoutManager must cause the appropriate recalculation to be done.
Author: Alexander Malmberg <alexander@malmberg.org>
Date: 2002-11
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998
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; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GNUstep_H_NSLAYOUTMANAGER
#define _GNUstep_H_NSLAYOUTMANAGER
#include <Foundation/Foundation.h>
#include <AppKit/NSFont.h>
#include <AppKit/NSTextStorage.h>
#include <AppKit/NSTextContainer.h>
#ifndef _GNUstep_H_NSLayoutManager
#define _GNUstep_H_NSLayoutManager
#include <AppKit/GSLayoutManager.h>
#include <AppKit/NSTextView.h>
@class NSTypesetter;
@class NSTextView;
@class NSWindow;
@class NSRulerView;
@class NSParagraphStyle;
@class NSView;
// These are unclear:
@class NSGlyphGenerator;
/*
These glyph attributes are used only inside the glyph generation machinery,
but must be shared between componenets.
*/
enum _NSGlyphAttribute {
NSGlyphAttributeSoft = 0,
NSGlyphAttributeElastic = 1,
NSGlyphAttributeInscribe = 5,
};
/*
The inscribe attribute of a glyph determines how it is laid out relative to
the previous glyph.
*/
typedef enum {
NSGlyphInscribeBase = 0,
NSGlyphInscribeBelow = 1,
NSGlyphInscribeAbove = 2,
NSGlyphInscribeOverstrike = 3,
NSGlyphInscribeOverBelow = 4
} NSGlyphInscription;
@interface NSLayoutManager : NSObject
@interface NSLayoutManager : GSLayoutManager
{
/* Public for use only in the associated NSTextViews. Don't access
them directly from elsewhere. */
@ -82,340 +41,90 @@ typedef enum {
BOOL _isSynchronizingFlags;
BOOL _isSynchronizingDelegates;
BOOL _beganEditing;
@protected
NSMutableArray *_textContainers;
NSTextStorage *_textStorage;
/* NB: if _textContainersCount == 1, then _firstTextView == our only
text view. */
/* Cached - number of text containers: */
unsigned _textContainersCount;
/* Cached - first text view: */
NSTextView *_firstTextView;
/* Selection */
NSRange _selected_range;
NSRange _original_selected_range;
NSSelectionGranularity _selectionGranularity;
NSSelectionAffinity _selectionAffinity;
id _delegate;
/* TODO: Tidyup the following ivars, remove useless ones */
BOOL _backgroundLayout;
BOOL _showsInvisibleChars;
BOOL _showsControlChars;
BOOL _usesScreenFonts;
BOOL _finished;
float _hyphenationFactor;
NSTypesetter *_typesetter;
void *_glyphData; // Private glyph storage.
void *_currentGlyphs; // Current chunk pointer.
unsigned _glyphIndex; // Current glyph index.
void *_glyphGaps; // Gaps in character mapping.
unsigned _chunkIndex; // Current chunk in glyph stream.
unsigned _glyphOffset; // Current glyph in chunk.
NSGlyphGenerator *_glyphGenerator;
NSRect _extraLineFragmentRect;
NSRect _extraLineFragmentUsedRect;
NSTextContainer *_extraLineFragmentContainer;
// Enable/disable stacks
unsigned short _textViewResizeDisableStack;
unsigned short _displayInvalidationDisableStack;
NSRange _deferredDisplayCharRange;
// Cache for rectangle arrays (Cost: 8 bytes + malloced 16 * <max number of rects returned in an array> bytes)
NSRect *_cachedRectArray;
unsigned _cachedRectArrayCapacity;
// Cache for glyph strings (used when drawing) (Cost: 8 bytes + malloced glyph buffer size)
char *_glyphBuffer;
unsigned _glyphBufferSize;
// Cache for faster glyph location lookup (Cost: 20 bytes)
NSRange _cachedLocationNominalGlyphRange;
unsigned _cachedLocationGlyphIndex;
NSPoint _cachedLocation;
// Cache for faster glyph location lookup (Cost: 12 bytes)
NSRange _cachedFontCharRange;
NSFont *_cachedFont;
// Cache for first unlaid glypha and character (Cost: 8 bytes)
unsigned _firstUnlaidGlyphIndex;
unsigned _firstUnlaidCharIndex;
NSRange _newlyFilledGlyphRange;
/* Retained by the NSLayoutManager. NSTextView:s that change this value
should release the old value and retain the new one. It is nil originally
and will be released when the NSLayoutManager is deallocated. */
NSMutableDictionary *_typingAttributes;
}
/**************************** Initialization ****************************/
/* TODO */
- (id) init;
/*************************** Helper objects ***************************/
- (NSTextStorage *) textStorage;
- (void) setTextStorage: (NSTextStorage *)aTextStorage;
- (void) replaceTextStorage: (NSTextStorage *)newTextStorage;
- (id) delegate;
- (void) setDelegate: (id)aDelegate;
/**************************** Containers ****************************/
- (NSArray *) textContainers;
-(void) addTextContainer: (NSTextContainer *)container;
- (void) insertTextContainer: (NSTextContainer*)aTextContainer
atIndex: (unsigned)index;
- (void) removeTextContainerAtIndex: (unsigned)index;
- (void) textContainerChangedGeometry: (NSTextContainer *)aContainer;
- (void) textContainerChangedTextView: (NSTextContainer *)aContainer;
/************************** Invalidation primitives **************************/
- (void) invalidateGlyphsForCharacterRange: (NSRange)aRange
changeInLength: (int)lengthChange
actualCharacterRange: (NSRange *)actualRange;
- (void) invalidateLayoutForCharacterRange: (NSRange)aRange
isSoft: (BOOL)flag
actualCharacterRange: (NSRange *)actualRange;
- (void) invalidateDisplayForGlyphRange: (NSRange)aRange;
#ifndef STRICT_40
- (void) invalidateDisplayForCharacterRange: (NSRange)aRange;
#endif
/******************* Invalidation sent by NSTextStorage *******************/
- (void) textStorage: (NSTextStorage *)aTextStorage
edited: (unsigned)mask
range: (NSRange)newCharRange
changeInLength: (int)lengthChange
invalidatedRange: (NSRange)invalidatedRange;
/*********************** Global layout manager options ***********************/
- (void) setBackgroundLayoutEnabled: (BOOL)flag;
- (BOOL) backgroundLayoutEnabled;
- (void) setShowsInvisibleCharacters: (BOOL)flag;
- (BOOL) showsInvisibleCharacters;
- (void) setShowsControlCharacters: (BOOL)flag;
- (BOOL) showsControlCharacters;
/************************ Adding and removing glyphs ************************/
- (void) insertGlyph: (NSGlyph)aGlyph atGlyphIndex: (unsigned)glyphIndex
characterIndex: (unsigned)charIndex;
- (void) replaceGlyphAtIndex: (unsigned)glyphIndex
withGlyph: (NSGlyph)newGlyph;
- (void) deleteGlyphsInRange: (NSRange)aRange;
- (void) setCharacterIndex: (unsigned)charIndex
forGlyphAtIndex: (unsigned)glyphIndex;
/************************ Accessing glyphs ************************/
- (unsigned) numberOfGlyphs;
- (NSGlyph) glyphAtIndex: (unsigned)glyphIndex;
- (NSGlyph) glyphAtIndex: (unsigned)glyphIndex
isValidIndex: (BOOL *)isValidIndex;
- (unsigned) getGlyphs: (NSGlyph *)glyphArray range: (NSRange)glyphRange;
- (unsigned) characterIndexForGlyphAtIndex: (unsigned)glyphIndex;
/************************ Set/Get glyph attributes ************************/
- (void) setIntAttribute: (int)attributeTag
value: (int)anInt
forGlyphAtIndex: (unsigned)glyphIndex;
- (int) intAttribute: (int)attributeTag
forGlyphAtIndex: (unsigned)glyphIndex;
- (void) setAttachmentSize: (NSSize)attachmentSize
forGlyphRange: (NSRange)glyphRange;
/************************ Set/Get layout attributes ************************/
- (void) setTextContainer: (NSTextContainer *)aTextContainer
forGlyphRange: (NSRange)glyphRange;
- (void) setLineFragmentRect: (NSRect)fragmentRect
forGlyphRange: (NSRange)glyphRange
usedRect: (NSRect)usedRect;
- (void) setExtraLineFragmentRect: (NSRect)fragmentRect
usedRect: (NSRect)usedRect
textContainer: (NSTextContainer *)container;
- (void) setDrawsOutsideLineFragment: (BOOL)flag
forGlyphAtIndex: (unsigned)glyphIndex;
- (void) setLocation: (NSPoint)location
forStartOfGlyphRange: (NSRange)glyphRange;
- (void) setNotShownAttribute: (BOOL)flag
forGlyphAtIndex: (unsigned)glyphIndex;
- (NSTextContainer *) textContainerForGlyphAtIndex: (unsigned)glyphIndex
effectiveRange: (NSRange *)effectiveRange;
- (NSRect) usedRectForTextContainer: (NSTextContainer *)container;
- (NSRect) lineFragmentRectForGlyphAtIndex: (unsigned)glyphIndex
effectiveRange: (NSRange *)effectiveGlyphRange;
- (NSRect) lineFragmentUsedRectForGlyphAtIndex: (unsigned)glyphIndex
effectiveRange: (NSRange *)effectiveGlyphRange;
- (NSRect) extraLineFragmentRect;
- (NSRect) extraLineFragmentUsedRect;
- (NSTextContainer *) extraLineFragmentTextContainer;
- (BOOL) drawsOutsideLineFragmentForGlyphAtIndex: (unsigned) glyphIndex;
- (NSPoint) locationForGlyphAtIndex: (unsigned)glyphIndex;
- (BOOL) notShownAttributeForGlyphAtIndex: (unsigned) glyphIndex;
/************************ More sophisticated queries ************************/
- (NSRange) glyphRangeForCharacterRange: (NSRange)charRange
actualCharacterRange: (NSRange *)actualCharRange;
- (NSRange) characterRangeForGlyphRange: (NSRange)glyphRange
actualGlyphRange: (NSRange *)actualGlyphRange;
- (NSRange) glyphRangeForTextContainer: (NSTextContainer *)container;
- (NSRange) rangeOfNominallySpacedGlyphsContainingIndex:(unsigned)glyphIndex;
- (NSRect *) rectArrayForCharacterRange: (NSRange)charRange
withinSelectedCharacterRange: (NSRange)selCharRange
inTextContainer: (NSTextContainer *)container
rectCount: (unsigned *)rectCount;
- (NSRect *) rectArrayForGlyphRange: (NSRange)glyphRange
withinSelectedGlyphRange: (NSRange)selGlyphRange
inTextContainer: (NSTextContainer *)container
rectCount: (unsigned *)rectCount;
- (NSRect) boundingRectForGlyphRange: (NSRange)glyphRange
inTextContainer: (NSTextContainer *)aTextContainer;
- (NSRange) glyphRangeForBoundingRect: (NSRect)bounds
inTextContainer: (NSTextContainer *)container;
- (NSRange) glyphRangeForBoundingRectWithoutAdditionalLayout: (NSRect)bounds
inTextContainer: (NSTextContainer *)container;
- (unsigned) glyphIndexForPoint: (NSPoint)aPoint
inTextContainer: (NSTextContainer *)aTextContainer;
- (unsigned) glyphIndexForPoint: (NSPoint)point
inTextContainer: (NSTextContainer *)container
fractionOfDistanceThroughGlyph: (float *)partialFraction;
- (unsigned) firstUnlaidCharacterIndex;
- (unsigned) firstUnlaidGlyphIndex;
- (void) getFirstUnlaidCharacterIndex: (unsigned *)charIndex
glyphIndex: (unsigned *)glyphIndex;
/************************ Screen font usage control ************************/
- (BOOL) usesScreenFonts;
- (void) setUsesScreenFonts: (BOOL)flag;
- (NSFont *) substituteFontForFont: (NSFont *)originalFont;
@end
@interface NSLayoutManager (NSTextViewSupport)
/************************ Ruler stuff ************************/
- (NSArray *) rulerMarkersForTextView: (NSTextView *)view
paragraphStyle: (NSParagraphStyle *)style
ruler: (NSRulerView *)ruler;
- (NSView *) rulerAccessoryViewForTextView: (NSTextView *)view
paragraphStyle: (NSParagraphStyle *)style
ruler: (NSRulerView *)ruler
enabled: (BOOL)isEnabled;
/************************ First responder support ************************/
- (BOOL) layoutManagerOwnsFirstResponderInWindow: (NSWindow *)window;
-(void) invalidateDisplayForGlyphRange: (NSRange)aRange;
-(void) invalidateDisplayForCharacterRange: (NSRange)aRange; /* not STRICT_40 ?? */
- (NSTextView *) firstTextView;
- (NSTextView *) textViewForBeginningOfSelection;
- (BOOL) layoutManagerOwnsFirstResponderInWindow: (NSWindow *)window;
/************************ Drawing support ************************/
-(NSArray *) rulerMarkersForTextView: (NSTextView *)textView
paragraphStyle: (NSParagraphStyle *)style
ruler: (NSRulerView *)ruler;
-(NSView *) rulerAccessoryViewForTextView: (NSTextView *)textView
paragraphStyle: (NSParagraphStyle *)style
ruler: (NSRulerView *)ruler
enabled: (BOOL)isEnabled;
- (void) drawBackgroundForGlyphRange: (NSRange)glyphsToShow
atPoint: (NSPoint)origin;
- (void) drawGlyphsForGlyphRange: (NSRange)glyphsToShow
atPoint: (NSPoint)origin;
- (void) drawUnderlineForGlyphRange: (NSRange)glyphRange
underlineType: (int)underlineVal
baselineOffset: (float)baselineOffset
lineFragmentRect: (NSRect)lineRect
lineFragmentGlyphRange: (NSRange)lineGlyphRange
containerOrigin: (NSPoint)containerOrigin;
- (void) underlineGlyphRange: (NSRange)glyphRange
underlineType: (int)underlineVal
lineFragmentRect: (NSRect)lineRect
lineFragmentGlyphRange: (NSRange)lineGlyphRange
containerOrigin: (NSPoint)containerOrigin;
/************************ Hyphenation support ************************/
- (float) hyphenationFactor;
- (void) setHyphenationFactor: (float)factor;
- (unsigned) _charIndexForInsertionPointMovingFromY: (float)position
bestX: (float)wanted
up: (BOOL)upFlag
textContainer: (NSTextContainer *)tc;
@end
@interface NSObject (NSLayoutManagerDelegate)
- (void) layoutManagerDidInvalidateLayout: (NSLayoutManager *)sender;
// This is sent whenever layout or glyphs become invalidated in a
// layout manager which previously had all layout complete.
- (void) layoutManager: (NSLayoutManager *)layoutManager
didCompleteLayoutForTextContainer: (NSTextContainer *)textContainer
atEnd: (BOOL)layoutFinishedFlag;
// This is sent whenever a container has been filled.
// This method can be useful for paginating. The textContainer might
// be nil if we have completed all layout and not all of it fit into
// the existing containers. atEnd indicates whether all layout is complete.
-(float) hyphenationFactor;
-(void) setHyphenationFactor: (float)factor;
@end
#endif // _GNUstep_H_NSLAYOUTMANAGER
@interface NSLayoutManager (layout)
- (void) textContainerChangedTextView: (NSTextContainer *)aContainer;
- (NSPoint) locationForGlyphAtIndex: (unsigned int)glyphIndex;
- (NSRect *) rectArrayForGlyphRange: (NSRange)glyphRange
withinSelectedGlyphRange: (NSRange)selGlyphRange
inTextContainer: (NSTextContainer *)container
rectCount: (unsigned int *)rectCount;
- (NSRect *) rectArrayForCharacterRange: (NSRange)charRange
withinSelectedCharacterRange: (NSRange)selCharRange
inTextContainer: (NSTextContainer *)container
rectCount: (unsigned int *)rectCount;
- (NSRect) boundingRectForGlyphRange: (NSRange)glyphRange
inTextContainer: (NSTextContainer *)aTextContainer;
- (NSRange) glyphRangeForBoundingRect: (NSRect)bounds
inTextContainer: (NSTextContainer *)container;
- (NSRange) glyphRangeForBoundingRectWithoutAdditionalLayout: (NSRect)bounds
inTextContainer: (NSTextContainer *)container;
- (unsigned int) glyphIndexForPoint: (NSPoint)aPoint
inTextContainer: (NSTextContainer *)aTextContainer;
- (unsigned int) glyphIndexForPoint: (NSPoint)point
inTextContainer: (NSTextContainer *)container
fractionOfDistanceThroughGlyph: (float *)partialFraction;
@end
@interface NSLayoutManager (drawing)
-(void) drawBackgroundForGlyphRange: (NSRange)range
atPoint: (NSPoint)containerOrigin;
-(void) drawGlyphsForGlyphRange: (NSRange)range
atPoint: (NSPoint)containerOrigin;
/* TODO: underline */
@end
#endif

View file

@ -23,7 +23,7 @@
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
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
@ -42,19 +42,18 @@
*
* But you can still subclass NSText to implement your own text
* editing class not derived from NSTextView. NSText declares general
* methods that a text editing object should have; it has ivars to
* track the various options (editable, selectable, background color
* etc) and implementations for methods setting and getting these
* generic options and for some helper methods which are simple
* wrappers around the real basic editing methods. The real editing
* methods are not implemented in NSText, which is why it is abstract.
* To make a working subclass, you need to implement these methods.
* methods that a text editing object should have; it has some helper
* methods which are simple wrappers around the real basic editing
* methods. The real editing methods are not implemented in NSText,
* which is why it is abstract. To make a working subclass, you need to
* implement these methods, marked as "PRIMITIVE" below.
*
* The working subclass could potentially be implemented in absolutely
* *any* way you want. I have been told that some versions of Emacs
* can be embedded as an X subwindow inside alien widgets and windows
* - so yes, potentially if you are able to figure out how to embed
* Emacs inside the GNUstep NSView tree, you can write a subclass
* of NSText which just uses Emacs. */
* *any* way you want. I have been told that some versions of Emacs can
* be embedded as an X subwindow inside alien widgets and windows - so
* yes, potentially if you are able to figure out how to embed Emacs
* inside the GNUstep NSView tree, you can write a subclass of NSText
* which just uses Emacs. */
#include <AppKit/NSView.h>
#include <AppKit/NSSpellProtocol.h>
@ -84,7 +83,7 @@ enum {
NSUpTextMovement = 0x15,
NSDownTextMovement = 0x16
};
enum {
NSParagraphSeparatorCharacter = 0x2029,
NSLineSeparatorCharacter = 0x2028,
@ -110,81 +109,75 @@ enum {
#include <AppKit/NSStringDrawing.h>
@interface NSText : NSView <NSChangeSpelling, NSIgnoreMisspelledWords>
{
id _delegate;
struct GSTextFlagsType {
unsigned is_field_editor: 1;
unsigned is_editable: 1;
unsigned is_selectable: 1;
unsigned is_rich_text: 1;
unsigned imports_graphics: 1;
unsigned draws_background: 1;
unsigned is_horizontally_resizable: 1;
unsigned is_vertically_resizable: 1;
unsigned uses_font_panel: 1;
unsigned uses_ruler: 1;
unsigned is_ruler_visible: 1;
} _tf;
NSColor *_background_color;
NSSize _minSize;
NSSize _maxSize;
{
}
/*
* Getting and Setting Contents
*/
/* these aren't in OPENSTEP */
- (void) replaceCharactersInRange: (NSRange)aRange
withRTF: (NSData*)rtfData;
- (void) replaceCharactersInRange: (NSRange)aRange
withRTFD: (NSData*)rtfdData;
/* PRIMITIVE */
- (void) replaceCharactersInRange: (NSRange)aRange
withString: (NSString*)aString;
/* PRIMITIVE */
-(void) replaceCharactersInRange: (NSRange)aRange /* GNUstep extension */
withAttributedString: (NSAttributedString *)aString;
/* PRIMITIVE */
- (void) setString: (NSString*)aString;
/* PRIMITIVE */
- (NSString*) string;
/*
* Old fashioned OpenStep methods (wrappers for the previous ones)
*/
- (void) replaceRange: (NSRange)aRange withString: (NSString*)aString;
- (void) replaceRange: (NSRange)aRange withString: (NSString*)aString; /* not OPENSTEP */
- (void) replaceRange: (NSRange)aRange withRTF: (NSData*)rtfData;
- (void) replaceRange: (NSRange)aRange withRTFD: (NSData*)rtfdData;
- (void) setText: (NSString*)aString;
- (void) setText: (NSString*)aString range: (NSRange)aRange;
- (void) setText: (NSString*)aString range: (NSRange)aRange; /* not OPENSTEP */
- (NSString*) text;
/*
* Graphic attributes
*/
/* PRIMITIVE */
- (NSColor*) backgroundColor;
/* PRIMITIVE */
- (BOOL) drawsBackground;
/* PRIMITIVE */
- (void) setBackgroundColor: (NSColor*)color;
/* PRIMITIVE */
- (void) setDrawsBackground: (BOOL)flag;
/*
* Managing Global Characteristics
*/
- (BOOL) importsGraphics;
- (BOOL) isEditable;
- (BOOL) isFieldEditor;
- (BOOL) isRichText;
- (BOOL) isSelectable;
- (void) setEditable: (BOOL)flag;
- (void) setFieldEditor: (BOOL)flag;
- (void) setImportsGraphics: (BOOL)flag;
- (void) setRichText: (BOOL)flag;
- (void) setSelectable: (BOOL)flag;
- (BOOL) importsGraphics; /* PRIMITIVE */
- (BOOL) isEditable; /* PRIMITIVE */
- (BOOL) isFieldEditor; /* PRIMITIVE */
- (BOOL) isRichText; /* PRIMITIVE */
- (BOOL) isSelectable; /* PRIMITIVE */
- (void) setEditable: (BOOL)flag; /* PRIMITIVE */
- (void) setFieldEditor: (BOOL)flag; /* PRIMITIVE */
- (void) setImportsGraphics: (BOOL)flag; /* PRIMITIVE */
- (void) setRichText: (BOOL)flag; /* PRIMITIVE */
- (void) setSelectable: (BOOL)flag; /* PRIMITIVE */
/*
* Using the font panel
*/
- (void) setUsesFontPanel: (BOOL)flag;
- (BOOL) usesFontPanel;
- (void) setUsesFontPanel: (BOOL)flag; /* PRIMITIVE */
- (BOOL) usesFontPanel; /* PRIMITIVE */
/*
* Managing the Ruler
*/
- (BOOL) isRulerVisible;
- (void) toggleRuler: (id)sender;
- (BOOL) isRulerVisible; /* PRIMITIVE */
- (void) toggleRuler: (id)sender; /* PRIMITIVE */
/*
* Managing the Selection
@ -195,113 +188,103 @@ enum {
/*
* Responding to Editing Commands
*/
- (void) copy: (id)sender;
- (void) copyFont: (id)sender;
- (void) copyRuler: (id)sender;
- (void) copy: (id)sender; /* PRIMITIVE */
- (void) copyFont: (id)sender; /* PRIMITIVE */
- (void) copyRuler: (id)sender; /* PRIMITIVE */
- (void) cut: (id)sender;
- (void) delete: (id)sender;
- (void) paste: (id)sender;
- (void) pasteFont: (id)sender;
- (void) pasteRuler: (id)sender;
- (void) delete: (id)sender; /* PRIMITIVE */
- (void) paste: (id)sender; /* PRIMITIVE */
- (void) pasteFont: (id)sender; /* PRIMITIVE */
- (void) pasteRuler: (id)sender; /* PRIMITIVE */
- (void) selectAll: (id)sender;
/*
* Managing Font
*/
- (void) changeFont: (id)sender;
- (NSFont*) font;
- (void) setFont: (NSFont*)font;
- (void) setFont: (NSFont*)font range: (NSRange)aRange;
- (void) changeFont: (id)sender; /* PRIMITIVE */
- (NSFont*) font; /* PRIMITIVE */
- (void) setFont: (NSFont*)font; /* PRIMITIVE */
- (void) setFont: (NSFont*)font range: (NSRange)aRange; /* PRIMITIVE */
/* Old OpenStep name for the same method. */
- (void) setFont: (NSFont*)font ofRange: (NSRange)aRange;
- (void) setFont: (NSFont*)font ofRange: (NSRange)aRange;
/*
* Managing Alignment
*/
- (NSTextAlignment) alignment;
- (void) setAlignment: (NSTextAlignment)mode;
- (void) alignCenter: (id)sender;
- (void) alignLeft: (id)sender;
- (void) alignRight: (id)sender;
- (NSTextAlignment) alignment; /* PRIMITIVE */
- (void) setAlignment: (NSTextAlignment)mode; /* PRIMITIVE */
- (void) alignCenter: (id)sender; /* PRIMITIVE */
- (void) alignLeft: (id)sender; /* PRIMITIVE */
- (void) alignRight: (id)sender; /* PRIMITIVE */
/*
* Text colour
*/
- (void) setTextColor: (NSColor*)color range: (NSRange)aRange;
- (void) setColor: (NSColor*)color ofRange: (NSRange)aRange;
- (void) setTextColor: (NSColor*)color;
- (NSColor*) textColor;
- (void) setTextColor: (NSColor*)color range: (NSRange)aRange; /* PRIMITIVE */ /* not OPENSTEP */
- (void) setColor: (NSColor*)color ofRange: (NSRange)aRange; /* PRIMITIVE */
- (void) setTextColor: (NSColor*)color; /* PRIMITIVE */
- (NSColor*) textColor; /* PRIMITIVE */
/*
* Text attributes
*/
- (void) subscript: (id)sender;
- (void) superscript: (id)sender;
- (void) underline: (id)sender;
- (void) unscript: (id)sender;
- (void) subscript: (id)sender; /* PRIMITIVE */
- (void) superscript: (id)sender; /* PRIMITIVE */
- (void) underline: (id)sender; /* PRIMITIVE */
- (void) unscript: (id)sender; /* PRIMITIVE */
/*
* Reading and Writing RTFD Files
*/
-(BOOL) readRTFDFromFile: (NSString*)path;
-(BOOL) writeRTFDToFile: (NSString*)path atomically: (BOOL)flag;
-(NSData*) RTFDFromRange: (NSRange)aRange;
-(NSData*) RTFFromRange: (NSRange)aRange;
-(BOOL) readRTFDFromFile: (NSString*)path; /* PRIMITIVE */
-(BOOL) writeRTFDToFile: (NSString*)path atomically: (BOOL)flag; /* PRIMITIVE */
-(NSData*) RTFDFromRange: (NSRange)aRange; /* PRIMITIVE */
-(NSData*) RTFFromRange: (NSRange)aRange; /* PRIMITIVE */
/*
* Sizing the Frame Rectangle
*/
- (BOOL) isHorizontallyResizable;
- (BOOL) isVerticallyResizable;
- (NSSize) maxSize;
- (NSSize) minSize;
- (void) setHorizontallyResizable: (BOOL)flag;
- (void) setMaxSize: (NSSize)newMaxSize;
- (void) setMinSize: (NSSize)newMinSize;
- (void) setVerticallyResizable: (BOOL)flag;
- (void) sizeToFit;
- (BOOL) isHorizontallyResizable; /* PRIMITIVE */
- (BOOL) isVerticallyResizable; /* PRIMITIVE */
- (NSSize) maxSize; /* PRIMITIVE */
- (NSSize) minSize; /* PRIMITIVE */
- (void) setHorizontallyResizable: (BOOL)flag; /* PRIMITIVE */
- (void) setMaxSize: (NSSize)newMaxSize; /* PRIMITIVE */
- (void) setMinSize: (NSSize)newMinSize; /* PRIMITIVE */
- (void) setVerticallyResizable: (BOOL)flag; /* PRIMITIVE */
- (void) sizeToFit; /* PRIMITIVE */
/*
* Spelling
*/
- (void) checkSpelling: (id)sender;
- (void) checkSpelling: (id)sender; /* PRIMITIVE */
- (void) showGuessPanel: (id)sender;
/*
* Scrolling
*/
- (void) scrollRangeToVisible: (NSRange)aRange;
- (void) scrollRangeToVisible: (NSRange)aRange; /* PRIMITIVE */
/*
* Managing the Delegate
*/
- (id) delegate;
- (void) setDelegate: (id)anObject;
/*
* NSCoding protocol
*/
- (void) encodeWithCoder: (NSCoder*)aCoder;
- (id) initWithCoder: (NSCoder*)aDecoder;
- (id) delegate; /* PRIMITIVE */
- (void) setDelegate: (id)anObject; /* PRIMITIVE */
/*
* NSChangeSpelling protocol
*/
- (void) changeSpelling: (id)sender;
- (void) changeSpelling: (id)sender; /* PRIMITIVE */
/*
* NSIgnoreMisspelledWords protocol
*/
- (void) ignoreSpelling: (id)sender;
- (void) ignoreSpelling: (id)sender; /* PRIMITIVE */ /* not OPENSTEP */
@end
@interface NSText (GNUstepExtensions)
- (void) replaceRange: (NSRange)aRange
withAttributedString: (NSAttributedString*)attrString;
- (unsigned) textLength;
- (unsigned) textLength; /* PRIMITIVE */
@end

View file

@ -33,8 +33,10 @@
#error "The OpenStep specification does not define an NSTextContainer class."
#endif
#include <Foundation/Foundation.h>
#include <AppKit/NSTextView.h>
#include <Foundation/NSGeometry.h>
@class GSLayoutManager;
@class NSTextView;
typedef enum {
NSLineSweepLeft,
@ -72,9 +74,9 @@ typedef enum {
/*
* Managing text components
*/
- (void) setLayoutManager: (NSLayoutManager *)aLayoutManager;
- (NSLayoutManager *) layoutManager;
- (void) replaceLayoutManager: (NSLayoutManager *)aLayoutManager;
- (void) setLayoutManager: (GSLayoutManager *)aLayoutManager;
- (GSLayoutManager *) layoutManager;
- (void) replaceLayoutManager: (GSLayoutManager *)aLayoutManager;
- (void) setTextView: (NSTextView *)aTextView;
- (NSTextView *) textView;

View file

@ -34,7 +34,7 @@
#include <AppKit/NSStringDrawing.h>
#include <AppKit/AppKitDefines.h>
@class NSLayoutManager;
@class GSLayoutManager;
/*
* When edit:range:changeInLength: is called, it takes a mask saying
@ -63,8 +63,8 @@ enum
unsigned _editCount;
}
- (void) addLayoutManager: (NSLayoutManager*)obj;
- (void) removeLayoutManager: (NSLayoutManager*)obj;
- (void) addLayoutManager: (GSLayoutManager*)obj;
- (void) removeLayoutManager: (GSLayoutManager*)obj;
- (NSArray*) layoutManagers;
/*

View file

@ -31,55 +31,117 @@
#ifndef _GNUstep_H_NSTextView
#define _GNUstep_H_NSTextView
#include <AppKit/NSDragging.h>
#include <AppKit/NSText.h>
#include <AppKit/NSTextAttachment.h>
#include <AppKit/NSRulerView.h>
#include <AppKit/NSRulerMarker.h>
#include <AppKit/NSInputManager.h>
@class NSTimer;
@class NSTextContainer;
@class NSTextStorage;
@class NSLayoutManager;
@class NSRulerView,NSRulerMarker;
@protocol NSDraggingInfo;
@protocol NSTextAttachmentCell;
typedef enum _NSSelectionGranularity {
typedef enum _NSSelectionGranularity {
NSSelectByCharacter = 0,
NSSelectByWord = 1,
NSSelectByParagraph = 2,
} NSSelectionGranularity;
#ifndef NO_GNUSTEP
typedef enum _NSSelectionAffinity {
/* TODO: this looks like a mosx extension, not a GNUstep extension. should
double-check */
typedef enum _NSSelectionAffinity {
NSSelectionAffinityUpstream = 0,
NSSelectionAffinityDownstream = 1,
} NSSelectionAffinity;
#endif
/*
If several NSTextView:s are connected to one NSLayoutManager, some attributes
are shared between them. This is done in two ways: storing the attributes in
the NSLayoutManager, or storing a copy in each NSTextView and ensuring that
the any changes are replicated in all of them.
Persistant attributes (ie. attributes that are encoded and decoded) need to
be stored in the NSTextView. Non-persistant attributes don't, and should
therefore be stored in the NSLayoutManager to avoid problems.
*/
@interface NSTextView : NSText <NSTextInput>
{
/** These attributes are shared by all text views attached to a layout
manager. Any changes must be replicated in all those text views. **/
id _delegate;
struct GSTextViewFlagsType {
unsigned is_field_editor:1;
unsigned is_editable:1;
unsigned is_selectable:1;
unsigned is_rich_text:1;
unsigned imports_graphics:1;
unsigned uses_font_panel:1;
unsigned uses_ruler:1;
unsigned is_ruler_visible:1;
/* I don't know for sure that these are supposed to be shared, but it
would be very awkward if they weren't. */
unsigned allows_undo:1;
unsigned smart_insert_delete:1;
/** End of shared attributes. **/
unsigned draws_background:1;
unsigned is_horizontally_resizable:1;
unsigned is_vertically_resizable:1;
/* owns_text_network is YES if we have created the whole network
of text classes (and thus we are responsible to release them
when we are released).
owns_text_network in NO if the text network was assembled by
hand, and the text storage owns everything - thus we need to
release nothing. */
unsigned owns_text_network: 1;
unsigned allows_undo: 1;
unsigned smart_insert_delete: 1;
release nothing.
See -initWithFrame: for more comments about this. */
unsigned owns_text_network:1;
/* multiple_textviews is YES if more than one NSTextView are
sharing this layout manager. In this case, we need to keep the
views in sync. */
unsigned multiple_textviews: 1;
unsigned multiple_textviews:1;
/* These two really are shared, but they're cached, They must be updated
whenever the delegate changes (including indirect changes). */
/* YES if delegate responds to
`shouldChangeTextInRange:replacementString:' */
unsigned delegate_responds_to_should_change: 1;
unsigned delegate_responds_to_should_change:1;
/* YES if delegate responds to
`textView:willChangeSelectionFromCharacterRange:toCharacterRange:' */
unsigned delegate_responds_to_will_change_sel: 1;
} _tvf;
unsigned delegate_responds_to_will_change_sel:1;
} _tf;
/* TODO: figure out whether these should be shared or not */
NSColor *_insertionPointColor; /* shared? */
NSDictionary *_selectedTextAttributes; /* shared? */
NSDictionary *_markedTextAttributes; /* shared? */
/* shared by all text views attached to one NSTextStorage */
int _spellCheckerDocumentTag;
NSColor *_backgroundColor;
NSSize _minSize;
NSSize _maxSize;
/* The following is the object used when posting notifications.
It is usually `self' - but in the case of multiple textviews
@ -87,32 +149,27 @@ typedef enum _NSSelectionAffinity {
might or might not be `self'. This must *not* be retained. */
NSTextView *_notifObject;
/* content */
NSTextStorage *_textStorage;
NSTextContainer *_textContainer;
/* manages layout information */
NSLayoutManager *_layoutManager;
/* container position */
/* other members of the text network */
NSTextContainer *_textContainer;
NSLayoutManager *_layoutManager;
NSTextStorage *_textStorage;
/* container inset and origin */
NSSize _textContainerInset;
NSPoint _textContainerOrigin;
/* These selection ivars should be shared with the other textviews -
ie, should be stored in the layout manager */
NSMutableDictionary *_typingAttributes;
NSRange _selected_range;
NSRange _original_selected_range;
NSColor *_caret_color;
int _spellCheckerDocumentTag;
NSDictionary *_selectedTextAttributes;
NSDictionary *_markedTextAttributes;
NSSelectionGranularity _selectionGranularity;
/* TODO: move to NSLayoutManager? */
/* Probably not necessary; the insertion point is always drawn in the
text view that is the first responder, so there shouldn't be any
problems with keeping track of it locally. Still need to think hard
about handling of it, though. */
#if 0
/* Timer used to redraw the insertion point ... FIXME - think what
happens with multiple textviews */
NSTimer *_insertionPointTimer;
/* Blinking of the insertion point is controlled by the following
ivar ... it is YES during the little period in which the
insertion point should be drawn on screen, and NO during the
@ -120,6 +177,7 @@ typedef enum _NSSelectionAffinity {
be drawn */
BOOL _drawInsertionPointNow;
/* Stores the insertion point rect - updated by
updateInsertionPointStateAndRestartTimer: - we must make sure we
call the method every time that the insertion point rect might
@ -133,358 +191,410 @@ typedef enum _NSSelectionAffinity {
go up or down. The memory of the horizontal position is changed
as soon as you do something different from moving the cursor
up/down. */
float _originalInsertPoint;
/* TODO: cursor movement needs to be worked out. The current methods
aren't good enough (eg. in a vertical layout, the original y position
should be preserved when moving left/right, but the original x position
is meaningless). A position (in the text container coordinate system)
based system won't work when moving through ligatures. A character based
system is better. A _originalCharacterIndex here should solve the problems;
a method:
-(unsigned int) characterIndexMoving: (int)direction
from: (unsigned int)currentCharIndex
original: (unsigned int)originalCharIndex
should be able to give proper behavior in all cases.
Need to figure out what "proper behavior" is when moving between two
NSTextView:s, though.
*/
unsigned int _originalCharIndex;
#endif
}
/**************************** Initializing ****************************/
/* Returns the default typing attributes: black text, default paragraph
style, default user font and size. */
+(NSDictionary*) defaultTypingAttributes; /* GNUstep extension */
/**** Initializing ****/
/* This is sent each time a view is initialized. If you subclass you
should ensure that you only register once. */
+(void) registerForServices;
// This is sent each time a view is initialized. If you subclass you
//should ensure that you only register once.
- (id)initWithFrame:(NSRect)frameRect
textContainer:(NSTextContainer *)container;
// Designated Initializer. container may be nil.
/* Designated Initializer. container may be nil. */
-(id) initWithFrame: (NSRect)frameRect
textContainer: (NSTextContainer *)container;
- (id)initWithFrame:(NSRect)frameRect;
// This variant will create the text network (textStorage, layoutManager,
// and a container).
/***************** Get/Set the container and other stuff *****************/
-(NSTextContainer*) textContainer;
-(void)setTextContainer:(NSTextContainer*) container;
// The set method should not be called directly, but you might want to
// override it. Gets or sets the text container for this view.
// Setting the text container marks the view as needing display. The
// text container calls the set method from its setTextView: method.
- (void)replaceTextContainer:(NSTextContainer *)newContainer;
// This method should be used instead of the primitive
// -setTextContainer: if you need to replace a view's text container
// with a new one leaving the rest of the web intact. This method
// deals with all the work of making sure the view doesn't get
// deallocated and removing the old container from the layoutManager
// and replacing it with the new one.
- (void)setTextContainerInset:(NSSize)inset;
- (NSSize)textContainerInset;
// The textContianerInset determines the padding that the view
// provides around the container. The container's origin will be
// inset by this amount from the bounds point {0,0} and padding will
// be left to the right and below the container of the same amount.
// This inset affects the view sizing in response to new layout and is
// used by the rectangular text containers when they track the view's
// frame dimensions.
- (NSPoint)textContainerOrigin;
- (void)invalidateTextContainerOrigin;
// The container's origin in the view is determined from the current
// usage of the container, the container inset, and the view size.
// textContainerOrigin returns this point.
// invalidateTextContainerOrigin is sent automatically whenever
// something changes that causes the origin to possibly move. You
// usually do not need to call invalidate yourself.
- (NSLayoutManager *) layoutManager;
- (NSTextStorage *) textStorage;
// Convenience methods
/************************* Key binding entry-point *************************/
- (void) insertText: (NSString *)insertString;
// This method is the funnel point for text insertion after keys pass
// through the key binder.
/*************************** Sizing methods ***************************/
- (void) setConstrainedFrameSize: (NSSize)desiredSize;
// Sets the frame size of the view to desiredSize constrained within
// min and max size.
/***************** New miscellaneous API above and beyond NSText *****************/
- (void) changeColor: (id)sender;
// Called from NSColorPanel to set the text colour of the selection
- (void) alignJustified: (id)sender;
- (void) setAlignment: (NSTextAlignment)alignment range: (NSRange)range;
// These complete the set of range: type set methods. to be equivalent
// to the set of non-range taking varieties.
- (void) pasteAsPlainText: (id)sender;
- (void) pasteAsRichText: (id)sender;
// These methods are like paste: (from NSResponder) but they restrict
// the acceptable type of the pasted data. They are suitable as menu
// actions for appropriate "Paste As" submenu commands.
/*************************** New Font menu commands ***************************/
- (void) turnOffKerning: (id)sender;
- (void) tightenKerning: (id)sender;
- (void) loosenKerning: (id)sender;
- (void) useStandardKerning: (id)sender;
- (void) turnOffLigatures: (id)sender;
- (void) useStandardLigatures: (id)sender;
- (void) useAllLigatures: (id)sender;
- (void) raiseBaseline: (id)sender;
- (void) lowerBaseline: (id)sender;
- (void) toggleTraditionalCharacterShape: (id)sender;
/*************************** Ruler support ***************************/
- (void) setRulerVisible: (BOOL)flag;
/* This variant will create the text network (NSTextStorage, NSLayoutManager,
and a NSTextContainer). The network will be owned by the NSTextView;
releasing it will release all parts of the network. */
-(id) initWithFrame:(NSRect)frameRect;
- (void) rulerView: (NSRulerView *)ruler
didMoveMarker: (NSRulerMarker *)marker;
- (void) rulerView: (NSRulerView *)ruler
didRemoveMarker: (NSRulerMarker *)marker;
- (void) rulerView: (NSRulerView *)ruler
didAddMarker: (NSRulerMarker *)marker;
- (BOOL) rulerView: (NSRulerView *)ruler
shouldMoveMarker: (NSRulerMarker *)marker;
- (BOOL) rulerView: (NSRulerView *)ruler
shouldAddMarker: (NSRulerMarker *)marker;
- (float) rulerView: (NSRulerView *)ruler
willMoveMarker: (NSRulerMarker *)marker
toLocation: (float)location;
- (BOOL) rulerView: (NSRulerView *)ruler
shouldRemoveMarker: (NSRulerMarker *)marker;
- (float) rulerView: (NSRulerView *)ruler
willAddMarker: (NSRulerMarker *)marker
atLocation: (float)location;
- (void) rulerView: (NSRulerView *)ruler
handleMouseDown: (NSEvent *)event;
/**** Text network management ****/
/*************************** Fine display control ***************************/
/* The set method should not be called directly, but you might want to
override it. Gets or sets the text container for this view.
Setting the text container marks the view as needing display. The
text container calls the set method from its setTextView: method. */
-(NSTextContainer *) textContainer;
-(void) setTextContainer: (NSTextContainer *)container;
- (void) setNeedsDisplayInRect: (NSRect)rect
avoidAdditionalLayout: (BOOL)flag;
/* This method should be used instead of the primitive
-setTextContainer: if you need to replace a view's text container
with a new one leaving the rest of the text network intact. This method
deals with all the work of making sure the view doesn't get
deallocated and removing the old container from the layoutManager
and replacing it with the new one. */
-(void) replaceTextContainer: (NSTextContainer *)newContainer;
- (BOOL) shouldDrawInsertionPoint;
- (void) drawInsertionPointInRect: (NSRect)rect color: (NSColor *)color
turnedOn: (BOOL)flag;
- (void) cleanUpAfterDragOperation;
-(NSLayoutManager *) layoutManager;
-(NSTextStorage *) textStorage;
/*************************** Pasteboard management ***************************/
- (NSString *) preferredPasteboardTypeFromArray: (NSArray *)availableTypes
restrictedToTypesFromArray: (NSArray *)allowedTypes;
- (BOOL) readSelectionFromPasteboard: (NSPasteboard *)pboard;
- (BOOL) readSelectionFromPasteboard: (NSPasteboard *)pboard
type: (NSString *)type;
- (NSArray *) readablePasteboardTypes;
- (NSArray *) writablePasteboardTypes;
- (BOOL) writeSelectionToPasteboard: (NSPasteboard *)pboard
type: (NSString *)type;
- (BOOL) writeSelectionToPasteboard: (NSPasteboard *)pboard
types: (NSArray *)types;
/*************************** Especially for subclassers ***************************/
- (void) updateRuler;
- (void) updateFontPanel;
/*
These two methods are for modifying the text programmatically. They
don't ask the delegate are send any notifications, and they always work
(ie. even if the text view isn't editable).
- (NSArray *) acceptableDragTypes;
- (void) updateDragTypeRegistration;
- (NSImage *) dragImageForSelectionWithEvent: (NSEvent *)event
origin: (NSPoint *)origin;
- (unsigned int) dragOperationForDraggingInfo: (id <NSDraggingInfo>)dragInfo
type: (NSString *)type;
- (BOOL) dragSelectionWithEvent: (NSEvent *)event
offset: (NSSize)mouseOffset
slideBack: (BOOL)slideBack;
- (NSRange) selectionRangeForProposedRange: (NSRange)proposedCharRange
granularity: (NSSelectionGranularity)gr;
- (void) transpose: (id)sender;
// The methods in the following list deal with settings that need to be
// shared by all the GNUTextViews of a single NSLayoutManager. Many
// of these methods are overrides of NSText or NSResponder methods.
/*************************** Selected/Marked range ***************************/
- (void) setSelectedRange: (NSRange)charRange
affinity: (NSSelectionAffinity)affinity
stillSelecting: (BOOL)stillSelectingFlag;
/* Called by drawing routines to determine where to draw insertion
point */
- (NSSelectionAffinity) selectionAffinity;
- (NSSelectionGranularity) selectionGranularity;
- (void) setSelectionGranularity: (NSSelectionGranularity)granularity;
- (void) setSelectedTextAttributes: (NSDictionary *)attributeDictionary;
- (NSDictionary *) selectedTextAttributes;
- (void) setInsertionPointColor: (NSColor *)color;
- (NSColor *) insertionPointColor;
- (void) updateInsertionPointStateAndRestartTimer: (BOOL)restartFlag;
- (NSRange) markedRange;
- (void) setMarkedTextAttributes: (NSDictionary *)attributeDictionary;
- (NSDictionary *) markedTextAttributes;
/*************************** Other GNUTextView methods ***************************/
- (void) setRulerVisible: (BOOL)flag;
- (BOOL) usesRuler;
- (void) setUsesRuler: (BOOL)flag;
- (int) spellCheckerDocumentTag;
- (BOOL) isContinuousSpellCheckingEnabled;
- (void) setContinuousSpellCheckingEnabled: (BOOL)flag;
- (void) toggleContinuousSpellChecking: (id)sender;
- (NSDictionary *) typingAttributes;
- (void) setTypingAttributes: (NSDictionary *)attrs;
- (BOOL) shouldChangeTextInRange: (NSRange)affectedCharRange
replacementString: (NSString *)replacementString;
- (void) didChangeText;
- (NSRange) rangeForUserTextChange;
- (NSRange) rangeForUserCharacterAttributeChange;
- (NSRange) rangeForUserParagraphAttributeChange;
- (BOOL) allowsUndo;
- (void) setAllowsUndo: (BOOL)flag;
/*************************** NSText methods ***************************/
/* Declared in the superclass
- (BOOL) isSelectable;
- (void) setSelectable:(BOOL)flag;
- (BOOL) isEditable;
- (void) setEditable:(BOOL)flag;
- (BOOL) isRichText;
- (void) setRichText:(BOOL)flag;
- (BOOL) importsGraphics;
- (void) setImportsGraphics:(BOOL)flag;
- (id) delegate;
- (void) setDelegate:(id)anObject;
- (BOOL) isFieldEditor;
- (void) setFieldEditor:(BOOL)flag;
- (BOOL) usesFontPanel;
- (void) setUsesFontPanel:(BOOL)flag;
- (BOOL) isRulerVisible;
- (void) setBackgroundColor:(NSColor *)color;
- (NSColor *) backgroundColor;
- (void) setDrawsBackground:(BOOL)flag;
- (BOOL) drawsBackground;
(They are really from NSText, but redeclared here so they can be documented
here.)
*/
- (NSRange) selectedRange;
- (void) setSelectedRange:(NSRange)charRange;
- (void) replaceCharactersInRange: (NSRange)aRange
withString: (NSString*)aString;
/*************************** NSResponder methods ***************************/
/*
If the text view isn't rich-text, the attributes of aString will be ignored
and the typing attributed will be used.
*/
-(void) replaceCharactersInRange: (NSRange)aRange /* GNUstep extension. */
withAttributedString: (NSAttributedString *)aString;
- (void) resignKeyWindow;
- (void) becomeKeyWindow;
- (BOOL) resignFirstResponder;
- (BOOL) becomeFirstResponder;
- (id) validRequestorForSendType:(NSString *)sendType
returnType:(NSString *)returnType;
/*************************** Smart copy/paste/delete support ***************************/
- (BOOL) smartInsertDeleteEnabled;
- (void) setSmartInsertDeleteEnabled: (BOOL)flag;
- (NSRange) smartDeleteRangeForProposedRange: (NSRange)proposedCharRange;
- (void) smartInsertForString: (NSString *)aString
replacingRange: (NSRange)charRange
beforeString: (NSString **)beforeString
afterString: (NSString **)afterString;
/*** Additional Font menu commands ***/
/* These complete the set of range: type set methods. to be equivalent
to the set of non-range taking varieties. */
-(void) setAlignment: (NSTextAlignment)alignment range: (NSRange)range;
-(void) setRulerVisible: (BOOL)flag;
-(BOOL) usesRuler;
-(void) setUsesRuler: (BOOL)flag;
-(BOOL) isContinuousSpellCheckingEnabled; /* mosx */
-(void) setContinuousSpellCheckingEnabled: (BOOL)flag; /* mosx */
-(BOOL) allowsUndo; /* mosx */
-(void) setAllowsUndo: (BOOL)flag; /* mosx */
-(BOOL) smartInsertDeleteEnabled;
-(void) setSmartInsertDeleteEnabled: (BOOL)flag;
/* These methods are like paste: (from NSResponder) but they restrict
the acceptable type of the pasted data. They are suitable as menu
actions for appropriate "Paste As" submenu commands. */
-(void) pasteAsPlainText: (id)sender;
-(void) pasteAsRichText: (id)sender;
/*** Dealing with user changes ***/
-(BOOL) shouldChangeTextInRange: (NSRange)affectedCharRange
replacementString: (NSString *)replacementString;
-(void) didChangeText;
-(NSRange) rangeForUserTextChange;
-(NSRange) rangeForUserCharacterAttributeChange;
-(NSRange) rangeForUserParagraphAttributeChange;
/*** Text container stuff ***/
/* The text container inset determines the padding that the view provides
around the container. The text container is placed in a rectangle in the
text view's bounds rectangle, inset by inset.width on the left and right
edge and inset.height on the top and bottom edge.
Thus, setting this to (3,5) will give a 3 unit border on the left edge of
the text container, a 3 unit border on the right edge, a 5 unit border on
the top edge, and a 5 unit border on the bottom edge.
*/
-(void) setTextContainerInset: (NSSize)inset;
-(NSSize) textContainerInset;
/* The text container's origin is the origin of the text container's
coordinate system in the text view's coordinate system. It is determined
from the current usage of the container, the container inset, and the view
size. textContainerOrigin returns this point.
{TODO: why describe how the origin is determined? atm, it's even incorrect}
invalidateTextContainerOrigin is sent automatically whenever something
changes that might cause the origin to move. You usually do not need to call
it yourself. */
-(NSPoint) textContainerOrigin;
-(void) invalidateTextContainerOrigin;
/*** Sizing methods ***/
/* Sets the frame size of the view to desiredSize constrained within
(effective) minimum size and maximum size, and to the directions in which
the text view is resizable. */
-(void) setConstrainedFrameSize: (NSSize)desiredSize;
-(void) setSelectedTextAttributes: (NSDictionary *)attributeDictionary;
-(NSDictionary *) selectedTextAttributes;
-(void) setInsertionPointColor: (NSColor *)color;
-(NSColor *) insertionPointColor;
/*** Marked range ***/
-(void) setMarkedTextAttributes: (NSDictionary *)attributeDictionary;
-(NSDictionary *) markedTextAttributes;
@end
@interface NSTextView (GSTextViewUpdateMultipleViews)
/*
These methods are implemented in NSTextView_actions.m. See the comment in
that file for details on the split and which methods are for
user/programmatic changes of the text.
*/
@interface NSTextView (user_actions)
-(void) alignJustified: (id)sender; /* mosx */
-(void) turnOffKerning: (id)sender;
-(void) tightenKerning: (id)sender;
-(void) loosenKerning: (id)sender;
-(void) useStandardKerning: (id)sender;
-(void) turnOffLigatures: (id)sender;
-(void) useStandardLigatures: (id)sender;
-(void) useAllLigatures: (id)sender;
-(void) raiseBaseline: (id)sender;
-(void) lowerBaseline: (id)sender;
-(void) toggleTraditionalCharacterShape: (id)sender; /* mosx */
-(void) transpose: (id)sender; /* not OPENSTEP */
-(void) toggleContinuousSpellChecking: (id)sender; /* mosx */
@end
@interface NSTextView (leftovers)
/*** Ruler support ***/
-(void) rulerView: (NSRulerView *)ruler didMoveMarker: (NSRulerMarker *)marker;
-(void) rulerView: (NSRulerView *)ruler didRemoveMarker: (NSRulerMarker *)marker;
-(void) rulerView: (NSRulerView *)ruler didAddMarker: (NSRulerMarker *)marker;
-(BOOL) rulerView: (NSRulerView *)ruler shouldMoveMarker: (NSRulerMarker *)marker;
-(BOOL) rulerView: (NSRulerView *)ruler shouldRemoveMarker: (NSRulerMarker *)marker;
-(BOOL) rulerView: (NSRulerView *)ruler shouldAddMarker: (NSRulerMarker *)marker;
-(float) rulerView: (NSRulerView *)ruler
willMoveMarker: (NSRulerMarker *)marker
toLocation: (float)location;
-(float) rulerView: (NSRulerView *)ruler
willAddMarker: (NSRulerMarker *)marker
atLocation: (float)location;
-(void) rulerView: (NSRulerView *)ruler
handleMouseDown: (NSEvent *)event;
/*** Fine display control ***/
/* Like -setNeedsDisplayInRect: (NSView), bit if flag is YES, won't do any
layout. This means that it will only display the glyphs in rect that have
already been laid out. */
-(void) setNeedsDisplayInRect: (NSRect)rect
avoidAdditionalLayout: (BOOL)flag;
-(BOOL) shouldDrawInsertionPoint;
-(void) drawInsertionPointInRect: (NSRect)rect
color: (NSColor *)color
turnedOn: (BOOL)flag;
/*** Pasteboard management ***/
-(NSString *) preferredPasteboardTypeFromArray: (NSArray *)availableTypes
restrictedToTypesFromArray: (NSArray *)allowedTypes; /* mosx */
-(BOOL) readSelectionFromPasteboard: (NSPasteboard *)pboard; /* mosx */
-(BOOL) readSelectionFromPasteboard: (NSPasteboard *)pboard
type: (NSString *)type; /* mosx */
-(NSArray *) readablePasteboardTypes; /* mosx */
-(NSArray *) writablePasteboardTypes; /* mosx */
-(BOOL) writeSelectionToPasteboard: (NSPasteboard *)pboard
type: (NSString *)type; /* mosx */
-(BOOL) writeSelectionToPasteboard: (NSPasteboard *)pboard
types: (NSArray *)types; /* mosx */
/* TODO: check that this belongs under pasteboard management */
-(id) validRequestorForSendType: (NSString *)sendType
returnType: (NSString *)returnType; /* mosx */
/*** Drag and drop handling ***/
-(NSImage *) dragImageForSelectionWithEvent: (NSEvent *)event
origin: (NSPoint *)origin; /* mosx */
-(unsigned int) dragOperationForDraggingInfo: (id <NSDraggingInfo>)dragInfo
type: (NSString *)type; /* mosx */
-(BOOL) dragSelectionWithEvent: (NSEvent *)event
offset: (NSSize)mouseOffset
slideBack: (BOOL)slideBack; /* mosx */
-(void) cleanUpAfterDragOperation; /* mosx */
/*** Selected range ***/
-(NSRange) selectionRangeForProposedRange: (NSRange)proposedCharRange
granularity: (NSSelectionGranularity)gr;
-(NSRange) selectedRange;
-(void) setSelectedRange: (NSRange)charRange;
-(void) setSelectedRange: (NSRange)charRange
affinity: (NSSelectionAffinity)affinity
stillSelecting: (BOOL)stillSelectingFlag;
/* Called by drawing routines to determine where to draw insertion
point */
-(NSSelectionAffinity) selectionAffinity;
-(NSSelectionGranularity) selectionGranularity;
-(void) setSelectionGranularity: (NSSelectionGranularity)granularity;
-(void) updateInsertionPointStateAndRestartTimer: (BOOL)restartFlag;
/*** Spell checking ***/
-(int) spellCheckerDocumentTag;
/*** Smart copy/paste/delete support ***/
-(NSRange) smartDeleteRangeForProposedRange: (NSRange)proposedCharRange;
-(void) smartInsertForString: (NSString *)aString
replacingRange: (NSRange)charRange
beforeString: (NSString **)beforeString
afterString: (NSString **)afterString;
/** TODO: categorize */
-(NSDictionary *) typingAttributes;
-(void) setTypingAttributes: (NSDictionary *)attrs;
-(void) updateRuler;
-(void) updateFontPanel;
-(NSArray *) acceptableDragTypes;
-(void) updateDragTypeRegistration;
@end
@interface NSTextView (GSTextView_sync)
/*
* This queries the NSLayoutManager to see if it is using multiple
* text views, and saves this information in a flag, and caches the
* first text view object. The NSLayoutManager needs to call this
* method to update this information. */
- (void) _updateMultipleTextViews;
-(void) _updateMultipleTextViews;
/* For internal use. */
-(void) _syncTextViewsByCalling: (SEL)action withFlag: (BOOL)flag;
-(void) _recacheDelegateResponses;
@end
// Note that all delegation messages come from the first textView
/* Note that all delegation messages come from the first text view of a
layout manager. */
@interface NSObject (NSTextViewDelegate)
- (void) textView: (NSTextView *)textView
clickedOnCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)cellFrame;
- (void) textView: (NSTextView *)textView
clickedOnCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)cellFrame
atIndex: (unsigned)charIndex;
-(void) textView: (NSTextView *)textView
clickedOnCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)cellFrame;
-(void) textView: (NSTextView *)textView
clickedOnCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)cellFrame
atIndex: (unsigned)charIndex;
- (BOOL) textView: (NSTextView *)textView clickedOnLink: (id)link;
- (BOOL) textView: (NSTextView *)textView
clickedOnLink: (id)link
atIndex: (unsigned)charIndex;
-(BOOL) textView: (NSTextView *)textView clickedOnLink: (id)link;
-(BOOL) textView: (NSTextView *)textView
clickedOnLink: (id)link
atIndex: (unsigned)charIndex;
- (void) textView: (NSTextView *)textView
-(void) textView: (NSTextView *)textView
doubleClickedOnCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)cellFrame;
- (void) textView: (NSTextView *)textView
inRect: (NSRect)cellFrame;
-(void) textView: (NSTextView *)textView
doubleClickedOnCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)cellFrame
atIndex: (unsigned)charIndex;
inRect: (NSRect)cellFrame
atIndex: (unsigned)charIndex;
- (void) textView: (NSTextView *)view
draggedCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)rect event:(NSEvent *)event;
- (void) textView: (NSTextView *)view
draggedCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)rect
event: (NSEvent *)event
atIndex: (unsigned)charIndex;
-(void) textView: (NSTextView *)view
draggedCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)rect event:(NSEvent *)event;
-(void) textView: (NSTextView *)view
draggedCell: (id <NSTextAttachmentCell>)cell
inRect: (NSRect)rect
event: (NSEvent *)event
atIndex: (unsigned)charIndex;
- (NSRange) textView: (NSTextView *)textView
-(NSRange) textView: (NSTextView *)textView
willChangeSelectionFromCharacterRange: (NSRange)oldSelectedCharRange
toCharacterRange: (NSRange)newSelectedCharRange;
toCharacterRange: (NSRange)newSelectedCharRange;
- (void) textViewDidChangeSelection: (NSNotification *)notification;
-(void) textViewDidChangeSelection: (NSNotification *)notification;
- (BOOL) textView: (NSTextView *)textView
shouldChangeTextInRange: (NSRange)affectedCharRange
replacementString: (NSString *)replacementString;
// If characters are changing, replacementString is what will replace
// the affectedCharRange. If attributes only are changing,
// replacementString will be nil.
/* If characters are changing, replacementString is what will replace
the affectedCharRange. If attributes only are changing,
replacementString will be nil. */
-(BOOL) textView: (NSTextView *)textView
shouldChangeTextInRange: (NSRange)affectedCharRange
replacementString: (NSString *)replacementString;
- (BOOL) textView: (NSTextView *)textView
doCommandBySelector: (SEL)commandSelector;
-(BOOL) textView: (NSTextView *)textView
doCommandBySelector: (SEL)commandSelector;
- (NSUndoManager *) undoManagerForTextView: (NSTextView *)view;
-(NSUndoManager *) undoManagerForTextView: (NSTextView *)view;
@end
/* NSOldNotifyingTextView -> the old view, NSNewNotifyingTextView ->
the new view. The text view delegate is not automatically
registered to receive this notification because the text machinery
will automatically switch over the delegate to observe the new
first text view as the first text view changes. */
APPKIT_EXPORT NSString *NSTextViewWillChangeNotifyingTextViewNotification;
// NSOldNotifyingTextView -> the old view, NSNewNotifyingTextView ->
// the new view. The text view delegate is not automatically
// registered to receive this notification because the text machinery
// will automatically switch over the delegate to observe the new
// first text view as the first text view changes.
APPKIT_EXPORT NSString *NSTextViewDidChangeSelectionNotification;
APPKIT_EXPORT NSString *NSOldSelectedCharacterRange;
#endif /* _GNUstep_H_NSTextView */
#if 0
// NSFontAttributeName; /* NSFont, default Helvetica 12 */
// NSParagraphStyleAttributeName; /* NSParagraphStyle, default defaultParagraphStyle */
// NSForegroundColorAttributeName; /* NSColor, default blackColor */
// NSUnderlineStyleAttributeName; /* int, default 0: no underline */
// NSSuperscriptAttributeName; /* int, default 0 */
// NSBackgroundColorAttributeName; /* NSColor, default nil: no background */
// NSAttachmentAttributeName; /* NSTextAttachment, default nil */
// NSLigatureAttributeName; /* int, default 1: default ligatures, 0: no ligatures, 2: all ligatures */
// NSBaselineOffsetAttributeName; /* float, in points; offset from baseline, default 0 */
// NSKernAttributeName; /* float, amount to modify default kerning, if 0, kerning off */
#endif

View file

@ -146,7 +146,6 @@ NSTextContainer.m \
NSTextField.m \
NSTextFieldCell.m \
NSTextStorage.m \
NSTextView.m \
NSToolbar.m \
NSToolbarItem.m \
NSView.m \
@ -169,9 +168,13 @@ GSFontInfo.m \
GSTable.m \
GSHbox.m \
GSVbox.m \
GSSimpleLayoutManager.m \
GSKeyBindingAction.m \
GSKeyBindingTable.m
GSKeyBindingTable.m \
NSTextView.m \
NSTextView_actions.m \
GSLayoutManager.m \
GSTypesetter.m \
GSHorizontalTypesetter.m
ifneq ($(FOUNDATION_LIB), fd)
libgnustep-gui_OBJC_FILES += NSPasteboard.m
@ -321,7 +324,11 @@ NSNibDeclarations.h \
NSNibLoading.h \
NSSpellProtocol.h \
NSUserInterfaceValidation.h \
PSOperators.h
PSOperators.h \
GSLayoutManager.h \
GSLayoutManager_internal.h \
GSTypesetter.h \
GSHorizontalTypesetter.h
# Extra DLL exports file
libgnustep-gui_DLL_DEF = libgnustep-gui.def

View file

@ -25,6 +25,8 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <math.h>
#include <AppKit/GSFontInfo.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
@ -91,7 +93,9 @@ static GSFontEnumerator *sharedEnumerator = nil;
@end
@interface GSFontInfo (Backend)
-initWithFontName: (NSString *)fontName matrix: (const float *)fmatrix;
-initWithFontName: (NSString *)fontName
matrix: (const float *)fmatrix
screenFont: (BOOL)screenFont;
@end
@implementation GSFontInfo
@ -102,10 +106,12 @@ static GSFontEnumerator *sharedEnumerator = nil;
}
+ (GSFontInfo*) fontInfoForFontName: (NSString*)nfontName
matrix: (const float *)fmatrix;
matrix: (const float *)fmatrix
screenFont: (BOOL)screenFont;
{
return AUTORELEASE([[fontInfoClass alloc] initWithFontName: nfontName
matrix: fmatrix]);
matrix: fmatrix
screenFont: screenFont]);
}
+ (int) weightForString: (NSString *)weightString
@ -337,7 +343,7 @@ static GSFontEnumerator *sharedEnumerator = nil;
- (float) defaultLineHeightForFont
{
// ascent plus descent plus some suitable linegap
return [self ascender] - [self descender] + [self pointSize]/ 11.0;
return [self ascender] - [self descender] + ceil([self pointSize]/ 11.0);
}
- (NSSize) advancementForGlyph: (NSGlyph)aGlyph

View file

@ -0,0 +1,683 @@
/*
GSHorizontalTypesetter.m
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Alexander Malmberg <alexander@malmberg.org>
Date: 2002
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,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "AppKit/GSHorizontalTypesetter.h"
#include "AppKit/GSLayoutManager.h"
#include <Foundation/NSException.h>
#include <Foundation/NSLock.h>
#include <Foundation/NSValue.h>
#include <Foundation/NSGeometry.h>
#include "AppKit/NSTextStorage.h"
#include "AppKit/NSParagraphStyle.h"
#include "AppKit/NSTextContainer.h"
@implementation GSHorizontalTypesetter
- init
{
if (!(self = [super init])) return nil;
lock = [[NSLock alloc] init];
return self;
}
-(void) dealloc
{
if (cache)
{
free(cache);
cache = NULL;
}
[super dealloc];
}
+(GSHorizontalTypesetter *) sharedInstance
{
static GSHorizontalTypesetter *shared;
if (!shared)
shared = [[self alloc] init];
return shared;
}
typedef struct GSHorizontalTypesetter_glyph_cache_s
{
NSGlyph g;
int char_index;
NSFont *font;
struct
{
BOOL explicit_kern;
float kern;
float baseline_offset;
int superscript;
} attributes;
BOOL nominal;
NSPoint pos; /* relative to the baseline */
float width;
BOOL dont_show, outside_line_frag;
} glyph_cache_t;
/* TODO: if we could know whether the layout manager had been modified since
the last time or not, we wouldn't need to clear the cache every time */
-(void) _cacheClear
{
cache_length = 0;
}
-(void) _cacheAttributes
{
NSNumber *n;
n = [curAttributes objectForKey: NSKernAttributeName];
if (!n)
attributes.explicit_kern = NO;
else
{
attributes.explicit_kern = YES;
attributes.kern = [n floatValue];
}
n = [curAttributes objectForKey: NSBaselineOffsetAttributeName];
if (n)
attributes.baseline_offset = [n floatValue];
else
attributes.baseline_offset = 0.0;
n = [curAttributes objectForKey: NSSuperscriptAttributeName];
if (n)
attributes.superscript = [n intValue];
else
attributes.superscript = 0;
}
-(void) _cacheMoveTo: (unsigned int)glyph
{
BOOL valid;
if (cache_base <= glyph && cache_base + cache_length > glyph)
{
int delta = glyph - cache_base;
cache_length -= delta;
memmove(cache,&cache[delta],sizeof(glyph_cache_t) * cache_length);
cache_base = glyph;
return;
}
cache_base = glyph;
cache_length = 0;
[curLayoutManager glyphAtIndex: glyph
isValidIndex: &valid];
if (valid)
{
unsigned int i;
at_end = NO;
i = [curLayoutManager characterIndexForGlyphAtIndex: glyph];
curAttributes = [curTextStorage attributesAtIndex: i
effectiveRange: &attributeRange];
[self _cacheAttributes];
paragraphRange = NSMakeRange(i,[curTextStorage length] - i);
curParagraphStyle = [curTextStorage attribute: NSParagraphStyleAttributeName
atIndex: i
longestEffectiveRange: &paragraphRange
inRange: paragraphRange];
curFont = [curLayoutManager effectiveFontForGlyphAtIndex: glyph
range: &fontRange];
}
else
at_end = YES;
}
-(void) _cacheGlyphs: (unsigned int)new_length
{
glyph_cache_t *g;
BOOL valid;
if (cache_size < new_length)
{
cache_size = new_length;
cache = realloc(cache,sizeof(glyph_cache_t) * cache_size);
}
for (g = &cache[cache_length];cache_length < new_length;cache_length++,g++)
{
g->g = [curLayoutManager glyphAtIndex: cache_base + cache_length
isValidIndex: &valid];
if (!valid)
{
at_end = YES;
break;
}
g->char_index = [curLayoutManager characterIndexForGlyphAtIndex: cache_base + cache_length];
// printf("cache glyph %i, char %i\n",cache_base + cache_length,g->char_index);
if (g->char_index >= paragraphRange.location + paragraphRange.length)
{
at_end = YES;
break;
}
/* cache attributes */
if (g->char_index >= attributeRange.location + attributeRange.length)
{
curAttributes = [curTextStorage attributesAtIndex: g->char_index
effectiveRange: &attributeRange];
[self _cacheAttributes];
}
g->attributes.explicit_kern = attributes.explicit_kern;
g->attributes.kern = attributes.kern;
g->attributes.baseline_offset = attributes.baseline_offset;
g->attributes.superscript = attributes.superscript;
if (cache_base + cache_length >= fontRange.location + fontRange.length)
{
curFont = [curLayoutManager effectiveFontForGlyphAtIndex: cache_base + cache_length
range: &fontRange];
}
g->font = curFont;
g->dont_show = NO;
g->outside_line_frag = NO;
}
}
/*
Should return the first glyph on the next line, which must be <=gi and
>=cache_base (TODO: not enough). Glyphs up to and including gi will have
been cached.
*/
-(unsigned int) breakLineByWordWrappingBefore: (unsigned int)gi
{
glyph_cache_t *g;
unichar ch;
NSString *str = [curTextStorage string];
gi -= cache_base;
g = cache + gi;
while (gi > 0)
{
if (g->g == NSControlGlyph)
return gi;
ch = [str characterAtIndex: g->char_index];
if (ch == 0x20 || ch == 0x0a || ch == 0x0d /* TODO: paragraph/line separator */ )
{
g->dont_show = YES;
if (gi > 0)
{
g->pos = g[-1].pos;
g->pos.x += g[-1].width;
}
else
g->pos = NSMakePoint(0,0);
g->width = 0;
return gi + 1 + cache_base;
}
gi--;
g--;
}
return gi + cache_base;
}
typedef struct
{
NSRect rect;
float last_used;
unsigned int last_glyph; /* last_glyph+1, actually */
} line_frag_t;
-(void) fullJustifyLine: (line_frag_t *)lf : (int)num_line_frags
{
unsigned int i,start;
float extra_space,delta;
unsigned int num_spaces;
NSString *str = [curTextStorage string];
glyph_cache_t *g;
unichar ch;
for (start = 0;num_line_frags;num_line_frags--,lf++)
{
num_spaces = 0;
for (i = start,g = cache + i;i < lf->last_glyph;i++,g++)
{
if (g->dont_show)
continue;
ch = [str characterAtIndex: g->char_index];
if (ch == 0x20)
num_spaces++;
}
if (!num_spaces)
continue;
extra_space = lf->rect.size.width - lf->last_used;
extra_space /= num_spaces;
delta = 0;
for (i = start,g = cache + i;i < lf->last_glyph;i++,g++)
{
g->pos.x += delta;
if (!g->dont_show && [str characterAtIndex: g->char_index] == 0x20)
{
if (i < lf->last_glyph)
g[1].nominal = NO;
delta += extra_space;
}
}
start = lf->last_glyph;
}
}
-(void) rightAlignLine: (line_frag_t *)lf : (int)num_line_frags
{
unsigned int i;
float delta;
glyph_cache_t *g;
for (i = 0,g = cache;num_line_frags;num_line_frags--,lf++)
{
delta = lf->rect.size.width - lf->last_used;
for (;i < lf->last_glyph;i++,g++)
g->pos.x += delta;
}
}
-(void) centerAlignLine: (line_frag_t *)lf : (int)num_line_frags
{
unsigned int i;
float delta;
glyph_cache_t *g;
for (i = 0,g = cache;num_line_frags;num_line_frags--,lf++)
{
delta = (lf->rect.size.width - lf->last_used) / 2.0;
for (;i < lf->last_glyph;i++,g++)
g->pos.x += delta;
}
}
-(int) layoutLineNewParagraph: (BOOL)newParagraph
{
NSRect rect,remain;
float line_height,max_line_height,baseline;
line_frag_t *line_frags = NULL;
int num_line_frags = 0;
[self _cacheMoveTo: curGlyph];
if (!cache_length)
[self _cacheGlyphs: 16];
if (!cache_length && at_end)
return 2;
{
float min = [curParagraphStyle minimumLineHeight];
max_line_height = [curParagraphStyle maximumLineHeight];
/* sanity */
if (max_line_height < min)
max_line_height = min;
line_height = [cache->font defaultLineHeightForFont];
baseline = line_height + [cache->font descender];
if (line_height < min)
line_height = min;
if (max_line_height > 0 && line_height > max_line_height)
line_height = max_line_height;
}
/* If we find out that we need to increase the line height, we have to
start over. The increased line height might give _completely_ different
line frag rects, so we can't reuse much of the layout information. */
restart:
// printf("start: at (%g %g) line_height = %g, baseline = %g\n",curPoint.x,curPoint.y,line_height,baseline);
{
float hindent,tindent = [curParagraphStyle tailIndent];
if (newParagraph)
hindent = [curParagraphStyle firstLineHeadIndent];
else
hindent = [curParagraphStyle headIndent];
if (tindent <= 0.0)
tindent = [curTextContainer containerSize].width + tindent;
remain = NSMakeRect(hindent,
curPoint.y,
tindent - hindent,
line_height + [curParagraphStyle lineSpacing]);
}
num_line_frags = 0;
if (line_frags)
{
free(line_frags);
line_frags = NULL;
}
while (1)
{
rect = [curTextContainer lineFragmentRectForProposedRect: remain
sweepDirection: NSLineSweepRight
movementDirection: num_line_frags?NSLineDoesntMove:NSLineMoveDown
remainingRect: &remain];
if (NSEqualRects(rect,NSZeroRect))
break;
num_line_frags++;
line_frags = realloc(line_frags,sizeof(line_frag_t) * num_line_frags);
line_frags[num_line_frags - 1].rect = rect;
}
if (!num_line_frags)
return 1;
{
unsigned int i = 0;
NSFont *f = cache->font;
glyph_cache_t *g;
NSGlyph last_glyph = NSNullGlyph;
NSPoint last_p,p;
unsigned int first_glyph;
line_frag_t *lf = line_frags;
int lfi = 0;
last_p = p = NSMakePoint(0,0);
g = cache;
first_glyph = 0;
while (1)
{
relayout:
if (i >= cache_length)
{
if (at_end)
break;
[self _cacheGlyphs: cache_length + 16];
if (i == cache_length)
break;
g = cache + i;
}
if (g->font != f)
{
float new_height;
f = g->font;
last_glyph = NSNullGlyph;
new_height = [f defaultLineHeightForFont];
if (max_line_height > 0 && new_height > max_line_height)
new_height = max_line_height;
if (new_height > line_height)
{
line_height = new_height;
baseline = line_height + [f descender];
goto restart;
}
}
if (g->g == NSControlGlyph)
{
unichar ch = [[curTextStorage string] characterAtIndex: g->char_index];
g->pos = p;
g->width = 0;
g->dont_show = YES;
g->nominal = YES;
i++;
g++;
last_glyph = NSNullGlyph;
if (ch == 0xa)
break;
continue;
}
g->nominal = YES;
if (g->attributes.explicit_kern)
p.x += g->attributes.kern;
/* TODO: this is a major bottleneck */
/* else if (last_glyph)
{
p = [f positionOfGlyph: g->g
precededByGlyph: last_glyph
isNominal: &g->nominal];
p.x += last_p.x;
p.y += last_p.y;
}*/
last_p = g->pos = p;
g->width = [f advancementForGlyph: g->g].width;
p.x += g->width;
if (p.x > lf->rect.size.width)
{
switch ([curParagraphStyle lineBreakMode])
{
default:
case NSLineBreakByCharWrapping:
char_wrapping:
lf->last_glyph = i;
break;
case NSLineBreakByWordWrapping:
lf->last_glyph = [self breakLineByWordWrappingBefore: cache_base + i] - cache_base;
if (lf->last_glyph <= first_glyph)
goto char_wrapping;
break;
}
/* We force at least one glyph into each line frag rect. This
ensures that typesetting will never get stuck (ie. if the text
container is to narrow to fit even a single glyph). */
if (lf->last_glyph <= first_glyph)
lf->last_glyph = i + 1;
last_p = p = NSMakePoint(0,0);
i = lf->last_glyph;
g = cache + i;
/* The -1 is always valid since there's at least one glyph in the
line frag rect (see above). */
lf->last_used = g[-1].pos.x + g[-1].width;
last_glyph = NSNullGlyph;
lf++;
lfi++;
if (lfi == num_line_frags)
break;
first_glyph = i;
goto relayout;
}
last_glyph = g->g;
i++;
g++;
}
if (lfi != num_line_frags)
{
lf->last_glyph = i;
lf->last_used = p.x;
/* TODO: incorrect if there is more than one line frag */
if ([curParagraphStyle alignment] == NSRightTextAlignment)
[self rightAlignLine: line_frags : num_line_frags];
else if ([curParagraphStyle alignment] == NSCenterTextAlignment)
[self centerAlignLine: line_frags : num_line_frags];
newParagraph = YES;
}
else
{
if ([curParagraphStyle lineBreakMode] == NSLineBreakByWordWrapping &&
[curParagraphStyle alignment] == NSJustifiedTextAlignment)
[self fullJustifyLine: line_frags : num_line_frags];
else if ([curParagraphStyle alignment] == NSRightTextAlignment)
[self rightAlignLine: line_frags : num_line_frags];
else if ([curParagraphStyle alignment] == NSCenterTextAlignment)
[self centerAlignLine: line_frags : num_line_frags];
lfi--;
newParagraph = NO;
}
[curLayoutManager setTextContainer: curTextContainer
forGlyphRange: NSMakeRange(cache_base,i)];
curGlyph = i + cache_base;
{
line_frag_t *lf;
NSPoint p;
unsigned int i,j;
glyph_cache_t *g;
for (lf = line_frags,i = 0,g = cache;lfi >= 0;lfi--,lf++)
{
[curLayoutManager setLineFragmentRect: lf->rect
forGlyphRange: NSMakeRange(cache_base + i,lf->last_glyph - i)
usedRect: lf->rect /* TODO */ ];
p = g->pos;
[curLayoutManager setDrawsOutsideLineFragment: g->outside_line_frag
forGlyphAtIndex: cache_base + i];
[curLayoutManager setNotShownAttribute: g->dont_show
forGlyphAtIndex: cache_base + i];
p.y += baseline;
j = i;
while (i < lf->last_glyph)
{
if (!g->nominal && i != j)
{
[curLayoutManager setLocation: p
forStartOfGlyphRange: NSMakeRange(cache_base + j,i - j)];
p = g->pos;
p.y += baseline;
j = i;
}
i++;
g++;
}
if (i != j)
{
[curLayoutManager setLocation: p
forStartOfGlyphRange: NSMakeRange(cache_base + j,i - j)];
}
}
}
}
curPoint = NSMakePoint(0,NSMaxY(line_frags->rect));
if (line_frags)
{
free(line_frags);
line_frags = NULL;
}
/* if we're really at the end, we should probably set the extra line frag
stuff here */
if (newParagraph)
return 3;
else
return 0;
}
-(int) layoutGlyphsInLayoutManager: (GSLayoutManager *)layoutManager
inTextContainer: (NSTextContainer *)textContainer
startingAtGlyphIndex: (unsigned int)glyphIndex
previousLineFragmentRect: (NSRect)previousLineFragRect
nextGlyphIndex: (unsigned int *)nextGlyphIndex
numberOfLineFragments: (unsigned int)howMany
{
int ret = 0;
BOOL newParagraph;
[lock lock];
NS_DURING
curLayoutManager = layoutManager;
curTextContainer = textContainer;
curTextStorage = [layoutManager textStorage];
/* printf("*** layout some stuff |%@|\n",curTextStorage);
[curLayoutManager _glyphDumpRuns];*/
curGlyph = glyphIndex;
[self _cacheClear];
newParagraph = NO;
if (!curGlyph)
newParagraph = YES;
ret = 0;
curPoint = NSMakePoint(0,NSMaxY(previousLineFragRect));
while (1)
{
ret = [self layoutLineNewParagraph: newParagraph];
if (ret == 3)
{
newParagraph = YES;
ret = 0;
}
else
newParagraph = NO;
if (ret)
break;
if (howMany)
if (!--howMany)
break;
}
*nextGlyphIndex = curGlyph;
NS_HANDLER
[lock unlock];
printf("got exception %@\n",localException);
[localException raise];
NS_ENDHANDLER
[lock unlock];
return ret;
}
@end

2187
Source/GSLayoutManager.m Normal file

File diff suppressed because it is too large Load diff

View file

@ -45,6 +45,9 @@
#include <Foundation/NSArray.h>
#include <Foundation/NSDebug.h>
#include <Foundation/NSZone.h>
#include <Foundation/NSLock.h>
#include <Foundation/NSThread.h>
#include <Foundation/NSNotification.h>
#include <AppKit/NSTextStorage.h>
#include "GSTextStorage.h"

83
Source/GSTypesetter.m Normal file
View file

@ -0,0 +1,83 @@
/*
GSTypesetter.m
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Alexander Malmberg <alexander@malmberg.org>
Date: 2002
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,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "AppKit/GSTypesetter.h"
#include "AppKit/GSLayoutManager.h"
#include "AppKit/GSHorizontalTypesetter.h"
#include <Foundation/NSDictionary.h>
#include <AppKit/NSAttributedString.h>
@implementation GSTypesetter
+ (NSSize) printingAdjustmentsInLayoutManager: (GSLayoutManager *)layoutManager
forNominallySpacedGlyphRange: (NSRange)glyphRange
packedGlyphs: (const unsigned char *)glyphs
count: (unsigned)packedGlyphCount
{
return NSMakeSize(0,0);
}
+(GSTypesetter *) sharedSystemTypesetter
{
return [GSHorizontalTypesetter sharedInstance];
}
-(NSFont *) fontForCharactersWithAttributes: (NSDictionary *)attributes
{
NSFont *f = [attributes valueForKey: NSFontAttributeName];
if (!f)
f = [NSFont userFontOfSize: 0];
return f;
}
-(int) layoutGlyphsInLayoutManager: (GSLayoutManager *)layoutManager
inTextContainer: (NSTextContainer *)textContainer
startingAtGlyphIndex: (unsigned int)glyphIndex
previousLineFragmentRect: (NSRect)previousLineFragRect
nextGlyphIndex: (unsigned int *)nextGlyphIndex
numberOfLineFragments: (unsigned int)howMany
{
[self subclassResponsibility: _cmd];
return 0;
}
-(BOOL) relayoutGlyphsInLayoutManager: (GSLayoutManager *)layoutManager
glyphRange: (NSRange)glyphRange
lineFragmentRect: (NSRect *)lineFragRect
textContainer: (NSTextContainer **)textContainer
previousLineFragmentRect: (NSRect)previousLineFragRect
{
return NO;
}
@end

View file

@ -52,7 +52,8 @@ static NSFont *placeHolder = nil;
@interface NSFont (Private)
- (id) initWithName: (NSString*)name
matrix: (const float*)fontMatrix
fix: (BOOL)explicitlySet;
fix: (BOOL)explicitlySet
screenFont: (BOOL)screenFont;
@end
static int currentVersion = 2;
@ -61,14 +62,16 @@ static int currentVersion = 2;
* Just to ensure that we use a standard name in the cache.
*/
static NSString*
newNameWithMatrix(NSString *name, const float *matrix, BOOL fix)
newNameWithMatrix(NSString *name, const float *matrix, BOOL fix,
BOOL screenFont)
{
NSString *nameWithMatrix;
nameWithMatrix = [[NSString alloc] initWithFormat:
@"%@ %.3f %.3f %.3f %.3f %.3f %.3f %c", name,
@"%@ %.3f %.3f %.3f %.3f %.3f %.3f %c %c", name,
matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5],
(fix == NO) ? 'N' : 'Y'];
(fix == NO) ? 'N' : 'Y',
screenFont ? 'S' : 'P'];
return nameWithMatrix;
}
@ -555,7 +558,10 @@ setNSFont(NSString* key, NSFont* font)
else
fix = YES;
font = [placeHolder initWithName: aFontName matrix: fontMatrix fix: fix];
font = [placeHolder initWithName: aFontName
matrix: fontMatrix
fix: fix
screenFont: NO];
return AUTORELEASE(font);
}
@ -582,7 +588,10 @@ setNSFont(NSString* key, NSFont* font)
fontMatrix[0] = fontSize;
fontMatrix[3] = fontSize;
font = [placeHolder initWithName: aFontName matrix: fontMatrix fix: NO];
font = [placeHolder initWithName: aFontName
matrix: fontMatrix
fix: NO
screenFont: NO];
return AUTORELEASE(font);
}
@ -612,6 +621,7 @@ setNSFont(NSString* key, NSFont* font)
- (id) initWithName: (NSString*)name
matrix: (const float*)fontMatrix
fix: (BOOL)explicitlySet
screenFont: (BOOL)screen;
{
NSString *nameWithMatrix;
NSFont *font;
@ -620,7 +630,8 @@ setNSFont(NSString* key, NSFont* font)
NSAssert(fontName == nil, NSInternalInconsistencyException);
/* Check whether the font is cached */
nameWithMatrix = newNameWithMatrix(name, fontMatrix, explicitlySet);
nameWithMatrix = newNameWithMatrix(name, fontMatrix, explicitlySet,
screen);
font = (id)NSMapGet(globalFontMap, (void*)nameWithMatrix);
if (font == nil)
{
@ -636,8 +647,10 @@ setNSFont(NSString* key, NSFont* font)
fontName = [name copy];
memcpy(matrix, fontMatrix, sizeof(matrix));
matrixExplicitlySet = explicitlySet;
screenFont = screen;
fontInfo = RETAIN([GSFontInfo fontInfoForFontName: fontName
matrix: fontMatrix]);
matrix: fontMatrix
screenFont: screen]);
if (fontInfo == nil)
{
RELEASE (self);
@ -666,7 +679,8 @@ setNSFont(NSString* key, NSFont* font)
{
NSString *nameWithMatrix;
nameWithMatrix = newNameWithMatrix(fontName, matrix, matrixExplicitlySet);
nameWithMatrix = newNameWithMatrix(fontName, matrix,
matrixExplicitlySet, screenFont);
NSMapRemove(globalFontMap, (void*)nameWithMatrix);
RELEASE(nameWithMatrix);
RELEASE(fontName);
@ -680,7 +694,8 @@ setNSFont(NSString* key, NSFont* font)
NSString *nameWithMatrix;
NSString *description;
nameWithMatrix = newNameWithMatrix(fontName, matrix, matrixExplicitlySet);
nameWithMatrix = newNameWithMatrix(fontName, matrix, matrixExplicitlySet,
screenFont);
description = [[super description] stringByAppendingFormat: @" %@",
nameWithMatrix];
RELEASE(nameWithMatrix);
@ -728,7 +743,10 @@ setNSFont(NSString* key, NSFont* font)
float fontMatrix[6];
memcpy(fontMatrix, matrix, sizeof(matrix));
fontMatrix[3] *= -1;
return [NSFont fontWithName: fontName matrix: fontMatrix];
return AUTORELEASE([placeHolder initWithName: fontName
matrix: fontMatrix
fix: YES
screenFont: screenFont]);
}
//
@ -768,8 +786,26 @@ setNSFont(NSString* key, NSFont* font)
- (NSDictionary*) afmDictionary { return [fontInfo afmDictionary]; }
- (NSString*) afmFileContents { return [fontInfo afmFileContents]; }
- (NSFont*) printerFont { return self; }
- (NSFont*) screenFont { return self; }
- (NSFont*) printerFont
{
if (!screenFont)
return self;
return [placeHolder initWithName: fontName
matrix: matrix
fix: matrixExplicitlySet
screenFont: NO];
}
- (NSFont*) screenFont
{
if (screenFont)
return self;
return [placeHolder initWithName: fontName
matrix: matrix
fix: matrixExplicitlySet
screenFont: YES];
}
- (float) ascender { return [fontInfo ascender]; }
- (float) descender { return [fontInfo descender]; }
- (float) capHeight { return [fontInfo capHeight]; }
@ -934,7 +970,10 @@ setNSFont(NSString* key, NSFont* font)
fix = YES;
}
self = [self initWithName: name matrix: fontMatrix fix: fix];
self = [self initWithName: name
matrix: fontMatrix
fix: fix
screenFont: NO];
return self;
}

File diff suppressed because it is too large Load diff

View file

@ -474,4 +474,14 @@ static NSParagraphStyle *defaultStyle = nil;
_tailIndent = p->_tailIndent;
}
- (id) copyWithZone: (NSZone*)aZone
{
NSMutableParagraphStyle *c;
c = (NSMutableParagraphStyle*)NSCopyObject (self, 0, aZone);
c->isa = [NSParagraphStyle class];
c->_tabStops = [_tabStops mutableCopyWithZone: aZone];
return c;
}
@end

View file

@ -29,21 +29,22 @@
*/
#include <gnustep/gui/config.h>
#include <Foundation/NSException.h>
#include <AppKit/NSSecureTextField.h>
#include <AppKit/NSImage.h>
#include <AppKit/NSFont.h>
#include <AppKit/NSTextView.h>
#include <AppKit/NSLayoutManager.h>
#include <AppKit/NSTextContainer.h>
#include <AppKit/NSWindow.h>
#include <AppKit/NSEvent.h>
#include "GSSimpleLayoutManager.h"
/* 'Secure' subclasses */
@interface NSSecureTextView : NSTextView
{}
@end
@interface GSSimpleSecureLayoutManager : GSSimpleLayoutManager
@interface GSSimpleSecureLayoutManager : NSLayoutManager
{}
@end

View file

@ -35,31 +35,12 @@
59 Temple Place - Suite 330, Boston, MA 02111 - 1307, USA.
*/
#include <Foundation/NSNotification.h>
#include <Foundation/NSString.h>
#include <Foundation/NSArchiver.h>
#include <Foundation/NSValue.h>
#include <Foundation/NSData.h>
#include <AppKit/NSFileWrapper.h>
#include <AppKit/NSControl.h>
#include <AppKit/NSText.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSWindow.h>
#include <AppKit/NSFontManager.h>
#include <AppKit/NSFont.h>
#include <AppKit/NSColor.h>
#include <AppKit/NSParagraphStyle.h>
#include <AppKit/NSPasteboard.h>
//#include <AppKit/NSTextView.h>
@class NSTextView;
#include <AppKit/NSSpellChecker.h>
#include <AppKit/NSScrollView.h>
#include <AppKit/NSPanel.h>
#include <AppKit/NSAttributedString.h>
#include <AppKit/NSDragging.h>
#include <AppKit/NSTextStorage.h>
#include <AppKit/NSTextContainer.h>
#include <AppKit/NSLayoutManager.h>
static Class abstract;
static Class concrete;
@ -92,22 +73,6 @@ static Class concrete;
* Instance methods
*/
/*
* Initialization
*/
- (id) init
{
return [self initWithFrame: NSMakeRect (0, 0, 100, 100)];
}
- (void) dealloc
{
RELEASE (_background_color);
[super dealloc];
}
/*
* Getting and Setting Contents
*/
@ -118,7 +83,7 @@ static Class concrete;
attr = [[NSAttributedString alloc] initWithRTF: rtfData
documentAttributes: NULL];
AUTORELEASE (attr);
[self replaceRange: aRange withAttributedString: attr];
[self replaceCharactersInRange: aRange withAttributedString: attr];
}
- (void) replaceCharactersInRange: (NSRange)aRange
@ -129,33 +94,47 @@ static Class concrete;
attr = [[NSAttributedString alloc] initWithRTFD: rtfdData
documentAttributes: NULL];
AUTORELEASE (attr);
[self replaceRange: aRange withAttributedString: attr];
[self replaceCharactersInRange: aRange withAttributedString: attr];
}
/* PRIMITIVE */
- (void) replaceCharactersInRange: (NSRange)aRange
withString: (NSString*)aString
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) replaceCharactersInRange: (NSRange)aRange
withAttributedString: (NSAttributedString*)attrString
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (NSData*) RTFDFromRange: (NSRange)aRange
{
[self subclassResponsibility: _cmd];
return nil;
}
/* PRIMITIVE */
- (NSData*) RTFFromRange: (NSRange)aRange
{
[self subclassResponsibility: _cmd];
return nil;
}
/* TODO: is this correct? seems that this would use the attributes of the
old text. */
- (void) setString: (NSString*)aString
{
[self replaceCharactersInRange: NSMakeRange (0, [self textLength])
withString: aString];
}
/* PRIMITIVE */
- (NSString*) string
{
[self subclassResponsibility: _cmd];
@ -198,158 +177,128 @@ static Class concrete;
/*
* Graphic attributes
*/
/* PRIMITIVE */
- (NSColor*) backgroundColor
{
return _background_color;
[self subclassResponsibility: _cmd];
return nil;
}
/* PRIMITIVE */
- (BOOL) drawsBackground
{
return _tf.draws_background;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (void) setBackgroundColor: (NSColor*)color
{
if (![_background_color isEqual: color])
{
ASSIGN (_background_color, color);
[self setNeedsDisplay: YES];
if (!_tf.is_field_editor)
{
/* If we are embedded in a scrollview, we might not be
filling all the scrollview's area (a textview might
resize itself dynamically in response to user input). If
this is the case, the scrollview is drawing the rest of
the background - change that too. */
NSScrollView *sv = [self enclosingScrollView];
if (sv != nil)
{
[sv setBackgroundColor: color];
}
}
}
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setDrawsBackground: (BOOL)flag
{
if (_tf.draws_background != flag)
{
_tf.draws_background = flag;
[self setNeedsDisplay: YES];
if (!_tf.is_field_editor)
{
/* See comment in setBackgroundColor:. */
NSScrollView *sv = [self enclosingScrollView];
if (sv != nil)
{
[sv setDrawsBackground: flag];
}
}
}
[self subclassResponsibility: _cmd];
}
/*
* Managing Global Characteristics
*/
/* PRIMITIVE */
- (BOOL) importsGraphics
{
return _tf.imports_graphics;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (BOOL) isEditable
{
return _tf.is_editable;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (BOOL) isFieldEditor
{
return _tf.is_field_editor;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (BOOL) isRichText
{
return _tf.is_rich_text;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (BOOL) isSelectable
{
return _tf.is_selectable;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (void) setEditable: (BOOL)flag
{
_tf.is_editable = flag;
if (flag)
{
_tf.is_selectable = YES;
}
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setFieldEditor: (BOOL)flag
{
_tf.is_field_editor = flag;
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setImportsGraphics: (BOOL)flag
{
_tf.imports_graphics = flag;
if (flag == YES)
{
_tf.is_rich_text = YES;
}
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setRichText: (BOOL)flag
{
_tf.is_rich_text = flag;
if (flag == NO)
{
_tf.imports_graphics = NO;
}
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void)setSelectable: (BOOL)flag
{
_tf.is_selectable = flag;
if (flag == NO)
{
_tf.is_editable = NO;
}
[self subclassResponsibility: _cmd];
}
/*
* Using the font panel
*/
/* PRIMITIVE */
- (BOOL) usesFontPanel
{
return _tf.uses_font_panel;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (void) setUsesFontPanel: (BOOL)flag
{
_tf.uses_font_panel = flag;
[self subclassResponsibility: _cmd];
}
/*
* Managing the Ruler
*/
/* PRIMITIVE */
- (BOOL) isRulerVisible
{
return _tf.is_ruler_visible;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (void) toggleRuler: (id)sender
{
[self subclassResponsibility: _cmd];
@ -358,12 +307,14 @@ static Class concrete;
/*
* Managing the Selection
*/
/* PRIMITIVE */
- (NSRange) selectedRange
{
[self subclassResponsibility: _cmd];
return NSMakeRange (NSNotFound, 0);
}
/* PRIMITIVE */
- (void) setSelectedRange: (NSRange)range
{
[self subclassResponsibility: _cmd];
@ -372,44 +323,52 @@ static Class concrete;
/*
* Copy and paste
*/
/* PRIMITIVE */
- (void) copy: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* Copy the current font to the font pasteboard */
/* PRIMITIVE */
- (void) copyFont: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* Copy the current ruler settings to the ruler pasteboard */
/* PRIMITIVE */
- (void) copyRuler: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) delete: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) cut: (id)sender
{
[self copy: sender];
[self delete: sender];
}
/* PRIMITIVE */
- (void) paste: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) pasteFont: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) pasteRuler: (id)sender
{
[self subclassResponsibility: _cmd];
@ -423,6 +382,7 @@ static Class concrete;
/*
* Managing Font
*/
/* PRIMITIVE */
- (NSFont*) font
{
[self subclassResponsibility: _cmd];
@ -434,16 +394,19 @@ static Class concrete;
* text object, or of all text for a plain text object. If the
* receiver doesn't use the Font Panel, however, this method does
* nothing. */
/* PRIMITIVE */
- (void) changeFont: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setFont: (NSFont*)font
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setFont: (NSFont*)font range: (NSRange)aRange
{
[self subclassResponsibility: _cmd];
@ -457,27 +420,32 @@ static Class concrete;
/*
* Managing Alingment
*/
/* PRIMITIVE */
- (NSTextAlignment) alignment
{
[self subclassResponsibility: _cmd];
return 0;
}
/* PRIMITIVE */
- (void) setAlignment: (NSTextAlignment)mode
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) alignCenter: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) alignLeft: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) alignRight: (id)sender
{
[self subclassResponsibility: _cmd];
@ -486,17 +454,20 @@ static Class concrete;
/*
* Text colour
*/
/* PRIMITIVE */
- (NSColor*) textColor
{
[self subclassResponsibility: _cmd];
return nil;
}
/* PRIMITIVE */
- (void) setTextColor: (NSColor*)color
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setTextColor: (NSColor*)color range: (NSRange)aRange
{
[self subclassResponsibility: _cmd];
@ -511,21 +482,25 @@ static Class concrete;
/*
* Text attributes
*/
/* PRIMITIVE */
- (void) subscript: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) superscript: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) unscript: (id)sender
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) underline: (id)sender
{
[self subclassResponsibility: _cmd];
@ -534,12 +509,14 @@ static Class concrete;
/*
* Reading and Writing RTFD Files
*/
/* PRIMITIVE */
- (BOOL) readRTFDFromFile: (NSString*)path
{
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (BOOL) writeRTFDToFile: (NSString*)path atomically: (BOOL)flag
{
[self subclassResponsibility: _cmd];
@ -549,46 +526,59 @@ static Class concrete;
/*
* Sizing the Frame Rectangle
*/
/* PRIMITIVE */
- (BOOL) isHorizontallyResizable
{
return _tf.is_horizontally_resizable;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (BOOL) isVerticallyResizable
{
return _tf.is_vertically_resizable;
[self subclassResponsibility: _cmd];
return NO;
}
/* PRIMITIVE */
- (NSSize) maxSize
{
return _maxSize;
[self subclassResponsibility: _cmd];
return NSMakeSize(0,0);
}
/* PRIMITIVE */
- (NSSize) minSize
{
return _minSize;
[self subclassResponsibility: _cmd];
return NSMakeSize(0,0);
}
/* PRIMITIVE */
- (void) setHorizontallyResizable: (BOOL)flag
{
_tf.is_horizontally_resizable = flag;
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setVerticallyResizable: (BOOL)flag
{
_tf.is_vertically_resizable = flag;
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setMaxSize: (NSSize)newMaxSize
{
_maxSize = newMaxSize;
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) setMinSize: (NSSize)newMinSize
{
_minSize = newMinSize;
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (void) sizeToFit
{
[self subclassResponsibility: _cmd];
@ -598,6 +588,7 @@ static Class concrete;
* Spelling
*/
/* PRIMITIVE */
- (void) checkSpelling: (id)sender
{
[self subclassResponsibility: _cmd];
@ -613,6 +604,7 @@ static Class concrete;
/*
* Scrolling
*/
/* PRIMITIVE */
- (void) scrollRangeToVisible: (NSRange)aRange
{
[self subclassResponsibility: _cmd];
@ -621,120 +613,24 @@ static Class concrete;
/*
* Managing the Delegate
*/
/* PRIMITIVE */
- (id) delegate
{
return _delegate;
[self subclassResponsibility: _cmd];
return nil;
}
/* PRIMITIVE */
- (void) setDelegate: (id)anObject
{
_delegate = anObject;
[self subclassResponsibility: _cmd];
}
/*
* NSView
*/
-(BOOL) needsPanelToBecomeKey
{
return _tf.is_editable;
}
/* text lays out from top to bottom */
- (BOOL) isFlipped
{
return YES;
}
- (BOOL) isOpaque
{
if (_tf.draws_background == NO
|| _background_color == nil
|| [_background_color alphaComponent] < 1.0)
return NO;
else
return YES;
}
//
// NSCoding protocol
//
- (void) encodeWithCoder: (NSCoder *)aCoder
{
BOOL flag;
[super encodeWithCoder: aCoder];
[aCoder encodeConditionalObject: _delegate];
flag = _tf.is_field_editor;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.is_editable;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.is_selectable;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.is_rich_text;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.imports_graphics;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.draws_background;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.is_horizontally_resizable;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.is_vertically_resizable;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.uses_font_panel;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.uses_ruler;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _tf.is_ruler_visible;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
[aCoder encodeObject: _background_color];
[aCoder encodeValueOfObjCType: @encode(NSSize) at: &_minSize];
[aCoder encodeValueOfObjCType: @encode(NSSize) at: &_maxSize];
}
- (id) initWithCoder: (NSCoder *)aDecoder
{
BOOL flag;
[super initWithCoder: aDecoder];
_delegate = [aDecoder decodeObject];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.is_field_editor = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.is_editable = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.is_selectable = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.is_rich_text = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.imports_graphics = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.draws_background = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.is_horizontally_resizable = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.is_vertically_resizable = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.uses_font_panel = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.uses_ruler = flag;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_tf.is_ruler_visible = flag;
_background_color = RETAIN([aDecoder decodeObject]);
[aDecoder decodeValueOfObjCType: @encode(NSSize) at: &_minSize];
[aDecoder decodeValueOfObjCType: @encode(NSSize) at: &_maxSize];
return self;
}
/*
* NSChangeSpelling protocol
*/
/* PRIMITIVE */
- (void) changeSpelling: (id)sender
{
[self subclassResponsibility: _cmd];
@ -743,6 +639,7 @@ static Class concrete;
/*
* NSIgnoreMisspelledWords protocol
*/
/* PRIMITIVE */
- (void) ignoreSpelling: (id)sender
{
[self subclassResponsibility: _cmd];
@ -752,12 +649,7 @@ static Class concrete;
@implementation NSText (GNUstepExtensions)
- (void) replaceRange: (NSRange)aRange
withAttributedString: (NSAttributedString*)attrString
{
[self subclassResponsibility: _cmd];
}
/* PRIMITIVE */
- (unsigned) textLength
{
[self subclassResponsibility: _cmd];

View file

@ -2,6 +2,9 @@
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Alexander Malmberg <alexander@malmberg.org>
Date: 2002-11-23
Author: Jonathan Gapen <jagapen@smithlab.chem.wisc.edu>
Date: 1999
@ -23,17 +26,22 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <AppKit/NSLayoutManager.h>
#import <AppKit/NSTextContainer.h>
#import <AppKit/NSTextStorage.h>
#import <AppKit/NSTextView.h>
#import <Foundation/NSGeometry.h>
#import <Foundation/NSNotification.h>
#include <Foundation/NSGeometry.h>
#include <Foundation/NSNotification.h>
#include <Foundation/NSDebug.h>
#include <AppKit/GSLayoutManager.h>
#include <AppKit/NSLayoutManager.h>
#include <AppKit/NSTextContainer.h>
#include <AppKit/NSTextStorage.h>
#include <AppKit/NSTextView.h>
@interface NSTextContainer (TextViewObserver)
- (void) _textViewFrameChanged: (NSNotification*)aNotification;
@end
/* TODO: rethink how this is is triggered.
use bounds rectangle instead of frame? */
@implementation NSTextContainer (TextViewObserver)
- (void) _textViewFrameChanged: (NSNotification*)aNotification
@ -110,14 +118,14 @@
[super dealloc];
}
- (void) setLayoutManager: (NSLayoutManager*)aLayoutManager
- (void) setLayoutManager: (GSLayoutManager*)aLayoutManager
{
/* The layout manager owns us - so he retains us and we don't retain
him. */
_layoutManager = aLayoutManager;
}
- (NSLayoutManager*) layoutManager
- (GSLayoutManager*) layoutManager
{
return _layoutManager;
}
@ -126,7 +134,7 @@
* Replaces the layout manager while maintaining the text object
* framework intact.
*/
- (void) replaceLayoutManager: (NSLayoutManager*)aLayoutManager
- (void) replaceLayoutManager: (GSLayoutManager*)aLayoutManager
{
if (aLayoutManager != _layoutManager)
{
@ -186,7 +194,9 @@
}
}
[_layoutManager textContainerChangedTextView: self];
/* If someone's trying to set a NSTextView for us, the layout manager we
have must be capable of handling NSTextView:s. */
[(NSLayoutManager *)_layoutManager textContainerChangedTextView: self];
}
- (NSTextView*) textView
@ -298,14 +308,104 @@
return _lineFragmentPadding;
}
- (NSRect) lineFragmentRectForProposedRect: (NSRect)proposedRect
sweepDirection: (NSLineSweepDirection)sweepDir
movementDirection: (NSLineMovementDirection)moveDir
remainingRect: (NSRect*)remainingRect
-(NSRect) lineFragmentRectForProposedRect: (NSRect)proposed
sweepDirection: (NSLineSweepDirection)sweep
movementDirection: (NSLineMovementDirection)move
remainingRect: (NSRect *)remain
{
// line fragment rectangle simply must fit within the container rectangle
*remainingRect = NSZeroRect;
return NSIntersectionRect (proposedRect, _containerRect);
float minx, maxx, miny, maxy;
float cminx, cmaxx, cminy, cmaxy;
minx = NSMinX(proposed);
maxx = NSMaxX(proposed);
miny = NSMinY(proposed);
maxy = NSMaxY(proposed);
cminx = NSMinX(_containerRect);
cmaxx = NSMaxX(_containerRect);
cminy = NSMinY(_containerRect);
cmaxy = NSMaxY(_containerRect);
*remain = NSZeroRect;
if (minx >= cminx && maxx <= cmaxx &&
miny >= cminy && maxy <= cmaxy)
{
return proposed;
}
switch (move)
{
case NSLineMoveLeft:
if (maxx < cminx)
return NSZeroRect;
if (maxx > cmaxx)
{
minx -= maxx-cmaxx;
maxx = cmaxx;
}
break;
case NSLineMoveRight:
if (minx > cmaxx)
return NSZeroRect;
if (minx < cminx)
{
maxx += cminx-minx;
minx = cminx;
}
break;
case NSLineMoveDown:
if (miny > cmaxy)
return NSZeroRect;
if (miny < cminy)
{
maxy += cminy - miny;
miny = cminy;
}
break;
case NSLineMoveUp:
if (maxy < cminy)
return NSZeroRect;
if (maxy > cmaxy)
{
miny -= maxy - cmaxy;
maxy = cmaxy;
}
break;
case NSLineDoesntMove:
break;
}
switch (sweep)
{
case NSLineSweepLeft:
case NSLineSweepRight:
if (minx < cminx)
minx = cminx;
if (maxx > cmaxx)
maxx = cmaxx;
break;
case NSLineSweepDown:
case NSLineSweepUp:
if (miny < cminy)
miny = cminy;
if (maxy > cmaxy)
maxy = cmaxy;
break;
}
if (minx < cminx || maxx > cmaxx ||
miny < cminy || maxy > cmaxy)
{
return NSZeroRect;
}
return NSMakeRect(minx, miny, maxx - minx, maxy - miny);
}
- (BOOL) isSimpleRectangularTextContainer

View file

@ -23,10 +23,12 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <Foundation/Foundation.h>
#include <Foundation/NSNotification.h>
#include <Foundation/NSException.h>
#include <Foundation/NSDebug.h>
#include <AppKit/NSAttributedString.h>
#include <AppKit/NSTextStorage.h>
#include <AppKit/NSLayoutManager.h>
#include <AppKit/GSLayoutManager.h>
@implementation NSTextStorage
@ -87,9 +89,9 @@ static NSNotificationCenter *nc = nil;
}
/*
* Managing NSLayoutManagers
* Managing GSLayoutManagers
*/
- (void) addLayoutManager: (NSLayoutManager*)obj
- (void) addLayoutManager: (GSLayoutManager*)obj
{
if ([_layoutManagers indexOfObjectIdenticalTo: obj] == NSNotFound)
{
@ -98,7 +100,7 @@ static NSNotificationCenter *nc = nil;
}
}
- (void) removeLayoutManager: (NSLayoutManager*)obj
- (void) removeLayoutManager: (GSLayoutManager*)obj
{
[obj setTextStorage: nil];
[_layoutManagers removeObjectIdenticalTo: obj];
@ -226,7 +228,7 @@ static NSNotificationCenter *nc = nil;
for (i = 0; i < [_layoutManagers count]; i++)
{
NSLayoutManager *lManager = [_layoutManagers objectAtIndex: i];
GSLayoutManager *lManager = [_layoutManagers objectAtIndex: i];
[lManager textStorage: self edited: _editedMask range: r
changeInLength: _editedDelta invalidatedRange: _editedRange];

File diff suppressed because it is too large Load diff

1257
Source/NSTextView_actions.m Normal file

File diff suppressed because it is too large Load diff