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 53 of file stroke_font.h.

Constructor & Destructor Documentation

STROKE_FONT::STROKE_FONT ( GAL aGal)

Constructor.

Definition at line 43 of file stroke_font.cpp.

43  :
44  m_gal( aGal )
45 {
46 }
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:130

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 140 of file stroke_font.cpp.

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

Referenced by LoadNewStrokeFont().

141 {
143 
144  std::deque<VECTOR2D> boundingPoints;
145 
146  boundingPoints.push_back( VECTOR2D( aGLYPHBoundingX.x, 0 ) );
147  boundingPoints.push_back( VECTOR2D( aGLYPHBoundingX.y, 0 ) );
148 
149  for( GLYPH::const_iterator pointListIt = aGLYPH.begin(); pointListIt != aGLYPH.end(); ++pointListIt )
150  {
151  for( std::deque<VECTOR2D>::const_iterator pointIt = pointListIt->begin();
152  pointIt != pointListIt->end(); ++pointIt )
153  {
154  boundingPoints.push_back( VECTOR2D( aGLYPHBoundingX.x, pointIt->y ) );
155  }
156  }
157 
158  boundingBox.Compute( boundingPoints );
159 
160  return boundingBox;
161 }
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:588
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 377 of file stroke_font.cpp.

References OVERBAR_POSITION_FACTOR.

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

378 {
379  // Static method.
380  // Compute the Y position of the overbar. This is the distance between
381  // the text base line and the overbar axis.
382  return aGlyphHeight * OVERBAR_POSITION_FACTOR + aGlyphThickness;
383 }
static const double OVERBAR_POSITION_FACTOR
Factor that determines relative vertical position of the overbar.
Definition: stroke_font.h:190
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 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().

387 {
388  // Compute the Y position of the overbar. This is the distance between
389  // the text base line and the overbar axis.
391 }
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:130
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 400 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().

403 {
404  VECTOR2D string_bbox;
405  double ymax = 0.0;
406  double ymin = 0.0;
407 
408  for( UTF8::uni_iter it = aText.ubegin(), end = aText.uend(); it < end; ++it )
409  {
410  wxASSERT_MSG( *it != '\n',
411  wxT( "This function is intended to work with single line strings" ) );
412 
413  // If it is double tilda, then it is displayed as a single tilda
414  // If it is single tilda, then it is toggling overbar, so we need to skip it
415  if( *it == '~' )
416  {
417  if( ++it >= end )
418  break;
419  }
420 
421  // Index in the bounding boxes table
422  int dd = *it - ' ';
423 
424  if( dd >= (int) m_glyphBoundingBoxes.size() || dd < 0 )
425  dd = '?' - ' ';
426 
427  const BOX2D& box = m_glyphBoundingBoxes[dd];
428 
429  string_bbox.x += box.GetEnd().x;
430 
431  // Calculate Y min and Y max
432  if( aTopLimit )
433  {
434  ymax = std::max( ymax, box.GetY() );
435  ymax = std::max( ymax, box.GetEnd().y );
436  }
437 
438  if( aBottomLimit )
439  {
440  ymin = std::min( ymin, box.GetY() );
441  ymin = std::min( ymin, box.GetEnd().y );
442  }
443  }
444 
445  string_bbox.x *= aGlyphSize.x;
446  string_bbox.x += aGlyphThickness;
447  string_bbox.y = aGlyphSize.y + aGlyphThickness;
448 
449  // For italic correction, take in account italic tilt
450  if( m_gal->IsFontItalic() )
451  string_bbox.x += string_bbox.y * STROKE_FONT::ITALIC_TILT;
452 
453  if( aTopLimit )
454  *aTopLimit = ymax * aGlyphSize.y;
455 
456  if( aBottomLimit )
457  *aBottomLimit = ymin * aGlyphSize.y;
458 
459  return string_bbox;
460 }
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:132
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:200
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:285
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:130
class uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded ...
Definition: utf8.h:207
uni_iter uend() const
Function uend returns a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:294
#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 394 of file stroke_font.cpp.

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

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

395 {
397 }
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:130
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 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().

