Bump version to 5.0-14
[LibreOffice.git] / svtools / source / urlobj / inetimg.cxx
blob51ef978ee0bb180501e6b91ee450a944966e96a2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
30 bool bRet = false;
31 switch( nFormat )
33 case SotClipboardFormatId::INET_IMAGE:
35 OUString sString;
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();
52 break;
54 case SotClipboardFormatId::NETSCAPE_IMAGE:
55 break;
56 default: break;
58 return bRet;
61 bool INetImage::Read( SvStream& rIStm, SotClipboardFormatId nFormat )
63 bool bRet = false;
64 switch( nFormat )
66 case SotClipboardFormatId::INET_IMAGE:
68 OUString sINetImg = read_zeroTerminated_uInt8s_ToOUString(rIStm, RTL_TEXTENCODING_UTF8);
69 sal_Int32 nStart = 0;
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,
75 nStart ).toInt32();
76 aSizePixel.Height() = sINetImg.getToken( 0, TOKEN_SEPARATOR,
77 nStart ).toInt32();
78 bRet = !sINetImg.isEmpty();
80 break;
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
90 sal_Int32 iHSpace;
91 sal_Int32 iVSpace;
92 sal_Int32 iBorder;
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 !!!!
104 rIStm.SeekRel( 8 );
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);
115 if( nAltOffset )
117 rIStm.Seek( nFilePos + nAltOffset );
118 aAlternateText = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
120 else if( !aAlternateText.isEmpty() )
121 aAlternateText.clear();
123 if( nAnchorOffset )
125 rIStm.Seek( nFilePos + nAnchorOffset );
126 aTargetURL = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
128 else if( !aTargetURL.isEmpty() )
129 aTargetURL.clear();
131 bRet = 0 == rIStm.GetError();
133 break;
134 default: break;
136 return bRet;
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */