Mercurial > projects > dstep
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dstep/appkit/NSSimpleHorizontalTypesetter.d Sun Jan 03 22:06:11 2010 +0100 @@ -0,0 +1,227 @@ +/** + * Copyright: Copyright (c) 2009 Jacob Carlborg. + * Authors: Jacob Carlborg + * Version: Initial created: Sep 24, 2009 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module dstep.appkit.NSSimpleHorizontalTypesetter; + +import dstep.appkit.NSFont; +import dstep.appkit.NSLayoutManager; +import dstep.appkit.NSParagraphStyle; +import dstep.appkit.NSTextContainer; +import dstep.appkit.NSTextStorage; +import dstep.appkit.NSTypesetter; +import dstep.internal.Version; +import dstep.foundation.NSGeometry; +import dstep.foundation.NSObjCRuntime; +import dstep.foundation.NSRange; +import dstep.objc.bridge.Bridge; +import dstep.objc.objc; + +version (D_LP64) +{ + pragma(msg, "warning: NSSimpleHorizontalTypesetter is deprecated starting from Mac OS X 10.4 Tiger."); + pragma(msg, "warning: Developers are recommended to adopt NSATSTypesetter, the default concrete subclass from Mac OS X 10.3 Panther."); +} + +else: + +typedef int NSLayoutStatus; + +enum +{ + NSLayoutNotDone = 0, + NSLayoutDone, + NSLayoutCantFit, + NSLayoutOutOfGlyphs +} + +typedef int NSGlyphLayoutMode; + +enum +{ + NSGlyphLayoutAtAPoint = 0, + NSGlyphLayoutAgainstAPoint, + NSGlyphLayoutWithPrevious +} + +typedef int NSLayoutDirection; + +enum +{ + NSLayoutLeftToRight = 0, + NSLayoutRightToLeft +} + +const NSBaselineNotSet = -1.0; +const NumGlyphsToGetEachTime = 20; + +alias extern (C) NSPoint function (id obj, SEL sel, NSGlyph cur, NSGlyph prev, bool isNominal) _NSPositionOfGlyphMethod; + +struct NSTypesetterGlyphInfo +{ + NSPoint curLocation; + float extent; + float belowBaseline; + float aboveBaseline; + uint glyphCharacterIndex; + id font; + NSSize attachmentSize; + + struct + { + uint defaultPositioning; //:1 + uint dontShow; //:1 + uint isAttachment; //:1 + } +} + +const TNSTypesetterSubclassExtensions = ` + + void typesetterLaidOneGlyph (NSTypesetterGlyphInfo* gl) + { + return invokeObjcSelf!(void, "typesetterLaidOneGlyph:", NSTypesetterGlyphInfo*)(gl); + } + + void willSetLineFragmentRect (NSRect* aRect, NSRange aRange, NSRect* bRect) + { + return invokeObjcSelf!(void, "willSetLineFragmentRect:forGlyphRange:usedRect:", NSRect*, NSRange, NSRect*)(aRect, aRange, bRect); + } +`; + +class NSSimpleHorizontalTypesetter : NSTypesetter +{ + mixin (ObjcWrap); + + static NSSimpleHorizontalTypesetter sharedInstance () + { + return invokeObjcSelfClass!(NSSimpleHorizontalTypesetter, "sharedInstance"); + } + + NSLayoutManager currentLayoutManager () + { + return invokeObjcSelf!(NSLayoutManager, "currentLayoutManager"); + } + + NSTextContainer currentContainer () + { + return invokeObjcSelf!(NSTextContainer, "currentContainer"); + } + + NSParagraphStyle currentParagraphStyle () + { + return invokeObjcSelf!(NSParagraphStyle, "currentParagraphStyle"); + } + + NSTextStorage currentTextStorage () + { + return invokeObjcSelf!(NSTextStorage, "currentTextStorage"); + } + + NSTypesetterGlyphInfo baseOfTypesetterGlyphInfo () + { + return invokeObjcSelf!(NSTypesetterGlyphInfo, "baseOfTypesetterGlyphInfo"); + } + + NSUInteger sizeOfTypesetterGlyphInfo () + { + return invokeObjcSelf!(NSUInteger, "sizeOfTypesetterGlyphInfo"); + } + + NSUInteger capacityOfTypesetterGlyphInfo () + { + return invokeObjcSelf!(NSUInteger, "capacityOfTypesetterGlyphInfo"); + } + + NSUInteger firstGlyphIndexOfCurrentLineFragment () + { + return invokeObjcSelf!(NSUInteger, "firstGlyphIndexOfCurrentLineFragment"); + } + + void layoutGlyphsInLayoutManager (NSLayoutManager layoutManager, NSUInteger startGlyphIndex, NSUInteger maxNumLines, out NSUInteger nextGlyphIndex) + { + return invokeObjcSelf!(void, "layoutGlyphsInLayoutManager:startingAtGlyphIndex:maxNumberOfLineFragments:nextGlyphIndex:", NSLayoutManager, NSUInteger, NSUInteger, NSUInteger*)(layoutManager, startGlyphIndex, maxNumLines, &nextGlyphIndex); + } + + NSLayoutStatus layoutGlyphsInHorizontalLineFragment (NSRect* lineFragmentRect, float* baseline) + { + return invokeObjcSelf!(NSLayoutStatus, "layoutGlyphsInHorizontalLineFragment:baseline:", NSRect*, float*)(lineFragmentRect, baseline); + } + + void clearGlyphCache () + { + return invokeObjcSelf!(void, "clearGlyphCache"); + } + + void fillAttributesCache () + { + return invokeObjcSelf!(void, "fillAttributesCache"); + } + + void clearAttributesCache () + { + return invokeObjcSelf!(void, "clearAttributesCache"); + } + + NSUInteger growGlyphCaches (NSUInteger desiredCapacity, bool fillGlyphInfo) + { + return invokeObjcSelf!(NSUInteger, "growGlyphCaches:fillGlyphInfo:", NSUInteger, bool)(desiredCapacity, fillGlyphInfo); + } + + void updateCurGlyphOffset () + { + return invokeObjcSelf!(void, "updateCurGlyphOffset"); + } + + void insertGlyph (NSGlyph glyph, NSUInteger glyphIndex, NSUInteger charIndex) + { + return invokeObjcSelf!(void, "insertGlyph:atGlyphIndex:characterIndex:", NSGlyph, NSUInteger, NSUInteger)(glyph, glyphIndex, charIndex); + } + + NSLayoutStatus layoutControlGlyphForLineFragment (NSRect lineFrag) + { + return invokeObjcSelf!(NSLayoutStatus, "layoutControlGlyphForLineFragment:", NSRect)(lineFrag); + } + + void layoutTab () + { + return invokeObjcSelf!(void, "layoutTab"); + } + + void breakLineAtIndex (NSUInteger location) + { + return invokeObjcSelf!(void, "breakLineAtIndex:", NSUInteger)(location); + } + + NSUInteger glyphIndexToBreakLineByHyphenatingWordAtIndex (NSUInteger charIndex) + { + return invokeObjcSelf!(NSUInteger, "glyphIndexToBreakLineByHyphenatingWordAtIndex:", NSUInteger)(charIndex); + } + + NSUInteger glyphIndexToBreakLineByWordWrappingAtIndex (NSUInteger charIndex) + { + return invokeObjcSelf!(NSUInteger, "glyphIndexToBreakLineByWordWrappingAtIndex:", NSUInteger)(charIndex); + } + + NSLayoutStatus layoutControlGlyphForLineFragment (NSRect lineFrag) + { + return invokeObjcSelf!(NSLayoutStatus, "layoutControlGlyphForLineFragment:", NSRect)(lineFrag); + } + + void fullJustifyLineAtGlyphIndex (NSUInteger glyphIndexForLineBreak) + { + return invokeObjcSelf!(void, "fullJustifyLineAtGlyphIndex:", NSUInteger)(glyphIndexForLineBreak); + } + + // NSTypesetterSubclassExtensions + void typesetterLaidOneGlyph (NSTypesetterGlyphInfo* gl) + { + return invokeObjcSelf!(void, "typesetterLaidOneGlyph:", NSTypesetterGlyphInfo*)(gl); + } + + void willSetLineFragmentRect (NSRect* aRect, NSRange aRange, NSRect* bRect) + { + return invokeObjcSelf!(void, "willSetLineFragmentRect:forGlyphRange:usedRect:", NSRect*, NSRange, NSRect*)(aRect, aRange, bRect); + } +} \ No newline at end of file