123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- #include "sys-defines.h"
- #include "extern.h"
- #define MAX_DASH_LENGTH 255
- void
- _pl_x_set_attributes (R___(Plotter *_plotter) int x_gc_type)
- {
- int i;
- if (_plotter->x_drawable1 == (Drawable)NULL
- && _plotter->x_drawable2 == (Drawable)NULL)
-
- return;
- if (x_gc_type == X_GC_FOR_DRAWING)
-
- {
- XGCValues gcv;
- bool have_dash_list = false;
- unsigned char *dash_list = (unsigned char *)NULL;
- int dash_list_len = 0, dash_offset = 0;
-
- if (_plotter->drawstate->dash_array_in_effect)
-
- {
- dash_list_len = _plotter->drawstate->dash_array_len;
- if (dash_list_len > 0)
- {
- bool odd_length;
- double min_sing_val, max_sing_val;
- int i, dash_cycle_length;
-
-
- _matrix_sing_vals (_plotter->drawstate->transform.m,
- &min_sing_val, &max_sing_val);
-
- odd_length = (dash_list_len & 1 ? true : false);
- dash_list = (unsigned char *)_pl_xmalloc ((odd_length ? 2 : 1) * dash_list_len * sizeof(unsigned char));
- have_dash_list = true;
- dash_cycle_length = 0;
- for (i = 0; i < dash_list_len; i++)
- {
- double unrounded_dashlen;
- int dashlen;
-
- unrounded_dashlen =
- min_sing_val * _plotter->drawstate->dash_array[i];
-
- dashlen = IROUND(unrounded_dashlen);
- dashlen = IMAX(dashlen, 1);
- dashlen = IMIN(dashlen, MAX_DASH_LENGTH);
-
-
- dash_list[i] = (unsigned int)dashlen;
- dash_cycle_length += dashlen;
- if (odd_length)
- {
- dash_list[dash_list_len + i] = (unsigned int)dashlen;
- dash_cycle_length += dashlen;
- }
- }
- if (odd_length)
- dash_list_len *= 2;
-
- dash_offset = IROUND(min_sing_val * _plotter->drawstate->dash_offset);
- if (dash_cycle_length > 0)
-
- {
- while (dash_offset < 0)
- dash_offset += dash_cycle_length;
- dash_offset %= dash_cycle_length;
- }
-
- gcv.line_style = LineOnOffDash;
- }
- else
- gcv.line_style = LineSolid;
-
- }
- else
-
- {
- if (_plotter->drawstate->line_type != PL_L_SOLID)
- {
- const int *dash_array;
- int i, scale;
-
- dash_list_len = _pl_g_line_styles[_plotter->drawstate->line_type].dash_array_len;
- dash_array = _pl_g_line_styles[_plotter->drawstate->line_type].dash_array;
-
- scale = _plotter->drawstate->quantized_device_line_width;
- if (scale <= 0)
- scale = 1;
- dash_list = (unsigned char *)_pl_xmalloc (PL_MAX_DASH_ARRAY_LEN * sizeof(unsigned char));
- have_dash_list = true;
- for (i = 0; i < dash_list_len; i++)
- {
- int dashlen;
-
- dashlen = scale * dash_array[i];
- dashlen = IMAX(dashlen, 1);
- dashlen = IMIN(dashlen, MAX_DASH_LENGTH);
- dash_list[i] = (unsigned int)dashlen;
- }
-
- gcv.line_style = LineOnOffDash;
- dash_offset = 0;
- }
- else
- {
-
- gcv.line_style = LineSolid;
- }
- }
-
-
- if (have_dash_list)
- {
- bool do_it = false;
- if (_plotter->drawstate->x_gc_dash_offset != dash_offset
- || _plotter->drawstate->x_gc_dash_list_len != dash_list_len)
- do_it = true;
- if (do_it == false)
- {
- for (i = 0; i < dash_list_len; i++)
- {
- if ((unsigned char)_plotter->drawstate->x_gc_dash_list[i] != dash_list[i])
- {
- do_it = true;
- break;
- }
- }
- }
- if (do_it)
- {
-
- XSetDashes (_plotter->x_dpy, _plotter->drawstate->x_gc_fg,
- dash_offset, (char *)dash_list, dash_list_len);
-
-
- if (_plotter->drawstate->x_gc_dash_list_len > 0)
- free ((char *)_plotter->drawstate->x_gc_dash_list);
- _plotter->drawstate->x_gc_dash_list = (char *)dash_list;
- _plotter->drawstate->x_gc_dash_list_len = dash_list_len;
- _plotter->drawstate->x_gc_dash_offset = dash_offset;
- }
- else
- free (dash_list);
- }
-
- if (_plotter->drawstate->x_gc_line_style != gcv.line_style)
- {
-
- XChangeGC (_plotter->x_dpy, _plotter->drawstate->x_gc_fg,
- GCLineStyle, &gcv);
-
- _plotter->drawstate->x_gc_line_style = gcv.line_style;
- }
-
- switch (_plotter->drawstate->cap_type)
- {
- case PL_CAP_BUTT:
- default:
- gcv.cap_style = CapButt;
- break;
- case PL_CAP_ROUND:
- gcv.cap_style = CapRound;
- break;
- case PL_CAP_PROJECT:
- gcv.cap_style = CapProjecting;
- break;
- case PL_CAP_TRIANGULAR:
- gcv.cap_style = CapRound;
- break;
- }
- if (_plotter->drawstate->x_gc_cap_style != gcv.cap_style)
- {
-
- XChangeGC (_plotter->x_dpy, _plotter->drawstate->x_gc_fg,
- GCCapStyle, &gcv);
-
- _plotter->drawstate->x_gc_cap_style = gcv.cap_style;
- }
-
-
- switch (_plotter->drawstate->join_type)
- {
- case PL_JOIN_MITER:
- default:
- gcv.join_style = JoinMiter;
- break;
- case PL_JOIN_ROUND:
- gcv.join_style = JoinRound;
- break;
- case PL_JOIN_BEVEL:
- gcv.join_style = JoinBevel;
- break;
- case PL_JOIN_TRIANGULAR:
- gcv.join_style = JoinRound;
- break;
- }
- if (_plotter->drawstate->x_gc_join_style != gcv.join_style)
- {
-
- XChangeGC (_plotter->x_dpy, _plotter->drawstate->x_gc_fg,
- GCJoinStyle, &gcv);
-
- _plotter->drawstate->x_gc_join_style = gcv.join_style;
- }
-
-
- gcv.line_width = _plotter->drawstate->quantized_device_line_width;
- if (_plotter->drawstate->x_gc_line_width != gcv.line_width)
- {
-
- XChangeGC (_plotter->x_dpy, _plotter->drawstate->x_gc_fg,
- GCLineWidth, &gcv);
-
- _plotter->drawstate->x_gc_line_width = gcv.line_width;
- }
- }
-
- else if (x_gc_type == X_GC_FOR_FILLING)
-
- {
- XGCValues gcv;
-
-
- switch (_plotter->drawstate->fill_rule_type)
- {
- case PL_FILL_ODD_WINDING:
- default:
- gcv.fill_rule = EvenOddRule;
- break;
- case PL_FILL_NONZERO_WINDING:
- gcv.fill_rule = WindingRule;
- break;
- }
- if (_plotter->drawstate->x_gc_fill_rule != gcv.fill_rule)
- {
-
- XChangeGC (_plotter->x_dpy, _plotter->drawstate->x_gc_fill,
- GCFillRule, &gcv);
-
- _plotter->drawstate->x_gc_fill_rule = gcv.fill_rule;
- }
- }
-
- return;
- }
|