comparison dstep/appkit/NSSimpleHorizontalTypesetter.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents
children f8a3b67adfcb
comparison
equal deleted inserted replaced
15:7ff919f595d5 16:19885b43130e
1 /**
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
3 * Authors: Jacob Carlborg
4 * Version: Initial created: Sep 24, 2009
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */
7 module dstep.appkit.NSSimpleHorizontalTypesetter;
8
9 import dstep.appkit.NSFont;
10 import dstep.appkit.NSLayoutManager;
11 import dstep.appkit.NSParagraphStyle;
12 import dstep.appkit.NSTextContainer;
13 import dstep.appkit.NSTextStorage;
14 import dstep.appkit.NSTypesetter;
15 import dstep.internal.Version;
16 import dstep.foundation.NSGeometry;
17 import dstep.foundation.NSObjCRuntime;
18 import dstep.foundation.NSRange;
19 import dstep.objc.bridge.Bridge;
20 import dstep.objc.objc;
21
22 version (D_LP64)
23 {
24 pragma(msg, "warning: NSSimpleHorizontalTypesetter is deprecated starting from Mac OS X 10.4 Tiger.");
25 pragma(msg, "warning: Developers are recommended to adopt NSATSTypesetter, the default concrete subclass from Mac OS X 10.3 Panther.");
26 }
27
28 else:
29
30 typedef int NSLayoutStatus;
31
32 enum
33 {
34 NSLayoutNotDone = 0,
35 NSLayoutDone,
36 NSLayoutCantFit,
37 NSLayoutOutOfGlyphs
38 }
39
40 typedef int NSGlyphLayoutMode;
41
42 enum
43 {
44 NSGlyphLayoutAtAPoint = 0,
45 NSGlyphLayoutAgainstAPoint,
46 NSGlyphLayoutWithPrevious
47 }
48
49 typedef int NSLayoutDirection;
50
51 enum
52 {
53 NSLayoutLeftToRight = 0,
54 NSLayoutRightToLeft
55 }
56
57 const NSBaselineNotSet = -1.0;
58 const NumGlyphsToGetEachTime = 20;
59
60 alias extern (C) NSPoint function (id obj, SEL sel, NSGlyph cur, NSGlyph prev, bool isNominal) _NSPositionOfGlyphMethod;
61
62 struct NSTypesetterGlyphInfo
63 {
64 NSPoint curLocation;
65 float extent;
66 float belowBaseline;
67 float aboveBaseline;
68 uint glyphCharacterIndex;
69 id font;
70 NSSize attachmentSize;
71
72 struct
73 {
74 uint defaultPositioning; //:1
75 uint dontShow; //:1
76 uint isAttachment; //:1
77 }
78 }
79
80 const TNSTypesetterSubclassExtensions = `
81
82 void typesetterLaidOneGlyph (NSTypesetterGlyphInfo* gl)
83 {
84 return invokeObjcSelf!(void, "typesetterLaidOneGlyph:", NSTypesetterGlyphInfo*)(gl);
85 }
86
87 void willSetLineFragmentRect (NSRect* aRect, NSRange aRange, NSRect* bRect)
88 {
89 return invokeObjcSelf!(void, "willSetLineFragmentRect:forGlyphRange:usedRect:", NSRect*, NSRange, NSRect*)(aRect, aRange, bRect);
90 }
91 `;
92
93 class NSSimpleHorizontalTypesetter : NSTypesetter
94 {
95 mixin (ObjcWrap);
96
97 static NSSimpleHorizontalTypesetter sharedInstance ()
98 {
99 return invokeObjcSelfClass!(NSSimpleHorizontalTypesetter, "sharedInstance");
100 }
101
102 NSLayoutManager currentLayoutManager ()
103 {
104 return invokeObjcSelf!(NSLayoutManager, "currentLayoutManager");
105 }
106
107 NSTextContainer currentContainer ()
108 {
109 return invokeObjcSelf!(NSTextContainer, "currentContainer");
110 }
111
112 NSParagraphStyle currentParagraphStyle ()
113 {
114 return invokeObjcSelf!(NSParagraphStyle, "currentParagraphStyle");
115 }
116
117 NSTextStorage currentTextStorage ()
118 {
119 return invokeObjcSelf!(NSTextStorage, "currentTextStorage");
120 }
121
122 NSTypesetterGlyphInfo baseOfTypesetterGlyphInfo ()
123 {
124 return invokeObjcSelf!(NSTypesetterGlyphInfo, "baseOfTypesetterGlyphInfo");
125 }
126
127 NSUInteger sizeOfTypesetterGlyphInfo ()
128 {
129 return invokeObjcSelf!(NSUInteger, "sizeOfTypesetterGlyphInfo");
130 }
131
132 NSUInteger capacityOfTypesetterGlyphInfo ()
133 {
134 return invokeObjcSelf!(NSUInteger, "capacityOfTypesetterGlyphInfo");
135 }
136
137 NSUInteger firstGlyphIndexOfCurrentLineFragment ()
138 {
139 return invokeObjcSelf!(NSUInteger, "firstGlyphIndexOfCurrentLineFragment");
140 }
141
142 void layoutGlyphsInLayoutManager (NSLayoutManager layoutManager, NSUInteger startGlyphIndex, NSUInteger maxNumLines, out NSUInteger nextGlyphIndex)
143 {
144 return invokeObjcSelf!(void, "layoutGlyphsInLayoutManager:startingAtGlyphIndex:maxNumberOfLineFragments:nextGlyphIndex:", NSLayoutManager, NSUInteger, NSUInteger, NSUInteger*)(layoutManager, startGlyphIndex, maxNumLines, &nextGlyphIndex);
145 }
146
147 NSLayoutStatus layoutGlyphsInHorizontalLineFragment (NSRect* lineFragmentRect, float* baseline)
148 {
149 return invokeObjcSelf!(NSLayoutStatus, "layoutGlyphsInHorizontalLineFragment:baseline:", NSRect*, float*)(lineFragmentRect, baseline);
150 }
151
152 void clearGlyphCache ()
153 {
154 return invokeObjcSelf!(void, "clearGlyphCache");
155 }
156
157 void fillAttributesCache ()
158 {
159 return invokeObjcSelf!(void, "fillAttributesCache");
160 }
161
162 void clearAttributesCache ()
163 {
164 return invokeObjcSelf!(void, "clearAttributesCache");
165 }
166
167 NSUInteger growGlyphCaches (NSUInteger desiredCapacity, bool fillGlyphInfo)
168 {
169 return invokeObjcSelf!(NSUInteger, "growGlyphCaches:fillGlyphInfo:", NSUInteger, bool)(desiredCapacity, fillGlyphInfo);
170 }
171
172 void updateCurGlyphOffset ()
173 {
174 return invokeObjcSelf!(void, "updateCurGlyphOffset");
175 }
176
177 void insertGlyph (NSGlyph glyph, NSUInteger glyphIndex, NSUInteger charIndex)
178 {
179 return invokeObjcSelf!(void, "insertGlyph:atGlyphIndex:characterIndex:", NSGlyph, NSUInteger, NSUInteger)(glyph, glyphIndex, charIndex);
180 }
181
182 NSLayoutStatus layoutControlGlyphForLineFragment (NSRect lineFrag)
183 {
184 return invokeObjcSelf!(NSLayoutStatus, "layoutControlGlyphForLineFragment:", NSRect)(lineFrag);
185 }
186
187 void layoutTab ()
188 {
189 return invokeObjcSelf!(void, "layoutTab");
190 }
191
192 void breakLineAtIndex (NSUInteger location)
193 {
194 return invokeObjcSelf!(void, "breakLineAtIndex:", NSUInteger)(location);
195 }
196
197 NSUInteger glyphIndexToBreakLineByHyphenatingWordAtIndex (NSUInteger charIndex)
198 {
199 return invokeObjcSelf!(NSUInteger, "glyphIndexToBreakLineByHyphenatingWordAtIndex:", NSUInteger)(charIndex);
200 }
201
202 NSUInteger glyphIndexToBreakLineByWordWrappingAtIndex (NSUInteger charIndex)
203 {
204 return invokeObjcSelf!(NSUInteger, "glyphIndexToBreakLineByWordWrappingAtIndex:", NSUInteger)(charIndex);
205 }
206
207 NSLayoutStatus layoutControlGlyphForLineFragment (NSRect lineFrag)
208 {
209 return invokeObjcSelf!(NSLayoutStatus, "layoutControlGlyphForLineFragment:", NSRect)(lineFrag);
210 }
211
212 void fullJustifyLineAtGlyphIndex (NSUInteger glyphIndexForLineBreak)
213 {
214 return invokeObjcSelf!(void, "fullJustifyLineAtGlyphIndex:", NSUInteger)(glyphIndexForLineBreak);
215 }
216
217 // NSTypesetterSubclassExtensions
218 void typesetterLaidOneGlyph (NSTypesetterGlyphInfo* gl)
219 {
220 return invokeObjcSelf!(void, "typesetterLaidOneGlyph:", NSTypesetterGlyphInfo*)(gl);
221 }
222
223 void willSetLineFragmentRect (NSRect* aRect, NSRange aRange, NSRect* bRect)
224 {
225 return invokeObjcSelf!(void, "willSetLineFragmentRect:forGlyphRange:usedRect:", NSRect*, NSRange, NSRect*)(aRect, aRange, bRect);
226 }
227 }