Q: How do the Text object margins work?
A: The margins do work, but it's difficult to correctly set them. You need to offset the values by the frame rectangle of the text. The following code snippet illustrates the necessary steps:
/* This routine assumes that you have defined currentDocText somewhere else */
#define DESIREDleftMARGIN some int value
#define DESIREDrightMARGIN some int value
#define DESIREDtopMARGIN some int value
#define DESIREDbottomMARGIN some int value
- setMargins:sender
{
NXRect aRect;
/* Get the current frame values */
[currentDocText getFrame:&aRect];
[currentDocText setMarginLeft: NX_X(&aRect) + DESIREDleftMARGIN
right: - NX_X(&aRect) + DESIREDrightMARGIN
top: NX_Y(&aRect) + DESIREDtopMARGIN
bottom: - NX_Y(&aRect) + DESIREDbottomMARGIN]; ];
return self;
}
If you call getMarginLeft:right:top:bottom:, the returned values are the same as the ones you provide to setMarginLeft:right:top:bottom:. So, to determine the "true" margins, you need to subtract the frame's dimensions.
QA647
Valid for 1.0, 2.0, 3.0