You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.7 KiB

17 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009-2014 Jerry Jacobs
  5. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef GR_TEXT_H
  25. #define GR_TEXT_H
  26. #include <eda_item.h>
  27. #include <font/text_attributes.h>
  28. namespace KIGFX
  29. {
  30. class COLOR4D;
  31. }
  32. namespace KIFONT
  33. {
  34. class METRICS;
  35. }
  36. class PLOTTER;
  37. /**
  38. * Pen width should not allow characters to become cluttered up in their own fatness. Normal
  39. * text is normally around 15% the fontsize, and bold text around 20%. So we set a hard limit
  40. * at 25%, and a secondary limit for non-decorative text that must be readable at small sizes
  41. * at 18%.
  42. *
  43. * @param aPenSize the pen size to clamp.
  44. * @param aSize the char size (height or width, or its wxSize).
  45. * @param aBold true if text accept bold pen size.
  46. * @return the max pen size allowed.
  47. */
  48. int Clamp_Text_PenSize( int aPenSize, int aSize, bool aStrict = false );
  49. float Clamp_Text_PenSize( float aPenSize, int aSize, bool aStrict = false );
  50. int Clamp_Text_PenSize( int aPenSize, const VECTOR2I& aSize, bool aStrict = false );
  51. /**
  52. * @param aTextSize the char size (height or width).
  53. * @return the "best" value for a pen size to draw/plot a bold text.
  54. */
  55. int GetPenSizeForBold( int aTextSize );
  56. int GetPenSizeForBold( const wxSize& aTextSize );
  57. /**
  58. * @param aTextSize the char size (height or width).
  59. * @return the "best" value for a pen size to draw/plot a demibold text.
  60. */
  61. int GetPenSizeForDemiBold( int aTextSize );
  62. int GetPenSizeForDemiBold( const wxSize& aTextSize );
  63. /**
  64. * @param aTextSize = the char size (height or width).
  65. * @return the "best" value for a pen size to draw/plot a non-bold text.
  66. */
  67. int GetPenSizeForNormal( int aTextSize );
  68. int GetPenSizeForNormal( const wxSize& aTextSize );
  69. inline void InferBold( TEXT_ATTRIBUTES* aAttrs )
  70. {
  71. int penSize( aAttrs->m_StrokeWidth );
  72. wxSize textSize( aAttrs->m_Size.x, aAttrs->m_Size.y );
  73. aAttrs->m_Bold = abs( penSize - GetPenSizeForBold( textSize ) )
  74. < abs( penSize - GetPenSizeForNormal( textSize ) );
  75. }
  76. /**
  77. * Returns the margin for knocking out text.
  78. */
  79. inline int GetKnockoutTextMargin( const VECTOR2I& aSize, int aThickness )
  80. {
  81. return std::max( KiROUND( aThickness / 2 ), KiROUND( aSize.y / 9.0 ) );
  82. }
  83. /**
  84. * @return the X size of the graphic text.
  85. */
  86. int GRTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize,
  87. int aThickness, bool aBold, bool aItalic, const KIFONT::METRICS& aFontMetrics );
  88. /**
  89. * Print a graphic text through wxDC.
  90. *
  91. * @param aDC is the current Device Context.
  92. * @param aPos is the text position (according to h_justify, v_justify).
  93. * @param aColor is the text color.
  94. * @param aText is the text to draw.
  95. * @param aOrient is the angle.
  96. * @param aSize is the text size (size.x or size.y can be < 0 for mirrored texts).
  97. * @param aH_justify is the horizontal justification (Left, center, right).
  98. * @param aV_justify is the vertical justification (bottom, center, top).
  99. * @param aWidth is the line width (pen width) (use default width if aWidth = 0).
  100. * if width < 0 : draw segments in sketch mode, width = abs(width)
  101. * Use a value min(aSize.x, aSize.y) / 5 for a bold text.
  102. * @param aItalic is the true to simulate an italic font.
  103. * @param aBold use true to use a bold font. Useful only with default width value (aWidth = 0).
  104. * @param aFont is the font to use, or nullptr for the KiCad stroke font
  105. */
  106. void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const KIGFX::COLOR4D& aColor,
  107. const wxString& aText, const EDA_ANGLE& aOrient, const VECTOR2I& aSize,
  108. enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify,
  109. int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont,
  110. const KIFONT::METRICS& aFontMetrics );
  111. #endif /* GR_TEXT_H */