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

Function psl_paragraphprocess

src/postscriptlight.c:1950–2356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1948}
1949
1950static int psl_paragraphprocess (struct PSL_CTRL *PSL, double y, double fontsize, char *paragraph) {
1951 /* Typeset one or more paragraphs. Separate paragraphs by adding \r to end of last word in a paragraph.
1952 * This is a subfunction that simply place all the text attributes on the stack.
1953 */
1954 int n, p, n_scan, last_k = -1, error = 0, old_font, font, font2, after, len, n_alloc_txt, F_flag;
1955 int *font_unique = NULL;
1956 unsigned int i, i1, i0, j, k, n_items, n_font_unique, n_rgb_unique;
1957 size_t n_alloc, n_words = 0;
1958 double old_size, last_rgb[4] = {0.0, 0.0, 0.0, 0.0}, rgb[4] = {0.0, 0.0, 0.0, 0.0};
1959 int sub_on, super_on, scaps_on, symbol_on, font_on, size_on, color_on, under_on, plain_word = false, escape;
1960 char *c = NULL, *clean = NULL, test_char, **text = NULL, *lastp = NULL, *copy = NULL;
1961 const char *sep = " ";
1962 struct PSL_WORD **word = NULL, **rgb_unique = NULL;
1963
1964 if (fontsize == 0.0) return (PSL_NO_ERROR); /* Nothing to do if text has zero size */
1965
1966 sub_on = super_on = scaps_on = symbol_on = font_on = size_on = color_on = under_on = false;
1967
1968
1969 /* Break input string into words (sorta based on old pstext) */
1970 n_alloc = PSL_CHUNK;
1971 text = (char **) PSL_memory (PSL, NULL, n_alloc, char *);
1972 copy = strdup (paragraph); /* Need copy since strtok_r will mess with the text */
1973 psl_got_composite_fontswitch (PSL, copy);
1974 c = strtok_r (copy, sep, &lastp); /* Found first word */
1975 while (c) { /* Found another word */
1976 text[n_words] = strdup (c);
1977 len = (int)strlen(text[n_words]) - 1;
1978 if (text[n_words][len] == '\r') { /* New paragraph */
1979 text[n_words][len] = '\0'; /* chop off CR */
1980 n_words++;
1981 if (n_words == n_alloc) {
1982 n_alloc <<= 1;
1983 text = (char **) PSL_memory (PSL, text, n_alloc, char *);
1984 }
1985 text[n_words] = strdup (""); /* This adds an empty string */
1986 }
1987 n_words++;
1988 if (n_words == n_alloc) {
1989 n_alloc <<= 1;
1990 text = (char **) PSL_memory (PSL, text, n_alloc, char *);
1991 }
1992 c = strtok_r (NULL, sep, &lastp);
1993 }
1994 text = (char **) PSL_memory (PSL, text, n_words, char *);
1995 PSL_free (copy);
1996
1997 /* Now process the words into pieces we can typeset. */
1998
1999 n_alloc = PSL_CHUNK;
2000 old_font = font = PSL->current.font_no;
2001 old_size = fontsize;
2002 PSL_rgb_copy (rgb, PSL->current.rgb[PSL_IS_FONT]); /* Initial font color is current font color */
2003
2004 word = PSL_memory (PSL, NULL, n_alloc, struct PSL_WORD *);
2005
2006 for (i = k = 0; i < n_words; i++) {
2007

Callers 2

PSL_plotparagraphboxFunction · 0.85
PSL_plotparagraphFunction · 0.85

Calls 12

strdupFunction · 0.85
strtok_rFunction · 0.85
psl_prepare_textFunction · 0.85
psl_add_word_partFunction · 0.85
psl_getfontFunction · 0.85
PSL_messageFunction · 0.85
psl_bulkcopyFunction · 0.85
PSL_commentFunction · 0.85
PSL_commandFunction · 0.85
PSL_defunitsFunction · 0.85
psl_freewordsFunction · 0.85

Tested by

no test coverage detected