1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 *
31 *
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
38 *
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56 /*************************************************************************
57 * @file
58 * Background image.
59 ************************************************************************/
60 #include <xfilter/xfbgimage.hxx>
61 #include <xfilter/ixfattrlist.hxx>
62 #include <xfilter/xfutil.hxx>
63 #include "xfbase64.hxx"
64
XFBGImage()65 XFBGImage::XFBGImage()
66 : m_bUserFileLink(false)
67 , m_bRepeate(false)
68 , m_bStretch(false)
69 , m_bPosition(true)
70 , m_eHoriAlign(enumXFAlignCenter)
71 , m_eVertAlign(enumXFAlignCenter)
72 {}
73
SetImageData(sal_uInt8 const * buf,int len)74 void XFBGImage::SetImageData(sal_uInt8 const *buf, int len)
75 {
76 m_strData = XFBase64::Encode(buf,len);
77 m_bUserFileLink = false;
78 }
79
Equal(IXFStyle *)80 bool XFBGImage::Equal(IXFStyle * /* pStyle */)
81 {
82 return false;
83 }
84
ToXml(IXFStream * pStrm)85 void XFBGImage::ToXml(IXFStream *pStrm)
86 {
87 IXFAttrList *pAttrList = pStrm->GetAttrList();
88 pAttrList->Clear();
89
90 if( m_bUserFileLink )
91 {
92 pAttrList->AddAttribute( "xlink:href", m_strFileName);
93 }
94
95 pAttrList->AddAttribute( "xlink:type", "simple" );
96 pAttrList->AddAttribute( "xlink:actuate", "onLoad");
97
98 if( m_bPosition )
99 {
100 OUString str = GetAlignName(m_eVertAlign) + " ";
101 if( m_eHoriAlign == enumXFAlignStart )
102 str += "left";
103 else if( m_eHoriAlign == enumXFAlignCenter )
104 str += "center";
105 else if( m_eHoriAlign == enumXFAlignEnd )
106 str += "right";
107
108 pAttrList->AddAttribute( "style:position", str );
109 pAttrList->AddAttribute( "style:repeat", "no-repeat" );
110 }
111 else if( m_bRepeate )
112 pAttrList->AddAttribute( "style:repeat", "repeat" );
113 else if( m_bStretch )
114 pAttrList->AddAttribute( "style:repeat", "stretch" );
115
116 pStrm->StartElement( "style:background-image" );
117
118 if( !m_bUserFileLink )
119 {
120 pAttrList->Clear();
121 pStrm->StartElement( "office:binary-data" );
122 pStrm->Characters(m_strData);
123 pStrm->EndElement( "office:binary-data" );
124 }
125
126 pStrm->EndElement( "style:background-image" );
127 }
128
operator ==(XFBGImage const & img1,XFBGImage const & img2)129 bool operator==(XFBGImage const & img1, XFBGImage const & img2)
130 {
131 if( img1.m_bUserFileLink != img2.m_bUserFileLink )
132 return false;
133 if( img1.m_bUserFileLink )
134 {
135 if( img1.m_strFileName != img2.m_strFileName )
136 return false;
137 }
138 else
139 {
140 //I'll not compare the content of the two buffer,it's time consuming.
141 return false;
142 }
143 if( img1.m_bPosition != img2.m_bPosition )
144 return false;
145 if( img1.m_bRepeate != img2.m_bRepeate )
146 return false;
147 if( img1.m_bStretch != img2.m_bStretch )
148 return false;
149 if( img1.m_bPosition )
150 {
151 if( (img1.m_eHoriAlign != img2.m_eHoriAlign) || (img1.m_eVertAlign != img2.m_eVertAlign) )
152 return false;
153 }
154 return true;
155 }
156
operator !=(XFBGImage const & img1,XFBGImage const & img2)157 bool operator!=(XFBGImage const & img1, XFBGImage const & img2)
158 {
159 return !(img1==img2);
160 }
161
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
163