Mercurial > projects > dstep
view dstep/appkit/NSTypesetter.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 | b9de51448c6b |
line wrap: on
line source
/** * 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.NSTypesetter; import dstep.appkit.NSFont; import dstep.appkit.NSLayoutManager; import dstep.appkit.NSParagraphStyle; import dstep.appkit.NSSimpleHorizontalTypesetter; import dstep.appkit.NSTextContainer; import dstep.applicationservices.coregraphics.CGBase; import dstep.corefoundation.CFCharacterSet; import dstep.foundation.NSArray; import dstep.foundation.NSAttributedString; import dstep.foundation.NSDictionary; import dstep.foundation.NSGeometry; import dstep.foundation.NSObjCRuntime; import dstep.foundation.NSObject; import dstep.foundation.NSRange; import dstep.objc.bridge.Bridge; import dstep.objc.objc; typedef NSUInteger NSTypesetterControlCharacterAction; enum : NSUInteger { NSTypesetterZeroAdvancementAction = (1 << 0), NSTypesetterWhitespaceAction = (1 << 1), NSTypesetterHorizontalTabAction = (1 << 2), NSTypesetterLineBreakAction = (1 << 3), NSTypesetterParagraphBreakAction = (1 << 4), NSTypesetterContainerBreakAction = (1 << 5) } const TNSLayoutPhaseInterface = ` void willSetLineFragmentRect (NSRectPointer lineRect, NSRange glyphRange, NSRectPointer usedRect, CGFloat* baselineOffset) { return invokeObjcSelf!(void, "willSetLineFragmentRect:forGlyphRange:usedRect:baselineOffset:", NSRectPointer, NSRange, NSRectPointer, CGFloat*)(lineRect, glyphRange, usedRect, baselineOffset); } bool shouldBreakLineByWordBeforeCharacterAtIndex (NSUInteger charIndex) { return invokeObjcSelf!(bool, "shouldBreakLineByWordBeforeCharacterAtIndex:", NSUInteger)(charIndex); } bool shouldBreakLineByHyphenatingBeforeCharacterAtIndex (NSUInteger charIndex) { return invokeObjcSelf!(bool, "shouldBreakLineByHyphenatingBeforeCharacterAtIndex:", NSUInteger)(charIndex); } float hyphenationFactorForGlyphAtIndex (NSUInteger glyphIndex) { return invokeObjcSelf!(float, "hyphenationFactorForGlyphAtIndex:", NSUInteger)(glyphIndex); } uint hyphenCharacterForGlyphAtIndex (NSUInteger glyphIndex) { return invokeObjcSelf!(uint, "hyphenCharacterForGlyphAtIndex:", NSUInteger)(glyphIndex); } NSRect boundingBoxForControlGlyphAtIndex (NSUInteger glyphIndex, NSTextContainer textContainer, NSRect proposedRect, NSPoint glyphPosition, NSUInteger charIndex) { return invokeObjcSelf!(NSRect, "boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment:glyphPosition:characterIndex:", NSUInteger, NSTextContainer, NSRect, NSPoint, NSUInteger)(glyphIndex, textContainer, proposedRect, glyphPosition, charIndex); } //mixin ObjcBindMethod!(willSetLineFragmentRect, "willSetLineFragmentRect:forGlyphRange:usedRect:baselineOffset:"); //mixin ObjcBindMethod!(shouldBreakLineByWordBeforeCharacterAtIndex, "shouldBreakLineByWordBeforeCharacterAtIndex:"); //mixin ObjcBindMethod!(shouldBreakLineByHyphenatingBeforeCharacterAtIndex, "shouldBreakLineByHyphenatingBeforeCharacterAtIndex:"); //mixin ObjcBindMethod!(hyphenationFactorForGlyphAtIndex, "hyphenationFactorForGlyphAtIndex:"); //mixin ObjcBindMethod!(hyphenCharacterForGlyphAtIndex, "hyphenCharacterForGlyphAtIndex:"); //mixin ObjcBindMethod!(boundingBoxForControlGlyphAtIndex, "boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment:glyphPosition:characterIndex:"); `; const TNSGlyphStorageInterface = ` NSRange characterRangeForGlyphRange (NSRange glyphRange, NSRangePointer actualGlyphRange) { return invokeObjcSelf!(NSRange, "characterRangeForGlyphRange:actualGlyphRange:", NSRange, NSRangePointer)(glyphRange, actualGlyphRange); } NSRange glyphRangeForCharacterRange (NSRange charRange, NSRangePointer actualCharRange) { return invokeObjcSelf!(NSRange, "glyphRangeForCharacterRange:actualCharacterRange:", NSRange, NSRangePointer)(charRange, actualCharRange); } NSUInteger getGlyphsInRange (NSRange glyphsRange, NSGlyph* glyphBuffer, NSUInteger* charIndexBuffer, NSGlyphInscription* inscribeBuffer, bool* elasticBuffer, char* bidiLevelBuffer) { return invokeObjcSelf!(NSUInteger, "getGlyphsInRange:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:", NSRange, NSGlyph*, NSUInteger*, NSGlyphInscription*, bool*, char*)(glyphsRange, glyphBuffer, charIndexBuffer, inscribeBuffer, elasticBuffer, bidiLevelBuffer); } void getLineFragmentRect (NSRectPointer lineFragmentRect, NSRectPointer lineFragmentUsedRect, NSRectPointer remainingRect, NSUInteger startingGlyphIndex, NSRect proposedRect, CGFloat lineSpacing, CGFloat paragraphSpacingBefore, CGFloat paragraphSpacingAfter) { return invokeObjcSelf!(void, "getLineFragmentRect:usedRect:remainingRect:forStartingGlyphAtIndex:proposedRect:lineSpacing:paragraphSpacingBefore:paragraphSpacingAfter:", NSRectPointer, NSRectPointer, NSRectPointer, NSUInteger, NSRect, CGFloat, CGFloat, CGFloat)(lineFragmentRect, lineFragmentUsedRect, remainingRect, startingGlyphIndex, proposedRect, lineSpacing, paragraphSpacingBefore, paragraphSpacingAfter); } void setLineFragmentRect (NSRect fragmentRect, NSRange glyphRange, NSRect usedRect, CGFloat baselineOffset) { return invokeObjcSelf!(void, "setLineFragmentRect:forGlyphRange:usedRect:baselineOffset:", NSRect, NSRange, NSRect, CGFloat)(fragmentRect, glyphRange, usedRect, baselineOffset); } void substituteGlyphsInRange (NSRange glyphRange, NSGlyph* glyphs) { return invokeObjcSelf!(void, "substituteGlyphsInRange:withGlyphs:", NSRange, NSGlyph*)(glyphRange, glyphs); } void insertGlyph (uint glyph, NSUInteger glyphIndex, NSUInteger characterIndex) { return invokeObjcSelf!(void, "insertGlyph:atGlyphIndex:characterIndex:", uint, NSUInteger, NSUInteger)(glyph, glyphIndex, characterIndex); } void deleteGlyphsInRange (NSRange glyphRange) { return invokeObjcSelf!(void, "deleteGlyphsInRange:", NSRange)(glyphRange); } void setNotShownAttribute (bool flag, NSRange glyphRange) { return invokeObjcSelf!(void, "setNotShownAttribute:forGlyphRange:", bool, NSRange)(flag, glyphRange); } void setDrawsOutsideLineFragment (bool flag, NSRange glyphRange) { return invokeObjcSelf!(void, "setDrawsOutsideLineFragment:forGlyphRange:", bool, NSRange)(flag, glyphRange); } void setLocation (NSPoint location, CGFloat* advancements, NSRange glyphRange) { return invokeObjcSelf!(void, "setLocation:withAdvancements:forStartOfGlyphRange:", NSPoint, CGFloat*, NSRange)(location, advancements, glyphRange); } void setAttachmentSize (NSSize attachmentSize, NSRange glyphRange) { return invokeObjcSelf!(void, "setAttachmentSize:forGlyphRange:", NSSize, NSRange)(attachmentSize, glyphRange); } void setBidiLevels (char* levels, NSRange glyphRange) { return invokeObjcSelf!(void, "setBidiLevels:forGlyphRange:", char*, NSRange)(levels, glyphRange); } //mixin ObjcBindMethod!(characterRangeForGlyphRange, "characterRangeForGlyphRange:actualGlyphRange:"); //mixin ObjcBindMethod!(glyphRangeForCharacterRange, "glyphRangeForCharacterRange:actualCharacterRange:"); //mixin ObjcBindMethod!(getGlyphsInRange, "getGlyphsInRange:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:"); //mixin ObjcBindMethod!(getLineFragmentRect, "getLineFragmentRect:usedRect:remainingRect:forStartingGlyphAtIndex:proposedRect:lineSpacing:paragraphSpacingBefore:paragraphSpacingAfter:"); //mixin ObjcBindMethod!(setLineFragmentRect, "setLineFragmentRect:forGlyphRange:usedRect:baselineOffset:"); //mixin ObjcBindMethod!(substituteGlyphsInRange, "substituteGlyphsInRange:withGlyphs:"); //mixin ObjcBindMethod!(insertGlyph, "insertGlyph:atGlyphIndex:characterIndex:"); //mixin ObjcBindMethod!(deleteGlyphsInRange, "deleteGlyphsInRange:"); //mixin ObjcBindMethod!(setNotShownAttribute, "setNotShownAttribute:forGlyphRange:"); //mixin ObjcBindMethod!(setDrawsOutsideLineFragment, "setDrawsOutsideLineFragment:forGlyphRange:"); //mixin ObjcBindMethod!(setLocation, "setLocation:withAdvancements:forStartOfGlyphRange:"); //mixin ObjcBindMethod!(setAttachmentSize, "setAttachmentSize:forGlyphRange:"); //mixin ObjcBindMethod!(setBidiLevels, "setBidiLevels:forGlyphRange:"); `; class NSTypesetter : NSObject { mixin (ObjcWrap); void getLineFragmentRect (NSRectPointer lineFragmentRect, NSRectPointer lineFragmentUsedRect, NSRange paragraphSeparatorGlyphRange, NSPoint lineOrigin) { return invokeObjcSelf!(void, "getLineFragmentRect:usedRect:forParagraphSeparatorGlyphRange:atProposedOrigin:", NSRectPointer, NSRectPointer, NSRange, NSPoint)(lineFragmentRect, lineFragmentUsedRect, paragraphSeparatorGlyphRange, lineOrigin); } bool usesFontLeading () { return invokeObjcSelf!(bool, "usesFontLeading"); } void setUsesFontLeading (bool flag) { return invokeObjcSelf!(void, "setUsesFontLeading:", bool)(flag); } int typesetterBehavior () { return invokeObjcSelf!(int, "typesetterBehavior"); } void setTypesetterBehavior (int behavior) { return invokeObjcSelf!(void, "setTypesetterBehavior:", int)(behavior); } float hyphenationFactor () { return invokeObjcSelf!(float, "hyphenationFactor"); } void setHyphenationFactor (float factor) { return invokeObjcSelf!(void, "setHyphenationFactor:", float)(factor); } CGFloat lineFragmentPadding () { return invokeObjcSelf!(CGFloat, "lineFragmentPadding"); } void setLineFragmentPadding (CGFloat padding) { return invokeObjcSelf!(void, "setLineFragmentPadding:", CGFloat)(padding); } NSFont substituteFontForFont (NSFont originalFont) { return invokeObjcSelf!(NSFont, "substituteFontForFont:", NSFont)(originalFont); } NSTextTab textTabForGlyphLocation (CGFloat glyphLocation, int direction, CGFloat maxLocation) { return invokeObjcSelf!(NSTextTab, "textTabForGlyphLocation:writingDirection:maxLocation:", CGFloat, int, CGFloat)(glyphLocation, direction, maxLocation); } bool bidiProcessingEnabled () { return invokeObjcSelf!(bool, "bidiProcessingEnabled"); } void setBidiProcessingEnabled (bool flag) { return invokeObjcSelf!(void, "setBidiProcessingEnabled:", bool)(flag); } void setAttributedString (NSAttributedString attrString) { return invokeObjcSelf!(void, "setAttributedString:", NSAttributedString)(attrString); } NSAttributedString attributedString () { return invokeObjcSelf!(NSAttributedString, "attributedString"); } void setParagraphGlyphRange (NSRange paragraphRange, NSRange paragraphSeparatorRange) { return invokeObjcSelf!(void, "setParagraphGlyphRange:separatorGlyphRange:", NSRange, NSRange)(paragraphRange, paragraphSeparatorRange); } NSRange paragraphGlyphRange () { return invokeObjcSelf!(NSRange, "paragraphGlyphRange"); } NSRange paragraphSeparatorGlyphRange () { return invokeObjcSelf!(NSRange, "paragraphSeparatorGlyphRange"); } NSRange paragraphCharacterRange () { return invokeObjcSelf!(NSRange, "paragraphCharacterRange"); } NSRange paragraphSeparatorCharacterRange () { return invokeObjcSelf!(NSRange, "paragraphSeparatorCharacterRange"); } NSUInteger layoutParagraphAtPoint (NSPointPointer lineFragmentOrigin) { return invokeObjcSelf!(NSUInteger, "layoutParagraphAtPoint:", NSPointPointer)(lineFragmentOrigin); } void beginParagraph () { return invokeObjcSelf!(void, "beginParagraph"); } void endParagraph () { return invokeObjcSelf!(void, "endParagraph"); } void beginLineWithGlyphAtIndex (NSUInteger glyphIndex) { return invokeObjcSelf!(void, "beginLineWithGlyphAtIndex:", NSUInteger)(glyphIndex); } void endLineWithGlyphRange (NSRange lineGlyphRange) { return invokeObjcSelf!(void, "endLineWithGlyphRange:", NSRange)(lineGlyphRange); } CGFloat lineSpacingAfterGlyphAtIndex (NSUInteger glyphIndex, NSRect rect) { return invokeObjcSelf!(CGFloat, "lineSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:", NSUInteger, NSRect)(glyphIndex, rect); } CGFloat paragraphSpacingBeforeGlyphAtIndex (NSUInteger glyphIndex, NSRect rect) { return invokeObjcSelf!(CGFloat, "paragraphSpacingBeforeGlyphAtIndex:withProposedLineFragmentRect:", NSUInteger, NSRect)(glyphIndex, rect); } CGFloat paragraphSpacingAfterGlyphAtIndex (NSUInteger glyphIndex, NSRect rect) { return invokeObjcSelf!(CGFloat, "paragraphSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:", NSUInteger, NSRect)(glyphIndex, rect); } NSDictionary attributesForExtraLineFragment () { return invokeObjcSelf!(NSDictionary, "attributesForExtraLineFragment"); } uint actionForControlCharacterAtIndex (NSUInteger charIndex) { return invokeObjcSelf!(uint, "actionForControlCharacterAtIndex:", NSUInteger)(charIndex); } NSLayoutManager layoutManager () { return invokeObjcSelf!(NSLayoutManager, "layoutManager"); } NSArray textContainers () { return invokeObjcSelf!(NSArray, "textContainers"); } NSTextContainer currentTextContainer () { return invokeObjcSelf!(NSTextContainer, "currentTextContainer"); } NSParagraphStyle currentParagraphStyle () { return invokeObjcSelf!(NSParagraphStyle, "currentParagraphStyle"); } void setHardInvalidation (bool flag, NSRange glyphRange) { return invokeObjcSelf!(void, "setHardInvalidation:forGlyphRange:", bool, NSRange)(flag, glyphRange); } void layoutGlyphsInLayoutManager (NSLayoutManager layoutManager, NSUInteger startGlyphIndex, NSUInteger maxNumLines, NSUInteger* nextGlyph) { return invokeObjcSelf!(void, "layoutGlyphsInLayoutManager:startingAtGlyphIndex:maxNumberOfLineFragments:nextGlyphIndex:", NSLayoutManager, NSUInteger, NSUInteger, NSUInteger*)(layoutManager, startGlyphIndex, maxNumLines, nextGlyph); } NSRange layoutCharactersInRange (NSRange characterRange, NSLayoutManager layoutManager, NSUInteger maxNumLines) { return invokeObjcSelf!(NSRange, "layoutCharactersInRange:forLayoutManager:maximumNumberOfLineFragments:", NSRange, NSLayoutManager, NSUInteger)(characterRange, layoutManager, maxNumLines); } static NSSize printingAdjustmentInLayoutManager (NSLayoutManager layoutMgr, NSRange nominallySpacedGlyphsRange, char* packedGlyphs, NSUInteger packedGlyphsCount) { return invokeObjcSelfClass!(NSSize, "printingAdjustmentInLayoutManager:forNominallySpacedGlyphRange:packedGlyphs:count:", NSLayoutManager, NSRange, char*, NSUInteger)(layoutMgr, nominallySpacedGlyphsRange, packedGlyphs, packedGlyphsCount); } CGFloat baselineOffsetInLayoutManager (NSLayoutManager layoutMgr, NSUInteger glyphIndex) { return invokeObjcSelf!(CGFloat, "baselineOffsetInLayoutManager:glyphIndex:", NSLayoutManager, NSUInteger)(layoutMgr, glyphIndex); } static Object sharedSystemTypesetter () { return invokeObjcSelfClass!(Object, "sharedSystemTypesetter"); } static Object sharedSystemTypesetterForBehavior (int theBehavior) { return invokeObjcSelfClass!(Object, "sharedSystemTypesetterForBehavior:", int)(theBehavior); } static int defaultTypesetterBehavior () { return invokeObjcSelfClass!(int, "defaultTypesetterBehavior"); } // NSLayoutPhaseInterface void willSetLineFragmentRect (NSRectPointer lineRect, NSRange glyphRange, NSRectPointer usedRect, CGFloat* baselineOffset) { return invokeObjcSelf!(void, "willSetLineFragmentRect:forGlyphRange:usedRect:baselineOffset:", NSRectPointer, NSRange, NSRectPointer, CGFloat*)(lineRect, glyphRange, usedRect, baselineOffset); } bool shouldBreakLineByWordBeforeCharacterAtIndex (NSUInteger charIndex) { return invokeObjcSelf!(bool, "shouldBreakLineByWordBeforeCharacterAtIndex:", NSUInteger)(charIndex); } bool shouldBreakLineByHyphenatingBeforeCharacterAtIndex (NSUInteger charIndex) { return invokeObjcSelf!(bool, "shouldBreakLineByHyphenatingBeforeCharacterAtIndex:", NSUInteger)(charIndex); } float hyphenationFactorForGlyphAtIndex (NSUInteger glyphIndex) { return invokeObjcSelf!(float, "hyphenationFactorForGlyphAtIndex:", NSUInteger)(glyphIndex); } uint hyphenCharacterForGlyphAtIndex (NSUInteger glyphIndex) { return invokeObjcSelf!(uint, "hyphenCharacterForGlyphAtIndex:", NSUInteger)(glyphIndex); } NSRect boundingBoxForControlGlyphAtIndex (NSUInteger glyphIndex, NSTextContainer textContainer, NSRect proposedRect, NSPoint glyphPosition, NSUInteger charIndex) { return invokeObjcSelf!(NSRect, "boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment:glyphPosition:characterIndex:", NSUInteger, NSTextContainer, NSRect, NSPoint, NSUInteger)(glyphIndex, textContainer, proposedRect, glyphPosition, charIndex); } // NSGlyphStorageInterface NSRange characterRangeForGlyphRange (NSRange glyphRange, NSRangePointer actualGlyphRange) { return invokeObjcSelf!(NSRange, "characterRangeForGlyphRange:actualGlyphRange:", NSRange, NSRangePointer)(glyphRange, actualGlyphRange); } NSRange glyphRangeForCharacterRange (NSRange charRange, NSRangePointer actualCharRange) { return invokeObjcSelf!(NSRange, "glyphRangeForCharacterRange:actualCharacterRange:", NSRange, NSRangePointer)(charRange, actualCharRange); } NSUInteger getGlyphsInRange (NSRange glyphsRange, NSGlyph* glyphBuffer, NSUInteger* charIndexBuffer, NSGlyphInscription* inscribeBuffer, bool* elasticBuffer, char* bidiLevelBuffer) { return invokeObjcSelf!(NSUInteger, "getGlyphsInRange:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:", NSRange, NSGlyph*, NSUInteger*, NSGlyphInscription*, bool*, char*)(glyphsRange, glyphBuffer, charIndexBuffer, inscribeBuffer, elasticBuffer, bidiLevelBuffer); } void getLineFragmentRect (NSRectPointer lineFragmentRect, NSRectPointer lineFragmentUsedRect, NSRectPointer remainingRect, NSUInteger startingGlyphIndex, NSRect proposedRect, CGFloat lineSpacing, CGFloat paragraphSpacingBefore, CGFloat paragraphSpacingAfter) { return invokeObjcSelf!(void, "getLineFragmentRect:usedRect:remainingRect:forStartingGlyphAtIndex:proposedRect:lineSpacing:paragraphSpacingBefore:paragraphSpacingAfter:", NSRectPointer, NSRectPointer, NSRectPointer, NSUInteger, NSRect, CGFloat, CGFloat, CGFloat)(lineFragmentRect, lineFragmentUsedRect, remainingRect, startingGlyphIndex, proposedRect, lineSpacing, paragraphSpacingBefore, paragraphSpacingAfter); } void setLineFragmentRect (NSRect fragmentRect, NSRange glyphRange, NSRect usedRect, CGFloat baselineOffset) { return invokeObjcSelf!(void, "setLineFragmentRect:forGlyphRange:usedRect:baselineOffset:", NSRect, NSRange, NSRect, CGFloat)(fragmentRect, glyphRange, usedRect, baselineOffset); } void substituteGlyphsInRange (NSRange glyphRange, NSGlyph* glyphs) { return invokeObjcSelf!(void, "substituteGlyphsInRange:withGlyphs:", NSRange, NSGlyph*)(glyphRange, glyphs); } void insertGlyph (uint glyph, NSUInteger glyphIndex, NSUInteger characterIndex) { return invokeObjcSelf!(void, "insertGlyph:atGlyphIndex:characterIndex:", uint, NSUInteger, NSUInteger)(glyph, glyphIndex, characterIndex); } void deleteGlyphsInRange (NSRange glyphRange) { return invokeObjcSelf!(void, "deleteGlyphsInRange:", NSRange)(glyphRange); } void setNotShownAttribute (bool flag, NSRange glyphRange) { return invokeObjcSelf!(void, "setNotShownAttribute:forGlyphRange:", bool, NSRange)(flag, glyphRange); } void setDrawsOutsideLineFragment (bool flag, NSRange glyphRange) { return invokeObjcSelf!(void, "setDrawsOutsideLineFragment:forGlyphRange:", bool, NSRange)(flag, glyphRange); } void setLocation (NSPoint location, CGFloat* advancements, NSRange glyphRange) { return invokeObjcSelf!(void, "setLocation:withAdvancements:forStartOfGlyphRange:", NSPoint, CGFloat*, NSRange)(location, advancements, glyphRange); } void setAttachmentSize (NSSize attachmentSize, NSRange glyphRange) { return invokeObjcSelf!(void, "setAttachmentSize:forGlyphRange:", NSSize, NSRange)(attachmentSize, glyphRange); } void setBidiLevels (char* levels, NSRange glyphRange) { return invokeObjcSelf!(void, "setBidiLevels:forGlyphRange:", char*, NSRange)(levels, glyphRange); } }