MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtplot_contlabel_plotlabels

Function gmtplot_contlabel_plotlabels

src/gmt_plot.c:4052–4176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4050}
4051
4052GMT_LOCAL void gmtplot_contlabel_plotlabels (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, struct GMT_CONTOUR *G, unsigned int mode) {
4053 /* mode controls what takes place:
4054 * mode = 1: We place all the PSL variables required to use the text for clipping of painting.
4055 * mode = 2: We paint the text that is stored in the PSL variables.
4056 * mode = 4: We use the text stored in the PSL variables to set up a clip path. CLipping is turned ON.
4057 * mode = 8: We draw the lines.
4058 * mode = 16: We turn clip path OFF.
4059 * mode = 32: We want rounded rectangles instead of straight rectangular boxes [straight text only].
4060 */
4061 int justify = 0, form = 0, *just = NULL, *node = NULL, *nlabels_per_segment = NULL, *npoints_per_segment = NULL;
4062 uint64_t k, m, seg, n_points = 0;
4063 unsigned int n_segments = 0, n_labels = 0, first_point_in_segment = 0, this_seg;
4064 double *angle = NULL, *xpath = NULL, *ypath = NULL, *xtxt = NULL, *ytxt = NULL;
4065 char **txt = NULL, **pen = NULL, **fonts = NULL;
4066 struct GMT_CONTOUR_LINE *L = NULL;
4067 void *A1 = NULL, *A2 = NULL;
4068
4069 form = mode; /* Which actions to take */
4070 if (G->box & 4) form |= PSL_TXT_ROUND; /* Want round box shape */
4071 if (G->curved_text) form |= PSL_TXT_CURVED; /* Want text set along curved path */
4072 if (G->fillbox) form |= PSL_TXT_FILLBOX; /* Want the box filled */
4073 if (G->box & 1) form |= PSL_TXT_DRAWBOX; /* Want box outline */
4074 if (G->font_label.form & 2) /* Must supply both font rgb and pen rgb and use charpath and S to fill and outline text */
4075 form |= (G->font_label.form & 8) ? PSL_TXT_PENFILL : PSL_TXT_FILLPEN;
4076 if (mode & PSL_TXT_INIT) { /* Determine and places all PSL attributes */
4077 char *font = NULL;
4078 if (G->number_placement && G->n_cont == 1) /* Special 1-label justification check */
4079 justify = G->end_just[(G->number_placement+1)/2]; /* Gives index 0 or 1 */
4080 else
4081 justify = G->just;
4082
4083 for (seg = 0; seg < G->n_segments; seg++) {
4084 L = G->segment[seg]; /* Pointer to current segment */
4085 n_segments++; /* Number of segments */
4086 n_points += (unsigned int)L->n; /* Total number of points in all segments so far */
4087 n_labels += L->n_labels; /* Number of labels so far */
4088 }
4089
4090 if (n_labels == 0) return; /* There are no labels */
4091
4092 gmt_M_malloc2 (GMT, xpath, ypath, n_points, NULL, double);
4093 gmt_M_malloc2 (GMT, npoints_per_segment, nlabels_per_segment, n_segments, NULL, int);
4094 if (G->curved_text) { /* Must pass node locations of labels */
4095 node = gmt_M_memory (GMT, NULL, n_labels, int);
4096 A1 = node;
4097 }
4098 else { /* Must pass x,y locations of labels */
4099 gmt_M_malloc2 (GMT, xtxt, ytxt, n_points, NULL, double);
4100 A1 = xtxt;
4101 A2 = ytxt;
4102 }
4103 angle = gmt_M_memory (GMT, NULL, n_labels, double);
4104 txt = gmt_M_memory (GMT, NULL, n_labels, char *);
4105 pen = gmt_M_memory (GMT, NULL, n_segments, char *);
4106 fonts = gmt_M_memory (GMT, NULL, n_labels, char *);
4107 PSL_setfont (PSL, G->font_label.id);
4108 for (seg = m = this_seg = 0; seg < G->n_segments; seg++) { /* Process all segments, skip those without labels */
4109 L = G->segment[seg]; /* Pointer to current segment */

Callers 1

gmt_contlabel_plotFunction · 0.85

Calls 11

PSL_setfontFunction · 0.85
strdupFunction · 0.85
PSL_makepenFunction · 0.85
PSL_makecolorFunction · 0.85
PSL_makefontsizeFunction · 0.85
PSL_makefontFunction · 0.85
PSL_commentFunction · 0.85
gmt_textpath_initFunction · 0.85
psl_set_txt_arrayFunction · 0.85
psl_set_int_arrayFunction · 0.85
PSL_plottextlineFunction · 0.85

Tested by

no test coverage detected