KiCad PCB EDA Suite
|
Class STROKE_FONT implements stroke font drawing. More...
#include <stroke_font.h>
Public Member Functions | |
STROKE_FONT (GAL *aGal) | |
Constructor. More... | |
bool | LoadNewStrokeFont (const char *const aNewStrokeFont[], int aNewStrokeFontSize) |
Load the new stroke font. More... | |
void | Draw (const UTF8 &aText, const VECTOR2D &aPosition, double aRotationAngle) |
Draw a string. More... | |
void | SetGAL (GAL *aGal) |
Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one. More... | |
VECTOR2D | ComputeStringBoundaryLimits (const UTF8 &aText, const VECTOR2D &aGlyphSize, double aGlyphThickness) const |
Compute the boundary limits of aText (the bounding box of all shapes). More... | |
double | ComputeOverbarVerticalPosition (double aGlyphHeight, double aGlyphThickness) const |
Compute the vertical position of an overbar, sometimes used in texts. More... | |
Static Public Member Functions | |
static double | GetInterline (double aGlyphHeight, double aGlyphThickness) |
Compute the distance (interline) between 2 lines of text (for multiline texts). More... | |
Private Member Functions | |
VECTOR2D | computeTextLineSize (const UTF8 &aText) const |
Compute the X and Y size of a given text. More... | |
double | computeOverbarVerticalPosition () const |
Compute the vertical position of an overbar, sometimes used in texts. More... | |
int | getInterline () const |
Returns a single line height using current settings. More... | |
BOX2D | computeBoundingBox (const GLYPH &aGlyph, const VECTOR2D &aGlyphBoundingX) const |
Compute the bounding box of a given glyph. More... | |
void | drawSingleLineText (const UTF8 &aText) |
Draws a single line of text. More... | |
unsigned | linesCount (const UTF8 &aText) const |
Returns number of lines for a given text. More... | |
Private Attributes | |
GAL * | m_gal |
Pointer to the GAL. More... | |
GLYPH_LIST | m_glyphs |
Glyph list. More... | |
std::vector< BOX2D > | m_glyphBoundingBoxes |
Bounding boxes of the glyphs. More... | |
Static Private Attributes | |
static const double | OVERBAR_POSITION_FACTOR = 1.22 |
More... | |
static const double | BOLD_FACTOR = 1.3 |
More... | |
static const double | STROKE_FONT_SCALE = 1.0 / 21.0 |
More... | |
static const double | ITALIC_TILT = 1.0 / 8 |
More... | |
static const double | INTERLINE_PITCH_RATIO = 1.5 |
More... | |
Friends | |
class | GAL |
Class STROKE_FONT implements stroke font drawing.
A stroke font is composed of lines.
Definition at line 53 of file stroke_font.h.
STROKE_FONT::STROKE_FONT | ( | GAL * | aGal | ) |
|
private |
Compute the bounding box of a given glyph.
aGlyph | is the glyph. |
aGlyphBoundingX | is the x-component of the bounding box size. |
Definition at line 140 of file stroke_font.cpp.
References boundingBox(), BOX2< Vec >::Compute(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by LoadNewStrokeFont().
double STROKE_FONT::ComputeOverbarVerticalPosition | ( | double | aGlyphHeight, |
double | aGlyphThickness | ||
) | const |
Compute the vertical position of an overbar, sometimes used in texts.
This is the distance between the text base line and the overbar.
aGlyphHeight | is the height (vertical size) of the text. |
aGlyphThickness | is the thickness of the lines used to draw the text. |
Definition at line 377 of file stroke_font.cpp.
References OVERBAR_POSITION_FACTOR.
Referenced by computeOverbarVerticalPosition(), EDA_TEXT::GetTextBox(), and SetGAL().
|
private |
Compute the vertical position of an overbar, sometimes used in texts.
This is the distance between the text base line and the overbar.
Definition at line 386 of file stroke_font.cpp.
References ComputeOverbarVerticalPosition(), KIGFX::GAL::GetGlyphSize(), KIGFX::GAL::GetLineWidth(), m_gal, and VECTOR2< T >::y.
Referenced by drawSingleLineText(), and KIGFX::GAL::GetOverbarVerticalPosition().
VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits | ( | const UTF8 & | aText, |
const VECTOR2D & | aGlyphSize, | ||
double | aGlyphThickness | ||
) | const |
Compute the boundary limits of aText (the bounding box of all shapes).
The overbar and alignment are not taken in account, '~' characters are skipped.
Definition at line 400 of file stroke_font.cpp.
References BOX2< Vec >::GetEnd(), GetInterline(), KIGFX::GAL::IsFontItalic(), ITALIC_TILT, m_gal, m_glyphBoundingBoxes, max, UTF8::ubegin(), UTF8::uend(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by computeTextLineSize(), EDA_TEXT::GetTextBox(), and SetGAL().
Compute the X and Y size of a given text.
The text is expected to be a only one line text.
aText | is the text string (one line). |
Definition at line 394 of file stroke_font.cpp.
References ComputeStringBoundaryLimits(), KIGFX::GAL::GetGlyphSize(), KIGFX::GAL::GetLineWidth(), and m_gal.
Referenced by drawSingleLineText(), and KIGFX::GAL::GetTextLineSize().
Draw a string.
aText | is the text to be drawn. |
aPosition | is the text position in world coordinates. |
aRotationAngle | is the text rotation angle in radians. |
Definition at line 164 of file stroke_font.cpp.
References BOLD_FACTOR, drawSingleLineText(), UTF8::empty(), UTF8::find(), KIGFX::GAL::GetGlyphSize(), getInterline(), KIGFX::GAL::GetLineWidth(), KIGFX::GAL::GetVerticalJustify(), GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, KIGFX::GAL::IsFontBold(), linesCount(), m_gal, UTF8::npos, KIGFX::GAL::Restore(), KIGFX::GAL::Rotate(), KIGFX::GAL::Save(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), UTF8::substr(), KIGFX::GAL::Translate(), and VECTOR2< T >::y.
Referenced by KIGFX::GAL::StrokeText().
|
private |
Draws a single line of text.
Multiline texts should be split before using the function.
aText | is the text to be drawn. |
Definition at line 244 of file stroke_font.cpp.
References computeOverbarVerticalPosition(), computeTextLineSize(), KIGFX::GAL::DrawLine(), KIGFX::GAL::DrawPolyline(), BOX2< Vec >::GetEnd(), KIGFX::GAL::GetGlyphSize(), KIGFX::GAL::GetHorizontalJustify(), KIGFX::GAL::GetLineWidth(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, i, KIGFX::GAL::IsFontItalic(), KIGFX::GAL::IsTextMirrored(), ITALIC_TILT, m_gal, m_glyphBoundingBoxes, m_glyphs, ProcessOverbars(), KIGFX::GAL::Restore(), KIGFX::GAL::Save(), KIGFX::GAL::Translate(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by Draw().
|
static |
Compute the distance (interline) between 2 lines of text (for multiline texts).
aGlyphHeight | is the height (vertical size) of the text. |
aGlyphThickness | is the thickness of the lines used to draw the text. |
Definition at line 128 of file stroke_font.cpp.
References INTERLINE_PITCH_RATIO.
Referenced by ComputeStringBoundaryLimits(), SCH_GLOBALLABEL::CreateGraphicShape(), getInterline(), EDA_TEXT::GetInterline(), and SetGAL().
|
private |
Returns a single line height using current settings.
Definition at line 134 of file stroke_font.cpp.
References KIGFX::GAL::GetGlyphSize(), GetInterline(), KIGFX::GAL::GetLineWidth(), KiROUND(), m_gal, and VECTOR2< T >::y.
Referenced by Draw().
|
inlineprivate |
Returns number of lines for a given text.
aText | is the text to be checked. |
Definition at line 169 of file stroke_font.h.
References UTF8::begin(), UTF8::empty(), and UTF8::end().
Referenced by Draw().
bool STROKE_FONT::LoadNewStrokeFont | ( | const char *const | aNewStrokeFont[], |
int | aNewStrokeFontSize | ||
) |
Load the new stroke font.
aNewStrokeFont | is the pointer to the font data. |
aNewStrokeFontSize | is the size of the font data. |
Definition at line 49 of file stroke_font.cpp.
References computeBoundingBox(), FONT_OFFSET, i, m_glyphBoundingBoxes, m_glyphs, STROKE_FONT_SCALE, VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by KIGFX::GAL::GAL().
|
inline |
Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one.
aGal | is the new GAL instance. |
Definition at line 84 of file stroke_font.h.
References ComputeOverbarVerticalPosition(), ComputeStringBoundaryLimits(), GetInterline(), and m_gal.
|
friend |
Definition at line 55 of file stroke_font.h.
|
staticprivate |
Factor that determines relative line width for bold text.
Definition at line 182 of file stroke_font.h.
Referenced by Draw().
|
staticprivate |
Factor that determines the pitch between 2 lines.
Definition at line 192 of file stroke_font.h.
Referenced by GetInterline().
|
staticprivate |
Tilt factor for italic style (the is is the scaling factor on dY relative coordinates to give a tilst shape
Definition at line 189 of file stroke_font.h.
Referenced by ComputeStringBoundaryLimits(), and drawSingleLineText().
|
private |
Pointer to the GAL.
Definition at line 119 of file stroke_font.h.
Referenced by computeOverbarVerticalPosition(), ComputeStringBoundaryLimits(), computeTextLineSize(), Draw(), drawSingleLineText(), getInterline(), and SetGAL().
|
private |
Bounding boxes of the glyphs.
Definition at line 121 of file stroke_font.h.
Referenced by ComputeStringBoundaryLimits(), drawSingleLineText(), and LoadNewStrokeFont().
|
private |
Glyph list.
Definition at line 120 of file stroke_font.h.
Referenced by drawSingleLineText(), and LoadNewStrokeFont().
|
staticprivate |
Factor that determines relative vertical position of the overbar.
Definition at line 179 of file stroke_font.h.
Referenced by ComputeOverbarVerticalPosition().
|
staticprivate |
Scale factor for a glyph
Definition at line 185 of file stroke_font.h.
Referenced by LoadNewStrokeFont().