Clean up some of the PDF hypertext stuff, and add opening HTTP[S] urls.
Fixes https://gitlab.com/kicad/code/kicad/issues/12153
This commit is contained in:
parent
59dc6c8e45
commit
b80824951e
|
@ -955,52 +955,70 @@ bool PDF_PLOTTER::EndPlot()
|
||||||
{
|
{
|
||||||
const BOX2D& box = menuPair.first;
|
const BOX2D& box = menuPair.first;
|
||||||
const std::vector<wxString>& urls = menuPair.second;
|
const std::vector<wxString>& urls = menuPair.second;
|
||||||
|
wxString js = wxT( "var aParams = [ " );
|
||||||
// We currently only support menu links for internal pages and property lists.
|
|
||||||
// This vector holds the menu titles and (optional) page numbers.
|
|
||||||
std::vector<std::pair<wxString, int>> menuItems;
|
|
||||||
|
|
||||||
for( const wxString& url : urls )
|
for( const wxString& url : urls )
|
||||||
{
|
{
|
||||||
wxString pageNumber;
|
|
||||||
|
|
||||||
if( url.StartsWith( "!" ) )
|
if( url.StartsWith( "!" ) )
|
||||||
{
|
{
|
||||||
menuItems.push_back( { url.AfterFirst( '!' ), -1 } );
|
wxString property = url.AfterFirst( '!' );
|
||||||
}
|
|
||||||
else if( EDA_TEXT::IsGotoPageHref( url, &pageNumber ) )
|
|
||||||
{
|
|
||||||
for( size_t ii = 0; ii < m_pageNumbers.size(); ++ii )
|
|
||||||
{
|
|
||||||
if( m_pageNumbers[ii] == pageNumber )
|
|
||||||
menuItems.push_back( { pageNumber, ii } );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString js = wxT( "var aParams = [ " );
|
if( property.Find( "http:" ) >= 0 )
|
||||||
|
{
|
||||||
|
wxString href = property.substr( property.Find( "http:" ) );
|
||||||
|
|
||||||
for( const std::pair<wxString, int>& menuItem : menuItems )
|
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%s' }, " ),
|
||||||
|
EscapeString( property, CTX_JS_STR ),
|
||||||
|
EscapeString( href, CTX_JS_STR ) );
|
||||||
|
}
|
||||||
|
else if( property.Find( "https:" ) >= 0 )
|
||||||
{
|
{
|
||||||
if( menuItem.second < 0 )
|
wxString href = property.substr( property.Find( "https:" ) );
|
||||||
{
|
|
||||||
js += wxString::Format( wxT( "{ cName: '%s', cReturn: null }, " ),
|
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%s' }, " ),
|
||||||
EscapeString( menuItem.first, CTX_JS_STR ) );
|
EscapeString( property, CTX_JS_STR ),
|
||||||
|
EscapeString( href, CTX_JS_STR ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxString menuText = wxString::Format( _( "Show Page %s" ), menuItem.first );
|
js += wxString::Format( wxT( "{ cName: '%s', cReturn: null }, " ),
|
||||||
|
EscapeString( property, CTX_JS_STR ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( url.StartsWith( "#" ) )
|
||||||
|
{
|
||||||
|
wxString pageNumber = url.AfterFirst( '#' );
|
||||||
|
|
||||||
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%d' }, " ),
|
for( size_t ii = 0; ii < m_pageNumbers.size(); ++ii )
|
||||||
|
{
|
||||||
|
if( m_pageNumbers[ii] == pageNumber )
|
||||||
|
{
|
||||||
|
wxString menuText = wxString::Format( _( "Show Page %s" ), pageNumber );
|
||||||
|
|
||||||
|
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '#%d' }, " ),
|
||||||
EscapeString( menuText, CTX_JS_STR ),
|
EscapeString( menuText, CTX_JS_STR ),
|
||||||
menuItem.second );
|
static_cast<int>( ii ) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( url.StartsWith( "http:" ) || url.StartsWith( "https:" ) )
|
||||||
|
{
|
||||||
|
wxString menuText = wxString::Format( _( "Open %s" ), url );
|
||||||
|
|
||||||
|
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%s' }, " ),
|
||||||
|
EscapeString( menuText, CTX_JS_STR ),
|
||||||
|
EscapeString( url, CTX_JS_STR ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
js += wxT( "]; " );
|
js += wxT( "]; " );
|
||||||
|
|
||||||
js += wxT( "var cChoice = app.popUpMenuEx.apply\\( app, aParams \\); " );
|
js += wxT( "var cChoice = app.popUpMenuEx.apply\\( app, aParams \\); " );
|
||||||
js += wxT( "if\\( cChoice != null \\) this.pageNum = cChoice; " );
|
js += wxT( "if\\( cChoice != null && cChoice.startsWith\\( '#' \\) \\)"
|
||||||
|
" this.pageNum = cChoice.slice\\( 1 \\); " );
|
||||||
|
js += wxT( "else if\\( cChoice != null && cChoice.startsWith\\( 'http' \\) \\)"
|
||||||
|
" app.launchURL\\( cChoice \\);" );
|
||||||
|
|
||||||
startPdfObject( menuHandle );
|
startPdfObject( menuHandle );
|
||||||
|
|
||||||
|
|
|
@ -983,13 +983,16 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
||||||
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
|
||||||
std::vector<std::pair<wxString, wxString>> pages;
|
std::vector<std::pair<wxString, wxString>> pages;
|
||||||
std::vector<wxString> pageHrefs;
|
std::vector<wxString> pageHrefs;
|
||||||
|
BOX2I bbox = GetBoundingBox();
|
||||||
|
|
||||||
label->GetIntersheetRefs( &pages );
|
label->GetIntersheetRefs( &pages );
|
||||||
|
|
||||||
for( const std::pair<wxString, wxString>& page : pages )
|
for( const std::pair<wxString, wxString>& page : pages )
|
||||||
pageHrefs.push_back( wxT( "#" ) + page.first );
|
pageHrefs.push_back( wxT( "#" ) + page.first );
|
||||||
|
|
||||||
aPlotter->HyperlinkMenu( GetBoundingBox(), pageHrefs );
|
bbox.Offset( label->GetSchematicTextOffset( settings ) );
|
||||||
|
|
||||||
|
aPlotter->HyperlinkMenu( bbox, pageHrefs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -882,6 +882,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
||||||
static std::vector<VECTOR2I> s_poly;
|
static std::vector<VECTOR2I> s_poly;
|
||||||
|
|
||||||
RENDER_SETTINGS* settings = aPlotter->RenderSettings();
|
RENDER_SETTINGS* settings = aPlotter->RenderSettings();
|
||||||
|
SCHEMATIC* schematic = Schematic();
|
||||||
SCH_CONNECTION* connection = Connection();
|
SCH_CONNECTION* connection = Connection();
|
||||||
int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
|
int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
|
||||||
COLOR4D color = settings->GetLayerColor( layer );
|
COLOR4D color = settings->GetLayerColor( layer );
|
||||||
|
@ -917,6 +918,21 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
||||||
{
|
{
|
||||||
std::vector<wxString> properties;
|
std::vector<wxString> properties;
|
||||||
|
|
||||||
|
if( schematic && connection )
|
||||||
|
{
|
||||||
|
auto& netSettings = schematic->Prj().GetProjectFile().m_NetSettings;
|
||||||
|
wxString netName = connection->Name();
|
||||||
|
wxString className = netSettings->GetEffectiveNetClass( netName )->GetName();
|
||||||
|
|
||||||
|
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
||||||
|
_( "Net" ),
|
||||||
|
UnescapeString( netName ) ) );
|
||||||
|
|
||||||
|
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
||||||
|
_( "Resolved netclass" ),
|
||||||
|
UnescapeString( className ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
for( const SCH_FIELD& field : GetFields() )
|
for( const SCH_FIELD& field : GetFields() )
|
||||||
{
|
{
|
||||||
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
||||||
|
@ -924,7 +940,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
||||||
field.GetShownText() ) );
|
field.GetShownText() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
aPlotter->HyperlinkMenu( GetBoundingBox(), properties );
|
aPlotter->HyperlinkMenu( GetBodyBoundingBox(), properties );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -858,7 +858,7 @@ void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
||||||
UnescapeString( netName ) ) );
|
UnescapeString( netName ) ) );
|
||||||
|
|
||||||
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
||||||
_( "Net class" ),
|
_( "Resolved netclass" ),
|
||||||
UnescapeString( className ) ) );
|
UnescapeString( className ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue