1/*
2 * << Haru Free PDF Library >> -- hpdf_annotation.c
3 *
4 * URL: http://libharu.org
5 *
6 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7 * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
8 *
9 * Permission to use, copy, modify, distribute and sell this software
10 * and its documentation for any purpose is hereby granted without fee,
11 * provided that the above copyright notice appear in all copies and
12 * that both that copyright notice and this permission notice appear
13 * in supporting documentation.
14 * It is provided "as is" without express or implied warranty.
15 *
16 */
17
18#include "hpdf_conf.h"
19#include "hpdf_utils.h"
20#include "hpdf_info.h"
21#include "hpdf_3dmeasure.h"
22#include "hpdf.h"
23
24/*----------------------------------------------------------------------------*/
25/*------ HPDF_3DMeasure -----------------------------------------------------*/
26
27HPDF_STATUS
28HPDF_Dict_AddPoint3D(HPDF_Dict dict, const char* key, HPDF_Point3D point)
29{
30 HPDF_Array array;
31 HPDF_STATUS ret = HPDF_OK;
32 array = HPDF_Array_New (dict->mmgr);
33 if (!array)
34 return HPDF_Error_GetCode ( dict->error);
35
36 if (HPDF_Dict_Add (dict, key, array) != HPDF_OK)
37 return HPDF_Error_GetCode ( dict->error);
38
39 ret += HPDF_Array_AddReal(array, point.x);
40 ret += HPDF_Array_AddReal(array, point.y);
41 ret += HPDF_Array_AddReal(array, point.z);
42
43 return ret;
44}
45
46
47
48
49HPDF_3DMeasure
50HPDF_3DC3DMeasure_New(HPDF_MMgr mmgr,
51 HPDF_Xref xref,
52 HPDF_Point3D firstanchorpoint,
53 HPDF_Point3D textanchorpoint
54 )
55{
56 HPDF_3DMeasure measure;
57 HPDF_STATUS ret = HPDF_OK;
58
59
60 HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n"));
61
62 measure = HPDF_Dict_New (mmgr);
63 if (!measure)
64 return NULL;
65
66 if (HPDF_Xref_Add (xref, measure) != HPDF_OK)
67 return NULL;
68
69 ret += HPDF_Dict_AddPoint3D(measure, "A1", firstanchorpoint);
70 ret += HPDF_Dict_AddPoint3D(measure, "TP", textanchorpoint);
71
72 ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure");
73 ret += HPDF_Dict_AddName (measure, "Subtype", "3DC");
74
75 if (ret != HPDF_OK)
76 return NULL;
77
78 return measure;
79}
80
81
82
83HPDF_EXPORT(HPDF_STATUS)
84HPDF_3DMeasure_SetColor(HPDF_3DMeasure measure,
85 HPDF_RGBColor color)
86{
87 HPDF_Array array;
88 HPDF_STATUS ret = HPDF_OK;
89
90 array = HPDF_Array_New (measure->mmgr);
91 if (!array)
92 return HPDF_Error_GetCode (measure->error);
93
94 ret = HPDF_Dict_Add (measure, "C", array);
95 if (ret != HPDF_OK)
96 return ret;
97
98 ret += HPDF_Array_AddName(array, "DeviceRGB");
99 ret += HPDF_Array_AddReal(array, color.r);
100 ret += HPDF_Array_AddReal(array, color.g);
101 ret += HPDF_Array_AddReal(array, color.b);
102
103 return ret;
104}
105
106
107HPDF_EXPORT(HPDF_STATUS)
108HPDF_3DMeasure_SetTextSize(HPDF_3DMeasure measure,
109 HPDF_REAL textsize)
110{
111 HPDF_STATUS ret = HPDF_OK;
112
113 ret = HPDF_Dict_AddReal(measure, "TS", textsize);
114
115 return ret;
116}
117
118
119HPDF_EXPORT(HPDF_STATUS)
120HPDF_3DMeasure_SetName(HPDF_3DMeasure measure,
121 const char* name)
122{
123 HPDF_STATUS ret = HPDF_OK;
124 HPDF_String s;
125
126 s = HPDF_String_New (measure->mmgr, name, 0);
127 if (!s)
128 return HPDF_Error_GetCode ( s->error);
129
130 ret = HPDF_Dict_Add(measure, "TRL", s);
131
132 return ret;
133}
134
135HPDF_EXPORT(HPDF_STATUS)
136HPDF_3DC3DMeasure_SetTextBoxSize(HPDF_3DMeasure measure,
137 HPDF_INT32 x,
138 HPDF_INT32 y)
139{
140 HPDF_Array array;
141 HPDF_STATUS ret = HPDF_OK;
142
143 array = HPDF_Array_New (measure->mmgr);
144 if (!array)
145 return HPDF_Error_GetCode (measure->error);
146
147 ret = HPDF_Dict_Add (measure, "TB", array);
148 if (ret != HPDF_OK)
149 return ret;
150
151 ret += HPDF_Array_AddNumber(array, x);
152 ret += HPDF_Array_AddNumber(array, y);
153
154 return ret;
155}
156
157HPDF_EXPORT(HPDF_STATUS)
158HPDF_3DC3DMeasure_SetText(HPDF_3DMeasure measure,
159 const char* text,
160 HPDF_Encoder encoder)
161{
162 HPDF_STATUS ret = HPDF_OK;
163 HPDF_String s;
164
165 s = HPDF_String_New (measure->mmgr, text, encoder);
166 if (!s)
167 return HPDF_Error_GetCode ( s->error);
168
169 ret = HPDF_Dict_Add(measure, "UT", s);
170
171 return ret;
172}
173
174HPDF_EXPORT(HPDF_STATUS)
175HPDF_3DC3DMeasure_SetProjectionAnotation(HPDF_3DMeasure measure,
176 HPDF_Annotation projectionanotation)
177{
178 HPDF_STATUS ret = HPDF_OK;
179
180 ret = HPDF_Dict_Add(measure, "S", projectionanotation);
181
182 return ret;
183}
184
185
186HPDF_3DMeasure
187HPDF_PD33DMeasure_New(HPDF_MMgr mmgr,
188 HPDF_Xref xref,
189 HPDF_Point3D annotationPlaneNormal,
190 HPDF_Point3D firstAnchorPoint,
191 HPDF_Point3D secondAnchorPoint,
192 HPDF_Point3D leaderLinesDirection,
193 HPDF_Point3D measurementValuePoint,
194 HPDF_Point3D textYDirection,
195 HPDF_REAL value,
196 const char* unitsString
197 )
198{
199 HPDF_3DMeasure measure;
200 HPDF_STATUS ret = HPDF_OK;
201 HPDF_String s;
202
203 HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n"));
204
205 measure = HPDF_Dict_New (mmgr);
206 if (!measure)
207 return NULL;
208
209 if (HPDF_Xref_Add (xref, measure) != HPDF_OK)
210 return NULL;
211
212 ret += HPDF_Dict_AddPoint3D(measure, "AP", annotationPlaneNormal);
213 ret += HPDF_Dict_AddPoint3D(measure, "A1", firstAnchorPoint);
214 ret += HPDF_Dict_AddPoint3D(measure, "A2", secondAnchorPoint);
215 ret += HPDF_Dict_AddPoint3D(measure, "D1", leaderLinesDirection);
216 ret += HPDF_Dict_AddPoint3D(measure, "TP", measurementValuePoint);
217 ret += HPDF_Dict_AddPoint3D(measure, "TY", textYDirection);
218
219 ret += HPDF_Dict_AddReal(measure, "V", value);
220
221 s = HPDF_String_New (measure->mmgr, unitsString, 0);
222 if (!s)
223 return NULL;
224
225 ret = HPDF_Dict_Add(measure, "U", s);
226
227 ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure");
228 ret += HPDF_Dict_AddName (measure, "Subtype", "PD3");
229
230 if (ret != HPDF_OK)
231 return NULL;
232
233 return measure;
234}
235
236