~ubuntu-branches/ubuntu/breezy/koffice/breezy-security

« back to all changes in this revision

Viewing changes to filters/kchart/png/pngexportdia.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-10-11 14:49:50 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051011144950-lwpngbifzp8nk0ds
Tags: 1:1.4.1-0ubuntu7
* SECURITY UPDATE: fix heap based buffer overflow in the RTF importer of KWord
* Opening specially crafted RTF files in KWord can cause
  execution of abitrary code.
* Add kubuntu_01_rtfimport_heap_overflow.diff
* References:
  CAN-2005-2971
  CESA-2005-005
  http://www.koffice.org/security/advisory-20051011-1.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
#include <qcheckbox.h>
 
21
#include <qimage.h>
 
22
#include <qlabel.h>
 
23
#include <qlayout.h>
 
24
#include <qlineedit.h>
 
25
#include <qpaintdevice.h>
 
26
#include <qrect.h>
 
27
#include <qvbuttongroup.h>
 
28
#include <qwidget.h>
 
29
 
 
30
#include <kapplication.h>
 
31
#include <kdebug.h>
 
32
#include <klocale.h>
 
33
#include <kmessagebox.h>
 
34
#include <knuminput.h>
 
35
 
 
36
#include "pngexportdia.h"
 
37
 
 
38
 
 
39
PNGExportDia::PNGExportDia( int width, int height, 
 
40
                            QWidget *parent, const char *name )
 
41
    : KDialogBase( parent, name, true,
 
42
                   i18n("PNG Export Filter Parameters" ), Ok|Cancel )
 
43
{
 
44
    kapp->restoreOverrideCursor();
 
45
 
 
46
    setupGUI();
 
47
 
 
48
    m_realWidth  = width;
 
49
    m_realHeight = height;
 
50
    m_widthEdit ->setValue( m_realWidth );
 
51
    m_heightEdit->setValue( m_realHeight  );
 
52
    m_percWidthEdit->setValue( 100 );
 
53
    m_percHeightEdit->setValue( 100 );
 
54
 
 
55
    connectAll();
 
56
    connect( m_proportional, SIGNAL( clicked() ),
 
57
             this,         SLOT( proportionalClicked() ) );
 
58
}
 
59
 
 
60
 
 
61
PNGExportDia::~PNGExportDia()
 
62
{
 
63
}
 
64
 
 
65
 
 
66
void PNGExportDia::setupGUI()
 
67
{
 
68
    //resize( size() );
 
69
    QWidget *page = new QWidget( this );
 
70
    setMainWidget(page);
 
71
 
 
72
#if 0
 
73
    QBoxLayout* mainLayout = new QVBoxLayout( page, 
 
74
                                              KDialog::marginHint(), 
 
75
                                              KDialog::spacingHint() );
 
76
#else
 
77
    QGridLayout *mainLayout = new QGridLayout( page, 5, 2,
 
78
                                               KDialog::marginHint(), 
 
79
                                               KDialog::spacingHint() );
 
80
#endif
 
81
    m_proportional = new QCheckBox( page, "proportional" );
 
82
    m_proportional->setText( i18n( "Keep ratio" ) );
 
83
    m_proportional->setChecked( true );
 
84
    mainLayout->addWidget( m_proportional, 0, 0 );
 
85
 
 
86
    QLabel* width = new QLabel( page, "width" );
 
87
    width->setText( i18n( "Width:" ) );
 
88
    m_widthEdit = new KIntNumInput( page, "widthEdit" );
 
89
    QLabel* height = new QLabel( page, "height" );
 
90
    height->setText( i18n( "Height:" ) );
 
91
    m_heightEdit = new KIntNumInput( page, "heightEdit" );
 
92
 
 
93
    mainLayout->addWidget( width,      1, 0 );
 
94
    mainLayout->addWidget( m_widthEdit,  1, 1 );
 
95
    mainLayout->addWidget( height,     2, 0 );
 
96
    mainLayout->addWidget( m_heightEdit, 2, 1 );
 
97
 
 
98
    QLabel* percentWidth = new QLabel( page, "PercentWidth" );
 
99
    percentWidth->setText( i18n( "Width (%):" ) );
 
100
    m_percWidthEdit = new KDoubleNumInput( page, "percWidthEdit" );
 
101
    QLabel* percentHeight = new QLabel( page, "PercentHeight" );
 
102
    percentHeight->setText( i18n( "Height (%):" ) );
 
103
    m_percHeightEdit = new KDoubleNumInput( page, "percHeightEdit" );
 
104
 
 
105
    mainLayout->addWidget( percentWidth,   3, 0 );
 
106
    mainLayout->addWidget( m_percHeightEdit, 3, 1 );
 
107
    mainLayout->addWidget( percentHeight,  4, 0 );
 
108
    mainLayout->addWidget( m_percWidthEdit,  4, 1 );
 
109
 
 
110
    /* Display the main layout */
 
111
    //mainLayout->addStretch( 5 );
 
112
    mainLayout->activate();
 
113
}
 
