xref: /aoo41x/main/svtools/source/urlobj/inetimg.cxx (revision 5900e8ec)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #include <tools/debug.hxx>
27cdf0e10cSrcweir #include <sot/formats.hxx>
28cdf0e10cSrcweir #include <tools/stream.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <svtools/inetimg.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #define TOKEN_SEPARATOR '\001'
33cdf0e10cSrcweir 
Write(SvStream & rOStm,sal_uLong nFormat) const34cdf0e10cSrcweir sal_Bool INetImage::Write( SvStream& rOStm, sal_uLong nFormat ) const
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
37cdf0e10cSrcweir 	switch( nFormat )
38cdf0e10cSrcweir 	{
39cdf0e10cSrcweir 	case SOT_FORMATSTR_ID_INET_IMAGE:
40cdf0e10cSrcweir 		{
41cdf0e10cSrcweir 			String sString;
42cdf0e10cSrcweir 			(sString += aImageURL ) += TOKEN_SEPARATOR;
43cdf0e10cSrcweir 			(sString += aTargetURL ) += TOKEN_SEPARATOR;
44cdf0e10cSrcweir 			(sString += aTargetFrame ) += TOKEN_SEPARATOR;
45cdf0e10cSrcweir 			(sString += aAlternateText ) += TOKEN_SEPARATOR;
46cdf0e10cSrcweir 			sString += String::CreateFromInt32( aSizePixel.Width() );
47cdf0e10cSrcweir 			sString += TOKEN_SEPARATOR;
48cdf0e10cSrcweir 			sString += String::CreateFromInt32( aSizePixel.Height() );
49cdf0e10cSrcweir 			ByteString sOut( sString, RTL_TEXTENCODING_UTF8 );
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 			rOStm.Write( sOut.GetBuffer(), sOut.Len() );
52cdf0e10cSrcweir 			static const sal_Char aEndChar[2] = { 0 };
53cdf0e10cSrcweir 			rOStm.Write( aEndChar, sizeof( aEndChar ));
54cdf0e10cSrcweir 			bRet = 0 == rOStm.GetError();
55cdf0e10cSrcweir 		}
56cdf0e10cSrcweir 		break;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	case SOT_FORMATSTR_ID_NETSCAPE_IMAGE:
59cdf0e10cSrcweir 		break;
60cdf0e10cSrcweir 	}
61cdf0e10cSrcweir 	return bRet;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
Read(SvStream & rIStm,sal_uLong nFormat)64cdf0e10cSrcweir sal_Bool INetImage::Read( SvStream& rIStm, sal_uLong nFormat )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
67cdf0e10cSrcweir 	switch( nFormat )
68cdf0e10cSrcweir 	{
69cdf0e10cSrcweir 	case SOT_FORMATSTR_ID_INET_IMAGE:
70cdf0e10cSrcweir 		{
71cdf0e10cSrcweir 			String sINetImg;
72cdf0e10cSrcweir 			rIStm.ReadCString( sINetImg, RTL_TEXTENCODING_UTF8 );
73cdf0e10cSrcweir 			xub_StrLen nStart = 0;
74cdf0e10cSrcweir 			aImageURL = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
75cdf0e10cSrcweir 			aTargetURL = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
76cdf0e10cSrcweir 			aTargetFrame = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
77cdf0e10cSrcweir 			aAlternateText = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
78cdf0e10cSrcweir 			aSizePixel.Width() = sINetImg.GetToken( 0, TOKEN_SEPARATOR,
79cdf0e10cSrcweir 													nStart ).ToInt32();
80cdf0e10cSrcweir 			aSizePixel.Height() = sINetImg.GetToken( 0, TOKEN_SEPARATOR,
81cdf0e10cSrcweir 													nStart ).ToInt32();
82cdf0e10cSrcweir 			bRet = 0 != sINetImg.Len();
83cdf0e10cSrcweir 		}
84cdf0e10cSrcweir 		break;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	case SOT_FORMATSTR_ID_NETSCAPE_IMAGE:
87cdf0e10cSrcweir 		{
88cdf0e10cSrcweir /*
89cdf0e10cSrcweir 	--> structure size  MUST - alignment of 4!
90cdf0e10cSrcweir 	int     iSize;              // size of all data, including variable length strings
91cdf0e10cSrcweir 	sal_Bool    bIsMap;             // For server side maps
92cdf0e10cSrcweir 	sal_Int32   iWidth;             // Fixed size data correspond to fields in LO_ImageDataStruct
93cdf0e10cSrcweir 	sal_Int32   iHeight;            //   and EDT_ImageData
94cdf0e10cSrcweir 	sal_Int32   iHSpace;
95cdf0e10cSrcweir 	sal_Int32   iVSpace;
96cdf0e10cSrcweir 	sal_Int32   iBorder;
97cdf0e10cSrcweir 	int     iLowResOffset;      // Offsets into string_data. If 0, string is NULL (not used)
98cdf0e10cSrcweir 	int     iAltOffset;         // (alternate text?)
99cdf0e10cSrcweir 	int     iAnchorOffset;      // HREF in image
100cdf0e10cSrcweir 	int     iExtraHTML_Offset;  // Extra HTML (stored in CImageElement)
101cdf0e10cSrcweir 	sal_Char pImageURL[1]; 		// Append all variable-length strings starting here
102cdf0e10cSrcweir */
103cdf0e10cSrcweir 			rtl_TextEncoding eSysCSet = gsl_getSystemTextEncoding();
104cdf0e10cSrcweir 			sal_Int32 nVal, nAnchorOffset, nAltOffset, nFilePos;
105cdf0e10cSrcweir 			ByteString sData;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 			nFilePos = rIStm.Tell();
108cdf0e10cSrcweir 			// skip over iSize (int), bIsMao ( sal_Bool ) alignment of 4 !!!!
109cdf0e10cSrcweir 			rIStm.SeekRel( 8 );
110cdf0e10cSrcweir 			rIStm >> nVal;	aSizePixel.Width() = nVal;
111cdf0e10cSrcweir 			rIStm >> nVal;	aSizePixel.Height() = nVal;
112cdf0e10cSrcweir 			// skip over iHSpace, iVSpace, iBorder, iLowResOffset
113cdf0e10cSrcweir 			rIStm.SeekRel( 3 * sizeof( sal_Int32 ) + sizeof( int ) );
114cdf0e10cSrcweir 			rIStm >> nAltOffset;
115cdf0e10cSrcweir 			rIStm >> nAnchorOffset;
116cdf0e10cSrcweir 			// skip over iExtraHTML_Offset
117cdf0e10cSrcweir 			rIStm.SeekRel( sizeof( int ) );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 			rIStm.ReadCString( aImageURL, eSysCSet );
120cdf0e10cSrcweir 			if( nAltOffset )
121cdf0e10cSrcweir 			{
122cdf0e10cSrcweir 				rIStm.Seek( nFilePos + nAltOffset );
123cdf0e10cSrcweir 				rIStm.ReadCString( aAlternateText, eSysCSet );
124cdf0e10cSrcweir 			}
125cdf0e10cSrcweir 			else if( aAlternateText.Len() )
126cdf0e10cSrcweir 				aAlternateText.Erase();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 			if( nAnchorOffset )
129cdf0e10cSrcweir 			{
130cdf0e10cSrcweir 				rIStm.Seek( nFilePos + nAnchorOffset );
131cdf0e10cSrcweir 				rIStm.ReadCString( aTargetURL, eSysCSet );
132cdf0e10cSrcweir 			}
133cdf0e10cSrcweir 			else if( aTargetURL.Len() )
134cdf0e10cSrcweir 				aTargetURL.Erase();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 			bRet = 0 == rIStm.GetError();
137cdf0e10cSrcweir 		}
138cdf0e10cSrcweir 		break;
139cdf0e10cSrcweir 	}
140cdf0e10cSrcweir 	return bRet;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143