update dev300-m58
[ooovba.git] / svtools / source / urlobj / inetimg.cxx
blobbd790c3761afe36c902af01680d65774103051b1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inetimg.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <tools/debug.hxx>
34 #include <sot/formats.hxx>
35 #include <tools/stream.hxx>
37 #ifndef GCC
38 #endif
40 #include "inetimg.hxx"
42 #define TOKEN_SEPARATOR '\001'
44 sal_Bool INetImage::Write( SvStream& rOStm, ULONG nFormat ) const
46 sal_Bool bRet = sal_False;
47 switch( nFormat )
49 case SOT_FORMATSTR_ID_INET_IMAGE:
51 String sString;
52 (sString += aImageURL ) += TOKEN_SEPARATOR;
53 (sString += aTargetURL ) += TOKEN_SEPARATOR;
54 (sString += aTargetFrame ) += TOKEN_SEPARATOR;
55 (sString += aAlternateText ) += TOKEN_SEPARATOR;
56 sString += String::CreateFromInt32( aSizePixel.Width() );
57 sString += TOKEN_SEPARATOR;
58 sString += String::CreateFromInt32( aSizePixel.Height() );
59 ByteString sOut( sString, RTL_TEXTENCODING_UTF8 );
61 rOStm.Write( sOut.GetBuffer(), sOut.Len() );
62 static const sal_Char aEndChar[2] = { 0 };
63 rOStm.Write( aEndChar, sizeof( aEndChar ));
64 bRet = 0 == rOStm.GetError();
66 break;
68 case SOT_FORMATSTR_ID_NETSCAPE_IMAGE:
69 break;
71 return bRet;
74 sal_Bool INetImage::Read( SvStream& rIStm, ULONG nFormat )
76 sal_Bool bRet = sal_False;
77 switch( nFormat )
79 case SOT_FORMATSTR_ID_INET_IMAGE:
81 String sINetImg;
82 rIStm.ReadCString( sINetImg, RTL_TEXTENCODING_UTF8 );
83 xub_StrLen nStart = 0;
84 aImageURL = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
85 aTargetURL = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
86 aTargetFrame = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
87 aAlternateText = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
88 aSizePixel.Width() = sINetImg.GetToken( 0, TOKEN_SEPARATOR,
89 nStart ).ToInt32();
90 aSizePixel.Height() = sINetImg.GetToken( 0, TOKEN_SEPARATOR,
91 nStart ).ToInt32();
92 bRet = 0 != sINetImg.Len();
94 break;
96 case SOT_FORMATSTR_ID_NETSCAPE_IMAGE:
99 --> structure size MUST - alignment of 4!
100 int iSize; // size of all data, including variable length strings
101 BOOL bIsMap; // For server side maps
102 INT32 iWidth; // Fixed size data correspond to fields in LO_ImageDataStruct
103 INT32 iHeight; // and EDT_ImageData
104 INT32 iHSpace;
105 INT32 iVSpace;
106 INT32 iBorder;
107 int iLowResOffset; // Offsets into string_data. If 0, string is NULL (not used)
108 int iAltOffset; // (alternate text?)
109 int iAnchorOffset; // HREF in image
110 int iExtraHTML_Offset; // Extra HTML (stored in CImageElement)
111 sal_Char pImageURL[1]; // Append all variable-length strings starting here
113 rtl_TextEncoding eSysCSet = gsl_getSystemTextEncoding();
114 sal_Int32 nVal, nAnchorOffset, nAltOffset, nFilePos;
115 ByteString sData;
117 nFilePos = rIStm.Tell();
118 // skip over iSize (int), bIsMao ( BOOL ) alignment of 4 !!!!
119 rIStm.SeekRel( 8 );
120 rIStm >> nVal; aSizePixel.Width() = nVal;
121 rIStm >> nVal; aSizePixel.Height() = nVal;
122 // skip over iHSpace, iVSpace, iBorder, iLowResOffset
123 rIStm.SeekRel( 3 * sizeof( INT32 ) + sizeof( int ) );
124 rIStm >> nAltOffset;
125 rIStm >> nAnchorOffset;
126 // skip over iExtraHTML_Offset
127 rIStm.SeekRel( sizeof( int ) );
129 rIStm.ReadCString( aImageURL, eSysCSet );
130 if( nAltOffset )
132 rIStm.Seek( nFilePos + nAltOffset );
133 rIStm.ReadCString( aAlternateText, eSysCSet );
135 else if( aAlternateText.Len() )
136 aAlternateText.Erase();
138 if( nAnchorOffset )
140 rIStm.Seek( nFilePos + nAnchorOffset );
141 rIStm.ReadCString( aTargetURL, eSysCSet );
143 else if( aTargetURL.Len() )
144 aTargetURL.Erase();
146 bRet = 0 == rIStm.GetError();
148 break;
150 return bRet;