Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <comphelper/string.hxx>
31 : : #include <string.h>
32 : : #include <rtl/strbuf.hxx>
33 : : #include <vcl/svapp.hxx>
34 : : #include <tools/urlobj.hxx>
35 : : #include <vcl/wrkwin.hxx>
36 : : #include <sot/formats.hxx>
37 : :
38 : : #include "svl/urihelper.hxx"
39 : : #include <svtools/imap.hxx>
40 : : #include <svtools/imapobj.hxx>
41 : : #include <svtools/imaprect.hxx>
42 : : #include <svtools/imapcirc.hxx>
43 : : #include <svtools/imappoly.hxx>
44 : :
45 : : #include <math.h>
46 : :
47 : : #define NOTEOL(c) ((c)!='\0')
48 : :
49 [ # # ][ # # ]: 0 : TYPEINIT0_AUTOFACTORY( ImageMap );
50 : :
51 : 0 : void IMapObject::AppendCERNCoords(rtl::OStringBuffer& rBuf, const Point& rPoint100) const
52 : : {
53 [ # # ][ # # ]: 0 : const Point aPixPt( Application::GetDefaultDevice()->LogicToPixel( rPoint100, MapMode( MAP_100TH_MM ) ) );
[ # # ][ # # ]
54 : :
55 [ # # ]: 0 : rBuf.append('(');
56 [ # # ]: 0 : rBuf.append(static_cast<sal_Int32>(aPixPt.X()));
57 [ # # ]: 0 : rBuf.append(',');
58 [ # # ]: 0 : rBuf.append(static_cast<sal_Int32>(aPixPt.Y()));
59 [ # # ]: 0 : rBuf.append(RTL_CONSTASCII_STRINGPARAM(") "));
60 : 0 : }
61 : :
62 : 0 : void IMapObject::AppendNCSACoords(rtl::OStringBuffer& rBuf, const Point& rPoint100) const
63 : : {
64 [ # # ][ # # ]: 0 : const Point aPixPt( Application::GetDefaultDevice()->LogicToPixel( rPoint100, MapMode( MAP_100TH_MM ) ) );
[ # # ][ # # ]
65 : :
66 [ # # ]: 0 : rBuf.append(static_cast<sal_Int32>(aPixPt.X()));
67 [ # # ]: 0 : rBuf.append(',');
68 [ # # ]: 0 : rBuf.append(static_cast<sal_Int32>(aPixPt.Y()));
69 [ # # ]: 0 : rBuf.append(' ');
70 : 0 : }
71 : :
72 : 0 : void IMapObject::AppendCERNURL(rtl::OStringBuffer& rBuf, const String& rBaseURL) const
73 : : {
74 [ # # ][ # # ]: 0 : rBuf.append(rtl::OUStringToOString(URIHelper::simpleNormalizedMakeRelative(rBaseURL, aURL), osl_getThreadTextEncoding()));
[ # # ][ # # ]
75 : 0 : }
76 : :
77 : 0 : void IMapObject::AppendNCSAURL(rtl::OStringBuffer& rBuf, const String& rBaseURL) const
78 : : {
79 [ # # ][ # # ]: 0 : rBuf.append(rtl::OUStringToOString(URIHelper::simpleNormalizedMakeRelative(rBaseURL, aURL), osl_getThreadTextEncoding()));
[ # # ][ # # ]
80 : 0 : rBuf.append(' ');
81 : 0 : }
82 : :
83 : 0 : void IMapRectangleObject::WriteCERN( SvStream& rOStm, const String& rBaseURL ) const
84 : : {
85 [ # # ]: 0 : rtl::OStringBuffer aStrBuf(RTL_CONSTASCII_STRINGPARAM("rectangle "));
86 : :
87 [ # # ]: 0 : AppendCERNCoords(aStrBuf, aRect.TopLeft());
88 [ # # ][ # # ]: 0 : AppendCERNCoords(aStrBuf, aRect.BottomRight());
89 [ # # ]: 0 : AppendCERNURL(aStrBuf, rBaseURL);
90 : :
91 [ # # ]: 0 : rOStm.WriteLine(aStrBuf.makeStringAndClear());
92 : 0 : }
93 : :
94 : 0 : void IMapRectangleObject::WriteNCSA( SvStream& rOStm, const String& rBaseURL ) const
95 : : {
96 [ # # ]: 0 : rtl::OStringBuffer aStrBuf(RTL_CONSTASCII_STRINGPARAM("rect "));
97 : :
98 [ # # ]: 0 : AppendNCSAURL(aStrBuf, rBaseURL);
99 [ # # ]: 0 : AppendNCSACoords(aStrBuf, aRect.TopLeft());
100 [ # # ][ # # ]: 0 : AppendNCSACoords(aStrBuf, aRect.BottomRight());
101 : :
102 [ # # ]: 0 : rOStm.WriteLine(aStrBuf.makeStringAndClear());
103 : 0 : }
104 : :
105 : 0 : void IMapCircleObject::WriteCERN( SvStream& rOStm, const String& rBaseURL ) const
106 : : {
107 [ # # ]: 0 : rtl::OStringBuffer aStrBuf(RTL_CONSTASCII_STRINGPARAM("circle "));
108 : :
109 [ # # ]: 0 : AppendCERNCoords(aStrBuf, aCenter);
110 [ # # ]: 0 : aStrBuf.append(nRadius);
111 [ # # ]: 0 : aStrBuf.append(' ');
112 [ # # ]: 0 : AppendCERNURL(aStrBuf, rBaseURL);
113 : :
114 [ # # ]: 0 : rOStm.WriteLine(aStrBuf.makeStringAndClear());
115 : 0 : }
116 : :
117 : 0 : void IMapCircleObject::WriteNCSA( SvStream& rOStm, const String& rBaseURL ) const
118 : : {
119 [ # # ]: 0 : rtl::OStringBuffer aStrBuf(RTL_CONSTASCII_STRINGPARAM("circle "));
120 : :
121 [ # # ]: 0 : AppendNCSAURL(aStrBuf, rBaseURL);
122 [ # # ]: 0 : AppendNCSACoords(aStrBuf, aCenter);
123 [ # # ]: 0 : AppendNCSACoords(aStrBuf, aCenter + Point(nRadius, 0));
124 : :
125 [ # # ]: 0 : rOStm.WriteLine(aStrBuf.makeStringAndClear());
126 : 0 : }
127 : :
128 : 0 : void IMapPolygonObject::WriteCERN( SvStream& rOStm, const String& rBaseURL ) const
129 : : {
130 [ # # ]: 0 : rtl::OStringBuffer aStrBuf(RTL_CONSTASCII_STRINGPARAM("polygon "));
131 [ # # ]: 0 : const sal_uInt16 nCount = aPoly.GetSize();
132 : :
133 [ # # ]: 0 : for (sal_uInt16 i = 0; i < nCount; ++i)
134 [ # # ][ # # ]: 0 : AppendCERNCoords(aStrBuf, aPoly[i]);
135 : :
136 [ # # ]: 0 : AppendCERNURL(aStrBuf, rBaseURL);
137 : :
138 [ # # ]: 0 : rOStm.WriteLine(aStrBuf.makeStringAndClear());
139 : 0 : }
140 : :
141 : 0 : void IMapPolygonObject::WriteNCSA( SvStream& rOStm, const String& rBaseURL ) const
142 : : {
143 [ # # ]: 0 : rtl::OStringBuffer aStrBuf(RTL_CONSTASCII_STRINGPARAM("poly "));
144 [ # # ]: 0 : const sal_uInt16 nCount = Min( aPoly.GetSize(), (sal_uInt16) 100 );
145 : :
146 [ # # ]: 0 : AppendNCSAURL(aStrBuf, rBaseURL);
147 : :
148 [ # # ]: 0 : for (sal_uInt16 i = 0; i < nCount; ++i)
149 [ # # ][ # # ]: 0 : AppendNCSACoords(aStrBuf, aPoly[i]);
150 : :
151 [ # # ]: 0 : rOStm.WriteLine(aStrBuf.makeStringAndClear());
152 : 0 : }
153 : :
154 : 0 : void ImageMap::Write( SvStream& rOStm, sal_uLong nFormat, const String& rBaseURL ) const
155 : : {
156 [ # # # # ]: 0 : switch( nFormat )
157 : : {
158 : 0 : case( IMAP_FORMAT_BIN ) : Write( rOStm, rBaseURL );
159 : 0 : case( IMAP_FORMAT_CERN ) : ImpWriteCERN( rOStm, rBaseURL ); break;
160 : 0 : case( IMAP_FORMAT_NCSA ) : ImpWriteNCSA( rOStm, rBaseURL ); break;
161 : :
162 : : default:
163 : 0 : break;
164 : : }
165 : 0 : }
166 : :
167 : 0 : void ImageMap::ImpWriteCERN( SvStream& rOStm, const String& rBaseURL ) const
168 : : {
169 : : IMapObject* pObj;
170 : 0 : size_t nCount = maList.size();
171 : :
172 [ # # ]: 0 : for ( size_t i = 0; i < nCount; i++ )
173 : : {
174 : 0 : pObj = maList[ i ];
175 : :
176 [ # # # # ]: 0 : switch( pObj->GetType() )
177 : : {
178 : : case( IMAP_OBJ_RECTANGLE ):
179 : 0 : ( (IMapRectangleObject*) pObj )->WriteCERN( rOStm, rBaseURL );
180 : 0 : break;
181 : :
182 : : case( IMAP_OBJ_CIRCLE ):
183 : 0 : ( (IMapCircleObject*) pObj )->WriteCERN( rOStm, rBaseURL );
184 : 0 : break;
185 : :
186 : : case( IMAP_OBJ_POLYGON ):
187 : 0 : ( (IMapPolygonObject*) pObj )->WriteCERN( rOStm, rBaseURL );
188 : 0 : break;
189 : :
190 : : default:
191 : 0 : break;
192 : : }
193 : : }
194 : 0 : }
195 : :
196 : 0 : void ImageMap::ImpWriteNCSA( SvStream& rOStm, const String& rBaseURL ) const
197 : : {
198 : : IMapObject* pObj;
199 : 0 : size_t nCount = maList.size();
200 : :
201 [ # # ]: 0 : for ( size_t i = 0; i < nCount; i++ )
202 : : {
203 : 0 : pObj = maList[ i ];
204 : :
205 [ # # # # ]: 0 : switch( pObj->GetType() )
206 : : {
207 : : case( IMAP_OBJ_RECTANGLE ):
208 : 0 : ( (IMapRectangleObject*) pObj )->WriteNCSA( rOStm, rBaseURL );
209 : 0 : break;
210 : :
211 : : case( IMAP_OBJ_CIRCLE ):
212 : 0 : ( (IMapCircleObject*) pObj )->WriteNCSA( rOStm, rBaseURL );
213 : 0 : break;
214 : :
215 : : case( IMAP_OBJ_POLYGON ):
216 : 0 : ( (IMapPolygonObject*) pObj )->WriteNCSA( rOStm, rBaseURL );
217 : 0 : break;
218 : :
219 : : default:
220 : 0 : break;
221 : : }
222 : : }
223 : 0 : }
224 : :
225 : 0 : sal_uLong ImageMap::Read( SvStream& rIStm, sal_uLong nFormat, const String& rBaseURL )
226 : : {
227 : 0 : sal_uLong nRet = IMAP_ERR_FORMAT;
228 : :
229 [ # # ]: 0 : if ( nFormat == IMAP_FORMAT_DETECT )
230 : 0 : nFormat = ImpDetectFormat( rIStm );
231 : :
232 [ # # # # ]: 0 : switch ( nFormat )
233 : : {
234 : 0 : case ( IMAP_FORMAT_BIN ) : Read( rIStm, rBaseURL ); break;
235 : 0 : case ( IMAP_FORMAT_CERN ) : nRet = ImpReadCERN( rIStm, rBaseURL ); break;
236 : 0 : case ( IMAP_FORMAT_NCSA ) : nRet = ImpReadNCSA( rIStm, rBaseURL ); break;
237 : :
238 : : default:
239 : 0 : break;
240 : : }
241 : :
242 [ # # ]: 0 : if ( !rIStm.GetError() )
243 : 0 : nRet = IMAP_ERR_OK;
244 : :
245 : 0 : return nRet;
246 : : }
247 : :
248 : 0 : sal_uLong ImageMap::ImpReadCERN( SvStream& rIStm, const String& rBaseURL )
249 : : {
250 : : // alten Inhalt loeschen
251 [ # # ]: 0 : ClearImageMap();
252 : :
253 : 0 : rtl::OString aStr;
254 [ # # ][ # # ]: 0 : while ( rIStm.ReadLine( aStr ) )
255 [ # # ]: 0 : ImpReadCERNLine( aStr, rBaseURL );
256 : :
257 : 0 : return IMAP_ERR_OK;
258 : : }
259 : :
260 : 0 : void ImageMap::ImpReadCERNLine( const rtl::OString& rLine, const String& rBaseURL )
261 : : {
262 [ # # ]: 0 : rtl::OString aStr = comphelper::string::stripStart(rLine, ' ');
263 [ # # ]: 0 : aStr = comphelper::string::stripStart(aStr, '\t');
264 : 0 : aStr = comphelper::string::remove(aStr, ';');
265 : 0 : aStr = aStr.toAsciiLowerCase();
266 : :
267 : 0 : const char* pStr = aStr.getStr();
268 : 0 : char cChar = *pStr++;
269 : :
270 : : // Anweisung finden
271 : 0 : rtl::OStringBuffer aBuf;
272 [ # # ][ # # ]: 0 : while( ( cChar >= 'a' ) && ( cChar <= 'z' ) && NOTEOL( cChar ) )
[ # # ][ # # ]
273 : : {
274 [ # # ]: 0 : aBuf.append(cChar);
275 : 0 : cChar = *pStr++;
276 : : }
277 : 0 : rtl::OString aToken = aBuf.makeStringAndClear();
278 : :
279 [ # # ]: 0 : if ( NOTEOL( cChar ) )
280 : : {
281 [ # # ][ # # ]: 0 : if ( ( aToken == "rectangle" ) || ( aToken == "rect" ) )
[ # # ]
282 : : {
283 [ # # ]: 0 : const Point aTopLeft( ImpReadCERNCoords( &pStr ) );
284 [ # # ]: 0 : const Point aBottomRight( ImpReadCERNCoords( &pStr ) );
285 [ # # ]: 0 : const String aURL( ImpReadCERNURL( &pStr, rBaseURL ) );
286 [ # # ]: 0 : const Rectangle aRect( aTopLeft, aBottomRight );
287 : :
288 [ # # ][ # # ]: 0 : IMapRectangleObject* pObj = new IMapRectangleObject( aRect, aURL, String(), String(), String(), String() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
289 [ # # ][ # # ]: 0 : maList.push_back( pObj );
290 : : }
291 [ # # ][ # # ]: 0 : else if ( ( aToken == "circle" ) || ( aToken == "circ" ) )
[ # # ]
292 : : {
293 [ # # ]: 0 : const Point aCenter( ImpReadCERNCoords( &pStr ) );
294 [ # # ]: 0 : const long nRadius = ImpReadCERNRadius( &pStr );
295 [ # # ]: 0 : const String aURL( ImpReadCERNURL( &pStr, rBaseURL ) );
296 : :
297 [ # # ][ # # ]: 0 : IMapCircleObject* pObj = new IMapCircleObject( aCenter, nRadius, aURL, String(), String(), String(), String() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
298 [ # # ][ # # ]: 0 : maList.push_back( pObj );
299 : : }
300 [ # # ][ # # ]: 0 : else if ( ( aToken == "polygon" ) || ( aToken == "poly" ) )
[ # # ]
301 : : {
302 : : const sal_uInt16 nCount = comphelper::string::getTokenCount(aStr,
303 [ # # ]: 0 : '(') - 1;
304 [ # # ]: 0 : Polygon aPoly( nCount );
305 [ # # ]: 0 : String aURL;
306 : :
307 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; i++ )
308 [ # # ][ # # ]: 0 : aPoly[ i ] = ImpReadCERNCoords( &pStr );
309 : :
310 [ # # ][ # # ]: 0 : aURL = ImpReadCERNURL( &pStr, rBaseURL );
[ # # ]
311 : :
312 [ # # ][ # # ]: 0 : IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, String(), String(), String(), String() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
313 [ # # ][ # # ]: 0 : maList.push_back( pObj );
[ # # ]
314 : : }
315 : 0 : }
316 : 0 : }
317 : :
318 : 0 : Point ImageMap::ImpReadCERNCoords( const char** ppStr )
319 : : {
320 [ # # ]: 0 : String aStrX;
321 [ # # ]: 0 : String aStrY;
322 : 0 : Point aPt;
323 : 0 : char cChar = *(*ppStr)++;
324 : :
325 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) )
[ # # ][ # # ]
326 : 0 : cChar = *(*ppStr)++;
327 : :
328 [ # # ]: 0 : if ( NOTEOL( cChar ) )
329 : : {
330 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) )
[ # # ][ # # ]
331 : : {
332 [ # # ]: 0 : aStrX += cChar;
333 : 0 : cChar = *(*ppStr)++;
334 : : }
335 : :
336 [ # # ]: 0 : if ( NOTEOL( cChar ) )
337 : : {
338 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) )
[ # # ][ # # ]
339 : 0 : cChar = *(*ppStr)++;
340 : :
341 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) )
[ # # ][ # # ]
342 : : {
343 [ # # ]: 0 : aStrY += cChar;
344 : 0 : cChar = *(*ppStr)++;
345 : : }
346 : :
347 [ # # ]: 0 : if ( NOTEOL( cChar ) )
348 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( cChar != ')' ) )
[ # # ]
349 : 0 : cChar = *(*ppStr)++;
350 : :
351 [ # # ][ # # ]: 0 : aPt = Point( aStrX.ToInt32(), aStrY.ToInt32() );
352 : : }
353 : : }
354 : :
355 [ # # ][ # # ]: 0 : return aPt;
356 : : }
357 : :
358 : 0 : long ImageMap::ImpReadCERNRadius( const char** ppStr )
359 : : {
360 [ # # ]: 0 : String aStr;
361 : 0 : char cChar = *(*ppStr)++;
362 : :
363 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) )
[ # # ][ # # ]
364 : 0 : cChar = *(*ppStr)++;
365 : :
366 [ # # ]: 0 : if ( NOTEOL( cChar ) )
367 : : {
368 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) )
[ # # ][ # # ]
369 : : {
370 [ # # ]: 0 : aStr += cChar;
371 : 0 : cChar = *(*ppStr)++;
372 : : }
373 : : }
374 : :
375 [ # # ][ # # ]: 0 : return aStr.ToInt32();
376 : : }
377 : :
378 : 0 : String ImageMap::ImpReadCERNURL( const char** ppStr, const String& rBaseURL )
379 : : {
380 : 0 : rtl::OUString aStr(rtl::OUString::createFromAscii(*ppStr));
381 : :
382 [ # # ]: 0 : aStr = comphelper::string::stripStart(aStr, ' ');
383 [ # # ]: 0 : aStr = comphelper::string::stripStart(aStr, '\t');
384 [ # # ]: 0 : aStr = comphelper::string::stripEnd(aStr, ' ');
385 [ # # ]: 0 : aStr = comphelper::string::stripEnd(aStr, '\t');
386 : :
387 [ # # ][ # # ]: 0 : return INetURLObject::GetAbsURL( rBaseURL, aStr );
[ # # ]
388 : : }
389 : :
390 : 0 : sal_uLong ImageMap::ImpReadNCSA( SvStream& rIStm, const String& rBaseURL )
391 : : {
392 : : // alten Inhalt loeschen
393 [ # # ]: 0 : ClearImageMap();
394 : :
395 : 0 : rtl::OString aStr;
396 [ # # ][ # # ]: 0 : while ( rIStm.ReadLine( aStr ) )
397 [ # # ]: 0 : ImpReadNCSALine( aStr, rBaseURL );
398 : :
399 : 0 : return IMAP_ERR_OK;
400 : : }
401 : :
402 : 0 : void ImageMap::ImpReadNCSALine( const rtl::OString& rLine, const String& rBaseURL )
403 : : {
404 [ # # ]: 0 : rtl::OString aStr = comphelper::string::stripStart(rLine, ' ');
405 [ # # ]: 0 : aStr = comphelper::string::stripStart(aStr, '\t');
406 : 0 : aStr = comphelper::string::remove(aStr, ';');
407 : 0 : aStr = aStr.toAsciiLowerCase();
408 : :
409 : 0 : const char* pStr = aStr.getStr();
410 : 0 : char cChar = *pStr++;
411 : :
412 : : // Anweisung finden
413 : 0 : rtl::OStringBuffer aBuf;
414 [ # # ][ # # ]: 0 : while( ( cChar >= 'a' ) && ( cChar <= 'z' ) && NOTEOL( cChar ) )
[ # # ][ # # ]
415 : : {
416 [ # # ]: 0 : aBuf.append(cChar);
417 : 0 : cChar = *pStr++;
418 : : }
419 : 0 : rtl::OString aToken = aBuf.makeStringAndClear();
420 : :
421 [ # # ]: 0 : if ( NOTEOL( cChar ) )
422 : : {
423 [ # # ]: 0 : if ( aToken == "rect" )
424 : : {
425 [ # # ]: 0 : const String aURL( ImpReadNCSAURL( &pStr, rBaseURL ) );
426 [ # # ]: 0 : const Point aTopLeft( ImpReadNCSACoords( &pStr ) );
427 [ # # ]: 0 : const Point aBottomRight( ImpReadNCSACoords( &pStr ) );
428 [ # # ]: 0 : const Rectangle aRect( aTopLeft, aBottomRight );
429 : :
430 [ # # ][ # # ]: 0 : IMapRectangleObject* pObj = new IMapRectangleObject( aRect, aURL, String(), String(), String(), String() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
431 [ # # ][ # # ]: 0 : maList.push_back( pObj );
432 : : }
433 [ # # ]: 0 : else if ( aToken == "circle" )
434 : : {
435 [ # # ]: 0 : const String aURL( ImpReadNCSAURL( &pStr, rBaseURL ) );
436 [ # # ]: 0 : const Point aCenter( ImpReadNCSACoords( &pStr ) );
437 [ # # ]: 0 : const Point aDX( aCenter - ImpReadNCSACoords( &pStr ) );
438 : 0 : long nRadius = (long) sqrt( (double) aDX.X() * aDX.X() +
439 : 0 : (double) aDX.Y() * aDX.Y() );
440 : :
441 [ # # ][ # # ]: 0 : IMapCircleObject* pObj = new IMapCircleObject( aCenter, nRadius, aURL, String(), String(), String(), String() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
442 [ # # ][ # # ]: 0 : maList.push_back( pObj );
443 : : }
444 [ # # ]: 0 : else if ( aToken == "poly" )
445 : : {
446 : : const sal_uInt16 nCount = comphelper::string::getTokenCount(aStr,
447 [ # # ]: 0 : ',') - 1;
448 [ # # ]: 0 : const String aURL( ImpReadNCSAURL( &pStr, rBaseURL ) );
449 [ # # ]: 0 : Polygon aPoly( nCount );
450 : :
451 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; i++ )
452 [ # # ][ # # ]: 0 : aPoly[ i ] = ImpReadNCSACoords( &pStr );
453 : :
454 [ # # ][ # # ]: 0 : IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, String(), String(), String(), String() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
455 [ # # ][ # # ]: 0 : maList.push_back( pObj );
[ # # ]
456 : : }
457 : 0 : }
458 : 0 : }
459 : :
460 : 0 : String ImageMap::ImpReadNCSAURL( const char** ppStr, const String& rBaseURL )
461 : : {
462 [ # # ]: 0 : String aStr;
463 : 0 : char cChar = *(*ppStr)++;
464 : :
465 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( ( cChar == ' ' ) || ( cChar == '\t' ) ) )
[ # # ][ # # ]
466 : 0 : cChar = *(*ppStr)++;
467 : :
468 [ # # ]: 0 : if ( NOTEOL( cChar ) )
469 : : {
470 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( cChar != ' ' ) && ( cChar != '\t' ) )
[ # # ][ # # ]
471 : : {
472 [ # # ]: 0 : aStr += cChar;
473 : 0 : cChar = *(*ppStr)++;
474 : : }
475 : : }
476 : :
477 [ # # ][ # # ]: 0 : return INetURLObject::GetAbsURL( rBaseURL, aStr );
[ # # ][ # # ]
[ # # ]
478 : : }
479 : :
480 : 0 : Point ImageMap::ImpReadNCSACoords( const char** ppStr )
481 : : {
482 [ # # ]: 0 : String aStrX;
483 [ # # ]: 0 : String aStrY;
484 : 0 : Point aPt;
485 : 0 : char cChar = *(*ppStr)++;
486 : :
487 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) )
[ # # ][ # # ]
488 : 0 : cChar = *(*ppStr)++;
489 : :
490 [ # # ]: 0 : if ( NOTEOL( cChar ) )
491 : : {
492 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) )
[ # # ][ # # ]
493 : : {
494 [ # # ]: 0 : aStrX += cChar;
495 : 0 : cChar = *(*ppStr)++;
496 : : }
497 : :
498 [ # # ]: 0 : if ( NOTEOL( cChar ) )
499 : : {
500 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) )
[ # # ][ # # ]
501 : 0 : cChar = *(*ppStr)++;
502 : :
503 [ # # ][ # # ]: 0 : while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) )
[ # # ][ # # ]
504 : : {
505 [ # # ]: 0 : aStrY += cChar;
506 : 0 : cChar = *(*ppStr)++;
507 : : }
508 : :
509 [ # # ][ # # ]: 0 : aPt = Point( aStrX.ToInt32(), aStrY.ToInt32() );
510 : : }
511 : : }
512 : :
513 [ # # ][ # # ]: 0 : return aPt;
514 : : }
515 : :
516 : 0 : sal_uLong ImageMap::ImpDetectFormat( SvStream& rIStm )
517 : : {
518 : 0 : sal_uLong nPos = rIStm.Tell();
519 : 0 : sal_uLong nRet = IMAP_FORMAT_BIN;
520 : : char cMagic[6];
521 : :
522 [ # # ]: 0 : rIStm.Read( cMagic, sizeof( cMagic ) );
523 : :
524 : : // Falls wir kein internes Format haben,
525 : : // untersuchen wir das Format
526 [ # # ]: 0 : if ( memcmp( cMagic, IMAPMAGIC, sizeof( cMagic ) ) )
527 : : {
528 : 0 : long nCount = 128;
529 : :
530 [ # # ]: 0 : rIStm.Seek( nPos );
531 : 0 : rtl::OString aStr;
532 [ # # ][ # # ]: 0 : while ( rIStm.ReadLine( aStr ) && nCount-- )
[ # # ][ # # ]
533 : : {
534 : 0 : aStr = aStr.toAsciiLowerCase();
535 : :
536 [ # # ][ # # : 0 : if ( (aStr.indexOfL(RTL_CONSTASCII_STRINGPARAM("rect")) != -1) ||
# # # # ]
537 : 0 : (aStr.indexOfL(RTL_CONSTASCII_STRINGPARAM("circ")) != -1) ||
538 : 0 : (aStr.indexOfL(RTL_CONSTASCII_STRINGPARAM("poly")) != -1) )
539 : : {
540 [ # # # # ]: 0 : if ( ( aStr.indexOf('(') != -1 ) &&
[ # # ]
541 : 0 : ( aStr.indexOf(')') != -1 ) )
542 : : {
543 : 0 : nRet = IMAP_FORMAT_CERN;
544 : : }
545 : : else
546 : 0 : nRet = IMAP_FORMAT_NCSA;
547 : :
548 : 0 : break;
549 : : }
550 : 0 : }
551 : : }
552 : :
553 [ # # ]: 0 : rIStm.Seek( nPos );
554 : :
555 : 0 : return nRet;
556 : : }
557 : :
558 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|