123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #include "sys-defines.h"
- #include "extern.h"
- #include "xmi.h"
- static const int mi_join_style[] =
- { MI_JOIN_MITER, MI_JOIN_ROUND, MI_JOIN_BEVEL, MI_JOIN_TRIANGULAR };
- static const int mi_cap_style[] =
- { MI_CAP_BUTT, MI_CAP_ROUND, MI_CAP_PROJECTING, MI_CAP_TRIANGULAR };
- void
- _set_common_mi_attributes (plDrawState *drawstate, void * ptr)
- {
- int line_style, num_dashes, offset;
- unsigned int *dashbuf;
- bool dash_array_allocated = false;
- miGCAttribute attributes[5];
- int values [5];
- unsigned int local_dashbuf[PL_MAX_DASH_ARRAY_LEN];
- miGC *pGC;
- pGC = (miGC *)ptr;
-
-
- attributes[0] = MI_GC_FILL_RULE;
- values[0] = (drawstate->fill_rule_type == PL_FILL_NONZERO_WINDING ?
- MI_WINDING_RULE : MI_EVEN_ODD_RULE);
- attributes[1] = MI_GC_JOIN_STYLE;
- values[1] = mi_join_style[drawstate->join_type];
- attributes[2] = MI_GC_CAP_STYLE;
- values[2] = mi_cap_style[drawstate->cap_type];
- attributes[3] = MI_GC_ARC_MODE;
- values[3] = MI_ARC_CHORD;
- attributes[4] = MI_GC_LINE_WIDTH;
- values[4] = drawstate->quantized_device_line_width;
- miSetGCAttribs (pGC, 5, attributes, values);
-
- miSetGCMiterLimit (pGC, drawstate->miter_limit);
-
- if (drawstate->dash_array_in_effect)
-
- {
- int i;
-
- num_dashes = drawstate->dash_array_len;
- if (num_dashes > 0)
-
- {
- bool odd_length;
- double min_sing_val, max_sing_val;
- int dash_cycle_length;
-
- _matrix_sing_vals (drawstate->transform.m,
- &min_sing_val, &max_sing_val);
-
- line_style = MI_LINE_ON_OFF_DASH;
- odd_length = (num_dashes & 1 ? true : false);
- {
- int array_len;
-
- array_len = (odd_length ? 2 : 1) * num_dashes;
- if (array_len <= PL_MAX_DASH_ARRAY_LEN)
- dashbuf = local_dashbuf;
- else
- {
- dashbuf = (unsigned int *)_pl_xmalloc (array_len * sizeof(unsigned int));
- dash_array_allocated = true;
- }
- }
- dash_cycle_length = 0;
- for (i = 0; i < num_dashes; i++)
- {
- double unrounded_dashlen;
- int dashlen;
- unrounded_dashlen =
- min_sing_val * drawstate->dash_array[i];
- dashlen = IROUND(unrounded_dashlen);
- dashlen = IMAX(dashlen, 1);
- dashbuf[i] = (unsigned int)dashlen;
- dash_cycle_length += dashlen;
- if (odd_length)
- {
- dashbuf[num_dashes + i] = (unsigned int)dashlen;
- dash_cycle_length += dashlen;
- }
- }
- if (odd_length)
- num_dashes *= 2;
- offset = IROUND(min_sing_val * drawstate->dash_offset);
- if (dash_cycle_length > 0)
-
- {
- while (offset < 0)
- offset += dash_cycle_length;
- offset %= dash_cycle_length;
- }
- }
- else
-
- {
- line_style = MI_LINE_SOLID;
- dashbuf = NULL;
- offset = 0;
- }
- }
- else
-
- {
- if (drawstate->line_type == PL_L_SOLID)
- {
- line_style = MI_LINE_SOLID;
- num_dashes = 0;
- dashbuf = NULL;
- offset = 0;
- }
- else
- {
- const int *dash_array;
- int scale, i;
-
- line_style = MI_LINE_ON_OFF_DASH;
- num_dashes =
- _pl_g_line_styles[drawstate->line_type].dash_array_len;
- dash_array = _pl_g_line_styles[drawstate->line_type].dash_array;
- dashbuf = local_dashbuf;
- offset = 0;
-
- scale = drawstate->quantized_device_line_width;
- if (scale <= 0)
- scale = 1;
- for (i = 0; i < num_dashes; i++)
- {
- int dashlen;
-
- dashlen = scale * dash_array[i];
- dashlen = IMAX(dashlen, 1);
- dashbuf[i] = (unsigned int)dashlen;
- }
- }
- }
-
- miSetGCAttrib (pGC, MI_GC_LINE_STYLE, line_style);
- if (line_style != (int)MI_LINE_SOLID)
- miSetGCDashes (pGC, num_dashes, dashbuf, offset);
- if (dash_array_allocated)
- free (dashbuf);
- }
|