Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sot/formats.hxx>
30 : : #include <tools/stream.hxx>
31 : :
32 : : #include <svtools/inetimg.hxx>
33 : :
34 : : #define TOKEN_SEPARATOR '\001'
35 : :
36 : 0 : sal_Bool INetImage::Write( SvStream& rOStm, sal_uLong nFormat ) const
37 : : {
38 : 0 : sal_Bool bRet = sal_False;
39 [ # # # ]: 0 : switch( nFormat )
40 : : {
41 : : case SOT_FORMATSTR_ID_INET_IMAGE:
42 : : {
43 [ # # ]: 0 : String sString;
44 [ # # ][ # # ]: 0 : (sString += aImageURL ) += TOKEN_SEPARATOR;
45 [ # # ][ # # ]: 0 : (sString += aTargetURL ) += TOKEN_SEPARATOR;
46 [ # # ][ # # ]: 0 : (sString += aTargetFrame ) += TOKEN_SEPARATOR;
47 [ # # ][ # # ]: 0 : (sString += aAlternateText ) += TOKEN_SEPARATOR;
48 [ # # ][ # # ]: 0 : sString += String::CreateFromInt32( aSizePixel.Width() );
[ # # ]
49 [ # # ]: 0 : sString += TOKEN_SEPARATOR;
50 [ # # ][ # # ]: 0 : sString += String::CreateFromInt32( aSizePixel.Height() );
[ # # ]
51 : :
52 : : rtl::OString sOut(rtl::OUStringToOString(sString,
53 [ # # ][ # # ]: 0 : RTL_TEXTENCODING_UTF8));
54 : :
55 [ # # ]: 0 : rOStm.Write(sOut.getStr(), sOut.getLength());
56 : : static const sal_Char aEndChar[2] = { 0 };
57 [ # # ]: 0 : rOStm.Write( aEndChar, sizeof( aEndChar ));
58 [ # # ]: 0 : bRet = 0 == rOStm.GetError();
59 : : }
60 : 0 : break;
61 : :
62 : : case SOT_FORMATSTR_ID_NETSCAPE_IMAGE:
63 : 0 : break;
64 : : }
65 : 0 : return bRet;
66 : : }
67 : :
68 : 0 : sal_Bool INetImage::Read( SvStream& rIStm, sal_uLong nFormat )
69 : : {
70 : 0 : sal_Bool bRet = sal_False;
71 [ # # # ]: 0 : switch( nFormat )
72 : : {
73 : : case SOT_FORMATSTR_ID_INET_IMAGE:
74 : : {
75 [ # # ][ # # ]: 0 : String sINetImg = read_zeroTerminated_uInt8s_ToOUString(rIStm, RTL_TEXTENCODING_UTF8);
76 : 0 : xub_StrLen nStart = 0;
77 [ # # ][ # # ]: 0 : aImageURL = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
[ # # ]
78 [ # # ][ # # ]: 0 : aTargetURL = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
[ # # ]
79 [ # # ][ # # ]: 0 : aTargetFrame = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
[ # # ]
80 [ # # ][ # # ]: 0 : aAlternateText = sINetImg.GetToken( 0, TOKEN_SEPARATOR, nStart );
[ # # ]
81 : 0 : aSizePixel.Width() = sINetImg.GetToken( 0, TOKEN_SEPARATOR,
82 [ # # ][ # # ]: 0 : nStart ).ToInt32();
[ # # ]
83 : 0 : aSizePixel.Height() = sINetImg.GetToken( 0, TOKEN_SEPARATOR,
84 [ # # ][ # # ]: 0 : nStart ).ToInt32();
[ # # ]
85 [ # # ]: 0 : bRet = 0 != sINetImg.Len();
86 : : }
87 : 0 : break;
88 : :
89 : : case SOT_FORMATSTR_ID_NETSCAPE_IMAGE:
90 : : {
91 : : /*
92 : : --> structure size MUST - alignment of 4!
93 : : int iSize; // size of all data, including variable length strings
94 : : sal_Bool bIsMap; // For server side maps
95 : : sal_Int32 iWidth; // Fixed size data correspond to fields in LO_ImageDataStruct
96 : : sal_Int32 iHeight; // and EDT_ImageData
97 : : sal_Int32 iHSpace;
98 : : sal_Int32 iVSpace;
99 : : sal_Int32 iBorder;
100 : : int iLowResOffset; // Offsets into string_data. If 0, string is NULL (not used)
101 : : int iAltOffset; // (alternate text?)
102 : : int iAnchorOffset; // HREF in image
103 : : int iExtraHTML_Offset; // Extra HTML (stored in CImageElement)
104 : : sal_Char pImageURL[1]; // Append all variable-length strings starting here
105 : : */
106 [ # # ]: 0 : rtl_TextEncoding eSysCSet = osl_getThreadTextEncoding();
107 : : sal_Int32 nVal, nAnchorOffset, nAltOffset, nFilePos;
108 : :
109 : 0 : nFilePos = rIStm.Tell();
110 : : // skip over iSize (int), bIsMao ( sal_Bool ) alignment of 4 !!!!
111 [ # # ]: 0 : rIStm.SeekRel( 8 );
112 [ # # ]: 0 : rIStm >> nVal; aSizePixel.Width() = nVal;
113 [ # # ]: 0 : rIStm >> nVal; aSizePixel.Height() = nVal;
114 : : // skip over iHSpace, iVSpace, iBorder, iLowResOffset
115 [ # # ]: 0 : rIStm.SeekRel( 3 * sizeof( sal_Int32 ) + sizeof( int ) );
116 [ # # ]: 0 : rIStm >> nAltOffset;
117 [ # # ]: 0 : rIStm >> nAnchorOffset;
118 : : // skip over iExtraHTML_Offset
119 [ # # ]: 0 : rIStm.SeekRel( sizeof( int ) );
120 : :
121 [ # # ][ # # ]: 0 : aImageURL = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
122 [ # # ]: 0 : if( nAltOffset )
123 : : {
124 [ # # ]: 0 : rIStm.Seek( nFilePos + nAltOffset );
125 [ # # ][ # # ]: 0 : aAlternateText = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
126 : : }
127 [ # # ]: 0 : else if( aAlternateText.Len() )
128 [ # # ]: 0 : aAlternateText.Erase();
129 : :
130 [ # # ]: 0 : if( nAnchorOffset )
131 : : {
132 [ # # ]: 0 : rIStm.Seek( nFilePos + nAnchorOffset );
133 [ # # ][ # # ]: 0 : aTargetURL = read_zeroTerminated_uInt8s_ToOUString(rIStm, eSysCSet);
134 : : }
135 [ # # ]: 0 : else if( aTargetURL.Len() )
136 [ # # ]: 0 : aTargetURL.Erase();
137 : :
138 : 0 : bRet = 0 == rIStm.GetError();
139 : : }
140 : 0 : break;
141 : : }
142 : 0 : return bRet;
143 : : }
144 : :
145 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|