114
 
 
115
 
 
116
// ----------------------------------------------------------------
 
117
//                          public methods
 
118
 
 
119
int PNGExportDia::width()
 
120
{
 
121
    return m_widthEdit->value();
 
122
}
 
123
 
 
124
 
 
125
int PNGExportDia::height()
 
126
{
 
127
    return m_heightEdit->value();
 
128
}
 
129
 
 
130
 
 
131
// ----------------------------------------------------------------
 
132
//                            slots
 
133
 
 
134
 
 
135
void PNGExportDia::widthChanged( int width )
 
136
{
 
137
    disconnectAll();
 
138
    width = QMIN( width, m_realWidth * 10 );
 
139
    width = QMAX( width, m_realWidth / 10 );
 
140
    double percent = (100.0 * static_cast<double>( width ) 
 
141
                      / static_cast<double>( m_realWidth ));
 
142
    m_percWidthEdit->setValue(  percent  );
 
143
    if ( m_proportional->isChecked() ) {
 
144
        m_percHeightEdit->setValue( percent );
 
145
        int height = static_cast<int>( m_realHeight * percent / 100.0 );
 
146
        m_heightEdit->setValue(  height );
 
147
    }
 
148
    connectAll();
 
149
}
 
150
 
 
151
 
 
152
void PNGExportDia::heightChanged( int height )
 
153
{
 
154
    disconnectAll();
 
155
    height = QMIN( height, m_realHeight * 10 );
 
156
    height = QMAX( height, m_realHeight / 10 );
 
157
    double percent = (100.0 * static_cast<double>( height )
 
158
                      / static_cast<double>( m_realHeight ));
 
159
    m_percHeightEdit->setValue( percent  );
 
160
    if ( m_proportional->isChecked() ) {
 
161
        m_percWidthEdit->setValue(  percent  );
 
162
        int width = static_cast<int>( m_realWidth * percent / 100.0 );
 
163
        m_widthEdit->setValue( width );
 
164
    }
 
165
    connectAll();
 
166
}
 
167
 
 
168
 
 
169
void PNGExportDia::percentWidthChanged( double percent )
 
170
{
 
171
    disconnectAll();
 
172
    percent = QMIN( percent, 1000 );
 
173
    percent = QMAX( percent, 10 );
 
174
    int width = static_cast<int>( m_realWidth * percent / 100. );
 
175
    m_widthEdit->setValue(  width  );
 
176
    if ( m_proportional->isChecked() ) {
 
177
        int height = static_cast<int>( m_realHeight * percent / 100. );
 
178
        m_heightEdit->setValue(  height  );
 
179
        m_percHeightEdit->setValue(  percent );
 
180
    }
 
181
    connectAll();
 
182
}
 
183
 
 
184
 
 
185
void PNGExportDia::percentHeightChanged( double percent )
 
