Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <osl/thread.h>
21 : #include <sot/formats.hxx>
22 : #include <tools/stream.hxx>
23 :
24 : #include <svtools/inetimg.hxx>
25 :
26 : static const sal_Unicode TOKEN_SEPARATOR = '\001';
27 :
28 0 : bool INetImage::Write( SvStream& rOStm, SotClipboardFormatId nFormat ) const
29 : {
30 0 : bool bRet = false;
31 0 : switch( nFormat )
32 : {
33 : case SotClipboardFormatId::INET_IMAGE:
34 : {
35 0 : OUString sString;
36 0 : (sString += aImageURL ) += OUString(TOKEN_SEPARATOR);
37 0 : (sString += aTargetURL ) += OUString(TOKEN_SEPARATOR);
38 0 : (sString += aTargetFrame ) += OUString(TOKEN_SEPARATOR);
39 0 : (sString += aAlternateText ) += OUString(TOKEN_SEPARATOR);
40 0 : sString += OUString::number( aSizePixel.Width() );
41 0 : sString += OUString(TOKEN_SEPARATOR);
42 0 : sString += OUString::number( aSizePixel.Height() );
43 :
44 : OString sOut(OUStringToOString(sString,
45 0 : RTL_TEXTENCODING_UTF8));
46 :
47 0 : rOStm.Write(sOut.getStr(), sOut.getLength());
48 : static const sal_Char aEndChar[2] = { 0 };
49 0 : rOStm.Write( aEndChar, sizeof( aEndChar ));
50 0 : bRet = 0 == rOStm.GetError();
51 : }
52 0 : break;
53 :
54 : case SotClipboardFormatId::NETSCAPE_IMAGE:
55 0 : break;
56 0 : default: break;
57 : }
58 0 : return bRet;
59 : }
60 :
61 0 : bool INetImage::Read( SvStream& rIStm, SotClipboardFormatId nFormat )
62 : {
63 0 : bool bRet = false;
64 0 : switch( nFormat )
65 : {
66 : case SotClipboardFormatId::INET_IMAGE:
67 : {
68 0 : OUString sINetImg = read_zeroTerminated_uInt8s_ToOUString(rIStm, RTL_TEXTENCODING_UTF8);
69 0 : sal_Int32 nStart = 0;
70 0 : aImageURL = sINetImg.getToken( 0, TOKEN_SEPARATOR, nStart );
71 0 : aTargetURL = sINetImg.getToken( 0, TOKEN_SEPARATOR, nStart );
72 0 : aTargetFrame = sINetImg.getToken( 0, TOKEN_SEPARATOR, nStart );
73 0 : aAlternateText = sINetImg.getToken( 0, TOKEN_SEPARATOR, nStart );
74 0 : aSizePixel.Width() = sINetImg.getToken( 0, TOKEN_SEPARATOR,
75 0 : nStart ).toInt32();
76 0 : aSizePixel.Height() = sINetImg.getToken( 0, TOKEN_SEPARATOR,
77 0 : nStart ).toInt32();
78 0 : bRet = !sINetImg.isEmpty();
79 : }
80 0 : break;
81 :
82 : case SotClipboardFormatId::NETSCAPE_IMAGE:
83 : {
84 : /*
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
98 : */
99 0 : rtl_TextEncoding eSysCSet = osl_getThreadTextEncoding();
100 : sal_Int32 nVal, nAnchorOffset, nAltOffset, nFilePos;
101 :
102 0 : nFilePos = rIStm.Tell();
103 : // skip over iSize (int), bIsMao ( sal_Bool ) alignment of 4 !!!!
104 0 : rIStm.SeekRel( 8 );
105 0 : rIStm.ReadInt32( nVal ); aSizePixel.Width() = nVal;
106 0 : rIStm.ReadInt32( nVal ); aSizePixel.Height() = nVal;
107 : // skip over iHSpace, iVSpace, iBorder, iLowResOffset
108 0 : rIStm.SeekRel( 3 * sizeof( sal_Int32 ) + sizeof( int ) );
109 0 : rIStm.ReadInt32( nAltOffset );
110 0 : rIStm.ReadInt32( nAnchorOffset );
111 : // skip over iExtraHTML_Offset
112 0 : rIStm.SeekRel( sizeof( int ) );
113 :
114 0 : aImageURL = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
115 0 : if( nAltOffset )
116 : {
117 0 : rIStm.Seek( nFilePos + nAltOffset );
118 0 : aAlternateText = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
119 : }
120 0 : else if( !aAlternateText.isEmpty() )
121 0 : aAlternateText.clear();
122 :
123 0 : if( nAnchorOffset )
124 : {
125 0 : rIStm.Seek( nFilePos + nAnchorOffset );
126 0 : aTargetURL = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
127 : }
128 0 : else if( !aTargetURL.isEmpty() )
129 0 : aTargetURL.clear();
130 :
131 0 : bRet = 0 == rIStm.GetError();
132 : }
133 0 : break;
134 0 : default: break;
135 : }
136 0 : return bRet;
137 : }
138 :
139 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|