Skip to content
Open
17 changes: 13 additions & 4 deletions src/gmt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -14913,13 +14913,22 @@ int gmt_just_decode (struct GMT_CTRL *GMT, char *key, int def) {
/*! . */
void gmt_smart_justify (struct GMT_CTRL *GMT, int just, double angle, double dx, double dy, double *x_shift, double *y_shift, unsigned int mode) {
/* mode = 2: Assume a radius offset so that corner shifts are adjusted by 1/sqrt(2) */
/* mode = 3: pstext -Dj (smart offset based on justification) */
/* mode = 4: pstext -DJ (smart offset based on justification with corner adjustment) */
double s, c, xx, yy, f;
gmt_M_unused(GMT);
f = (mode == 2) ? 1.0 / M_SQRT2 : 1.0;
f = (mode == 2 || mode == 4) ? 1.0 / M_SQRT2 : 1.0;
sincosdegree (angle, &s, &c);
xx = (2 - (just%4)) * dx * f; /* Smart shift in x */
yy = (1 - (just/4)) * dy * f; /* Smart shift in y */
*x_shift += c * xx - s * yy; /* Must account for angle of label */

if (mode >= 3 && just == PSL_MC) {
/* For MC justification, apply offset directly with rotation */
*x_shift += c * dx - s * dy;
*y_shift += s * dx + c * dy;
return;
}
xx = (2 - (just%4)) * dx * f;
yy = (1 - (just/4)) * dy * f;
*x_shift += c * xx - s * yy;
*y_shift += s * xx + c * yy;
}

Expand Down
12 changes: 6 additions & 6 deletions src/pstext.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ GMT_LOCAL void pstext_output_words (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL,
gmt_setpen (GMT, &(T->vecpen));
PSL_plotsegment (PSL, x, y, x + T->x_offset, y + T->y_offset);
}
if (Ctrl->D.justify) /* Smart offset according to justification (from Dave Huang) */
gmt_smart_justify (GMT, T->block_justify, T->paragraph_angle, T->x_offset, T->y_offset, &x, &y, Ctrl->D.justify);
if (Ctrl->D.justify && !(Ctrl->D.justify == 1 && T->block_justify == PSL_MC)) /* Smart offset according to justification (from Dave Huang) */
gmt_smart_justify (GMT, T->block_justify, T->paragraph_angle, T->x_offset, T->y_offset, &x, &y, Ctrl->D.justify + 2);
else
x += T->x_offset, y += T->y_offset; /* Move to the actual reference point */
if (T->boxflag) { /* Need to lay down the box first, then place text */
Expand Down Expand Up @@ -937,8 +937,8 @@ EXTERN_MSC int GMT_pstext (void *V_API, int mode, void *args) {
else if (T.paragraph_angle < -90.0) T.paragraph_angle += 180.0;
}
if (add) {
if (Ctrl->D.justify) /* Smart offset according to justification (from Dave Huang) */
gmt_smart_justify (GMT, T.block_justify, T.paragraph_angle, T.x_offset, T.y_offset, &plot_x, &plot_y, Ctrl->D.justify);
if (Ctrl->D.justify && !(Ctrl->D.justify == 1 && T.block_justify == PSL_MC)) /* Smart offset according to justification (from Dave Huang) */
gmt_smart_justify (GMT, T.block_justify, T.paragraph_angle, T.x_offset, T.y_offset, &plot_x, &plot_y, Ctrl->D.justify + 2);
else { /* Default hard offset */
plot_x += T.x_offset;
plot_y += T.y_offset;
Expand Down Expand Up @@ -1350,8 +1350,8 @@ EXTERN_MSC int GMT_pstext (void *V_API, int mode, void *args) {
else if (T.paragraph_angle < -90.0) T.paragraph_angle += 180.0;
}
if (add) {
if (Ctrl->D.justify) /* Smart offset according to justification (from Dave Huang) */
gmt_smart_justify (GMT, T.block_justify, T.paragraph_angle, T.x_offset, T.y_offset, &plot_x, &plot_y, Ctrl->D.justify);
if (Ctrl->D.justify && !(Ctrl->D.justify == 1 && T.block_justify == PSL_MC)) /* Smart offset according to justification (from Dave Huang) */
gmt_smart_justify (GMT, T.block_justify, T.paragraph_angle, T.x_offset, T.y_offset, &plot_x, &plot_y, Ctrl->D.justify + 2);
else { /* Default hard offset */
plot_x += T.x_offset;
plot_y += T.y_offset;
Expand Down
Loading