1 /*  -*-objc-*-
2    NSAttributedString.h
3 
4    Categories which add capabilities to NSAttributedString
5 
6    Copyright (C) 1999 Free Software Foundation, Inc.
7 
8    Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
9    Date: July 1999
10 
11    This file is part of the GNUstep GUI Library.
12 
13    This library is free software; you can redistribute it and/or
14    modify it under the terms of the GNU Lesser General Public
15    License as published by the Free Software Foundation; either
16    version 2 of the License, or (at your option) any later version.
17 
18    This library is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
21    Lesser General Public License for more details.
22 
23    You should have received a copy of the GNU Lesser General Public
24    License along with this library; see the file COPYING.LIB.
25    If not, see <http://www.gnu.org/licenses/> or write to the
26    Free Software Foundation, 51 Franklin Street, Fifth Floor,
27    Boston, MA 02110-1301, USA.
28 */
29 
30 #ifndef _GNUstep_H_NSAttributedString
31 #define _GNUstep_H_NSAttributedString
32 #import <GNUstepBase/GSVersionMacros.h>
33 
34 #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
35 
36 #import <Foundation/NSAttributedString.h>
37 #import <Foundation/NSRange.h>
38 #import <AppKit/NSFontManager.h>
39 // for NSWritingDirection
40 #import <AppKit/NSParagraphStyle.h>
41 #import <AppKit/NSText.h>
42 #import <AppKit/AppKitDefines.h>
43 
44 @class NSTextAttachment;
45 @class NSFileWrapper;
46 @class NSString;
47 @class NSDictionary;
48 @class NSData;
49 @class NSArray;
50 @class NSURL;
51 @class NSError;
52 @class NSTextBlock;
53 @class NSTextList;
54 @class NSTextTable;
55 
56 /* Global NSString attribute names used in accessing the respective
57    property in a text attributes dictionary.  if the key is not in the
58    dictionary the default value is assumed.  */
59 APPKIT_EXPORT NSString *NSAttachmentAttributeName;
60 APPKIT_EXPORT NSString *NSBackgroundColorAttributeName;
61 APPKIT_EXPORT NSString *NSBaselineOffsetAttributeName;
62 APPKIT_EXPORT NSString *NSCursorAttributeName;
63 APPKIT_EXPORT NSString *NSExpansionAttributeName;
64 APPKIT_EXPORT NSString *NSFontAttributeName;
65 APPKIT_EXPORT NSString *NSForegroundColorAttributeName;
66 APPKIT_EXPORT NSString *NSKernAttributeName;
67 APPKIT_EXPORT NSString *NSLigatureAttributeName;
68 APPKIT_EXPORT NSString *NSLinkAttributeName;
69 APPKIT_EXPORT NSString *NSObliquenessAttributeName;
70 APPKIT_EXPORT NSString *NSParagraphStyleAttributeName;
71 APPKIT_EXPORT NSString *NSShadowAttributeName;
72 APPKIT_EXPORT NSString *NSStrikethroughColorAttributeName;
73 APPKIT_EXPORT NSString *NSStrikethroughStyleAttributeName;
74 APPKIT_EXPORT NSString *NSStrokeColorAttributeName;
75 APPKIT_EXPORT NSString *NSStrokeWidthAttributeName;
76 APPKIT_EXPORT NSString *NSSuperscriptAttributeName;
77 APPKIT_EXPORT NSString *NSToolTipAttributeName;
78 APPKIT_EXPORT NSString *NSUnderlineColorAttributeName;
79 APPKIT_EXPORT NSString *NSUnderlineStyleAttributeName;
80 
81 #if OS_API_VERSION(MAC_OS_X_VERSION_10_8, GS_API_LATEST)
82 APPKIT_EXPORT NSString *NSTextAlternativesAttributeName;
83 #endif
84 
85 #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
86 APPKIT_EXPORT NSString *NSWritingDirectionAttributeName;
87 #endif
88 
89 #if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST)
90 APPKIT_EXPORT NSString *NSGlyphInfoAttributeName;
91 #endif
92 
93 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
94 APPKIT_EXPORT NSString *NSPaperSizeDocumentAttribute;
95 APPKIT_EXPORT NSString *NSLeftMarginDocumentAttribute;
96 APPKIT_EXPORT NSString *NSRightMarginDocumentAttribute;
97 APPKIT_EXPORT NSString *NSTopMarginDocumentAttribute;
98 APPKIT_EXPORT NSString *NSBottomMarginDocumentAttribute;
99 APPKIT_EXPORT NSString *NSHyphenationFactorDocumentAttribute;
100 APPKIT_EXPORT NSString *NSDocumentTypeDocumentAttribute;
101 APPKIT_EXPORT NSString *NSCharacterEncodingDocumentAttribute;
102 APPKIT_EXPORT NSString *NSViewSizeDocumentAttribute;
103 APPKIT_EXPORT NSString *NSViewZoomDocumentAttribute;
104 APPKIT_EXPORT NSString *NSViewModeDocumentAttribute;
105 APPKIT_EXPORT NSString *NSBackgroundColorDocumentAttribute;
106 APPKIT_EXPORT NSString *NSCocoaVersionDocumentAttribute;
107 APPKIT_EXPORT NSString *NSReadOnlyDocumentAttribute;
108 APPKIT_EXPORT NSString *NSConvertedDocumentAttribute;
109 APPKIT_EXPORT NSString *NSDefaultTabIntervalDocumentAttribute;
110 APPKIT_EXPORT NSString *NSTitleDocumentAttribute;
111 APPKIT_EXPORT NSString *NSCompanyDocumentAttribute;
112 APPKIT_EXPORT NSString *NSCopyrightDocumentAttribute;
113 APPKIT_EXPORT NSString *NSSubjectDocumentAttribute;
114 APPKIT_EXPORT NSString *NSAuthorDocumentAttribute;
115 APPKIT_EXPORT NSString *NSKeywordsDocumentAttribute;
116 APPKIT_EXPORT NSString *NSCommentDocumentAttribute;
117 APPKIT_EXPORT NSString *NSEditorDocumentAttribute;
118 APPKIT_EXPORT NSString *NSCreationTimeDocumentAttribute;
119 APPKIT_EXPORT NSString *NSModificationTimeDocumentAttribute;
120 
121 // DocumentType values
122 
123 APPKIT_EXPORT NSString *NSPlainTextDocumentType;
124 APPKIT_EXPORT NSString *NSRTFTextDocumentType;
125 APPKIT_EXPORT NSString *NSRTFDTextDocumentType;
126 APPKIT_EXPORT NSString *NSMacSimpleTextDocumentType;
127 APPKIT_EXPORT NSString *NSHTMLTextDocumentType;
128 APPKIT_EXPORT NSString *NSDocFormatTextDocumentType;
129 APPKIT_EXPORT NSString *NSWordMLTextDocumentType;
130 APPKIT_EXPORT NSString *NSOfficeOpenXMLTextDocumentType;
131 APPKIT_EXPORT NSString *NSOpenDocumentTextDocumentType;
132 
133 // for HTML export
134 
135 APPKIT_EXPORT NSString *NSExcludedElementsDocumentAttribute;
136 APPKIT_EXPORT NSString *NSTextEncodingNameDocumentAttribute;
137 APPKIT_EXPORT NSString *NSPrefixSpacesDocumentAttribute;
138 
139 // for HTML import
140 
141 APPKIT_EXPORT NSString *NSBaseURLDocumentOption;
142 APPKIT_EXPORT NSString *NSCharacterEncodingDocumentOption;
143 APPKIT_EXPORT NSString *NSDefaultAttributesDocumentOption;
144 APPKIT_EXPORT NSString *NSDocumentTypeDocumentOption;
145 APPKIT_EXPORT NSString *NSTextEncodingNameDocumentOption;
146 APPKIT_EXPORT NSString *NSTextSizeMultiplierDocumentOption;
147 APPKIT_EXPORT NSString *NSTimeoutDocumentOption;
148 APPKIT_EXPORT NSString *NSWebPreferencesDocumentOption;
149 APPKIT_EXPORT NSString *NSWebResourceLoadDelegateDocumentOption;
150 
151 // special attributes
152 
153 APPKIT_EXPORT NSString *NSCharacterShapeAttributeName;
154 APPKIT_EXPORT const unsigned NSUnderlineByWordMask;
155 APPKIT_EXPORT NSString *NSSpellingStateAttributeName;
156 APPKIT_EXPORT const unsigned NSSpellingStateSpellingFlag;
157 APPKIT_EXPORT const unsigned NSSpellingStateGrammarFlag;
158 
159 // readFrom... attributes
160 
161 APPKIT_EXPORT NSString *NSCharacterEncodingDocumentOption;
162 APPKIT_EXPORT NSString *NSBaseURLDocumentOption;
163 APPKIT_EXPORT NSString *NSDefaultAttributesDocumentOption;
164 APPKIT_EXPORT NSString *NSDocumentTypeDocumentOption;
165 
166 // initWithHTML... attributes
167 
168 APPKIT_EXPORT NSString *NSTextEncodingNameDocumentOption;
169 APPKIT_EXPORT NSString *NSTimeoutDocumentOption;
170 APPKIT_EXPORT NSString *NSWebPreferencesDocumentOption;
171 APPKIT_EXPORT NSString *NSWebResourceLoadDelegateDocumentOption;
172 APPKIT_EXPORT NSString *NSTextSizeMultiplierDocumentOption;
173 
174 // Private Attributes
175 APPKIT_EXPORT NSString *NSTextInsertionUndoableAttributeName;
176 
177 /* Currently supported values for NSUnderlineStyleAttributeName.  */
178 enum _NSUnderlineStyle
179 {
180 	NSUnderlineStyleNone   = 0x00,
181 	NSUnderlineStyleSingle = 0x01,
182 	NSUnderlineStyleThick  = 0x02,
183 	NSUnderlineStyleDouble = 0x09
184 };
185 
186 enum _NSUnderlinePattern
187 {
188 	NSUnderlinePatternSolid      = 0x0000,
189 	NSUnderlinePatternDot        = 0x0100,
190 	NSUnderlinePatternDash       = 0x0200,
191 	NSUnderlinePatternDashDot    = 0x0300,
192 	NSUnderlinePatternDashDotDot = 0x0400
193 };
194 #endif
195 
196 #if OS_API_VERSION(GS_API_MACOSX, MAC_OS_X_VERSION_10_3)
197 // Deprecated
198 enum
199 {
200   GSNoUnderlineStyle = 0,
201   NSSingleUnderlineStyle = 1,
202 	NSUnderlineStrikethroughMask
203 };
204 #endif
205 
206 #if OS_API_VERSION(MAC_OS_X_VERSION_10_11, GS_API_LATEST)
207 typedef NSInteger NSWritingDirectionFormatType;
208 enum {
209   NSWritingDirectionEmbedding = (0 << 1),
210   NSWritingDirectionOverride = (1 << 1)
211 };
212 #endif
213 
214 @interface NSAttributedString (AppKit)
215 - (BOOL) containsAttachments;
216 - (NSDictionary*) fontAttributesInRange: (NSRange)range;
217 - (NSDictionary*) rulerAttributesInRange: (NSRange)range;
218 - (NSUInteger) lineBreakBeforeIndex: (NSUInteger)location
219                         withinRange: (NSRange)aRange;
220 - (NSRange) doubleClickAtIndex: (NSUInteger)location;
221 - (NSUInteger) nextWordFromIndex: (NSUInteger)location forward: (BOOL)isForward;
222 
223 - (id) initWithRTF: (NSData*)data documentAttributes: (NSDictionary**)dict;
224 - (id) initWithRTFD: (NSData*)data documentAttributes: (NSDictionary**)dict;
225 - (id) initWithPath: (NSString*)path documentAttributes: (NSDictionary**)dict;
226 - (id) initWithURL: (NSURL*)url documentAttributes: (NSDictionary**)dict;
227 - (id) initWithRTFDFileWrapper: (NSFileWrapper*)wrapper
228   documentAttributes: (NSDictionary**)dict;
229 - (id) initWithHTML: (NSData*)data documentAttributes: (NSDictionary**)dict;
230 - (id) initWithHTML: (NSData*)data
231             baseURL: (NSURL*)base
232  documentAttributes: (NSDictionary**)dict;
233 
234 - (NSData*) RTFFromRange: (NSRange)range
235       documentAttributes: (NSDictionary*)dict;
236 - (NSData*) RTFDFromRange: (NSRange)range
237        documentAttributes: (NSDictionary*)dict;
238 - (NSFileWrapper*) RTFDFileWrapperFromRange: (NSRange)range
239                          documentAttributes: (NSDictionary*)dict;
240 
241 #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
242 + (NSArray *) textFileTypes;
243 + (NSArray *) textPasteboardTypes;
244 + (NSArray *) textUnfilteredFileTypes;
245 + (NSArray *) textUnfilteredPasteboardTypes;
246 #endif
247 #if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
248 + (NSArray *) textTypes;
249 + (NSArray *) textUnfilteredTypes;
250 #endif
251 #if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST)
252 - (NSData *) docFormatFromRange: (NSRange)range
253              documentAttributes: (NSDictionary *)dict;
254 - (id) initWithDocFormat: (NSData *)data
255       documentAttributes: (NSDictionary **)dict;
256 - (id) initWithHTML: (NSData *)data
257             options: (NSDictionary *)options
258  documentAttributes: (NSDictionary **)dict;
259 
260 - (NSUInteger) lineBreakByHyphenatingBeforeIndex: (NSUInteger)location
261                                      withinRange: (NSRange)aRange;
262 #endif
263 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
264 - (NSData *) dataFromRange: (NSRange)range
265         documentAttributes: (NSDictionary *)dict
266                      error: (NSError **)error;
267 - (NSFileWrapper *) fileWrapperFromRange: (NSRange)range
268                       documentAttributes: (NSDictionary *)dict
269                                    error: (NSError **)error;
270 - (id) initWithData: (NSData *)data
271             options: (NSDictionary *)options
272  documentAttributes: (NSDictionary **)dict
273               error: (NSError **)error;
274 - (id) initWithURL: (NSURL *)url
275            options: (NSDictionary *)options
276 documentAttributes: (NSDictionary **)dict
277              error: (NSError **)error;
278 
279 - (NSInteger) itemNumberInTextList: (NSTextList *)list
280                            atIndex: (NSUInteger)location;
281 - (NSRange) rangeOfTextBlock: (NSTextBlock *)block
282                      atIndex: (NSUInteger)location;
283 - (NSRange) rangeOfTextList: (NSTextList *)list
284                     atIndex: (NSUInteger)location;
285 - (NSRange) rangeOfTextTable: (NSTextTable *)table
286                      atIndex: (NSUInteger)location;
287 #endif
288 @end
289 
290 @interface NSMutableAttributedString (AppKit)
291 - (void) superscriptRange: (NSRange)range;
292 - (void) subscriptRange: (NSRange)range;
293 - (void) unscriptRange: (NSRange)range;
294 - (void) applyFontTraits: (NSFontTraitMask)traitMask range: (NSRange)range;
295 - (void) setAlignment: (NSTextAlignment)alignment range: (NSRange)range;
296 
297 - (void) fixAttributesInRange: (NSRange)range;
298 - (void) fixFontAttributeInRange: (NSRange)range;
299 - (void) fixParagraphStyleAttributeInRange: (NSRange)range;
300 - (void) fixAttachmentAttributeInRange: (NSRange)range;
301 
302 - (void) updateAttachmentsFromPath: (NSString *)path;
303 
304 - (BOOL) readFromURL: (NSURL *)url
305 	     options: (NSDictionary *)options
306   documentAttributes: (NSDictionary**)documentAttributes;
307 #if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST)
308 - (BOOL) readFromData: (NSData *)data
309               options: (NSDictionary *)options
310    documentAttributes: (NSDictionary **)documentAttributes;
311 #endif
312 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
313 - (BOOL) readFromData: (NSData *)data
314               options: (NSDictionary *)options
315    documentAttributes: (NSDictionary **)documentAttributes
316                 error: (NSError **)error;
317 - (BOOL) readFromURL: (NSURL *)url
318              options: (NSDictionary *)options
319   documentAttributes: (NSDictionary **)documentAttributes
320                error: (NSError **)error;
321 
322 - (void) setBaseWritingDirection: (NSWritingDirection)writingDirection
323                            range: (NSRange)range;
324 #endif
325 @end
326 
327 #endif
328 
329 #endif
330 
331