forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hpdf_3dmeasure.c
235 lines (176 loc) · 5.41 KB
/
hpdf_3dmeasure.c
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* << Haru Free PDF Library >> -- hpdf_annotation.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
*/
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf_info.h"
#include "hpdf_3dmeasure.h"
#include "hpdf.h"
/*----------------------------------------------------------------------------*/
/*------ HPDF_3DMeasure -----------------------------------------------------*/
HPDF_STATUS
HPDF_Dict_AddPoint3D(HPDF_Dict dict, const char* key, HPDF_Point3D point)
{
HPDF_Array array;
HPDF_STATUS ret = HPDF_OK;
array = HPDF_Array_New (dict->mmgr);
if (!array)
return HPDF_Error_GetCode ( dict->error);
if (HPDF_Dict_Add (dict, key, array) != HPDF_OK)
return HPDF_Error_GetCode ( dict->error);
ret += HPDF_Array_AddReal(array, point.x);
ret += HPDF_Array_AddReal(array, point.y);
ret += HPDF_Array_AddReal(array, point.z);
return ret;
}
HPDF_3DMeasure
HPDF_3DC3DMeasure_New(HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Point3D firstanchorpoint,
HPDF_Point3D textanchorpoint
)
{
HPDF_3DMeasure measure;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n"));
measure = HPDF_Dict_New (mmgr);
if (!measure)
return NULL;
if (HPDF_Xref_Add (xref, measure) != HPDF_OK)
return NULL;
ret += HPDF_Dict_AddPoint3D(measure, "A1", firstanchorpoint);
ret += HPDF_Dict_AddPoint3D(measure, "TP", textanchorpoint);
ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure");
ret += HPDF_Dict_AddName (measure, "Subtype", "3DC");
if (ret != HPDF_OK)
return NULL;
return measure;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DMeasure_SetColor(HPDF_3DMeasure measure,
HPDF_RGBColor color)
{
HPDF_Array array;
HPDF_STATUS ret = HPDF_OK;
array = HPDF_Array_New (measure->mmgr);
if (!array)
return HPDF_Error_GetCode (measure->error);
ret = HPDF_Dict_Add (measure, "C", array);
if (ret != HPDF_OK)
return ret;
ret += HPDF_Array_AddName(array, "DeviceRGB");
ret += HPDF_Array_AddReal(array, color.r);
ret += HPDF_Array_AddReal(array, color.g);
ret += HPDF_Array_AddReal(array, color.b);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DMeasure_SetTextSize(HPDF_3DMeasure measure,
HPDF_REAL textsize)
{
HPDF_STATUS ret = HPDF_OK;
ret = HPDF_Dict_AddReal(measure, "TS", textsize);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DMeasure_SetName(HPDF_3DMeasure measure,
const char* name)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_String s;
s = HPDF_String_New (measure->mmgr, name, 0);
if (!s)
return HPDF_Error_GetCode ( s->error);
ret = HPDF_Dict_Add(measure, "TRL", s);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DC3DMeasure_SetTextBoxSize(HPDF_3DMeasure measure,
HPDF_INT32 x,
HPDF_INT32 y)
{
HPDF_Array array;
HPDF_STATUS ret = HPDF_OK;
array = HPDF_Array_New (measure->mmgr);
if (!array)
return HPDF_Error_GetCode (measure->error);
ret = HPDF_Dict_Add (measure, "TB", array);
if (ret != HPDF_OK)
return ret;
ret += HPDF_Array_AddNumber(array, x);
ret += HPDF_Array_AddNumber(array, y);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DC3DMeasure_SetText(HPDF_3DMeasure measure,
const char* text,
HPDF_Encoder encoder)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_String s;
s = HPDF_String_New (measure->mmgr, text, encoder);
if (!s)
return HPDF_Error_GetCode ( s->error);
ret = HPDF_Dict_Add(measure, "UT", s);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DC3DMeasure_SetProjectionAnotation(HPDF_3DMeasure measure,
HPDF_Annotation projectionanotation)
{
HPDF_STATUS ret = HPDF_OK;
ret = HPDF_Dict_Add(measure, "S", projectionanotation);
return ret;
}
HPDF_3DMeasure
HPDF_PD33DMeasure_New(HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Point3D annotationPlaneNormal,
HPDF_Point3D firstAnchorPoint,
HPDF_Point3D secondAnchorPoint,
HPDF_Point3D leaderLinesDirection,
HPDF_Point3D measurementValuePoint,
HPDF_Point3D textYDirection,
HPDF_REAL value,
const char* unitsString
)
{
HPDF_3DMeasure measure;
HPDF_STATUS ret = HPDF_OK;
HPDF_String s;
HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n"));
measure = HPDF_Dict_New (mmgr);
if (!measure)
return NULL;
if (HPDF_Xref_Add (xref, measure) != HPDF_OK)
return NULL;
ret += HPDF_Dict_AddPoint3D(measure, "AP", annotationPlaneNormal);
ret += HPDF_Dict_AddPoint3D(measure, "A1", firstAnchorPoint);
ret += HPDF_Dict_AddPoint3D(measure, "A2", secondAnchorPoint);
ret += HPDF_Dict_AddPoint3D(measure, "D1", leaderLinesDirection);
ret += HPDF_Dict_AddPoint3D(measure, "TP", measurementValuePoint);
ret += HPDF_Dict_AddPoint3D(measure, "TY", textYDirection);
ret += HPDF_Dict_AddReal(measure, "V", value);
s = HPDF_String_New (measure->mmgr, unitsString, 0);
if (!s)
return NULL;
ret = HPDF_Dict_Add(measure, "U", s);
ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure");
ret += HPDF_Dict_AddName (measure, "Subtype", "PD3");
if (ret != HPDF_OK)
return NULL;
return measure;
}