186
{
 
187
    disconnectAll();
 
188
    percent = QMIN( percent, 1000 );
 
189
    percent = QMAX( percent, 10 );
 
190
    if ( m_proportional->isChecked() ) {
 
191
        int width = static_cast<int>( m_realWidth * percent / 100. );
 
192
        m_widthEdit->setValue(  width  );
 
193
        m_percWidthEdit->setValue(  percent  );
 
194
    }
 
195
    int height = static_cast<int>( m_realHeight * percent / 100. );
 
196
    m_heightEdit->setValue(  height  );
 
197
    connectAll();
 
198
}
 
199
 
 
200
 
 
201
void PNGExportDia::proportionalClicked()
 
202
{
 
203
    if ( m_proportional->isChecked() ) {
 
204
        disconnectAll();
 
205
        int width = m_widthEdit->value( );
 
206
        width = QMIN( width, m_realWidth * 10 );
 
207
        width = QMAX( width, m_realWidth / 10 );
 
208
        double percent = (100.0 * static_cast<double>( width )
 
209
                          / static_cast<double>( m_realWidth ));
 
210
        m_percHeightEdit->setValue(  percent  );
 
211
        int height = static_cast<int>( m_realHeight * percent / 100. );
 
212
        m_heightEdit->setValue(  height  );
 
213
        connectAll();
 
214
    }
 
215
}
 
216
 
 
217
 
 
218
// ----------------------------------------------------------------
 
219
//                          private methods
 
220
 
 
221
 
 
222
void PNGExportDia::connectAll()
 
223
{
 
224
    connect( m_widthEdit,      SIGNAL( valueChanged(int) ),
 
225
             this,             SLOT( widthChanged( int ) ) );
 
226
    connect( m_heightEdit,     SIGNAL( valueChanged(int) ),
 
227
             this,             SLOT( heightChanged( int ) ) );
 
228
    connect( m_percWidthEdit,  SIGNAL( valueChanged(double) ),
 
229
             this,             SLOT( percentWidthChanged( double ) ) );
 
230
    connect( m_percHeightEdit, SIGNAL( valueChanged(double) ),
 
231
             this,             SLOT( percentHeightChanged(double ) ) );
 
232
}
 
233
 
 
234
 
 
235
void PNGExportDia::disconnectAll()
 
236
{
 
237
    disconnect( m_widthEdit,      SIGNAL( valueChanged(int) ),
 
238
                this,             SLOT( widthChanged( int ) ) );
 
239
    disconnect( m_heightEdit,     SIGNAL( valueChanged(int) ),
 
240
                this,             SLOT( heightChanged( int ) ) );
 
241
    disconnect( m_percWidthEdit,  SIGNAL( valueChanged(double) ),
 
242
                this,             SLOT( percentWidthChanged( double ) ) );
 
243
    disconnect( m_percHeightEdit, SIGNAL( valueChanged(double) ),
 
244
                this,             SLOT( percentHeightChanged(double ) ) );
 
245
}
 
246
 
 
247
 
 
248
#if 0
 
249
void PNGExportDia::slotOk()
 
250
{
 
251
    hide();
 
252
    //doc->setZoomAndResolution( 100, 600, 600 );
 
253
    //doc->setZoomAndResolution( 1000, QPaintDevice::x11AppDpiX(), QPaintDevice::x11AppDpiY() );
 
254
    //doc->newZoomAndResolution( false, false );
 
255
    int width = widthEdit->value();
 
256
    int height = heightEdit->value();
 
257
//     kdDebug( KFormula::DEBUGID ) << k_funcinfo
 
258
//                                  << "(" << width << " " << height << ")"
 
259
//                                  << endl;
 
260
//     width = realWidth;
 
261
//     height = realHeight;
 
262
    QImage image = formula->drawImage( width, height );
 
263
    if ( !image.save( _fileOut, "PNG" ) ) {
 
264
        KMessageBox::error( 0, i18n( "Failed to write file." ), i18n( "PNG Export Error" ) );
 
265
    }
 
266
    reject();
 
267
}
 
268
#endif
 
269
 
 
270
#include "pngexportdia.moc"