~kicad-product-committers/kicad/kicad-gal

« back to all changes in this revision

Viewing changes to gal/common/stroke_font.h

  • Committer: torstenhtr at gmx
  • Date: 2012-08-04 14:55:55 UTC
  • Revision ID: torstenhtr@gmx.de-20120804145555-jbm9k193p1tth439
Cleaned up the files.
Repaired and improved the test examples.
Added the wxDC backend.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * This program source code file is part of KICAD, a free EDA CAD application.
3
3
 *
4
 
 * Copyright (C) 2010 Virtenio GmbH, Torsten Hueter, torsten.hueter <at> virtenio.de
5
 
 * Copyright (C) 2007 Kicad Developers, see change_log.txt for contributors.
 
4
 * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
 
5
 * Copyright (C) 2012 Kicad Developers, see change_log.txt for contributors.
6
6
 *
7
7
 * Stroke font class
8
8
 *
38
38
#include <gal/common/graphics_abstraction_layer.h>
39
39
#include <math/vector2d.h>
40
40
 
41
 
typedef std::deque<POINTS>      Glyph;
42
 
typedef std::deque<Glyph>       GlyphList;
 
41
typedef std::deque<POINTS2D> Glyph;
 
42
typedef std::deque<Glyph> GlyphList;
43
43
 
 
44
/// Horizontal justification types
44
45
enum HorizontalJustify
45
46
{
46
 
    HORIZONTAL_JUSTIFY_LEFT = -1, HORIZONTAL_JUSTIFY_CENTER = 0, HORIZONTAL_JUSTIFY_RIGHT = 1
 
47
    HORIZONTAL_JUSTIFY_LEFT = -1,   ///< Left justified
 
48
    HORIZONTAL_JUSTIFY_CENTER = 0,  ///< Centered
 
49
    HORIZONTAL_JUSTIFY_RIGHT = 1    ///< Right justified
47
50
};
48
51
 
49
 
 
 
52
/// Vertical justification types
50
53
enum VerticalJustify
51
54
{
52
 
    VERTICAL_JUSTIFY_TOP = -1, VERTICAL_JUSTIFY_CENTER = 0, VERTICAL_JUSTIFY_BOTTOM = 1
 
55
    VERTICAL_JUSTIFY_TOP = -1,      ///< Top justified
 
56
    VERTICAL_JUSTIFY_CENTER = 0,    ///< Centered
 
57
    VERTICAL_JUSTIFY_BOTTOM = 1     ///< Bottom justified
53
58
};
54
59
 
55
 
 
 
60
/**
 
61
 * @brief Class STROKE_FONT implements stroke font drawing.
 
62
 *
 
63
 * A stroke font is composed of lines.
 
64
 */
56
65
class STROKE_FONT
57
66
{
58
67
public:
59
 
    // Constructors
 
68
    /// Constructor
60
69
    STROKE_FONT();
61
70
 
62
 
    // Destructor
63
 
    virtual ~STROKE_FONT();
 
71
    /// Destructor
 
72
    ~STROKE_FONT();
64
73
 
65
74
    // TODO Load font from a text file
66
75
 
67
 
    //! @brief Load the new stroke font
68
 
    //! @param newStrokeFont Pointer to the font data
69
 
    //! @param newStrokeFontSize Size of the font data
 
76
    /**
 
77
     * @brief Load the new stroke font.
 
78
     *
 
79
     * @param aNewStrokeFont is the pointer to the font data.
 
80
     * @param aNewStrokeFontSize is the size of the font data.
 
81
     * @return True, if the font was successfully loaded, else false.
 
82
     */
70
83
    bool LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNewStrokeFontSize );
71
84
 
72
 
    //! @brief Draw a string
73
 
    //! @param text The text to be drawn
74
 
    //! @param position Text position in world coordinates
75
 
    //! @param rotationAngle Text rotation angle
76
 
    void Draw( std::string aText, POINT aPosition, double aRotationAngle );
 
85
    /**
 
86
     * @brief Draw a string.
 
87
     *
 
88
     * @param aText is the text to be drawn.
 
89
     * @param aPosition is the text position in world coordinates.
 
90
     * @param aRotationAngle is the text rotation angle.
 
91
     */
 
92
    void Draw( std::string aText, POINT2D aPosition, double aRotationAngle );
77
93
 
