1 /************************************************************************/
2 /* */
3 /* Buffer administration: manage embedded objects. */
4 /* */
5 /************************************************************************/
6
7 # include "docBaseConfig.h"
8
9 # include <stdlib.h>
10 # include <string.h>
11
12 # include <geoGrid.h>
13 # include <appDebugon.h>
14
15 # include "docObject.h"
16 # include "docObjectProperties.h"
17
18 /************************************************************************/
19 /* */
20 /* Manage inserted objects. */
21 /* */
22 /************************************************************************/
23
docCleanInsertedObject(InsertedObject * io)24 void docCleanInsertedObject( InsertedObject * io )
25 {
26 utilCleanMemoryBuffer( &io->ioObjectData );
27 utilCleanMemoryBuffer( &io->ioResultData );
28
29 if ( io->ioObjectName )
30 { free( io->ioObjectName ); }
31 if ( io->ioObjectClass )
32 { free( io->ioObjectClass ); }
33
34 bmCleanRasterImage( &(io->ioRasterImage) );
35 }
36
docInitInsertedObject(InsertedObject * io)37 void docInitInsertedObject( InsertedObject * io )
38 {
39 io->ioKind= DOCokUNKNOWN;
40 io->ioResultKind= DOCokUNKNOWN;
41 io->ioRtfResultKind= RESULTkindUNKNOWN;
42 io->ioRtfEmbedKind= EMBEDkindOBJEMB;
43
44 docInitPictureProperties( &(io->ioPictureProperties) );
45
46 io->ioInline= 1;
47
48 io->ioTwipsWide= 0;
49 io->ioTwipsHigh= 0;
50
51 io->ioPixelsWide= 0;
52 io->ioPixelsHigh= 0;
53 io->ioScaleXSet= 100;
54 io->ioScaleYSet= 100;
55 io->ioScaleXUsed= 100;
56 io->ioScaleYUsed= 100;
57
58 io->ioX0Twips= 0;
59 docInitLayoutPosition( &(io->ioY0Position) );
60
61 io->ioTopCropTwips= 0;
62 io->ioBottomCropTwips= 0;
63 io->ioLeftCropTwips= 0;
64 io->ioRightCropTwips= 0;
65
66 utilInitMemoryBuffer( &io->ioObjectData );
67 utilInitMemoryBuffer( &io->ioResultData );
68
69 io->ioObjectName= (char *)0;
70 io->ioObjectClass= (char *)0;
71
72 io->ioDrawingShape= (struct DrawingShape *)0;
73
74 io->ioDrawingSurface= (struct DrawingSurface *)0;
75 bmInitRasterImage( &(io->ioRasterImage) );
76
77 return;
78 }
79
docObjectAdaptToPictureGeometry(InsertedObject * io,const PictureProperties * pip)80 void docObjectAdaptToPictureGeometry( InsertedObject * io,
81 const PictureProperties * pip )
82 {
83 io->ioTwipsWide= pip->pipTwipsWide;
84 io->ioTwipsHigh= pip->pipTwipsHigh;
85
86 io->ioScaleXSet= pip->pipScaleXSet;
87 io->ioScaleYSet= pip->pipScaleYSet;
88 io->ioScaleXUsed= pip->pipScaleXUsed;
89 io->ioScaleYUsed= pip->pipScaleYUsed;
90
91 io->ioTopCropTwips= pip->pipTopCropTwips;
92 io->ioBottomCropTwips= pip->pipBottomCropTwips;
93 io->ioLeftCropTwips= pip->pipLeftCropTwips;
94 io->ioRightCropTwips= pip->pipRightCropTwips;
95
96 return;
97 }
98
docObjectSetData(InsertedObject * io,const char * bytes,int size)99 int docObjectSetData( InsertedObject * io,
100 const char * bytes,
101 int size )
102 {
103 return utilMemoryBufferSetBytes( &(io->ioObjectData),
104 (const unsigned char *)bytes, size );
105 }
106
docSetResultData(InsertedObject * io,const char * bytes,int size)107 int docSetResultData( InsertedObject * io,
108 const char * bytes,
109 int size )
110 {
111 return utilMemoryBufferSetBytes( &(io->ioResultData),
112 (const unsigned char *)bytes, size );
113 }
114
docSetObjectName(InsertedObject * io,const char * name,int len)115 int docSetObjectName( InsertedObject * io,
116 const char * name,
117 int len )
118 {
119 char * fresh= (char *)malloc( len+ 1 );
120
121 if ( ! fresh )
122 { LXDEB(len,fresh); return -1; }
123
124 io->ioObjectName= fresh;
125 strncpy( fresh, name, len ); fresh[len]= '\0';
126
127 return 0;
128 }
129
docSetObjectClass(InsertedObject * io,const char * name,int len)130 int docSetObjectClass( InsertedObject * io,
131 const char * name,
132 int len )
133 {
134 char * fresh= (char *)malloc( len+ 1 );
135
136 if ( ! fresh )
137 { LXDEB(len,fresh); return -1; }
138
139 io->ioObjectClass= fresh;
140 strncpy( fresh, name, len ); fresh[len]= '\0';
141
142 return 0;
143 }
144
145 /************************************************************************/
146 /* */
147 /* Find the pixel rectangle inside the cropping margins of an image. */
148 /* */
149 /************************************************************************/
150
docObjectGetCropRect(DocumentRectangle * drSrc,const PictureProperties * pip,const BitmapDescription * bd)151 void docObjectGetCropRect( DocumentRectangle * drSrc,
152 const PictureProperties * pip,
153 const BitmapDescription * bd )
154 {
155 int c1Twips;
156
157 drSrc->drX0= 0;
158 drSrc->drY0= 0;
159 drSrc->drX1= bd->bdPixelsWide- 1;
160 drSrc->drY1= bd->bdPixelsHigh- 1;
161
162 if ( pip->pipLeftCropTwips+ pip->pipRightCropTwips > 0 )
163 {
164 drSrc->drX0= ( bd->bdPixelsWide* pip->pipLeftCropTwips ) /
165 pip->pipTwipsWide;
166 c1Twips= pip->pipTwipsWide- pip->pipRightCropTwips;
167 drSrc->drX1= ( bd->bdPixelsWide* c1Twips )/ pip->pipTwipsWide;
168
169 if ( drSrc->drX0 < 0 )
170 { drSrc->drX0= 0; }
171 if ( drSrc->drX1 > bd->bdPixelsWide- 1 )
172 { drSrc->drX1= bd->bdPixelsWide- 1; }
173 }
174
175 if ( pip->pipTopCropTwips+ pip->pipBottomCropTwips > 0 )
176 {
177 drSrc->drY0= ( bd->bdPixelsHigh* pip->pipTopCropTwips ) /
178 pip->pipTwipsHigh;
179 c1Twips= pip->pipTwipsHigh- pip->pipBottomCropTwips;
180 drSrc->drY1= ( bd->bdPixelsHigh* c1Twips )/ pip->pipTwipsHigh;
181
182 if ( drSrc->drY0 < 0 )
183 { drSrc->drY0= 0; }
184 if ( drSrc->drY1 > bd->bdPixelsHigh- 1 )
185 { drSrc->drY1= bd->bdPixelsHigh- 1; }
186 }
187
188 return;
189 }
190
docObjectSetPixelSize(InsertedObject * io,double pixelsPerTwip)191 void docObjectSetPixelSize( InsertedObject * io,
192 double pixelsPerTwip )
193 {
194 io->ioPixelsWide= COORDtoGRID( pixelsPerTwip,
195 ( io->ioScaleXUsed* io->ioTwipsWide )/ 100 );
196 io->ioPixelsHigh= COORDtoGRID( pixelsPerTwip,
197 ( io->ioScaleYUsed* io->ioTwipsHigh )/ 100 );
198
199 if ( io->ioPixelsWide < 1 )
200 { io->ioPixelsWide= 1; }
201 if ( io->ioPixelsHigh < 1 )
202 { io->ioPixelsHigh= 1; }
203
204 return;
205 }
206
207