mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
Fixed style in CPTextView
This commit is contained in:
1 parent
714ed89a4c
commit
776f68c9dd
13 files changed
+919
-1096
No files matched your search
+1
-1
@@ -472,7 +472,7 @@ var cachedBlackColor,
|
||||
return [CPColor colorWithHexString:"99CCFF"];
|
||||
}
|
||||
|
||||
+ (CPColor)selectedTextBackgroundColorUnfocussed
|
||||
+ (CPColor)_selectedTextBackgroundColorUnfocussed
|
||||
{
|
||||
return [CPColor colorWithHexString:"CCCCCC"];
|
||||
}
|
||||
|
||||
+1
-3
@@ -465,9 +465,7 @@ following:
|
||||
if ([self isItalic])
|
||||
traits |= CPFontItalicTrait;
|
||||
|
||||
var descriptor = [[CPFontDescriptor fontDescriptorWithName:_name size:_size] fontDescriptorWithSymbolicTraits:traits];
|
||||
|
||||
return descriptor;
|
||||
return [[CPFontDescriptor fontDescriptorWithName:_name size:_size] fontDescriptorWithSymbolicTraits:traits];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -44,8 +44,8 @@ CPUnitalicFontMask = 1 << 24;
|
||||
|
||||
|
||||
var CPSharedFontManager = nil,
|
||||
CPFontManagerFactory = Nil,
|
||||
CPFontPanelFactory = Nil;
|
||||
CPFontManagerFactory = nil,
|
||||
CPFontPanelFactory = nil;
|
||||
|
||||
/*
|
||||
modifyFont: sender's tag
|
||||
|
||||
@@ -44,14 +44,14 @@ CPFontTraitsAttribute = @"CPFontTraitsAttribute";
|
||||
// Font traits dictionary keys
|
||||
/*
|
||||
CPFontSymbolicTrait a CPNumber that contains CPFontFamilyClass and
|
||||
typeface information flags.
|
||||
typeface information flags.
|
||||
*/
|
||||
CPFontSymbolicTrait = @"CPFontSymbolicTrait";
|
||||
|
||||
/*
|
||||
CPFontWeightTrait
|
||||
We use CPString with CSS string values for font weight
|
||||
(normal | bold | bolder | lighter | 100 | 200 | 300 | 400
|
||||
(normal | bold | bolder | lighter | 100 | 200 | 300 | 400
|
||||
| 500 | 600 | 700 | 800 | 900)
|
||||
NOTE: Cocoa compatibility issue: NSFontWeightTrait are NSNumber for
|
||||
font weight (from -1.0 to 1.0, 0.0 for normal weight).
|
||||
@@ -61,14 +61,14 @@ CPFontWeightTrait = @"CPFontWeightTrait";
|
||||
/*
|
||||
CPFontFamilyClass
|
||||
*/
|
||||
CPFontUnknownClass = (0 << 28);
|
||||
CPFontOldStyleSerifsClass = (1 << 28);
|
||||
CPFontTransitionalSerifsClass = (2 << 28);
|
||||
CPFontModernSerifsClass = (3 << 28);
|
||||
CPFontClarendonSerifsClass = (4 << 28);
|
||||
CPFontSlabSerifsClass = (5 << 28);
|
||||
CPFontFreeformSerifsClass = (7 << 28);
|
||||
CPFontSansSerifClass = (8 << 28);
|
||||
CPFontUnknownClass = 0 << 28;
|
||||
CPFontOldStyleSerifsClass = 1 << 28;
|
||||
CPFontTransitionalSerifsClass = 2 << 28;
|
||||
CPFontModernSerifsClass = 3 << 28;
|
||||
CPFontClarendonSerifsClass = 4 << 28;
|
||||
CPFontSlabSerifsClass = 5 << 28;
|
||||
CPFontFreeformSerifsClass = 7 << 28;
|
||||
CPFontSansSerifClass = 8 << 28;
|
||||
|
||||
CPFontSerifClass = (CPFontOldStyleSerifsClass | CPFontTransitionalSerifsClass |
|
||||
CPFontModernSerifsClass | CPFontClarendonSerifsClass |
|
||||
@@ -79,12 +79,11 @@ CPFontFamilyClassMask = 0xF0000000;
|
||||
/*
|
||||
Typeface information
|
||||
*/
|
||||
CPFontItalicTrait = (1 << 0);
|
||||
CPFontBoldTrait = (1 << 1);
|
||||
CPFontExpandedTrait = (1 << 5); /* TODO: CCS 3 font-stretch */
|
||||
CPFontCondensedTrait = (1 << 6);
|
||||
|
||||
CPFontSmallCapsTrait = (1 << 7);
|
||||
CPFontItalicTrait = 1 << 0;
|
||||
CPFontBoldTrait = 1 << 1;
|
||||
CPFontExpandedTrait = 1 << 5; /* TODO: CCS 3 font-stretch */
|
||||
CPFontCondensedTrait = 1 << 6;
|
||||
CPFontSmallCapsTrait = 1 << 7;
|
||||
|
||||
/*!
|
||||
@ingroup appkit
|
||||
@@ -126,9 +125,7 @@ CPFontSmallCapsTrait = (1 << 7);
|
||||
*/
|
||||
- (id)initWithFontAttributes:(CPDictionary)attributes
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
if (self = [super init])
|
||||
{
|
||||
_attributes = [[CPMutableDictionary alloc] init];
|
||||
|
||||
@@ -149,6 +146,7 @@ CPFontSmallCapsTrait = (1 << 7);
|
||||
- (CPFontDescriptor)fontDescriptorByAddingAttributes:(CPDictionary)attributes
|
||||
{
|
||||
var attrib = [_attributes copy];
|
||||
|
||||
[attrib addEntriesFromDictionary:attributes];
|
||||
|
||||
return [[CPFontDescriptor alloc] initWithFontAttributes:attrib];
|
||||
@@ -163,6 +161,7 @@ CPFontSmallCapsTrait = (1 << 7);
|
||||
- (CPFontDescriptor)fontDescriptorWithSize:(float)aSize
|
||||
{
|
||||
var attrib = [_attributes copy];
|
||||
|
||||
[attrib setObject:[CPString stringWithString:aSize + ''] forKey:CPFontSizeAttribute];
|
||||
|
||||
return [[CPFontDescriptor alloc] initWithFontAttributes:attrib];
|
||||
@@ -203,20 +202,14 @@ CPFontSmallCapsTrait = (1 << 7);
|
||||
{
|
||||
var value = [_attributes objectForKey:CPFontSizeAttribute];
|
||||
|
||||
if (value)
|
||||
return [value floatValue];
|
||||
|
||||
return 0.0;
|
||||
return value ? [value floatValue] : 0.0;
|
||||
}
|
||||
|
||||
- (CPFontSymbolicTraits)symbolicTraits
|
||||
{
|
||||
var traits = [_attributes objectForKey:CPFontTraitsAttribute];
|
||||
|
||||
if (traits && [traits objectForKey:CPFontSymbolicTrait])
|
||||
return [[traits objectForKey:CPFontSymbolicTrait] unsignedIntValue];
|
||||
|
||||
return 0;
|
||||
return (traits && [traits objectForKey:CPFontSymbolicTrait]) ? [[traits objectForKey:CPFontSymbolicTrait] unsignedIntValue] : 0;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -257,10 +250,7 @@ var _wrapNameRegEx = new RegExp(/(\w+\s+\w+)(,*)/g);
|
||||
|
||||
- (CPString)fontStyleCSSString
|
||||
{
|
||||
if ([self symbolicTraits] & CPFontItalicTrait)
|
||||
return @"italic";
|
||||
|
||||
return @"normal";
|
||||
return [self symbolicTraits] & CPFontItalicTrait ? @"italic" : @"normal";
|
||||
}
|
||||
|
||||
- (CPString)fontWeightCSSString
|
||||
@@ -282,10 +272,7 @@ var _wrapNameRegEx = new RegExp(/(\w+\s+\w+)(,*)/g);
|
||||
|
||||
- (CPString)fontSizeCSSString
|
||||
{
|
||||
if ([_attributes objectForKey:CPFontSizeAttribute])
|
||||
return [[_attributes objectForKey:CPFontSizeAttribute] intValue] + "px";
|
||||
|
||||
return @"";
|
||||
return [_attributes objectForKey:CPFontSizeAttribute] ? [[_attributes objectForKey:CPFontSizeAttribute] intValue] + "px" : @"";
|
||||
}
|
||||
|
||||
- (CPString)fontFamilyCSSString
|
||||
|
||||
@@ -50,12 +50,10 @@ var kTypefaceIndex_Normal = 0,
|
||||
kTypefaceIndex_Italic = 1,
|
||||
kTypefaceIndex_Bold = 2,
|
||||
kTypefaceIndex_BoldItalic = 3;
|
||||
|
||||
var kToolbarHeight = 32,
|
||||
kToolbarHeight = 32,
|
||||
kBorderSpacing = 6,
|
||||
kInnerSpacing = 2;
|
||||
|
||||
var kNothingChanged = 0,
|
||||
kNothingChanged = 0,
|
||||
kFontNameChanged = 1,
|
||||
kTypefaceChanged = 2,
|
||||
kSizeChanged = 3,
|
||||
@@ -63,9 +61,7 @@ var kNothingChanged = 0,
|
||||
kBackgroundColorChanged = 5,
|
||||
kUnderlineChanged = 6,
|
||||
kWeightChanged = 7;
|
||||
|
||||
var _sharedFontPanel = nil;
|
||||
|
||||
_sharedFontPanel;
|
||||
|
||||
// FIXME<!> Locale support
|
||||
var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
@@ -142,6 +138,10 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
_CPFontPanelSampleView _sampleView;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Class methods
|
||||
|
||||
/*!
|
||||
Check if the shared Font panel exists.
|
||||
*/
|
||||
@@ -161,29 +161,26 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
return _sharedFontPanel;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Init methods
|
||||
|
||||
/*! @ignore */
|
||||
- (id)init
|
||||
{
|
||||
self = [super initWithContentRect:CGRectMake(100, 90, 450, 394) styleMask:(CPTitledWindowMask | CPClosableWindowMask /*| CPResizableWindowMask*/ )];
|
||||
|
||||
if (self)
|
||||
if (self = [super initWithContentRect:CGRectMake(100, 90, 450, 394) styleMask:(CPTitledWindowMask | CPClosableWindowMask /*| CPResizableWindowMask*/ )])
|
||||
{
|
||||
[[self contentView] setBackgroundColor:[CPColor colorWithWhite:0.95 alpha:1.0]];
|
||||
|
||||
[self setTitle:@"Font Panel"];
|
||||
[self setLevel:CPFloatingWindowLevel];
|
||||
|
||||
[self setFloatingPanel:YES];
|
||||
[self setBecomesKeyOnlyIfNeeded:YES];
|
||||
|
||||
[self setMinSize:CGSizeMake(378, 394)];
|
||||
|
||||
_availableFonts = [[CPFontManager sharedFontManager] availableFonts];
|
||||
|
||||
_textColor = [CPColor blackColor];
|
||||
|
||||
_setupDone = NO;
|
||||
_fontChanges = kNothingChanged;
|
||||
_textColor = [CPColor blackColor];
|
||||
_setupDone = NO;
|
||||
_fontChanges = kNothingChanged;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -192,14 +189,15 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
/*! @ignore */
|
||||
- (void)_setupToolbarView
|
||||
{
|
||||
var colorPanel = [CPColorPanel sharedColorPanel];
|
||||
|
||||
_toolbarView = [[CPView alloc] initWithFrame:CGRectMake(0, kBorderSpacing, CGRectGetWidth([self frame]), kToolbarHeight)];
|
||||
[_toolbarView setAutoresizingMask:CPViewWidthSizable];
|
||||
|
||||
/* text color */
|
||||
// Text color
|
||||
_textColorWell = [[CPColorWell alloc] initWithFrame:CGRectMake(10, 0, 25, 25)];
|
||||
[_textColorWell setColor:_textColor]; // <!> FIXME: use bindings
|
||||
[_toolbarView addSubview:_textColorWell];
|
||||
var colorPanel = [CPColorPanel sharedColorPanel];
|
||||
[colorPanel setTarget:self];
|
||||
[colorPanel setAction:@selector(changeColor:)];
|
||||
}
|
||||
@@ -237,9 +235,9 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
[self _setupBrowser:_traitBrowser];
|
||||
[self _setupBrowser:_sizeBrowser];
|
||||
[[CPNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(textViewDidChangeSelection:)
|
||||
name:CPTextViewDidChangeSelectionNotification
|
||||
object:nil];
|
||||
selector:@selector(textViewDidChangeSelection:)
|
||||
name:CPTextViewDidChangeSelectionNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)textViewDidChangeSelection:(CPNotification)notification
|
||||
@@ -250,27 +248,27 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
|
||||
- (void)_refreshWithTextView:(CPTextView)textView
|
||||
{
|
||||
if ([self isVisible])
|
||||
{
|
||||
var attribs = [textView typingAttributes],
|
||||
font = [attribs objectForKey:CPFontAttributeName] || [[textView textStorage] font] || [CPFont systemFontOfSize:12.0];
|
||||
if (![self isVisible])
|
||||
return;
|
||||
|
||||
if (font)
|
||||
{
|
||||
var trait = kTypefaceIndex_Normal;
|
||||
var attribs = [textView typingAttributes],
|
||||
font = [attribs objectForKey:CPFontAttributeName] || [[textView textStorage] font] || [CPFont systemFontOfSize:12.0];
|
||||
|
||||
if ([font isItalic] && [font isBold])
|
||||
trait = kTypefaceIndex_BoldItalic;
|
||||
else if ([font isItalic])
|
||||
trait = kTypefaceIndex_Italic;
|
||||
else if ([font isBold])
|
||||
trait = kTypefaceIndex_Bold;
|
||||
if (!font)
|
||||
return;
|
||||
|
||||
[self setCurrentFont:font];
|
||||
[self setCurrentTrait:trait];
|
||||
[self setCurrentSize:[font size] + ""]; //cast to string
|
||||
}
|
||||
}
|
||||
var trait = kTypefaceIndex_Normal;
|
||||
|
||||
if ([font isItalic] && [font isBold])
|
||||
trait = kTypefaceIndex_BoldItalic;
|
||||
else if ([font isItalic])
|
||||
trait = kTypefaceIndex_Italic;
|
||||
else if ([font isBold])
|
||||
trait = kTypefaceIndex_Bold;
|
||||
|
||||
[self setCurrentFont:font];
|
||||
[self setCurrentTrait:trait];
|
||||
[self setCurrentSize:[font size] + ""]; //cast to string
|
||||
}
|
||||
|
||||
- (void)orderFront:(id)sender
|
||||
@@ -292,7 +290,7 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
|
||||
/*!
|
||||
@param aFont the font to convert.
|
||||
@return The converted font or \c aFont if failed to convert.
|
||||
@return The converted font or \c aFont if failed to convert.
|
||||
*/
|
||||
- (CPFont)panelConvertFont:(CPFont)aFont
|
||||
{
|
||||
@@ -395,7 +393,7 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
/*!
|
||||
Set the selected font in Font panel.
|
||||
@param font the selected font
|
||||
@param flag if \c the current selection have multiple fonts.
|
||||
@param flag if \c the current selection have multiple fonts.
|
||||
*/
|
||||
- (void)setPanelFont:(CPFont)font isMultiple:(BOOL)flag
|
||||
{
|
||||
@@ -420,10 +418,9 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
if ([self currentTrait] != typefaceIndex)
|
||||
[self setCurrentTrait:typefaceIndex ];
|
||||
|
||||
[_sampleView setAttributedString:
|
||||
[[CPAttributedString alloc] initWithString:[font familyName]
|
||||
attributes:[CPDictionary dictionaryWithObjects:[font, [CPColor blackColor]] forKeys:[CPFontAttributeName, CPForegroundColorAttributeName]]]
|
||||
];
|
||||
[_sampleView setAttributedString: [[CPAttributedString alloc] initWithString:[font familyName]
|
||||
attributes:[CPDictionary dictionaryWithObjects:[font, [CPColor blackColor]]
|
||||
forKeys:[CPFontAttributeName, CPForegroundColorAttributeName]]]];
|
||||
|
||||
_fontChanges = kNothingChanged;
|
||||
}
|
||||
@@ -468,8 +465,8 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
|
||||
if (aBrowser === _traitBrowser)
|
||||
return [_availableTraits count]
|
||||
else
|
||||
return [_availableSizes count]
|
||||
|
||||
return [_availableSizes count]
|
||||
}
|
||||
|
||||
- (id)browser:(id)aBrowser child:(int)index ofItem:(id)anItem
|
||||
@@ -494,4 +491,5 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
}
|
||||
|
||||
@end
|
||||
[CPFontManager setFontPanelFactory:CPFontPanel];
|
||||
|
||||
[CPFontManager setFontPanelFactory:CPFontPanel];
|
||||
+114
-116
@@ -42,15 +42,7 @@ function _RectEqualToRectHorizontally(lhsRect, rhsRect)
|
||||
|
||||
_oncontextmenuhandler = function () { return false; };
|
||||
|
||||
|
||||
@implementation CPArray(SortedSearching)
|
||||
|
||||
- (unsigned)indexOfObject:(id)anObject sortedByFunction:(Function)aFunction context:(id)aContext
|
||||
{
|
||||
var result = [self _indexOfObject:anObject sortedByFunction:aFunction context:aContext];
|
||||
|
||||
return (result >= 0) ? result : CPNotFound;
|
||||
}
|
||||
@implementation CPArray (SortedSearching)
|
||||
|
||||
- (unsigned)_indexOfObject:(id)anObject sortedByFunction:(Function)aFunction context:(id)aContext
|
||||
{
|
||||
@@ -70,12 +62,16 @@ _oncontextmenuhandler = function () { return false; };
|
||||
while (first <= last)
|
||||
{
|
||||
mid = FLOOR((first + last) / 2);
|
||||
c = aFunction(anObject, self[mid], aContext);
|
||||
c = aFunction(anObject, self[mid], aContext);
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
first = mid + 1;
|
||||
}
|
||||
else if (c < 0)
|
||||
{
|
||||
last = mid - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (mid < length - 1 && aFunction(anObject, self[mid + 1], aContext) == CPOrderedSame)
|
||||
@@ -85,7 +81,7 @@ _oncontextmenuhandler = function () { return false; };
|
||||
}
|
||||
}
|
||||
|
||||
return -first - 1;
|
||||
return ((-first - 1) >= 0) ? result : CPNotFound;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -102,7 +98,7 @@ var _sortRange = function(location, anObject)
|
||||
|
||||
var _objectWithLocationInRange = function(aList, aLocation)
|
||||
{
|
||||
var index = [aList indexOfObject: aLocation sortedByFunction:_sortRange context:nil];
|
||||
var index = [aList _indexOfObject: aLocation sortedByFunction:_sortRange context:nil];
|
||||
|
||||
if (index != CPNotFound)
|
||||
return aList[index];
|
||||
@@ -121,6 +117,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
if (CPLocationInRange(location, aList[i]._range))
|
||||
{
|
||||
list.push(aList[i]);
|
||||
|
||||
if (CPMaxRange(aList[i]._range) <= CPMaxRange(aRange))
|
||||
location = CPMaxRange(aList[i]._range);
|
||||
else
|
||||
@@ -142,18 +139,20 @@ var _objectsInRange = function(aList, aRange)
|
||||
|
||||
@implementation _CPLineFragment : CPObject
|
||||
{
|
||||
CGRect _fragmentRect;
|
||||
CGRect _usedRect;
|
||||
CGPoint _location;
|
||||
CPRange _range;
|
||||
CPTextContainer _textContainer;
|
||||
BOOL _isInvalid;
|
||||
CPMutableArray _runs;
|
||||
CPArray _glyphsFrames @accessors(getter=glyphsFrames);
|
||||
|
||||
/* 'Glyphs' frames */
|
||||
CPArray _glyphsFrames;
|
||||
BOOL _isInvalid;
|
||||
CGRect _fragmentRect;
|
||||
CGRect _usedRect;
|
||||
CGPoint _location;
|
||||
CPRange _range;
|
||||
CPTextContainer _textContainer;
|
||||
CPMutableArray _runs;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Init methods
|
||||
|
||||
- (id)createDOMElementWithText:(CPString)aString andFont:(CPFont)aFont andColor:(CPColor)aColor
|
||||
{
|
||||
#if PLATFORM(DOM)
|
||||
@@ -179,7 +178,8 @@ var _objectsInRange = function(aList, aRange)
|
||||
span.innerText = aString;
|
||||
else if (CPFeatureIsCompatible(CPJavaScriptTextContentFeature))
|
||||
span.textContent = aString;
|
||||
//<!> FIXME aString.replace(/&/g,'&')
|
||||
|
||||
//<!> FIXME aString.replace(/&/g,'&')
|
||||
return span;
|
||||
#else
|
||||
return nil;
|
||||
@@ -188,24 +188,23 @@ var _objectsInRange = function(aList, aRange)
|
||||
|
||||
- (id)initWithRange:(CPRange)aRange textContainer:(CPTextContainer)aContainer textStorage:(CPTextStorage)textStorage
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
if (self = [super init])
|
||||
{
|
||||
var effectiveRange = CPMakeRange(0,0),
|
||||
location;
|
||||
|
||||
_fragmentRect = CGRectMakeZero();
|
||||
_usedRect = CGRectMakeZero();
|
||||
_location = CGPointMakeZero();
|
||||
_range = CPMakeRangeCopy(aRange);
|
||||
_textContainer = aContainer;
|
||||
_isInvalid = NO;
|
||||
|
||||
_runs = [[CPMutableArray alloc] init];
|
||||
var effectiveRange = CPMakeRange(0,0),
|
||||
location;
|
||||
|
||||
for (location = aRange.location; location < CPMaxRange(aRange); location = CPMaxRange(effectiveRange))
|
||||
{
|
||||
var attributes = [textStorage attributesAtIndex:location effectiveRange:effectiveRange];
|
||||
|
||||
effectiveRange = attributes ? CPIntersectionRange(aRange, effectiveRange) : aRange;
|
||||
|
||||
var string = [textStorage._string substringWithRange:effectiveRange],
|
||||
@@ -248,11 +247,6 @@ var _objectsInRange = function(aList, aRange)
|
||||
"\n\t_range="+CPStringFromRange(_range);
|
||||
}
|
||||
|
||||
- (CPArray)glyphFrames
|
||||
{
|
||||
return _glyphsFrames;
|
||||
}
|
||||
|
||||
- (void)drawUnderlineForGlyphRange:(CPRange)glyphRange
|
||||
underlineType:(int)underlineVal
|
||||
baselineOffset:(float)baselineOffset
|
||||
@@ -273,8 +267,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
|
||||
- (void)_removeFromDOM
|
||||
{
|
||||
var i,
|
||||
l = _runs.length;
|
||||
var l = _runs.length;
|
||||
|
||||
for (var i = 0; i < l; i++)
|
||||
{
|
||||
@@ -299,9 +292,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
var run = runs[i];
|
||||
|
||||
if (run.DOMactive && !run.DOMpatched || !run.elem)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
orig.x = _glyphsFrames[run._range.location - _runs[0]._range.location].origin.x + aPoint.x;
|
||||
|
||||
@@ -343,9 +334,9 @@ var _objectsInRange = function(aList, aRange)
|
||||
|
||||
for (var i = 0; i < l; i++)
|
||||
{
|
||||
// FIXME <!> newFragmentRuns[i].elem.style.left !== oldFragmentRuns[i].elem.style.left && compare CSS-strings
|
||||
if (newFragmentRuns[i].string !== oldFragmentRuns[i].string ||
|
||||
!_RectEqualToRectHorizontally(newLineFragment._fragmentRect, _fragmentRect))
|
||||
// FIXME <!> newFragmentRuns[i].elem.style.left !== oldFragmentRuns[i].elem.style.left && compare CSS-strings
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
@@ -354,11 +345,12 @@ var _objectsInRange = function(aList, aRange)
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)_relocateVerticallyByY:(double) verticalOffset rangeOffset:(unsigned) rangeOffset
|
||||
- (void)_relocateVerticallyByY:(double)verticalOffset rangeOffset:(unsigned)rangeOffset
|
||||
{
|
||||
_range.location += rangeOffset;
|
||||
var l = _runs.length;
|
||||
|
||||
_range.location += rangeOffset;
|
||||
|
||||
for (var i = 0; i < l; i++)
|
||||
{
|
||||
_runs[i]._range.location += rangeOffset;
|
||||
@@ -394,9 +386,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
|
||||
- (id)initWithRange:(CPRange)aRange attributes:(CPDictionary)attributes
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
if (self = [super init])
|
||||
{
|
||||
_attributes = attributes;
|
||||
_range = CPMakeRangeCopy(aRange);
|
||||
@@ -420,50 +410,44 @@ var _objectsInRange = function(aList, aRange)
|
||||
*/
|
||||
@implementation CPLayoutManager : CPObject
|
||||
{
|
||||
CPTextStorage _textStorage;
|
||||
Class _lineFragmentFactory @accessors(setter:setLineFragmentFactory:);
|
||||
CPMutableArray _textContainers @accessors(getter=textContainers);
|
||||
CPTextStorage _textStorage @accessors(property=textStorage);
|
||||
CPTypesetter _typesetter @accessors(property=typesetter);
|
||||
|
||||
id _delegate;
|
||||
CPMutableArray _textContainers;
|
||||
CPTypesetter _typesetter;
|
||||
|
||||
CPMutableArray _lineFragments;
|
||||
CPMutableArray _lineFragmentsForRescue;
|
||||
id _extraLineFragment;
|
||||
Class _lineFragmentFactory;
|
||||
|
||||
CPMutableArray _temporaryAttributes;
|
||||
|
||||
BOOL _isValidatingLayoutAndGlyphs;
|
||||
var _removeInvalidLineFragmentsRange;
|
||||
CPRange _removeInvalidLineFragmentsRange;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Init methods
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
if (self = [super init])
|
||||
{
|
||||
_textContainers = [[CPMutableArray alloc] init];
|
||||
_lineFragments = [[CPMutableArray alloc] init];
|
||||
_typesetter = [CPTypesetter sharedSystemTypesetter];
|
||||
_isValidatingLayoutAndGlyphs = NO;
|
||||
_lineFragmentFactory = [_CPLineFragment class];
|
||||
_textContainers = [[CPMutableArray alloc] init];
|
||||
_lineFragments = [[CPMutableArray alloc] init];
|
||||
_typesetter = [CPTypesetter sharedSystemTypesetter];
|
||||
_isValidatingLayoutAndGlyphs = NO;
|
||||
_lineFragmentFactory = [_CPLineFragment class];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setTextStorage:(CPTextStorage)textStorage
|
||||
{
|
||||
if (_textStorage === textStorage)
|
||||
return;
|
||||
|
||||
_textStorage = textStorage;
|
||||
}
|
||||
|
||||
- (CPTextStorage)textStorage
|
||||
{
|
||||
return _textStorage;
|
||||
}
|
||||
#pragma mark -
|
||||
#pragma mark Text containes method
|
||||
|
||||
- (void)insertTextContainer:(CPTextContainer)aContainer atIndex:(int)index
|
||||
{
|
||||
@@ -484,11 +468,6 @@ var _objectsInRange = function(aList, aRange)
|
||||
[_textContainers removeObjectAtIndex:index];
|
||||
}
|
||||
|
||||
- (CPArray)textContainers
|
||||
{
|
||||
return _textContainers;
|
||||
}
|
||||
|
||||
// <!> fixme
|
||||
- (int)numberOfGlyphs
|
||||
{
|
||||
@@ -539,6 +518,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
for (var i = 0; i < c; i++)
|
||||
{
|
||||
var fragment = fragments[i];
|
||||
|
||||
if (fragment._textContainer === container)
|
||||
{
|
||||
var frames = [fragment glyphFrames],
|
||||
@@ -556,25 +536,29 @@ var _objectsInRange = function(aList, aRange)
|
||||
}
|
||||
}
|
||||
}
|
||||
return (rect) ? rect : CGRectMakeZero();
|
||||
|
||||
return rect ? rect : CGRectMakeZero();
|
||||
}
|
||||
|
||||
- (CPRange)glyphRangeForTextContainer:(CPTextContainer)aTextContainer
|
||||
{
|
||||
var range = nil,
|
||||
c = [_lineFragments count];
|
||||
|
||||
for (var i = 0; i < c; i++)
|
||||
{
|
||||
var fragment = _lineFragments[i];
|
||||
|
||||
if (fragment._textContainer === aTextContainer)
|
||||
{
|
||||
if (!range)
|
||||
if (!range)
|
||||
range = CPMakeRangeCopy(fragment._range);
|
||||
else
|
||||
range = CPUnionRange(range, fragment._range);
|
||||
}
|
||||
}
|
||||
return (range)?range:CPMakeRange(CPNotFound, 0);
|
||||
|
||||
return range ? range : CPMakeRange(CPNotFound, 0);
|
||||
}
|
||||
|
||||
- (void)_removeInvalidLineFragments
|
||||
@@ -610,9 +594,9 @@ var _objectsInRange = function(aList, aRange)
|
||||
_isValidatingLayoutAndGlyphs = YES;
|
||||
|
||||
var startIndex = CPNotFound,
|
||||
removeRange = CPMakeRange(0,0);
|
||||
removeRange = CPMakeRange(0, 0),
|
||||
l = _lineFragments.length;
|
||||
|
||||
var l = _lineFragments.length;
|
||||
if (l)
|
||||
{
|
||||
for (var i = 0; i < l; i++)
|
||||
@@ -626,11 +610,14 @@ var _objectsInRange = function(aList, aRange)
|
||||
}
|
||||
}
|
||||
|
||||
// start one line above current line to make sure that a word can jump up
|
||||
if (startIndex == CPNotFound && CPMaxRange (_lineFragments[l - 1]._range) < [_textStorage length])
|
||||
startIndex = CPMaxRange(_lineFragments[l - 1]._range); // start one line above current line to make sure that a word can jump up
|
||||
startIndex = CPMaxRange(_lineFragments[l - 1]._range);
|
||||
}
|
||||
else
|
||||
{
|
||||
startIndex = 0;
|
||||
}
|
||||
|
||||
/* nothing to validate and layout */
|
||||
if (startIndex == CPNotFound)
|
||||
@@ -642,10 +629,11 @@ var _objectsInRange = function(aList, aRange)
|
||||
if (removeRange.length)
|
||||
_removeInvalidLineFragmentsRange = CPMakeRangeCopy(removeRange);
|
||||
|
||||
if (!startIndex) // We erased all lines
|
||||
[self setExtraLineFragmentRect:CGRectMake(0,0) usedRect:CGRectMake(0,0) textContainer:nil];
|
||||
// We erased all lines
|
||||
if (!startIndex)
|
||||
[self setExtraLineFragmentRect:CGRectMake(0, 0) usedRect:CGRectMake(0, 0) textContainer:nil];
|
||||
|
||||
// document.title=startIndex;
|
||||
// document.title=startIndex;
|
||||
[_typesetter layoutGlyphsInLayoutManager:self startingAtGlyphIndex:startIndex maxNumberOfLineFragments:-1 nextGlyphIndex:nil];
|
||||
[self _cleanUpDOM];
|
||||
_isValidatingLayoutAndGlyphs = NO;
|
||||
@@ -661,7 +649,8 @@ var _objectsInRange = function(aList, aRange)
|
||||
for (var i = 0; i < l; i++)
|
||||
{
|
||||
if (CPLocationInRange(location, _lineFragments[i]._range))
|
||||
{ found = YES;
|
||||
{
|
||||
found = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -685,20 +674,25 @@ var _objectsInRange = function(aList, aRange)
|
||||
if (![oldLineFragment isVisuallyIdenticalToFragment: newLineFragment])
|
||||
{
|
||||
isIdentical = NO;
|
||||
if (newLength < oldLength && oldLineFragment._range.length == 1 && newLineFragment._range.length > 1 && newLineFragment._range.location === oldLineFragment._range.location) // deleting newline in its own line-> move up instead of re.layouting
|
||||
|
||||
// deleting newline in its own line-> move up instead of re.layouting
|
||||
if (newLength < oldLength && oldLineFragment._range.length == 1 && newLineFragment._range.length > 1 && newLineFragment._range.location === oldLineFragment._range.location)
|
||||
{
|
||||
isIdentical = YES;
|
||||
i--;
|
||||
startLineForDOMRemoval--;
|
||||
}
|
||||
if (newLength > oldLength && newLineFragment._range.length == 1 && oldLineFragment._range.length > 1 && newLineFragment._range.location === oldLineFragment._range.location) // newline entered in its own line-> move down instead of re.layouting
|
||||
|
||||
// newline entered in its own line-> move down instead of re.layouting
|
||||
if (newLength > oldLength && newLineFragment._range.length == 1 && oldLineFragment._range.length > 1 && newLineFragment._range.location === oldLineFragment._range.location)
|
||||
{
|
||||
isIdentical = YES;
|
||||
startLineForDOMRemoval--;
|
||||
}
|
||||
}
|
||||
|
||||
if (isIdentical) // patch the linefragments instead of re-layoutung
|
||||
// patch the linefragments instead of re-layoutung
|
||||
if (isIdentical)
|
||||
{
|
||||
var rangeOffset = CPMaxRange(_lineFragments[i]._range) - CPMaxRange(_lineFragmentsForRescue[startLineForDOMRemoval]._range);
|
||||
|
||||
@@ -724,17 +718,19 @@ var _objectsInRange = function(aList, aRange)
|
||||
var lineFragments = _objectsInRange(_lineFragments, range);
|
||||
|
||||
for (var i = 0; i < lineFragments.length; i++)
|
||||
[[lineFragments[i]._textContainer textView] setNeedsDisplayInRect: lineFragments[i]._fragmentRect];
|
||||
[[lineFragments[i]._textContainer textView] setNeedsDisplayInRect:lineFragments[i]._fragmentRect];
|
||||
}
|
||||
|
||||
- (void)invalidateLayoutForCharacterRange:(CPRange)aRange isSoft:(BOOL)flag actualCharacterRange:(CPRangePointer)actualCharRange
|
||||
{
|
||||
var firstFragmentIndex = _lineFragments.length? [_lineFragments indexOfObject: aRange.location sortedByFunction:_sortRange context:nil]:CPNotFound;
|
||||
var firstFragmentIndex = _lineFragments.length ? [_lineFragments _indexOfObject: aRange.location sortedByFunction:_sortRange context:nil] : CPNotFound;
|
||||
|
||||
if (firstFragmentIndex == CPNotFound)
|
||||
{
|
||||
if (_lineFragments.length)
|
||||
{
|
||||
firstFragmentIndex = _lineFragments.length - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (actualCharRange)
|
||||
@@ -747,7 +743,9 @@ var _objectsInRange = function(aList, aRange)
|
||||
}
|
||||
}
|
||||
else
|
||||
firstFragmentIndex = firstFragmentIndex + (firstFragmentIndex ? - 1 : 0);
|
||||
{
|
||||
firstFragmentIndex = firstFragmentIndex + (firstFragmentIndex ? -1 : 0);
|
||||
}
|
||||
|
||||
var fragment = _lineFragments[firstFragmentIndex],
|
||||
range = CPMakeRangeCopy(fragment._range);
|
||||
@@ -780,11 +778,10 @@ var _objectsInRange = function(aList, aRange)
|
||||
|
||||
- (CPRange)glyphRangeForBoundingRect:(CGRect)aRect inTextContainer:(CPTextContainer)container
|
||||
{
|
||||
var range = nil,
|
||||
i,
|
||||
c = [_lineFragments count];
|
||||
var c = [_lineFragments count];
|
||||
range;
|
||||
|
||||
for (i = 0; i < c; i++)
|
||||
for (var i = 0; i < c; i++)
|
||||
{
|
||||
var fragment = _lineFragments[i];
|
||||
|
||||
@@ -822,11 +819,13 @@ var _objectsInRange = function(aList, aRange)
|
||||
}
|
||||
}
|
||||
}
|
||||
return (range)?range:CPMakeRange(0,0);
|
||||
|
||||
return range ? range : CPMakeRange(0,0);
|
||||
}
|
||||
|
||||
- (void)drawBackgroundForGlyphRange:(CPRange)aRange atPoint:(CGPoint)aPoint
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void)drawUnderlineForGlyphRange:(CPRange)glyphRange
|
||||
@@ -846,10 +845,10 @@ var _objectsInRange = function(aList, aRange)
|
||||
if (!lineFragments.length)
|
||||
return;
|
||||
|
||||
var ctx = nil,
|
||||
paintedRange = CPMakeRangeCopy(aRange),
|
||||
var paintedRange = CPMakeRangeCopy(aRange),
|
||||
l = lineFragments.length,
|
||||
lineFragmentIndex,
|
||||
l= lineFragments.length;
|
||||
ctx;
|
||||
|
||||
for (lineFragmentIndex = 0; lineFragmentIndex < l; lineFragmentIndex++)
|
||||
{
|
||||
@@ -861,13 +860,16 @@ var _objectsInRange = function(aList, aRange)
|
||||
- (unsigned)glyphIndexForPoint:(CGPoint)point inTextContainer:(CPTextContainer)container fractionOfDistanceThroughGlyph:(FloatArray)partialFraction
|
||||
{
|
||||
var c = [_lineFragments count];
|
||||
|
||||
for (var i = 0; i < c; i++)
|
||||
{
|
||||
var fragment = _lineFragments[i];
|
||||
|
||||
if (fragment._textContainer === container)
|
||||
{
|
||||
var frames = [fragment glyphFrames],
|
||||
len = fragment._range.length;
|
||||
|
||||
for (var j = 0; j < len; j++)
|
||||
{
|
||||
if (CGRectContainsPoint(frames[j], point))
|
||||
@@ -880,6 +882,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not found, maybe a point left to the last character was clicked->search again with broader constraints
|
||||
if ([[_textStorage string] length])
|
||||
{
|
||||
@@ -896,10 +899,11 @@ var _objectsInRange = function(aList, aRange)
|
||||
lastFrame = [fragment glyphFrames][fragment._range.length - 1],
|
||||
firstFrame = [fragment glyphFrames][0];
|
||||
|
||||
// skip tabs and move on the last fragment in this line
|
||||
// skip tabs and move on the last fragment in this line
|
||||
if (i < c - 1 && _lineFragments[i + 1]._fragmentRect.origin.y === fragment._fragmentRect.origin.y)
|
||||
continue;
|
||||
// this allows clicking before and after the (invisible) return character
|
||||
|
||||
// this allows clicking before and after the (invisible) return character
|
||||
if (point.x > CGRectGetMaxX(lastFrame) && fragment.length > 0 &&
|
||||
[[_textStorage string] characterAtIndex: nlLoc] === '\n' || i === c - 1)
|
||||
return nlLoc + 1;
|
||||
@@ -911,6 +915,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CPNotFound;
|
||||
}
|
||||
|
||||
@@ -959,16 +964,6 @@ var _objectsInRange = function(aList, aRange)
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (CPTypesetter)typesetter
|
||||
{
|
||||
return _typesetter;
|
||||
}
|
||||
|
||||
- (void)setTypesetter:(CPTypesetter)aTypesetter
|
||||
{
|
||||
_typesetter = aTypesetter;
|
||||
}
|
||||
|
||||
- (void)setTextContainer:(CPTextContainer)aTextContainer forGlyphRange:(CPRange)glyphRange
|
||||
{
|
||||
var fragments = _objectsInRange(_lineFragments, glyphRange),
|
||||
@@ -980,12 +975,13 @@ var _objectsInRange = function(aList, aRange)
|
||||
}
|
||||
|
||||
var lineFragment = [[_lineFragmentFactory alloc] initWithRange:glyphRange textContainer:aTextContainer textStorage:_textStorage];
|
||||
|
||||
_lineFragments.push(lineFragment);
|
||||
}
|
||||
|
||||
- (id)_lineFragmentForLocation:(unsigned) aLoc
|
||||
{
|
||||
var fragments = _objectsInRange(_lineFragments, CPMakeRange(aLoc,0)),
|
||||
var fragments = _objectsInRange(_lineFragments, CPMakeRange(aLoc, 0)),
|
||||
l = fragments.length;
|
||||
|
||||
if (l > 0)
|
||||
@@ -993,6 +989,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)setLineFragmentRect:(CGRect)fragmentRect forGlyphRange:(CPRange)glyphRange usedRect:(CGRect)usedRect
|
||||
{
|
||||
var lineFragment = _objectWithLocationInRange(_lineFragments, glyphRange.location);
|
||||
@@ -1015,6 +1012,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
- (void)setLocation:(CGPoint)aPoint forStartOfGlyphRange:(CPRange)glyphRange
|
||||
{
|
||||
var lineFragment = _objectWithLocationInRange(_lineFragments, glyphRange.location);
|
||||
|
||||
if (lineFragment)
|
||||
lineFragment._location = CGPointCreateCopy(aPoint);
|
||||
}
|
||||
@@ -1053,7 +1051,9 @@ var _objectsInRange = function(aList, aRange)
|
||||
_extraLineFragment._textContainer = textContainer;
|
||||
}
|
||||
else
|
||||
{
|
||||
_extraLineFragment = nil;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1061,7 +1061,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
*/
|
||||
- (CGRect)usedRectForTextContainer:(CPTextContainer)textContainer
|
||||
{
|
||||
var rect = nil;
|
||||
var rect;
|
||||
|
||||
for (var i = 0; i < _lineFragments.length; i++)
|
||||
{
|
||||
@@ -1074,7 +1074,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
}
|
||||
}
|
||||
|
||||
return (rect)?rect:CGRectMakeZero();
|
||||
return rect ? rect : CGRectMakeZero();
|
||||
}
|
||||
|
||||
- (CGRect)lineFragmentRectForGlyphAtIndex:(unsigned)glyphIndex effectiveRange:(CPRangePointer)effectiveGlyphRange
|
||||
@@ -1170,11 +1170,6 @@ var _objectsInRange = function(aList, aRange)
|
||||
return index;
|
||||
}
|
||||
|
||||
- (void)setLineFragmentFactory:(Class)lineFragmentFactory
|
||||
{
|
||||
_lineFragmentFactory = lineFragmentFactory;
|
||||
}
|
||||
|
||||
- (CPArray)rectArrayForCharacterRange:(CPRange)charRange
|
||||
withinSelectedCharacterRange:(CPRange)selectedCharRange
|
||||
inTextContainer:(CPTextContainer)container
|
||||
@@ -1192,6 +1187,7 @@ var _objectsInRange = function(aList, aRange)
|
||||
for (var i = 0; i < lineFragments.length; i++)
|
||||
{
|
||||
var fragment = lineFragments[i];
|
||||
|
||||
if (fragment._textContainer === container)
|
||||
{
|
||||
var frames = [fragment glyphFrames],
|
||||
@@ -1220,10 +1216,12 @@ var _objectsInRange = function(aList, aRange)
|
||||
}
|
||||
|
||||
var len = rectArray.length;
|
||||
|
||||
for (var i = 0; i < len - 1; i++) // extend the width of all but the last one
|
||||
{
|
||||
if (rectArray[i].origin.y == rectArray[i + 1].origin.y)
|
||||
continue;
|
||||
|
||||
rectArray[i].size.width = containerSize.width - rectArray[i].origin.x;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,15 +84,15 @@ CPParagraphStyleAttributeName = @"CPParagraphStyleAttributeName";
|
||||
|
||||
@implementation CPParagraphStyle : CPObject
|
||||
{
|
||||
CPArray _tabStops @accessors(property = tabStops);
|
||||
CPTextAlignment _alignment @accessors(property = alignment);
|
||||
unsigned _firstLineHeadIndent @accessors(property = firstLineHeadIndent);
|
||||
unsigned _headIndent @accessors(property = headIndent);
|
||||
unsigned _tailIndent @accessors(property = tailIndent);
|
||||
unsigned _paragraphSpacing @accessors(property = paragraphSpacing);
|
||||
unsigned _minimumLineHeight @accessors(property = minimumLineHeight);
|
||||
unsigned _maximumLineHeight @accessors(property = maximumLineHeight);
|
||||
unsigned _lineSpacing @accessors(property = lineSpacing);
|
||||
CPArray _tabStops @accessors(property=tabStops);
|
||||
CPTextAlignment _alignment @accessors(property=alignment);
|
||||
unsigned _firstLineHeadIndent @accessors(property=firstLineHeadIndent);
|
||||
unsigned _headIndent @accessors(property=headIndent);
|
||||
unsigned _tailIndent @accessors(property=tailIndent);
|
||||
unsigned _paragraphSpacing @accessors(property=paragraphSpacing);
|
||||
unsigned _minimumLineHeight @accessors(property=minimumLineHeight);
|
||||
unsigned _maximumLineHeight @accessors(property=maximumLineHeight);
|
||||
unsigned _lineSpacing @accessors(property=lineSpacing);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -76,12 +76,16 @@ CPLineMovesUp = 4;
|
||||
*/
|
||||
@implementation CPTextContainer : CPObject
|
||||
{
|
||||
CGSize _size;
|
||||
CPTextView _textView;
|
||||
CPLayoutManager _layoutManager;
|
||||
float _lineFragmentPadding;
|
||||
float _lineFragmentPadding @accessors(property=lineFragmentPadding);
|
||||
CGSize _size @accessors(property=containerSize)
|
||||
CPLayoutManager _layoutManager @accessors(property=layoutManager);
|
||||
CPTextView _textView @accessors(property=textView);
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Init methods
|
||||
|
||||
- (id)initWithContainerSize:(CGSize)aSize
|
||||
{
|
||||
self = [super init];
|
||||
@@ -100,10 +104,8 @@ CPLineMovesUp = 4;
|
||||
return [self initWithContainerSize:CPMakeSize(1e7, 1e7)];
|
||||
}
|
||||
|
||||
- (CGSize)containerSize
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
#pragma mark -
|
||||
#pragma mark Setter methods
|
||||
|
||||
- (void)setContainerSize:(CGSize)someSize
|
||||
{
|
||||
@@ -112,9 +114,11 @@ CPLineMovesUp = 4;
|
||||
_size = someSize;
|
||||
|
||||
if (oldSize.width != _size.width)
|
||||
{ [_layoutManager invalidateLayoutForCharacterRange:CPMakeRange(0,[[_layoutManager textStorage] length])
|
||||
isSoft:NO
|
||||
actualCharacterRange:NULL];
|
||||
{
|
||||
[_layoutManager invalidateLayoutForCharacterRange:CPMakeRange(0, [[_layoutManager textStorage] length])
|
||||
isSoft:NO
|
||||
actualCharacterRange:NULL];
|
||||
|
||||
[_layoutManager _validateLayoutAndGlyphs];
|
||||
}
|
||||
}
|
||||
@@ -127,15 +131,15 @@ CPLineMovesUp = 4;
|
||||
if (flag)
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(textViewFrameChanged:)
|
||||
name:CPViewFrameDidChangeNotification
|
||||
object:_textView];
|
||||
selector:@selector(textViewFrameChanged:)
|
||||
name:CPViewFrameDidChangeNotification
|
||||
object:_textView];
|
||||
}
|
||||
else
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter] removeObserver:self
|
||||
name:CPViewFrameDidChangeNotification
|
||||
object:_textView];
|
||||
name:CPViewFrameDidChangeNotification
|
||||
object:_textView];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,40 +160,12 @@ CPLineMovesUp = 4;
|
||||
|
||||
_textView = aTextView;
|
||||
|
||||
if (_textView != nil)
|
||||
if (_textView)
|
||||
[_textView setTextContainer:self];
|
||||
|
||||
[_layoutManager textContainerChangedTextView:self];
|
||||
}
|
||||
|
||||
- (CPTextView)textView
|
||||
{
|
||||
return _textView;
|
||||
}
|
||||
|
||||
- (void)setLayoutManager:(CPLayoutManager)aManager
|
||||
{
|
||||
if (_layoutManager === aManager)
|
||||
return;
|
||||
|
||||
_layoutManager = aManager;
|
||||
}
|
||||
|
||||
- (CPLayoutManager)layoutManager
|
||||
{
|
||||
return _layoutManager;
|
||||
}
|
||||
|
||||
- (void)setLineFragmentPadding:(float)aFloat
|
||||
{
|
||||
_lineFragmentPadding = aFloat;
|
||||
}
|
||||
|
||||
- (float)lineFragmentPadding
|
||||
{
|
||||
return _lineFragmentPadding;
|
||||
}
|
||||
|
||||
- (BOOL)containsPoint:(CGPoint)aPoint
|
||||
{
|
||||
return CGRectContainsPoint(CGRectMake(0, 0, _size.width, _size.height), aPoint);
|
||||
@@ -209,7 +185,7 @@ CPLineMovesUp = 4;
|
||||
|
||||
if (sweep != CPLineSweepRight || movement != CPLineMovesDown)
|
||||
{
|
||||
CPLog.trace(@"FIXME: unsupported sweep ("+sweep+") or movement ("+movement+")");
|
||||
CPLog.trace(@"FIXME: unsupported sweep (" + sweep + ") or movement (" + movement + ")");
|
||||
return CGRectMakeZero();
|
||||
}
|
||||
|
||||
@@ -230,4 +206,4 @@ CPLineMovesUp = 4;
|
||||
return resultRect;
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
@@ -42,16 +42,19 @@ CPTextStorageDidProcessEditingNotification = @"CPTextStorageDidProcessEditingNot
|
||||
{
|
||||
CPColor _foregroundColor @accessors(property=foregroundColor);
|
||||
CPFont _font @accessors(property=font);
|
||||
CPMutableArray _layoutManagers @accessors(getter=layoutManagers);
|
||||
CPRange _editedRange @accessors(getter=editedRange);
|
||||
id _delegate @accessors(property=delegate);
|
||||
int _changeInLength @accessors(property=changeinLength);
|
||||
unsigned _editedMask @accessors(property=editedMask);
|
||||
|
||||
CPMutableArray _layoutManagers;
|
||||
id _delegate;
|
||||
|
||||
int _changeInLength;
|
||||
unsigned _editedMask;
|
||||
CPRange _editedRange;
|
||||
int _editCount; // {begin,end}Editing counter
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Init methods
|
||||
|
||||
- (id)initWithString:(CPString)aString attributes:(CPDictionary)attributes
|
||||
{
|
||||
self = [super initWithString:aString attributes:attributes];
|
||||
@@ -77,10 +80,9 @@ CPTextStorageDidProcessEditingNotification = @"CPTextStorageDidProcessEditingNot
|
||||
return [self initWithString:@"" attributes:nil];
|
||||
}
|
||||
|
||||
- (id)delegate
|
||||
{
|
||||
return _delegate;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Delegate methods
|
||||
|
||||
- (void)setDelegate:(id)aDelegate
|
||||
{
|
||||
@@ -107,6 +109,10 @@ CPTextStorageDidProcessEditingNotification = @"CPTextStorageDidProcessEditingNot
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Layout manager methods
|
||||
|
||||
- (void)addLayoutManager:(CPLayoutManager)aManager
|
||||
{
|
||||
if (![_layoutManagers containsObject:aManager])
|
||||
@@ -124,50 +130,36 @@ CPTextStorageDidProcessEditingNotification = @"CPTextStorageDidProcessEditingNot
|
||||
}
|
||||
}
|
||||
|
||||
- (CPArray)layoutManagers
|
||||
{
|
||||
return _layoutManagers;
|
||||
}
|
||||
|
||||
- (CPRange)editedRange
|
||||
{
|
||||
return _editedRange;
|
||||
}
|
||||
|
||||
- (int)changeInLength
|
||||
{
|
||||
return _changeInLength;
|
||||
}
|
||||
|
||||
- (unsigned)editedMask
|
||||
{
|
||||
return _editedMask;
|
||||
}
|
||||
|
||||
- (void)invalidateAttributesInRange:(CPRange)aRange
|
||||
{
|
||||
/* FIXME: stub */
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Editing methods
|
||||
|
||||
- (void)processEditing
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:CPTextStorageWillProcessEditingNotification
|
||||
object:self];
|
||||
var notificationCenter = [CPNotificationCenter defaultCenter];
|
||||
|
||||
[notificationCenter postNotificationName:CPTextStorageWillProcessEditingNotification
|
||||
object:self];
|
||||
|
||||
[self invalidateAttributesInRange:[self editedRange]];
|
||||
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:CPTextStorageDidProcessEditingNotification
|
||||
object:self];
|
||||
[notificationCenter postNotificationName:CPTextStorageDidProcessEditingNotification
|
||||
object:self];
|
||||
|
||||
var c = [_layoutManagers count];
|
||||
|
||||
for (var i = 0; i < c; i++)
|
||||
{
|
||||
[[_layoutManagers objectAtIndex:i] textStorage:self
|
||||
edited:_editedMask
|
||||
range:_editedRange
|
||||
changeInLength:_changeInLength
|
||||
invalidatedRange:_editedRange];
|
||||
edited:_editedMask
|
||||
range:_editedRange
|
||||
changeInLength:_changeInLength
|
||||
invalidatedRange:_editedRange];
|
||||
}
|
||||
|
||||
_editedRange.location = CPNotFound;
|
||||
@@ -207,10 +199,7 @@ CPTextStorageDidProcessEditingNotification = @"CPTextStorageDidProcessEditingNot
|
||||
_changeInLength += lengthChange;
|
||||
aRange.length += lengthChange;
|
||||
|
||||
if (_editedRange.location == CPNotFound)
|
||||
_editedRange = aRange;
|
||||
else
|
||||
_editedRange = CPUnionRange(_editedRange,aRange);
|
||||
_editedRange.location == CPNotFound ? aRange : CPUnionRange(_editedRange,aRange);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,4 +250,5 @@ CPTextStorageDidProcessEditingNotification = @"CPTextStorageDidProcessEditingNot
|
||||
|
||||
return [super attributedSubstringFromRange:aRange];
|
||||
}
|
||||
@end
|
||||
|
||||
@end
|
||||
+252
-361
File diff suppressed because it is too large.
Load diff
+148
-151
@@ -33,18 +33,18 @@
|
||||
/*
|
||||
CPTypesetterControlCharacterAction
|
||||
*/
|
||||
CPTypesetterZeroAdvancementAction = (1 << 0);
|
||||
CPTypesetterWhitespaceAction = (1 << 1);
|
||||
CPSTypesetterHorizontalTabAction = (1 << 2);
|
||||
CPTypesetterLineBreakAction = (1 << 3);
|
||||
CPTypesetterParagraphBreakAction = (1 << 4);
|
||||
CPTypesetterContainerBreakAction = (1 << 5);
|
||||
|
||||
CPTypesetterZeroAdvancementAction = 1 << 0;
|
||||
CPTypesetterWhitespaceAction = 1 << 1;
|
||||
CPSTypesetterHorizontalTabAction = 1 << 2;
|
||||
CPTypesetterLineBreakAction = 1 << 3;
|
||||
CPTypesetterParagraphBreakAction = 1 << 4;
|
||||
CPTypesetterContainerBreakAction = 1 << 5;
|
||||
|
||||
var _measuringContext,
|
||||
_measuringContextFont,
|
||||
_isCanvasSizingInvalid,
|
||||
_didTestCanvasSizingValid;
|
||||
_didTestCanvasSizingValid,
|
||||
_sharedSimpleTypesetter;
|
||||
|
||||
function _widthOfStringForFont(aString, aFont)
|
||||
{
|
||||
@@ -71,11 +71,17 @@ function _widthOfStringForFont(aString, aFont)
|
||||
return _measuringContext.measureText(aString);
|
||||
}
|
||||
|
||||
var CPSystemTypesetterFactory = nil;
|
||||
var CPSystemTypesetterFactory;
|
||||
|
||||
@implementation CPTypesetter : CPObject
|
||||
{
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Class methods
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
[CPTypesetter _setSystemTypesetterFactory:[CPSimpleTypesetter class]];
|
||||
}
|
||||
|
||||
+ (id)sharedSystemTypesetter
|
||||
@@ -88,11 +94,6 @@ var CPSystemTypesetterFactory = nil;
|
||||
CPSystemTypesetterFactory = aClass;
|
||||
}
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
[CPTypesetter _setSystemTypesetterFactory:[CPSimpleTypesetter class]];
|
||||
}
|
||||
|
||||
- (CPTypesetterControlCharacterAction)actionForControlCharacterAtIndex:(unsigned)charIndex
|
||||
{
|
||||
return CPTypesetterZeroAdvancementAction;
|
||||
@@ -123,13 +124,10 @@ var CPSystemTypesetterFactory = nil;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
var _sharedSimpleTypesetter = nil;
|
||||
|
||||
@implementation CPSimpleTypesetter : CPTypesetter
|
||||
{
|
||||
CPLayoutManager _layoutManager;
|
||||
CPTextContainer _currentTextContainer;
|
||||
CPLayoutManager _layoutManager @accessors(property=layoutManager);
|
||||
CPTextContainer _currentTextContainer @accessors(property=currentTextContainer);
|
||||
CPTextStorage _textStorage;
|
||||
|
||||
CPRange _attributesRange;
|
||||
@@ -144,6 +142,10 @@ var _sharedSimpleTypesetter = nil;
|
||||
unsigned _indexOfCurrentContainer;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Class methods
|
||||
|
||||
+ (id)sharedInstance
|
||||
{
|
||||
if (_sharedSimpleTypesetter === nil)
|
||||
@@ -152,16 +154,6 @@ var _sharedSimpleTypesetter = nil;
|
||||
return _sharedSimpleTypesetter;
|
||||
}
|
||||
|
||||
- (CPLayoutManager)layoutManager
|
||||
{
|
||||
return _layoutManager;
|
||||
}
|
||||
|
||||
- (CPTextContainer)currentTextContainer
|
||||
{
|
||||
return _currentTextContainer;
|
||||
}
|
||||
|
||||
- (CPArray)textContainers
|
||||
{
|
||||
return [_layoutManager textContainers];
|
||||
@@ -174,13 +166,14 @@ var _sharedSimpleTypesetter = nil;
|
||||
if (!tabStops)
|
||||
tabStops = [CPParagraphStyle _defaultTabStops];
|
||||
|
||||
var i,
|
||||
l = tabStops.length;
|
||||
var l = tabStops.length,
|
||||
i;
|
||||
|
||||
|
||||
if (aWidth > tabStops[l - 1]._location)
|
||||
return nil;
|
||||
|
||||
for (i = l-1; i >= 0; i--)
|
||||
for (i = l - 1; i >= 0; i--)
|
||||
{
|
||||
if (aWidth > tabStops[i]._location)
|
||||
{
|
||||
@@ -188,6 +181,7 @@ var _sharedSimpleTypesetter = nil;
|
||||
return tabStops[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -197,10 +191,15 @@ var _sharedSimpleTypesetter = nil;
|
||||
advancements:(CPArray)advancements
|
||||
lineCount:(unsigned)lineCount
|
||||
{
|
||||
|
||||
if (!lineCount)
|
||||
return NO;
|
||||
|
||||
var myX = 0,
|
||||
rect = CGRectMake(lineOrigin.x, lineOrigin.y, _lineWidth, _lineHeight);
|
||||
|
||||
[_layoutManager setTextContainer:_currentTextContainer forGlyphRange:lineRange]; // creates a new lineFragment
|
||||
var rect = CGRectMake(lineOrigin.x, lineOrigin.y, _lineWidth, _lineHeight);
|
||||
[_layoutManager setLineFragmentRect: rect forGlyphRange:lineRange usedRect:rect];
|
||||
var myX = 0;
|
||||
[_layoutManager setLineFragmentRect:rect forGlyphRange:lineRange usedRect:rect];
|
||||
|
||||
switch ([_currentParagraph alignment])
|
||||
{
|
||||
@@ -220,9 +219,6 @@ var _sharedSimpleTypesetter = nil;
|
||||
[_layoutManager setLocation:CPMakePoint(myX, _lineBase) forStartOfGlyphRange:lineRange];
|
||||
[_layoutManager _setAdvancements:advancements forGlyphRange:lineRange];
|
||||
|
||||
if (!lineCount)
|
||||
return NO;
|
||||
|
||||
return ([_layoutManager _rescuingInvalidFragmentsWasPossibleForGlyphRange:lineRange]);
|
||||
}
|
||||
|
||||
@@ -250,24 +246,22 @@ var _sharedSimpleTypesetter = nil;
|
||||
isTabStop = NO,
|
||||
isWordWrapped = NO,
|
||||
numberOfGlyphs= [_textStorage length],
|
||||
leading;
|
||||
|
||||
var numLines = 0,
|
||||
leading,
|
||||
numLines = 0,
|
||||
theString = [_textStorage string],
|
||||
lineOrigin,
|
||||
ascent,
|
||||
descent;
|
||||
|
||||
var advancements = [],
|
||||
descent,
|
||||
advancements = [],
|
||||
prevRangeWidth = 0,
|
||||
measuringRange = CPMakeRange(glyphIndex, 0),
|
||||
currentAnchor = 0,
|
||||
_previousFont = nil;
|
||||
_previousFont;
|
||||
|
||||
if (glyphIndex > 0)
|
||||
lineOrigin = CGPointCreateCopy([_layoutManager lineFragmentRectForGlyphAtIndex:glyphIndex effectiveRange:nil].origin);
|
||||
else if ([_layoutManager extraLineFragmentTextContainer])
|
||||
lineOrigin = CGPointMake(0, [_layoutManager extraLineFragmentUsedRect].origin.y);
|
||||
lineOrigin = CGPointMake(0, [_layoutManager extraLineFragmentUsedRect].origin.y);
|
||||
else
|
||||
lineOrigin = CGPointMake(0, 0);
|
||||
|
||||
@@ -278,123 +272,124 @@ var _sharedSimpleTypesetter = nil;
|
||||
|
||||
for (; numLines != maxNumLines && glyphIndex < numberOfGlyphs; glyphIndex++)
|
||||
{
|
||||
if (!CPLocationInRange(glyphIndex, _attributesRange))
|
||||
{
|
||||
_currentAttributes = [_textStorage attributesAtIndex:glyphIndex effectiveRange:_attributesRange];
|
||||
_currentFont = [_currentAttributes objectForKey:CPFontAttributeName];
|
||||
_currentParagraph = [_currentAttributes objectForKey:CPParagraphStyleAttributeName] || [CPParagraphStyle defaultParagraphStyle];
|
||||
if (!CPLocationInRange(glyphIndex, _attributesRange))
|
||||
{
|
||||
_currentAttributes = [_textStorage attributesAtIndex:glyphIndex effectiveRange:_attributesRange];
|
||||
_currentFont = [_currentAttributes objectForKey:CPFontAttributeName];
|
||||
_currentParagraph = [_currentAttributes objectForKey:CPParagraphStyleAttributeName] || [CPParagraphStyle defaultParagraphStyle];
|
||||
|
||||
if (!_currentFont)
|
||||
_currentFont = [_textStorage font] || [CPFont systemFontOfSize:12.0];
|
||||
if (!_currentFont)
|
||||
_currentFont = [_textStorage font] || [CPFont systemFontOfSize:12.0];
|
||||
|
||||
ascent = ["x" sizeWithFont:_currentFont].height; //FIXME
|
||||
descent = 0; //FIXME
|
||||
leading = (ascent - descent) * 0.2; // FAKE leading
|
||||
}
|
||||
ascent = ["x" sizeWithFont:_currentFont].height; //FIXME
|
||||
descent = 0; //FIXME
|
||||
leading = (ascent - descent) * 0.2; // FAKE leading
|
||||
}
|
||||
|
||||
if (_previousFont !== _currentFont)
|
||||
{
|
||||
measuringRange = CPMakeRange(glyphIndex, 0);
|
||||
currentAnchor = prevRangeWidth;
|
||||
_previousFont = _currentFont;
|
||||
}
|
||||
if (_previousFont !== _currentFont)
|
||||
{
|
||||
measuringRange = CPMakeRange(glyphIndex, 0);
|
||||
currentAnchor = prevRangeWidth;
|
||||
_previousFont = _currentFont;
|
||||
}
|
||||
|
||||
lineRange.length++;
|
||||
measuringRange.length++;
|
||||
lineRange.length++;
|
||||
measuringRange.length++;
|
||||
|
||||
var currentChar = theString[glyphIndex], // use pure javascript methods for performance reasons
|
||||
rangeWidth = _widthOfStringForFont(theString.substr(measuringRange.location, measuringRange.length), _currentFont).width + currentAnchor;
|
||||
|
||||
switch (currentChar) // faster than sending actionForControlCharacterAtIndex: called for each char.
|
||||
{
|
||||
case '\n':
|
||||
case '\r':
|
||||
isNewline = YES;
|
||||
break;
|
||||
case '\t':
|
||||
{
|
||||
isTabStop = YES;
|
||||
var nextTab = [self textTabForWidth:rangeWidth + lineOrigin.x writingDirection:0];
|
||||
if (nextTab)
|
||||
{
|
||||
rangeWidth = nextTab._location - lineOrigin.x;
|
||||
}
|
||||
else
|
||||
rangeWidth += 28; //FIXME
|
||||
} // fallthrough intentional
|
||||
case ' ':
|
||||
wrapRange = CPMakeRangeCopy(lineRange);
|
||||
wrapWidth = rangeWidth;
|
||||
break;
|
||||
}
|
||||
|
||||
advancements.push(rangeWidth - prevRangeWidth);
|
||||
prevRangeWidth = _lineWidth = rangeWidth;
|
||||
|
||||
if (lineOrigin.x + rangeWidth > containerSize.width)
|
||||
{
|
||||
if (wrapWidth)
|
||||
{
|
||||
lineRange = wrapRange;
|
||||
_lineWidth = wrapWidth;
|
||||
}
|
||||
var currentChar = theString[glyphIndex], // use pure javascript methods for performance reasons
|
||||
rangeWidth = _widthOfStringForFont(theString.substr(measuringRange.location, measuringRange.length), _currentFont).width + currentAnchor;
|
||||
|
||||
switch (currentChar) // faster than sending actionForControlCharacterAtIndex: called for each char.
|
||||
{
|
||||
case '\n':
|
||||
case '\r':
|
||||
isNewline = YES;
|
||||
isWordWrapped = YES;
|
||||
glyphIndex = CPMaxRange(lineRange) - 1; // start the line starts directly at current character
|
||||
}
|
||||
break;
|
||||
|
||||
_lineHeight = MAX(_lineHeight, ascent - descent + leading);
|
||||
_lineBase = MAX(_lineBase, ascent);
|
||||
|
||||
if (isNewline || isTabStop)
|
||||
case '\t':
|
||||
{
|
||||
if ([self _flushRange:lineRange lineOrigin:lineOrigin currentContainerSize:containerSize advancements:advancements lineCount:numLines])
|
||||
return;
|
||||
var nextTab = [self textTabForWidth:rangeWidth + lineOrigin.x writingDirection:0];
|
||||
|
||||
if (isTabStop)
|
||||
{
|
||||
lineOrigin.x += rangeWidth;
|
||||
isTabStop = NO;
|
||||
}
|
||||
isTabStop = YES;
|
||||
|
||||
if (isNewline)
|
||||
{
|
||||
if ([_currentParagraph minimumLineHeight])
|
||||
_lineHeight = MAX(_lineHeight, [_currentParagraph minimumLineHeight]);
|
||||
if (nextTab)
|
||||
rangeWidth = nextTab._location - lineOrigin.x;
|
||||
else
|
||||
rangeWidth += 28; //FIXME
|
||||
} // fallthrough intentional
|
||||
case ' ':
|
||||
wrapRange = CPMakeRangeCopy(lineRange);
|
||||
wrapWidth = rangeWidth;
|
||||
break;
|
||||
}
|
||||
|
||||
if ([_currentParagraph maximumLineHeight])
|
||||
_lineHeight = MIN(_lineHeight, [_currentParagraph maximumLineHeight]);
|
||||
advancements.push(rangeWidth - prevRangeWidth);
|
||||
prevRangeWidth = _lineWidth = rangeWidth;
|
||||
|
||||
lineOrigin.y += _lineHeight;
|
||||
|
||||
if ([_currentParagraph lineSpacing])
|
||||
lineOrigin.y += [_currentParagraph lineSpacing];
|
||||
|
||||
if (lineOrigin.y > [_currentTextContainer containerSize].height)
|
||||
{
|
||||
_indexOfCurrentContainer++;
|
||||
_indexOfCurrentContainer = MAX(_indexOfCurrentContainer, [[_layoutManager textContainers] count] - 1);
|
||||
_currentTextContainer = [[_layoutManager textContainers] objectAtIndex: _indexOfCurrentContainer];
|
||||
}
|
||||
|
||||
lineOrigin.x = 0;
|
||||
numLines++;
|
||||
isNewline = NO;
|
||||
}
|
||||
|
||||
_lineWidth = 0;
|
||||
advancements = [];
|
||||
currentAnchor = 0;
|
||||
prevRangeWidth = 0;
|
||||
_lineHeight = 0;
|
||||
_lineBase = 0;
|
||||
lineRange = CPMakeRange(glyphIndex + 1, 0);
|
||||
measuringRange = CPMakeRange(glyphIndex + 1, 0);
|
||||
wrapRange = CPMakeRange(0, 0);
|
||||
wrapWidth = 0;
|
||||
isWordWrapped = NO;
|
||||
if (lineOrigin.x + rangeWidth > containerSize.width)
|
||||
{
|
||||
if (wrapWidth)
|
||||
{
|
||||
lineRange = wrapRange;
|
||||
_lineWidth = wrapWidth;
|
||||
}
|
||||
|
||||
isNewline = YES;
|
||||
isWordWrapped = YES;
|
||||
glyphIndex = CPMaxRange(lineRange) - 1; // start the line starts directly at current character
|
||||
}
|
||||
|
||||
_lineHeight = MAX(_lineHeight, ascent - descent + leading);
|
||||
_lineBase = MAX(_lineBase, ascent);
|
||||
|
||||
if (isNewline || isTabStop)
|
||||
{
|
||||
if ([self _flushRange:lineRange lineOrigin:lineOrigin currentContainerSize:containerSize advancements:advancements lineCount:numLines])
|
||||
return;
|
||||
|
||||
if (isTabStop)
|
||||
{
|
||||
lineOrigin.x += rangeWidth;
|
||||
isTabStop = NO;
|
||||
}
|
||||
|
||||
if (isNewline)
|
||||
{
|
||||
if ([_currentParagraph minimumLineHeight])
|
||||
_lineHeight = MAX(_lineHeight, [_currentParagraph minimumLineHeight]);
|
||||
|
||||
if ([_currentParagraph maximumLineHeight])
|
||||
_lineHeight = MIN(_lineHeight, [_currentParagraph maximumLineHeight]);
|
||||
|
||||
lineOrigin.y += _lineHeight;
|
||||
|
||||
if ([_currentParagraph lineSpacing])
|
||||
lineOrigin.y += [_currentParagraph lineSpacing];
|
||||
|
||||
if (lineOrigin.y > [_currentTextContainer containerSize].height)
|
||||
{
|
||||
_indexOfCurrentContainer++;
|
||||
_indexOfCurrentContainer = MAX(_indexOfCurrentContainer, [[_layoutManager textContainers] count] - 1);
|
||||
_currentTextContainer = [[_layoutManager textContainers] objectAtIndex: _indexOfCurrentContainer];
|
||||
}
|
||||
|
||||
lineOrigin.x = 0;
|
||||
numLines++;
|
||||
isNewline = NO;
|
||||
}
|
||||
|
||||
_lineWidth = 0;
|
||||
advancements = [];
|
||||
currentAnchor = 0;
|
||||
prevRangeWidth = 0;
|
||||
_lineHeight = 0;
|
||||
_lineBase = 0;
|
||||
lineRange = CPMakeRange(glyphIndex + 1, 0);
|
||||
measuringRange = CPMakeRange(glyphIndex + 1, 0);
|
||||
wrapRange = CPMakeRange(0, 0);
|
||||
wrapWidth = 0;
|
||||
isWordWrapped = NO;
|
||||
}
|
||||
}
|
||||
|
||||
// this is to "flush" the remaining characters
|
||||
@@ -403,7 +398,9 @@ var _sharedSimpleTypesetter = nil;
|
||||
|
||||
if ([theString.charAt(theString.length - 1) === "\n"])
|
||||
{
|
||||
var rect = CGRectMake(0, lineOrigin.y, containerSize.width, [_layoutManager._lineFragments lastObject]._usedRect.size.height); // fixme: row-height is crudely hacked
|
||||
// fixme: row-height is crudely hacked
|
||||
var rect = CGRectMake(0, lineOrigin.y, containerSize.width, [_layoutManager._lineFragments lastObject]._usedRect.size.height);
|
||||
|
||||
[_layoutManager setExtraLineFragmentRect:rect usedRect:rect textContainer:_currentTextContainer];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +54,12 @@ var hexTable = [];
|
||||
|
||||
- (id)init
|
||||
{
|
||||
[self resetFont];
|
||||
[self resetParagraphStyle];
|
||||
_range = CPMakeRange(0, 0);
|
||||
if (self = [super init])
|
||||
{
|
||||
[self resetFont];
|
||||
[self resetParagraphStyle];
|
||||
_range = CPMakeRange(0, 0);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -78,28 +81,27 @@ var hexTable = [];
|
||||
{
|
||||
var font = [CPFont _fontWithName:fontName size:fontSize bold:bold italic:italic];
|
||||
|
||||
if (font == nil)
|
||||
if (font)
|
||||
return font;
|
||||
|
||||
//Before giving up and using a default font, we try if this is
|
||||
//not the case of a font with a composite name, such as
|
||||
//'Helvetica-Light'. In that case, even if we don't have
|
||||
//exactly an 'Helvetica-Light' font family, we might have an
|
||||
//'Helvetica' one.
|
||||
var range = [fontName rangeOfString:@"-"];
|
||||
|
||||
if (range.location != CPNotFound)
|
||||
{
|
||||
/* Before giving up and using a default font, we try if this is
|
||||
* not the case of a font with a composite name, such as
|
||||
* 'Helvetica-Light'. In that case, even if we don't have
|
||||
* exactly an 'Helvetica-Light' font family, we might have an
|
||||
* 'Helvetica' one. */
|
||||
var range = [fontName rangeOfString:@"-"];
|
||||
var fontFamily = [fontName substringToIndex: range.location];
|
||||
|
||||
if (range.location != CPNotFound)
|
||||
{
|
||||
var fontFamily = [fontName substringToIndex: range.location];
|
||||
|
||||
font = [CPFont fontWithName:fontFamily size:fontSize];
|
||||
}
|
||||
|
||||
if (font == nil)
|
||||
{
|
||||
/* Last resort, default font. :-( */
|
||||
font = [CPFont systemFontOfSize:fontSize];
|
||||
}
|
||||
font = [CPFont fontWithName:fontFamily size:fontSize];
|
||||
}
|
||||
|
||||
/* Last resort, default font. :-( */
|
||||
if (font == nil)
|
||||
font = [CPFont systemFontOfSize:fontSize];
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
@@ -137,7 +139,6 @@ var hexTable = [];
|
||||
fontSize = 12.0;
|
||||
italic = NO;
|
||||
bold = NO;
|
||||
|
||||
underline = 0;
|
||||
strikethrough = 0;
|
||||
script = 0;
|
||||
@@ -257,37 +258,36 @@ var kRgsymRtf = {
|
||||
|
||||
@implementation _CPRTFParser : CPObject
|
||||
{
|
||||
CPString _codePage;
|
||||
CGSize _paper;
|
||||
CPString _rtf;
|
||||
unsigned _curState;
|
||||
CPArray _states;
|
||||
unsigned _currentParseIndex;
|
||||
BOOL _hexreturn;
|
||||
_RTFAttribute _currentRun;
|
||||
CPAttributedString _result;
|
||||
CPArray _colorArray;
|
||||
CPArray _fontArray;
|
||||
CPString _freename;
|
||||
BOOL _parsingFontTable;
|
||||
CPString _codePage;
|
||||
CGSize _paper;
|
||||
CPString _rtf;
|
||||
unsigned _curState;
|
||||
CPArray _states;
|
||||
unsigned _currentParseIndex;
|
||||
BOOL _hexreturn;
|
||||
_RTFAttribute _currentRun;
|
||||
CPAttributedString _result;
|
||||
CPArray _colorArray;
|
||||
CPArray _fontArray;
|
||||
CPString _freename;
|
||||
BOOL _parsingFontTable;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
_paper = CPMakeSize(0, 0);
|
||||
_rtf = "";
|
||||
_curState = 0; // 0 = normal, 1 = skip
|
||||
_states = [];
|
||||
_currentParseIndex = 0;
|
||||
_hexreturn = NO;
|
||||
_currentRun = nil;
|
||||
_result = [CPAttributedString new];
|
||||
_colorArray = [];
|
||||
_fontArray = ['Arial']; // FIXME: should be name of system font
|
||||
_freename = "";
|
||||
_parsingFontTable = NO;
|
||||
_paper = CPMakeSize(0, 0);
|
||||
_rtf = "";
|
||||
_curState = 0; // 0 = normal, 1 = skip
|
||||
_states = [];
|
||||
_currentParseIndex = 0;
|
||||
_hexreturn = NO;
|
||||
_result = [CPAttributedString new];
|
||||
_colorArray = [];
|
||||
_fontArray = ['Arial']; // FIXME: should be name of system font
|
||||
_freename = "";
|
||||
_parsingFontTable = NO;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -302,7 +302,7 @@ var kRgsymRtf = {
|
||||
return sym[4];
|
||||
|
||||
case 1:
|
||||
console.log("skipped : " + sym[4]);
|
||||
CPLogConsole("skipped : " + sym[4]);
|
||||
return '';
|
||||
|
||||
default:
|
||||
@@ -419,12 +419,14 @@ var kRgsymRtf = {
|
||||
{
|
||||
if (_currentRun && _currentRun.bold)
|
||||
[self _flushCurrentRun];
|
||||
|
||||
_currentRun.bold = NO
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_currentRun && !_currentRun.bold)
|
||||
[self _flushCurrentRun]
|
||||
if (_currentRun && !_currentRun.bold)
|
||||
[self _flushCurrentRun];
|
||||
|
||||
_currentRun.bold = YES;
|
||||
}
|
||||
|
||||
@@ -435,16 +437,19 @@ var kRgsymRtf = {
|
||||
{
|
||||
if (_currentRun && _currentRun.italic)
|
||||
[self _flushCurrentRun];
|
||||
|
||||
_currentRun.italic = NO
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_currentRun && !_currentRun.italic)
|
||||
[self _flushCurrentRun]
|
||||
[self _flushCurrentRun];
|
||||
|
||||
_currentRun.italic = YES;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "qc": // paragraph center
|
||||
[_currentRun.paragraph setAlignment:CPCenterTextAlignment];
|
||||
break;
|
||||
@@ -477,7 +482,7 @@ var kRgsymRtf = {
|
||||
|
||||
if (sym[4] == "destSkip")
|
||||
{
|
||||
console.log("Dest skip start : [" + sym[0] + "]");
|
||||
CPLogConsole("Dest skip start : [" + sym[0] + "]");
|
||||
_curState++;
|
||||
}
|
||||
|
||||
@@ -494,9 +499,8 @@ var kRgsymRtf = {
|
||||
{
|
||||
case kRTFParserType_prop:
|
||||
if (sym[2] || !fParam)
|
||||
{
|
||||
param = sym[1];
|
||||
}
|
||||
|
||||
return [self _applyPropChange:sym parameter:param];
|
||||
|
||||
case kRTFParserType_char:
|
||||
@@ -565,15 +569,14 @@ var kRgsymRtf = {
|
||||
|
||||
case "tx": // tabstop
|
||||
var location = parseInt(param) / 20;
|
||||
|
||||
if (_currentRun)
|
||||
{
|
||||
[_currentRun addTab:location type:CPLeftTabStopType];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log("skip : " + keyword + " param: " + param);
|
||||
CPLogConsole("skip : " + keyword + " param: " + param);
|
||||
|
||||
}
|
||||
|
||||
@@ -639,10 +642,8 @@ var kRgsymRtf = {
|
||||
- (CPAttributedString)parseRTF:(CPString)rtf
|
||||
{
|
||||
if (rtf.length == 0)
|
||||
{
|
||||
// alert("invalid rtf");
|
||||
return '';
|
||||
}
|
||||
|
||||
_currentParseIndex = -1;
|
||||
|
||||
var len = rtf.length,
|
||||
@@ -667,35 +668,38 @@ var kRgsymRtf = {
|
||||
if (lastchar == 1)
|
||||
{
|
||||
lastchar = 0;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
_freename += tmp;
|
||||
[self _appendPlainString:tmp];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "{":
|
||||
if ([self pushState])
|
||||
{
|
||||
console.log("push");
|
||||
}
|
||||
CPLogConsole("push");
|
||||
|
||||
break;
|
||||
|
||||
case "}":
|
||||
if ([self popState])
|
||||
{
|
||||
console.log("pop");
|
||||
}
|
||||
CPLogConsole("pop");
|
||||
|
||||
if (_freename)
|
||||
{
|
||||
console.log(_freename);
|
||||
CPLogConsole(_freename);
|
||||
|
||||
if (_parsingFontTable)
|
||||
{
|
||||
_fontArray.push(_freename);
|
||||
_parsingFontTable = NO;
|
||||
}
|
||||
|
||||
_freename = "";
|
||||
}
|
||||
|
||||
[self _flushCurrentRun]
|
||||
break;
|
||||
|
||||
@@ -727,9 +731,7 @@ var kRgsymRtf = {
|
||||
var temp = parseInt(hex, 16);
|
||||
|
||||
if (hexTable && hexTable[hex.toUpperCase()] !== undefined)
|
||||
{
|
||||
temp = parseInt(hexTable[hex.toUpperCase()], 16);
|
||||
}
|
||||
|
||||
[self _appendPlainString: String.fromCharCode(temp)]
|
||||
hex = '';
|
||||
@@ -737,7 +739,7 @@ var kRgsymRtf = {
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("hex skipped");
|
||||
CPLogConsole("hex skipped");
|
||||
}
|
||||
|
||||
_hexreturn = NO;
|
||||
@@ -745,7 +747,6 @@ var kRgsymRtf = {
|
||||
else if (ch !== undefined && _curState === 0)
|
||||
{
|
||||
[self _appendPlainString:ch];
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
+192
-205
@@ -46,46 +46,50 @@ var PAPERSIZE = @"PaperSize",
|
||||
|
||||
function _points2twips(a) { return (a) * 20.0; }
|
||||
|
||||
|
||||
@implementation _CPRTFProducer:CPObject
|
||||
@implementation _CPRTFProducer : CPObject
|
||||
{
|
||||
CPAttributedString text;
|
||||
CPAttributedString text;
|
||||
CPMutableDictionary fontDict;
|
||||
CPMutableDictionary colorDict;
|
||||
CPDictionary docDict;
|
||||
CPMutableArray attachments;
|
||||
CPFont currentFont;
|
||||
|
||||
CPColor fgColor;
|
||||
CPColor bgColor;
|
||||
CPColor ulColor;
|
||||
CPDictionary docDict;
|
||||
CPMutableArray attachments;
|
||||
CPFont currentFont;
|
||||
CPColor fgColor;
|
||||
CPColor bgColor;
|
||||
CPColor ulColor;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Class methods
|
||||
|
||||
|
||||
+ (CPString)produceRTF:(CPAttributedString)aText documentAttributes:(CPDictionary)dict
|
||||
{
|
||||
var mynew = [self new],
|
||||
data;
|
||||
|
||||
return [mynew RTFDStringFromAttributedString:aText
|
||||
documentAttributes:dict];
|
||||
return [mynew RTFDStringFromAttributedString:aText documentAttributes:dict];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark init methods
|
||||
|
||||
- (id)init
|
||||
{
|
||||
/*
|
||||
* maintain a dictionary for the used colours
|
||||
* (for rtf-header generation)
|
||||
*/
|
||||
colorDict = [CPMutableDictionary new];
|
||||
/*
|
||||
* maintain a dictionary for the used fonts
|
||||
* (for rtf-header generation)
|
||||
*/
|
||||
fontDict = [CPMutableDictionary new];
|
||||
if (self = [super init])
|
||||
{
|
||||
// maintain a dictionary for the used colours
|
||||
// (for rtf-header generation)
|
||||
colorDict = [CPMutableDictionary new];
|
||||
|
||||
currentFont = nil;
|
||||
fgColor = [CPColor blackColor];
|
||||
bgColor= [CPColor whiteColor];
|
||||
//maintain a dictionary for the used fonts
|
||||
//(for rtf-header generation)
|
||||
fontDict = [CPMutableDictionary new];
|
||||
|
||||
fgColor = [CPColor blackColor];
|
||||
bgColor= [CPColor whiteColor];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -93,155 +97,145 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
// private stuff follows
|
||||
- (CPString)fontTable
|
||||
{
|
||||
// write Font Table
|
||||
if ([fontDict count])
|
||||
{
|
||||
var fontlistString = "",
|
||||
fontEnum,
|
||||
currFont,
|
||||
keyArray;
|
||||
|
||||
keyArray = [fontDict allKeys];
|
||||
keyArray = [keyArray sortedArrayUsingSelector:@selector(compare:)];
|
||||
fontEnum = [keyArray objectEnumerator];
|
||||
|
||||
while ((currFont = [fontEnum nextObject]) !== nil)
|
||||
{
|
||||
var fontFamily,
|
||||
detail;
|
||||
|
||||
if ([currFont isEqualToString:@"Symbol"])
|
||||
fontFamily = @"tech";
|
||||
else if ([currFont isEqualToString:@"Helvetica"])
|
||||
fontFamily = @"swiss";
|
||||
else if ([currFont isEqualToString:@"Arial"])
|
||||
fontFamily = @"swiss";
|
||||
else if ([currFont isEqualToString:@"Courier"])
|
||||
fontFamily = @"modern";
|
||||
else if ([currFont isEqualToString:@"Times"])
|
||||
fontFamily = @"roman";
|
||||
else fontFamily = @"nil";
|
||||
|
||||
detail = [CPString stringWithFormat:@"%@\\f%@ %@;",
|
||||
[fontDict objectForKey:currFont], fontFamily, currFont];
|
||||
fontlistString += detail;
|
||||
}
|
||||
|
||||
return [CPString stringWithFormat:@"{\\fonttbl%@}\n", fontlistString];
|
||||
}
|
||||
else
|
||||
if (![fontDict count])
|
||||
return @"";
|
||||
|
||||
var fontlistString = "",
|
||||
fontEnum,
|
||||
currFont,
|
||||
keyArray;
|
||||
|
||||
keyArray = [fontDict allKeys];
|
||||
keyArray = [keyArray sortedArrayUsingSelector:@selector(compare:)];
|
||||
fontEnum = [keyArray objectEnumerator];
|
||||
|
||||
while ((currFont = [fontEnum nextObject]) !== nil)
|
||||
{
|
||||
var fontFamily,
|
||||
detail;
|
||||
|
||||
if ([currFont isEqualToString:@"Symbol"])
|
||||
fontFamily = @"tech";
|
||||
else if ([currFont isEqualToString:@"Helvetica"])
|
||||
fontFamily = @"swiss";
|
||||
else if ([currFont isEqualToString:@"Arial"])
|
||||
fontFamily = @"swiss";
|
||||
else if ([currFont isEqualToString:@"Courier"])
|
||||
fontFamily = @"modern";
|
||||
else if ([currFont isEqualToString:@"Times"])
|
||||
fontFamily = @"roman";
|
||||
else fontFamily = @"nil";
|
||||
|
||||
detail = [CPString stringWithFormat:@"%@\\f%@ %@;", [fontDict objectForKey:currFont], fontFamily, currFont];
|
||||
fontlistString += detail;
|
||||
}
|
||||
|
||||
return [CPString stringWithFormat:@"{\\fonttbl%@}\n", fontlistString];
|
||||
}
|
||||
|
||||
- (CPString)colorTable
|
||||
{
|
||||
// write Colour table
|
||||
if ([colorDict count])
|
||||
{
|
||||
var result,
|
||||
count = [colorDict count],
|
||||
list = [CPMutableArray arrayWithCapacity:count],
|
||||
keyEnum = [colorDict keyEnumerator],
|
||||
next,
|
||||
i;
|
||||
|
||||
while ((next = [keyEnum nextObject]) != nil)
|
||||
{
|
||||
var cn = [colorDict objectForKey:next];
|
||||
|
||||
[list insertObject:next atIndex:[cn intValue] - 1];
|
||||
}
|
||||
|
||||
result = [CPString stringWithString:@"{\\colortbl;"];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
var color = [[list objectAtIndex:i]
|
||||
colorUsingColorSpaceName:CPCalibratedRGBColorSpace];
|
||||
|
||||
result += [CPString stringWithFormat:
|
||||
@"\\red%d\\green%d\\blue%d;",
|
||||
([color redComponent] * 255),
|
||||
([color greenComponent] * 255),
|
||||
([color blueComponent] * 255)];
|
||||
}
|
||||
|
||||
result += @"}\n";
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
if (![fontDict count])
|
||||
return @"";
|
||||
|
||||
var result,
|
||||
count = [colorDict count],
|
||||
list = [CPMutableArray arrayWithCapacity:count],
|
||||
keyEnum = [colorDict keyEnumerator],
|
||||
next,
|
||||
i;
|
||||
|
||||
while ((next = [keyEnum nextObject]) != nil)
|
||||
{
|
||||
var cn = [colorDict objectForKey:next];
|
||||
|
||||
[list insertObject:next atIndex:[cn intValue] - 1];
|
||||
}
|
||||
|
||||
result = [CPString stringWithString:@"{\\colortbl;"];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
var color = [[list objectAtIndex:i]
|
||||
colorUsingColorSpaceName:CPCalibratedRGBColorSpace];
|
||||
|
||||
result += [CPString stringWithFormat:@"\\red%d\\green%d\\blue%d;",
|
||||
([color redComponent] * 255),
|
||||
([color greenComponent] * 255),
|
||||
([color blueComponent] * 255)];
|
||||
}
|
||||
|
||||
result += @"}\n";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (CPString)documentAttributes
|
||||
{
|
||||
if (docDict != nil)
|
||||
{
|
||||
var result,
|
||||
detail,
|
||||
val,
|
||||
num;
|
||||
|
||||
result = [CPString string];
|
||||
|
||||
val = [docDict objectForKey:PAPERSIZE];
|
||||
|
||||
if (val != nil)
|
||||
{
|
||||
var size = [val sizeValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\paperw%d \\paperh%d",
|
||||
_points2twips(size.width),
|
||||
_points2twips(size.height)];
|
||||
|
||||
result += detail;
|
||||
}
|
||||
|
||||
num = [docDict objectForKey:LEFTMARGIN];
|
||||
|
||||
if (num != nil)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\margl%d", _points2twips(f)];
|
||||
result+= detail;
|
||||
}
|
||||
|
||||
num = [docDict objectForKey:RIGHTMARGIN];
|
||||
|
||||
if (num != nil)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\margr%d", _points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
|
||||
num = [docDict objectForKey:TOPMARGIN];
|
||||
|
||||
if (num != nil)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\margt%d", _points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
|
||||
num = [docDict objectForKey:BUTTOMMARGIN];
|
||||
|
||||
if (num != nil)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\margb%d", _points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
if (!docDitc)
|
||||
return @"";
|
||||
|
||||
var result,
|
||||
detail,
|
||||
val,
|
||||
num;
|
||||
|
||||
result = [CPString string];
|
||||
|
||||
val = [docDict objectForKey:PAPERSIZE];
|
||||
|
||||
if (val)
|
||||
{
|
||||
var size = [val sizeValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\paperw%d \\paperh%d",
|
||||
_points2twips(size.width),
|
||||
_points2twips(size.height)];
|
||||
|
||||
result += detail;
|
||||
}
|
||||
|
||||
num = [docDict objectForKey:LEFTMARGIN];
|
||||
|
||||
if (num)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\margl%d", _points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
|
||||
num = [docDict objectForKey:RIGHTMARGIN];
|
||||
|
||||
if (num)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\margr%d", _points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
|
||||
num = [docDict objectForKey:TOPMARGIN];
|
||||
|
||||
if (num)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\margt%d", _points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
|
||||
num = [docDict objectForKey:BUTTOMMARGIN];
|
||||
|
||||
if (num)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
|
||||
detail = [CPString stringWithFormat:@"\\margb%d", _points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (CPString)headerString
|
||||
@@ -249,7 +243,6 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
var result;
|
||||
|
||||
result = [CPString stringWithString:@"{\\rtf1\\ansi"];
|
||||
|
||||
result += [self fontTable];
|
||||
result += [self colorTable];
|
||||
result += [self documentAttributes];
|
||||
@@ -285,13 +278,10 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
if (num == nil)
|
||||
{
|
||||
cn = [colorDict count] + 1;
|
||||
|
||||
[colorDict setObject:[CPNumber numberWithInt:cn] forKey:color];
|
||||
}
|
||||
|
||||
var cn = [num intValue];
|
||||
|
||||
return cn + 1;
|
||||
return [num intValue] + 1;
|
||||
}
|
||||
|
||||
- (CPString)paragraphStyle:(CPParagraphStyle)paraStyle
|
||||
@@ -356,37 +346,35 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
if (twips != 0.0)
|
||||
headerString += [CPString stringWithFormat:@"\\sl-%d", twips];
|
||||
|
||||
// tabs
|
||||
if (1)
|
||||
{
|
||||
var enumerator,
|
||||
tab;
|
||||
var enumerator,
|
||||
tab;
|
||||
|
||||
enumerator = [[paraStyle tabStops] objectEnumerator];
|
||||
while ((tab = [enumerator nextObject]))
|
||||
enumerator = [[paraStyle tabStops] objectEnumerator];
|
||||
|
||||
while ((tab = [enumerator nextObject]))
|
||||
{
|
||||
switch ([tab tabStopType])
|
||||
{
|
||||
switch ([tab tabStopType])
|
||||
{
|
||||
case CPLeftTabStopType:
|
||||
// no tabkind emission needed
|
||||
case CPLeftTabStopType:
|
||||
// no tabkind emission needed
|
||||
break;
|
||||
/* case NSRightTabStopType:
|
||||
headerString += @"\\tqr";
|
||||
break;
|
||||
case NSCenterTabStopType:
|
||||
headerString += @"\\tqc";
|
||||
break;
|
||||
case NSDecimalTabStopType:
|
||||
headerString += @"\\tqdec";
|
||||
break;
|
||||
default:
|
||||
NSLog(@"Unknown tab stop type.");
|
||||
headerString += @"\\tqr";
|
||||
break;
|
||||
case NSCenterTabStopType:
|
||||
headerString += @"\\tqc";
|
||||
break;
|
||||
case NSDecimalTabStopType:
|
||||
headerString += @"\\tqdec";
|
||||
break;
|
||||
default:
|
||||
NSLog(@"Unknown tab stop type.");
|
||||
*/
|
||||
}
|
||||
|
||||
headerString += [CPString stringWithFormat:@"\\tx%d",_points2twips([tab location])];
|
||||
}
|
||||
}
|
||||
|
||||
return headerString;
|
||||
}
|
||||
|
||||
@@ -435,9 +423,8 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
* font name
|
||||
*/
|
||||
if (currentFont == nil || ![fontName isEqualToString:[currentFont familyName]])
|
||||
{
|
||||
headerString += [self fontToken:fontName];
|
||||
}
|
||||
|
||||
/*
|
||||
* font size
|
||||
*/
|
||||
@@ -457,6 +444,7 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
headerString += @"\\i";
|
||||
trailerString += @"\\i0";
|
||||
}
|
||||
|
||||
if (traits & CPBoldFontMask)
|
||||
{
|
||||
headerString += @"\\b";
|
||||
@@ -478,9 +466,9 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
}
|
||||
else if ([currAttrib isEqualToString:CPBackgroundColorAttributeName])
|
||||
{
|
||||
var color = [attributes objectForKey:CPBackgroundColorAttributeName];
|
||||
var color = [attributes objectForKey:CPBackgroundColorAttributeName];
|
||||
|
||||
if (![color isEqual:bgColor])
|
||||
if (![color isEqual:bgColor])
|
||||
{
|
||||
headerString += [CPString stringWithFormat:@"\\cb%d", [self numberForColor:color]];
|
||||
trailerString += @"\\cb0";
|
||||
@@ -488,8 +476,8 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
}
|
||||
else if ([currAttrib isEqualToString:CPUnderlineStyleAttributeName])
|
||||
{
|
||||
headerString += @"\\ul";
|
||||
trailerString += @"\\ulnone";
|
||||
headerString += @"\\ul";
|
||||
trailerString += @"\\ulnone";
|
||||
}
|
||||
else if ([currAttrib isEqualToString:CPSuperscriptAttributeName])
|
||||
{
|
||||
@@ -539,8 +527,8 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
substring = substring.replace(/\t/g, '\\tab');
|
||||
substring = substring.replace(/{/g, '\\{');
|
||||
substring = substring.replace(/}/g, '\\}');
|
||||
// FIXME: All characters not in the standard encoding must be
|
||||
// replaced by \'xx
|
||||
// FIXME: All characters not in the standard encoding must be
|
||||
// replaced by \'xx
|
||||
|
||||
if (!first)
|
||||
{
|
||||
@@ -551,7 +539,7 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
else
|
||||
braces = substring;
|
||||
|
||||
result += braces;
|
||||
result += braces;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -578,7 +566,7 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
completeRange = CPMakeRange(0, length),
|
||||
first = YES;
|
||||
|
||||
// FIXME <!> split along newline characters and run as outer loop
|
||||
// FIXME <!> split along newline characters and run as outer loop
|
||||
while (CPMaxRange(currRange) < CPMaxRange(completeRange)) // save all "runs"
|
||||
{
|
||||
var attributes,
|
||||
@@ -586,13 +574,12 @@ function _points2twips(a) { return (a) * 20.0; }
|
||||
runString;
|
||||
|
||||
attributes = [text attributesAtIndex:CPMaxRange(currRange)
|
||||
longestEffectiveRange:currRange
|
||||
inRange:completeRange];
|
||||
longestEffectiveRange:currRange
|
||||
inRange:completeRange];
|
||||
substring = [string substringWithRange:currRange];
|
||||
|
||||
runString = [self runStringForString:substring
|
||||
attributes:attributes
|
||||
paragraphStart:YES];
|
||||
attributes:attributes
|
||||
paragraphStart:YES];
|
||||
|
||||
result += runString;
|
||||
first = NO;
|
||||
|
||||
Reference in new issue
Block a user