KiCad PCB EDA Suite
KIGFX::STROKE_FONT Class Reference

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, VECTOR2D aGlyphSize, double aGlyphThickness, double *aTopLimit=NULL, double *aBottomLimit=NULL) const
 Compute the boundary limits of aText (the bbox of all shapes). More...
 
VECTOR2D ComputeTextLineSize (const UTF8 &aText) const
 Compute the X and Y size of a given text. 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

GALm_gal
 Pointer to the GAL. More...
 
GLYPH_LIST m_glyphs
 Glyph list. More...
 
std::vector< BOX2Dm_glyphBoundingBoxes
 Bounding boxes of the glyphs. More...
 

Static Private Attributes

static const double OVERBAR_POSITION_FACTOR = 1.22
 

Factor that determines relative vertical position of the overbar.

More...
 
static const double BOLD_FACTOR = 1.3
 

Factor that determines relative line width for bold text.

More...
 
static const double STROKE_FONT_SCALE = 1.0 / 21.0
 

Scale factor for a glyph

More...
 
static const double ITALIC_TILT = 1.0 / 8
 

Tilt factor for italic style (the is is the scaling factor on dY relative coordinates to give a tilst shape

More...
 
static const double INTERLINE_PITCH_RATIO = 1.5
 

Factor that determines the pitch between 2 lines.

More...
 

Friends

class GAL
 

Detailed Description

Class STROKE_FONT implements stroke font drawing.

A stroke font is composed of lines.

Definition at line 51 of file stroke_font.h.

Constructor & Destructor Documentation

STROKE_FONT::STROKE_FONT ( GAL aGal)

Constructor.

Definition at line 41 of file stroke_font.cpp.

41  :
42  m_gal( aGal )
43 {
44 }
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:128

Member Function Documentation

BOX2D STROKE_FONT::computeBoundingBox ( const GLYPH aGlyph,
const VECTOR2D aGlyphBoundingX 
) const
private

Compute the bounding box of a given glyph.

Parameters
aGlyphis the glyph.
aGlyphBoundingXis the x-component of the bounding box size.
Returns
is the complete bounding box size.

Definition at line 138 of file stroke_font.cpp.

References boundingBox(), BOX2< Vec >::Compute(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by LoadNewStrokeFont().

139 {
141 
142  std::deque<VECTOR2D> boundingPoints;
143 
144  boundingPoints.push_back( VECTOR2D( aGLYPHBoundingX.x, 0 ) );
145  boundingPoints.push_back( VECTOR2D( aGLYPHBoundingX.y, 0 ) );
146 
147  for( GLYPH::const_iterator pointListIt = aGLYPH.begin(); pointListIt != aGLYPH.end(); ++pointListIt )
148  {
149  for( std::deque<VECTOR2D>::const_iterator pointIt = pointListIt->begin();
150  pointIt != pointListIt->end(); ++pointIt )
151  {
152  boundingPoints.push_back( VECTOR2D( aGLYPHBoundingX.x, pointIt->y ) );
153  }
154  }
155 
156  boundingBox.Compute( boundingPoints );
157 
158  return boundingBox;
159 }
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:79
Class BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated class Vec.
Definition: box2.h:41
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
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.

Parameters
aGlyphHeightis the height (vertical size) of the text.
aGlyphThicknessis the thickness of the lines used to draw the text.
Returns
the relative position of the overbar axis.

Definition at line 385 of file stroke_font.cpp.

References OVERBAR_POSITION_FACTOR.

Referenced by computeOverbarVerticalPosition(), and EDA_TEXT::GetTextBox().

386 {
387  // Static method.
388  // Compute the Y position of the overbar. This is the distance between
389  // the text base line and the overbar axis.
390  return aGlyphHeight * OVERBAR_POSITION_FACTOR + aGlyphThickness;
391 }
static const double OVERBAR_POSITION_FACTOR
Factor that determines relative vertical position of the overbar.
Definition: stroke_font.h:188
double STROKE_FONT::computeOverbarVerticalPosition ( ) const
private

Compute the vertical position of an overbar, sometimes used in texts.

This is the distance between the text base line and the overbar.

Returns
the relative position of the overbar axis.

Definition at line 394 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().

395 {
396  // Compute the Y position of the overbar. This is the distance between
397  // the text base line and the overbar axis.
399 }
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:128
const VECTOR2D & GetGlyphSize() const
double ComputeOverbarVerticalPosition(double aGlyphHeight, double aGlyphThickness) const
Compute the vertical position of an overbar, sometimes used in texts.
double GetLineWidth() const
Get the line width.
VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits ( const UTF8 aText,
VECTOR2D  aGlyphSize,
double  aGlyphThickness,
double *  aTopLimit = NULL,
double *  aBottomLimit = NULL 
) const

Compute the boundary limits of aText (the bbox of all shapes).

The overbar is not taken in account, by ~ are skipped.

Returns
a VECTOR2D giving the h size of line, and the V glyph size and ( if aTopLimit or aBottomLimit not NULL ) the top and bottom limits of the text.

Definition at line 408 of file stroke_font.cpp.

References BOX2< Vec >::GetEnd(), BOX2< Vec >::GetY(), KIGFX::GAL::IsFontItalic(), ITALIC_TILT, m_gal, m_glyphBoundingBoxes, max, min, UTF8::ubegin(), UTF8::uend(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by computeTextLineSize(), and EDA_TEXT::GetTextBox().

411 {
412  VECTOR2D string_bbox;
413  double ymax = 0.0;
414  double ymin = 0.0;
415 
416  for( UTF8::uni_iter it = aText.ubegin(), end = aText.uend(); it < end; ++it )
417  {
418  wxASSERT_MSG( *it != '\n',
419  wxT( "This function is intended to work with single line strings" ) );
420 
421  // If it is double tilda, then it is displayed as a single tilda
422  // If it is single tilda, then it is toggling overbar, so we need to skip it
423  if( *it == '~' )
424  {
425  if( ++it >= end )
426  break;
427  }
428 
429  // Index in the bounding boxes table
430  int dd = *it - ' ';
431 
432  if( dd >= (int) m_glyphBoundingBoxes.size() || dd < 0 )
433  dd = '?' - ' ';
434 
435  const BOX2D& box = m_glyphBoundingBoxes[dd];
436 
437  string_bbox.x += box.GetEnd().x;
438 
439  // Calculate Y min and Y max
440  if( aTopLimit )
441  {
442  ymax = std::max( ymax, box.GetY() );
443  ymax = std::max( ymax, box.GetEnd().y );
444  }
445 
446  if( aBottomLimit )
447  {
448  ymin = std::min( ymin, box.GetY() );
449  ymin = std::min( ymin, box.GetEnd().y );
450  }
451  }
452 
453  string_bbox.x *= aGlyphSize.x;
454  string_bbox.x += aGlyphThickness;
455  string_bbox.y = aGlyphSize.y + aGlyphThickness;
456 
457  // For italic correction, take in account italic tilt
458  if( m_gal->IsFontItalic() )
459  string_bbox.x += string_bbox.y * STROKE_FONT::ITALIC_TILT;
460 
461  if( aTopLimit )
462  *aTopLimit = ymax * aGlyphSize.y;
463 
464  if( aBottomLimit )
465  *aBottomLimit = ymin * aGlyphSize.y;
466 
467  return string_bbox;
468 }
coord_type GetY() const
Definition: box2.h:179
const Vec GetEnd() const
Definition: box2.h:183
std::vector< BOX2D > m_glyphBoundingBoxes
Bounding boxes of the glyphs.
Definition: stroke_font.h:130
static const double ITALIC_TILT
Tilt factor for italic style (the is is the scaling factor on dY relative coordinates to give a tilst...
Definition: stroke_font.h:198
Class BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated class Vec.
Definition: box2.h:41
uni_iter ubegin() const
Function ubegin returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:216
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:128
class uni_iter is a non-muting iterator that walks through unicode code points in the UTF8 encoded st...
Definition: utf8.h:137
uni_iter uend() const
Function uend returns a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:225
#define max(a, b)
Definition: auxiliary.h:86
bool IsFontItalic() const
Returns true if current font has 'italic' attribute enabled.
#define min(a, b)
Definition: auxiliary.h:85
VECTOR2D KIGFX::STROKE_FONT::ComputeTextLineSize ( const UTF8 aText) const

Compute the X and Y size of a given text.

The text is expected to be a only one line text.

Parameters
aTextis the text string (one line).
Returns
the text size.
VECTOR2D STROKE_FONT::computeTextLineSize ( const UTF8 aText) const
private

Compute the X and Y size of a given text.

The text is expected to be a only one line text.

Parameters
aTextis the text string (one line).
Returns
the text size.

Definition at line 402 of file stroke_font.cpp.

References ComputeStringBoundaryLimits(), KIGFX::GAL::GetGlyphSize(), KIGFX::GAL::GetLineWidth(), and m_gal.

Referenced by drawSingleLineText(), and KIGFX::GAL::GetTextLineSize().

403 {
405 }
VECTOR2D ComputeStringBoundaryLimits(const UTF8 &aText, VECTOR2D aGlyphSize, double aGlyphThickness, double *aTopLimit=NULL, double *aBottomLimit=NULL) const
Compute the boundary limits of aText (the bbox of all shapes).
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:128
const VECTOR2D & GetGlyphSize() const
double GetLineWidth() const
Get the line width.
void STROKE_FONT::Draw ( const UTF8 aText,
const VECTOR2D aPosition,
double  aRotationAngle 
)

Draw a string.

Parameters
aTextis the text to be drawn.
aPositionis the text position in world coordinates.
aRotationAngleis the text rotation angle.

Definition at line 162 of file stroke_font.cpp.

References BOLD_FACTOR, drawSingleLineText(), 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, 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().

163 {
164  if( aText.empty() )
165  return;
166 
167  // Context needs to be saved before any transformations
168  m_gal->Save();
169 
170  m_gal->Translate( aPosition );
171  m_gal->Rotate( -aRotationAngle );
172 
173  // Single line height
174  int lineHeight = getInterline( );
175  int lineCount = linesCount( aText );
176  const VECTOR2D& glyphSize = m_gal->GetGlyphSize();
177 
178  // align the 1st line of text
179  switch( m_gal->GetVerticalJustify() )
180  {
182  m_gal->Translate( VECTOR2D( 0, glyphSize.y ) );
183  break;
184 
186  m_gal->Translate( VECTOR2D( 0, glyphSize.y / 2.0 ) );
187  break;
188 
190  break;
191 
192  default:
193  break;
194  }
195 
196  if( lineCount > 1 )
197  {
198  switch( m_gal->GetVerticalJustify() )
199  {
201  break;
202 
204  m_gal->Translate( VECTOR2D(0, -( lineCount - 1 ) * lineHeight / 2) );
205  break;
206 
208  m_gal->Translate( VECTOR2D(0, -( lineCount - 1 ) * lineHeight ) );
209  break;
210  }
211  }
212 
213  m_gal->SetIsStroke( true );
214  //m_gal->SetIsFill( false );
215 
216  if( m_gal->IsFontBold() )
218 
219  // Split multiline strings into separate ones and draw them line by line
220  size_t begin = 0;
221  size_t newlinePos = aText.find( '\n' );
222 
223  while( newlinePos != aText.npos )
224  {
225  size_t length = newlinePos - begin;
226 
227  drawSingleLineText( aText.substr( begin, length ) );
228  m_gal->Translate( VECTOR2D( 0.0, lineHeight ) );
229 
230  begin = newlinePos + 1;
231  newlinePos = aText.find( '\n', begin );
232  }
233 
234  // Draw the last (or the only one) line
235  if( !aText.empty() )
236  drawSingleLineText( aText.substr( begin ) );
237 
238  m_gal->Restore();
239 }
EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
Returns current text vertical justification setting.
static const double BOLD_FACTOR
Factor that determines relative line width for bold text.
Definition: stroke_font.h:191
virtual void Rotate(double aAngle)
Rotate the context.
UTF8 substr(size_t pos=0, size_t len=npos) const
Definition: utf8.h:104
virtual void SetLineWidth(double aLineWidth)
Set the line width.
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:128
bool IsFontBold() const
Returns true if current font has 'bold' attribute enabled.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
const VECTOR2D & GetGlyphSize() const
unsigned linesCount(const UTF8 &aText) const
Returns number of lines for a given text.
Definition: stroke_font.h:178
void drawSingleLineText(const UTF8 &aText)
Draws a single line of text.
virtual void Restore()
Restore the context.
double GetLineWidth() const
Get the line width.
virtual void Save()
Save the context.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
int getInterline() const
Returns a single line height using current settings.
void STROKE_FONT::drawSingleLineText ( const UTF8 aText)
private

Draws a single line of text.

Multiline texts should be split before using the function.

Parameters
aTextis the text to be drawn.

Definition at line 242 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, KIGFX::GAL::IsFontItalic(), KIGFX::GAL::IsTextMirrored(), ITALIC_TILT, m_gal, m_glyphBoundingBoxes, m_glyphs, KIGFX::GAL::Restore(), KIGFX::GAL::Save(), KIGFX::GAL::Translate(), UTF8::ubegin(), UTF8::uend(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Draw().

243 {
244  // By default the overbar is turned off
245  bool overbar = false;
246 
247  double xOffset;
248  VECTOR2D glyphSize( m_gal->GetGlyphSize() );
249  double overbar_italic_comp = computeOverbarVerticalPosition() * ITALIC_TILT;
250 
251  if( m_gal->IsTextMirrored() )
252  overbar_italic_comp = -overbar_italic_comp;
253 
254  // Compute the text size
255  VECTOR2D textSize = computeTextLineSize( aText );
256  double half_thickness = m_gal->GetLineWidth()/2;
257 
258  // Context needs to be saved before any transformations
259  m_gal->Save();
260 
261  // First adjust: the text X position is corrected by half_thickness
262  // because when the text with thickness is draw, its full size is textSize,
263  // but the position of lines is half_thickness to textSize - half_thickness
264  // so we must translate the coordinates by half_thickness on the X axis
265  // to place the text inside the 0 to textSize X area.
266  m_gal->Translate( VECTOR2D( half_thickness, 0 ) );
267 
268  // Adjust the text position to the given horizontal justification
269  switch( m_gal->GetHorizontalJustify() )
270  {
272  m_gal->Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
273  break;
274 
276  if( !m_gal->IsTextMirrored() )
277  m_gal->Translate( VECTOR2D( -textSize.x, 0 ) );
278  break;
279 
281  if( m_gal->IsTextMirrored() )
282  m_gal->Translate( VECTOR2D( -textSize.x, 0 ) );
283  break;
284 
285  default:
286  break;
287  }
288 
289  if( m_gal->IsTextMirrored() )
290  {
291  // In case of mirrored text invert the X scale of points and their X direction
292  // (m_glyphSize.x) and start drawing from the position where text normally should end
293  // (textSize.x)
294  xOffset = textSize.x - m_gal->GetLineWidth();
295  glyphSize.x = -glyphSize.x;
296  }
297  else
298  {
299  xOffset = 0.0;
300  }
301 
302  // The overbar is indented inward at the beginning of an italicized section, but
303  // must not be indented on subsequent letters to ensure that the bar segments
304  // overlap.
305  bool last_had_overbar = false;
306 
307  for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
308  {
309  // Toggle overbar
310  if( *chIt == '~' )
311  {
312  if( ++chIt >= end )
313  break;
314 
315  if( *chIt != '~' ) // It was a single tilda, it toggles overbar
316  overbar = !overbar;
317 
318  // If it is a double tilda, just process the second one
319  }
320 
321  int dd = *chIt - ' ';
322 
323  if( dd >= (int) m_glyphBoundingBoxes.size() || dd < 0 )
324  dd = '?' - ' ';
325 
326  GLYPH& glyph = m_glyphs[dd];
327  BOX2D& bbox = m_glyphBoundingBoxes[dd];
328 
329  if( overbar )
330  {
331  double overbar_start_x = xOffset;
332  double overbar_start_y = - computeOverbarVerticalPosition();
333  double overbar_end_x = xOffset + glyphSize.x * bbox.GetEnd().x;
334  double overbar_end_y = overbar_start_y;
335 
336  if( !last_had_overbar )
337  {
338  overbar_start_x += overbar_italic_comp;
339  last_had_overbar = true;
340  }
341 
342  VECTOR2D startOverbar( overbar_start_x, overbar_start_y );
343  VECTOR2D endOverbar( overbar_end_x, overbar_end_y );
344 
345  m_gal->DrawLine( startOverbar, endOverbar );
346  }
347  else
348  {
349  last_had_overbar = false;
350  }
351 
352  for( GLYPH::iterator pointListIt = glyph.begin(); pointListIt != glyph.end();
353  ++pointListIt )
354  {
355  std::deque<VECTOR2D> pointListScaled;
356 
357  for( std::deque<VECTOR2D>::iterator pointIt = pointListIt->begin();
358  pointIt != pointListIt->end(); ++pointIt )
359  {
360  VECTOR2D pointPos( pointIt->x * glyphSize.x + xOffset, pointIt->y * glyphSize.y );
361 
362  if( m_gal->IsFontItalic() )
363  {
364  // FIXME should be done other way - referring to the lowest Y value of point
365  // because now italic fonts are translated a bit
366  if( m_gal->IsTextMirrored() )
367  pointPos.x += pointPos.y * STROKE_FONT::ITALIC_TILT;
368  else
369  pointPos.x -= pointPos.y * STROKE_FONT::ITALIC_TILT;
370  }
371 
372  pointListScaled.push_back( pointPos );
373  }
374 
375  m_gal->DrawPolyline( pointListScaled );
376  }
377 
378  xOffset += glyphSize.x * bbox.GetEnd().x;
379  }
380 
381  m_gal->Restore();
382 }
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Returns current text horizontal justification setting.
double computeOverbarVerticalPosition() const
Compute the vertical position of an overbar, sometimes used in texts.
const Vec GetEnd() const
Definition: box2.h:183
GLYPH_LIST m_glyphs
Glyph list.
Definition: stroke_font.h:129
std::vector< BOX2D > m_glyphBoundingBoxes
Bounding boxes of the glyphs.
Definition: stroke_font.h:130
static const double ITALIC_TILT
Tilt factor for italic style (the is is the scaling factor on dY relative coordinates to give a tilst...
Definition: stroke_font.h:198
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
Class BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated class Vec.
Definition: box2.h:41
uni_iter ubegin() const
Function ubegin returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:216
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:128
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
VECTOR2D computeTextLineSize(const UTF8 &aText) const
Compute the X and Y size of a given text.
const VECTOR2D & GetGlyphSize() const
class uni_iter is a non-muting iterator that walks through unicode code points in the UTF8 encoded st...
Definition: utf8.h:137
uni_iter uend() const
Function uend returns a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:225
virtual void Restore()
Restore the context.
double GetLineWidth() const
Get the line width.
bool IsFontItalic() const
Returns true if current font has 'italic' attribute enabled.
virtual void Save()
Save the context.
std::deque< std::deque< VECTOR2D > > GLYPH
Definition: stroke_font.h:41
bool IsTextMirrored() const
Returns true if text should displayed mirrored.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
double STROKE_FONT::GetInterline ( double  aGlyphHeight,
double  aGlyphThickness 
)
static

Compute the distance (interline) between 2 lines of text (for multiline texts).

Parameters
aGlyphHeightis the height (vertical size) of the text.
aGlyphThicknessis the thickness of the lines used to draw the text.
Returns
the interline.

Definition at line 126 of file stroke_font.cpp.

References INTERLINE_PITCH_RATIO.

Referenced by SCH_GLOBALLABEL::CreateGraphicShape(), getInterline(), and EDA_TEXT::GetInterline().

127 {
128  return ( aGlyphHeight * INTERLINE_PITCH_RATIO ) + aGlyphThickness;
129 }
static const double INTERLINE_PITCH_RATIO
Factor that determines the pitch between 2 lines.
Definition: stroke_font.h:201
int STROKE_FONT::getInterline ( ) const
private

Returns a single line height using current settings.

Returns
The line height.

Definition at line 132 of file stroke_font.cpp.

References KIGFX::GAL::GetGlyphSize(), GetInterline(), KIGFX::GAL::GetLineWidth(), KiROUND(), m_gal, and VECTOR2< T >::y.

Referenced by Draw().

133 {
135 }
static double GetInterline(double aGlyphHeight, double aGlyphThickness)
Compute the distance (interline) between 2 lines of text (for multiline texts).
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:128
const VECTOR2D & GetGlyphSize() const
double GetLineWidth() const
Get the line width.
unsigned KIGFX::STROKE_FONT::linesCount ( const UTF8 aText) const
inlineprivate

Returns number of lines for a given text.

Parameters
aTextis the text to be checked.
Returns
unsigned - The number of lines in aText.

Definition at line 178 of file stroke_font.h.

Referenced by Draw().

179  {
180  if( aText.empty() )
181  return 0; // std::count does not work well with empty strings
182  else
183  // aText.end() - 1 is to skip a newline character that is potentially at the end
184  return std::count( aText.begin(), aText.end() - 1, '\n' ) + 1;
185  }
bool STROKE_FONT::LoadNewStrokeFont ( const char *const  aNewStrokeFont[],
int  aNewStrokeFontSize 
)

Load the new stroke font.

Parameters
aNewStrokeFontis the pointer to the font data.
aNewStrokeFontSizeis the size of the font data.
Returns
True, if the font was successfully loaded, else false.

Definition at line 47 of file stroke_font.cpp.

References computeBoundingBox(), FONT_OFFSET, m_glyphBoundingBoxes, m_glyphs, STROKE_FONT_SCALE, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by KIGFX::GAL::GAL().

48 {
49  m_glyphs.clear();
50  m_glyphBoundingBoxes.clear();
51  m_glyphs.resize( aNewStrokeFontSize );
52  m_glyphBoundingBoxes.resize( aNewStrokeFontSize );
53 
54  for( int j = 0; j < aNewStrokeFontSize; j++ )
55  {
56  GLYPH glyph;
57  double glyphStartX = 0.0;
58  double glyphEndX = 0.0;
59  VECTOR2D glyphBoundingX;
60 
61  std::deque<VECTOR2D> pointList;
62 
63  int i = 0;
64 
65  while( aNewStrokeFont[j][i] )
66  {
67  VECTOR2D point( 0.0, 0.0 );
68  char coordinate[2] = { 0, };
69 
70  for( int k = 0; k < 2; k++ )
71  {
72  coordinate[k] = aNewStrokeFont[j][i + k];
73  }
74 
75  if( i < 2 )
76  {
77  // The first two values contain the width of the char
78  glyphStartX = ( coordinate[0] - 'R' ) * STROKE_FONT_SCALE;
79  glyphEndX = ( coordinate[1] - 'R' ) * STROKE_FONT_SCALE;
80  glyphBoundingX = VECTOR2D( 0, glyphEndX - glyphStartX );
81  }
82  else if( ( coordinate[0] == ' ' ) && ( coordinate[1] == 'R' ) )
83  {
84  // Raise pen
85  if( pointList.size() > 0 )
86  glyph.push_back( pointList );
87 
88  pointList.clear();
89  }
90  else
91  {
92  // In stroke font, coordinates values are coded as <value> + 'R',
93  // <value> is an ASCII char.
94  // therefore every coordinate description of the Hershey format has an offset,
95  // it has to be subtracted
96  // Note:
97  // * the stroke coordinates are stored in reduced form (-1.0 to +1.0),
98  // and the actual size is stroke coordinate * glyph size
99  // * a few shapes have a height slightly bigger than 1.0 ( like '{' '[' )
100  point.x = (double) ( coordinate[0] - 'R' ) * STROKE_FONT_SCALE - glyphStartX;
101  #define FONT_OFFSET -10
102  // FONT_OFFSET is here for historical reasons, due to the way the stroke font
103  // was built. It allows shapes coordinates like W M ... to be >= 0
104  // Only shapes like j y have coordinates < 0
105  point.y = (double) ( coordinate[1] - 'R' + FONT_OFFSET ) * STROKE_FONT_SCALE;
106  pointList.push_back( point );
107  }
108 
109  i += 2;
110  }
111 
112  if( pointList.size() > 0 )
113  glyph.push_back( pointList );
114 
115  m_glyphs[j] = glyph;
116 
117  // Compute the bounding box of the glyph
118  m_glyphBoundingBoxes[j] = computeBoundingBox( glyph, glyphBoundingX );
119  }
120 
121  return true;
122 }
GLYPH_LIST m_glyphs
Glyph list.
Definition: stroke_font.h:129
std::vector< BOX2D > m_glyphBoundingBoxes
Bounding boxes of the glyphs.
Definition: stroke_font.h:130
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
BOX2D computeBoundingBox(const GLYPH &aGlyph, const VECTOR2D &aGlyphBoundingX) const
Compute the bounding box of a given glyph.
static const double STROKE_FONT_SCALE
Scale factor for a glyph
Definition: stroke_font.h:194
#define FONT_OFFSET
std::deque< std::deque< VECTOR2D > > GLYPH
Definition: stroke_font.h:41
void KIGFX::STROKE_FONT::SetGAL ( GAL aGal)
inline

Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one.

Parameters
aGalis the new GAL instance.

Definition at line 82 of file stroke_font.h.

References m_gal.

83  {
84  m_gal = aGal;
85  }
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:128

Friends And Related Function Documentation

friend class GAL
friend

Definition at line 53 of file stroke_font.h.

Member Data Documentation

const double STROKE_FONT::BOLD_FACTOR = 1.3
staticprivate

Factor that determines relative line width for bold text.

Definition at line 191 of file stroke_font.h.

Referenced by Draw().

const double STROKE_FONT::INTERLINE_PITCH_RATIO = 1.5
staticprivate

Factor that determines the pitch between 2 lines.

Definition at line 201 of file stroke_font.h.

Referenced by GetInterline().

const double STROKE_FONT::ITALIC_TILT = 1.0 / 8
staticprivate

Tilt factor for italic style (the is is the scaling factor on dY relative coordinates to give a tilst shape

Definition at line 198 of file stroke_font.h.

Referenced by ComputeStringBoundaryLimits(), and drawSingleLineText().

GAL* KIGFX::STROKE_FONT::m_gal
private
std::vector<BOX2D> KIGFX::STROKE_FONT::m_glyphBoundingBoxes
private

Bounding boxes of the glyphs.

Definition at line 130 of file stroke_font.h.

Referenced by ComputeStringBoundaryLimits(), drawSingleLineText(), and LoadNewStrokeFont().

GLYPH_LIST KIGFX::STROKE_FONT::m_glyphs
private

Glyph list.

Definition at line 129 of file stroke_font.h.

Referenced by drawSingleLineText(), and LoadNewStrokeFont().

const double STROKE_FONT::OVERBAR_POSITION_FACTOR = 1.22
staticprivate

Factor that determines relative vertical position of the overbar.

Definition at line 188 of file stroke_font.h.

Referenced by ComputeOverbarVerticalPosition().

const double STROKE_FONT::STROKE_FONT_SCALE = 1.0 / 21.0
staticprivate

Scale factor for a glyph

Definition at line 194 of file stroke_font.h.

Referenced by LoadNewStrokeFont().


The documentation for this class was generated from the following files: