1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
57 * For LWP filter architecture prototype
58 * Implemention of class LwpBackgroundStuff.
61 #include "lwpbackgroundstuff.hxx"
62 #include "lwppttntbl.hxx"
63 #include "xfilter/xfbgimage.hxx"
65 #include "tools/stream.hxx"
66 #include "vcl/bmpacc.hxx"
67 #include "svx/xbitmap.hxx"
70 void LwpBackgroundStuff::Read(LwpObjectStream
* pStrm
)
72 pStrm
->QuickRead(&m_nID
, sizeof(m_nID
));
73 m_aFillColor
.Read(pStrm
);
74 m_aPatternColor
.Read(pStrm
);
78 void LwpBackgroundStuff::GetPattern(sal_uInt16 btPttnIndex
, sal_uInt8
* pPttnArray
)
87 assert((2 < btPttnIndex
) && (btPttnIndex
< 72));
88 sal_uInt8
* pTempArray
= s_pLwpPatternTab
[btPttnIndex
];
89 for(sal_uInt8 i
= 0; i
< 32; i
++)
91 pPttnArray
[i
] = (i
%4 == 0) ? pTempArray
[7-i
/4] : 0;
96 LwpColor
* LwpBackgroundStuff::GetFillColor()
98 if (m_nID
== BACK_PATTERN
)
100 return &m_aPatternColor
;
103 return &m_aFillColor
;
106 XFBGImage
* LwpBackgroundStuff::GetFillPattern()
109 if (!this->IsPatternFill())
114 // get pattern array from pattern table
115 sal_uInt8
* pPttnArray
= new sal_uInt8
[32];
116 this->GetPattern(m_nID
, pPttnArray
);
118 // create bitmap object from the pattern array
119 Bitmap
aBmp( Size(8, 8), 1 );
120 BitmapWriteAccess
* pWA
= aBmp
.AcquireWriteAccess();
121 sal_uInt8
* pBuf
= pWA
->GetBuffer();
122 memcpy(pBuf
, pPttnArray
, 32);
123 aBmp
.ReleaseAccess(pWA
);
127 delete [] pPttnArray
;
131 // create XOBitmap object from bitmap object
133 aXOBitmap
.SetBitmap( aBmp
);
134 aXOBitmap
.Bitmap2Array();
135 aXOBitmap
.SetBitmapType( XBITMAP_8X8
);
137 // set back/fore-ground colors
138 if (m_aFillColor
.IsValidColor() && m_aPatternColor
.IsValidColor())
140 Color
aBackColor(static_cast<sal_uInt8
>(m_aFillColor
.GetRed()),
141 static_cast<sal_uInt8
>(m_aFillColor
.GetGreen()),
142 static_cast<sal_uInt8
>(m_aFillColor
.GetBlue()));
143 Color
aForeColor(static_cast<sal_uInt8
>(m_aPatternColor
.GetRed()),
144 static_cast<sal_uInt8
>(m_aPatternColor
.GetGreen()),
145 static_cast<sal_uInt8
>(m_aPatternColor
.GetBlue()));
147 if( aXOBitmap
.GetBackgroundColor() == COL_BLACK
)
149 aXOBitmap
.SetPixelColor( aBackColor
);
150 aXOBitmap
.SetBackgroundColor( aForeColor
);
154 aXOBitmap
.SetPixelColor( aForeColor
);
155 aXOBitmap
.SetBackgroundColor( aBackColor
);
159 // transfer image data from XOBitmap->SvStream->BYTE-Array
160 SvMemoryStream aPicMemStream
;
161 aXOBitmap
.Array2Bitmap();
162 aXOBitmap
.GetBitmap().Write(aPicMemStream
);
163 sal_uInt32 nSize
= aPicMemStream
.GetSize();
164 sal_uInt8
* pImageBuff
= new sal_uInt8
[nSize
];
165 memcpy(pImageBuff
, aPicMemStream
.GetData(), nSize
);
167 // create XFBGImage object.
168 XFBGImage
* pXFBGImage
= new XFBGImage();
169 pXFBGImage
->SetImageData(pImageBuff
, nSize
);
173 delete [] pImageBuff
;
178 pXFBGImage
->SetRepeate();