78
 
    //! @brief Set the Graphics Abstraction Layer
79
 
    //! @param gal Pointer to the Graphics Abstraction Layer to draw the text
 
94
    /**
 
95
     * @brief Set the Graphics Abstraction Layer.
 
96
     *
 
97
     * @param aGal is the pointer to the Graphics Abstraction Layer to draw the text.
 
98
     */
80
99
    void SetGraphicsAbstractionLayer( GRAPHICS_ABSTRACTION_LAYER* aGal );
81
100
 
82
 
    //! @brief Set the scale factor of the font for the glyph size
83
 
    //! @param scaleFactor The scale factor
 
101
    /**
 
102
     * @brief Set the scale factor of the font for the glyph size.
 
103
     *
 
104
     * @param aScaleFactor is the scale factor of the font.
 
105
     */
84
106
    void SetScaleFactor( const double aScaleFactor );
85
107
 
86
 
    //! @brief Set the glyph size
87
 
    //! @param glyphSize The glyph size
88
 
    void SetGlyphSize( VECTOR2D aGlyphSize );
89
 
 
90
 
    void SetHorizontalJustify( HorizontalJustify aHorizontalJustify );
91
 
    void SetVerticalJustify( VerticalJustify aVerticalJustify );
 
108
    /**
 
109
     * @brief Set the glyph size.
 
110
     *
 
111
     * @param aGlyphSize is the glyph size.
 
112
     */
 
113
    inline void SetGlyphSize( VECTOR2D aGlyphSize )
 
114
    {
 
115
        glyphSize = aGlyphSize;
 
116
    }
 
117
 
 
118
    /**
 
119
     * @brief Set the horizontal justify for text drawing.
 
120
     *
 
121
     * @param aHorizontalJustify is the horizontal justify value.
 
122
     */
 
123
    inline void SetHorizontalJustify( HorizontalJustify aHorizontalJustify )
 
124
    {
 
125
        horizontalJustify = aHorizontalJustify;
 
126
    }
 
127
 
 
128
    /**
 
129
     * @brief Set the vertical justify for text drawing.
 
130
     *
 
131
     * @param aVerticalJustify is the vertical justify value.
 
132
     */
 
133
    inline void SetVerticalJustify( VerticalJustify aVerticalJustify )
 
134
    {
 
135
        verticalJustify = aVerticalJustify;
 
136
    }
92
137
 
93
138
private:
94
 
    GlyphList               m_glyphs;
95
 
    std::deque<BoundingBox> m_glyphBoundingBoxes;
96
 
 
97
 
    GRAPHICS_ABSTRACTION_LAYER* m_gal;
98
 
 
99
 
    double                  m_scaleFactor;
100
 
 
101
 
    VECTOR2D                m_glyphSize;
102
 
    HorizontalJustify       m_horizontalJustify;
103
 
    VerticalJustify         m_verticalJustify;
104
 
 
105
 
    BoundingBox computeBoundingBox( Glyph aGlyph, VECTOR2D aGlyphBoundingX );
 
139
    GRAPHICS_ABSTRACTION_LAYER* graphics;           ///< Pointer to the GAL
 
140
 
 
141
    GlyphList glyphs;                               ///< Glyph list
 
142
    std::deque<BOUNDING_BOX> glyphBoundingBoxes;    ///< Bounding boxes of the glyphs
 
143
    double scaleFactor;                             ///< Scale factor for the glyph
 
144
    VECTOR2D glyphSize;                             ///< Size of the glyphs
 
145
    HorizontalJustify horizontalJustify;            ///< Horizontal justification
 
146
    VerticalJustify verticalJustify;                ///< Vertical justification
 
147
 
 
148
    /**
 
149
     * @brief Compute the bounding box of a given glyph.
 
150
     *
 
151
     * @param aGlyph is the glyph.
 
152
     * @param aGlyphBoundingX is the x-component of the bounding box size.
 
153
     * @return is the complete bounding box size.
 
154
     */
 
155
    BOUNDING_BOX computeBoundingBox( Glyph aGlyph, VECTOR2D aGlyphBoundingX );
 
156
 
 
157
    /**
 
158
     * @brief Compute the size of a given text.
 
159
     *
 
160
     * @param aText is the text string.
 
161
     * @return is the text size.
 
162
     */
106
163
    VECTOR2D computeTextSize( std::string aText );
107
164
};
108
165