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

« back to all changes in this revision

Viewing changes to krita/core/tool/kis_tool_freehand.cc

  • 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
/*
 
2
 *  kis_tool_brush.cc - part of Krita
 
3
 *
 
4
 *  Copyright (c) 2003-2004 Boudewijn Rempt <boud@valdyas.org>
 
5
 *  Copyright (c) 2004 Bart Coppens <kde@bartcoppens.be>
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
20
 */
 
21
#include <qevent.h>
 
22
#include <qlabel.h>
 
23
#include <qlayout.h>
 
24
#include <qwidget.h>
 
25
#include <qrect.h>
 
26
 
 
27
#include <kdebug.h>
 
28
#include <kaction.h>
 
29
#include <kcommand.h>
 
30
#include <klocale.h>
 
31
 
 
32
#include "kis_painter.h"
 
33
#include "kis_fill_painter.h"
 
34
#include "kis_tool_freehand.h"
 
35
#include "kis_cursor.h"
 
36
#include "kis_doc.h"
 
37
#include "kis_view.h"
 
38
#include "kis_button_press_event.h"
 
39
#include "kis_button_release_event.h"
 
40
#include "kis_move_event.h"
 
41
 
 
42
KisToolFreehand::KisToolFreehand(QString transactionText)
 
43
                : super(transactionText),
 
44
                m_dragDist ( 0 ),
 
45
                m_transactionText(transactionText),
 
46
                m_mode( HOVER )
 
47
{
 
48
        m_painter = 0;
 
49
        m_currentImage = 0;
 
50
 
 
51
        m_useTempLayer = false;
 
52
}
 
53
 
 
54
KisToolFreehand::~KisToolFreehand()
 
55
{
 
56
}
 
57
 
 
58
void KisToolFreehand::update(KisCanvasSubject *subject)
 
59
{
 
60
        super::update(subject);
 
61
        m_currentImage = m_subject -> currentImg();
 
62
}
 
63
 
 
64
void KisToolFreehand::buttonPress(KisButtonPressEvent *e)
 
65
{
 
66
        if (!m_subject) return;
 
67
 
 
68
        if (!m_subject -> currentBrush()) return;
 
69
 
 
70
        if (!m_currentImage || !m_currentImage -> activeDevice()) return;
 
71
 
 
72
        if (e -> button() == QMouseEvent::LeftButton) {
 
73
 
 
74
                initPaint(e);
 
75
 
 
76
                paintAt(e -> pos(), e -> pressure(), e -> xTilt(), e -> yTilt());
 
77
 
 
78
                m_prevPos = e -> pos();
 
79
                m_prevPressure = e -> pressure();
 
80
                m_prevXTilt = e -> xTilt();
 
81
                m_prevYTilt = e -> yTilt();
 
82
 
 
83
                QRect r = m_painter -> dirtyRect();
 
84
                if ( r.isValid() ) {
 
85
                        m_dirtyRect = r;
 
86
                        m_currentImage -> notify(r);
 
87
                }
 
88
         }
 
89
}
 
90
 
 
91
void KisToolFreehand::buttonRelease(KisButtonReleaseEvent* e)
 
92
{
 
93
        if (e -> button() == QMouseEvent::LeftButton && m_mode == PAINT) {
 
94
                endPaint();
 
95
        }
 
96
}
 
97
 
 
98
void KisToolFreehand::move(KisMoveEvent *e)
 
99
{
 
100
        if (m_mode == PAINT) {
 
101
                paintLine(m_prevPos, m_prevPressure, m_prevXTilt, m_prevYTilt, e -> pos(), e -> pressure(), e -> xTilt(), e -> yTilt());
 
102
 
 
103
                m_prevPos = e -> pos();
 
104
                m_prevPressure = e -> pressure();
 
105
                m_prevXTilt = e -> xTilt();
 
106
                m_prevYTilt = e -> yTilt();
 
107
 
 
108
                QRect r = m_painter -> dirtyRect();
 
109
                m_dirtyRect |= r;
 
110
                m_currentImage -> notify(r);
 
111
        }
 
112
}
 
113
 
 
114
void KisToolFreehand::initPaint(KisEvent *)
 
