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

Function PSL_plotparagraphbox

src/postscriptlight.c:5897–5992  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5895}
5896
5897int PSL_plotparagraphbox (struct PSL_CTRL *PSL, double x, double y, double fontsize, char *paragraph, double angle, int justify, double offset[], int mode) {
5898 /* Determines the text box that fits the given typeset paragraph and fills/strokes with current fill/pen.
5899 * mode = 0 (PSL_RECT_STRAIGHT), 1 (PSL_RECT_ROUNDED), 2 (PSL_RECT_CONVEX) or 3 (PSL_RECT_CONCAVE).
5900 */
5901 int error = 0;
5902 if (offset[0] < 0.0 || offset[1] < 0.0) {
5903 PSL_message (PSL, PSL_MSG_ERROR, "Warning: Bad paragraphbox text offset (%g/%g)\n", offset[0], offset[1]);
5904 return (PSL_BAD_VALUE);
5905 }
5906 if (mode < PSL_RECT_STRAIGHT || mode > PSL_RECT_CONCAVE) {
5907 PSL_message (PSL, PSL_MSG_ERROR, "Warning: Bad paragraphbox mode (%d)\n", mode);
5908 return (PSL_BAD_VALUE);
5909 }
5910
5911 if ((error = psl_paragraphprocess (PSL, y, fontsize, paragraph)) != PSL_NO_ERROR) return (error);
5912
5913 PSL_command (PSL, "V ");
5914 PSL_setorigin (PSL, x, y, angle, PSL_FWD); /* To original point */
5915
5916 /* Do the relative horizontal justification */
5917
5918 PSL_defunits (PSL, "PSL_xgap", offset[0]);
5919 PSL_defunits (PSL, "PSL_ygap", offset[1]);
5920
5921 PSL_command (PSL, "0 0 M\n0 PSL_textjustifier");
5922 PSL_command (PSL, (PSL->internal.comments) ? "\t%% Just get paragraph height\n" : "\n");
5923
5924 /* Adjust origin for box justification */
5925
5926 PSL_command (PSL, "/PSL_justify %d def\n", justify);
5927 PSL_command (PSL, "/PSL_x0 PSL_parwidth PSL_justify 1 sub 4 mod 0.5 mul neg mul def\n");
5928 if (justify > 8) /* Top row */
5929 PSL_command (PSL, "/PSL_y0 0 def\n");
5930 else if (justify > 4) /* Middle row */
5931 PSL_command (PSL, "/PSL_y0 PSL_parheight 2 div def\n");
5932 else /* Bottom row */
5933 PSL_command (PSL, "/PSL_y0 PSL_parheight def\n");
5934 PSL_command (PSL, "/PSL_txt_y0 PSL_top neg def\n");
5935
5936 /* Make upper left textbox corner the origin */
5937
5938 PSL_command (PSL, "PSL_x0 PSL_y0 T\n");
5939
5940 PSL_comment (PSL, "Start PSL box beneath text block:\n");
5941 if (mode == PSL_RECT_CONVEX) { /* Create convex box path */
5942 PSL_command (PSL, "/PSL_h PSL_parheight 2 div PSL_ygap add def\n");
5943 PSL_command (PSL, "/PSL_w PSL_parwidth 2 div PSL_xgap add def\n");
5944 PSL_command (PSL, "/PSL_rx PSL_w PSL_w mul PSL_xgap PSL_xgap mul add 2 PSL_xgap mul div def\n");
5945 PSL_command (PSL, "/PSL_ry PSL_h PSL_h mul PSL_ygap PSL_ygap mul add 2 PSL_ygap mul div def\n");
5946 PSL_command (PSL, "/PSL_ax PSL_w PSL_rx PSL_xgap sub atan def\n");
5947 PSL_command (PSL, "/PSL_ay PSL_h PSL_ry PSL_ygap sub atan def\n");
5948 PSL_comment (PSL, "PSL_path:\n");
5949 PSL_command (PSL, "PSL_xgap neg PSL_ygap M\n");
5950 PSL_command (PSL, "PSL_ry PSL_xgap 2 mul sub PSL_parheight 2 div neg PSL_ry 180 PSL_ay sub 180 PSL_ay add arc\n");
5951 PSL_command (PSL, "PSL_parwidth 2 div PSL_parheight 2 PSL_ygap mul add PSL_rx sub neg PSL_rx 270 PSL_ax sub 270 PSL_ax add arc\n");
5952 PSL_command (PSL, "PSL_parwidth PSL_xgap 2 mul add PSL_ry sub PSL_parheight 2 div neg PSL_ry PSL_ay dup neg exch arc\n");
5953 PSL_command (PSL, "PSL_parwidth 2 div PSL_ygap 2 mul PSL_rx sub PSL_rx 90 PSL_ax sub 90 PSL_ax add arc\n");
5954 }

Callers 3

PSL_plotparagraphbox_Function · 0.85
pstext_output_wordsFunction · 0.85
mainFunction · 0.85

Calls 6

PSL_messageFunction · 0.85
psl_paragraphprocessFunction · 0.85
PSL_commandFunction · 0.85
PSL_setoriginFunction · 0.85
PSL_defunitsFunction · 0.85
PSL_commentFunction · 0.85

Tested by

no test coverage detected