diff --git a/src/gmt_support.c b/src/gmt_support.c index 6941e47d04f..61e87ef6176 100644 --- a/src/gmt_support.c +++ b/src/gmt_support.c @@ -14913,14 +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 */ - *y_shift += s * xx + c * yy; + + if (mode >= 3 && just == PSL_MC) { + *x_shift += dx; + *y_shift += 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 } /*! . */ diff --git a/src/pstext.c b/src/pstext.c index d69b622699f..507e6136562 100644 --- a/src/pstext.c +++ b/src/pstext.c @@ -187,7 +187,7 @@ GMT_LOCAL void pstext_output_words (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, 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); + 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 */ @@ -938,7 +938,7 @@ EXTERN_MSC int GMT_pstext (void *V_API, int mode, void *args) { } 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); + 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; @@ -1351,7 +1351,7 @@ EXTERN_MSC int GMT_pstext (void *V_API, int mode, void *args) { } 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); + 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;