comparison dwt/internal/cocoa/NSTypesetter.d @ 45:d8635bb48c7c

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