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 std::vector<wxString>& urls = menuPair.second;
|
||||
|
||||
// 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;
|
||||
wxString js = wxT( "var aParams = [ " );
|
||||
|
||||
for( const wxString& url : urls )
|
||||
{
|
||||
wxString pageNumber;
|
||||
|
||||
if( url.StartsWith( "!" ) )
|
||||
{
|
||||
menuItems.push_back( { url.AfterFirst( '!' ), -1 } );
|
||||
wxString property = url.AfterFirst( '!' );
|
||||
|
||||
if( property.Find( "http:" ) >= 0 )
|
||||
{
|
||||
wxString href = property.substr( property.Find( "http:" ) );
|
||||
|
||||
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%s' }, " ),
|
||||
EscapeString( property, CTX_JS_STR ),
|
||||
EscapeString( href, CTX_JS_STR ) );
|
||||
}
|
||||
else if( property.Find( "https:" ) >= 0 )
|
||||
{
|
||||
wxString href = property.substr( property.Find( "https:" ) );
|
||||
|
||||
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%s' }, " ),
|
||||
EscapeString( property, CTX_JS_STR ),
|
||||
EscapeString( href, CTX_JS_STR ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
js += wxString::Format( wxT( "{ cName: '%s', cReturn: null }, " ),
|
||||
EscapeString( property, CTX_JS_STR ) );
|
||||
}
|
||||
}
|
||||
else if( EDA_TEXT::IsGotoPageHref( url, &pageNumber ) )
|
||||
else if( url.StartsWith( "#" ) )
|
||||
{
|
||||
wxString pageNumber = url.AfterFirst( '#' );
|
||||
|
||||
for( size_t ii = 0; ii < m_pageNumbers.size(); ++ii )
|
||||
{
|
||||
if( m_pageNumbers[ii] == pageNumber )
|
||||
menuItems.push_back( { pageNumber, ii } );
|
||||
{
|
||||
wxString menuText = wxString::Format( _( "Show Page %s" ), pageNumber );
|
||||
|
||||
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '#%d' }, " ),
|
||||
EscapeString( menuText, CTX_JS_STR ),
|
||||
static_cast<int>( ii ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wxString js = wxT( "var aParams = [ " );
|
||||
|
||||
for( const std::pair<wxString, int>& menuItem : menuItems )
|
||||
{
|
||||
if( menuItem.second < 0 )
|
||||
else if( url.StartsWith( "http:" ) || url.StartsWith( "https:" ) )
|
||||
{
|
||||
js += wxString::Format( wxT( "{ cName: '%s', cReturn: null }, " ),
|
||||
EscapeString( menuItem.first, CTX_JS_STR ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString menuText = wxString::Format( _( "Show Page %s" ), menuItem.first );
|
||||
wxString menuText = wxString::Format( _( "Open %s" ), url );
|
||||
|
||||
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%d' }, " ),
|
||||
js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%s' }, " ),
|
||||
EscapeString( menuText, CTX_JS_STR ),
|
||||
menuItem.second );
|
||||
EscapeString( url, CTX_JS_STR ) );
|
||||
}
|
||||
}
|
||||
|
||||
js += wxT( "]; " );
|
||||
|
||||
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 );
|
||||
|
||||
|
|
|
@ -983,13 +983,16 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
|||
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
|
||||
std::vector<std::pair<wxString, wxString>> pages;
|
||||
std::vector<wxString> pageHrefs;
|
||||
BOX2I bbox = GetBoundingBox();
|
||||
|
||||
label->GetIntersheetRefs( &pages );
|
||||
|
||||
for( const std::pair<wxString, wxString>& page : pages )
|
||||
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;
|
||||
|
||||
RENDER_SETTINGS* settings = aPlotter->RenderSettings();
|
||||
SCHEMATIC* schematic = Schematic();
|
||||
SCH_CONNECTION* connection = Connection();
|
||||
int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
|
||||
COLOR4D color = settings->GetLayerColor( layer );
|
||||
|
@ -917,6 +918,21 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
|||
{
|
||||
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() )
|
||||
{
|
||||
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
||||
|
@ -924,7 +940,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const
|
|||
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 ) ) );
|
||||
|
||||
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
||||
_( "Net class" ),
|
||||
_( "Resolved netclass" ),
|
||||
UnescapeString( className ) ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue