Skip to content

Commit 31ec2b3

Browse files
authored
pstext: fix text clipping issue 8929 (#8996)
Fix #8929 Assisted-by: Claude Sonnet 4.6
1 parent bc3d467 commit 31ec2b3

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

src/pstext.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,37 @@ EXTERN_MSC int GMT_pstext (void *V_API, int mode, void *args) {
10241024
curr_txt = use_text;
10251025
fmode = gmt_setfont (GMT, &T.font);
10261026

1027-
PSL_plottext (PSL, plot_x, plot_y, T.font.size, curr_txt, T.paragraph_angle, T.block_justify, fmode);
1027+
if (Ctrl->G.mode) { /* Set up text clip path instead of plotting directly */
1028+
int n_labels = 1, form = (T.boxflag & 4) ? PSL_TXT_ROUND : 0;
1029+
char *font = NULL, **fonts = NULL;
1030+
double one_x = plot_x, one_y = plot_y, one_angle = T.paragraph_angle;
1031+
int one_just = T.block_justify;
1032+
char *one_txt[1];
1033+
one_txt[0] = curr_txt;
1034+
form |= PSL_TXT_INIT;
1035+
if (Ctrl->G.mode == PSTEXT_CLIPPLOT) form |= PSL_TXT_SHOW;
1036+
form |= PSL_TXT_CLIP_ON;
1037+
gmt_textpath_init(GMT, &Ctrl->W.pen, Ctrl->G.fill.rgb);
1038+
if (T.space_flag) {
1039+
offset[0] = 0.01 * T.x_space * T.font.size / PSL_POINTS_PER_INCH;
1040+
offset[1] = 0.01 * T.y_space * T.font.size / PSL_POINTS_PER_INCH;
1041+
}
1042+
else {
1043+
offset[0] = T.x_space;
1044+
offset[1] = T.y_space;
1045+
}
1046+
fonts = gmt_M_memory(GMT, NULL, 1, char *);
1047+
PSL_setfont(PSL, T.font.id);
1048+
font = PSL_makefont(PSL, T.font.size, T.font.fill.rgb);
1049+
fonts[0] = strdup(font);
1050+
psl_set_int_array(PSL, "label_justify", &one_just, 1);
1051+
psl_set_txt_array(PSL, "label_font", fonts, 1);
1052+
PSL_plottextline(PSL, NULL, NULL, NULL, 1, &one_x, &one_y, one_txt, &one_angle, &n_labels, T.font.size, T.block_justify, offset, form);
1053+
gmt_M_str_free(fonts[0]);
1054+
gmt_M_free(GMT, fonts);
1055+
}
1056+
else
1057+
PSL_plottext(PSL, plot_x, plot_y, T.font.size, curr_txt, T.paragraph_angle, T.block_justify, fmode);
10281058

10291059
if (clip_set)
10301060
gmt_map_clip_off (GMT);
@@ -1054,7 +1084,7 @@ EXTERN_MSC int GMT_pstext (void *V_API, int mode, void *args) {
10541084
if (!Ctrl->F.get_xy_from_justify && Ctrl->F.R_justify == 0) ncol += 2; /* Expect input to have x,y */
10551085
ncol += a_col; /* Might also have the angle among the numerical columns */
10561086
if (Ctrl->F.get_text == GET_CMD_FORMAT) { /* Format z column into text */
1057-
z_col = ncol - a_col; /* Normally this would be GMT_Z */
1087+
z_col = ncol - a_col; /* Normally this would be GMT_Z */
10581088
ncol++; /* One more numerical column to read */
10591089
rec_mode = (Ctrl->F.mixed) ? GMT_READ_MIXED : GMT_READ_DATA;
10601090
geometry = (Ctrl->F.mixed) ? GMT_IS_NONE : GMT_IS_POINT;

0 commit comments

Comments
 (0)