Skip to content

Clipping seems not working with gmt text -G+n when text position is assigned using -F+c[justify] #8929

Closed

Description

@mkononets

Clipping seems not working with gmt text -G+n when text position is assigned using -F+c[justify]

gmt begin text-clipping png
  gmt plot -T -R0/1/0/1 -JX5c
  gmt text -F+f10p,Helvetica+cMC+jMC+t'Test text' -G+n -C20%+tO -N
  gmt basemap -BWStr -Bxafg -Byafg
  gmt clip -C
  gmt text -F+f10p,Helvetica+cMC+jMC+t'Test text' -Gred@90 -C20%+tO
gmt end show
Image

Providing coordinates on the input enables clipping, that is, the gridlines behind the text label got clipped, see below.

gmt begin text-clipping png
  gmt plot -T -R0/1/0/1 -JX5c
  echo 0.5 0.5 | gmt text -F+f10p,Helvetica+jMC+t'Test text' -G+n -C20%+tO -N
  gmt basemap -BWStr -Bxafg -Byafg
  gmt clip -C
  gmt text -F+f10p,Helvetica+cMC+jMC+t'Test text' -Gred@90 -C20%+tO
gmt end show
Image

gmt 6.6.0 on linux, same with versions 6.5.0 and 6.3.0 FWIW.

Activity

  1. added
    bug
    on Mar 17, 2026
  2. changed the title [-]Clipping seems not working with `gmt text -G+n` when text position is assigned using -F+c[justify] -G+n[/-] [+]Clipping seems not working with `gmt text -G+n` when text position is assigned using `-F+c[justify]`[/+] on Mar 17, 2026
  3. anbj commented on Mar 17, 2026

    @anbj
    Contributor

    (It looks like the link to 'clip -C' (https://docs.generic-mapping-tools.org/dev/text.html#g) refers to the wrong -C (text module); it's supposed to link to -C in the clip module I think.)

  4. joa-quim commented on Mar 20, 2026

    @joa-quim
    Member

    By Claude's

    ● Now it's clear.
    
      Issue #8929: Root Cause
    
      The bug is in pstext.c, in the Ctrl->F.no_input early-return branch (lines 911-986).
    
      What happens
    
      When using -F+cMC+t'Test text' (text and position fully specified on the command line, no input data), the code enters the no_input branch at line 911.
      This branch:
    
      1. Computes the position from +cMC (line 923)
      2. Plots the text box and/or text directly (lines 955-977)
      3. Returns at line 986
    
      The problem: this branch completely ignores Ctrl->G.mode. It never collects the text into the c_x/c_y/c_txt/c_angle/c_just/c_font arrays, and never
      calls PSL_plottextline() with PSL_TXT_CLIP_ON to activate the clipping path.
    
      Why the workaround works
    
      When coordinates are piped in (echo 0.5 0.5 | gmt text -F+jMC+t'Test text' -G+n ...), the code takes the main loop path (lines 1059-1443) instead. In
      that path, when Ctrl->G.mode is set (line 1422), text info is collected into arrays, and after the loop ends, PSL_plottextline() is called at line 1495
      with PSL_TXT_CLIP_ON to properly set up the clipping path.
    
      The fix
    
      The no_input branch (lines 911-986) needs to handle Ctrl->G.mode. Instead of directly plotting and returning, when Ctrl->G.mode is set it should:
      1. Collect the text info into the clipping arrays (like lines 1422-1435 do)
      2. Call PSL_plottextline() with PSL_TXT_CLIP_ON (like lines 1466-1495 do)
    
      Or more simply, the no_input path could be refactored to feed into the same clipping logic that the main path uses.
    
  5. added a commit that references this issue on Apr 22, 2026
    31ec2b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions