1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sot/formats.hxx>
21 #include <tools/stream.hxx>
23 #include <svtools/inetimg.hxx>
25 #define TOKEN_SEPARATOR '\001'
27 sal_Bool
INetImage::Write( SvStream
& rOStm
, sal_uLong nFormat
) const
29 sal_Bool bRet
= sal_False
;
32 case SOT_FORMATSTR_ID_INET_IMAGE
:
35 (sString
+= aImageURL
) += TOKEN_SEPARATOR
;
36 (sString
+= aTargetURL
) += TOKEN_SEPARATOR
;
37 (sString
+= aTargetFrame
) += TOKEN_SEPARATOR
;
38 (sString
+= aAlternateText
) += TOKEN_SEPARATOR
;
39 sString
+= OUString::number( aSizePixel
.Width() );
40 sString
+= TOKEN_SEPARATOR
;
41 sString
+= OUString::number( aSizePixel
.Height() );
43 OString
sOut(OUStringToOString(sString
,
44 RTL_TEXTENCODING_UTF8
));
46 rOStm
.Write(sOut
.getStr(), sOut
.getLength());
47 static const sal_Char aEndChar
[2] = { 0 };
48 rOStm
.Write( aEndChar
, sizeof( aEndChar
));
49 bRet
= 0 == rOStm
.GetError();
53 case SOT_FORMATSTR_ID_NETSCAPE_IMAGE
:
59 sal_Bool
INetImage::Read( SvStream
& rIStm
, sal_uLong nFormat
)
61 sal_Bool bRet
= sal_False
;
64 case SOT_FORMATSTR_ID_INET_IMAGE
:
66 String sINetImg
= read_zeroTerminated_uInt8s_ToOUString(rIStm
, RTL_TEXTENCODING_UTF8
);
68 aImageURL
= sINetImg
.GetToken( 0, TOKEN_SEPARATOR
, nStart
);
69 aTargetURL
= sINetImg
.GetToken( 0, TOKEN_SEPARATOR
, nStart
);
70 aTargetFrame
= sINetImg
.GetToken( 0, TOKEN_SEPARATOR
, nStart
);
71 aAlternateText
= sINetImg
.GetToken( 0, TOKEN_SEPARATOR
, nStart
);
72 aSizePixel
.Width() = sINetImg
.GetToken( 0, TOKEN_SEPARATOR
,
74 aSizePixel
.Height() = sINetImg
.GetToken( 0, TOKEN_SEPARATOR
,
76 bRet
= 0 != sINetImg
.Len();
80 case SOT_FORMATSTR_ID_NETSCAPE_IMAGE
:
83 --> structure size MUST - alignment of 4!
84 int iSize; // size of all data, including variable length strings
85 sal_Bool bIsMap; // For server side maps
86 sal_Int32 iWidth; // Fixed size data correspond to fields in LO_ImageDataStruct
87 sal_Int32 iHeight; // and EDT_ImageData
91 int iLowResOffset; // Offsets into string_data. If 0, string is NULL (not used)
92 int iAltOffset; // (alternate text?)
93 int iAnchorOffset; // HREF in image
94 int iExtraHTML_Offset; // Extra HTML (stored in CImageElement)
95 sal_Char pImageURL[1]; // Append all variable-length strings starting here
97 rtl_TextEncoding eSysCSet
= osl_getThreadTextEncoding();
98 sal_Int32 nVal
, nAnchorOffset
, nAltOffset
, nFilePos
;
100 nFilePos
= rIStm
.Tell();
101 // skip over iSize (int), bIsMao ( sal_Bool ) alignment of 4 !!!!
103 rIStm
>> nVal
; aSizePixel
.Width() = nVal
;
104 rIStm
>> nVal
; aSizePixel
.Height() = nVal
;
105 // skip over iHSpace, iVSpace, iBorder, iLowResOffset
106 rIStm
.SeekRel( 3 * sizeof( sal_Int32
) + sizeof( int ) );
108 rIStm
>> nAnchorOffset
;
109 // skip over iExtraHTML_Offset
110 rIStm
.SeekRel( sizeof( int ) );
112 aImageURL
= read_zeroTerminated_uInt8s_ToOUString(rIStm
, eSysCSet
);
115 rIStm
.Seek( nFilePos
+ nAltOffset
);
116 aAlternateText
= read_zeroTerminated_uInt8s_ToOUString(rIStm
, eSysCSet
);
118 else if( aAlternateText
.Len() )
119 aAlternateText
.Erase();
123 rIStm
.Seek( nFilePos
+ nAnchorOffset
);
124 aTargetURL
= read_zeroTerminated_uInt8s_ToOUString(rIStm
, eSysCSet
);
126 else if( aTargetURL
.Len() )
129 bRet
= 0 == rIStm
.GetError();
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */