Rework on class EDA_TEXT and related classes and draw functions. More work. Eechema: in rotate texts: redraw the full screen to avoid garbage on screen.
This commit is contained in:
parent
b59a07128f
commit
bc699c8d8f
|
@ -264,14 +264,6 @@ void BASIC_GAL::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint
|
|||
|
||||
BASIC_GAL basic_gal;
|
||||
|
||||
|
||||
int OverbarPositionY( int aVTextSize, int aThickness )
|
||||
{
|
||||
basic_gal.SetGlyphSize( VECTOR2D( aVTextSize, aVTextSize ) );
|
||||
basic_gal.SetLineWidth( aThickness );
|
||||
return KiROUND( basic_gal.GetOverbarVerticalPosition() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Function GetPensizeForBold
|
||||
* @return the "best" value for a pen size to draw/plot a bold text
|
||||
|
|
|
@ -117,7 +117,7 @@ wxString EDA_TEXT::ShortenedShownText() const
|
|||
int EDA_TEXT::GetInterline( int aTextThickness ) const
|
||||
{
|
||||
int thickness = aTextThickness <= 0 ? m_Thickness : aTextThickness;
|
||||
return KiROUND( m_Size.y * KIGFX::STROKE_FONT::INTERLINE_PITCH_RATIO ) + thickness;
|
||||
return KiROUND( KIGFX::STROKE_FONT::GetInterline( m_Size.y, thickness ) );
|
||||
}
|
||||
|
||||
EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const
|
||||
|
@ -178,8 +178,9 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const
|
|||
if( hasOverBar )
|
||||
{
|
||||
// A overbar adds an extra size to the text
|
||||
double curr_height = m_Size.y * 1.15; // Height from the base line text of chars like [ or {
|
||||
int extra_height = KiROUND( OverbarPositionY( m_Size.y, thickness ) - curr_height );
|
||||
double curr_height = m_Size.y * 1.15; // Height from the base line text of chars like [ or {
|
||||
int extra_height = KiROUND(
|
||||
KIGFX::STROKE_FONT::ComputeOverbarVerticalPosition( m_Size.y, thickness ) - curr_height );
|
||||
textsize.y += extra_height;
|
||||
rect.Move( wxPoint( 0, -extra_height ) );
|
||||
}
|
||||
|
|
|
@ -121,9 +121,16 @@ bool STROKE_FONT::LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNe
|
|||
}
|
||||
|
||||
|
||||
// Static function:
|
||||
double STROKE_FONT::GetInterline( double aGlyphHeight, double aGlyphThickness )
|
||||
{
|
||||
return ( aGlyphHeight * INTERLINE_PITCH_RATIO ) + aGlyphThickness;
|
||||
}
|
||||
|
||||
|
||||
int STROKE_FONT::getInterline() const
|
||||
{
|
||||
return KiROUND( m_glyphSize.y * INTERLINE_PITCH_RATIO ) + m_gal->GetLineWidth();
|
||||
return KiROUND( GetInterline( m_glyphSize.y, m_gal->GetLineWidth() ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -364,11 +371,20 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText )
|
|||
}
|
||||
|
||||
|
||||
double STROKE_FONT::ComputeOverbarVerticalPosition( double aGlyphHeight, double aGlyphThickness )
|
||||
{
|
||||
// Static method.
|
||||
// Compute the Y position of the overbar. This is the distance between
|
||||
// the text base line and the overbar axis.
|
||||
return aGlyphHeight * OVERBAR_POSITION_FACTOR + aGlyphThickness;
|
||||
}
|
||||
|
||||
|
||||
double STROKE_FONT::computeOverbarVerticalPosition() const
|
||||
{
|
||||
// Compute the Y position of the overbar. This is the distance between
|
||||
// the text base line and the overbar axis.
|
||||
return m_glyphSize.y * OVERBAR_POSITION_FACTOR + m_gal->GetLineWidth();
|
||||
return ComputeOverbarVerticalPosition( m_glyphSize.y, m_gal->GetLineWidth() );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors.
|
||||
* Copyright (C) 2004-2016 KiCad Developers, see change_log.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
|
||||
|
@ -151,7 +151,7 @@ void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField )
|
|||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::RotateField( SCH_FIELD* aField, wxDC* aDC )
|
||||
void SCH_EDIT_FRAME::RotateField( SCH_FIELD* aField )
|
||||
{
|
||||
wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T && !aField->GetText().IsEmpty(),
|
||||
wxT( "Cannot rotate invalid schematic field." ) );
|
||||
|
@ -162,14 +162,10 @@ void SCH_EDIT_FRAME::RotateField( SCH_FIELD* aField, wxDC* aDC )
|
|||
if( aField->GetFlags() == 0 )
|
||||
SaveCopyInUndoList( component, UR_CHANGED );
|
||||
|
||||
aField->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
||||
|
||||
if( aField->GetOrientation() == TEXT_ORIENT_HORIZ )
|
||||
aField->SetOrientation( TEXT_ORIENT_VERT );
|
||||
else
|
||||
aField->SetOrientation( TEXT_ORIENT_HORIZ );
|
||||
|
||||
aField->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
||||
|
||||
OnModify();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ static bool lastTextBold = false;
|
|||
static bool lastTextItalic = false;
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC )
|
||||
void SCH_EDIT_FRAME::ChangeTextOrient( SCH_TEXT* aTextItem )
|
||||
{
|
||||
wxCHECK_RET( (aTextItem != NULL) && aTextItem->CanIncrementLabel(),
|
||||
wxT( "Invalid schematic text item." ) );
|
||||
|
@ -58,12 +58,8 @@ void SCH_EDIT_FRAME::ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC )
|
|||
if( aTextItem->GetFlags() == 0 )
|
||||
SaveCopyInUndoList( aTextItem, UR_CHANGED );
|
||||
|
||||
m_canvas->CrossHairOff( aDC );
|
||||
aTextItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
||||
aTextItem->SetOrientation( orient );
|
||||
OnModify();
|
||||
aTextItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
||||
m_canvas->CrossHairOn( aDC );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2016 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
|
||||
|
@ -25,22 +25,20 @@
|
|||
|
||||
/**
|
||||
* @file sch_text.cpp
|
||||
* @brief Code for handling schematic sheet labels.
|
||||
* @brief Code for handling schematic texts (texts, labels, hlabels and global labels).
|
||||
*/
|
||||
|
||||
#include <fctsys.h>
|
||||
#include <gr_basic.h>
|
||||
#include <macros.h>
|
||||
#include <trigo.h>
|
||||
#include <eeschema_id.h>
|
||||
#include <class_drawpanel.h>
|
||||
#include <drawtxt.h>
|
||||
#include <schframe.h>
|
||||
#include <plot_common.h>
|
||||
#include <base_units.h>
|
||||
#include <msgpanel.h>
|
||||
#include <gal/stroke_font.h>
|
||||
|
||||
#include <general.h>
|
||||
#include <protos.h>
|
||||
#include <sch_text.h>
|
||||
#include <class_netlist_object.h>
|
||||
|
@ -48,7 +46,7 @@
|
|||
|
||||
extern void IncrementLabelMember( wxString& name, int aIncrement );
|
||||
|
||||
#define DRAW_BBOX 1 // Only for tests: set to 1 to draw the boudding box of labels
|
||||
#define DRAW_BBOX 0 // Only for tests: set to 1 to draw the bounding box of labels
|
||||
|
||||
/* Names of sheet label types. */
|
||||
const char* SheetLabelType[] =
|
||||
|
@ -1295,7 +1293,8 @@ void SCH_GLOBALLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const
|
|||
// Note: this factor is due to the fact we need a margin for the graphic symbol.
|
||||
#define Y_OVERBAR_CORRECTION 1.2
|
||||
if( hasOverBar )
|
||||
y = KiROUND( OverbarPositionY( halfSize, linewidth ) * Y_OVERBAR_CORRECTION );
|
||||
y = KiROUND( KIGFX::STROKE_FONT::GetInterline( halfSize, linewidth )
|
||||
* Y_OVERBAR_CORRECTION );
|
||||
|
||||
// Gives room for line thickess and margin
|
||||
y += linewidth // for line thickess
|
||||
|
|
|
@ -865,18 +865,20 @@ void SCH_EDIT_FRAME::OnRotate( wxCommandEvent& aEvent )
|
|||
case SCH_GLOBAL_LABEL_T:
|
||||
case SCH_HIERARCHICAL_LABEL_T:
|
||||
m_canvas->MoveCursorToCrossHair();
|
||||
ChangeTextOrient( (SCH_TEXT*) item, &dc );
|
||||
ChangeTextOrient( (SCH_TEXT*) item );
|
||||
m_canvas->Refresh();
|
||||
break;
|
||||
|
||||
case SCH_FIELD_T:
|
||||
m_canvas->MoveCursorToCrossHair();
|
||||
RotateField( (SCH_FIELD*) item, &dc );
|
||||
RotateField( (SCH_FIELD*) item );
|
||||
if( item->GetParent()->Type() == SCH_COMPONENT_T )
|
||||
{
|
||||
// Now that we're moving a field, they're no longer autoplaced.
|
||||
SCH_COMPONENT *parent = static_cast<SCH_COMPONENT*>( item->GetParent() );
|
||||
parent->ClearFieldsAutoplaced();
|
||||
}
|
||||
m_canvas->Refresh();
|
||||
break;
|
||||
|
||||
case SCH_BITMAP_T:
|
||||
|
|
|
@ -910,7 +910,7 @@ private:
|
|||
// Text, label, glabel
|
||||
SCH_TEXT* CreateNewText( wxDC* aDC, int aType );
|
||||
void EditSchematicText( SCH_TEXT* TextStruct );
|
||||
void ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC );
|
||||
void ChangeTextOrient( SCH_TEXT* aTextItem );
|
||||
|
||||
/**
|
||||
* Function OnCovertTextType
|
||||
|
@ -1113,7 +1113,7 @@ private:
|
|||
*/
|
||||
void EditComponentFieldText( SCH_FIELD* aField );
|
||||
|
||||
void RotateField( SCH_FIELD* aField, wxDC* aDC );
|
||||
void RotateField( SCH_FIELD* aField );
|
||||
|
||||
/**
|
||||
* Function PastListOfItems
|
||||
|
|
|
@ -80,14 +80,6 @@ int GetPenSizeForBold( int aTextSize );
|
|||
*/
|
||||
int GraphicTextWidth( const wxString& aText, const wxSize& aSize, bool italic, bool bold );
|
||||
|
||||
/**
|
||||
* @return the verical position of the overbar of a text
|
||||
* (relative to a horizontal text)
|
||||
* @param aVTextSize = the text vertical size
|
||||
* @param aThickness = the thickness of text
|
||||
*/
|
||||
int OverbarPositionY( int aVTextSize, int aThickness );
|
||||
|
||||
/**
|
||||
* Function DrawGraphicText
|
||||
* Draw a graphic text (like module texts)
|
||||
|
|
|
@ -84,6 +84,14 @@ public:
|
|||
m_glyphSize = aGlyphSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current glyph size.
|
||||
*/
|
||||
VECTOR2D GetGlyphSize() const
|
||||
{
|
||||
return m_glyphSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a bold property of current font.
|
||||
*
|
||||
|
@ -144,7 +152,31 @@ public:
|
|||
m_gal = aGal;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Compute the vertical position of an overbar, sometimes used in texts.
|
||||
* This is the distance between the text base line and the overbar.
|
||||
* @return the relative position of the overbar axis.
|
||||
*/
|
||||
static double ComputeOverbarVerticalPosition( double aGlyphHeight, double aGlyphThickness );
|
||||
|
||||
/**
|
||||
* @brief Compute the X and Y size of a given text. The text is expected to be
|
||||
* a only one line text.
|
||||
*
|
||||
* @param aText is the text string (one line).
|
||||
* @return the text size.
|
||||
*/
|
||||
static double GetInterline( double aGlyphHeight, double aGlyphThickness );
|
||||
|
||||
private:
|
||||
GAL* m_gal; ///< Pointer to the GAL
|
||||
GLYPH_LIST m_glyphs; ///< Glyph list
|
||||
std::vector<BOX2D> m_glyphBoundingBoxes; ///< Bounding boxes of the glyphs
|
||||
VECTOR2D m_glyphSize; ///< Size of the glyphs
|
||||
EDA_TEXT_HJUSTIFY_T m_horizontalJustify; ///< Horizontal justification
|
||||
EDA_TEXT_VJUSTIFY_T m_verticalJustify; ///< Vertical justification
|
||||
bool m_bold, m_italic, m_mirrored, m_overbar; ///< Properties of text
|
||||
|
||||
/**
|
||||
* @brief Compute the X and Y size of a given text. The text is expected to be
|
||||
* a only one line text.
|
||||
|
@ -161,15 +193,6 @@ protected:
|
|||
*/
|
||||
double computeOverbarVerticalPosition() const;
|
||||
|
||||
private:
|
||||
GAL* m_gal; ///< Pointer to the GAL
|
||||
GLYPH_LIST m_glyphs; ///< Glyph list
|
||||
std::vector<BOX2D> m_glyphBoundingBoxes; ///< Bounding boxes of the glyphs
|
||||
VECTOR2D m_glyphSize; ///< Size of the glyphs
|
||||
EDA_TEXT_HJUSTIFY_T m_horizontalJustify; ///< Horizontal justification
|
||||
EDA_TEXT_VJUSTIFY_T m_verticalJustify; ///< Vertical justification
|
||||
bool m_bold, m_italic, m_mirrored, m_overbar; ///< Properties of text
|
||||
|
||||
/**
|
||||
* @brief Returns a single line height using current settings.
|
||||
*
|
||||
|
@ -222,13 +245,6 @@ private:
|
|||
///> on dY relative coordinates to give a tilst shape
|
||||
static const double ITALIC_TILT;
|
||||
|
||||
public:
|
||||
// These members are declared public only to be (temporary, I am expecting)
|
||||
// used in legacy canvas, to avoid multiple declarations of the same constants,
|
||||
// having multiple declarations of the same constants is really a thing to avoid.
|
||||
//
|
||||
// They will be private later, when the legacy canvas is removed.
|
||||
|
||||
///> Factor that determines the pitch between 2 lines.
|
||||
static const double INTERLINE_PITCH_RATIO;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue