/* <fillstyle> = {empty | solid {<density>} | pattern {<n>}} {noborder | border {<lt>}} */ void parse_fillstyle(struct fill_style_type *fs, int def_style, int def_density, int def_pattern, t_colorspec def_bordertype) { TBOOLEAN set_fill = FALSE; TBOOLEAN set_param = FALSE; TBOOLEAN transparent = FALSE; /* Set defaults */ fs->fillstyle = def_style; fs->filldensity = def_density; fs->fillpattern = def_pattern; fs->border_color = def_bordertype; if (END_OF_COMMAND) return; if (!equals(c_token, "fs") && !almost_equals(c_token, "fill$style")) return; c_token++; while (!END_OF_COMMAND) { if (almost_equals(c_token, "trans$parent")) { transparent = TRUE; c_token++; } if (almost_equals(c_token, "e$mpty")) { fs->fillstyle = FS_EMPTY; c_token++; } else if (almost_equals(c_token, "s$olid")) { fs->fillstyle = transparent ? FS_TRANSPARENT_SOLID : FS_SOLID; set_fill = TRUE; c_token++; } else if (almost_equals(c_token, "p$attern")) { fs->fillstyle = transparent ? FS_TRANSPARENT_PATTERN : FS_PATTERN; set_fill = TRUE; c_token++; } if (END_OF_COMMAND) continue; else if (almost_equals(c_token, "bo$rder")) { fs->border_color.type = TC_DEFAULT; c_token++; if (equals(c_token,"-") || isanumber(c_token)) { fs->border_color.type = TC_LT; fs->border_color.lt = int_expression() - 1; } else if (equals(c_token,"lc") || almost_equals(c_token,"linec$olor")) { parse_colorspec(&fs->border_color, TC_Z); } else if (equals(c_token,"rgb") || equals(c_token,"lt") || almost_equals(c_token,"linet$ype")) { c_token--; parse_colorspec(&fs->border_color, TC_Z); } continue; } else if (almost_equals(c_token, "nobo$rder")) { fs->border_color.type = TC_LT; fs->border_color.lt = LT_NODRAW; c_token++; continue; } /* We hit something unexpected */ if (!set_fill || set_param) break; if (!(isanumber(c_token) || type_udv(c_token) == INTGR || type_udv(c_token) == CMPLX)) break; if (fs->fillstyle == FS_SOLID || fs->fillstyle == FS_TRANSPARENT_SOLID) { /* user sets 0...1, but is stored as an integer 0..100 */ fs->filldensity = 100.0 * real_expression() + 0.5; if (fs->filldensity < 0) fs->filldensity = 0; if (fs->filldensity > 100) fs->filldensity = 100; set_param = TRUE; } else if (fs->fillstyle == FS_PATTERN || fs->fillstyle == FS_TRANSPARENT_PATTERN) { fs->fillpattern = int_expression(); if (fs->fillpattern < 0) fs->fillpattern = 0; set_param = TRUE; } } }
/* * allow_ls controls whether we are allowed to accept linestyle in * the current context [ie not when doing a set linestyle command] * allow_point is whether we accept a point command */ int lp_parse(struct lp_style_type *lp, TBOOLEAN allow_ls, TBOOLEAN allow_point) { /* keep track of which options were set during this call */ int set_lt = 0, set_pal = 0, set_lw = 0, set_pt = 0, set_ps = 0, set_pi = 0; int new_lt = 0; /* EAM Mar 2010 - We don't want properties from a user-defined default * linetype to override properties explicitly set here. So fill in a * local lp_style_type as we go and then copy over the specifically * requested properties on top of the default ones. */ struct lp_style_type newlp = *lp; if (allow_ls && (almost_equals(c_token, "lines$tyle") || equals(c_token, "ls"))) { c_token++; lp_use_properties(lp, int_expression()); } while (!END_OF_COMMAND) { if (almost_equals(c_token, "linet$ype") || equals(c_token, "lt")) { if (set_lt++) break; c_token++; if (almost_equals(c_token, "rgb$color")) { if (set_pal++) break; c_token--; parse_colorspec(&(newlp.pm3d_color), TC_RGB); newlp.use_palette = 1; } else /* both syntaxes allowed: 'with lt pal' as well as 'with pal' */ if (almost_equals(c_token, "pal$ette")) { if (set_pal++) break; c_token--; parse_colorspec(&(newlp.pm3d_color), TC_Z); newlp.use_palette = 1; } else if (equals(c_token,"bgnd")) { *lp = background_lp; c_token++; } else { /* These replace the base style */ new_lt = int_expression(); lp->l_type = new_lt - 1; /* user may prefer explicit line styles */ if (prefer_line_styles && allow_ls) lp_use_properties(lp, new_lt); else load_linetype(lp, new_lt); } } /* linetype, lt */ /* both syntaxes allowed: 'with lt pal' as well as 'with pal' */ if (almost_equals(c_token, "pal$ette")) { if (set_pal++) break; c_token--; parse_colorspec(&(newlp.pm3d_color), TC_Z); newlp.use_palette = 1; continue; } if (equals(c_token,"lc") || almost_equals(c_token,"linec$olor") || equals(c_token,"fc") || almost_equals(c_token,"fillc$olor")) { newlp.use_palette = 1; if (set_pal++) break; c_token++; if (almost_equals(c_token, "rgb$color")) { c_token--; parse_colorspec(&(newlp.pm3d_color), TC_RGB); } else if (almost_equals(c_token, "pal$ette")) { c_token--; parse_colorspec(&(newlp.pm3d_color), TC_Z); } else if (equals(c_token,"bgnd")) { newlp.pm3d_color.type = TC_LT; newlp.pm3d_color.lt = LT_BACKGROUND; c_token++; } else if (almost_equals(c_token, "var$iable")) { c_token++; newlp.l_type = LT_COLORFROMCOLUMN; newlp.pm3d_color.type = TC_LINESTYLE; } else { /* Pull the line colour from a default linetype, but */ /* only if we are not in the middle of defining one! */ if (allow_ls) { struct lp_style_type temp; load_linetype(&temp, int_expression()); newlp.pm3d_color = temp.pm3d_color; } else { newlp.pm3d_color.type = TC_LT; newlp.pm3d_color.lt = int_expression() - 1; } } continue; } if (almost_equals(c_token, "linew$idth") || equals(c_token, "lw")) { if (set_lw++) break; c_token++; newlp.l_width = real_expression(); if (newlp.l_width < 0) newlp.l_width = 0; continue; } if (equals(c_token,"bgnd")) { if (set_lt++) break;; c_token++; *lp = background_lp; continue; } if (almost_equals(c_token, "pointt$ype") || equals(c_token, "pt")) { if (allow_point) { if (set_pt++) break; c_token++; newlp.p_type = int_expression() - 1; } else { int_warn(c_token, "No pointtype specifier allowed, here"); c_token += 2; } continue; } if (almost_equals(c_token, "points$ize") || equals(c_token, "ps")) { if (allow_point) { if (set_ps++) break; c_token++; if (almost_equals(c_token, "var$iable")) { newlp.p_size = PTSZ_VARIABLE; c_token++; } else if (almost_equals(c_token, "def$ault")) { newlp.p_size = PTSZ_DEFAULT; c_token++; } else { newlp.p_size = real_expression(); if (newlp.p_size < 0) newlp.p_size = 0; } } else { int_warn(c_token, "No pointsize specifier allowed, here"); c_token += 2; } continue; } if (almost_equals(c_token, "pointi$nterval") || equals(c_token, "pi")) { c_token++; if (allow_point) { newlp.p_interval = int_expression(); set_pi = 1; } else { int_warn(c_token, "No pointinterval specifier allowed, here"); int_expression(); } continue; } /* caught unknown option -> quit the while(1) loop */ break; } if (set_lt > 1 || set_pal > 1 || set_lw > 1 || set_pt > 1 || set_ps > 1) int_error(c_token, "duplicated arguments in style specification"); if (set_pal) { lp->pm3d_color = newlp.pm3d_color; lp->use_palette = newlp.use_palette; /* FIXME: This was used by hidden3d, but breaks contour coloring */ /* new_lt = LT_SINGLECOLOR; */ } if (set_lw) lp->l_width = newlp.l_width; if (set_pt) lp->p_type = newlp.p_type; if (set_ps) lp->p_size = newlp.p_size; if (set_pi) lp->p_interval = newlp.p_interval; if (newlp.l_type == LT_COLORFROMCOLUMN) lp->l_type = LT_COLORFROMCOLUMN; return new_lt; }
void parse_fillstyle(struct fill_style_type *fs, int def_style, int def_density, int def_pattern, t_colorspec def_bordertype) { TBOOLEAN set_fill = FALSE; TBOOLEAN set_border = FALSE; TBOOLEAN transparent = FALSE; /* Set defaults */ fs->fillstyle = def_style; fs->filldensity = def_density; fs->fillpattern = def_pattern; fs->border_color = def_bordertype; if (END_OF_COMMAND) return; if (!equals(c_token, "fs") && !almost_equals(c_token, "fill$style")) return; c_token++; while (!END_OF_COMMAND) { int i; if (almost_equals(c_token, "trans$parent")) { transparent = TRUE; c_token++; continue; } i = lookup_table(fs_opt_tbl, c_token); switch (i) { default: break; case FS_EMPTY: case FS_SOLID: case FS_PATTERN: if (set_fill && fs->fillstyle != i) int_error(c_token, "conflicting option"); fs->fillstyle = i; set_fill = TRUE; c_token++; if (isanumber(c_token) || type_udv(c_token) == INTGR || type_udv(c_token) == CMPLX) { if (fs->fillstyle == FS_SOLID) { /* user sets 0...1, but is stored as an integer 0..100 */ fs->filldensity = 100.0 * real_expression() + 0.5; if (fs->filldensity < 0) fs->filldensity = 0; if (fs->filldensity > 100) fs->filldensity = 100; } else if (fs->fillstyle == FS_PATTERN) { fs->fillpattern = int_expression(); if (fs->fillpattern < 0) fs->fillpattern = 0; } else int_error(c_token, "this fill style does not have a parameter"); } continue; } if (almost_equals(c_token, "bo$rder")) { if (set_border && fs->border_color.lt == LT_NODRAW) int_error(c_token, "conflicting option"); fs->border_color.type = TC_DEFAULT; set_border = TRUE; c_token++; if (END_OF_COMMAND) continue; if (equals(c_token,"-") || isanumber(c_token)) { fs->border_color.type = TC_LT; fs->border_color.lt = int_expression() - 1; } else if (equals(c_token,"lc") || almost_equals(c_token,"linec$olor")) { parse_colorspec(&fs->border_color, TC_Z); } else if (equals(c_token,"rgb") || equals(c_token,"lt") || almost_equals(c_token,"linet$ype")) { c_token--; parse_colorspec(&fs->border_color, TC_Z); } continue; } else if (almost_equals(c_token, "nobo$rder")) { if (set_border && fs->border_color.lt != LT_NODRAW) int_error(c_token, "conflicting option"); fs->border_color.type = TC_LT; fs->border_color.lt = LT_NODRAW; set_border = TRUE; c_token++; continue; } /* Keyword must belong to someone else */ break; } if (transparent) { if (fs->fillstyle == FS_SOLID) fs->fillstyle = FS_TRANSPARENT_SOLID; else if (fs->fillstyle == FS_PATTERN) fs->fillstyle = FS_TRANSPARENT_PATTERN; } }
/* * destination_class tells us whether we are filling in a line style ('set style line'), * a persistant linetype ('set linetype') or an ad hoc set of properties for a single * use ('plot ... lc foo lw baz'). * allow_point controls whether we accept a point attribute in this lp_style. */ int lp_parse(struct lp_style_type *lp, lp_class destination_class, TBOOLEAN allow_point) { /* keep track of which options were set during this call */ int set_lt = 0, set_pal = 0, set_lw = 0; int set_pt = 0, set_ps = 0, set_pi = 0; int set_dt = 0; int new_lt = 0; /* EAM Mar 2010 - We don't want properties from a user-defined default * linetype to override properties explicitly set here. So fill in a * local lp_style_type as we go and then copy over the specifically * requested properties on top of the default ones. */ struct lp_style_type newlp = *lp; if ((destination_class == LP_ADHOC) && (almost_equals(c_token, "lines$tyle") || equals(c_token, "ls"))) { c_token++; lp_use_properties(lp, int_expression()); } while (!END_OF_COMMAND) { /* This special case is to flag an attemp to "set object N lt <lt>", * which would otherwise be accepted but ignored, leading to confusion * FIXME: Couldn't this be handled at a higher level? */ if ((destination_class == LP_NOFILL) && (equals(c_token,"lt") || almost_equals(c_token,"linet$ype"))) { int_error(c_token, "object linecolor must be set using fillstyle border"); } if (almost_equals(c_token, "linet$ype") || equals(c_token, "lt")) { if (set_lt++) break; if (destination_class == LP_TYPE) int_error(c_token, "linetype definition cannot use linetype"); c_token++; if (almost_equals(c_token, "rgb$color")) { if (set_pal++) break; c_token--; parse_colorspec(&(newlp.pm3d_color), TC_RGB); } else /* both syntaxes allowed: 'with lt pal' as well as 'with pal' */ if (almost_equals(c_token, "pal$ette")) { if (set_pal++) break; c_token--; parse_colorspec(&(newlp.pm3d_color), TC_Z); } else if (equals(c_token,"bgnd")) { *lp = background_lp; c_token++; } else if (equals(c_token,"black")) { *lp = default_border_lp; c_token++; } else if (equals(c_token,"nodraw")) { lp->l_type = LT_NODRAW; c_token++; } else { /* These replace the base style */ new_lt = int_expression(); lp->l_type = new_lt - 1; /* user may prefer explicit line styles */ if (prefer_line_styles && (destination_class != LP_STYLE)) lp_use_properties(lp, new_lt); else load_linetype(lp, new_lt); } } /* linetype, lt */ /* both syntaxes allowed: 'with lt pal' as well as 'with pal' */ if (almost_equals(c_token, "pal$ette")) { if (set_pal++) break; c_token--; parse_colorspec(&(newlp.pm3d_color), TC_Z); continue; } /* This is so that "set obj ... lw N fc <colorspec>" doesn't eat up the * fc colorspec as a line property. We need to parse it later as a * _fill_ property. Also prevents "plot ... fc <col1> fs <foo> lw <baz>" * from generating an error claiming redundant line properties. */ if ((destination_class == LP_NOFILL || destination_class == LP_ADHOC) && (equals(c_token,"fc") || almost_equals(c_token,"fillc$olor"))) break; if (equals(c_token,"lc") || almost_equals(c_token,"linec$olor") || equals(c_token,"fc") || almost_equals(c_token,"fillc$olor") ) { if (set_pal++) break; c_token++; if (almost_equals(c_token, "rgb$color") || isstring(c_token)) { c_token--; parse_colorspec(&(newlp.pm3d_color), TC_RGB); } else if (almost_equals(c_token, "pal$ette")) { c_token--; parse_colorspec(&(newlp.pm3d_color), TC_Z); } else if (equals(c_token,"bgnd")) { newlp.pm3d_color.type = TC_LT; newlp.pm3d_color.lt = LT_BACKGROUND; c_token++; } else if (equals(c_token,"black")) { newlp.pm3d_color.type = TC_LT; newlp.pm3d_color.lt = LT_BLACK; c_token++; } else if (almost_equals(c_token, "var$iable")) { c_token++; newlp.l_type = LT_COLORFROMCOLUMN; newlp.pm3d_color.type = TC_LINESTYLE; } else { /* Pull the line colour from a default linetype, but */ /* only if we are not in the middle of defining one! */ if (destination_class != LP_STYLE) { struct lp_style_type temp; load_linetype(&temp, int_expression()); newlp.pm3d_color = temp.pm3d_color; } else { newlp.pm3d_color.type = TC_LT; newlp.pm3d_color.lt = int_expression() - 1; } } continue; } if (almost_equals(c_token, "linew$idth") || equals(c_token, "lw")) { if (set_lw++) break; c_token++; newlp.l_width = real_expression(); if (newlp.l_width < 0) newlp.l_width = 0; continue; } if (equals(c_token,"bgnd")) { if (set_lt++) break;; c_token++; *lp = background_lp; continue; } if (equals(c_token,"black")) { if (set_lt++) break;; c_token++; *lp = default_border_lp; continue; } if (almost_equals(c_token, "pointt$ype") || equals(c_token, "pt")) { if (allow_point) { char *symbol; if (set_pt++) break; c_token++; if ((symbol = try_to_get_string())) { newlp.p_type = PT_CHARACTER; /* An alternative mechanism would be to use * utf8toulong(&newlp.p_char, symbol); */ strncpy((char *)(&newlp.p_char), symbol, 3); /* Truncate ascii text to single character */ if ((((char *)&newlp.p_char)[0] & 0x80) == 0) ((char *)&newlp.p_char)[1] = '\0'; /* UTF-8 characters may use up to 3 bytes */ ((char *)&newlp.p_char)[3] = '\0'; free(symbol); } else { newlp.p_type = int_expression() - 1; } } else { int_warn(c_token, "No pointtype specifier allowed, here"); c_token += 2; } continue; } if (almost_equals(c_token, "points$ize") || equals(c_token, "ps")) { if (allow_point) { if (set_ps++) break; c_token++; if (almost_equals(c_token, "var$iable")) { newlp.p_size = PTSZ_VARIABLE; c_token++; } else if (almost_equals(c_token, "def$ault")) { newlp.p_size = PTSZ_DEFAULT; c_token++; } else { newlp.p_size = real_expression(); if (newlp.p_size < 0) newlp.p_size = 0; } } else { int_warn(c_token, "No pointsize specifier allowed, here"); c_token += 2; } continue; } if (almost_equals(c_token, "pointi$nterval") || equals(c_token, "pi")) { c_token++; if (allow_point) { newlp.p_interval = int_expression(); set_pi = 1; } else { int_warn(c_token, "No pointinterval specifier allowed, here"); int_expression(); } continue; } if (almost_equals(c_token, "dasht$ype") || equals(c_token, "dt")) { int tmp; if (set_dt++) break; c_token++; tmp = parse_dashtype(&newlp.custom_dash_pattern); /* Pull the dashtype from the list of already defined dashtypes, */ /* but only if it we didn't get an explicit one back from parse_dashtype */ if (tmp == DASHTYPE_AXIS) lp->l_type = LT_AXIS; if (tmp >= 0) tmp = load_dashtype(&newlp.custom_dash_pattern, tmp + 1); newlp.d_type = tmp; continue; } /* caught unknown option -> quit the while(1) loop */ break; } if (set_lt > 1 || set_pal > 1 || set_lw > 1 || set_pt > 1 || set_ps > 1 || set_dt > 1) int_error(c_token, "duplicated arguments in style specification"); if (set_pal) { lp->pm3d_color = newlp.pm3d_color; /* hidden3d uses this to decide that a single color surface is wanted */ lp->flags |= LP_EXPLICIT_COLOR; } else { lp->flags &= ~LP_EXPLICIT_COLOR; } if (set_lw) lp->l_width = newlp.l_width; if (set_pt) { lp->p_type = newlp.p_type; lp->p_char = newlp.p_char; } if (set_ps) lp->p_size = newlp.p_size; if (set_pi) lp->p_interval = newlp.p_interval; if (newlp.l_type == LT_COLORFROMCOLUMN) lp->l_type = LT_COLORFROMCOLUMN; if (set_dt) { lp->d_type = newlp.d_type; lp->custom_dash_pattern = newlp.custom_dash_pattern; } return new_lt; }
/* * allow_ls controls whether we are allowed to accept linestyle in * the current context [ie not when doing a set linestyle command] * allow_point is whether we accept a point command * allow any order of options - pm 24.11.2001 * EAM Oct 2005 - Require that default values have been placed in lp by the caller */ void lp_parse(struct lp_style_type *lp, TBOOLEAN allow_ls, TBOOLEAN allow_point) { /* avoid duplicating options */ int set_lt = 0, set_pal = 0, set_lw = 0, set_pt = 0, set_ps = 0; if (allow_ls && (almost_equals(c_token, "lines$tyle") || equals(c_token, "ls"))) { c_token++; lp_use_properties(lp, int_expression()); } while (!END_OF_COMMAND) { if (almost_equals(c_token, "linet$ype") || equals(c_token, "lt")) { if (set_lt++) break; c_token++; if (almost_equals(c_token, "rgb$color")) { if (set_pal++) break; c_token--; parse_colorspec(&lp->pm3d_color, TC_RGB); lp->use_palette = 1; } else /* both syntaxes allowed: 'with lt pal' as well as 'with pal' */ if (almost_equals(c_token, "pal$ette")) { if (set_pal++) break; c_token--; parse_colorspec(&lp->pm3d_color, TC_Z); lp->use_palette = 1; #ifdef KEYWORD_BGND } else if (equals(c_token,"bgnd")) { lp->l_type = LT_BACKGROUND; c_token++; #endif } else { int lt = int_expression(); lp->l_type = lt - 1; /* user may prefer explicit line styles */ if (prefer_line_styles && allow_ls) lp_use_properties(lp, lt); } } /* linetype, lt */ /* both syntaxes allowed: 'with lt pal' as well as 'with pal' */ if (almost_equals(c_token, "pal$ette")) { if (set_pal++) break; c_token--; parse_colorspec(&lp->pm3d_color, TC_Z); lp->use_palette = 1; continue; } if (equals(c_token,"lc") || almost_equals(c_token,"linec$olor")) { lp->use_palette = 1; if (set_pal++) break; c_token++; if (almost_equals(c_token, "rgb$color")) { c_token--; parse_colorspec(&lp->pm3d_color, TC_RGB); } else if (almost_equals(c_token, "pal$ette")) { c_token--; parse_colorspec(&lp->pm3d_color, TC_Z); #ifdef KEYWORD_BGND } else if (equals(c_token,"bgnd")) { lp->pm3d_color.type = TC_LT; lp->pm3d_color.lt = LT_BACKGROUND; c_token++; #endif } else if (almost_equals(c_token, "var$iable")) { c_token++; lp->l_type = LT_COLORFROMCOLUMN; lp->pm3d_color.type = TC_LINESTYLE; } else { lp->pm3d_color.type = TC_LT; lp->pm3d_color.lt = int_expression() - 1; } continue; } if (almost_equals(c_token, "linew$idth") || equals(c_token, "lw")) { if (set_lw++) break; c_token++; lp->l_width = real_expression(); if (lp->l_width < 0) lp->l_width = 0; continue; } if (equals(c_token,"bgnd")) { lp->l_type = LT_BACKGROUND; lp->use_palette = 0; c_token++; continue; } if (almost_equals(c_token, "pointt$ype") || equals(c_token, "pt")) { if (allow_point) { if (set_pt++) break; c_token++; lp->p_type = int_expression() - 1; } else { int_warn(c_token, "No pointtype specifier allowed, here"); c_token += 2; } continue; } if (almost_equals(c_token, "points$ize") || equals(c_token, "ps")) { if (allow_point) { if (set_ps++) break; c_token++; if (almost_equals(c_token, "var$iable")) { lp->p_size = PTSZ_VARIABLE; c_token++; } else if (almost_equals(c_token, "def$ault")) { lp->p_size = PTSZ_DEFAULT; c_token++; } else { lp->p_size = real_expression(); if (lp->p_size < 0) lp->p_size = 0; } } else { int_warn(c_token, "No pointsize specifier allowed, here"); c_token += 2; } continue; } if (almost_equals(c_token, "pointi$nterval") || equals(c_token, "pi")) { c_token++; if (allow_point) { lp->p_interval = int_expression(); } else { int_warn(c_token, "No pointinterval specifier allowed, here"); int_expression(); } continue; } /* unknown option catched -> quit the while(1) loop */ break; } if (set_lt > 1 || set_pal > 1 || set_lw > 1 || set_pt > 1 || set_ps > 1) int_error(c_token, "duplicated arguments in style specification"); }