165 {
166  if( aText.empty() )
167  return;
168 
169  // Context needs to be saved before any transformations
170  m_gal->Save();
171 
172  m_gal->Translate( aPosition );
173  m_gal->Rotate( -aRotationAngle );
174 
175  // Single line height
176  int lineHeight = getInterline( );
177  int lineCount = linesCount( aText );
178  const VECTOR2D& glyphSize = m_gal->GetGlyphSize();
179 
180  // align the 1st line of text
181  switch( m_gal->GetVerticalJustify() )
182  {
184  m_gal->Translate( VECTOR2D( 0, glyphSize.y ) );
185  break;
186 
188  m_gal->Translate( VECTOR2D( 0, glyphSize.y / 2.0 ) );
189  break;
190 
192  break;
193 
194  default:
195  break;
196  }
197 
198  if( lineCount > 1 )
199  {
200  switch( m_gal->GetVerticalJustify() )
201  {
203  break;
204 
206  m_gal->Translate( VECTOR2D(0, -( lineCount - 1 ) * lineHeight / 2) );
207  break;
208 
210  m_gal->Translate( VECTOR2D(0, -( lineCount - 1 ) * lineHeight ) );
211  break;
212  }
213  }
214 
215  m_gal->SetIsStroke( true );
216  //m_gal->SetIsFill( false );
217 
218  if( m_gal->IsFontBold() )
220 
221  // Split multiline strings into separate ones and draw them line by line
222  size_t begin = 0;
223  size_t newlinePos = aText.find( '\n' );
224 
225  while( newlinePos != aText.npos )
226  {
227  size_t length = newlinePos - begin;
228 
229  drawSingleLineText( aText.substr( begin, length ) );
230  m_gal->Translate( VECTOR2D( 0.0, lineHeight ) );
231 
232  begin = newlinePos + 1;
233  newlinePos = aText.find( '\n', begin );
234  }
235 
236  // Draw the last (or the only one) line
237  if( !aText.empty() )
238  drawSingleLineText( aText.substr( begin ) );
239 
240  m_gal->Restore();
241 }
static constexpr std::string::size_type npos
Definition: utf8.h:155
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:193
std::string substr(size_t pos=0, size_t len=npos) const
Definition: utf8.h:182
virtual void Rotate(double aAngle)
Rotate the context.
virtual void SetLineWidth(double aLineWidth)
Set the line width.
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:130
bool IsFontBold() const
Returns true if current font has 'bold' attribute enabled.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:588
bool empty() const
Definition: utf8.h:108
std::string::size_type find(char c) const
Definition: utf8.h:110
const VECTOR2D & GetGlyphSize() const
unsigned linesCount(const UTF8 &aText) const
Returns number of lines for a given text.
Definition: stroke_font.h:180
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 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, 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().

