LibreOffice Module lotuswordpro (master) 1
xfbgimage.cxx
Go to the documentation of this file.
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>
62#include <xfilter/xfutil.hxx>
63#include "xfbase64.hxx"
64
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
74void XFBGImage::SetImageData(sal_uInt8 const *buf, int len)
75{
76 m_strData = XFBase64::Encode(buf,len);
77 m_bUserFileLink = false;
78}
79
80bool XFBGImage::Equal(IXFStyle * /* pStyle */)
81{
82 return false;
83}
84
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) + " ";
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
129bool 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
157bool operator!=(XFBGImage const & img1, XFBGImage const & img2)
158{
159 return !(img1==img2);
160}
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Attribute list interface for sax writer.
Definition: ixfattrlist.hxx:72
virtual void Clear()=0
@descr: Clear all the attributes in the attribute list.
virtual void AddAttribute(const OUString &name, const OUString &value)=0
@descr: Add an attribute to the attribute list.
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
virtual void Characters(const OUString &oustr)=0
@descr output text node.
virtual IXFAttrList * GetAttrList()=0
@descr return the Attribute list interface.
virtual void StartElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::startElement()
virtual void EndElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::endElement()
@descr Interface for all style object.
Definition: ixfstyle.hxx:71
Background image object.
Definition: xfbgimage.hxx:70
OUString m_strFileName
Definition: xfbgimage.hxx:113
bool m_bRepeate
Definition: xfbgimage.hxx:116
virtual void ToXml(IXFStream *pStrm) override
Definition: xfbgimage.cxx:85
virtual bool Equal(IXFStyle *pStyle) override
@descr decide whether there has been a style that is the same as this object.
Definition: xfbgimage.cxx:80
bool m_bPosition
Definition: xfbgimage.hxx:118
bool m_bStretch
Definition: xfbgimage.hxx:117
OUString m_strData
Definition: xfbgimage.hxx:114
enumXFAlignType m_eVertAlign
Definition: xfbgimage.hxx:120
enumXFAlignType m_eHoriAlign
Definition: xfbgimage.hxx:119
void SetImageData(sal_uInt8 const *buf, int len)
@descr Use base64 stream as image source.
Definition: xfbgimage.cxx:74
bool m_bUserFileLink
Definition: xfbgimage.hxx:115
static OUString Encode(sal_uInt8 const *buf, sal_Int32 len)
@descr Encode binary buffer to base64 encoding.
Definition: xfbase64.cxx:97
unsigned char sal_uInt8
bool operator==(XFBGImage const &img1, XFBGImage const &img2)
Definition: xfbgimage.cxx:129
bool operator!=(XFBGImage const &img1, XFBGImage const &img2)
Definition: xfbgimage.cxx:157
@ enumXFAlignStart
Definition: xfdefs.hxx:174
@ enumXFAlignEnd
Definition: xfdefs.hxx:176
@ enumXFAlignCenter
Definition: xfdefs.hxx:175
OUString GetAlignName(enumXFAlignType align)
Definition: xfutil.cxx:296