mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-11 14:59:50 +00:00
Eeschema, export to clipboard: allow using the Cairo printing system.
The Cairo printing system is already used to print to printer, it can be now used to print to clipboard and fixes the issue with opacity < 1. However to use it in clipboard, the advanced config needs to set the new EnableEeschemaExportClipboardCairo = 1 (for now) The default is false.
This commit is contained in:
parent
16cbb218c6
commit
929b2c06fe
common
eeschema
include
@ -105,6 +105,7 @@ static const wxChar EnableGit[] = wxT( "EnableGit" );
|
||||
static const wxChar EnableLibWithText[] = wxT( "EnableLibWithText" );
|
||||
static const wxChar EnableLibDir[] = wxT( "EnableLibDir" );
|
||||
static const wxChar EnableEeschemaPrintCairo[] = wxT( "EnableEeschemaPrintCairo" );
|
||||
static const wxChar EnableEeschemaExportClipboardCairo[] = wxT( "EnableEeschemaExportClipboardCairo" );
|
||||
static const wxChar DisambiguationTime[] = wxT( "DisambiguationTime" );
|
||||
static const wxChar PcbSelectionVisibilityRatio[] = wxT( "PcbSelectionVisibilityRatio" );
|
||||
static const wxChar FontErrorSize[] = wxT( "FontErrorSize" );
|
||||
@ -257,6 +258,7 @@ ADVANCED_CFG::ADVANCED_CFG()
|
||||
m_EnableLibDir = false;
|
||||
|
||||
m_EnableEeschemaPrintCairo = true;
|
||||
m_EnableEeschemaExportClipboardCairo = false;
|
||||
|
||||
m_3DRT_BevelHeight_um = 30;
|
||||
m_3DRT_BevelExtentFactor = 1.0 / 16.0;
|
||||
@ -502,6 +504,10 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
|
||||
&m_EnableEeschemaPrintCairo,
|
||||
m_EnableEeschemaPrintCairo ) );
|
||||
|
||||
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::EnableEeschemaExportClipboardCairo,
|
||||
&m_EnableEeschemaExportClipboardCairo,
|
||||
m_EnableEeschemaExportClipboardCairo ) );
|
||||
|
||||
configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::PcbSelectionVisibilityRatio,
|
||||
&m_PcbSelectionVisibilityRatio,
|
||||
m_PcbSelectionVisibilityRatio, 0.0, 1.0 ) );
|
||||
|
@ -35,6 +35,10 @@
|
||||
#include <zoom_defines.h>
|
||||
#include <drawing_sheet/ds_proxy_view_item.h>
|
||||
#include <string_utils.h>
|
||||
#include <wx/dcprint.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/dcmemory.h>
|
||||
#include <wx/log.h>
|
||||
|
||||
|
||||
SCH_PRINTOUT::SCH_PRINTOUT( SCH_EDIT_FRAME* aParent, const wxString& aTitle, bool aUseCairo ) :
|
||||
@ -96,7 +100,8 @@ bool SCH_PRINTOUT::OnPrintPage( int page )
|
||||
KIGFX::SCH_VIEW* sch_view = m_parent->GetCanvas()->GetView();
|
||||
sch_view->GetDrawingSheet()->SetPageNumber( TO_UTF8( screen->GetPageNumber() ) );
|
||||
|
||||
PrintPage( screen );
|
||||
// Print page using the current wxPrinterDC
|
||||
PrintPage( screen, GetDC(), true );
|
||||
|
||||
// Restore the initial current sheet
|
||||
m_parent->SetCurrentSheet( oldsheetpath );
|
||||
@ -118,8 +123,10 @@ int SCH_PRINTOUT::milsToIU( int aMils )
|
||||
/*
|
||||
* This is the real print function: print the active screen
|
||||
*/
|
||||
void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
|
||||
bool SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen, wxDC* aDC, bool aForPrinting )
|
||||
{
|
||||
// Note: some data (like paper size) is available only when printing
|
||||
|
||||
if( !m_useCairo )
|
||||
{
|
||||
// Version using print to a wxDC
|
||||
@ -132,7 +139,7 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
|
||||
wxSize pageSizeIU; // Page size in internal units
|
||||
VECTOR2I old_org;
|
||||
wxRect fitRect;
|
||||
wxDC* dc = GetDC();
|
||||
wxDC* dc = aDC;
|
||||
|
||||
wxBusyCursor dummy;
|
||||
|
||||
@ -150,7 +157,7 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
|
||||
pageSizeIU = ToWxSize( aScreen->GetPageSettings().GetSizeIU( schIUScale.IU_PER_MILS ) );
|
||||
FitThisSizeToPaper( pageSizeIU );
|
||||
|
||||
fitRect = GetLogicalPaperRect();
|
||||
fitRect = !aForPrinting ? wxRect( 0, 0, 6000, 4000 ) : GetLogicalPaperRect();
|
||||
|
||||
// When is the actual paper size does not match the schematic page size, the drawing will
|
||||
// not be centered on X or Y axis. Give a draw offset to center the schematic page on the
|
||||
@ -160,7 +167,7 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
|
||||
|
||||
// Using a wxAffineMatrix2D has a big advantage: it handles different pages orientations
|
||||
//(PORTRAIT/LANDSCAPE), but the affine matrix is not always supported
|
||||
if( dc->CanUseTransformMatrix() )
|
||||
if( dc->CanUseTransformMatrix() && aForPrinting )
|
||||
{
|
||||
wxAffineMatrix2D matrix; // starts from a unity matrix (the current wxDC default)
|
||||
|
||||
@ -192,7 +199,7 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
|
||||
fitRect.x -= xoffset;
|
||||
fitRect.y -= yoffset;
|
||||
}
|
||||
else
|
||||
else if( aForPrinting )
|
||||
{
|
||||
SetLogicalOrigin( 0, 0 ); // Reset all offset settings made previously.
|
||||
// When printing previous pages (all prints are using the same wxDC)
|
||||
@ -257,7 +264,7 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
|
||||
}
|
||||
else
|
||||
{
|
||||
wxDC* dc = GetDC();
|
||||
wxDC* dc = aDC;
|
||||
m_view = m_parent->GetCanvas()->GetView();
|
||||
KIGFX::GAL_DISPLAY_OPTIONS options;
|
||||
options.cairo_antialiasing_mode = KIGFX::CAIRO_ANTIALIASING_MODE::GOOD;
|
||||
@ -275,9 +282,28 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
|
||||
EE_SELECTION_TOOL* selTool = m_parent->GetToolManager()->GetTool<EE_SELECTION_TOOL>();
|
||||
|
||||
// Target paper size
|
||||
wxRect pageSizePx = GetLogicalPageRect();
|
||||
const VECTOR2D pageSizeIn( (double) pageSizePx.width / dc->GetPPI().x,
|
||||
(double) pageSizePx.height / dc->GetPPI().y );
|
||||
wxRect pageSizePix;
|
||||
wxSize dcPPI = dc->GetPPI();
|
||||
|
||||
if( aForPrinting )
|
||||
pageSizePix = GetLogicalPageRect();
|
||||
else
|
||||
{
|
||||
dc->SetUserScale( 1, 1 );
|
||||
|
||||
if( wxMemoryDC* memdc = dynamic_cast<wxMemoryDC*>( dc ) )
|
||||
{
|
||||
wxBitmap& bm = memdc->GetSelectedBitmap();
|
||||
pageSizePix = wxRect( 0, 0, bm.GetWidth(), bm.GetHeight() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const VECTOR2D pageSizeIn( (double) pageSizePix.width / dcPPI.x,
|
||||
(double) pageSizePix.height / dcPPI.y );
|
||||
const VECTOR2D pageSizeIU( milsToIU( pageSizeIn.x * 1000 ), milsToIU( pageSizeIn.y * 1000 ) );
|
||||
|
||||
galPrint->SetSheetSize( pageSizeIn );
|
||||
@ -384,7 +410,7 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
|
||||
gal->SetLookAtPoint( drawingAreaBBox.Centre() );
|
||||
gal->SetZoomFactor( print_scale );
|
||||
gal->SetClearColor( dstSettings->GetBackgroundColor() );
|
||||
gal->ResizeScreen( pageSizePx.GetWidth(),pageSizePx.GetHeight() );
|
||||
gal->ResizeScreen( pageSizePix.GetWidth(),pageSizePix.GetHeight() );
|
||||
gal->ClearScreen();
|
||||
|
||||
// Needed to use the same order for printing as for screen redraw
|
||||
@ -395,4 +421,6 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
|
||||
view->Redraw();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
@ -44,7 +44,18 @@ public:
|
||||
bool HasPage( int page ) override;
|
||||
bool OnBeginDocument( int startPage, int endPage ) override;
|
||||
void GetPageInfo( int* minPage, int* maxPage, int* selPageFrom, int* selPageTo ) override;
|
||||
void PrintPage( SCH_SCREEN* aScreen );
|
||||
|
||||
/**
|
||||
* Print the current SCH_SCREEN using a given wxDC
|
||||
* @param aScreen is the screen corresponding to the sheet to print
|
||||
* @param aDC is the drawing context to use. It can be only
|
||||
* a wxDC returned by wxPrintout::GetDC() (a wxPrinterDC, a wxPostScriptDC or a wxMemoryDC )
|
||||
* a wxMemoryDC (to print to the clipboard)
|
||||
* @param aForPrinting = true to draw to a printer, false to a wxMeoryDC used to
|
||||
* draw to the Clipboard
|
||||
* @return true if OK
|
||||
*/
|
||||
bool PrintPage( SCH_SCREEN* aScreen, wxDC* aDC, bool aForPrinting );
|
||||
|
||||
private:
|
||||
SCH_EDIT_FRAME* m_parent;
|
||||
|
@ -47,6 +47,9 @@
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/richmsgdlg.h>
|
||||
|
||||
#include <advanced_config.h>
|
||||
#include "printing/sch_printout.h"
|
||||
|
||||
|
||||
bool SCH_EDIT_FRAME::CheckSheetForRecursion( SCH_SHEET* aSheet, SCH_SHEET_PATH* aCurrentSheet )
|
||||
{
|
||||
@ -620,6 +623,7 @@ bool SCH_EDIT_FRAME::EditSheetProperties( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHi
|
||||
|
||||
void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard()
|
||||
{
|
||||
bool useCairo = ADVANCED_CFG::GetCfg().m_EnableEeschemaExportClipboardCairo;;
|
||||
wxRect drawArea;
|
||||
BASE_SCREEN* screen = GetScreen();
|
||||
|
||||
@ -673,7 +677,24 @@ void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard()
|
||||
|
||||
cfg->SetDefaultFont( eeconfig()->m_Appearance.default_font );
|
||||
|
||||
PrintPage( cfg );
|
||||
if( useCairo )
|
||||
{
|
||||
try
|
||||
{
|
||||
dc.SetUserScale( 1.0, 1.0 );
|
||||
SCH_PRINTOUT printout( this, wxEmptyString, true );
|
||||
bool success = printout.PrintPage( GetScreen(), cfg->GetPrintDC(), false );
|
||||
|
||||
if( !success )
|
||||
wxLogMessage( _( "Cannot create the schematic image") );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
wxLogMessage( "printout internal error" );
|
||||
}
|
||||
}
|
||||
else
|
||||
PrintPage( cfg );
|
||||
|
||||
// Deselect Bitmap from DC before using the bitmap
|
||||
dc.SelectObject( wxNullBitmap );
|
||||
|
@ -536,6 +536,15 @@ public:
|
||||
*/
|
||||
bool m_EnableEeschemaPrintCairo;
|
||||
|
||||
/**
|
||||
* Enable Eeschema Export to clipboard using Cairo.
|
||||
*
|
||||
* Setting name: "EnableEeschemaExportClipboardCairo"
|
||||
* Valid values: 0 or 1
|
||||
* Default value: 0
|
||||
*/
|
||||
bool m_EnableEeschemaExportClipboardCairo;
|
||||
|
||||
/**
|
||||
* Board object selection visibility limit.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user