Mercurial > projects > dwt-mac
comparison dwt/internal/cocoa/NSTypesetter.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | 8b48be5454ce |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * | |
11 * Port to the D Programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
13 *******************************************************************************/ | |
14 module dwt.internal.cocoa.NSTypesetter; | |
15 | |
16 import dwt.internal.cocoa.CGFloat; | |
17 import dwt.internal.cocoa.NSArray; | |
18 import dwt.internal.cocoa.NSAttributedString; | |
19 import dwt.internal.cocoa.NSDictionary; | |
20 import dwt.internal.cocoa.NSFont; | |
21 import dwt.internal.cocoa.NSInteger; | |
22 import dwt.internal.cocoa.NSLayoutManager; | |
23 import dwt.internal.cocoa.NSObject; | |
24 import dwt.internal.cocoa.NSParagraphStyle; | |
25 import dwt.internal.cocoa.NSPoint; | |
26 import dwt.internal.cocoa.NSRange; | |
27 import dwt.internal.cocoa.NSRect; | |
28 import dwt.internal.cocoa.NSSize; | |
29 import dwt.internal.cocoa.NSText : NSWritingDirection; | |
30 import dwt.internal.cocoa.NSTextContainer; | |
31 import dwt.internal.cocoa.NSTextTab; | |
32 import dwt.internal.cocoa.OS; | |
33 import objc = dwt.internal.objc.runtime; | |
34 | |
35 enum NSTypesetterControlCharacterAction : NSUInteger | |
36 { | |
37 NSTypesetterZeroAdvancementAction = (1 << 0), | |
38 NSTypesetterWhitespaceAction = (1 << 1), | |
39 NSTypesetterHorizontalTabAction = (1 << 2), | |
40 NSTypesetterLineBreakAction = (1 << 3), | |
41 NSTypesetterParagraphBreakAction = (1 << 4), | |
42 NSTypesetterContainerBreakAction = (1 << 5) | |
43 } | |
44 | |
45 alias NSTypesetterControlCharacterAction.NSTypesetterZeroAdvancementAction NSTypesetterZeroAdvancementAction; | |
46 alias NSTypesetterControlCharacterAction.NSTypesetterWhitespaceAction NSTypesetterWhitespaceAction; | |
47 alias NSTypesetterControlCharacterAction.NSTypesetterHorizontalTabAction NSTypesetterHorizontalTabAction; | |
48 alias NSTypesetterControlCharacterAction.NSTypesetterLineBreakAction NSTypesetterLineBreakAction; | |
49 alias NSTypesetterControlCharacterAction.NSTypesetterParagraphBreakAction NSTypesetterParagraphBreakAction; | |
50 alias NSTypesetterControlCharacterAction.NSTypesetterContainerBreakAction NSTypesetterContainerBreakAction; | |
51 | |
52 public class NSTypesetter : NSObject | |
53 { | |
54 | |
55 public this () | |
56 { | |
57 super(); | |
58 } | |
59 | |
60 public this (objc.id id) | |
61 { | |
62 super(id); | |
63 } | |
64 | |
65 public NSTypesetterControlCharacterAction actionForControlCharacterAtIndex (NSUInteger charIndex) | |
66 { | |
67 return cast(NSTypesetterControlCharacterAction) OS.objc_msgSend(this.id, OS.sel_actionForControlCharacterAtIndex_1, charIndex); | |
68 } | |
69 | |
70 public NSAttributedString attributedString () | |
71 { | |
72 objc.id result = OS.objc_msgSend(this.id, OS.sel_attributedString); | |
73 return result !is null ? new NSAttributedString(result) : null; | |
74 } | |
75 | |
76 public NSDictionary attributesForExtraLineFragment () | |
77 { | |
78 objc.id result = OS.objc_msgSend(this.id, OS.sel_attributesForExtraLineFragment); | |
79 return result !is null ? new NSDictionary(result) : null; | |
80 } | |
81 | |
82 public CGFloat baselineOffsetInLayoutManager (NSLayoutManager layoutMgr, NSUInteger glyphIndex) | |
83 { | |
84 return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_baselineOffsetInLayoutManager_1glyphIndex_1, | |
85 layoutMgr !is null ? layoutMgr.id : null, glyphIndex); | |
86 } | |
87 | |
88 public void beginLineWithGlyphAtIndex (NSUInteger glyphIndex) | |
89 { | |
90 OS.objc_msgSend(this.id, OS.sel_beginLineWithGlyphAtIndex_1, glyphIndex); | |
91 } | |
92 | |
93 public void beginParagraph () | |
94 { | |
95 OS.objc_msgSend(this.id, OS.sel_beginParagraph); | |
96 } | |
97 | |
98 public bool bidiProcessingEnabled () | |
99 { | |
100 return OS.objc_msgSend(this.id, OS.sel_bidiProcessingEnabled) !is null; | |
101 } | |
102 | |
103 public NSRect boundingBoxForControlGlyphAtIndex (NSUInteger glyphIndex, NSTextContainer textContainer, NSRect proposedRect, | |
104 NSPoint glyphPosition, NSUInteger charIndex) | |
105 { | |
106 NSRect result; | |
107 OS.objc_msgSend_stret(result, this.id, | |
108 OS.sel_boundingBoxForControlGlyphAtIndex_1forTextContainer_1proposedLineFragment_1glyphPosition_1characterIndex_1, glyphIndex, | |
109 textContainer !is null ? textContainer.id : null, proposedRect, glyphPosition, charIndex); | |
110 return result; | |
111 } | |
112 | |
113 public NSRange characterRangeForGlyphRange (NSRange glyphRange, NSRangePointer actualGlyphRange) | |
114 { | |
115 NSRange result; | |
116 OS.objc_msgSend_stret(result, this.id, OS.sel_characterRangeForGlyphRange_1actualGlyphRange_1, glyphRange, actualGlyphRange); | |
117 return result; | |
118 } | |
119 | |
120 public NSParagraphStyle currentParagraphStyle () | |
121 { | |
122 objc.id result = OS.objc_msgSend(this.id, OS.sel_currentParagraphStyle); | |
123 return result !is null ? new NSParagraphStyle(result) : null; | |
124 } | |
125 | |
126 public NSTextContainer currentTextContainer () | |
127 { | |
128 objc.id result = OS.objc_msgSend(this.id, OS.sel_currentTextContainer); | |
129 return result !is null ? new NSTextContainer(result) : null; | |
130 } | |
131 | |
132 public static NSTypesetterBehavior defaultTypesetterBehavior () | |
133 { | |
134 return cast(NSTypesetterBehavior) OS.objc_msgSend(OS.class_NSTypesetter, OS.sel_defaultTypesetterBehavior); | |
135 } | |
136 | |
137 public void deleteGlyphsInRange (NSRange glyphRange) | |
138 { | |
139 OS.objc_msgSend(this.id, OS.sel_deleteGlyphsInRange_1, glyphRange); | |
140 } | |
141 | |
142 public void endLineWithGlyphRange (NSRange lineGlyphRange) | |
143 { | |
144 OS.objc_msgSend(this.id, OS.sel_endLineWithGlyphRange_1, lineGlyphRange); | |
145 } | |
146 | |
147 public void endParagraph () | |
148 { | |
149 OS.objc_msgSend(this.id, OS.sel_endParagraph); | |
150 } | |
151 | |
152 public NSUInteger getGlyphsInRange (NSRange glyphsRange, NSGlyph* glyphBuffer, NSUInteger* charIndexBuffer, NSGlyphInscription* inscribeBuffer, | |
153 bool* elasticBuffer, /*unsigned char* */ubyte* bidiLevelBuffer) | |
154 { | |
155 return cast(NSUInteger) OS.objc_msgSend(this.id, | |
156 OS.sel_getGlyphsInRange_1glyphs_1characterIndexes_1glyphInscriptions_1elasticBits_1bidiLevels_1, glyphsRange, glyphBuffer, | |
157 charIndexBuffer, inscribeBuffer, elasticBuffer, bidiLevelBuffer); | |
158 } | |
159 | |
160 public void getLineFragmentRect_usedRect_forParagraphSeparatorGlyphRange_atProposedOrigin_ (NSRectPointer lineFragmentRect, | |
161 NSRectPointer lineFragmentUsedRect, NSRange paragraphSeparatorGlyphRange, NSPoint lineOrigin) | |
162 { | |
163 OS.objc_msgSend(this.id, OS.sel_getLineFragmentRect_1usedRect_1forParagraphSeparatorGlyphRange_1atProposedOrigin_1, lineFragmentRect, | |
164 lineFragmentUsedRect, paragraphSeparatorGlyphRange, lineOrigin); | |
165 } | |
166 | |
167 public void getLineFragmentRect_usedRect_remainingRect_forStartingGlyphAtIndex_proposedRect_lineSpacing_paragraphSpacingBefore_paragraphSpacingAfter_ ( | |
168 NSRectPointer lineFragmentRect, NSRectPointer lineFragmentUsedRect, NSRectPointer remainingRect, NSUInteger startingGlyphIndex, | |
169 NSRect proposedRect, CGFloat lineSpacing, CGFloat paragraphSpacingBefore, CGFloat paragraphSpacingAfter) | |
170 { | |
171 OS.objc_msgSend( | |
172 this.id, | |
173 OS.sel_getLineFragmentRect_1usedRect_1remainingRect_1forStartingGlyphAtIndex_1proposedRect_1lineSpacing_1paragraphSpacingBefore_1paragraphSpacingAfter_1, | |
174 lineFragmentRect, lineFragmentUsedRect, remainingRect, startingGlyphIndex, proposedRect, lineSpacing, paragraphSpacingBefore, | |
175 paragraphSpacingAfter); | |
176 } | |
177 | |
178 public NSRange glyphRangeForCharacterRange (NSRange charRange, NSRangePointer actualCharRange) | |
179 { | |
180 NSRange result; | |
181 OS.objc_msgSend_stret(result, this.id, OS.sel_glyphRangeForCharacterRange_1actualCharacterRange_1, charRange, actualCharRange); | |
182 return result; | |
183 } | |
184 | |
185 public /*UTF32Char*/dchar hyphenCharacterForGlyphAtIndex (NSUInteger glyphIndex) | |
186 { | |
187 return cast(/*UTF32Char*/dchar) OS.objc_msgSend(this.id, OS.sel_hyphenCharacterForGlyphAtIndex_1, glyphIndex); | |
188 } | |
189 | |
190 public float hyphenationFactor () | |
191 { | |
192 return cast(float) OS.objc_msgSend_fpret(this.id, OS.sel_hyphenationFactor); | |
193 } | |
194 | |
195 public float hyphenationFactorForGlyphAtIndex (NSUInteger glyphIndex) | |
196 { | |
197 return cast(float) OS.objc_msgSend_fpret(this.id, OS.sel_hyphenationFactorForGlyphAtIndex_1, glyphIndex); | |
198 } | |
199 | |
200 public void insertGlyph (NSGlyph glyph, NSUInteger glyphIndex, NSUInteger characterIndex) | |
201 { | |
202 OS.objc_msgSend(this.id, OS.sel_insertGlyph_1atGlyphIndex_1characterIndex_1, glyph, glyphIndex, characterIndex); | |
203 } | |
204 | |
205 public NSRange layoutCharactersInRange (NSRange characterRange, NSLayoutManager layoutManager, NSUInteger maxNumLines) | |
206 { | |
207 NSRange result; | |
208 OS.objc_msgSend_stret(result, this.id, OS.sel_layoutCharactersInRange_1forLayoutManager_1maximumNumberOfLineFragments_1, characterRange, | |
209 layoutManager !is null ? layoutManager.id : null, maxNumLines); | |
210 return result; | |
211 } | |
212 | |
213 public void layoutGlyphsInLayoutManager (NSLayoutManager layoutManager, NSUInteger startGlyphIndex, NSUInteger maxNumLines, NSUInteger* nextGlyph) | |
214 { | |
215 OS.objc_msgSend(this.id, OS.sel_layoutGlyphsInLayoutManager_1startingAtGlyphIndex_1maxNumberOfLineFragments_1nextGlyphIndex_1, | |
216 layoutManager !is null ? layoutManager.id : null, startGlyphIndex, maxNumLines, nextGlyph); | |
217 } | |
218 | |
219 public NSLayoutManager layoutManager () | |
220 { | |
221 objc.id result = OS.objc_msgSend(this.id, OS.sel_layoutManager); | |
222 return result !is null ? new NSLayoutManager(result) : null; | |
223 } | |
224 | |
225 public NSUInteger layoutParagraphAtPoint (NSPointPointer lineFragmentOrigin) | |
226 { | |
227 return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_layoutParagraphAtPoint_1, lineFragmentOrigin); | |
228 } | |
229 | |
230 public CGFloat lineFragmentPadding () | |
231 { | |
232 return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_lineFragmentPadding); | |
233 } | |
234 | |
235 public CGFloat lineSpacingAfterGlyphAtIndex (NSUInteger glyphIndex, NSRect rect) | |
236 { | |
237 return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_lineSpacingAfterGlyphAtIndex_1withProposedLineFragmentRect_1, glyphIndex, rect); | |
238 } | |
239 | |
240 public NSRange paragraphCharacterRange () | |
241 { | |
242 NSRange result; | |
243 OS.objc_msgSend_stret(result, this.id, OS.sel_paragraphCharacterRange); | |
244 return result; | |
245 } | |
246 | |
247 public NSRange paragraphGlyphRange () | |
248 { | |
249 NSRange result; | |
250 OS.objc_msgSend_stret(result, this.id, OS.sel_paragraphGlyphRange); | |
251 return result; | |
252 } | |
253 | |
254 public NSRange paragraphSeparatorCharacterRange () | |
255 { | |
256 NSRange result; | |
257 OS.objc_msgSend_stret(result, this.id, OS.sel_paragraphSeparatorCharacterRange); | |
258 return result; | |
259 } | |
260 | |
261 public NSRange paragraphSeparatorGlyphRange () | |
262 { | |
263 NSRange result; | |
264 OS.objc_msgSend_stret(result, this.id, OS.sel_paragraphSeparatorGlyphRange); | |
265 return result; | |
266 } | |
267 | |
268 public CGFloat paragraphSpacingAfterGlyphAtIndex (NSUInteger glyphIndex, NSRect rect) | |
269 { | |
270 return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_paragraphSpacingAfterGlyphAtIndex_1withProposedLineFragmentRect_1, glyphIndex, rect); | |
271 } | |
272 | |
273 public CGFloat paragraphSpacingBeforeGlyphAtIndex (NSUInteger glyphIndex, NSRect rect) | |
274 { | |
275 return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_paragraphSpacingBeforeGlyphAtIndex_1withProposedLineFragmentRect_1, glyphIndex, rect); | |
276 } | |
277 | |
278 public static NSSize printingAdjustmentInLayoutManager (NSLayoutManager layoutMgr, NSRange nominallySpacedGlyphsRange, | |
279 /*const unsigned char* */ubyte* packedGlyphs, NSUInteger packedGlyphsCount) | |
280 { | |
281 NSSize result; | |
282 OS.objc_msgSend_stret(result, OS.class_NSTypesetter, | |
283 OS.sel_printingAdjustmentInLayoutManager_1forNominallySpacedGlyphRange_1packedGlyphs_1count_1, | |
284 layoutMgr !is null ? layoutMgr.id : null, nominallySpacedGlyphsRange, packedGlyphs, packedGlyphsCount); | |
285 return result; | |
286 } | |
287 | |
288 public void setAttachmentSize (NSSize attachmentSize, NSRange glyphRange) | |
289 { | |
290 OS.objc_msgSend(this.id, OS.sel_setAttachmentSize_1forGlyphRange_1, attachmentSize, glyphRange); | |
291 } | |
292 | |
293 public void setAttributedString (NSAttributedString attrString) | |
294 { | |
295 OS.objc_msgSend(this.id, OS.sel_setAttributedString_1, attrString !is null ? attrString.id : null); | |
296 } | |
297 | |
298 public void setBidiLevels (/*const uint8_t* */ubyte* levels, NSRange glyphRange) | |
299 { | |
300 OS.objc_msgSend(this.id, OS.sel_setBidiLevels_1forGlyphRange_1, levels, glyphRange); | |
301 } | |
302 | |
303 public void setBidiProcessingEnabled (bool flag) | |
304 { | |
305 OS.objc_msgSend(this.id, OS.sel_setBidiProcessingEnabled_1, flag); | |
306 } | |
307 | |
308 public void setDrawsOutsideLineFragment (bool flag, NSRange glyphRange) | |
309 { | |
310 OS.objc_msgSend(this.id, OS.sel_setDrawsOutsideLineFragment_1forGlyphRange_1, flag, glyphRange); | |
311 } | |
312 | |
313 public void setHardInvalidation (bool flag, NSRange glyphRange) | |
314 { | |
315 OS.objc_msgSend(this.id, OS.sel_setHardInvalidation_1forGlyphRange_1, flag, glyphRange); | |
316 } | |
317 | |
318 public void setHyphenationFactor (float factor) | |
319 { | |
320 OS.objc_msgSend(this.id, OS.sel_setHyphenationFactor_1, factor); | |
321 } | |
322 | |
323 public void setLineFragmentPadding (CGFloat padding) | |
324 { | |
325 OS.objc_msgSend(this.id, OS.sel_setLineFragmentPadding_1, padding); | |
326 } | |
327 | |
328 public void setLineFragmentRect (NSRect fragmentRect, NSRange glyphRange, NSRect usedRect, CGFloat baselineOffset) | |
329 { | |
330 OS.objc_msgSend(this.id, OS.sel_setLineFragmentRect_1forGlyphRange_1usedRect_1baselineOffset_1, fragmentRect, glyphRange, usedRect, | |
331 baselineOffset); | |
332 } | |
333 | |
334 public void setLocation (NSPoint location, /*const CGFloat* */CGFloat* advancements, NSRange glyphRange) | |
335 { | |
336 OS.objc_msgSend(this.id, OS.sel_setLocation_1withAdvancements_1forStartOfGlyphRange_1, location, advancements, glyphRange); | |
337 } | |
338 | |
339 public void setNotShownAttribute (bool flag, NSRange glyphRange) | |
340 { | |
341 OS.objc_msgSend(this.id, OS.sel_setNotShownAttribute_1forGlyphRange_1, flag, glyphRange); | |
342 } | |
343 | |
344 public void setParagraphGlyphRange (NSRange paragraphRange, NSRange paragraphSeparatorRange) | |
345 { | |
346 OS.objc_msgSend(this.id, OS.sel_setParagraphGlyphRange_1separatorGlyphRange_1, paragraphRange, paragraphSeparatorRange); | |
347 } | |
348 | |
349 public void setTypesetterBehavior (NSTypesetterBehavior behavior) | |
350 { | |
351 OS.objc_msgSend(this.id, OS.sel_setTypesetterBehavior_1, behavior); | |
352 } | |
353 | |
354 public void setUsesFontLeading (bool flag) | |
355 { | |
356 OS.objc_msgSend(this.id, OS.sel_setUsesFontLeading_1, flag); | |
357 } | |
358 | |
359 public static id sharedSystemTypesetter () | |
360 { | |
361 objc.id result = OS.objc_msgSend(OS.class_NSTypesetter, OS.sel_sharedSystemTypesetter); | |
362 return result !is null ? new id(result) : null; | |
363 } | |
364 | |
365 public static id sharedSystemTypesetterForBehavior (NSTypesetterBehavior theBehavior) | |
366 { | |
367 objc.id result = OS.objc_msgSend(OS.class_NSTypesetter, OS.sel_sharedSystemTypesetterForBehavior_1, theBehavior); | |
368 return result !is null ? new id(result) : null; | |
369 } | |
370 | |
371 public bool shouldBreakLineByHyphenatingBeforeCharacterAtIndex (NSUInteger charIndex) | |
372 { | |
373 return OS.objc_msgSend(this.id, OS.sel_shouldBreakLineByHyphenatingBeforeCharacterAtIndex_1, charIndex) !is null; | |
374 } | |
375 | |
376 public bool shouldBreakLineByWordBeforeCharacterAtIndex (NSUInteger charIndex) | |
377 { | |
378 return OS.objc_msgSend(this.id, OS.sel_shouldBreakLineByWordBeforeCharacterAtIndex_1, charIndex) !is null; | |
379 } | |
380 | |
381 public NSFont substituteFontForFont (NSFont originalFont) | |
382 { | |
383 objc.id result = OS.objc_msgSend(this.id, OS.sel_substituteFontForFont_1, originalFont !is null ? originalFont.id : null); | |
384 return result !is null ? new NSFont(result) : null; | |
385 } | |
386 | |
387 public void substituteGlyphsInRange (NSRange glyphRange, NSGlyph* glyphs) | |
388 { | |
389 OS.objc_msgSend(this.id, OS.sel_substituteGlyphsInRange_1withGlyphs_1, glyphRange, glyphs); | |
390 } | |
391 | |
392 public NSArray textContainers () | |
393 { | |
394 objc.id result = OS.objc_msgSend(this.id, OS.sel_textContainers); | |
395 return result !is null ? new NSArray(result) : null; | |
396 } | |
397 | |
398 public NSTextTab textTabForGlyphLocation (CGFloat glyphLocation, NSWritingDirection direction, CGFloat maxLocation) | |
399 { | |
400 objc.id result = OS.objc_msgSend(this.id, OS.sel_textTabForGlyphLocation_1writingDirection_1maxLocation_1, glyphLocation, direction, | |
401 maxLocation); | |
402 return result !is null ? new NSTextTab(result) : null; | |
403 } | |
404 | |
405 public NSTypesetterBehavior typesetterBehavior () | |
406 { | |
407 return cast(NSTypesetterBehavior) OS.objc_msgSend(this.id, OS.sel_typesetterBehavior); | |
408 } | |
409 | |
410 public bool usesFontLeading () | |
411 { | |
412 return OS.objc_msgSend(this.id, OS.sel_usesFontLeading) !is null; | |
413 } | |
414 | |
415 public void willSetLineFragmentRect (NSRectPointer lineRect, NSRange glyphRange, NSRectPointer usedRect, CGFloat* baselineOffset) | |
416 { | |
417 OS.objc_msgSend(this.id, OS.sel_willSetLineFragmentRect_1forGlyphRange_1usedRect_1baselineOffset_1, lineRect, glyphRange, usedRect, | |
418 baselineOffset); | |
419 } | |
420 | |
421 } |