adding measuring contexts, streamlining printing code

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43012 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2006-11-04 07:50:06 +00:00
parent fd7915711f
commit ad66794547
9 changed files with 29 additions and 39 deletions

View File

@@ -393,6 +393,9 @@ public:
static wxGraphicsContext* Create( wxWindow* window ) ; static wxGraphicsContext* Create( wxWindow* window ) ;
// create a context that can be used for measuring texts only, no drawing allowed
static wxGraphicsContext * Create();
wxGraphicsPath CreatePath() const; wxGraphicsPath CreatePath() const;
virtual wxGraphicsPen CreatePen(const wxPen& pen) const; virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
@@ -605,6 +608,9 @@ public :
virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0; virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0;
// create a context that can be used for measuring texts only, no drawing allowed
virtual wxGraphicsContext * CreateMeasuringContext() = 0;
// Path // Path
virtual wxGraphicsPath CreatePath() = 0; virtual wxGraphicsPath CreatePath() = 0;

View File

@@ -36,9 +36,6 @@ class WXDLLEXPORT wxPrinterDC: public wxDC
wxPrintData& GetPrintData() { return m_printData; } wxPrintData& GetPrintData() { return m_printData; }
virtual wxSize GetPPI() const; virtual wxSize GetPPI() const;
#if wxMAC_USE_CORE_GRAPHICS
void MacSetCGContext( void * cg ) ;
#endif
protected: protected:
virtual void DoGetSize( int *width, int *height ) const; virtual void DoGetSize( int *width, int *height ) const;
wxPrintData m_printData ; wxPrintData m_printData ;

View File

@@ -71,6 +71,9 @@ void wxGCDC::SetGraphicsContext( wxGraphicsContext* ctx )
m_ok = true; m_ok = true;
// apply the stored transformations to the passed in context // apply the stored transformations to the passed in context
ComputeScaleAndOrigin(); ComputeScaleAndOrigin();
m_graphicContext->SetFont( m_font , m_textForegroundColour );
m_graphicContext->SetPen( m_pen );
m_graphicContext->SetBrush( m_brush);
} }
} }
@@ -78,12 +81,6 @@ wxGCDC::wxGCDC(const wxWindowDC& dc)
{ {
Init(); Init();
SetGraphicsContext( wxGraphicsContext::Create(dc) ); SetGraphicsContext( wxGraphicsContext::Create(dc) );
if ( dc.GetFont().Ok())
m_graphicContext->SetFont( m_graphicContext->CreateFont(dc.GetFont(),dc.GetTextForeground()));
if ( dc.GetPen().Ok())
m_graphicContext->SetPen( m_graphicContext->CreatePen(dc.GetPen()));
if ( dc.GetBrush().Ok())
m_graphicContext->SetBrush( m_graphicContext->CreateBrush(dc.GetBrush()));
} }
void wxGCDC::Init() void wxGCDC::Init()

View File

@@ -509,7 +509,7 @@ void wxGraphicsContext::SetPen( const wxGraphicsPen& pen )
void wxGraphicsContext::SetPen( const wxPen& pen ) void wxGraphicsContext::SetPen( const wxPen& pen )
{ {
if ( pen.GetStyle() == wxTRANSPARENT ) if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
SetPen( wxNullGraphicsPen ); SetPen( wxNullGraphicsPen );
else else
SetPen( CreatePen( pen ) ); SetPen( CreatePen( pen ) );
@@ -523,7 +523,7 @@ void wxGraphicsContext::SetBrush( const wxGraphicsBrush& brush )
void wxGraphicsContext::SetBrush( const wxBrush& brush ) void wxGraphicsContext::SetBrush( const wxBrush& brush )
{ {
if ( brush.GetStyle() == wxTRANSPARENT ) if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
SetBrush( wxNullGraphicsBrush ); SetBrush( wxNullGraphicsBrush );
else else
SetBrush( CreateBrush( brush ) ); SetBrush( CreateBrush( brush ) );
@@ -682,6 +682,11 @@ wxGraphicsContext* wxGraphicsContext::Create( wxWindow* window )
return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(window); return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(window);
} }
wxGraphicsContext* wxGraphicsContext::Create()
{
return wxGraphicsRenderer::GetDefaultRenderer()->CreateMeasuringContext();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxGraphicsRenderer // wxGraphicsRenderer
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@@ -145,8 +145,6 @@ wxWindowDC::wxWindowDC(wxWindow *window)
SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) ); SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
} }
m_graphicContext->SetPen( m_pen ) ;
m_graphicContext->SetBrush( m_brush ) ;
SetClippingRegion( 0 , 0 , m_width , m_height ) ; SetClippingRegion( 0 , 0 , m_width , m_height ) ;
#else #else
int x , y ; int x , y ;

