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 <osl/thread.h>
21 #include <sot/formats.hxx>
22 #include <tools/stream.hxx>
24 #include <svtools/inetimg.hxx>
26 static const sal_Unicode TOKEN_SEPARATOR
= '\001';
28 bool INetImage::Write( SvStream
& rOStm
, SotClipboardFormatId nFormat
) const
33 case SotClipboardFormatId::INET_IMAGE
:
36 (sString
+= aImageURL
) += OUString(TOKEN_SEPARATOR
);
37 (sString
+= aTargetURL
) += OUString(TOKEN_SEPARATOR
);
38 (sString
+= aTargetFrame
) += OUString(TOKEN_SEPARATOR
);
39 (sString
+= aAlternateText
) += OUString(TOKEN_SEPARATOR
);
40 sString
+= OUString::number( aSizePixel
.Width() );
41 sString
+= OUString(TOKEN_SEPARATOR
);
42 sString
+= OUString::number( aSizePixel
.Height() );
44 OString
sOut(OUStringToOString(sString
,
45 RTL_TEXTENCODING_UTF8
));
47 rOStm
.Write(sOut
.getStr(), sOut
.getLength());
48 static const sal_Char aEndChar
[2] = { 0 };
49 rOStm
.Write( aEndChar
, sizeof( aEndChar
));
50 bRet
= 0 == rOStm
.GetError();
54 case SotClipboardFormatId::NETSCAPE_IMAGE
:
61 bool INetImage::Read( SvStream
& rIStm
, SotClipboardFormatId nFormat
)
66 case SotClipboardFormatId::INET_IMAGE
:
68 OUString sINetImg
= read_zeroTerminated_uInt8s_ToOUString(rIStm
, RTL_TEXTENCODING_UTF8
);
70 aImageURL
= sINetImg
.getToken( 0, TOKEN_SEPARATOR
, nStart
);
71 aTargetURL
= sINetImg
.getToken( 0, TOKEN_SEPARATOR
, nStart
);
72 aTargetFrame
= sINetImg
.getToken( 0, TOKEN_SEPARATOR
, nStart
);
73 aAlternateText
= sINetImg
.getToken( 0, TOKEN_SEPARATOR
, nStart
);
74 aSizePixel
.Width() = sINetImg
.getToken( 0, TOKEN_SEPARATOR
,
76 aSizePixel
.Height() = sINetImg
.getToken( 0, TOKEN_SEPARATOR
,
78 bRet
= !sINetImg
.isEmpty();
82 case SotClipboardFormatId::NETSCAPE_IMAGE
:
85 --> structure size MUST - alignment of 4!
86 int iSize; // size of all data, including variable length strings
87 sal_Bool bIsMap; // For server side maps
88 sal_Int32 iWidth; // Fixed size data correspond to fields in LO_ImageDataStruct
89 sal_Int32 iHeight; // and EDT_ImageData
93 int iLowResOffset; // Offsets into string_data. If 0, string is NULL (not used)
94 int iAltOffset; // (alternate text?)
95 int iAnchorOffset; // HREF in image
96 int iExtraHTML_Offset; // Extra HTML (stored in CImageElement)
97 sal_Char pImageURL[1]; // Append all variable-length strings starting here
99 rtl_TextEncoding eSysCSet
= osl_getThreadTextEncoding();
100 sal_Int32 nVal
, nAnchorOffset
, nAltOffset
, nFilePos
;
102 nFilePos
= rIStm
.Tell();
103 // skip over iSize (int), bIsMao ( sal_Bool ) alignment of 4 !!!!
105 rIStm
.ReadInt32( nVal
); aSizePixel
.Width() = nVal
;
106 rIStm
.ReadInt32( nVal
); aSizePixel
.Height() = nVal
;
107 // skip over iHSpace, iVSpace, iBorder, iLowResOffset
108 rIStm
.SeekRel( 3 * sizeof( sal_Int32
) + sizeof( int ) );
109 rIStm
.ReadInt32( nAltOffset
);
110 rIStm
.ReadInt32( nAnchorOffset
);
111 // skip over iExtraHTML_Offset
112 rIStm
.SeekRel( sizeof( int ) );
114 aImageURL
= read_zeroTerminated_uInt8s_ToOUString(rIStm
, eSysCSet
);
117 rIStm
.Seek( nFilePos
+ nAltOffset
);
118 aAlternateText
= read_zeroTerminated_uInt8s_ToOUString(rIStm
, eSysCSet
);
120 else if( !aAlternateText
.isEmpty() )
121 aAlternateText
.clear();
125 rIStm
.Seek( nFilePos
+ nAnchorOffset
);
126 aTargetURL
= read_zeroTerminated_uInt8s_ToOUString(rIStm
, eSysCSet
);
128 else if( !aTargetURL
.isEmpty() )
131 bRet
= 0 == rIStm
.GetError();
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */