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