mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
eliminate warnings + style
This commit is contained in:
+13
-1
@@ -22,6 +22,7 @@
|
||||
|
||||
@import <Foundation/CPObject.j>
|
||||
|
||||
@import "CPControl.j"
|
||||
@import "CPFont.j"
|
||||
@import "CPFontPanel.j"
|
||||
@import "CPFontDescriptor.j"
|
||||
@@ -74,6 +75,8 @@ CPRemoveTraitFontAction = 7;
|
||||
BOOL _multiple @accessors(getter=isMultiple, setter=setMultiple:);
|
||||
|
||||
CPDictionary _activeChange;
|
||||
|
||||
unsigned _fontAction;
|
||||
}
|
||||
|
||||
// Getting the Shared Font Manager
|
||||
@@ -98,6 +101,15 @@ CPRemoveTraitFontAction = 7;
|
||||
{
|
||||
CPFontManagerFactory = aClass;
|
||||
}
|
||||
/*!
|
||||
Sets the class that will be used to create the application's
|
||||
Font panel.
|
||||
*/
|
||||
+ (void)setFontPanelFactory:(Class)aClass
|
||||
{
|
||||
CPFontPanelFactory = aClass;
|
||||
}
|
||||
|
||||
|
||||
- (id)init
|
||||
{
|
||||
@@ -380,7 +392,7 @@ CPRemoveTraitFontAction = 7;
|
||||
break;
|
||||
|
||||
case CPAddTraitFontAction:
|
||||
newFont = [self convertFont:aFont toHaveTrait:_currentFontTrait];
|
||||
newFont = [self convertFont:aFont toHaveTrait:[self traitsOfFont:aFont]];
|
||||
break;
|
||||
|
||||
case CPSizeUpFontAction:
|
||||
|
||||
+2
-200
@@ -10,6 +10,8 @@
|
||||
* Daniel Boehringer on 8/02/2014.
|
||||
* Copyright Daniel Boehringer on 8/02/2014.
|
||||
*
|
||||
* and
|
||||
*
|
||||
* Emmanuel Maillard on 28/02/2010.
|
||||
* Copyright Emmanuel Maillard 2010.
|
||||
*
|
||||
@@ -29,13 +31,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "CPControl.j"
|
||||
|
||||
/*
|
||||
@import "RTFProducer.j"
|
||||
@import "RTFParser.j"
|
||||
*/
|
||||
|
||||
CPParagraphSeparatorCharacter = 0x2029;
|
||||
CPLineSeparatorCharacter = 0x2028;
|
||||
CPEnterCharacter = "\u0003";
|
||||
@@ -65,196 +60,3 @@ CPTextDidBeginEditingNotification = @"CPTextDidBeginEditingNotification";
|
||||
CPTextDidChangeNotification = @"CPTextDidChangeNotification";
|
||||
CPTextDidEndEditingNotification = @"CPTextDidEndEditingNotification";
|
||||
|
||||
@implementation CPText : CPControl
|
||||
{
|
||||
}
|
||||
|
||||
- (void)changeFont:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText " + _cmd + "] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)copy:(id)sender
|
||||
{
|
||||
var selectedRange = [self selectedRange];
|
||||
|
||||
if (selectedRange.length < 1)
|
||||
return;
|
||||
|
||||
var pasteboard = [CPPasteboard generalPasteboard],
|
||||
stringForPasting = [[self stringValue] substringWithRange:selectedRange];
|
||||
|
||||
[pasteboard declareTypes:[CPStringPboardType] owner:nil];
|
||||
|
||||
if ([self isRichText])
|
||||
{
|
||||
// crude hack to make rich pasting possible in chrome and firefox. this requires a RTF roundtrip, unfortunately
|
||||
var richData = [RTFProducer produceRTF:[[self textStorage] attributedSubstringFromRange:selectedRange] documentAttributes: @{}];
|
||||
[pasteboard setString:richData forType:CPStringPboardType];
|
||||
}
|
||||
else
|
||||
[pasteboard setString:stringForPasting forType:CPStringPboardType];
|
||||
|
||||
}
|
||||
- (void)paste:(id)sender
|
||||
{
|
||||
var pasteboard = [CPPasteboard generalPasteboard],
|
||||
// dataForPasting = [pasteboard dataForType:CPRichStringPboardType],
|
||||
stringForPasting = [pasteboard stringForType:CPStringPboardType];
|
||||
|
||||
if ([stringForPasting hasPrefix:"{\\rtf1\\ansi"])
|
||||
stringForPasting = [[_RTFParser new] parseRTF:stringForPasting];
|
||||
|
||||
if (![self isRichText] && [stringForPasting isKindOfClass:[CPAttributedString class]])
|
||||
stringForPasting = stringForPasting._string;
|
||||
|
||||
if (stringForPasting)
|
||||
[self insertText:stringForPasting];
|
||||
}
|
||||
|
||||
- (void)copyFont:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText " + _cmd + "] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)cut:(id)sender
|
||||
{
|
||||
[self copy:sender];
|
||||
|
||||
var loc = [self selectedRange].location;
|
||||
|
||||
[self replaceCharactersInRange:[self selectedRange] withString:""];
|
||||
[self setSelectedRange:CPMakeRange(loc,0) ];
|
||||
}
|
||||
|
||||
- (void)delete:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (CPFont)font:(CPFont)aFont
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)isHorizontallyResizable
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isRichText
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isRulerVisible
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isVerticallyResizable
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (CPSize)maxSize
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return CPMakeSize(0,0);
|
||||
}
|
||||
|
||||
- (CPSize)minSize
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return CPMakeSize(0,0);
|
||||
}
|
||||
|
||||
- (void)pasteFont:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)replaceCharactersInRange:(CPRange)aRange withString:(CPString)aString
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)scrollRangeToVisible:(CPRange)aRange
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)selectedAll:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (CPRange)selectedRange
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return CPMakeRange(CPNotFound, 0);
|
||||
}
|
||||
|
||||
- (void)setFont:(CPFont)aFont
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setFont:(CPFont)aFont rang:(CPRange)aRange
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setHorizontallyResizable:(BOOL)flag
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setMaxSize:(CPSize)aSize
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setMinSize:(CPSize)aSize
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setString:(CPString)aString
|
||||
{
|
||||
[self replaceCharactersInRange: CPMakeRange(0, [[self string] length]) withString:aString];
|
||||
}
|
||||
|
||||
- (void)setUsesFontPanel:(BOOL)flag
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setVerticallyResizable:(BOOL)flag
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (CPString)string
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)underline:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (BOOL)usesFontPanel
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -30,9 +30,11 @@
|
||||
*/
|
||||
|
||||
|
||||
@import "CPTextStorage.j"
|
||||
@import "CPFontManager.j"
|
||||
@import "CPPanel.j"
|
||||
@import "CPLayoutManager.j"
|
||||
@import "CPColorWell.j"
|
||||
@import "CPColorPanel.j"
|
||||
|
||||
/*
|
||||
Collection indexes
|
||||
@@ -69,7 +71,7 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
CPTextContainer _textContainer;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CPRect)rect
|
||||
- (id)initWithFrame:(CGRect)rect
|
||||
{
|
||||
self = [super initWithFrame:rect];
|
||||
|
||||
@@ -95,7 +97,7 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
- (void)drawRect:(CPRect)rect
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
var ctx = [[CPGraphicsContext currentContext] graphicsPort],
|
||||
glyphRange = [_layoutManager glyphRangeForTextContainer:_textContainer],
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
@import "CPTextStorage.j"
|
||||
@import "CPTextContainer.j"
|
||||
@import "CPTypesetter.j"
|
||||
@import "CPTextView.j"
|
||||
|
||||
function _RectEqualToRectHorizontally(lhsRect, rhsRect)
|
||||
{
|
||||
@@ -918,100 +918,9 @@ var _objectsInRange = function(aList, aRange)
|
||||
[tempAttributes._attributes addEntriesFromDictionary:attributes];
|
||||
}
|
||||
|
||||
// i did not touch this monster (yet)
|
||||
- (void)_handleTemporaryAttributes:(CPDictionary)attributes forCharacterRange:(CPRange)charRange withSelector:(SEL)attributesOperation
|
||||
{
|
||||
if (!_temporaryAttributes)
|
||||
_temporaryAttributes = [[CPMutableArray alloc] init];
|
||||
|
||||
var location = charRange.location,
|
||||
length = 0,
|
||||
dirtyRange = nil;
|
||||
|
||||
while (length != charRange.length)
|
||||
{
|
||||
var tempAttributesIndex = [_temporaryAttributes indexOfObject: location sortedByFunction:_sortRange context:nil];
|
||||
|
||||
if (tempAttributesIndex != CPNotFound)
|
||||
{
|
||||
var tempAttributes = _temporaryAttributes[tempAttributesIndex];
|
||||
|
||||
if (CPRangeInRange(charRange, tempAttributes._range))
|
||||
{
|
||||
[self performSelector:attributesOperation withObject:attributes withObject:tempAttributes];
|
||||
dirtyRange = (dirtyRange)?CPUnionRange(dirtyRange, tempAttributes._range):CPMakeRangeCopy(tempAttributes._range);
|
||||
location += tempAttributes._range.length;
|
||||
length += tempAttributes._range.length;
|
||||
}
|
||||
else if (location == tempAttributes._range.location && CPMaxRange(tempAttributes._range) > CPMaxRange(charRange))
|
||||
{
|
||||
var maxRange = CPMaxRange(charRange),
|
||||
splittedAttribute = [[_CPTemporaryAttributes alloc] initWithRange:CPMakeRange(maxRange, CPMaxRange(tempAttributes._range) - maxRange)
|
||||
attributes:[tempAttributes._attributes copy]];
|
||||
|
||||
if ([_temporaryAttributes count] == tempAttributesIndex + 1)
|
||||
[_temporaryAttributes addObject:splittedAttribute];
|
||||
else
|
||||
[_temporaryAttributes insertObject:splittedAttribute atIndex:tempAttributesIndex + 1];
|
||||
|
||||
tempAttributes._range = CPMakeRange(tempAttributes._range.location, maxRange - tempAttributes._range.location);
|
||||
[self performSelector:attributesOperation withObject:attributes withObject:tempAttributes];
|
||||
|
||||
location += tempAttributes._range.length;
|
||||
length += tempAttributes._range.length;
|
||||
|
||||
dirtyRange = (dirtyRange)?CPUnionRange(dirtyRange, tempAttributes._range):CPMakeRangeCopy(tempAttributes._range);
|
||||
dirtyRange = CPUnionRange(dirtyRange, splittedAttribute._range);
|
||||
}
|
||||
else
|
||||
{
|
||||
var splittedAttribute = [[_CPTemporaryAttributes alloc] initWithRange:CPMakeRange(location, CPMaxRange(tempAttributes._range) - location)
|
||||
attributes:[tempAttributes._attributes copy]];
|
||||
|
||||
if ([_temporaryAttributes count] == tempAttributesIndex + 1)
|
||||
[_temporaryAttributes addObject:splittedAttribute];
|
||||
else
|
||||
[_temporaryAttributes insertObject:splittedAttribute atIndex:tempAttributesIndex + 1];
|
||||
|
||||
tempAttributes._range = CPMakeRange(tempAttributes._range.location, location - tempAttributes._range.location);
|
||||
dirtyRange = (dirtyRange)?CPUnionRange(dirtyRange, tempAttributes._range):CPMakeRangeCopy(tempAttributes._range);
|
||||
dirtyRange = CPUnionRange(dirtyRange, splittedAttribute._range);
|
||||
|
||||
if (splittedAttribute._range.length <= charRange.length)
|
||||
{
|
||||
location += splittedAttribute._range.length;
|
||||
length += splittedAttribute._range.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
var nextLocation = location + charRange.length,
|
||||
nextAttribute = [[_CPTemporaryAttributes alloc] initWithRange:CPMakeRange(nextLocation, CPMaxRange(splittedAttribute._range) - nextLocation)
|
||||
attributes:[tempAttributes._attributes copy]];
|
||||
|
||||
splittedAttribute._range = CPMakeRange(splittedAttribute._range.location, nextLocation - splittedAttribute._range.location);
|
||||
|
||||
var insertIndex = [_temporaryAttributes indexOfObject:splittedAttribute];
|
||||
|
||||
if ([_temporaryAttributes count] == insertIndex + 1)
|
||||
[_temporaryAttributes addObject:nextAttribute];
|
||||
else
|
||||
[_temporaryAttributes insertObject:nextAttribute atIndex:insertIndex + 1];
|
||||
|
||||
length = charRange.length;
|
||||
}
|
||||
[self performSelector:attributesOperation withObject:attributes withObject:splittedAttribute];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[_temporaryAttributes addObject:[[_CPTemporaryAttributes alloc] initWithRange:charRange attributes:attributes]];
|
||||
dirtyRange = CPMakeRangeCopy(charRange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dirtyRange)
|
||||
[self invalidateDisplayForGlyphRange:dirtyRange];
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (void)setTemporaryAttributes:(CPDictionary)attributes forCharacterRange:(CPRange)charRange
|
||||
@@ -1024,126 +933,19 @@ var _objectsInRange = function(aList, aRange)
|
||||
[self _handleTemporaryAttributes:attributes forCharacterRange:charRange withSelector:@selector(_addAttributes:toTemporaryAttributes:)];
|
||||
}
|
||||
|
||||
// i did not touch this monster (yet)
|
||||
- (void)removeTemporaryAttribute:(CPString)attributeName forCharacterRange:(CPRange)charRange
|
||||
{
|
||||
if (!_temporaryAttributes)
|
||||
return;
|
||||
|
||||
var location = charRange.location,
|
||||
length = 0,
|
||||
dirtyRange = nil;
|
||||
while (length != charRange.length)
|
||||
{
|
||||
var tempAttributesIndex = [_temporaryAttributes indexOfObject: location sortedByFunction:_sortRange context:nil];
|
||||
|
||||
if (tempAttributesIndex != CPNotFound)
|
||||
{
|
||||
var tempAttributes = _temporaryAttributes[tempAttributesIndex];
|
||||
|
||||
if (CPRangeInRange(charRange, tempAttributes._range))
|
||||
{
|
||||
location += tempAttributes._range.length;
|
||||
length += tempAttributes._range.length;
|
||||
dirtyRange = (dirtyRange)?CPUnionRange(dirtyRange, tempAttributes._range):CPMakeRangeCopy(tempAttributes._range);
|
||||
|
||||
[tempAttributes._attributes removeObjectForKey:attributeName];
|
||||
|
||||
if ([[tempAttributes._attributes allKeys] count] == 0)
|
||||
[_temporaryAttributes removeObjectAtIndex:tempAttributesIndex];
|
||||
}
|
||||
else if (location == tempAttributes._range.location && CPMaxRange(tempAttributes._range) > CPMaxRange(charRange))
|
||||
{
|
||||
var maxRange = CPMaxRange(charRange),
|
||||
splittedAttribute = [[_CPTemporaryAttributes alloc] initWithRange:CPMakeRange(maxRange, CPMaxRange(tempAttributes._range) - maxRange)
|
||||
attributes:[tempAttributes._attributes copy]];
|
||||
|
||||
if ([_temporaryAttributes count] == tempAttributesIndex + 1)
|
||||
[_temporaryAttributes addObject:splittedAttribute];
|
||||
else
|
||||
[_temporaryAttributes insertObject:splittedAttribute atIndex:tempAttributesIndex + 1];
|
||||
|
||||
tempAttributes._range = CPMakeRange(tempAttributes._range.location, maxRange - tempAttributes._range.location);
|
||||
location += tempAttributes._range.length;
|
||||
length += tempAttributes._range.length;
|
||||
|
||||
[tempAttributes._attributes removeObjectForKey:attributeName];
|
||||
if ([[tempAttributes._attributes allKeys] count] == 0)
|
||||
[_temporaryAttributes removeObjectAtIndex:tempAttributesIndex];
|
||||
|
||||
dirtyRange = (dirtyRange)?CPUnionRange(dirtyRange, tempAttributes._range):CPMakeRangeCopy(tempAttributes._range);
|
||||
dirtyRange = CPUnionRange(dirtyRange, splittedAttribute._range);
|
||||
}
|
||||
else
|
||||
{
|
||||
var splittedAttribute = [[_CPTemporaryAttributes alloc] initWithRange:CPMakeRange(location, CPMaxRange(tempAttributes._range) - location)
|
||||
attributes:[tempAttributes._attributes copy]];
|
||||
|
||||
if ([_temporaryAttributes count] == tempAttributesIndex + 1)
|
||||
[_temporaryAttributes addObject:splittedAttribute];
|
||||
else
|
||||
[_temporaryAttributes insertObject:splittedAttribute atIndex:tempAttributesIndex + 1];
|
||||
|
||||
tempAttributes._range = CPMakeRange(tempAttributes._range.location, location - tempAttributes._range.location);
|
||||
|
||||
dirtyRange = (dirtyRange)?CPUnionRange(dirtyRange, tempAttributes._range):CPMakeRangeCopy(tempAttributes._range);
|
||||
dirtyRange = CPUnionRange(dirtyRange, splittedAttribute._range);
|
||||
|
||||
if (splittedAttribute._range.length < charRange.length)
|
||||
{
|
||||
location += splittedAttribute._range.length;
|
||||
length += splittedAttribute._range.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
var nextLocation = location + charRange.length,
|
||||
nextAttribute = [[_CPTemporaryAttributes alloc] initWithRange:CPMakeRange(nextLocation, CPMaxRange(splittedAttribute._range) - nextLocation)
|
||||
attributes:[tempAttributes._attributes copy]];
|
||||
|
||||
splittedAttribute._range = CPMakeRange(splittedAttribute._range.location, nextLocation - splittedAttribute._range.location);
|
||||
var insertIndex = [_temporaryAttributes indexOfObject:splittedAttribute];
|
||||
|
||||
if ([_temporaryAttributes count] == insertIndex + 1)
|
||||
[_temporaryAttributes addObject:nextAttribute];
|
||||
else
|
||||
[_temporaryAttributes insertObject:nextAttribute atIndex:insertIndex + 1];
|
||||
|
||||
length = charRange.length;
|
||||
}
|
||||
|
||||
[splittedAttribute._attributes removeObjectForKey:attributeName];
|
||||
if ([[splittedAttribute._attributes allKeys] count] == 0)
|
||||
[_temporaryAttributes removeObject:splittedAttribute];
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (dirtyRange)
|
||||
[self invalidateDisplayForGlyphRange:dirtyRange];
|
||||
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (CPDictionary)temporaryAttributesAtCharacterIndex:(unsigned)index effectiveRange:(CPRangePointer)effectiveRange
|
||||
{
|
||||
var tempAttribute = _objectWithLocationInRange(_runs, index); // <!> _runs is wild guess
|
||||
|
||||
if (!tempAttribute)
|
||||
return nil;
|
||||
|
||||
if (effectiveRange)
|
||||
{
|
||||
effectiveRange.location = tempAttribute._range.location;
|
||||
effectiveRange.length = tempAttribute._range.length;
|
||||
}
|
||||
|
||||
return tempAttribute._attributes;
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (void)textContainerChangedTextView:(CPTextContainer)aContainer
|
||||
{
|
||||
/* FIXME: stub */
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (CPTypesetter)typesetter
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
@import <Foundation/CPObject.j>
|
||||
@import "CPText.j"
|
||||
@import "CPControl.j"
|
||||
|
||||
var _sharedDefaultParagraphStyle,
|
||||
_defaultTabStopArray;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import <Foundation/CPGeometry.j>
|
||||
@import "CPLayoutManager.j"
|
||||
|
||||
/*
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
*/
|
||||
|
||||
|
||||
//@import <Foundation/CPAttributedString.j>
|
||||
@import <Foundation/CPNotificationCenter.j>
|
||||
@import <Foundation/CPAttributedString.j>
|
||||
@import "CPLayoutManager.j"
|
||||
|
||||
|
||||
@@ -226,7 +227,7 @@ CPKernAttributeName = @"CPKernAttributeName";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeAttribute:(id)anAttribute range:(CPRange)aRange
|
||||
- (void)removeAttribute:(CPString)anAttribute range:(CPRange)aRange
|
||||
{
|
||||
[self beginEditing];
|
||||
[super removeAttribute:anAttribute range:aRange];
|
||||
|
||||
+210
-12
@@ -24,11 +24,12 @@
|
||||
*/
|
||||
|
||||
@import "CPText.j"
|
||||
@import "CPParagraphStyle.j"
|
||||
@import "CPTextStorage.j"
|
||||
@import "CPTextContainer.j"
|
||||
@import "CPLayoutManager.j"
|
||||
@import "CPFontManager.j"
|
||||
@import "_CPRTFProducer.j"
|
||||
@import "_CPRTFParser.j"
|
||||
@import "CPLayoutManager.j"
|
||||
|
||||
_MakeRangeFromAbs = function(a1, a2)
|
||||
{
|
||||
@@ -74,6 +75,203 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
kDelegateRespondsTo_textView_shouldChangeTextInRange_replacementString = 0x0008,
|
||||
kDelegateRespondsTo_textView_shouldChangeTypingAttributes_toAttributes = 0x0010;
|
||||
|
||||
|
||||
|
||||
@implementation CPText : CPControl
|
||||
{
|
||||
}
|
||||
|
||||
- (void)changeFont:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText " + _cmd + "] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)copy:(id)sender
|
||||
{
|
||||
var selectedRange = [self selectedRange];
|
||||
|
||||
if (selectedRange.length < 1)
|
||||
return;
|
||||
|
||||
var pasteboard = [CPPasteboard generalPasteboard],
|
||||
stringForPasting = [[self stringValue] substringWithRange:selectedRange];
|
||||
|
||||
[pasteboard declareTypes:[CPStringPboardType] owner:nil];
|
||||
|
||||
if ([self isRichText])
|
||||
{
|
||||
// crude hack to make rich pasting possible in chrome and firefox. this requires a RTF roundtrip, unfortunately
|
||||
var richData = [_CPRTFProducer produceRTF:[[self textStorage] attributedSubstringFromRange:selectedRange] documentAttributes: @{}];
|
||||
[pasteboard setString:richData forType:CPStringPboardType];
|
||||
}
|
||||
else
|
||||
[pasteboard setString:stringForPasting forType:CPStringPboardType];
|
||||
|
||||
}
|
||||
- (void)paste:(id)sender
|
||||
{
|
||||
var pasteboard = [CPPasteboard generalPasteboard],
|
||||
// dataForPasting = [pasteboard dataForType:CPRichStringPboardType],
|
||||
stringForPasting = [pasteboard stringForType:CPStringPboardType];
|
||||
|
||||
if ([stringForPasting hasPrefix:"{\\rtf1\\ansi"])
|
||||
stringForPasting = [[_CPRTFParser new] parseRTF:stringForPasting];
|
||||
|
||||
if (![self isRichText] && [stringForPasting isKindOfClass:[CPAttributedString class]])
|
||||
stringForPasting = stringForPasting._string;
|
||||
|
||||
if (stringForPasting)
|
||||
[self insertText:stringForPasting];
|
||||
}
|
||||
|
||||
- (void)copyFont:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText " + _cmd + "] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)cut:(id)sender
|
||||
{
|
||||
[self copy:sender];
|
||||
|
||||
var loc = [self selectedRange].location;
|
||||
|
||||
[self replaceCharactersInRange:[self selectedRange] withString:""];
|
||||
[self setSelectedRange:CPMakeRange(loc,0) ];
|
||||
}
|
||||
|
||||
- (void)delete:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (CPFont)font:(CPFont)aFont
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)isHorizontallyResizable
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isRichText
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isRulerVisible
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isVerticallyResizable
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (CPSize)maxSize
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return CPMakeSize(0,0);
|
||||
}
|
||||
|
||||
- (CPSize)minSize
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return CPMakeSize(0,0);
|
||||
}
|
||||
|
||||
- (void)pasteFont:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)replaceCharactersInRange:(CPRange)aRange withString:(CPString)aString
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)scrollRangeToVisible:(CPRange)aRange
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)selectedAll:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (CPRange)selectedRange
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return CPMakeRange(CPNotFound, 0);
|
||||
}
|
||||
|
||||
- (void)setFont:(CPFont)aFont
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setFont:(CPFont)aFont rang:(CPRange)aRange
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setHorizontallyResizable:(BOOL)flag
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setMaxSize:(CPSize)aSize
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setMinSize:(CPSize)aSize
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setString:(CPString)aString
|
||||
{
|
||||
[self replaceCharactersInRange: CPMakeRange(0, [[self string] length]) withString:aString];
|
||||
}
|
||||
|
||||
- (void)setUsesFontPanel:(BOOL)flag
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (void)setVerticallyResizable:(BOOL)flag
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (CPString)string
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)underline:(id)sender
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
}
|
||||
|
||||
- (BOOL)usesFontPanel
|
||||
{
|
||||
CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility");
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/*!
|
||||
@ingroup appkit
|
||||
@class CPTextView
|
||||
@@ -127,13 +325,13 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
int _stickyXLocation;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CPRect)aFrame textContainer:(CPTextContainer)aContainer
|
||||
- (id)initWithFrame:(CGRect)aFrame textContainer:(CPTextContainer)aContainer
|
||||
{
|
||||
self = [super initWithFrame:aFrame];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_DOMElement.style.cursor = "text";
|
||||
self._DOMElement.style.cursor = "text";
|
||||
_textContainerInset = CPSizeMake(2,0);
|
||||
_textContainerOrigin = CPPointMake(_bounds.origin.x, _bounds.origin.y);
|
||||
[aContainer setTextView:self];
|
||||
@@ -202,7 +400,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
[[[self window] undoManager] redo];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CPRect)aFrame
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
{
|
||||
var layoutManager = [[CPLayoutManager alloc] init],
|
||||
textStorage = [[CPTextStorage alloc] init],
|
||||
@@ -403,7 +601,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
- (void)insertText:(id)aString
|
||||
- (void)insertText:(CPString)aString
|
||||
{
|
||||
var isAttributed = [aString isKindOfClass:CPAttributedString],
|
||||
string = (isAttributed)?[aString string]:aString;
|
||||
@@ -454,7 +652,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
[self setNeedsDisplayInRect:_caretRect];
|
||||
}
|
||||
|
||||
- (void)drawRect:(CPRect)aRect
|
||||
- (void)drawRect:(CGRect)aRect
|
||||
{
|
||||
var ctx = [[CPGraphicsContext currentContext] graphicsPort],
|
||||
range = [_layoutManager glyphRangeForBoundingRect:aRect inTextContainer:_textContainer];
|
||||
@@ -1188,7 +1386,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
[self deleteBackward: sender];
|
||||
}
|
||||
|
||||
- stringValue
|
||||
- (CPString)stringValue
|
||||
{
|
||||
return _textStorage._string;
|
||||
}
|
||||
@@ -1297,7 +1495,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
|
||||
- (void)setUsesFontPanel:(BOOL)flag
|
||||
{
|
||||
_usesFontPanel = flags;
|
||||
_usesFontPanel = flag;
|
||||
}
|
||||
|
||||
- (BOOL)usesFontPanel
|
||||
@@ -1415,7 +1613,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
_minSize = aSize;
|
||||
}
|
||||
|
||||
- (void)setConstrainedFrameSize:(CPSize)desiredSize
|
||||
- (void)setConstrainedFrameSize:(CGSize)desiredSize
|
||||
{
|
||||
[self setFrameSize:desiredSize];
|
||||
}
|
||||
@@ -1426,7 +1624,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
|
||||
}
|
||||
|
||||
- (void)setFrameSize:(CPSize) aSize
|
||||
- (void)setFrameSize:(CGSize) aSize
|
||||
{
|
||||
var minSize = [self minSize],
|
||||
maxSize = [self maxSize],
|
||||
@@ -1636,7 +1834,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
return (_selectionRange.length === 0 && [self _isFocused])
|
||||
}
|
||||
|
||||
- (void)drawInsertionPointInRect:(CPRect)aRect color:(CPColor)aColor turnedOn:(BOOL)flag
|
||||
- (void)drawInsertionPointInRect:(CGRect)aRect color:(CPColor)aColor turnedOn:(BOOL)flag
|
||||
{
|
||||
var style;
|
||||
if (!_caretDOM)
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
*/
|
||||
|
||||
@import <Foundation/CPObject.j>
|
||||
@import "CPTextStorage.j"
|
||||
@import "CPParagraphStyle.j"
|
||||
@import "CPTextStorage.j"
|
||||
|
||||
/*
|
||||
CPTypesetterControlCharacterAction
|
||||
@@ -110,7 +110,7 @@ var CPSystemTypesetterFactory = Nil;
|
||||
- (void)layoutGlyphsInLayoutManager:(CPLayoutManager)layoutManager
|
||||
startingAtGlyphIndex:(unsigned)startGlyphIndex
|
||||
maxNumberOfLineFragments:(unsigned)maxNumLines
|
||||
nextGlyphIndex:(UIntegerPointer)nextGlyph
|
||||
nextGlyphIndex:(UIntegerReference)nextGlyph
|
||||
{
|
||||
CPLog.error(@"-[CPTypesetter subclass responsibility");
|
||||
}
|
||||
|
||||
@@ -25,8 +25,9 @@ e.g. using zaach/jison on github
|
||||
*/
|
||||
|
||||
@import <Foundation/CPAttributedString.j>
|
||||
@import "CPControl.j"
|
||||
@import <Foundation/CPGeometry.j>
|
||||
@import "CPControl.j"
|
||||
@import "CPFontManager.j"
|
||||
|
||||
var hexTable = [];
|
||||
|
||||
@@ -87,20 +88,14 @@ var hexTable = [];
|
||||
{
|
||||
var fontFamily = [fontName substringToIndex: range.location];
|
||||
|
||||
font = [[CPFontManager sharedFontManager] fontWithFamily: fontFamily
|
||||
traits: traits
|
||||
weight: weight
|
||||
size: fontSize];
|
||||
font = [CPFont fontWithName:fontFamily size:fontSize];
|
||||
}
|
||||
|
||||
if (font == nil)
|
||||
{
|
||||
console.log(@"RTFParser",
|
||||
@"Could not find font %@ size %f traits %d weight %d",
|
||||
fontName, fontSize, traits, weight);
|
||||
|
||||
/* Last resort, default font. :-( */
|
||||
font = [CPFont systemFontOfSize: fontSize];
|
||||
font = [CPFont systemFontOfSize:fontSize];
|
||||
}
|
||||
}
|
||||
return font;
|
||||
@@ -258,7 +253,7 @@ var kRgsymRtf = {
|
||||
"\\" : [ "\\", 0, false, kRTFParserType_char, '\\']
|
||||
}
|
||||
|
||||
@implementation _RTFParser : CPObject
|
||||
@implementation _CPRTFParser : CPObject
|
||||
{
|
||||
CPString _codePage;
|
||||
CPSize _paper;
|
||||
@@ -23,9 +23,11 @@
|
||||
*/
|
||||
|
||||
@import <Foundation/CPAttributedString.j>
|
||||
@import "CPFont.j"
|
||||
@import "CPParagraphStyle.j"
|
||||
@import "CPColor.j"
|
||||
@import "CPGraphics.j"
|
||||
@import "CPTextStorage.j"
|
||||
@import "CPFontManager.j"
|
||||
|
||||
|
||||
var PAPERSIZE = @"PaperSize";
|
||||
@@ -34,12 +36,10 @@ var RIGHTMARGIN = @"RightMargin";
|
||||
var TOPMARGIN = @"TopMargin";
|
||||
var BUTTOMMARGIN = @"ButtomMargin";
|
||||
|
||||
CPISOLatin1StringEncoding = "CPISOLatin1StringEncoding";
|
||||
|
||||
function _points2twips(a) { return (a)*20.0; }
|
||||
|
||||
|
||||
@implementation RTFProducer:CPObject
|
||||
@implementation _CPRTFProducer:CPObject
|
||||
{
|
||||
CPAttributedString text;
|
||||
CPMutableDictionary fontDict;
|
||||
@@ -53,13 +53,13 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
CPColor ulColor;
|
||||
}
|
||||
|
||||
+ (CPString)produceRTF: (CPAttributedString) aText documentAttributes: (CPDictionary)dict
|
||||
+ (CPString)produceRTF:(CPAttributedString) aText documentAttributes:(CPDictionary)dict
|
||||
{
|
||||
var mynew = [self new],
|
||||
data;
|
||||
|
||||
return [mynew RTFDStringFromAttributedString: aText
|
||||
documentAttributes: dict];
|
||||
return [mynew RTFDStringFromAttributedString:aText
|
||||
documentAttributes:dict];
|
||||
}
|
||||
|
||||
- (id)init
|
||||
@@ -94,7 +94,7 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
var keyArray;
|
||||
|
||||
keyArray = [fontDict allKeys];
|
||||
keyArray = [keyArray sortedArrayUsingSelector: @selector(compare:)];
|
||||
keyArray = [keyArray sortedArrayUsingSelector:@selector(compare:)];
|
||||
|
||||
fontEnum = [keyArray objectEnumerator];
|
||||
while ((currFont = [fontEnum nextObject]) !== nil)
|
||||
@@ -102,23 +102,23 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
var fontFamily;
|
||||
var detail;
|
||||
|
||||
if ([currFont isEqualToString: @"Symbol"])
|
||||
if ([currFont isEqualToString:@"Symbol"])
|
||||
fontFamily = @"tech";
|
||||
else if ([currFont isEqualToString: @"Helvetica"])
|
||||
else if ([currFont isEqualToString:@"Helvetica"])
|
||||
fontFamily = @"swiss";
|
||||
else if ([currFont isEqualToString: @"Arial"])
|
||||
else if ([currFont isEqualToString:@"Arial"])
|
||||
fontFamily = @"swiss";
|
||||
else if ([currFont isEqualToString: @"Courier"])
|
||||
else if ([currFont isEqualToString:@"Courier"])
|
||||
fontFamily = @"modern";
|
||||
else if ([currFont isEqualToString: @"Times"])
|
||||
else if ([currFont isEqualToString:@"Times"])
|
||||
fontFamily = @"roman";
|
||||
else fontFamily = @"nil";
|
||||
|
||||
detail = [CPString stringWithFormat: @"%@\\f%@ %@;",
|
||||
[fontDict objectForKey: currFont], fontFamily, currFont];
|
||||
detail = [CPString stringWithFormat:@"%@\\f%@ %@;",
|
||||
[fontDict objectForKey:currFont], fontFamily, currFont];
|
||||
fontlistString += detail;
|
||||
}
|
||||
return [CPString stringWithFormat: @"{\\fonttbl%@}\n", fontlistString];
|
||||
return [CPString stringWithFormat:@"{\\fonttbl%@}\n", fontlistString];
|
||||
}
|
||||
else
|
||||
return @"";
|
||||
@@ -131,22 +131,22 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
{
|
||||
var result,
|
||||
count = [colorDict count],
|
||||
list = [CPMutableArray arrayWithCapacity: 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];
|
||||
var cn = [colorDict objectForKey:next];
|
||||
[list insertObject:next atIndex:[cn intValue]-1];
|
||||
}
|
||||
|
||||
result = [CPString stringWithString: @"{\\colortbl;"];
|
||||
result = [CPString stringWithString:@"{\\colortbl;"];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
var color = [[list objectAtIndex: i]
|
||||
colorUsingColorSpaceName: CPCalibratedRGBColorSpace];
|
||||
var color = [[list objectAtIndex:i]
|
||||
colorUsingColorSpaceName:CPCalibratedRGBColorSpace];
|
||||
result += [CPString stringWithFormat:
|
||||
@"\\red%d\\green%d\\blue%d;",
|
||||
([color redComponent]*255),
|
||||
@@ -172,45 +172,45 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
|
||||
result = [CPString string];
|
||||
|
||||
val = [docDict objectForKey: PAPERSIZE];
|
||||
val = [docDict objectForKey:PAPERSIZE];
|
||||
if (val != nil)
|
||||
{
|
||||
var size = [val sizeValue];
|
||||
detail = [CPString stringWithFormat: @"\\paperw%d \\paperh%d",
|
||||
detail = [CPString stringWithFormat:@"\\paperw%d \\paperh%d",
|
||||
_points2twips(size.width),
|
||||
_points2twips(size.height)];
|
||||
result += detail;
|
||||
}
|
||||
|
||||
num = [docDict objectForKey: LEFTMARGIN];
|
||||
num = [docDict objectForKey:LEFTMARGIN];
|
||||
if (num != nil)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
detail = [CPString stringWithFormat: @"\\margl%d",
|
||||
detail = [CPString stringWithFormat:@"\\margl%d",
|
||||
_points2twips(f)];
|
||||
result+= detail;
|
||||
}
|
||||
num = [docDict objectForKey: RIGHTMARGIN];
|
||||
num = [docDict objectForKey:RIGHTMARGIN];
|
||||
if (num != nil)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
detail = [CPString stringWithFormat: @"\\margr%d",
|
||||
detail = [CPString stringWithFormat:@"\\margr%d",
|
||||
_points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
num = [docDict objectForKey: TOPMARGIN];
|
||||
num = [docDict objectForKey:TOPMARGIN];
|
||||
if (num != nil)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
detail = [CPString stringWithFormat: @"\\margt%d",
|
||||
detail = [CPString stringWithFormat:@"\\margt%d",
|
||||
_points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
num = [docDict objectForKey: BUTTOMMARGIN];
|
||||
num = [docDict objectForKey:BUTTOMMARGIN];
|
||||
if (num != nil)
|
||||
{
|
||||
var f = [num floatValue];
|
||||
detail = [CPString stringWithFormat: @"\\margb%d",
|
||||
detail = [CPString stringWithFormat:@"\\margb%d",
|
||||
_points2twips(f)];
|
||||
result += detail;
|
||||
}
|
||||
@@ -225,7 +225,7 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
{
|
||||
var result;
|
||||
|
||||
result = [CPString stringWithString: @"{\\rtf1\\ansi"];
|
||||
result = [CPString stringWithString:@"{\\rtf1\\ansi"];
|
||||
|
||||
result += [self fontTable];
|
||||
result += [self colorTable];
|
||||
@@ -239,39 +239,39 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
return @"}";
|
||||
}
|
||||
|
||||
- (CPString)fontToken: (CPString) fontName
|
||||
- (CPString)fontToken:(CPString) fontName
|
||||
{
|
||||
var fCount = [fontDict objectForKey: fontName];
|
||||
var fCount = [fontDict objectForKey:fontName];
|
||||
|
||||
if (fCount == nil)
|
||||
{
|
||||
var count = [fontDict count];
|
||||
|
||||
fCount = [CPString stringWithFormat: @"\\f%d", count];
|
||||
[fontDict setObject: fCount forKey: fontName];
|
||||
fCount = [CPString stringWithFormat:@"\\f%d", count];
|
||||
[fontDict setObject:fCount forKey:fontName];
|
||||
}
|
||||
|
||||
return fCount;
|
||||
}
|
||||
|
||||
- (int)numberForColor: (CPColor)color
|
||||
- (int)numberForColor:(CPColor)color
|
||||
{
|
||||
var cn,
|
||||
num = [colorDict objectForKey: color];
|
||||
num = [colorDict objectForKey:color];
|
||||
|
||||
if (num == nil)
|
||||
{
|
||||
cn = [colorDict count] + 1;
|
||||
|
||||
[colorDict setObject: [CPNumber numberWithInt: cn]
|
||||
forKey: color];
|
||||
[colorDict setObject:[CPNumber numberWithInt:cn]
|
||||
forKey:color];
|
||||
}
|
||||
var cn = [num intValue];
|
||||
|
||||
return cn + 1;
|
||||
}
|
||||
|
||||
- (CPString) paragraphStyle: (CPParagraphStyle) paraStyle
|
||||
- (CPString) paragraphStyle:(CPParagraphStyle) paraStyle
|
||||
{
|
||||
var headerString = [CPString stringWithString:@"\\pard\\plain"],
|
||||
twips;
|
||||
@@ -327,7 +327,7 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
twips = _points2twips([paraStyle maximumLineHeight]);
|
||||
if (twips != 0.0)
|
||||
{
|
||||
headerString += [CPString stringWithFormat: @"\\sl-%d", twips];
|
||||
headerString += [CPString stringWithFormat:@"\\sl-%d", twips];
|
||||
}
|
||||
// tabs
|
||||
if (1)
|
||||
@@ -363,9 +363,9 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
return headerString;
|
||||
}
|
||||
|
||||
- (CPString) runStringForString: (CPString) substring
|
||||
attributes: (CPDictionary) attributes
|
||||
paragraphStart: (BOOL) first
|
||||
- (CPString) runStringForString:(CPString) substring
|
||||
attributes:(CPDictionary) attributes
|
||||
paragraphStart:(BOOL) first
|
||||
{
|
||||
var result = "",
|
||||
headerString = "",
|
||||
@@ -376,7 +376,7 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
if (first)
|
||||
{
|
||||
var paraStyle = [attributes objectForKey:CPParagraphStyleAttributeName];
|
||||
headerString += [self paragraphStyle: paraStyle];
|
||||
headerString += [self paragraphStyle:paraStyle];
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -390,7 +390,7 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
attribEnum = [attributes keyEnumerator];
|
||||
while ((currAttrib = [attribEnum nextObject]) != nil)
|
||||
{
|
||||
if ([currAttrib isEqualToString: CPFontAttributeName])
|
||||
if ([currAttrib isEqualToString:CPFontAttributeName])
|
||||
{
|
||||
/*
|
||||
* handle fonts
|
||||
@@ -399,17 +399,17 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
fontName,
|
||||
traits;
|
||||
|
||||
font = [attributes objectForKey: CPFontAttributeName];
|
||||
font = [attributes objectForKey:CPFontAttributeName];
|
||||
fontName = [font familyName];
|
||||
traits = [[CPFontManager sharedFontManager] traitsOfFont: font];
|
||||
traits = [[CPFontManager sharedFontManager] traitsOfFont:font];
|
||||
|
||||
/*
|
||||
* font name
|
||||
*/
|
||||
if (currentFont == nil ||
|
||||
![fontName isEqualToString: [currentFont familyName]])
|
||||
![fontName isEqualToString:[currentFont familyName]])
|
||||
{
|
||||
headerString += [self fontToken: fontName];
|
||||
headerString += [self fontToken:fontName];
|
||||
}
|
||||
/*
|
||||
* font size
|
||||
@@ -420,7 +420,7 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
var points =[font size]*2,
|
||||
pString;
|
||||
|
||||
pString = [CPString stringWithFormat: @"\\fs%d", points];
|
||||
pString = [CPString stringWithFormat:@"\\fs%d", points];
|
||||
headerString += pString;
|
||||
}
|
||||
/*
|
||||
@@ -440,32 +440,32 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
if (first)
|
||||
currentFont = font;
|
||||
}
|
||||
else if ([currAttrib isEqualToString: CPForegroundColorAttributeName])
|
||||
else if ([currAttrib isEqualToString:CPForegroundColorAttributeName])
|
||||
{
|
||||
var color = [attributes objectForKey: CPForegroundColorAttributeName];
|
||||
if (![color isEqual: fgColor])
|
||||
var color = [attributes objectForKey:CPForegroundColorAttributeName];
|
||||
if (![color isEqual:fgColor])
|
||||
{
|
||||
headerString += [CPString stringWithFormat:@"\\cf%d", [self numberForColor:color]];
|
||||
trailerString += @"\\cf0";
|
||||
}
|
||||
}
|
||||
else if ([currAttrib isEqualToString: CPBackgroundColorAttributeName])
|
||||
else if ([currAttrib isEqualToString:CPBackgroundColorAttributeName])
|
||||
{
|
||||
var color = [attributes objectForKey: CPBackgroundColorAttributeName];
|
||||
if (![color isEqual: bgColor])
|
||||
var color = [attributes objectForKey:CPBackgroundColorAttributeName];
|
||||
if (![color isEqual:bgColor])
|
||||
{
|
||||
headerString += [CPString stringWithFormat:@"\\cb%d", [self numberForColor: color]];
|
||||
headerString += [CPString stringWithFormat:@"\\cb%d", [self numberForColor:color]];
|
||||
trailerString += @"\\cb0";
|
||||
}
|
||||
}
|
||||
else if ([currAttrib isEqualToString: CPUnderlineStyleAttributeName])
|
||||
else if ([currAttrib isEqualToString:CPUnderlineStyleAttributeName])
|
||||
{
|
||||
headerString += @"\\ul";
|
||||
trailerString += @"\\ulnone";
|
||||
}
|
||||
else if ([currAttrib isEqualToString: CPSuperscriptAttributeName])
|
||||
else if ([currAttrib isEqualToString:CPSuperscriptAttributeName])
|
||||
{
|
||||
var value = [attributes objectForKey: CPSuperscriptAttributeName],
|
||||
var value = [attributes objectForKey:CPSuperscriptAttributeName],
|
||||
svalue = [value intValue] * 6;
|
||||
|
||||
if (svalue > 0)
|
||||
@@ -479,9 +479,9 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
trailerString += @"\\dn0";
|
||||
}
|
||||
}
|
||||
else if ([currAttrib isEqualToString: CPBaselineOffsetAttributeName])
|
||||
else if ([currAttrib isEqualToString:CPBaselineOffsetAttributeName])
|
||||
{
|
||||
var value = [attributes objectForKey: CPBaselineOffsetAttributeName],
|
||||
var value = [attributes objectForKey:CPBaselineOffsetAttributeName],
|
||||
svalue = [value floatValue] * 2;
|
||||
|
||||
if (svalue > 0)
|
||||
@@ -495,13 +495,13 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
trailerString += @"\\dn0";
|
||||
}
|
||||
}
|
||||
else if ([currAttrib isEqualToString: CPAttachmentAttributeName])
|
||||
else if ([currAttrib isEqualToString:CPAttachmentAttributeName])
|
||||
{
|
||||
}
|
||||
else if ([currAttrib isEqualToString: CPLigatureAttributeName])
|
||||
else if ([currAttrib isEqualToString:CPLigatureAttributeName])
|
||||
{
|
||||
}
|
||||
else if ([currAttrib isEqualToString: CPKernAttributeName])
|
||||
else if ([currAttrib isEqualToString:CPKernAttributeName])
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -519,7 +519,7 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
var braces;
|
||||
|
||||
if ([headerString length])
|
||||
braces = [CPString stringWithFormat: @"{%@ %@}", headerString, substring];
|
||||
braces = [CPString stringWithFormat:@"{%@ %@}", headerString, substring];
|
||||
else
|
||||
braces = substring;
|
||||
|
||||
@@ -530,7 +530,7 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
var nobraces;
|
||||
|
||||
if ([headerString length])
|
||||
nobraces = [CPString stringWithFormat: @"%@ %@", headerString, substring];
|
||||
nobraces = [CPString stringWithFormat:@"%@ %@", headerString, substring];
|
||||
else
|
||||
nobraces = substring;
|
||||
|
||||
@@ -559,7 +559,7 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
substring,
|
||||
runString;
|
||||
|
||||
attributes = [text attributesAtIndex: CPMaxRange(currRange)
|
||||
attributes = [text attributesAtIndex:CPMaxRange(currRange)
|
||||
longestEffectiveRange:currRange
|
||||
inRange:completeRange];
|
||||
substring = [string substringWithRange:currRange];
|
||||
@@ -574,8 +574,8 @@ function _points2twips(a) { return (a)*20.0; }
|
||||
}
|
||||
|
||||
|
||||
- (CPString) RTFDStringFromAttributedString: (CPAttributedString)aText
|
||||
documentAttributes: (CPDictionary)dict
|
||||
- (CPString) RTFDStringFromAttributedString:(CPAttributedString)aText
|
||||
documentAttributes:(CPDictionary)dict
|
||||
{
|
||||
var output = [CPString string],
|
||||
headerString,
|
||||
Reference in New Issue
Block a user