1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/***************************************************************************
*
* $Id: adraw.c 161 2010-10-26 20:17:16Z Michael.McTernan $
*
* This file is part of mscgen, a message sequence chart renderer.
* Copyright (C) 2005 Michael C McTernan, Michael.McTernan.2001@cs.bris.ac.uk
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
**************************************************************************/
/***************************************************************************
* Include Files
***************************************************************************/
#include "mscgen_config.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "mscgen_adraw_int.h"
/***************************************************************************
* Functions
***************************************************************************/
Boolean ADrawOpen(unsigned int w,
unsigned int h,
const char *file,
const char *fontName,
ADrawOutputType type,
struct ADrawTag *outContext)
{
assert(outContext);
switch(type)
{
case ADRAW_FMT_NULL:
return NullInit(outContext);
case ADRAW_FMT_PNG:
#if !defined(REMOVE_PNG_OUTPUT)
return GdoInit(w, h, file, fontName, outContext);
#else
fprintf(stderr, "Built with REMOVE_PNG_OUTPUT; PNG output is not supported\n");
return FALSE;
#endif
case ADRAW_FMT_EPS:
return PsInit(w, h, file, outContext);
case ADRAW_FMT_SVG:
return SvgInit(w, h, file, outContext);
default:
return FALSE;
}
}
ADrawColour ADrawGetColour(const char *colour)
{
assert(colour != NULL);
/* Check if an RGB value has been specified */
if(*colour == '#')
{
unsigned int c = ADRAW_COL_BLACK;
if(sscanf(&colour[1], "%x", &c) == 1)
{
return (ADrawColour)c;
}
}
else /* Check for name matches */
{
static const struct
{
char *name;
ADrawColour col;
}
colourMap[] =
{
{ "WHITE", ADRAW_COL_WHITE },
{ "BLACK", ADRAW_COL_BLACK },
{ "RED", ADRAW_COL_RED },
{ "ORANGE", ADRAW_COL_ORANGE },
{ "YELLOW", ADRAW_COL_YELLOW },
{ "GREEN", ADRAW_COL_GREEN },
{ "BLUE", ADRAW_COL_BLUE },
{ "INDIGO", ADRAW_COL_INDIGO },
{ "VIOLET", ADRAW_COL_VIOLET },
{ "SILVER", ADRAW_COL_SILVER },
{ "LIME", ADRAW_COL_LIME },
{ "GRAY", ADRAW_COL_GRAY },
{ "OLIVE", ADRAW_COL_OLIVE },
{ "MAROON", ADRAW_COL_MAROON },
{ "NAVY", ADRAW_COL_NAVY },
{ "PURPLE", ADRAW_COL_PURPLE },
{ "TEAL", ADRAW_COL_TEAL },
{ "FUCHSIA", ADRAW_COL_FUCHSIA },
{ "AQUA", ADRAW_COL_AQUA }
};
unsigned int t;
for(t = 0; t < sizeof(colourMap) / sizeof(colourMap[0]); t++)
{
if(strcasecmp(colour, colourMap[t].name) == 0)
{
return colourMap[t].col;
}
}
}
/* Default to black if all else failed */
return ADRAW_COL_BLACK;
}
void ADrawComputeArcPoint(float cx, float cy, float w, float h, float degrees,
unsigned int *x, unsigned int *y)
{
float rad = (float)((degrees * M_PI) / 180.0f);
*x = (unsigned int)round(cx + ((w / 2.0f) * cos(rad)));
*y = (unsigned int)round(cy + ((h / 2.0f) * sin(rad)));
}
/* END OF FILE */
|