115
{
 
116
        if (!m_currentImage || !m_currentImage -> activeDevice()) return;
 
117
 
 
118
        m_mode = PAINT;
 
119
        m_dragDist = 0;
 
120
 
 
121
        // Create painter
 
122
        KisPaintDeviceSP device;
 
123
        if (m_currentImage && (device = m_currentImage -> activeDevice())) {
 
124
                if (m_painter)
 
125
                        delete m_painter;
 
126
                if (m_useTempLayer) {
 
127
                        if (m_currentImage -> undoAdapter())
 
128
                                m_currentImage -> undoAdapter() -> beginMacro(m_transactionText);
 
129
 
 
130
                        // XXX ugly! hacky!
 
131
                        m_target = dynamic_cast<KisDoc*>(m_subject->document())->layerAdd(currentImage(), "temp", OPACITY_OPAQUE);
 
132
 
 
133
                        m_target -> setCompositeOp(m_compositeOp);
 
134
 
 
135
                        if (device -> hasSelection()) {
 
136
                                m_target -> addSelection(device -> selection());
 
137
                                m_target -> selection() -> setMaskColor( device -> selection() -> maskColor() );
 
138
                        }
 
139
 
 
140
                        dynamic_cast<KisLayer*>(m_target.data()) -> setVisible(true);
 
141
 
 
142
                        // XXX doesn't look very good I'm afraid
 
143
                        currentImage() -> add(dynamic_cast<KisLayer*>(m_target.data()),
 
144
                                currentImage() -> index(dynamic_cast<KisLayer*>(device.data())) + 1);
 
145
                        m_target = currentImage() -> activate(dynamic_cast<KisLayer*>(m_target.data()));
 
146
                        currentImage() -> notify();
 
147
                } else {
 
148
                        m_target = device;
 
149
                }
 
150
                m_painter = new KisPainter( m_target );
 
151
                Q_CHECK_PTR(m_painter);
 
152
                m_source = device;
 
153
                m_painter -> beginTransaction(m_transactionText);
 
154
        }
 
155
 
 
156
        m_painter -> setPaintColor(m_subject -> fgColor());
 
157
        m_painter -> setBackgroundColor(m_subject -> bgColor());
 
158
        m_painter -> setBrush(m_subject -> currentBrush());
 
159
 
 
160
        m_painter -> setOpacity(m_opacity);
 
161
 
 
162
        // if you're drawing on a temporary layer, the layer already sets this
 
163
        if (m_useTempLayer) {
 
164
                m_painter -> setCompositeOp(COMPOSITE_OVER);
 
165
        } else {
 
166
                m_painter -> setCompositeOp(m_compositeOp);
 
167
        }
 
168
 
 
169
        // Set the cursor -- ideally. this should be a mask created from the brush,
 
170
        // now that X11 can handle colored cursors.
 
171
#if 0
 
172
        // Setting cursors has no effect until the tool is selected again; this
 
173
        // should be fixed.
 
174
        setCursor(KisCursor::brushCursor());
 
175
#endif
 
176
}
 
177
 
 
178
void KisToolFreehand::endPaint()
 
179
{
 
180
        m_mode = HOVER;
 
181
        if (m_currentImage) {
 
182
                KisUndoAdapter *adapter = m_currentImage -> undoAdapter();
 
183
                if (adapter && m_painter) {
 
184
                        // If painting in mouse release, make sure painter
 
185
                        // is destructed or end()ed
 
186
                        if (m_useTempLayer) {
 
187
                                m_painter -> endTransaction();
 
188
                                KisPainter painter( m_source );
 
189
                                painter.setCompositeOp(m_compositeOp);
 
190
                                painter.beginTransaction(m_transactionText);
 
191
                                painter.bitBlt(m_dirtyRect.x(), m_dirtyRect.y(), m_compositeOp, m_target, OPACITY_OPAQUE,
 
192
                                               m_dirtyRect.x(), m_dirtyRect.y(), m_dirtyRect.width(), m_dirtyRect.height());
 
193
 
 
194
                                adapter -> addCommand(painter.endTransaction());
 
195
                                dynamic_cast<KisDoc*>(m_subject->document())->layerRemove(
 
196
                                        currentImage(), dynamic_cast<KisLayer*>(m_target.data()));
 
197
                                currentImage() -> activate(dynamic_cast<KisLayer*>(m_source.data()));
 
198
                                adapter -> endMacro();
 
199
                        } else {
 
200
                                adapter -> addCommand(m_painter->endTransaction());
 
201
                        }
 
202
                }
 
203
                delete m_painter;
 
204
                m_painter = 0;
 
205
                notifyModified();
 
206
        }
 
207
}
 
208
 
 
209
void KisToolFreehand::paintAt(const KisPoint &pos,
 
210
                           const double pressure,
 
211
                           const double xTilt,
 
212
                           const double yTilt)
 
213
{
 
214
        painter() -> paintAt(pos, pressure, xTilt, yTilt);
 
215
}
 
216
 
 
217
void KisToolFreehand::paintLine(const KisPoint & pos1,
 
218
                             const double pressure1,
 
219
                             const double xtilt1,
 
220
                             const double ytilt1,
 
221
                             const KisPoint & pos2,
 
222
                             const double pressure2,
 
223
                             const double xtilt2,
 
224
                             const double ytilt2)
 
225
{
 
226
        m_dragDist = painter() -> paintLine(pos1, pressure1, xtilt1, ytilt1, pos2, pressure2, xtilt2, ytilt2, m_dragDist);
 
227
}
 
228
 
 
229
 
 
230
KisImageSP KisToolFreehand::currentImage()
 
231
{
 
232
        return m_currentImage;
 
233
}
 
234
 
 
235
void KisToolFreehand::setUseTempLayer(bool u) {
 
236
        m_useTempLayer = u;
 
237
};
 
238
 
 
239
#include "kis_tool_freehand.moc"
 
240