245 {
246  double xOffset;
247  VECTOR2D glyphSize( m_gal->GetGlyphSize() );
248  double overbar_italic_comp = computeOverbarVerticalPosition() * ITALIC_TILT;
249 
250  if( m_gal->IsTextMirrored() )
251  overbar_italic_comp = -overbar_italic_comp;
252 
253  // Compute the text size
254  VECTOR2D textSize = computeTextLineSize( aText );
255  double half_thickness = m_gal->GetLineWidth()/2;
256 
257  // Context needs to be saved before any transformations
258  m_gal->Save();
259 
260  // First adjust: the text X position is corrected by half_thickness
261  // because when the text with thickness is draw, its full size is textSize,
262  // but the position of lines is half_thickness to textSize - half_thickness
263  // so we must translate the coordinates by half_thickness on the X axis
264  // to place the text inside the 0 to textSize X area.
265  m_gal->Translate( VECTOR2D( half_thickness, 0 ) );
266 
267  // Adjust the text position to the given horizontal justification
268  switch( m_gal->GetHorizontalJustify() )
269  {
271  m_gal->Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
272  break;
273 
275  if( !m_gal->IsTextMirrored() )
276  m_gal->Translate( VECTOR2D( -textSize.x, 0 ) );
277  break;
278 
280  if( m_gal->IsTextMirrored() )
281  m_gal->Translate( VECTOR2D( -textSize.x, 0 ) );
282  break;
283 
284  default:
285  break;
286  }
287 
288  if( m_gal->IsTextMirrored() )
289  {
290  // In case of mirrored text invert the X scale of points and their X direction
291  // (m_glyphSize.x) and start drawing from the position where text normally should end
292  // (textSize.x)
293  xOffset = textSize.x - m_gal->GetLineWidth();
294  glyphSize.x = -glyphSize.x;
295  }
296  else
297  {
298  xOffset = 0.0;
299  }
300 
301  // The overbar is indented inward at the beginning of an italicized section, but
302  // must not be indented on subsequent letters to ensure that the bar segments
303  // overlap.
304  bool last_had_overbar = false;
305  auto processedText = ProcessOverbars( aText );
306  const auto& text = processedText.first;
307  const auto& overbars = processedText.second;
308  int i = 0;
309 
310  for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
311  {
312  int dd = *chIt - ' ';
313 
314  if( dd >= (int) m_glyphBoundingBoxes.size() || dd < 0 )
315  dd = '?' - ' ';
316 
317  GLYPH& glyph = m_glyphs[dd];
318  BOX2D& bbox = m_glyphBoundingBoxes[dd];
319 
320  if( overbars[i] )
321  {
322  double overbar_start_x = xOffset;
323  double overbar_start_y = - computeOverbarVerticalPosition();
324  double overbar_end_x = xOffset + glyphSize.x * bbox.GetEnd().x;
325  double overbar_end_y = overbar_start_y;
326 
327  if( !last_had_overbar )
328  {
329  overbar_start_x += overbar_italic_comp;
330  last_had_overbar = true;
331  }
332 
333  VECTOR2D startOverbar( overbar_start_x, overbar_start_y );
334  VECTOR2D endOverbar( overbar_end_x, overbar_end_y );
335 
336  m_gal->DrawLine( startOverbar, endOverbar );
337  }
338  else
339  {
340  last_had_overbar = false;
341  }
342 
343  for( GLYPH::iterator pointListIt = glyph.begin(); pointListIt != glyph.end();
344  ++pointListIt )
345  {
346  std::deque<VECTOR2D> pointListScaled;
347 
348  for( std::deque<VECTOR2D>::iterator pointIt = pointListIt->begin();
349  pointIt != pointListIt->end(); ++pointIt )
350  {
351  VECTOR2D pointPos( pointIt->x * glyphSize.x + xOffset, pointIt->y * glyphSize.y );
352 
353  if( m_gal->IsFontItalic() )
354  {
355  // FIXME should be done other way - referring to the lowest Y value of point
356  // because now italic fonts are translated a bit
357  if( m_gal->IsTextMirrored() )
358  pointPos.x += pointPos.y * STROKE_FONT::ITALIC_TILT;
359  else
360  pointPos.x -= pointPos.y * STROKE_FONT::ITALIC_TILT;
361  }
362 
363  pointListScaled.push_back( pointPos );
364  }
365 
366  m_gal->DrawPolyline( pointListScaled );
367  }
368 
369  xOffset += glyphSize.x * bbox.GetEnd().x;
370  ++i;
371  }
372 
373  m_gal->Restore();
374 }
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Returns current text horizontal justification setting.
std::pair< UTF8, std::vector< bool > > ProcessOverbars(const UTF8 &aText)
Processes a text to extract the raw text and overbar flags.
Definition: text_utils.cpp:27
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:131
std::vector< BOX2D > m_glyphBoundingBoxes
Bounding boxes of the glyphs.
Definition: stroke_font.h:132
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:200
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
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:130
VECTOR2< double > VECTOR2D
Definition: vector2d.h:588
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-mutating iterator that walks through unicode code points in the UTF8 encoded ...
Definition: utf8.h:207
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:43
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 128 of file stroke_font.cpp.

References INTERLINE_PITCH_RATIO.

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

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

Returns a single line height using current settings.

Returns
The line height.

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().

135 {
137 }
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:130
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 180 of file stroke_font.h.

References UTF8::begin(), UTF8::empty(), and UTF8::end().

Referenced by Draw().

181  {
182  if( aText.empty() )
183  return 0; // std::count does not work well with empty strings
184  else
185  // aText.end() - 1 is to skip a newline character that is potentially at the end
186  return std::count( aText.begin(), aText.end() - 1, '\n' ) + 1;
187  }
bool empty() const
Definition: utf8.h:108
std::string::const_iterator end() const
Definition: utf8.h:197
std::string::const_iterator begin() const
Definition: utf8.h:196
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 49 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().

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

References m_gal.

85  {
86  m_gal = aGal;
87  }
GAL * m_gal
Pointer to the GAL.
Definition: stroke_font.h:130

Friends And Related Function Documentation

friend class GAL
friend

Definition at line 55 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 193 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 203 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 200 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 132 of file stroke_font.h.

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

GLYPH_LIST KIGFX::STROKE_FONT::m_glyphs
private

Glyph list.

Definition at line 131 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 190 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 196 of file stroke_font.h.

Referenced by LoadNewStrokeFont().


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