/* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 Jean-Pierre Charras, jpe.charras at wanadoo.fr * Copyright (C) 2004-2017 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 * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, you may find one here: * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * or you may search the http://www.gnu.org website for the version 2 license, * or you may write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ /** * @file eda_text.h * @brief Definition of base KiCad text object. */ #ifndef EDA_TEXT_H_ #define EDA_TEXT_H_ #include // NORMALIZE_ANGLE_POS( angle ); #include // wxStringSplit #include // EDA_DRAW_MODE_T #include // EDA_RECT // part of the kicad_plugin.h family of defines. // See kicad_plugin.h for the choice of the value // When set when calling EDA_TEXT::Format, disable writing the "hide" keyword in save file #define CTL_OMIT_HIDE (1 << 6) // Graphic Text justify: // Values -1,0,1 are used in computations, do not change them enum EDA_TEXT_HJUSTIFY_T { GR_TEXT_HJUSTIFY_LEFT = -1, GR_TEXT_HJUSTIFY_CENTER = 0, GR_TEXT_HJUSTIFY_RIGHT = 1 }; enum EDA_TEXT_VJUSTIFY_T { GR_TEXT_VJUSTIFY_TOP = -1, GR_TEXT_VJUSTIFY_CENTER = 0, GR_TEXT_VJUSTIFY_BOTTOM = 1 }; /* Options to draw items with thickness ( segments, arcs, circles, texts...) */ enum EDA_DRAW_MODE_T { FILLED = true, // normal mode: solid segments SKETCH = false // sketch mode: draw segments outlines only }; /** This is the "default-of-the-default" hardcoded text size; individual * application define their own default policy starting with this * (usually with a user option or project). **/ #define DEFAULT_SIZE_TEXT 50 // default text height (in mils, i.e. 1/1000") #define DIM_ANCRE_TEXTE 2 // Anchor size for text /** * Struct TEXT_EFFECTS * is a bucket for text effects. These fields are bundled so they * can be easily copied together as a lot. The privacy policy is established * by client (incorporating) code. */ struct TEXT_EFFECTS { TEXT_EFFECTS( int aSetOfBits = 0 ) : bits( aSetOfBits ), hjustify( GR_TEXT_HJUSTIFY_CENTER ), vjustify( GR_TEXT_VJUSTIFY_CENTER ), penwidth( 0 ), angle( 0.0 ) {} short bits; ///< any set of booleans a client uses. signed char hjustify; ///< horizontal justification signed char vjustify; ///< vertical justification wxSize size; int penwidth; double angle; ///< now: 0.1 degrees; future: degrees wxPoint pos; void Bit( int aBit, bool aValue ) { aValue ? bits |= (1<& aCornerBuffer ) const; /** * Function TextHitTest * Test if \a aPoint is within the bounds of this object. * @param aPoint- A wxPoint to test * @param aAccuracy - Amount to inflate the bounding box. * @return bool - true if a hit, else false */ virtual bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const; /** * Function TextHitTest (overloaded) * Tests if object bounding box is contained within or intersects \a aRect. * * @param aRect - Rect to test against. * @param aContains - Test for containment instead of intersection if true. * @param aAccuracy - Amount to inflate the bounding box. * @return bool - true if a hit, else false */ virtual bool TextHitTest( const EDA_RECT& aRect, bool aContains = false, int aAccuracy = 0 ) const; /** * Function LenSize * @return the text length in internal units * @param aLine : the line of text to consider. * For single line text, this parameter is always m_Text */ int LenSize( const wxString& aLine ) const; /** * Function GetTextBox * useful in multiline texts to calculate the full text or a line area (for * zones filling, locate functions....) * @return the rect containing the line of text (i.e. the position and the * size of one line) * this rectangle is calculated for 0 orient text. * If orientation is not 0 the rect must be rotated to match the * physical area * @param aLine The line of text to consider. * for single line text, aLine is unused * If aLine == -1, the full area (considering all lines) is returned * @param aThickness Overrides the current penwidth when greater than 0. * This is needed when the current penwidth is 0 and a default penwidth is used. * @param aInvertY Invert the Y axis when calculating bounding box. */ EDA_RECT GetTextBox( int aLine = -1, int aThickness = -1, bool aInvertY = false ) const; /** * Return the distance between two lines of text. * *

* Calculates the distance (pitch) between two lines of text. This distance includes the * interline distance plus room for characters like j, {, and [. It also used for single * line text, to calculate the text bounding box. *

* * @param aTextThickness Overrides the current thickness when greater than 0. * this is needed when the current m_Thickness is 0 and a default line thickness * is used */ int GetInterline( int aTextThickness = -1 ) const; /** * Function GetTextStyleName * @return a wxString with the style name( Normal, Italic, Bold, Bold+Italic) */ wxString GetTextStyleName(); /** * Function GetPositionsOfLinesOfMultilineText * Populates aPositions with the position of each line of * a multiline text, according to the vertical justification and the * rotation of the whole text * @param aPositions is the list to populate by the wxPoint positions * @param aLineCount is the number of lines (not recalculated here * for efficiency reasons */ void GetPositionsOfLinesOfMultilineText( std::vector& aPositions, int aLineCount ) const; /** * Function Format * outputs the object to \a aFormatter in s-expression form. * * @param aFormatter The #OUTPUTFORMATTER object to write to. * @param aNestLevel The indentation next level. * @param aControlBits The control bit definition for object specific formatting. * @throw IO_ERROR on write error. */ virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const; protected: wxString m_Text; private: /** * Function drawOneLineOfText * draws a single text line. * Used to draw each line of this EDA_TEXT, that can be multiline * @param aClipBox = the clipping rect, or NULL if no clipping * @param aDC = the current Device Context * @param aOffset = draw offset (usually (0,0)) * @param aColor = text color * @param aDrawMode = GR_OR, GR_XOR.., -1 to use the current mode. * @param aFillMode = FILLED or SKETCH * @param aText = the single line of text to draw. * @param aPos = the position of this line ). */ void drawOneLineOfText( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, EDA_DRAW_MODE_T aFillMode, const wxString& aText, const wxPoint& aPos ); // Private text effects data. API above provides accessor funcs. TEXT_EFFECTS m_e; /// EDA_TEXT effects bools enum TE_FLAGS { // start at zero, sequence is irrelevant TE_MIRROR, TE_ITALIC, TE_BOLD, TE_MULTILINE, TE_VISIBLE, }; }; #endif // EDA_TEXT_H_