LibreOffice Module vcl (master) 1
inetimg.cxx
Go to the documentation of this file.
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 <vcl/inetimg.hxx>
25#include <o3tl/string_view.hxx>
26
28
29void INetImage::Write( SvStream& rOStm, SotClipboardFormatId nFormat ) const
30{
31 switch( nFormat )
32 {
33 case SotClipboardFormatId::INET_IMAGE:
34 {
35 OUString sString(
36 aImageURL + OUStringChar(TOKEN_SEPARATOR) + aTargetURL
37 + OUStringChar(TOKEN_SEPARATOR) + aTargetFrame
38 + OUStringChar(TOKEN_SEPARATOR) /* + aAlternateText */
39 + OUStringChar(TOKEN_SEPARATOR)
40 + OUString::number(aSizePixel.Width())
41 + OUStringChar(TOKEN_SEPARATOR)
42 + OUString::number(aSizePixel.Height()));
43
44 OString sOut(OUStringToOString(sString,
45 RTL_TEXTENCODING_UTF8));
46
47 rOStm.WriteBytes(sOut.getStr(), sOut.getLength());
48 static const char aEndChar[2] = { 0 };
49 rOStm.WriteBytes(aEndChar, sizeof(aEndChar));
50 }
51 break;
52
53 case SotClipboardFormatId::NETSCAPE_IMAGE:
54 break;
55 default: break;
56 }
57}
58
60{
61 bool bRet = false;
62 switch( nFormat )
63 {
64 case SotClipboardFormatId::INET_IMAGE:
65 {
66 OUString sINetImg = read_zeroTerminated_uInt8s_ToOUString(rIStm, RTL_TEXTENCODING_UTF8);
67 sal_Int32 nStart = 0;
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 );
73 nStart )) );
75 nStart )) );
76 bRet = !sINetImg.isEmpty();
77 }
78 break;
79
80 case SotClipboardFormatId::NETSCAPE_IMAGE:
81 {
82/*
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
88 sal_Int32 iHSpace;
89 sal_Int32 iVSpace;
90 sal_Int32 iBorder;
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 char pImageURL[1]; // Append all variable-length strings starting here
96*/
97 rtl_TextEncoding eSysCSet = osl_getThreadTextEncoding();
98 sal_Int32 nVal, nAnchorOffset, nAltOffset;
99 sal_uInt64 nFilePos;
100
101 nFilePos = rIStm.Tell();
102 // skip over iSize (int), bIsMao ( sal_Bool ) alignment of 4 !!!!
103 rIStm.SeekRel( 8 );
104 rIStm.ReadInt32( nVal ); aSizePixel.setWidth( nVal );
105 rIStm.ReadInt32( nVal ); aSizePixel.setHeight( nVal );
106 // skip over iHSpace, iVSpace, iBorder, iLowResOffset
107 rIStm.SeekRel( 3 * sizeof( sal_Int32 ) + sizeof( int ) );
108 rIStm.ReadInt32( nAltOffset );
109 rIStm.ReadInt32( nAnchorOffset );
110 // skip over iExtraHTML_Offset
111 rIStm.SeekRel( sizeof( int ) );
112
114 if( nAltOffset )
115 {
116 rIStm.Seek( nFilePos + nAltOffset );
117 /*aAlternateText =*/ read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
118 }
119
120 if( nAnchorOffset )
121 {
122 rIStm.Seek( nFilePos + nAnchorOffset );
124 }
125 else if( !aTargetURL.isEmpty() )
126 aTargetURL.clear();
127
128 bRet = ERRCODE_NONE == rIStm.GetError();
129 }
130 break;
131 default: break;
132 }
133 return bRet;
134}
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString aTargetURL
Definition: inetimg.hxx:31
OUString aTargetFrame
Definition: inetimg.hxx:32
bool Read(SvStream &rIStm, SotClipboardFormatId nFormat)
Definition: inetimg.cxx:59
OUString aImageURL
Definition: inetimg.hxx:30
void Write(SvStream &rOStm, SotClipboardFormatId nFormat) const
Definition: inetimg.cxx:29
Size aSizePixel
Definition: inetimg.hxx:33
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
sal_uInt64 Tell() const
std::size_t WriteBytes(const void *pData, std::size_t nSize)
sal_uInt64 Seek(sal_uInt64 nPos)
SvStream & ReadInt32(sal_Int32 &rInt32)
sal_uInt64 SeekRel(sal_Int64 nPos)
ErrCode GetError() const
#define ERRCODE_NONE
SotClipboardFormatId
const sal_Unicode TOKEN_SEPARATOR
Definition: inetimg.cxx:27
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
TOOLS_DLLPUBLIC OUString read_zeroTerminated_uInt8s_ToOUString(SvStream &rStrm, rtl_TextEncoding eEnc)
sal_uInt16 sal_Unicode