From bc699c8d8f76fa8535e1a551b337720af3817849 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 23 Mar 2016 13:16:27 +0100 Subject: [PATCH] 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. --- common/drawtxt.cpp | 8 ---- common/eda_text.cpp | 7 ++-- common/gal/stroke_font.cpp | 20 +++++++++- eeschema/edit_component_in_schematic.cpp | 10 ++--- eeschema/edit_label.cpp | 6 +-- eeschema/sch_text.cpp | 15 ++++--- eeschema/schedit.cpp | 6 ++- eeschema/schframe.h | 4 +- include/drawtxt.h | 8 ---- include/gal/stroke_font.h | 50 ++++++++++++++++-------- 10 files changed, 72 insertions(+), 62 deletions(-) diff --git a/common/drawtxt.cpp b/common/drawtxt.cpp index 47ca3e987c..0114eb3724 100644 --- a/common/drawtxt.cpp +++ b/common/drawtxt.cpp @@ -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 diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 7c3733c86e..4d1bf0ce16 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -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 ) ); } diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp index 94e505f3fb..d490ccb28c 100644 --- a/common/gal/stroke_font.cpp +++ b/common/gal/stroke_font.cpp @@ -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() ); } diff --git a/eeschema/edit_component_in_schematic.cpp b/eeschema/edit_component_in_schematic.cpp index c9294a59cd..9f563b06ab 100644 --- a/eeschema/edit_component_in_schematic.cpp +++ b/eeschema/edit_component_in_schematic.cpp @@ -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 - * 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(); } diff --git a/eeschema/edit_label.cpp b/eeschema/edit_label.cpp index e343262b11..15e4b10c24 100644 --- a/eeschema/edit_label.cpp +++ b/eeschema/edit_label.cpp @@ -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 ); } diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index be2a0b84be..4f8fd8444f 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -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 - * 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 #include #include #include -#include #include #include #include #include -#include #include +#include -#include #include #include #include @@ -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 & 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 diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 97bb4b73b1..7457fdfc3f 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -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( item->GetParent() ); parent->ClearFieldsAutoplaced(); } + m_canvas->Refresh(); break; case SCH_BITMAP_T: diff --git a/eeschema/schframe.h b/eeschema/schframe.h index 59f65cfa85..daf348f1bb 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -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 diff --git a/include/drawtxt.h b/include/drawtxt.h index d2cc599640..faf61cf120 100644 --- a/include/drawtxt.h +++ b/include/drawtxt.h @@ -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) diff --git a/include/gal/stroke_font.h b/include/gal/stroke_font.h index 7b9aa3bf0d..c4fbf96aa9 100644 --- a/include/gal/stroke_font.h +++ b/include/gal/stroke_font.h @@ -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 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 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; };