Mercurial > projects > dwt-mac
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/cocoa/NSTypesetter.d Sat Aug 09 17:00:02 2008 +0200 @@ -0,0 +1,421 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * + * Port to the D Programming language: + * Jacob Carlborg <jacob.carlborg@gmail.com> + *******************************************************************************/ +module dwt.internal.cocoa.NSTypesetter; + +import dwt.internal.cocoa.CGFloat; +import dwt.internal.cocoa.NSArray; +import dwt.internal.cocoa.NSAttributedString; +import dwt.internal.cocoa.NSDictionary; +import dwt.internal.cocoa.NSFont; +import dwt.internal.cocoa.NSInteger; +import dwt.internal.cocoa.NSLayoutManager; +import dwt.internal.cocoa.NSObject; +import dwt.internal.cocoa.NSParagraphStyle; +import dwt.internal.cocoa.NSPoint; +import dwt.internal.cocoa.NSRange; +import dwt.internal.cocoa.NSRect; +import dwt.internal.cocoa.NSSize; +import dwt.internal.cocoa.NSText : NSWritingDirection; +import dwt.internal.cocoa.NSTextContainer; +import dwt.internal.cocoa.NSTextTab; +import dwt.internal.cocoa.OS; +import objc = dwt.internal.objc.runtime; + +enum NSTypesetterControlCharacterAction : NSUInteger +{ + NSTypesetterZeroAdvancementAction = (1 << 0), + NSTypesetterWhitespaceAction = (1 << 1), + NSTypesetterHorizontalTabAction = (1 << 2), + NSTypesetterLineBreakAction = (1 << 3), + NSTypesetterParagraphBreakAction = (1 << 4), + NSTypesetterContainerBreakAction = (1 << 5) +} + +alias NSTypesetterControlCharacterAction.NSTypesetterZeroAdvancementAction NSTypesetterZeroAdvancementAction; +alias NSTypesetterControlCharacterAction.NSTypesetterWhitespaceAction NSTypesetterWhitespaceAction; +alias NSTypesetterControlCharacterAction.NSTypesetterHorizontalTabAction NSTypesetterHorizontalTabAction; +alias NSTypesetterControlCharacterAction.NSTypesetterLineBreakAction NSTypesetterLineBreakAction; +alias NSTypesetterControlCharacterAction.NSTypesetterParagraphBreakAction NSTypesetterParagraphBreakAction; +alias NSTypesetterControlCharacterAction.NSTypesetterContainerBreakAction NSTypesetterContainerBreakAction; + +public class NSTypesetter : NSObject +{ + + public this () + { + super(); + } + + public this (objc.id id) + { + super(id); + } + + public NSTypesetterControlCharacterAction actionForControlCharacterAtIndex (NSUInteger charIndex) + { + return cast(NSTypesetterControlCharacterAction) OS.objc_msgSend(this.id, OS.sel_actionForControlCharacterAtIndex_1, charIndex); + } + + public NSAttributedString attributedString () + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_attributedString); + return result !is null ? new NSAttributedString(result) : null; + } + + public NSDictionary attributesForExtraLineFragment () + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_attributesForExtraLineFragment); + return result !is null ? new NSDictionary(result) : null; + } + + public CGFloat baselineOffsetInLayoutManager (NSLayoutManager layoutMgr, NSUInteger glyphIndex) + { + return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_baselineOffsetInLayoutManager_1glyphIndex_1, + layoutMgr !is null ? layoutMgr.id : null, glyphIndex); + } + + public void beginLineWithGlyphAtIndex (NSUInteger glyphIndex) + { + OS.objc_msgSend(this.id, OS.sel_beginLineWithGlyphAtIndex_1, glyphIndex); + } + + public void beginParagraph () + { + OS.objc_msgSend(this.id, OS.sel_beginParagraph); + } + + public bool bidiProcessingEnabled () + { + return OS.objc_msgSend(this.id, OS.sel_bidiProcessingEnabled) !is null; + } + + public NSRect boundingBoxForControlGlyphAtIndex (NSUInteger glyphIndex, NSTextContainer textContainer, NSRect proposedRect, + NSPoint glyphPosition, NSUInteger charIndex) + { + NSRect result; + OS.objc_msgSend_stret(result, this.id, + OS.sel_boundingBoxForControlGlyphAtIndex_1forTextContainer_1proposedLineFragment_1glyphPosition_1characterIndex_1, glyphIndex, + textContainer !is null ? textContainer.id : null, proposedRect, glyphPosition, charIndex); + return result; + } + + public NSRange characterRangeForGlyphRange (NSRange glyphRange, NSRangePointer actualGlyphRange) + { + NSRange result; + OS.objc_msgSend_stret(result, this.id, OS.sel_characterRangeForGlyphRange_1actualGlyphRange_1, glyphRange, actualGlyphRange); + return result; + } + + public NSParagraphStyle currentParagraphStyle () + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_currentParagraphStyle); + return result !is null ? new NSParagraphStyle(result) : null; + } + + public NSTextContainer currentTextContainer () + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_currentTextContainer); + return result !is null ? new NSTextContainer(result) : null; + } + + public static NSTypesetterBehavior defaultTypesetterBehavior () + { + return cast(NSTypesetterBehavior) OS.objc_msgSend(OS.class_NSTypesetter, OS.sel_defaultTypesetterBehavior); + } + + public void deleteGlyphsInRange (NSRange glyphRange) + { + OS.objc_msgSend(this.id, OS.sel_deleteGlyphsInRange_1, glyphRange); + } + + public void endLineWithGlyphRange (NSRange lineGlyphRange) + { + OS.objc_msgSend(this.id, OS.sel_endLineWithGlyphRange_1, lineGlyphRange); + } + + public void endParagraph () + { + OS.objc_msgSend(this.id, OS.sel_endParagraph); + } + + public NSUInteger getGlyphsInRange (NSRange glyphsRange, NSGlyph* glyphBuffer, NSUInteger* charIndexBuffer, NSGlyphInscription* inscribeBuffer, + bool* elasticBuffer, /*unsigned char* */ubyte* bidiLevelBuffer) + { + return cast(NSUInteger) OS.objc_msgSend(this.id, + OS.sel_getGlyphsInRange_1glyphs_1characterIndexes_1glyphInscriptions_1elasticBits_1bidiLevels_1, glyphsRange, glyphBuffer, + charIndexBuffer, inscribeBuffer, elasticBuffer, bidiLevelBuffer); + } + + public void getLineFragmentRect_usedRect_forParagraphSeparatorGlyphRange_atProposedOrigin_ (NSRectPointer lineFragmentRect, + NSRectPointer lineFragmentUsedRect, NSRange paragraphSeparatorGlyphRange, NSPoint lineOrigin) + { + OS.objc_msgSend(this.id, OS.sel_getLineFragmentRect_1usedRect_1forParagraphSeparatorGlyphRange_1atProposedOrigin_1, lineFragmentRect, + lineFragmentUsedRect, paragraphSeparatorGlyphRange, lineOrigin); + } + + public void getLineFragmentRect_usedRect_remainingRect_forStartingGlyphAtIndex_proposedRect_lineSpacing_paragraphSpacingBefore_paragraphSpacingAfter_ ( + NSRectPointer lineFragmentRect, NSRectPointer lineFragmentUsedRect, NSRectPointer remainingRect, NSUInteger startingGlyphIndex, + NSRect proposedRect, CGFloat lineSpacing, CGFloat paragraphSpacingBefore, CGFloat paragraphSpacingAfter) + { + OS.objc_msgSend( + this.id, + OS.sel_getLineFragmentRect_1usedRect_1remainingRect_1forStartingGlyphAtIndex_1proposedRect_1lineSpacing_1paragraphSpacingBefore_1paragraphSpacingAfter_1, + lineFragmentRect, lineFragmentUsedRect, remainingRect, startingGlyphIndex, proposedRect, lineSpacing, paragraphSpacingBefore, + paragraphSpacingAfter); + } + + public NSRange glyphRangeForCharacterRange (NSRange charRange, NSRangePointer actualCharRange) + { + NSRange result; + OS.objc_msgSend_stret(result, this.id, OS.sel_glyphRangeForCharacterRange_1actualCharacterRange_1, charRange, actualCharRange); + return result; + } + + public /*UTF32Char*/dchar hyphenCharacterForGlyphAtIndex (NSUInteger glyphIndex) + { + return cast(/*UTF32Char*/dchar) OS.objc_msgSend(this.id, OS.sel_hyphenCharacterForGlyphAtIndex_1, glyphIndex); + } + + public float hyphenationFactor () + { + return cast(float) OS.objc_msgSend_fpret(this.id, OS.sel_hyphenationFactor); + } + + public float hyphenationFactorForGlyphAtIndex (NSUInteger glyphIndex) + { + return cast(float) OS.objc_msgSend_fpret(this.id, OS.sel_hyphenationFactorForGlyphAtIndex_1, glyphIndex); + } + + public void insertGlyph (NSGlyph glyph, NSUInteger glyphIndex, NSUInteger characterIndex) + { + OS.objc_msgSend(this.id, OS.sel_insertGlyph_1atGlyphIndex_1characterIndex_1, glyph, glyphIndex, characterIndex); + } + + public NSRange layoutCharactersInRange (NSRange characterRange, NSLayoutManager layoutManager, NSUInteger maxNumLines) + { + NSRange result; + OS.objc_msgSend_stret(result, this.id, OS.sel_layoutCharactersInRange_1forLayoutManager_1maximumNumberOfLineFragments_1, characterRange, + layoutManager !is null ? layoutManager.id : null, maxNumLines); + return result; + } + + public void layoutGlyphsInLayoutManager (NSLayoutManager layoutManager, NSUInteger startGlyphIndex, NSUInteger maxNumLines, NSUInteger* nextGlyph) + { + OS.objc_msgSend(this.id, OS.sel_layoutGlyphsInLayoutManager_1startingAtGlyphIndex_1maxNumberOfLineFragments_1nextGlyphIndex_1, + layoutManager !is null ? layoutManager.id : null, startGlyphIndex, maxNumLines, nextGlyph); + } + + public NSLayoutManager layoutManager () + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_layoutManager); + return result !is null ? new NSLayoutManager(result) : null; + } + + public NSUInteger layoutParagraphAtPoint (NSPointPointer lineFragmentOrigin) + { + return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_layoutParagraphAtPoint_1, lineFragmentOrigin); + } + + public CGFloat lineFragmentPadding () + { + return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_lineFragmentPadding); + } + + public CGFloat lineSpacingAfterGlyphAtIndex (NSUInteger glyphIndex, NSRect rect) + { + return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_lineSpacingAfterGlyphAtIndex_1withProposedLineFragmentRect_1, glyphIndex, rect); + } + + public NSRange paragraphCharacterRange () + { + NSRange result; + OS.objc_msgSend_stret(result, this.id, OS.sel_paragraphCharacterRange); + return result; + } + + public NSRange paragraphGlyphRange () + { + NSRange result; + OS.objc_msgSend_stret(result, this.id, OS.sel_paragraphGlyphRange); + return result; + } + + public NSRange paragraphSeparatorCharacterRange () + { + NSRange result; + OS.objc_msgSend_stret(result, this.id, OS.sel_paragraphSeparatorCharacterRange); + return result; + } + + public NSRange paragraphSeparatorGlyphRange () + { + NSRange result; + OS.objc_msgSend_stret(result, this.id, OS.sel_paragraphSeparatorGlyphRange); + return result; + } + + public CGFloat paragraphSpacingAfterGlyphAtIndex (NSUInteger glyphIndex, NSRect rect) + { + return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_paragraphSpacingAfterGlyphAtIndex_1withProposedLineFragmentRect_1, glyphIndex, rect); + } + + public CGFloat paragraphSpacingBeforeGlyphAtIndex (NSUInteger glyphIndex, NSRect rect) + { + return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_paragraphSpacingBeforeGlyphAtIndex_1withProposedLineFragmentRect_1, glyphIndex, rect); + } + + public static NSSize printingAdjustmentInLayoutManager (NSLayoutManager layoutMgr, NSRange nominallySpacedGlyphsRange, + /*const unsigned char* */ubyte* packedGlyphs, NSUInteger packedGlyphsCount) + { + NSSize result; + OS.objc_msgSend_stret(result, OS.class_NSTypesetter, + OS.sel_printingAdjustmentInLayoutManager_1forNominallySpacedGlyphRange_1packedGlyphs_1count_1, + layoutMgr !is null ? layoutMgr.id : null, nominallySpacedGlyphsRange, packedGlyphs, packedGlyphsCount); + return result; + } + + public void setAttachmentSize (NSSize attachmentSize, NSRange glyphRange) + { + OS.objc_msgSend(this.id, OS.sel_setAttachmentSize_1forGlyphRange_1, attachmentSize, glyphRange); + } + + public void setAttributedString (NSAttributedString attrString) + { + OS.objc_msgSend(this.id, OS.sel_setAttributedString_1, attrString !is null ? attrString.id : null); + } + + public void setBidiLevels (/*const uint8_t* */ubyte* levels, NSRange glyphRange) + { + OS.objc_msgSend(this.id, OS.sel_setBidiLevels_1forGlyphRange_1, levels, glyphRange); + } + + public void setBidiProcessingEnabled (bool flag) + { + OS.objc_msgSend(this.id, OS.sel_setBidiProcessingEnabled_1, flag); + } + + public void setDrawsOutsideLineFragment (bool flag, NSRange glyphRange) + { + OS.objc_msgSend(this.id, OS.sel_setDrawsOutsideLineFragment_1forGlyphRange_1, flag, glyphRange); + } + + public void setHardInvalidation (bool flag, NSRange glyphRange) + { + OS.objc_msgSend(this.id, OS.sel_setHardInvalidation_1forGlyphRange_1, flag, glyphRange); + } + + public void setHyphenationFactor (float factor) + { + OS.objc_msgSend(this.id, OS.sel_setHyphenationFactor_1, factor); + } + + public void setLineFragmentPadding (CGFloat padding) + { + OS.objc_msgSend(this.id, OS.sel_setLineFragmentPadding_1, padding); + } + + public void setLineFragmentRect (NSRect fragmentRect, NSRange glyphRange, NSRect usedRect, CGFloat baselineOffset) + { + OS.objc_msgSend(this.id, OS.sel_setLineFragmentRect_1forGlyphRange_1usedRect_1baselineOffset_1, fragmentRect, glyphRange, usedRect, + baselineOffset); + } + + public void setLocation (NSPoint location, /*const CGFloat* */CGFloat* advancements, NSRange glyphRange) + { + OS.objc_msgSend(this.id, OS.sel_setLocation_1withAdvancements_1forStartOfGlyphRange_1, location, advancements, glyphRange); + } + + public void setNotShownAttribute (bool flag, NSRange glyphRange) + { + OS.objc_msgSend(this.id, OS.sel_setNotShownAttribute_1forGlyphRange_1, flag, glyphRange); + } + + public void setParagraphGlyphRange (NSRange paragraphRange, NSRange paragraphSeparatorRange) + { + OS.objc_msgSend(this.id, OS.sel_setParagraphGlyphRange_1separatorGlyphRange_1, paragraphRange, paragraphSeparatorRange); + } + + public void setTypesetterBehavior (NSTypesetterBehavior behavior) + { + OS.objc_msgSend(this.id, OS.sel_setTypesetterBehavior_1, behavior); + } + + public void setUsesFontLeading (bool flag) + { + OS.objc_msgSend(this.id, OS.sel_setUsesFontLeading_1, flag); + } + + public static id sharedSystemTypesetter () + { + objc.id result = OS.objc_msgSend(OS.class_NSTypesetter, OS.sel_sharedSystemTypesetter); + return result !is null ? new id(result) : null; + } + + public static id sharedSystemTypesetterForBehavior (NSTypesetterBehavior theBehavior) + { + objc.id result = OS.objc_msgSend(OS.class_NSTypesetter, OS.sel_sharedSystemTypesetterForBehavior_1, theBehavior); + return result !is null ? new id(result) : null; + } + + public bool shouldBreakLineByHyphenatingBeforeCharacterAtIndex (NSUInteger charIndex) + { + return OS.objc_msgSend(this.id, OS.sel_shouldBreakLineByHyphenatingBeforeCharacterAtIndex_1, charIndex) !is null; + } + + public bool shouldBreakLineByWordBeforeCharacterAtIndex (NSUInteger charIndex) + { + return OS.objc_msgSend(this.id, OS.sel_shouldBreakLineByWordBeforeCharacterAtIndex_1, charIndex) !is null; + } + + public NSFont substituteFontForFont (NSFont originalFont) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_substituteFontForFont_1, originalFont !is null ? originalFont.id : null); + return result !is null ? new NSFont(result) : null; + } + + public void substituteGlyphsInRange (NSRange glyphRange, NSGlyph* glyphs) + { + OS.objc_msgSend(this.id, OS.sel_substituteGlyphsInRange_1withGlyphs_1, glyphRange, glyphs); + } + + public NSArray textContainers () + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_textContainers); + return result !is null ? new NSArray(result) : null; + } + + public NSTextTab textTabForGlyphLocation (CGFloat glyphLocation, NSWritingDirection direction, CGFloat maxLocation) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_textTabForGlyphLocation_1writingDirection_1maxLocation_1, glyphLocation, direction, + maxLocation); + return result !is null ? new NSTextTab(result) : null; + } + + public NSTypesetterBehavior typesetterBehavior () + { + return cast(NSTypesetterBehavior) OS.objc_msgSend(this.id, OS.sel_typesetterBehavior); + } + + public bool usesFontLeading () + { + return OS.objc_msgSend(this.id, OS.sel_usesFontLeading) !is null; + } + + public void willSetLineFragmentRect (NSRectPointer lineRect, NSRange glyphRange, NSRectPointer usedRect, CGFloat* baselineOffset) + { + OS.objc_msgSend(this.id, OS.sel_willSetLineFragmentRect_1forGlyphRange_1usedRect_1baselineOffset_1, lineRect, glyphRange, usedRect, + baselineOffset); + } + +}