Add document format inference in NSAttributedString

Adds code in `initWithData` to infer document format for RTF, HTML, and plaintext documents.
Additionally refactors NSAttributedString to use the correct attribute types as described in Apple's documentation.
This commit is contained in:
ckegel 2023-04-21 11:47:30 -04:00
parent 5300f80f18
commit e086fe9f33
2 changed files with 224 additions and 194 deletions

View File

@ -27,110 +27,95 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <AppKit/NSStringDrawer.h>
#import <AppKit/NSTextAttachment.h>
NSString *const NSFontAttributeName = @"NSFontAttributeName";
NSString *const NSParagraphStyleAttributeName =
@"NSParagraphStyleAttributeName";
NSString *const NSForegroundColorAttributeName =
@"NSForegroundColorAttributeName";
NSString *const NSBackgroundColorAttributeName =
@"NSBackgroundColorAttributeName";
NSString *const NSUnderlineStyleAttributeName =
@"NSUnderlineStyleAttributeName";
NSString *const NSUnderlineColorAttributeName =
@"NSUnderlineColorAttributeName";
NSString *const NSAttachmentAttributeName = @"NSAttachmentAttributeName";
NSString *const NSKernAttributeName = @"NSKernAttributeName";
NSString *const NSLigatureAttributeName = @"NSLigatureAttributeName";
NSString *const NSStrikethroughStyleAttributeName =
@"NSStrikethroughStyleAttributeName";
NSString *const NSStrikethroughColorAttributeName =
@"NSStrikethroughColorAttributeName";
NSString *const NSObliquenessAttributeName = @"NSObliquenessAttributeName";
NSString *const NSStrokeWidthAttributeName = @"NSStrokeWidthAttributeName";
NSString *const NSStrokeColorAttributeName = @"NSStrokeColorAttributeName";
NSString *const NSBaselineOffsetAttributeName =
@"NSBaselineOffsetAttributeName";
NSString *const NSSuperscriptAttributeName = @"NSSuperscriptAttributeName";
NSString *const NSLinkAttributeName = @"NSLinkAttributeName";
NSString *const NSShadowAttributeName = @"NSShadowAttributeName";
NSString *const NSExpansionAttributeName = @"NSExpansionAttributeName";
NSString *const NSCursorAttributeName = @"NSCursorAttributeName";
NSString *const NSToolTipAttributeName = @"NSToolTipAttributeName";
NSString *const NSSpellingStateAttributeName =
@"NSSpellingStateAttributeName"; // temporary attribute
NSAttributedStringKey NSFontAttributeName = @"NSFontAttributeName";
NSAttributedStringKey NSParagraphStyleAttributeName = @"NSParagraphStyleAttributeName";
NSAttributedStringKey NSForegroundColorAttributeName = @"NSForegroundColorAttributeName";
NSAttributedStringKey NSBackgroundColorAttributeName = @"NSBackgroundColorAttributeName";
NSAttributedStringKey NSUnderlineStyleAttributeName = @"NSUnderlineStyleAttributeName";
NSAttributedStringKey NSUnderlineColorAttributeName = @"NSUnderlineColorAttributeName";
NSAttributedStringKey NSAttachmentAttributeName = @"NSAttachmentAttributeName";
NSAttributedStringKey NSKernAttributeName = @"NSKernAttributeName";
NSAttributedStringKey NSLigatureAttributeName = @"NSLigatureAttributeName";
NSAttributedStringKey NSStrikethroughStyleAttributeName = @"NSStrikethroughStyleAttributeName";
NSAttributedStringKey NSStrikethroughColorAttributeName = @"NSStrikethroughColorAttributeName";
NSAttributedStringKey NSObliquenessAttributeName = @"NSObliquenessAttributeName";
NSAttributedStringKey NSStrokeWidthAttributeName = @"NSStrokeWidthAttributeName";
NSAttributedStringKey NSStrokeColorAttributeName = @"NSStrokeColorAttributeName";
NSAttributedStringKey NSBaselineOffsetAttributeName = @"NSBaselineOffsetAttributeName";
NSAttributedStringKey NSSuperscriptAttributeName = @"NSSuperscriptAttributeName";
NSAttributedStringKey NSLinkAttributeName = @"NSLinkAttributeName";
NSAttributedStringKey NSShadowAttributeName = @"NSShadowAttributeName";
NSAttributedStringKey NSExpansionAttributeName = @"NSExpansionAttributeName";
NSAttributedStringKey NSCursorAttributeName = @"NSCursorAttributeName";
NSAttributedStringKey NSToolTipAttributeName = @"NSToolTipAttributeName";
NSAttributedStringKey NSSpellingStateAttributeName = @"NSSpellingStateAttributeName"; // temporary attribute
NSString *const NSDocumentTypeDocumentAttribute = @"DocumentType";
NSString *const NSConvertedDocumentAttribute = @"Converted";
NSString *const NSFileTypeDocumentAttribute = @"UTI";
NSString *const NSTitleDocumentAttribute = @"NSTitleDocumentAttribute";
NSString *const NSCompanyDocumentAttribute = @"NSCompanyDocumentAttribute";
NSString *const NSCopyrightDocumentAttribute = @"NSCopyrightDocumentAttribute";
NSString *const NSSubjectDocumentAttribute = @"NSSubjectDocumentAttribute";
NSString *const NSAuthorDocumentAttribute = @"NSAuthorDocumentAttribute";
NSString *const NSKeywordsDocumentAttribute = @"NSKeywordsDocumentAttribute";
NSString *const NSCommentDocumentAttribute = @"NSCommentDocumentAttribute";
NSString *const NSEditorDocumentAttribute = @"NSEditorDocumentAttribute";
NSString *const NSCreationTimeDocumentAttribute =
@"NSCreationTimeDocumentAttribute";
NSString *const NSModificationTimeDocumentAttribute =
@"NSModificationTimeDocumentAttribute";
NSString *const NSManagerDocumentAttribute = @"NSManagerDocumentAttribute";
NSString *const NSCategoryDocumentAttribute = @"NSCategoryDocumentAttribute";
NSString *const NSAppearanceDocumentAttribute =
@"NSAppearanceDocumentAttribute";
NSString *const NSCharacterEncodingDocumentAttribute = @"CharacterEncoding";
NSString *const NSDefaultAttributesDocumentAttribute = @"DefaultAttributes";
NSString *const NSPaperSizeDocumentAttribute = @"PaperSize";
NSString *const NSLeftMarginDocumentAttribute = @"LeftMargin";
NSString *const NSRightMarginDocumentAttribute = @"RightMargin";
NSString *const NSTopMarginDocumentAttribute = @"TopMargin";
NSString *const NSBottomMarginDocumentAttribute = @"BottomMargin";
NSString *const NSViewSizeDocumentAttribute = @"ViewSize";
NSString *const NSViewZoomDocumentAttribute = @"ViewZoom";
NSString *const NSViewModeDocumentAttribute = @"ViewMode";
NSString *const NSReadOnlyDocumentAttribute = @"ReadOnly";
NSString *const NSBackgroundColorDocumentAttribute = @"BackgroundColor";
NSString *const NSHyphenationFactorDocumentAttribute = @"HyphenationFactor";
NSString *const NSDefaultTabIntervalDocumentAttribute = @"DefaultTabInterval";
NSString *const NSTextLayoutSectionsAttribute =
@"NSTextLayoutSectionsAttribute";
NSString *const NSExcludedElementsDocumentAttribute = @"ExcludedElements";
NSString *const NSTextEncodingNameDocumentAttribute = @"TextEncodingName";
NSString *const NSPrefixSpacesDocumentAttribute = @"PrefixSpaces";
NSAttributedStringDocumentAttributeKey NSDocumentTypeDocumentAttribute = @"DocumentType";
NSAttributedStringDocumentAttributeKey NSConvertedDocumentAttribute = @"Converted";
NSAttributedStringDocumentAttributeKey NSFileTypeDocumentAttribute = @"UTI";
NSAttributedStringDocumentAttributeKey NSTitleDocumentAttribute = @"NSTitleDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSCompanyDocumentAttribute = @"NSCompanyDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSCopyrightDocumentAttribute = @"NSCopyrightDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSSubjectDocumentAttribute = @"NSSubjectDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSAuthorDocumentAttribute = @"NSAuthorDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSKeywordsDocumentAttribute = @"NSKeywordsDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSCommentDocumentAttribute = @"NSCommentDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSEditorDocumentAttribute = @"NSEditorDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSCreationTimeDocumentAttribute = @"NSCreationTimeDocumentAttribute";
NSAttributedStringKey NSModificationTimeDocumentAttribute = @"NSModificationTimeDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSManagerDocumentAttribute = @"NSManagerDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSCategoryDocumentAttribute = @"NSCategoryDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSAppearanceDocumentAttribute = @"NSAppearanceDocumentAttribute";
NSAttributedStringDocumentAttributeKey NSCharacterEncodingDocumentAttribute = @"CharacterEncoding";
NSAttributedStringDocumentAttributeKey NSDefaultAttributesDocumentAttribute = @"DefaultAttributes";
NSAttributedStringDocumentAttributeKey NSPaperSizeDocumentAttribute = @"PaperSize";
NSAttributedStringDocumentAttributeKey NSLeftMarginDocumentAttribute = @"LeftMargin";
NSAttributedStringDocumentAttributeKey NSRightMarginDocumentAttribute = @"RightMargin";
NSAttributedStringDocumentAttributeKey NSTopMarginDocumentAttribute = @"TopMargin";
NSAttributedStringDocumentAttributeKey NSBottomMarginDocumentAttribute = @"BottomMargin";
NSAttributedStringDocumentAttributeKey NSViewSizeDocumentAttribute = @"ViewSize";
NSAttributedStringDocumentAttributeKey NSViewZoomDocumentAttribute = @"ViewZoom";
NSAttributedStringDocumentAttributeKey NSViewModeDocumentAttribute = @"ViewMode";
NSAttributedStringDocumentAttributeKey NSReadOnlyDocumentAttribute = @"ReadOnly";
NSAttributedStringDocumentAttributeKey NSBackgroundColorDocumentAttribute = @"BackgroundColor";
NSAttributedStringDocumentAttributeKey NSHyphenationFactorDocumentAttribute = @"HyphenationFactor";
NSAttributedStringDocumentAttributeKey NSDefaultTabIntervalDocumentAttribute = @"DefaultTabInterval";
NSAttributedStringDocumentAttributeKey NSTextLayoutSectionsAttribute = @"NSTextLayoutSectionsAttribute";
NSAttributedStringDocumentAttributeKey NSExcludedElementsDocumentAttribute = @"ExcludedElements";
NSAttributedStringDocumentAttributeKey NSTextEncodingNameDocumentAttribute = @"TextEncodingName";
NSAttributedStringDocumentAttributeKey NSPrefixSpacesDocumentAttribute = @"PrefixSpaces";
NSAttributedStringDocumentAttributeKey NSCocoaVersionDocumentAttribute = @"NSCocoaVersionDocumentAttribute";
NSString *const NSDocumentTypeDocumentOption = @"DocumentType";
NSString *const NSDefaultAttributesDocumentOption = @"DefaultAttributes";
NSString *const NSCharacterEncodingDocumentOption = @"CharacterEncoding";
NSString *const NSTextEncodingNameDocumentOption = @"TextEncodingName";
NSString *const NSBaseURLDocumentOption = @"BaseURL";
NSString *const NSTimeoutDocumentOption = @"Timeout";
NSString *const NSWebPreferencesDocumentOption = @"WebPreferences";
NSString *const NSWebResourceLoadDelegateDocumentOption =
@"WebResourceLoadDelegate";
NSString *const NSTextSizeMultiplierDocumentOption = @"TextSizeMultiplier";
NSString *const NSFileTypeDocumentOption = @"UTI";
NSAttributedStringDocumentReadingOptionKey NSDocumentTypeDocumentOption = @"DocumentType";
NSAttributedStringDocumentReadingOptionKey NSDefaultAttributesDocumentOption = @"DefaultAttributes";
NSAttributedStringDocumentReadingOptionKey NSCharacterEncodingDocumentOption = @"CharacterEncoding";
NSAttributedStringDocumentReadingOptionKey NSTextEncodingNameDocumentOption = @"TextEncodingName";
NSAttributedStringDocumentReadingOptionKey NSBaseURLDocumentOption = @"BaseURL";
NSAttributedStringDocumentReadingOptionKey NSTimeoutDocumentOption = @"Timeout";
NSAttributedStringDocumentReadingOptionKey NSWebPreferencesDocumentOption = @"WebPreferences";
NSAttributedStringDocumentReadingOptionKey NSWebResourceLoadDelegateDocumentOption = @"WebResourceLoadDelegate";
NSAttributedStringDocumentReadingOptionKey NSTextSizeMultiplierDocumentOption = @"TextSizeMultiplier";
NSAttributedStringDocumentReadingOptionKey NSFileTypeDocumentOption = @"UTI";
NSString *const NSPlainTextDocumentType = @"NSPlainText";
NSString *const NSRTFTextDocumentType = @"NSRTF";
NSString *const NSRTFDTextDocumentType = @"NSRTFD";
NSString *const NSHTMLTextDocumentType = @"NSHTML";
NSString *const NSMacSimpleTextDocumentType = @"NSMacSimpleText";
NSString *const NSDocFormatTextDocumentType = @"NSDocFormat";
NSString *const NSWordMLTextDocumentType = @"NSWordML";
NSString *const NSWebArchiveTextDocumentType = @"NSWebArchive";
NSString *const NSOfficeOpenXMLTextDocumentType = @"NSOfficeOpenXML";
NSString *const NSOpenDocumentTextDocumentType = @"NSOpenDocument";
NSAttributedStringDocumentType NSPlainTextDocumentType = @"NSPlainText";
NSAttributedStringDocumentType NSRTFTextDocumentType = @"NSRTF";
NSAttributedStringDocumentType NSRTFDTextDocumentType = @"NSRTFD";
NSAttributedStringDocumentType NSHTMLTextDocumentType = @"NSHTML";
NSAttributedStringDocumentType NSMacSimpleTextDocumentType = @"NSMacSimpleText";
NSAttributedStringDocumentType NSDocFormatTextDocumentType = @"NSDocFormat";
NSAttributedStringDocumentType NSWordMLTextDocumentType = @"NSWordML";
NSAttributedStringDocumentType NSWebArchiveTextDocumentType = @"NSWebArchive";
NSAttributedStringDocumentType NSOfficeOpenXMLTextDocumentType = @"NSOfficeOpenXML";
NSAttributedStringDocumentType NSOpenDocumentTextDocumentType = @"NSOpenDocument";
NSString *const NSTextLayoutSectionOrientation =
@"NSTextLayoutSectionOrientation";
NSString *const NSTextLayoutSectionRange = @"NSTextLayoutSectionRange";
NSTextLayoutSectionKey NSTextLayoutSectionOrientation = @"NSTextLayoutSectionOrientation";
NSTextLayoutSectionKey NSTextLayoutSectionRange = @"NSTextLayoutSectionRange";
NSString *const NSCharacterShapeAttributeName = @"NSCharacterShape";
NSString *const NSUsesScreenFontsDocumentAttribute = @"UsesScreenFonts";
NSAttributedStringKey NSCharacterShapeAttributeName = @"NSCharacterShape";
NSAttributedStringKey NSUsesScreenFontsDocumentAttribute = @"UsesScreenFonts";
NSString *const NSTextEffectAttributeName = @"NSTextEffect";
const NSAttributedStringKey NSTextEffectAttributeName = @"NSTextEffect";
NSAttributedStringKey NSWritingDirectionAttributeName = @"NSWritingDirectionAttribute";
NSString *const NSCocoaVersionDocumentAttribute = @"NSCocoaVersionDocumentAttribute";
NSUInteger NSUnderlineStrikethroughMask = 0x4000;
NSUInteger NSUnderlineByWordMask = 0x8000;
@ -159,15 +144,48 @@ NSUInteger NSUnderlineByWordMask = 0x8000;
error: (NSError **) error
{
NSUnimplementedMethod();
NSString *docType = [options objectForKey:@"NSDocumentTypeDocumentAttribute"];
NSString *docType = [options objectForKey:NSDocumentTypeDocumentAttribute];
//Infer the document format if not provided
if(docType == nil){
NSLog(@"NSAttributedString initFromData - inferring document type");
//TODO: infer document type (assume RTF for now)
docType = NSRTFTextDocumentType;
//Extract a prefix from the document to identify the type
//FIXME: use 64 bit ready types and check encoding
char prefix[14];
NSUInteger dataLength = [data length];
if(dataLength < sizeof(prefix))
{
[data getBytes: prefix length: dataLength];
prefix[dataLength] = 0;
}
else
{
[data getBytes: prefix length: sizeof(prefix)];
}
//Use the prefix to determine the document format
// FIXME extend the list
if (strncmp(prefix, "{\\rtf", 5) == 0)
{
docType = NSRTFTextDocumentType;
}
else if (strncasecmp(prefix, "<!doctype html", 14) == 0 ||
strncasecmp(prefix, "<head", 5) == 0 ||
strncasecmp(prefix, "<title", 6) == 0 ||
strncasecmp(prefix, "<html", 5) == 0 ||
strncmp(prefix, "<!--", 4) == 0 ||
strncasecmp(prefix, "<h1", 3) == 0)
{
docType = NSHTMLTextDocumentType;
}
else
{
docType = NSPlainTextDocumentType;
}
}
//Read the document based on its type
//TODO: Implement reading for all types
if([docType isEqual: NSDocFormatTextDocumentType]){
return nil;
}
@ -192,10 +210,11 @@ NSUInteger NSUnderlineByWordMask = 0x8000;
return nil;
}
else if([docType isEqual: NSRTFTextDocumentType]){
return [self initWithRTF:data documentAttributes:attributes];
return [self initWithRTF: data documentAttributes: attributes];
}
else if([docType isEqual: NSRTFDTextDocumentType]){
return [self initWithRTFD:data documentAttributes:attributes];
NSLog(@"NSAttributedString initFromData - dont know how to parse %@", docType);
return nil;
}
else if([docType isEqual: NSWebArchiveTextDocumentType]){
NSLog(@"NSAttributedString initFromData - dont know how to parse %@", docType);
@ -253,7 +272,8 @@ NSUInteger NSUnderlineByWordMask = 0x8000;
}
- initWithRTF: (NSData *) rtf documentAttributes: (NSDictionary **) attributes {
NSLog(@"NSAttributedString - initializing from RTF");
*attributes = [NSDictionary dictionaryWithObject: NSRTFTextDocumentType
forKey: NSDocumentTypeDocumentAttribute];
NSAttributedString *string =
[NSRichTextReader attributedStringWithData: rtf];
if (string == nil) {
@ -287,9 +307,8 @@ NSUInteger NSUnderlineByWordMask = 0x8000;
documentAttributes: (NSDictionary **) attributes
error: (NSError **) error
{
NSLog(@"NSAttributedString - initializing from URL");
NSData *data = [NSData dataWithContentsOfURL: url];
return [self initWithData:data options:options documentAttributes:attributes error:error];
return [self initWithData: data options: options documentAttributes: attributes error: error];
}
#pragma mark -

View File

@ -26,103 +26,113 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
typedef NSString *NSAttributedStringDocumentReadingOptionKey;
typedef NSString *NSAttributedStringDocumentAttributeKey;
typedef NSString *NSAttributedStringDocumentType;
typedef NSString *NSTextLayoutSectionKey;
typedef NSString *NSAttributedStringKey;
APPKIT_EXPORT NSString *const NSFontAttributeName;
APPKIT_EXPORT NSString *const NSParagraphStyleAttributeName;
APPKIT_EXPORT NSString *const NSForegroundColorAttributeName;
APPKIT_EXPORT NSString *const NSBackgroundColorAttributeName;
APPKIT_EXPORT NSString *const NSUnderlineStyleAttributeName;
APPKIT_EXPORT NSString *const NSUnderlineColorAttributeName;
APPKIT_EXPORT NSString *const NSAttachmentAttributeName;
APPKIT_EXPORT NSString *const NSKernAttributeName;
APPKIT_EXPORT NSString *const NSLigatureAttributeName;
APPKIT_EXPORT NSString *const NSStrikethroughStyleAttributeName;
APPKIT_EXPORT NSString *const NSStrikethroughColorAttributeName;
APPKIT_EXPORT NSString *const NSObliquenessAttributeName;
APPKIT_EXPORT NSString *const NSStrokeWidthAttributeName;
APPKIT_EXPORT NSString *const NSStrokeColorAttributeName;
APPKIT_EXPORT NSString *const NSBaselineOffsetAttributeName;
APPKIT_EXPORT NSString *const NSSuperscriptAttributeName;
APPKIT_EXPORT NSString *const NSLinkAttributeName;
APPKIT_EXPORT NSString *const NSShadowAttributeName;
APPKIT_EXPORT NSString *const NSExpansionAttributeName;
APPKIT_EXPORT NSString *const NSCursorAttributeName;
APPKIT_EXPORT NSString *const NSToolTipAttributeName;
// The following constants are *not* declared as `const` in Apple's AppKit (they are located in __data)
APPKIT_EXPORT NSAttributedStringKey NSFontAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSParagraphStyleAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSForegroundColorAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSBackgroundColorAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSUnderlineStyleAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSUnderlineColorAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSAttachmentAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSKernAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSLigatureAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSStrikethroughStyleAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSStrikethroughColorAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSObliquenessAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSStrokeWidthAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSStrokeColorAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSBaselineOffsetAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSSuperscriptAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSLinkAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSShadowAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSExpansionAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSCursorAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSToolTipAttributeName;
APPKIT_EXPORT NSString *const NSSpellingStateAttributeName;
// The following constant is *not* declared as `const` in Apple's AppKit (they are located in __data)
APPKIT_EXPORT NSAttributedStringKey NSSpellingStateAttributeName;
APPKIT_EXPORT NSString *const NSDocumentTypeDocumentAttribute;
APPKIT_EXPORT NSString *const NSConvertedDocumentAttribute;
APPKIT_EXPORT NSString *const NSFileTypeDocumentAttribute;
APPKIT_EXPORT NSString *const NSTitleDocumentAttribute;
APPKIT_EXPORT NSString *const NSCompanyDocumentAttribute;
APPKIT_EXPORT NSString *const NSCopyrightDocumentAttribute;
APPKIT_EXPORT NSString *const NSSubjectDocumentAttribute;
APPKIT_EXPORT NSString *const NSAuthorDocumentAttribute;
APPKIT_EXPORT NSString *const NSKeywordsDocumentAttribute;
APPKIT_EXPORT NSString *const NSCommentDocumentAttribute;
APPKIT_EXPORT NSString *const NSEditorDocumentAttribute;
APPKIT_EXPORT NSString *const NSCreationTimeDocumentAttribute;
APPKIT_EXPORT NSString *const NSModificationTimeDocumentAttribute;
APPKIT_EXPORT NSString *const NSManagerDocumentAttribute;
APPKIT_EXPORT NSString *const NSCategoryDocumentAttribute;
APPKIT_EXPORT NSString *const NSAppearanceDocumentAttribute;
APPKIT_EXPORT NSString *const NSCharacterEncodingDocumentAttribute;
APPKIT_EXPORT NSString *const NSDefaultAttributesDocumentAttribute;
APPKIT_EXPORT NSString *const NSPaperSizeDocumentAttribute;
APPKIT_EXPORT NSString *const NSLeftMarginDocumentAttribute;
APPKIT_EXPORT NSString *const NSRightMarginDocumentAttribute;
APPKIT_EXPORT NSString *const NSTopMarginDocumentAttribute;
APPKIT_EXPORT NSString *const NSBottomMarginDocumentAttribute;
APPKIT_EXPORT NSString *const NSViewSizeDocumentAttribute;
APPKIT_EXPORT NSString *const NSViewZoomDocumentAttribute;
APPKIT_EXPORT NSString *const NSViewModeDocumentAttribute;
APPKIT_EXPORT NSString *const NSReadOnlyDocumentAttribute;
APPKIT_EXPORT NSString *const NSBackgroundColorDocumentAttribute;
APPKIT_EXPORT NSString *const NSHyphenationFactorDocumentAttribute;
APPKIT_EXPORT NSString *const NSDefaultTabIntervalDocumentAttribute;
APPKIT_EXPORT NSString *const NSTextLayoutSectionsAttribute;
APPKIT_EXPORT NSString *const NSExcludedElementsDocumentAttribute;
APPKIT_EXPORT NSString *const NSTextEncodingNameDocumentAttribute;
APPKIT_EXPORT NSString *const NSPrefixSpacesDocumentAttribute;
// The following constants are *not* declared as `const` in Apple's AppKit (they are located in __data)
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSDocumentTypeDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSConvertedDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSFileTypeDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSTitleDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSCompanyDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSCopyrightDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSSubjectDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSAuthorDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSKeywordsDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSCommentDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSEditorDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSCreationTimeDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSModificationTimeDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSManagerDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSCategoryDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSAppearanceDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSCharacterEncodingDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSDefaultAttributesDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSPaperSizeDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSLeftMarginDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSRightMarginDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSTopMarginDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSBottomMarginDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSViewSizeDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSViewZoomDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSViewModeDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSReadOnlyDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSBackgroundColorDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSHyphenationFactorDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSDefaultTabIntervalDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSTextLayoutSectionsAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSExcludedElementsDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSTextEncodingNameDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSPrefixSpacesDocumentAttribute;
APPKIT_EXPORT NSAttributedStringDocumentAttributeKey NSCocoaVersionDocumentAttribute;
APPKIT_EXPORT NSString *const NSDocumentTypeDocumentOption;
APPKIT_EXPORT NSString *const NSDefaultAttributesDocumentOption;
APPKIT_EXPORT NSString *const NSCharacterEncodingDocumentOption;
APPKIT_EXPORT NSString *const NSTextEncodingNameDocumentOption;
APPKIT_EXPORT NSString *const NSBaseURLDocumentOption;
APPKIT_EXPORT NSString *const NSTimeoutDocumentOption;
APPKIT_EXPORT NSString *const NSWebPreferencesDocumentOption;
APPKIT_EXPORT NSString *const NSWebResourceLoadDelegateDocumentOption;
APPKIT_EXPORT NSString *const NSTextSizeMultiplierDocumentOption;
APPKIT_EXPORT NSString *const NSFileTypeDocumentOption;
// The following constants are *not* declared as `const` in Apple's AppKit (they are located in __data)
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSDocumentTypeDocumentOption;
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSDefaultAttributesDocumentOption;
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSCharacterEncodingDocumentOption;
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSTextEncodingNameDocumentOption;
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSBaseURLDocumentOption;
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSTimeoutDocumentOption;
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSWebPreferencesDocumentOption;
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSWebResourceLoadDelegateDocumentOption;
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSTextSizeMultiplierDocumentOption;
APPKIT_EXPORT NSAttributedStringDocumentReadingOptionKey NSFileTypeDocumentOption;
APPKIT_EXPORT NSString *const NSPlainTextDocumentType;
APPKIT_EXPORT NSString *const NSRTFTextDocumentType;
APPKIT_EXPORT NSString *const NSRTFDTextDocumentType;
APPKIT_EXPORT NSString *const NSHTMLTextDocumentType;
APPKIT_EXPORT NSString *const NSMacSimpleTextDocumentType;
APPKIT_EXPORT NSString *const NSDocFormatTextDocumentType;
APPKIT_EXPORT NSString *const NSWordMLTextDocumentType;
APPKIT_EXPORT NSString *const NSWebArchiveTextDocumentType;
APPKIT_EXPORT NSString *const NSOfficeOpenXMLTextDocumentType;
APPKIT_EXPORT NSString *const NSOpenDocumentTextDocumentType;
// The following constants are *not* declared as `const` in Apple's AppKit (they are located in __data)
APPKIT_EXPORT NSAttributedStringDocumentType NSPlainTextDocumentType;
APPKIT_EXPORT NSAttributedStringDocumentType NSRTFTextDocumentType;
APPKIT_EXPORT NSAttributedStringDocumentType NSRTFDTextDocumentType;
APPKIT_EXPORT NSAttributedStringDocumentType NSHTMLTextDocumentType;
APPKIT_EXPORT NSAttributedStringDocumentType NSMacSimpleTextDocumentType;
APPKIT_EXPORT NSAttributedStringDocumentType NSDocFormatTextDocumentType;
APPKIT_EXPORT NSAttributedStringDocumentType NSWordMLTextDocumentType;
APPKIT_EXPORT NSAttributedStringDocumentType NSWebArchiveTextDocumentType;
APPKIT_EXPORT NSAttributedStringDocumentType NSOfficeOpenXMLTextDocumentType;
APPKIT_EXPORT NSAttributedStringDocumentType NSOpenDocumentTextDocumentType;
APPKIT_EXPORT NSString *const NSTextLayoutSectionOrientation;
APPKIT_EXPORT NSString *const NSTextLayoutSectionRange;
// The following constants are *not* declared as `const` in Apple's AppKit (they are located in __data)
APPKIT_EXPORT NSTextLayoutSectionKey NSTextLayoutSectionOrientation;
APPKIT_EXPORT NSTextLayoutSectionKey NSTextLayoutSectionRange;
APPKIT_EXPORT NSString *const NSCharacterShapeAttributeName;
APPKIT_EXPORT NSString *const NSUsesScreenFontsDocumentAttribute;
// The following constants are *not* declared as `const` in Apple's AppKit (they are located in __data)
APPKIT_EXPORT NSAttributedStringKey NSCharacterShapeAttributeName;
APPKIT_EXPORT NSAttributedStringKey NSUsesScreenFontsDocumentAttribute;
APPKIT_EXPORT NSString *const NSTextEffectAttributeName;
APPKIT_EXPORT const NSAttributedStringKey NSTextEffectAttributeName;
// The following constant is *not* declared as `const` in Apple's AppKit (they are located in __data)
APPKIT_EXPORT NSAttributedStringKey NSWritingDirectionAttributeName;
APPKIT_EXPORT NSString *const NSCocoaVersionDocumentAttribute;
// The following constants are *not* declared as `const` in Apple's AppKit (they are located in __data)
APPKIT_EXPORT NSUInteger NSUnderlineStrikethroughMask;
APPKIT_EXPORT NSUInteger NSUnderlineByWordMask;
enum {
NSSpellingStateSpellingFlag = 0x01,
NSSpellingStateGrammarFlag = 0x02,
@ -248,10 +258,11 @@ enum {
#pragma mark -
#pragma mark Getting Attribute Data
- (void)enumerateAttribute:(NSAttributedStringKey)attrName
inRange:(NSRange)enumerationRange
options:(NSAttributedStringEnumerationOptions)opts
usingBlock:(void (^)(id value, NSRange range, BOOL *stop))block;
- (void) enumerateAttribute: (NSAttributedStringKey) attrName
inRange: (NSRange) enumerationRange
options: (NSAttributedStringEnumerationOptions) opts
usingBlock:
(void (^)(id value, NSRange range, BOOL *stop)) block;
#pragma mark -
#pragma mark Testing String Data Sources