View File

@@ -100,9 +100,6 @@ void wxMemoryDC::DoSelect( const wxBitmap& bitmap )
CGContextScaleCTM( bmCtx , 1 , -1 ) ; CGContextScaleCTM( bmCtx , 1 , -1 ) ;
SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) ); SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
m_graphicContext->SetPen( m_pen ) ;
m_graphicContext->SetBrush( m_brush ) ;
m_graphicContext->SetFont( m_font , m_textForegroundColour) ;
} }
m_ok = (m_graphicContext != NULL) ; m_ok = (m_graphicContext != NULL) ;

View File

@@ -230,7 +230,7 @@ void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc )
m_err = noErr ; m_err = noErr ;
} }
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
dc->MacSetCGContext(pageContext) ; dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( pageContext ) );
#endif #endif
} }
@@ -247,7 +247,8 @@ void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc )
PMSessionEndDocument(native->m_macPrintSession); PMSessionEndDocument(native->m_macPrintSession);
} }
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
dc->MacSetCGContext(NULL) ; // the cg context we got when starting the page isn't valid anymore, so replace it
dc->SetGraphicsContext( wxGraphicsContext::Create() );
#endif #endif
} }
@@ -291,10 +292,9 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
m_mm_to_pix_y = mm2inches * sz.y; m_mm_to_pix_y = mm2inches * sz.y;
} }
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
/* // we need at least a measuring context because people start measuring before a page
// the cgContext will only be handed over page by page // gets printed at all
m_graphicContext = new wxMacCGContext() ; SetGraphicsContext( wxGraphicsContext::Create() );
*/
#endif #endif
} }
} }
@@ -306,23 +306,9 @@ wxSize wxPrinterDC::GetPPI() const
wxPrinterDC::~wxPrinterDC(void) wxPrinterDC::~wxPrinterDC(void)
{ {
#if wxMAC_USE_CORE_GRAPHICS
/*
// this context was borrowed
((wxMacCGContext*)(m_graphicContext))->SetNativeContext( NULL ) ;
*/
#endif
delete m_nativePrinterDC ; delete m_nativePrinterDC ;
} }
#if wxMAC_USE_CORE_GRAPHICS
void wxPrinterDC::MacSetCGContext( void * cg )
{
SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
m_graphicContext->SetPen( m_pen ) ;
m_graphicContext->SetBrush( m_brush ) ;
}
#endif
bool wxPrinterDC::StartDoc( const wxString& message ) bool wxPrinterDC::StartDoc( const wxString& message )
{ {
wxASSERT_MSG( Ok() , wxT("Called wxPrinterDC::StartDoc from an invalid object") ) ; wxASSERT_MSG( Ok() , wxT("Called wxPrinterDC::StartDoc from an invalid object") ) ;

View File

@@ -1869,6 +1869,8 @@ public :
virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ); virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window );
virtual wxGraphicsContext * CreateContext( wxWindow* window ); virtual wxGraphicsContext * CreateContext( wxWindow* window );
virtual wxGraphicsContext * CreateMeasuringContext();
// Path // Path
@@ -1934,6 +1936,11 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( wxWindow* window )
return new wxMacCoreGraphicsContext(this, window ); return new wxMacCoreGraphicsContext(this, window );
} }
wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateMeasuringContext()
{
return new wxMacCoreGraphicsContext(this);
}
// Path // Path
wxGraphicsPath wxMacCoreGraphicsRenderer::CreatePath() wxGraphicsPath wxMacCoreGraphicsRenderer::CreatePath()

View File

@@ -134,10 +134,7 @@ void wxOverlayImpl::Init( wxWindowDC* dc, int x , int y , int width , int height
void wxOverlayImpl::BeginDrawing( wxWindowDC* dc) void wxOverlayImpl::BeginDrawing( wxWindowDC* dc)
{ {
// TODO CS
dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) ); dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
// triggers an application of the already set device origins to the native context
dc->SetUserScale(1,1);
wxSize size = dc->GetSize() ; wxSize size = dc->GetSize() ;
dc->SetClippingRegion( 0 , 0 , size.x , size.y ) ; dc->SetClippingRegion( 0 , 0 , size.x , size.y ) ;
} }