Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/vcl/source/treelist/inetimg.cxx
Line
Count
Source (jump to first uncovered line)
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
27
const sal_Unicode TOKEN_SEPARATOR = '\001';
28
29
void INetImage::Write( SvStream& rOStm, SotClipboardFormatId nFormat ) const
30
0
{
31
0
    switch( nFormat )
32
0
    {
33
0
    case SotClipboardFormatId::INET_IMAGE:
34
0
        {
35
0
            OUString sString(
36
0
                aImageURL + OUStringChar(TOKEN_SEPARATOR) + aTargetURL
37
0
                + OUStringChar(TOKEN_SEPARATOR) + aTargetFrame
38
0
                + OUStringChar(TOKEN_SEPARATOR) /* + aAlternateText */
39
0
                + OUStringChar(TOKEN_SEPARATOR)
40
0
                + OUString::number(aSizePixel.Width())
41
0
                + OUStringChar(TOKEN_SEPARATOR)
42
0
                + OUString::number(aSizePixel.Height()));
43
44
0
            OString sOut(OUStringToOString(sString,
45
0
                RTL_TEXTENCODING_UTF8));
46
47
0
            rOStm.WriteBytes(sOut.getStr(), sOut.getLength());
48
0
            static const char aEndChar[2] = { 0 };
49
0
            rOStm.WriteBytes(aEndChar, sizeof(aEndChar));
50
0
        }
51
0
        break;
52
53
0
    case SotClipboardFormatId::NETSCAPE_IMAGE:
54
0
        break;
55
0
    default: break;
56
0
    }
57
0
}
58
59
bool INetImage::Read( SvStream& rIStm, SotClipboardFormatId nFormat )
60
0
{
61
0
    bool bRet = false;
62
0
    switch( nFormat )
63
0
    {
64
0
    case SotClipboardFormatId::INET_IMAGE:
65
0
        {
66
0
            OUString sINetImg = read_zeroTerminated_uInt8s_ToOUString(rIStm, RTL_TEXTENCODING_UTF8);
67
0
            sal_Int32 nStart = 0;
68
0
            aImageURL = sINetImg.getToken( 0, TOKEN_SEPARATOR, nStart );
69
0
            aTargetURL = sINetImg.getToken( 0, TOKEN_SEPARATOR, nStart );
70
0
            aTargetFrame = sINetImg.getToken( 0, TOKEN_SEPARATOR, nStart );
71
0
            /*aAlternateText =*/ sINetImg.getToken( 0, TOKEN_SEPARATOR, nStart );
72
0
            aSizePixel.setWidth( o3tl::toInt32(o3tl::getToken(sINetImg, 0, TOKEN_SEPARATOR,
73
0
                                                    nStart )) );
74
0
            aSizePixel.setHeight(o3tl::toInt32(o3tl::getToken( sINetImg, 0, TOKEN_SEPARATOR,
75
0
                                                    nStart )) );
76
0
            bRet = !sINetImg.isEmpty();
77
0
        }
78
0
        break;
79
80
0
    case SotClipboardFormatId::NETSCAPE_IMAGE:
81
0
        {
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
0
            rtl_TextEncoding eSysCSet = osl_getThreadTextEncoding();
98
0
            sal_Int32 nVal, nAnchorOffset, nAltOffset;
99
0
            sal_uInt64 nFilePos;
100
101
0
            nFilePos = rIStm.Tell();
102
            // skip over iSize (int), bIsMao ( sal_Bool ) alignment of 4 !!!!
103
0
            rIStm.SeekRel( 8 );
104
0
            rIStm.ReadInt32( nVal );  aSizePixel.setWidth( nVal );
105
0
            rIStm.ReadInt32( nVal );  aSizePixel.setHeight( nVal );
106
            // skip over iHSpace, iVSpace, iBorder, iLowResOffset
107
0
            rIStm.SeekRel( 3 * sizeof( sal_Int32 ) + sizeof( int ) );
108
0
            rIStm.ReadInt32( nAltOffset );
109
0
            rIStm.ReadInt32( nAnchorOffset );
110
            // skip over iExtraHTML_Offset
111
0
            rIStm.SeekRel( sizeof( int ) );
112
113
0
            aImageURL = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
114
0
            if( nAltOffset )
115
0
            {
116
0
                rIStm.Seek( nFilePos + nAltOffset );
117
0
                /*aAlternateText =*/ read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
118
0
            }
119
120
0
            if( nAnchorOffset )
121
0
            {
122
0
                rIStm.Seek( nFilePos + nAnchorOffset );
123
0
                aTargetURL = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
124
0
            }
125
0
            else if( !aTargetURL.isEmpty() )
126
0
                aTargetURL.clear();
127
128
0
            bRet = ERRCODE_NONE == rIStm.GetError();
129
0
        }
130
0
        break;
131
0
    default: break;
132
0
    }
133
0
    return bRet;
134
0
}
135
136
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */