123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- #include "sys-defines.h"
- #include "extern.h"
- void
- _pl_c_set_pen_color(R___(Plotter *_plotter) int cgm_object_type)
- {
- int red_long, green_long, blue_long;
- int red, green, blue;
- int byte_count, data_byte_count, data_len;
- int fullstrength;
- if (_plotter->drawstate->pen_type == 0
- && cgm_object_type != CGM_OBJECT_TEXT)
-
- return;
-
- red_long = _plotter->drawstate->fgcolor.red;
- green_long = _plotter->drawstate->fgcolor.green;
- blue_long = _plotter->drawstate->fgcolor.blue;
-
- switch (CGM_BINARY_BYTES_PER_COLOR_COMPONENT)
- {
- case 1:
-
- red = (((unsigned int)red_long) >> 8) & 0xff;
- green = (((unsigned int)green_long) >> 8) & 0xff;
- blue = (((unsigned int)blue_long) >> 8) & 0xff;
- break;
- case 2:
- default:
-
- red = red_long;
- green = green_long;
- blue = blue_long;
- break;
- }
- fullstrength = (1 << (8 * CGM_BINARY_BYTES_PER_COLOR_COMPONENT)) - 1;
- if ((red != 0 || green != 0 || blue != 0)
- && (red != fullstrength || green != fullstrength || blue != fullstrength))
- _plotter->cgm_page_need_color = true;
- switch (cgm_object_type)
- {
- case CGM_OBJECT_OPEN:
- if (_plotter->cgm_line_color.red != red
- || _plotter->cgm_line_color.green != green
- || _plotter->cgm_line_color.blue != blue)
-
- {
- data_len = 3 * CGM_BINARY_BYTES_PER_COLOR_COMPONENT;
- byte_count = data_byte_count = 0;
- _cgm_emit_command_header (_plotter->data->page, _plotter->cgm_encoding,
- CGM_ATTRIBUTE_ELEMENT, 4,
- data_len, &byte_count,
- "LINECOLR");
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)red,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)green,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)blue,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_command_terminator (_plotter->data->page, _plotter->cgm_encoding,
- &byte_count);
-
- _plotter->cgm_line_color.red = red;
- _plotter->cgm_line_color.green = green;
- _plotter->cgm_line_color.blue = blue;
- }
- break;
- case CGM_OBJECT_CLOSED:
- if (_plotter->cgm_edge_color.red != red
- || _plotter->cgm_edge_color.green != green
- || _plotter->cgm_edge_color.blue != blue)
-
- {
- data_len = 3 * CGM_BINARY_BYTES_PER_COLOR_COMPONENT;
- byte_count = data_byte_count = 0;
- _cgm_emit_command_header (_plotter->data->page, _plotter->cgm_encoding,
- CGM_ATTRIBUTE_ELEMENT, 29,
- data_len, &byte_count,
- "EDGECOLR");
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)red,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)green,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)blue,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_command_terminator (_plotter->data->page, _plotter->cgm_encoding,
- &byte_count);
-
- _plotter->cgm_edge_color.red = red;
- _plotter->cgm_edge_color.green = green;
- _plotter->cgm_edge_color.blue = blue;
- }
- break;
- case CGM_OBJECT_MARKER:
- if (_plotter->cgm_marker_color.red != red
- || _plotter->cgm_marker_color.green != green
- || _plotter->cgm_marker_color.blue != blue)
-
- {
- data_len = 3 * CGM_BINARY_BYTES_PER_COLOR_COMPONENT;
- byte_count = data_byte_count = 0;
- _cgm_emit_command_header (_plotter->data->page, _plotter->cgm_encoding,
- CGM_ATTRIBUTE_ELEMENT, 8,
- data_len, &byte_count,
- "MARKERCOLR");
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)red,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)green,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)blue,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_command_terminator (_plotter->data->page, _plotter->cgm_encoding,
- &byte_count);
-
- _plotter->cgm_marker_color.red = red;
- _plotter->cgm_marker_color.green = green;
- _plotter->cgm_marker_color.blue = blue;
- }
- break;
- case CGM_OBJECT_TEXT:
- if (_plotter->cgm_text_color.red != red
- || _plotter->cgm_text_color.green != green
- || _plotter->cgm_text_color.blue != blue)
-
- {
- data_len = 3 * CGM_BINARY_BYTES_PER_COLOR_COMPONENT;
- byte_count = data_byte_count = 0;
- _cgm_emit_command_header (_plotter->data->page, _plotter->cgm_encoding,
- CGM_ATTRIBUTE_ELEMENT, 14,
- data_len, &byte_count,
- "TEXTCOLR");
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)red,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)green,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)blue,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_command_terminator (_plotter->data->page, _plotter->cgm_encoding,
- &byte_count);
-
- _plotter->cgm_text_color.red = red;
- _plotter->cgm_text_color.green = green;
- _plotter->cgm_text_color.blue = blue;
- }
- break;
- default:
- break;
- }
- }
- void
- _pl_c_set_fill_color(R___(Plotter *_plotter) int cgm_object_type)
- {
- int red_long, green_long, blue_long;
- int red, green, blue;
- int fullstrength;
- int byte_count, data_byte_count, data_len;
- if (_plotter->drawstate->fill_type == 0)
-
- return;
- if (cgm_object_type != CGM_OBJECT_OPEN
- && cgm_object_type != CGM_OBJECT_CLOSED)
-
- return;
-
- red_long = _plotter->drawstate->fillcolor.red;
- green_long = _plotter->drawstate->fillcolor.green;
- blue_long = _plotter->drawstate->fillcolor.blue;
-
- switch (CGM_BINARY_BYTES_PER_COLOR_COMPONENT)
- {
- case 1:
-
- red = (((unsigned int)red_long) >> 8) & 0xff;
- green = (((unsigned int)green_long) >> 8) & 0xff;
- blue = (((unsigned int)blue_long) >> 8) & 0xff;
- break;
- case 2:
- default:
-
- red = red_long;
- green = green_long;
- blue = blue_long;
- break;
- }
- fullstrength = (1 << (8 * CGM_BINARY_BYTES_PER_COLOR_COMPONENT)) - 1;
- if ((red != 0 || green != 0 || blue != 0)
- && (red != fullstrength || green != fullstrength || blue != fullstrength))
- _plotter->cgm_page_need_color = true;
- if (_plotter->cgm_fillcolor.red != red
- || _plotter->cgm_fillcolor.green != green
- || _plotter->cgm_fillcolor.blue != blue)
-
- {
- data_len = 3 * CGM_BINARY_BYTES_PER_COLOR_COMPONENT;
- byte_count = data_byte_count = 0;
- _cgm_emit_command_header (_plotter->data->page, _plotter->cgm_encoding,
- CGM_ATTRIBUTE_ELEMENT, 23,
- data_len, &byte_count,
- "FILLCOLR");
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)red,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)green,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_color_component (_plotter->data->page, false, _plotter->cgm_encoding,
- (unsigned int)blue,
- data_len, &data_byte_count, &byte_count);
- _cgm_emit_command_terminator (_plotter->data->page, _plotter->cgm_encoding,
- &byte_count);
-
- _plotter->cgm_fillcolor.red = red;
- _plotter->cgm_fillcolor.green = green;
- _plotter->cgm_fillcolor.blue = blue;
- }
- }
- void
- _pl_c_set_bg_color(S___(Plotter *_plotter))
- {
- int red_long, green_long, blue_long;
- int red, green, blue;
-
- red_long = _plotter->drawstate->bgcolor.red;
- green_long = _plotter->drawstate->bgcolor.green;
- blue_long = _plotter->drawstate->bgcolor.blue;
-
- switch (CGM_BINARY_BYTES_PER_COLOR_COMPONENT)
- {
- case 1:
-
- red = (((unsigned int)red_long) >> 8) & 0xff;
- green = (((unsigned int)green_long) >> 8) & 0xff;
- blue = (((unsigned int)blue_long) >> 8) & 0xff;
- break;
- case 2:
- default:
-
- red = red_long;
- green = green_long;
- blue = blue_long;
- break;
- }
-
- _plotter->cgm_bgcolor.red = red;
- _plotter->cgm_bgcolor.green = green;
- _plotter->cgm_bgcolor.blue = blue;
-
- _plotter->cgm_bgcolor_suppressed = _plotter->drawstate->bgcolor_suppressed;
- }
|