Implement super- and subscript printing and plotting for eeschema.

This commit is contained in:
Jeff Young 2020-01-09 00:13:02 +00:00
parent 65c88ba2c3
commit 5e5edd03f6
10 changed files with 54 additions and 31 deletions

View File

@ -30,6 +30,7 @@
#include <gal/graphics_abstraction_layer.h>
#include <math/util.h> // for KiROUND
#include <wx/string.h>
#include <gr_text.h>
using namespace KIGFX;

View File

@ -42,6 +42,22 @@
#include <basic_gal.h>
static int s_textMarkupFlags = 0;
void SetTextMarkupFlags( int aMarkupFlags )
{
s_textMarkupFlags = aMarkupFlags;
}
int GetTextMarkupFlags()
{
return s_textMarkupFlags;
}
/**
* Function GetPensizeForBold
* @return the "best" value for a pen size to draw/plot a bold text
@ -165,7 +181,7 @@ void GRText( wxDC* aDC, const wxPoint& aPos, COLOR4D aColor, const wxString& aTe
basic_gal.m_Color = aColor;
basic_gal.SetClipBox( nullptr );
basic_gal.StrokeText( aText, VECTOR2D( aPos ), aOrient * M_PI/1800 );
basic_gal.StrokeText( aText, VECTOR2D( aPos ), aOrient * M_PI/1800, GetTextMarkupFlags() );
}

View File

@ -27,7 +27,6 @@
#include <fctsys.h>
#include <gr_basic.h>
#include <trigo.h>
#include <eda_base_frame.h>
#include <base_struct.h>
@ -879,7 +878,15 @@ void DXF_PLOTTER::Text( const wxPoint& aPos,
if( aMultilineAllowed && !aText.Contains( wxT( "\n" ) ) )
aMultilineAllowed = false; // the text has only one line.
if( textAsLines || containsNonAsciiChars( aText ) || aMultilineAllowed )
bool processSuperSub = false;
if( ( GetTextMarkupFlags() & ENABLE_SUBSCRIPT_MARKUP ) && aText.Contains( wxT( "#" ) ) )
processSuperSub = true;
if( ( GetTextMarkupFlags() & ENABLE_SUPERSCRIPT_MARKUP ) && aText.Contains( wxT( "^" ) ) )
processSuperSub = true;
if( textAsLines || containsNonAsciiChars( aText ) || aMultilineAllowed || processSuperSub )
{
// output text as graphics.
// Perhaps multiline texts could be handled as DXF text entity

View File

@ -998,9 +998,18 @@ void PS_PLOTTER::Text( const wxPoint& aPos,
if( aMultilineAllowed && !aText.Contains( wxT( "\n" ) ) )
aMultilineAllowed = false; // the text has only one line.
bool processSuperSub = false;
if( ( GetTextMarkupFlags() & ENABLE_SUBSCRIPT_MARKUP ) && aText.Contains( wxT( "#" ) ) )
processSuperSub = true;
if( ( GetTextMarkupFlags() & ENABLE_SUPERSCRIPT_MARKUP ) && aText.Contains( wxT( "^" ) ) )
processSuperSub = true;
// Draw the native postscript text (if requested)
// Currently: does not work: disable it
bool use_native = false; // = m_textMode == PLOT_TEXT_MODE::NATIVE && !aMultilineAllowed;
bool use_native = false; // = m_textMode == PLOT_TEXT_MODE::NATIVE
// && !aMultilineAllowed && !processSuperSub;
if( use_native )
{

View File

@ -31,6 +31,7 @@
#include <panel_eeschema_display_options.h>
#include <widgets/gal_options_panel.h>
#include <sch_junction.h>
#include <gr_text.h>
PANEL_EESCHEMA_DISPLAY_OPTIONS::PANEL_EESCHEMA_DISPLAY_OPTIONS( SCH_EDIT_FRAME* aFrame,
wxWindow* aWindow ) :
@ -76,7 +77,7 @@ bool PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataToWindow()
m_junctionSize.SetValue( SCH_JUNCTION::GetSymbolSize() );
m_checkShowHiddenPins->SetValue( m_frame->GetShowAllPins() );
int superSubFlags = KIGFX::ENABLE_SUBSCRIPT_MARKUP | KIGFX::ENABLE_SUPERSCRIPT_MARKUP;
int superSubFlags = ENABLE_SUBSCRIPT_MARKUP | ENABLE_SUPERSCRIPT_MARKUP;
m_checkSuperSub->SetValue( GetTextMarkupFlags() & superSubFlags );
@ -130,7 +131,7 @@ bool PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataFromWindow()
// Update canvas
m_frame->GetRenderSettings()->m_ShowHiddenPins = m_checkShowHiddenPins->GetValue();
int superSubFlags = KIGFX::ENABLE_SUBSCRIPT_MARKUP | KIGFX::ENABLE_SUPERSCRIPT_MARKUP;
int superSubFlags = ENABLE_SUBSCRIPT_MARKUP | ENABLE_SUPERSCRIPT_MARKUP;
if( m_checkSuperSub->GetValue() )
SetTextMarkupFlags( GetTextMarkupFlags() | superSubFlags );

View File

@ -44,13 +44,13 @@
#include <widgets/symbol_tree_pane.h>
#include <dialogs/panel_libedit_settings.h>
#include <sch_painter.h>
#include <gr_text.h>
#include "sch_junction.h"
static int s_defaultBusThickness = DEFAULTBUSTHICKNESS;
static int s_defaultWireThickness = DEFAULTDRAWLINETHICKNESS;
static int s_defaultTextSize = DEFAULT_SIZE_TEXT;
static int s_drawDefaultLineThickness = -1;
static int s_textMarkupFlags = 0;
static bool s_selectTextAsBox = false;
static bool s_selectDrawChildren = true;
static bool s_selectFillShapes = false;
@ -98,18 +98,6 @@ int GetDefaultLineThickness()
}
void SetTextMarkupFlags( int aMarkupFlags )
{
s_textMarkupFlags = aMarkupFlags;
}
int GetTextMarkupFlags()
{
return s_textMarkupFlags;
}
void SetDefaultLineThickness( int aThickness )
{
s_drawDefaultLineThickness = std::max( 1, aThickness );

View File

@ -147,9 +147,6 @@ void SetSelectionFillShapes( bool aBool );
int GetSelectionThickness();
void SetSelectionThickness( int aThickness );
int GetTextMarkupFlags();
void SetTextMarkupFlags( int aMarkupFlags );
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer );
void SetLayerColor( COLOR4D aColor, SCH_LAYER_ID aLayer );

View File

@ -46,12 +46,6 @@ class BITMAP_BASE;
namespace KIGFX
{
enum TEXT_MARKUP_FLAGS
{
ENABLE_SUBSCRIPT_MARKUP = 1 << 0,
ENABLE_SUPERSCRIPT_MARKUP = 1 << 1
};
/**
* @brief Class GAL is the abstract interface for drawing on a 2D-surface.
*

View File

@ -50,6 +50,15 @@
class PLOTTER;
enum TEXT_MARKUP_FLAGS
{
ENABLE_SUBSCRIPT_MARKUP = 1 << 0,
ENABLE_SUPERSCRIPT_MARKUP = 1 << 1
};
int GetTextMarkupFlags();
void SetTextMarkupFlags( int aMarkupFlags );
/**
* Function Clamp_Text_PenSize
*As a rule, pen width should not be >1/4em, otherwise the character

View File

@ -976,7 +976,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer )
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetTextAttributes( aText );
m_gal->StrokeText( shownText, position, aText->GetTextAngleRadians() );
m_gal->StrokeText( shownText, position, aText->GetTextAngleRadians(), GetTextMarkupFlags() );
}
@ -1008,7 +1008,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetTextAttributes( aText );
m_gal->StrokeText( shownText, position, aText->GetDrawRotationRadians() );
m_gal->StrokeText( shownText, position, aText->GetDrawRotationRadians(), GetTextMarkupFlags() );
// Draw the umbilical line
if( aText->IsSelected() )
@ -1138,7 +1138,8 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer )
m_gal->SetLineWidth( text.GetThickness() );
m_gal->SetTextAttributes( &text );
m_gal->StrokeText( text.GetShownText(), position, text.GetTextAngleRadians() );
m_gal->StrokeText( text.GetShownText(), position, text.GetTextAngleRadians(),
GetTextMarkupFlags() );
}