Fix using inactive painter when getting text extent
Ensure that the painter is active before using it.
This commit is contained in:
committed by
Vadim Zeitlin
parent
a5174c7483
commit
b991dc9d5a
@@ -19,6 +19,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPicture>
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/bitmap.h"
|
#include "wx/bitmap.h"
|
||||||
@@ -34,6 +35,38 @@
|
|||||||
|
|
||||||
#include "wx/private/graphics.h"
|
#include "wx/private/graphics.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
// Ensure that the given painter is active by calling begin() if it isn't. If
|
||||||
|
// it already is, don't do anything.
|
||||||
|
class EnsurePainterIsActive
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit EnsurePainterIsActive(QPainter* painter)
|
||||||
|
: m_painter(painter),
|
||||||
|
m_wasActive(painter->isActive())
|
||||||
|
{
|
||||||
|
if ( !m_wasActive )
|
||||||
|
m_painter->begin(&m_picture);
|
||||||
|
}
|
||||||
|
|
||||||
|
~EnsurePainterIsActive()
|
||||||
|
{
|
||||||
|
if ( !m_wasActive )
|
||||||
|
m_painter->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPainter* m_painter;
|
||||||
|
QPicture m_picture;
|
||||||
|
bool m_wasActive;
|
||||||
|
|
||||||
|
wxDECLARE_NO_COPY_CLASS(EnsurePainterIsActive);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxQtBrushData : public wxGraphicsObjectRefData
|
class WXDLLIMPEXP_CORE wxQtBrushData : public wxGraphicsObjectRefData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -935,6 +968,8 @@ public:
|
|||||||
wxCHECK_RET( !m_font.IsNull(),
|
wxCHECK_RET( !m_font.IsNull(),
|
||||||
"wxQtContext::GetTextExtent - no valid font set" );
|
"wxQtContext::GetTextExtent - no valid font set" );
|
||||||
|
|
||||||
|
EnsurePainterIsActive active(m_qtPainter);
|
||||||
|
|
||||||
const wxQtFontData*
|
const wxQtFontData*
|
||||||
fontData = static_cast<wxQtFontData*>(m_font.GetRefData());
|
fontData = static_cast<wxQtFontData*>(m_font.GetRefData());
|
||||||
m_qtPainter->setFont(fontData->GetFont());
|
m_qtPainter->setFont(fontData->GetFont());
|
||||||
@@ -959,6 +994,8 @@ public:
|
|||||||
wxCHECK_RET( !m_font.IsNull(),
|
wxCHECK_RET( !m_font.IsNull(),
|
||||||
"wxQtContext::GetPartialTextExtents - no valid font set" );
|
"wxQtContext::GetPartialTextExtents - no valid font set" );
|
||||||
|
|
||||||
|
EnsurePainterIsActive active(m_qtPainter);
|
||||||
|
|
||||||
const wxQtFontData*
|
const wxQtFontData*
|
||||||
fontData = static_cast<wxQtFontData*>(m_font.GetRefData());
|
fontData = static_cast<wxQtFontData*>(m_font.GetRefData());
|
||||||
m_qtPainter->setFont(fontData->GetFont());
|
m_qtPainter->setFont(fontData->GetFont());
|
||||||
|
Reference in New Issue
Block a user