| 5767 | } |
| 5768 | |
| 5769 | int PSL_plottextline (struct PSL_CTRL *PSL, double x[], double y[], int np[], int n_segments, void *arg1, void *arg2, char *label[], double angle[], int nlabel_per_seg[], double fontsize, int justify, double offset[], int mode) { |
| 5770 | /* Placing text along lines, setting up text clippaths, and drawing the lines */ |
| 5771 | /* x,y Array containing the concatenated label path of all segments |
| 5772 | * np Array containing length of each label path segment in concatenated path |
| 5773 | * n_segments Number of line segments |
| 5774 | * arg1, arg2 These are pointers to two arrays, depending on whether we have curved or straight baselines: |
| 5775 | * If curved baselines then |
| 5776 | * arg1 = node Index into x/y array of label plot positions per segment (i.e., start from 0 for each new segment) |
| 5777 | * arg2 = NULL Not used |
| 5778 | * If straight text baselines then |
| 5779 | * arg1 = xp Array of x coordinates of where labels will be placed |
| 5780 | * arg2 = yp Array of y coordinates of where labels will be placed |
| 5781 | * label Array of text labels |
| 5782 | * angle Text angle for each label |
| 5783 | * nlabel_per_seg Array containing number of labels per segment |
| 5784 | * fontsize Constant fontsize of all label texts [font use is the current font set with PSL_setfont] |
| 5785 | * just Justification of text relative to label coordinates [constant for all labels] |
| 5786 | * offset Clearances between text and textbox [constant] |
| 5787 | * mode = 1: We place all the PSL variables required to use the text for clipping of painting. |
| 5788 | * = 2: We paint the text that is stored in the PSL variables. |
| 5789 | * = 4: We use the text stored in the PSL variables to set up a clip path. Clipping is turned ON. |
| 5790 | * = 8: We draw the paths. |
| 5791 | * = 16: We turn clip path OFF. |
| 5792 | * = 32: We want rounded rectangles instead of straight rectangular boxes [straight text only]. |
| 5793 | * = 64: Typeset text along path [straight text]. |
| 5794 | * = 128: Fill box |
| 5795 | * = 256: Draw box |
| 5796 | * = 512: Fill & outline font, fill first, then outline |
| 5797 | * = 1024: Fill & outline font, outline first, then fill |
| 5798 | */ |
| 5799 | |
| 5800 | bool curved = ((mode & PSL_TXT_CURVED) == PSL_TXT_CURVED); /* True if baseline must follow line path */ |
| 5801 | int extras, kind = (curved) ? 1 : 0; |
| 5802 | char *name[2] = {"straight", "curved"}, *ext[2] = {"clip", "labels"}; |
| 5803 | |
| 5804 | if (mode & 1) { /* Lay down PSL variables */ |
| 5805 | int i = 0, n_labels = 0; |
| 5806 | |
| 5807 | if (n_segments <= 0) return (PSL_NO_ERROR); /* Nothing to do yet */ |
| 5808 | if (fontsize == 0.0) return (PSL_NO_ERROR); /* Nothing to do if text has zero size */ |
| 5809 | |
| 5810 | if (justify < 0) psl_remove_spaces (label, n_segments, nlabel_per_seg); /* Strip leading and trailing spaces */ |
| 5811 | for (i = 0; i < n_segments; i++) n_labels += nlabel_per_seg[i]; /* Count number of labels */ |
| 5812 | |
| 5813 | /* Set clearance and text height parameters */ |
| 5814 | PSL_comment (PSL, "Set constants for textbox clearance:\n"); |
| 5815 | PSL_defunits (PSL, "PSL_gap_x", offset[0]); /* Set text clearance in x direction */ |
| 5816 | PSL_defunits (PSL, "PSL_gap_y", offset[1]); /* Set text clearance in y direction */ |
| 5817 | |
| 5818 | /* Set PSL arrays and constants for this set of lines and labels */ |
| 5819 | if (curved) /* Set PSL array for curved baselines [also used to draw lines if selected] */ |
| 5820 | psl_set_reducedpath_arrays (PSL, x, y, n_segments, np, nlabel_per_seg, arg1); |
| 5821 | psl_set_attr_arrays (PSL, (curved) ? arg1 : NULL, angle, label, n_segments, nlabel_per_seg); |
| 5822 | psl_set_int_array (PSL, "label_n", nlabel_per_seg, n_segments); |
| 5823 | PSL_definteger (PSL, "PSL_n_paths", n_segments); |
| 5824 | PSL_definteger (PSL, "PSL_n_labels", n_labels); |
| 5825 | if (!curved) /* Set PSL array for text location with straight baselines */ |
| 5826 | psl_set_path_arrays (PSL, "txt", arg1, arg2, 1, &n_labels); |
no test coverage detected