作図ソフト dia の改良版
Révision | 9f7e2a9b612f117602a775cfb4c5aee529ab4154 (tree) |
---|---|
l'heure | 2014-06-08 17:57:32 |
Auteur | Hans Breuer <hans@breu...> |
Commiter | Hans Breuer |
cgm: replace magic numbers with named constants
No behavior change intended nor observed. There is no effect on the
exported files.
@@ -25,6 +25,8 @@ | ||
25 | 25 | #include <config.h> |
26 | 26 | #endif |
27 | 27 | |
28 | +#include "cgm.h" | |
29 | + | |
28 | 30 | #include <stdio.h> |
29 | 31 | #include <string.h> |
30 | 32 | #include <math.h> |
@@ -133,7 +135,7 @@ write_real(FILE *fp, double x) | ||
133 | 135 | } |
134 | 136 | |
135 | 137 | static void |
136 | -write_elhead(FILE *fp, int el_class, int el_id, int nparams) | |
138 | +write_elhead(FILE *fp, CgmElementClass el_class, int el_id, int nparams) | |
137 | 139 | { |
138 | 140 | guint16 head; |
139 | 141 |
@@ -398,7 +400,7 @@ LineAttrCGM *lnew, *lold; | ||
398 | 400 | |
399 | 401 | if ( lnew->cap != lold->cap ) |
400 | 402 | { |
401 | - write_elhead(renderer->file, 5, 37, 4); | |
403 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_LINE_CAP, 4); | |
402 | 404 | write_int16(renderer->file, lnew->cap); |
403 | 405 | write_int16(renderer->file, 3); /* cap of dashlines match */ |
404 | 406 | /* normal cap */ |
@@ -406,19 +408,19 @@ LineAttrCGM *lnew, *lold; | ||
406 | 408 | } |
407 | 409 | if ( lnew->join != lold->join ) |
408 | 410 | { |
409 | - write_elhead(renderer->file, 5, 38, 2); | |
411 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_LINE_JOIN, 2); | |
410 | 412 | write_int16(renderer->file, lnew->join); |
411 | 413 | lold->join = lnew->join; |
412 | 414 | } |
413 | 415 | if ( lnew->style != lold->style ) |
414 | 416 | { |
415 | - write_elhead(renderer->file, 5, 2, 2); | |
417 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_LINE_TYPE, 2); | |
416 | 418 | write_int16(renderer->file, lnew->style); |
417 | 419 | lold->style = lnew->style; |
418 | 420 | } |
419 | 421 | if ( lnew->width != lold->width ) |
420 | 422 | { |
421 | - write_elhead(renderer->file, 5, 3, REALSIZE); | |
423 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_LINE_WIDTH, REALSIZE); | |
422 | 424 | write_real(renderer->file, lnew->width); |
423 | 425 | lold->width = lnew->width; |
424 | 426 | } |
@@ -428,7 +430,7 @@ LineAttrCGM *lnew, *lold; | ||
428 | 430 | lnew->color.blue != lold->color.blue || |
429 | 431 | lnew->color.alpha != lold->color.alpha) |
430 | 432 | { |
431 | - write_elhead(renderer->file, 5, 4, 3); /* line colour */ | |
433 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_LINE_COLOR, 3); /* line color */ | |
432 | 434 | write_colour(renderer->file, &lnew->color); |
433 | 435 | putc(0, renderer->file); |
434 | 436 | lold->color = lnew->color; |
@@ -464,7 +466,7 @@ FillEdgeAttrCGM *fnew, *fold; | ||
464 | 466 | fnew->edgevis = 0; /* edge off */ |
465 | 467 | if ( fnew->edgevis != fold->edgevis ) |
466 | 468 | { |
467 | - write_elhead(renderer->file, 5, 30, 2); | |
469 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_EDGE_VISIBILITY, 2); | |
468 | 470 | write_int16(renderer->file, fnew->edgevis); |
469 | 471 | fold->edgevis = fnew->edgevis; |
470 | 472 | } |
@@ -474,13 +476,13 @@ FillEdgeAttrCGM *fnew, *fold; | ||
474 | 476 | fnew->edgevis = 1; /* edge on */ |
475 | 477 | if ( fnew->edgevis != fold->edgevis ) |
476 | 478 | { |
477 | - write_elhead(renderer->file, 5, 30, 2); | |
479 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_EDGE_VISIBILITY, 2); | |
478 | 480 | write_int16(renderer->file, fnew->edgevis); |
479 | 481 | fold->edgevis = fnew->edgevis; |
480 | 482 | } |
481 | 483 | if ( fnew->cap != fold->cap ) |
482 | 484 | { |
483 | - write_elhead(renderer->file, 5, 44, 4); | |
485 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_EDGE_CAP, 4); | |
484 | 486 | write_int16(renderer->file, fnew->cap); |
485 | 487 | write_int16(renderer->file, 3); /* cap of dashlines match */ |
486 | 488 | /* normal cap */ |
@@ -488,19 +490,19 @@ FillEdgeAttrCGM *fnew, *fold; | ||
488 | 490 | } |
489 | 491 | if ( fnew->join != fold->join ) |
490 | 492 | { |
491 | - write_elhead(renderer->file, 5, 45, 2); | |
493 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_EDGE_JOIN, 2); | |
492 | 494 | write_int16(renderer->file, fnew->join); |
493 | - fold->join = fnew->join; | |
495 | + fold->join = fnew->join; | |
494 | 496 | } |
495 | 497 | if ( fnew->style != fold->style ) |
496 | 498 | { |
497 | - write_elhead(renderer->file, 5, 27, 2); | |
499 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_EDGE_TYPE, 2); | |
498 | 500 | write_int16(renderer->file, fnew->style); |
499 | 501 | fold->style = fnew->style; |
500 | 502 | } |
501 | 503 | if ( fnew->width != fold->width ) |
502 | 504 | { |
503 | - write_elhead(renderer->file, 5, 28, REALSIZE); | |
505 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_EDGE_WIDTH, REALSIZE); | |
504 | 506 | write_real(renderer->file, fnew->width); |
505 | 507 | fold->width = fnew->width; |
506 | 508 | } |
@@ -510,7 +512,7 @@ FillEdgeAttrCGM *fnew, *fold; | ||
510 | 512 | fnew->color.blue != fold->color.blue || |
511 | 513 | fnew->color.alpha != fold->color.alpha) |
512 | 514 | { |
513 | - write_elhead(renderer->file, 5, 29, 3); /* line colour */ | |
515 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_EDGE_COLOR, 3); /* line color */ | |
514 | 516 | write_colour(renderer->file, &fnew->color); |
515 | 517 | putc(0, renderer->file); |
516 | 518 | fold->color = fnew->color; |
@@ -522,7 +524,7 @@ FillEdgeAttrCGM *fnew, *fold; | ||
522 | 524 | fnew->fill_style = 4; /* empty */ |
523 | 525 | if ( fnew->fill_style != fold->fill_style ) |
524 | 526 | { |
525 | - write_elhead(renderer->file, 5, 22, 2); | |
527 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_INTERIOR_STYLE, 2); | |
526 | 528 | write_int16(renderer->file, fnew->fill_style); |
527 | 529 | fold->fill_style = fnew->fill_style; |
528 | 530 | } |
@@ -532,7 +534,7 @@ FillEdgeAttrCGM *fnew, *fold; | ||
532 | 534 | fnew->fill_style = 1; /* solid fill */ |
533 | 535 | if ( fnew->fill_style != fold->fill_style ) |
534 | 536 | { |
535 | - write_elhead(renderer->file, 5, 22, 2); | |
537 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_INTERIOR_STYLE, 2); | |
536 | 538 | write_int16(renderer->file, fnew->fill_style); |
537 | 539 | fold->fill_style = fnew->fill_style; |
538 | 540 | } |
@@ -542,7 +544,7 @@ FillEdgeAttrCGM *fnew, *fold; | ||
542 | 544 | fnew->fill_color.blue != fold->fill_color.blue || |
543 | 545 | fnew->fill_color.alpha != fold->fill_color.alpha) |
544 | 546 | { |
545 | - write_elhead(renderer->file, 5, 23, 3); /* fill colour */ | |
547 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_FILL_COLOR, 3); /* fill color */ | |
546 | 548 | write_colour(renderer->file, &fnew->fill_color); |
547 | 549 | putc(0, renderer->file); |
548 | 550 | fold->fill_color = fnew->fill_color; |
@@ -565,7 +567,7 @@ TextAttrCGM *tnew, *told; | ||
565 | 567 | */ |
566 | 568 | if ( tnew->font_num != told->font_num ) |
567 | 569 | { |
568 | - write_elhead(renderer->file, 5, 10, 2); | |
570 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_TEXT_FONT_INDEX, 2); | |
569 | 571 | write_int16(renderer->file, tnew->font_num); |
570 | 572 | told->font_num = tnew->font_num; |
571 | 573 | } |
@@ -581,7 +583,7 @@ TextAttrCGM *tnew, *told; | ||
581 | 583 | h_basecap = 0.9 * (tnew->font_height - |
582 | 584 | dia_font_descent("Aq",renderer->font, |
583 | 585 | tnew->font_height)); |
584 | - write_elhead(renderer->file, 5, 15, REALSIZE); | |
586 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_CHARACTER_HEIGHT, REALSIZE); | |
585 | 587 | write_real(renderer->file, h_basecap); |
586 | 588 | told->font_height = tnew->font_height; |
587 | 589 | } |
@@ -592,7 +594,7 @@ TextAttrCGM *tnew, *told; | ||
592 | 594 | tnew->color.blue != told->color.blue || |
593 | 595 | tnew->color.alpha != told->color.alpha) |
594 | 596 | { |
595 | - write_elhead(renderer->file, 5, 14, 3); /* text colour */ | |
597 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_TEXT_COLOR, 3); /* text colour */ | |
596 | 598 | write_colour(renderer->file, &tnew->color); |
597 | 599 | putc(0, renderer->file); |
598 | 600 | told->color = tnew->color; |
@@ -611,9 +613,9 @@ end_render(DiaRenderer *self) | ||
611 | 613 | CgmRenderer *renderer = CGM_RENDERER(self); |
612 | 614 | |
613 | 615 | /* end picture */ |
614 | - write_elhead(renderer->file, 0, 5, 0); | |
616 | + write_elhead(renderer->file, CGM_DELIM, CGM_END_PICTURE, 0); | |
615 | 617 | /* end metafile */ |
616 | - write_elhead(renderer->file, 0, 2, 0); | |
618 | + write_elhead(renderer->file, CGM_DELIM, CGM_END_METAFILE, 0); | |
617 | 619 | |
618 | 620 | fclose(renderer->file); |
619 | 621 | } |
@@ -718,7 +720,7 @@ set_fillstyle(DiaRenderer *self, FillStyle mode) | ||
718 | 720 | #if 0 |
719 | 721 | switch(mode) { |
720 | 722 | case FILLSTYLE_SOLID: |
721 | - write_elhead(renderer->file, 5, 22, 2); | |
723 | + write_elhead(renderer->file, CGM_ATTRIB, CGM_INTERIOR_STYLE, 2); | |
722 | 724 | write_int16(renderer->file, 1); |
723 | 725 | break; |
724 | 726 | default: |
@@ -749,7 +751,7 @@ draw_line(DiaRenderer *self, | ||
749 | 751 | |
750 | 752 | write_line_attributes(renderer, line_colour); |
751 | 753 | |
752 | - write_elhead(renderer->file, 4, 1, 4 * REALSIZE); | |
754 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_POLYLINE, 2 * 2 * REALSIZE); | |
753 | 755 | write_real(renderer->file, start->x); |
754 | 756 | write_real(renderer->file, swap_y(renderer, start->y)); |
755 | 757 | write_real(renderer->file, end->x); |
@@ -766,7 +768,7 @@ draw_polyline(DiaRenderer *self, | ||
766 | 768 | |
767 | 769 | write_line_attributes(renderer, line_colour); |
768 | 770 | |
769 | - write_elhead(renderer->file, 4, 1, num_points * 2 * REALSIZE); | |
771 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_POLYLINE, num_points * 2 * REALSIZE); | |
770 | 772 | for (i = 0; i < num_points; i++) { |
771 | 773 | write_real(renderer->file, points[i].x); |
772 | 774 | write_real(renderer->file, swap_y(renderer, points[i].y)); |
@@ -783,7 +785,7 @@ draw_polygon (DiaRenderer *self, | ||
783 | 785 | |
784 | 786 | write_filledge_attributes(renderer, fill, stroke); |
785 | 787 | |
786 | - write_elhead(renderer->file, 4, 7, num_points * 2 * REALSIZE); | |
788 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_POLYGON, num_points * 2 * REALSIZE); | |
787 | 789 | for (i = 0; i < num_points; i++) { |
788 | 790 | write_real(renderer->file, points[i].x); |
789 | 791 | write_real(renderer->file, swap_y(renderer, points[i].y)); |
@@ -799,7 +801,7 @@ draw_rect(DiaRenderer *self, | ||
799 | 801 | |
800 | 802 | write_filledge_attributes(renderer, fill, stroke); |
801 | 803 | |
802 | - write_elhead(renderer->file, 4, 11, 4 * REALSIZE); | |
804 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_RECTANGLE, 4 * REALSIZE); | |
803 | 805 | write_real(renderer->file, ul_corner->x); |
804 | 806 | write_real(renderer->file, swap_y(renderer, ul_corner->y)); |
805 | 807 | write_real(renderer->file, lr_corner->x); |
@@ -807,11 +809,11 @@ draw_rect(DiaRenderer *self, | ||
807 | 809 | } |
808 | 810 | |
809 | 811 | static void |
810 | -write_ellarc(CgmRenderer *renderer, | |
811 | - int elemid, | |
812 | - Point *center, | |
813 | - real width, real height, | |
814 | - real angle1, real angle2 ) | |
812 | +write_ellarc (CgmRenderer *renderer, | |
813 | + CgmElementId elemid, | |
814 | + Point *center, | |
815 | + real width, real height, | |
816 | + real angle1, real angle2 ) | |
815 | 817 | { |
816 | 818 | real rx = width / 2, ry = height / 2; |
817 | 819 | int len; |
@@ -828,8 +830,8 @@ write_ellarc(CgmRenderer *renderer, | ||
828 | 830 | /* |
829 | 831 | ** Elliptical Arc (18) or Elliptical Arc close (19). |
830 | 832 | */ |
831 | - len = elemid == 18 ? (10 * REALSIZE) : (10 * REALSIZE + 2); | |
832 | - write_elhead(renderer->file, 4, elemid, len); | |
833 | + len = elemid == CGM_ELLIPTICAL_ARC ? (10 * REALSIZE) : (10 * REALSIZE + 2); | |
834 | + write_elhead(renderer->file, CGM_ELEMENT, elemid, len); | |
833 | 835 | write_real(renderer->file, center->x); /* center */ |
834 | 836 | write_real(renderer->file, ynew); |
835 | 837 | write_real(renderer->file, center->x + rx); /* axes 1 */ |
@@ -845,7 +847,7 @@ write_ellarc(CgmRenderer *renderer, | ||
845 | 847 | /* |
846 | 848 | ** Elliptical arc close, use PIE closure. |
847 | 849 | */ |
848 | - if ( elemid == 19 ) | |
850 | + if ( elemid == CGM_ELLIPTICAL_ARC_CLOSE ) | |
849 | 851 | write_int16(renderer->file, 0); |
850 | 852 | } |
851 | 853 |
@@ -860,7 +862,7 @@ draw_arc(DiaRenderer *self, | ||
860 | 862 | CgmRenderer *renderer = CGM_RENDERER(self); |
861 | 863 | |
862 | 864 | write_line_attributes(renderer, colour); |
863 | - write_ellarc(renderer, 18, center, width, height, angle1, angle2); | |
865 | + write_ellarc(renderer, CGM_ELLIPTICAL_ARC, center, width, height, angle1, angle2); | |
864 | 866 | } |
865 | 867 | |
866 | 868 | static void |
@@ -873,7 +875,7 @@ fill_arc(DiaRenderer *self, | ||
873 | 875 | CgmRenderer *renderer = CGM_RENDERER(self); |
874 | 876 | |
875 | 877 | write_filledge_attributes(renderer, colour, NULL); |
876 | - write_ellarc(renderer, 19, center, width, height, angle1, angle2); | |
878 | + write_ellarc(renderer, CGM_ELLIPTICAL_ARC_CLOSE, center, width, height, angle1, angle2); | |
877 | 879 | } |
878 | 880 | |
879 | 881 | static void |
@@ -888,7 +890,7 @@ draw_ellipse(DiaRenderer *self, | ||
888 | 890 | write_filledge_attributes(renderer, fill, stroke); |
889 | 891 | |
890 | 892 | ynew = swap_y(renderer, center->y); |
891 | - write_elhead(renderer->file, 4, 17, 6 * REALSIZE); | |
893 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_ELLIPSE, 6 * REALSIZE); | |
892 | 894 | write_real(renderer->file, center->x); /* center */ |
893 | 895 | write_real(renderer->file, ynew); |
894 | 896 | write_real(renderer->file, center->x + width/2); /* axes 1 */ |
@@ -919,7 +921,7 @@ write_bezier(CgmRenderer *renderer, | ||
919 | 921 | g_warning("only first BezPoint can be a BEZ_MOVE_TO"); |
920 | 922 | break; |
921 | 923 | case BEZ_LINE_TO: |
922 | - write_elhead(renderer->file, 4, 1, 4 * REALSIZE); | |
924 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_POLYLINE, 4 * REALSIZE); | |
923 | 925 | write_real(renderer->file, current.x); |
924 | 926 | write_real(renderer->file, current.y); |
925 | 927 | write_real(renderer->file, points[i].p1.x); |
@@ -928,7 +930,7 @@ write_bezier(CgmRenderer *renderer, | ||
928 | 930 | current.y = swap_y(renderer, points[i].p1.y); |
929 | 931 | break; |
930 | 932 | case BEZ_CURVE_TO: |
931 | - write_elhead(renderer->file, 4, 26, 8 * REALSIZE + 2); | |
933 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_POLYBEZIER, 8 * REALSIZE + 2); | |
932 | 934 | write_int16(renderer->file, 1); |
933 | 935 | write_real(renderer->file, current.x); |
934 | 936 | write_real(renderer->file, current.y); |
@@ -979,9 +981,9 @@ draw_beziergon (DiaRenderer *self, | ||
979 | 981 | /* |
980 | 982 | ** A filled bezier is created by using it within a figure. |
981 | 983 | */ |
982 | - write_elhead(renderer->file, 0, 8, 0); /* begin figure */ | |
984 | + write_elhead(renderer->file, CGM_DELIM, CGM_BEGIN_FIGURE, 0); /* begin figure */ | |
983 | 985 | write_bezier(renderer, points, numpoints); |
984 | - write_elhead(renderer->file, 0, 9, 0); /* end figure */ | |
986 | + write_elhead(renderer->file, CGM_DELIM, CGM_END_FIGURE, 0); /* end figure */ | |
985 | 987 | } |
986 | 988 | |
987 | 989 |
@@ -1019,7 +1021,7 @@ draw_string(DiaRenderer *self, | ||
1019 | 1021 | } |
1020 | 1022 | /* work out size of first chunk of text */ |
1021 | 1023 | chunk = MIN(maxfirstchunk, len); |
1022 | - write_elhead(renderer->file, 4, 4, 2 * REALSIZE + 2 + 1 + chunk); | |
1024 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_TEXT, 2 * REALSIZE + 2 + 1 + chunk); | |
1023 | 1025 | write_real(renderer->file, x); |
1024 | 1026 | write_real(renderer->file, y); |
1025 | 1027 | write_int16(renderer->file, (len == chunk)); /* last chunk? */ |
@@ -1033,7 +1035,7 @@ draw_string(DiaRenderer *self, | ||
1033 | 1035 | while (len > 0) { |
1034 | 1036 | /* append text */ |
1035 | 1037 | chunk = MIN(maxappendchunk, len); |
1036 | - write_elhead(renderer->file, 4, 6, 2 + 1 + chunk); | |
1038 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_APPEND_TEXT, 2 + 1 + chunk); | |
1037 | 1039 | write_int16(renderer->file, (len == chunk)); |
1038 | 1040 | putc(chunk, renderer->file); |
1039 | 1041 | fwrite(text, sizeof(char), chunk, renderer->file); |
@@ -1079,7 +1081,7 @@ draw_image(DiaRenderer *self, | ||
1079 | 1081 | clines = chunk / rowlen; |
1080 | 1082 | chunk = clines * rowlen; |
1081 | 1083 | |
1082 | - write_elhead(renderer->file, 4, 9, 6*REALSIZE + 8 + chunk); | |
1084 | + write_elhead(renderer->file, CGM_ELEMENT, CGM_CELL_ARRAY, 6*REALSIZE + 8 + chunk); | |
1083 | 1085 | write_real(renderer->file, x1); /* first corner */ |
1084 | 1086 | write_real(renderer->file, y1); |
1085 | 1087 | write_real(renderer->file, x2); /* second corner */ |
@@ -1091,7 +1093,7 @@ draw_image(DiaRenderer *self, | ||
1091 | 1093 | write_int16(renderer->file, dia_image_width(image)); |
1092 | 1094 | write_int16(renderer->file, clines); |
1093 | 1095 | |
1094 | - write_int16(renderer->file, 8); /* colour precision */ | |
1096 | + write_int16(renderer->file, 8); /* color precision */ | |
1095 | 1097 | write_int16(renderer->file, 1); /* packed encoding */ |
1096 | 1098 | |
1097 | 1099 | fwrite(ptr, sizeof(guint8), chunk, renderer->file); |
@@ -1128,14 +1130,14 @@ export_cgm(DiagramData *data, DiaContext *ctx, | ||
1128 | 1130 | |
1129 | 1131 | /* write BEGMF */ |
1130 | 1132 | len = strlen(dia_version_string); |
1131 | - write_elhead(file, 0, 1, len + 1); | |
1133 | + write_elhead(file, CGM_DELIM, CGM_BEGIN_METAFILE, len + 1); | |
1132 | 1134 | putc(len, file); |
1133 | 1135 | fwrite(dia_version_string, sizeof(char), len, file); |
1134 | 1136 | if (!IS_ODD(len)) |
1135 | 1137 | putc(0, file); |
1136 | 1138 | |
1137 | 1139 | /* write metafile version */ |
1138 | - write_elhead(file, 1, 1, 2); | |
1140 | + write_elhead(file, CGM_DESC, CGM_METAFILE_VERSION, 2); | |
1139 | 1141 | write_uint16(file, 3); /* use version 3 because we may use polybeziers */ |
1140 | 1142 | |
1141 | 1143 | #if 0 |
@@ -1149,48 +1151,48 @@ export_cgm(DiagramData *data, DiaContext *ctx, | ||
1149 | 1151 | #endif |
1150 | 1152 | |
1151 | 1153 | /* set integer precision */ |
1152 | - write_elhead(file, 1, 4, 2); | |
1154 | + write_elhead(file, CGM_DESC, CGM_INTEGER_PRECISION, 2); | |
1153 | 1155 | write_int16(file, 16); |
1154 | 1156 | |
1155 | 1157 | /* write element virtual device unit type */ |
1156 | - write_elhead(file, 1, 3, 2); | |
1158 | + write_elhead(file, CGM_DESC, CGM_VDC_TYPE, 2); | |
1157 | 1159 | write_int16(file, 1); /* real number */ |
1158 | 1160 | |
1159 | 1161 | /* write the colour precision */ |
1160 | - write_elhead(file, 1, 7, 2); | |
1161 | - write_int16(file, 8); /* 8 bits per chanel */ | |
1162 | + write_elhead(file, CGM_DESC, CGM_COLOUR_PRECISION, 2); | |
1163 | + write_int16(file, 8); /* 8 bits per channel */ | |
1162 | 1164 | |
1163 | 1165 | /* write element list command */ |
1164 | - write_elhead(file, 1, 11, 6); | |
1166 | + write_elhead(file, CGM_DESC, CGM_METAFILE_ELEMENT_LIST, 6); | |
1165 | 1167 | write_int16(file, 1); |
1166 | 1168 | write_int16(file, -1); |
1167 | 1169 | write_int16(file, 5); |
1168 | 1170 | |
1169 | 1171 | /* write font list */ |
1170 | 1172 | init_fonts(); |
1171 | - write_elhead(file, 1, 13, fontlistlen); | |
1173 | + write_elhead(file, CGM_DESC, CGM_FONT_LIST, fontlistlen); | |
1172 | 1174 | fwrite(fontlist, sizeof(char), fontlistlen, file); |
1173 | 1175 | if (IS_ODD(fontlistlen)) |
1174 | 1176 | putc(0, file); |
1175 | 1177 | |
1176 | 1178 | /* begin picture */ |
1177 | 1179 | len = strlen(diafilename); |
1178 | - write_elhead(file, 0, 3, len + 1); | |
1180 | + write_elhead(file, CGM_DELIM, CGM_BEGIN_PICTURE, len + 1); | |
1179 | 1181 | putc(len, file); |
1180 | 1182 | fwrite(diafilename, sizeof(char), len, file); |
1181 | 1183 | if (!IS_ODD(len)) |
1182 | 1184 | putc(0, file); |
1183 | 1185 | |
1184 | - /* write the colour mode string */ | |
1185 | - write_elhead(file, 2, 2, 2); | |
1186 | - write_int16(file, 1); /* direct colour mode (as opposed to indexed) */ | |
1186 | + /* write the color mode string */ | |
1187 | + write_elhead(file, CGM_PICDESC, CGM_COLOR_SELECTION_MODE, 2); | |
1188 | + write_int16(file, 1); /* direct color mode (as opposed to indexed) */ | |
1187 | 1189 | |
1188 | 1190 | /* write edge width mode */ |
1189 | - write_elhead(file, 2, 5, 2); | |
1191 | + write_elhead(file, CGM_PICDESC, CGM_EDGE_WIDTH_SPECIFICATION_MODE, 2); | |
1190 | 1192 | write_int16(file, 0); /* relative to virtual device coordinates */ |
1191 | 1193 | |
1192 | 1194 | /* write line width mode */ |
1193 | - write_elhead(file, 2, 3, 2); | |
1195 | + write_elhead(file, CGM_PICDESC, CGM_LINE_WIDTH_SPECIFICATION_MODE, 2); | |
1194 | 1196 | write_int16(file, 0); /* relative to virtual device coordinates */ |
1195 | 1197 | |
1196 | 1198 | extent = &data->extents; |
@@ -1200,7 +1202,7 @@ export_cgm(DiagramData *data, DiaContext *ctx, | ||
1200 | 1202 | ** 'portable' CGM |
1201 | 1203 | */ |
1202 | 1204 | /* write extents */ |
1203 | - write_elhead(file, 2, 6, 4 * REALSIZE); | |
1205 | + write_elhead(file, CGM_PICDESC, CGM_VDC_EXTENT, 4 * REALSIZE); | |
1204 | 1206 | write_real(file, extent->left); |
1205 | 1207 | write_real(file, extent->top); |
1206 | 1208 | write_real(file, extent->right); |
@@ -1208,23 +1210,23 @@ export_cgm(DiagramData *data, DiaContext *ctx, | ||
1208 | 1210 | renderer->y1 = extent->top; |
1209 | 1211 | renderer->y0 = extent->bottom; |
1210 | 1212 | |
1211 | - /* write back colour */ | |
1212 | - write_elhead(file, 2, 7, 3); | |
1213 | + /* write back color */ | |
1214 | + write_elhead(file, CGM_PICDESC, CGM_BACKGROUND_COLOR, 3); | |
1213 | 1215 | write_colour(file, &data->bg_color); |
1214 | 1216 | putc(0, file); |
1215 | 1217 | |
1216 | 1218 | /* begin the picture body */ |
1217 | - write_elhead(file, 0, 4, 0); | |
1219 | + write_elhead(file, CGM_DELIM, CGM_BEGIN_PICTURE_BODY, 0); | |
1218 | 1220 | |
1219 | 1221 | /* make text be the right way up */ |
1220 | - write_elhead(file, 5, 16, 4 * REALSIZE); | |
1222 | + write_elhead(file, CGM_ATTRIB, CGM_CHARACTER_ORIENTATION, 4 * REALSIZE); | |
1221 | 1223 | write_real(file, 0); |
1222 | 1224 | write_real(file, 1); |
1223 | 1225 | write_real(file, 1); |
1224 | 1226 | write_real(file, 0); |
1225 | 1227 | |
1226 | 1228 | /* set the text alignment to left/base */ |
1227 | - write_elhead(file, 5, 18, 4 + 2 * REALSIZE); | |
1229 | + write_elhead(file, CGM_ATTRIB, CGM_TEXT_ALIGNMENT, 4 + 2 * REALSIZE); | |
1228 | 1230 | write_int16(file, 1); /* left */ |
1229 | 1231 | write_int16(file, 4); /* base */ |
1230 | 1232 | write_real(file, 0.0); |
@@ -0,0 +1,110 @@ | ||
1 | +/* Dia -- an diagram creation/manipulation program | |
2 | + * Copyright (C) 1998 Alexander Larsson | |
3 | + * | |
4 | + * cgm.h -- Named constants for Dia CGM plug-in | |
5 | + * Copyright (C) 2014 Hans Breuer <hans@breuer.org> | |
6 | + * | |
7 | + * This program is free software; you can redistribute it and/or modify | |
8 | + * it under the terms of the GNU General Public License as published by | |
9 | + * the Free Software Foundation; either version 2 of the License, or | |
10 | + * (at your option) any later version. | |
11 | + * | |
12 | + * This program is distributed in the hope that it will be useful, | |
13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | + * GNU General Public License for more details. | |
16 | + * | |
17 | + * You should have received a copy of the GNU General Public License | |
18 | + * along with this program; if not, write to the Free Software | |
19 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 | + */ | |
21 | + | |
22 | +/*! | |
23 | + * Including parts of CGM v3.0 specification via: | |
24 | + * http://en.wikipedia.org/wiki/Computer_Graphics_Metafile#cite_note-2 | |
25 | + */ | |
26 | + | |
27 | +typedef enum { | |
28 | + CGM_DELIM = 0, /*!< Metafile Delimiter Elements */ | |
29 | + CGM_DESC = 1, /*!< Metafile Descriptor Elements */ | |
30 | + CGM_PICDESC = 2, /*!< Metafile Picture Descriptor Elements */ | |
31 | + CGM_ELEMENT = 4, /*!< Metafile Graphical Primitives ... */ | |
32 | + CGM_ATTRIB = 5 /*!< ... with Associated Attributes */ | |
33 | +} CgmElementClass; | |
34 | + | |
35 | +/* CGM_DELIM: Metafile Delimiter Elements */ | |
36 | +typedef enum { | |
37 | + CG_NOOP = 0, | |
38 | + CGM_BEGIN_METAFILE = 1, /*!< has 1 parameter: P1: (string fixed) metafile name */ | |
39 | + CGM_END_METAFILE = 2, | |
40 | + CGM_BEGIN_PICTURE = 3, /*!< has 1 parameter: P1: (string fixed) picture name */ | |
41 | + CGM_BEGIN_PICTURE_BODY = 4, | |
42 | + CGM_END_PICTURE = 5, | |
43 | + CGM_BEGIN_SEGMENT = 6, /*!< has 1 parameter: P1: (name) segment identifier */ | |
44 | + CGM_END_SEGMENT = 7, | |
45 | + CGM_BEGIN_FIGURE = 8, /*!< CGM v3? */ | |
46 | + CGM_END_FIGURE = 9 /*!< CGM v3? */ | |
47 | +} CgmDelimElementId; | |
48 | +/* CGM_DESC: Metafile Descriptor Elements */ | |
49 | +typedef enum { | |
50 | + CGM_METAFILE_VERSION = 1, /*!< valid values are 1, 2, 3, 4 */ | |
51 | + CGM_METAFILE_DESCRIPTION = 2, | |
52 | + CGM_VDC_TYPE = 3, /*<! 0,1 */ | |
53 | + CGM_INTEGER_PRECISION = 4, /*!< 8,16,24,32 */ | |
54 | + CGM_REAL_PRECISION = 5, /*!< {0,1}, {9,12,16,32}, {23,52,16,32} - 32/64 bit, floating/fixed point */ | |
55 | + CGM_COLOUR_PRECISION = 7, /*!< 8,16,24,32 */ | |
56 | + CGM_METAFILE_ELEMENT_LIST = 11, | |
57 | + CGM_FONT_LIST = 13 | |
58 | +} CgmDescElementId; | |
59 | +/* CGM_PICDESC: Metafile Picture Descriptor Elements */ | |
60 | +typedef enum { | |
61 | + CGM_COLOR_SELECTION_MODE = 2, | |
62 | + CGM_LINE_WIDTH_SPECIFICATION_MODE = 3, | |
63 | + CGM_EDGE_WIDTH_SPECIFICATION_MODE = 5, | |
64 | + CGM_VDC_EXTENT = 6, | |
65 | + CGM_BACKGROUND_COLOR = 7 | |
66 | +} CgmPicdescElementId; | |
67 | +/* CGM_ELEMENT: Metafile Graphical Element */ | |
68 | +typedef enum { | |
69 | + CGM_POLYLINE = 1, | |
70 | + CGM_DISJOINT_POLYLINE = 2, | |
71 | + CGM_POLYMARKER = 3, | |
72 | + CGM_TEXT = 4, | |
73 | + CGM_RESTRICTED_TEXT = 5, | |
74 | + CGM_APPEND_TEXT = 6, | |
75 | + CGM_POLYGON = 7, | |
76 | + CGM_POLYGON_SET = 8, | |
77 | + CGM_CELL_ARRAY = 9, /*!< aka. bitmap */ | |
78 | + CGM_RECTANGLE = 11, | |
79 | + CGM_CIRCLE = 12, | |
80 | + CGM_CIRCULAR_ARC_CENTER = 15, | |
81 | + CGM_CIRCULAR_ARC_CENTER_CLOSE = 16, | |
82 | + CGM_ELLIPSE = 17, | |
83 | + CGM_ELLIPTICAL_ARC = 18, | |
84 | + CGM_ELLIPTICAL_ARC_CLOSE = 19, | |
85 | + CGM_NURBS = 25, /*!< CGM 3.0: NON-UNIFORM RATIONAL B-SPLINE */ | |
86 | + CGM_POLYBEZIER = 26 /*!< CGM 3.0 */ | |
87 | +} CgmElementId; | |
88 | + | |
89 | +/* CGM_ATTRIB: Metafile Graphical ... Associated Attributes */ | |
90 | +enum CgmAttribElementId { | |
91 | + CGM_LINE_TYPE = 2, /*!< v1: (1=solid or 2=dashed) v3?: adds (3=dot 4=dash-dot 5=dash-dot-dot) */ | |
92 | + CGM_LINE_WIDTH = 3, | |
93 | + CGM_LINE_COLOR = 4, | |
94 | + CGM_TEXT_FONT_INDEX = 10, | |
95 | + CGM_TEXT_COLOR = 14, | |
96 | + CGM_CHARACTER_HEIGHT = 15, | |
97 | + CGM_CHARACTER_ORIENTATION = 16, | |
98 | + CGM_TEXT_ALIGNMENT = 18, | |
99 | + /* CGM_ATTRIB: Filled-Area ... Attributes */ | |
100 | + CGM_INTERIOR_STYLE = 22, /*!< (1= solid or 4 = empty) */ | |
101 | + CGM_FILL_COLOR = 23, | |
102 | + CGM_EDGE_TYPE = 27, /*!< (1=solid or 2=dashed) */ | |
103 | + CGM_EDGE_WIDTH = 28, | |
104 | + CGM_EDGE_COLOR = 29, | |
105 | + CGM_EDGE_VISIBILITY = 30, /*!< (1 = on) */ | |
106 | + CGM_LINE_CAP = 37, | |
107 | + CGM_LINE_JOIN = 38, | |
108 | + CGM_EDGE_CAP = 44, | |
109 | + CGM_EDGE_JOIN = 45, | |
110 | +}; |