Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSTextBlock

Inherits from
Implements
Package
com.apple.cocoa.application
Availability
Available in Mac OS X v10.4 and later.
Companion guides

Overview

NSTextBlock represents a block of text laid out in a subregion of the text container. Text blocks appear as attributes on paragraphs, as part of the paragraph style.

The most important subclass is NSTextTableBlock, which represents a block of text that appears as a cell in a table. The table itself is represented by a separate class, NSTextTable, which is referenced by all of its NSTextTableBlocks and which controls their sizing and positioning.

Tasks

Constructors

Working with Dimensions of Content

Getting and Setting Margins, Borders, and Padding

Getting and Setting Alignment

Working with Color

Determining Size and Position of Text Block

Drawing Colors and Decorations

Constructors

NSTextBlock

public NSTextBlock()

Discussion

The constructor for the NSTextBlock object.

Instance Methods

backgroundColor

Returns the background color of the text block.

public NSColor backgroundColor()

Availability
See Also

borderColorForEdge

Returns the border color of the text block edge specified by edge.

public NSColor borderColorForEdge(int edge)

Availability
See Also

boundsRectForContentRect

Called by the typesetter after the text block is laid out to return the rectangle the text in the block actually occupies, including padding, borders, and margins.

public NSRect boundsRectForContentRect(NSRect contentRect, NSRect rect, NSTextContainer textContainer, NSRange charRange)

Discussion

The contentRect is the actual rectangle in which the text was laid out, as determined by rectForLayoutAtPoint. The rect is the initial rectangle in textContainer proposed by the typesetter in which to lay out the glyphs for the characters in charRange.

Availability
See Also

contentWidth

Returns the width of the text block in points.

public float contentWidth()

Discussion

This is a convenience method that invokes valueForDimension:Width.

Availability
See Also

contentWidthValueType

Returns the type of value stored for the text block width.

public int contentWidthValueType()

Discussion

The value type is either an absolute value in points or a percentage.

Availability
See Also

drawBackgroundWithFrame

Called by the layout manager to draw any colors and other decorations before the text is drawn.

public void drawBackgroundWithFrame(NSRect frameRect, NSView controlView, NSRange charRange, NSLayoutManager layoutManager)

Discussion

The frameRect is the bounds rectangle in view coordinates. The controlView is the view in which drawing occurs. The charRange describes the characters whose glyphs are to be drawn, and the layoutManager is the layout manager controlling the typesetting.

Availability

rectForLayoutAtPoint

Called by the typesetter before the text block is laid out to return the rectangle within which glyphs should be laid out.

public NSRect rectForLayoutAtPoint(NSPoint startingPoint, NSRect rect, NSTextContainer textContainer, NSRange charRange)

Discussion

The startingPoint argument specifies the location, in container coordinates, where layout begins. The rect is the rectangle in which the block is constrained to lie: for top-level blocks, the container rectangle of textContainer; for nested blocks, the layout rectangle of the enclosing block. The charRange argument is the range of the characters to be laid out.

Availability
See Also

setBackgroundColor

Sets the background color of the text block.

public void setBackgroundColor(NSColor color)

Availability
See Also

setBorderColor

Sets the color of one or more borders of the text block.

public void setBorderColor(NSColor color)

Sets the color of one or more borders of the text block.

public void setBorderColor(NSColor color, int edge)

Discussion

If you specify an edge parameter, the color is applied to the specified edge; otherwise, it is applied to all edges. This setting has no visible effect unless the border width is larger than the default, which is 0.

Availability
See Also

setContentWidth

Sets the width of the text block.

public void setContentWidth(float val, int type)

Discussion

The value val is either an absolute value in points or a percentage of the enclosing block, as specified by type.

Availability
See Also

setValue

Sets the value type for a dimension of the text block.

public void setValue(float val, int type, int dimension)

Discussion

The value val is either an absolute value in points or a percentage of the enclosing block, as specified by type. The dimension argument specifies which dimension’s value to set.

Availability
See Also

setVerticalAlignment

Sets the vertical alignment of the text block to alignment.

public void setVerticalAlignment(int alignment)

Availability
See Also

setWidthForLayer

Sets the width of one or more edges of a specified layer of the text block.

public void setWidthForLayer(float val, int type, int layer)

Discussion

The width is specified by val, which is interpreted as points or a percentage according to type, and the layer—border, padding, or margin—is specified by layer.

Sets the width of one or more edges of a specified layer of the text block.

public void setWidthForLayer(float val, int type, int layer, int edge)

Discussion

The edge is specified by edge. If you do not specify an edge parameter, the width is applied to all edges.

Availability
See Also

valueForDimension

Returns the value of the text block dimension specified by dimension.

public float valueForDimension(int dimension)

Availability
See Also

valueTypeForDimension

Returns the value type of the text block dimension specified by dimension.

public int valueTypeForDimension(int dimension)

Discussion

The value type determines whether the value is interpreted as an absolute value in points or a percentage of the enclosing block.

Availability
See Also

verticalAlignment

Returns the vertical alignment of the text block.

public int verticalAlignment()

Availability
See Also

widthForLayer

Returns the width of a layer for a given edge of the text block in points.

public float widthForLayer(int layer, int edge)

Discussion

The text block layer can be its border, padding, or margin.

Availability
See Also

widthValueTypeForLayer

Returns the value type of a layer for a given edge of the text block.

public int widthValueTypeForLayer(int layer, int edge)

Discussion

The text block layer can be its border, padding, or margin.

Availability
See Also

Constants

The following constants specify values used with method parameters used for specifying width types.

Constant

Description

AbsoluteValueType

Absolute value in points

PercentageValueType

Percentage value (out of 100)

The following constants specify values used with method parameters used for specifying dimensions.

Constant

Description

Width

Width of the text block

MinimumWidth

Minimum width of the text block

MaximumWidth

Maximum width of the text block

Height

Height of the text block

MinimumHeight

Minimum height of the text block

MaximumHeight

Maximum height of the text block

The following constants specify values used with method parameters used for specifying layer information.

Constant

Description

Padding

Padding of the text block: space surrounding the content area extending to the border

Border

Border of the text block: space between padding and margin, typically colored to present a visible boundary

Margin

Margin of the text block: space surrounding the border

The following constants specify values used with method parameters used for specifying alignment.

Constant

Description

TopAlignment

Aligns adjacent blocks at their top

MiddleAlignment

Aligns adjacent blocks at their middle

BottomAlignment

Aligns adjacent blocks at their bottom

BaselineAlignment

Aligns adjacent blocks at the baseline of the first line of text in the block



Next Page > Hide TOC


© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.