1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inetimg.cxx,v $
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>
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
;
49 case SOT_FORMATSTR_ID_INET_IMAGE
:
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();
68 case SOT_FORMATSTR_ID_NETSCAPE_IMAGE
:
74 sal_Bool
INetImage::Read( SvStream
& rIStm
, ULONG nFormat
)
76 sal_Bool bRet
= sal_False
;
79 case SOT_FORMATSTR_ID_INET_IMAGE
:
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
,
90 aSizePixel
.Height() = sINetImg
.GetToken( 0, TOKEN_SEPARATOR
,
92 bRet
= 0 != sINetImg
.Len();
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
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
;
117 nFilePos
= rIStm
.Tell();
118 // skip over iSize (int), bIsMao ( BOOL ) alignment of 4 !!!!
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 ) );
125 rIStm
>> nAnchorOffset
;
126 // skip over iExtraHTML_Offset
127 rIStm
.SeekRel( sizeof( int ) );
129 rIStm
.ReadCString( aImageURL
, eSysCSet
);
132 rIStm
.Seek( nFilePos
+ nAltOffset
);
133 rIStm
.ReadCString( aAlternateText
, eSysCSet
);
135 else if( aAlternateText
.Len() )
136 aAlternateText
.Erase();
140 rIStm
.Seek( nFilePos
+ nAnchorOffset
);
141 rIStm
.ReadCString( aTargetURL
, eSysCSet
);
143 else if( aTargetURL
.Len() )
146 bRet
= 0 == rIStm
.GetError();