drawtxt.h 6.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2009-2014 Jerry Jacobs
 * Copyright (C) 1992-2014 KiCad Developers, see CHANGELOG.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
 */

25 26 27 28 29 30 31 32 33
/**
 * This file is part of the common libary
 * @file  drawtxt.h
 * @see   common.h
 */

#ifndef __INCLUDE__DRAWTXT_H__
#define __INCLUDE__DRAWTXT_H__ 1

34
#include <base_struct.h>
35
#include <eda_text.h>               // EDA_TEXT_HJUSTIFY_T and EDA_TEXT_VJUSTIFY_T
36

37 38 39 40 41 42
/* Minimum dimension in pixel for drawing/no drawing a text
 * used in Pcbnew to decide to draw (or not) some texts
 * ( like net names on pads/tracks )
 * When a text height is smaller than MIN_TEXT_SIZE,
 * it is not drawn by Pcbnew
 */
43 44
#define MIN_TEXT_SIZE   5

45 46 47 48 49 50
/* Absolute minimum dimension in pixel to draw a text as text or a line
 * When a text height is smaller than MIN_DRAWABLE_TEXT_SIZE,
 * it is drawn, but like a line by the draw text function
*/
#define MIN_DRAWABLE_TEXT_SIZE 3

51
class EDA_DRAW_PANEL;
52
class PLOTTER;
53

54 55
/**
 * Function  Clamp_Text_PenSize
56
 *As a rule, pen width should not be >1/4em, otherwise the character
57 58 59 60 61 62 63 64 65 66 67
 * will be cluttered up in its own fatness
 * The pen width max is aSize/4 for bold texts, and aSize/6 for normal texts
 * The "best" pen width is aSize/5 for bold texts,
 * so the clamp is consistant with bold option.
 * @param aPenSize = the pen size to clamp
 * @param aSize the char size (height or width, od its wxSize)
 * @param aBold = true if text accept bold pen size
 * @return the max pen size allowed
 */
int Clamp_Text_PenSize( int aPenSize, int aSize, bool aBold = true );
int Clamp_Text_PenSize( int aPenSize, wxSize aSize, bool aBold = true );
68

69 70
/**
 * Function GetPensizeForBold
71 72 73 74 75
 * @return the "best" value for a pen size to draw/plot a bold text
 * @param aTextSize = the char size (height or width)
 */
int GetPenSizeForBold( int aTextSize );

76
/**
77
 * Function GraphicTextWidth
charras's avatar
charras committed
78
 * @return the X size of the graphic text
79
 * the full X size is GraphicTextWidth + the thickness of graphic lines
charras's avatar
charras committed
80
 */
81
int GraphicTextWidth( const wxString& aText, int size_h, bool italic, bool bold );
charras's avatar
charras committed
82

83 84
/**
 * Function NegableTextLength
85 86 87
 * Return the text length of a negable string, excluding the ~ markers */
int NegableTextLength( const wxString& aText );

88 89 90 91 92 93
/**
 * Helper function for texts with over bar, can be used as strut value
 * for multiline text (add interline spacing)
 */
int OverbarPositionY( int size_v );

94 95
/**
 * Function DrawGraphicText
96
 * Draw a graphic text (like module texts)
97
 *  @param aClipBox = the clipping rect, or NULL if no clipping
98
 *  @param aDC = the current Device Context. NULL if draw within a 3D GL Canvas
99
 *  @param aPos = text position (according to h_justify, v_justify)
100
 *  @param aColor (enum EDA_COLOR_T) = text color
101 102 103 104 105 106 107
 *  @param aText = text to draw
 *  @param aOrient = angle in 0.1 degree
 *  @param aSize = text size (size.x or size.y can be < 0 for mirrored texts)
 *  @param aH_justify = horizontal justification (Left, center, right)
 *  @param aV_justify = vertical justification (bottom, center, top)
 *  @param aWidth = line width (pen width) (default = 0)
 *      if width < 0 : draw segments in sketch mode, width = abs(width)
108
 *      Use a value min(aSize.x, aSize.y) / 5 for a bold text
109
 *  @param aItalic = true to simulate an italic font
charras's avatar
charras committed
110
 *  @param aBold = true to use a bold font
111
 *  @param aCallback() = function called (if non null) to draw each segment.
112
 *                  used to draw 3D texts or for plotting, NULL for normal drawings
113 114
 *  @param aPlotter = a pointer to a PLOTTER instance, when this function is used to plot
 *                  the text. NULL to draw this text.
115
 */
116
void DrawGraphicText( EDA_RECT* aClipBox,
117 118
                      wxDC * aDC,
                      const wxPoint &aPos,
119
                      enum EDA_COLOR_T aColor,
120
                      const wxString &aText,
121
                      double aOrient,
122
                      const wxSize &aSize,
123 124
                      enum EDA_TEXT_HJUSTIFY_T aH_justify,
                      enum EDA_TEXT_VJUSTIFY_T aV_justify,
charras's avatar
charras committed
125 126
                      int aWidth,
                      bool aItalic,
127
                      bool aBold,
128
                      void (*aCallback)( int x0, int y0, int xf, int yf ) = NULL,
129
                      PLOTTER * aPlotter = NULL );
130 131


132 133 134 135 136 137
/**
 * Draw graphic text with a border, so that it can be read on different
 * backgrounds. See DrawGraphicText for most of the parameters.
 * If aBgColor is a dark color text is drawn in aColor2 with aColor1
 * border; otherwise colors are swapped.
 */
138
void DrawGraphicHaloText( EDA_RECT* aClipBox,
139 140 141 142 143 144
                          wxDC * aDC,
                          const wxPoint &aPos,
                          enum EDA_COLOR_T aBgColor,
                          enum EDA_COLOR_T aColor1,
                          enum EDA_COLOR_T aColor2,
                          const wxString &aText,
145
                          double aOrient,
146 147 148 149 150 151 152 153 154
                          const wxSize &aSize,
                          enum EDA_TEXT_HJUSTIFY_T aH_justify,
                          enum EDA_TEXT_VJUSTIFY_T aV_justify,
                          int aWidth,
                          bool aItalic,
                          bool aBold,
                          void (*aCallback)( int x0, int y0, int xf, int yf ) = NULL,
                          PLOTTER * aPlotter = NULL );

155
#endif /* __INCLUDE__DRAWTXT_H__ */