32 #include <wx/string.h> 36 using namespace KIGFX;
51 m_gal( aGal ), m_glyphs( nullptr ), m_glyphBoundingBoxes( nullptr ), m_maxGlyphWidth( 1.0 )
71 for(
int j = 0; j < aNewStrokeFontSize; j++ )
74 double glyphStartX = 0.0;
75 double glyphEndX = 0.0;
76 double glyphWidth = 0.0;
78 std::vector<VECTOR2D>* pointList =
nullptr;
83 while( aNewStrokeFont[j][i] )
86 if( aNewStrokeFont[j][i] ==
' ' && aNewStrokeFont[j][i+1] ==
'R' )
92 glyph->reserve( strokes + 1 );
96 while( aNewStrokeFont[j][i] )
99 char coordinate[2] = { 0, };
101 for(
int k : { 0, 1 } )
102 coordinate[k] = aNewStrokeFont[j][i + k];
109 glyphWidth = glyphEndX - glyphStartX;
111 else if( ( coordinate[0] ==
' ' ) && ( coordinate[1] ==
'R' ) )
114 pointList->shrink_to_fit();
130 #define FONT_OFFSET -10 138 pointList =
new std::vector<VECTOR2D>;
139 glyph->push_back( pointList );
142 pointList->push_back( point );
149 pointList->shrink_to_fit();
178 for(
const std::vector<VECTOR2D>* pointList : *aGLYPH )
180 for(
const VECTOR2D& point : *pointList )
182 min.
y = std::min( min.
y, point.y );
183 max.
y = std::max( max.
y, point.y );
187 return BOX2D( min, max - min );
250 size_t newlinePos = aText.
find(
'\n' );
252 while( newlinePos != aText.
npos )
254 size_t length = newlinePos - begin;
259 begin = newlinePos + 1;
260 newlinePos = aText.
find(
'\n', begin );
279 overbar_italic_comp = -overbar_italic_comp;
322 baseGlyphSize.x = -baseGlyphSize.x;
332 bool last_had_overbar =
false;
333 bool in_overbar =
false;
334 bool in_super_or_subscript =
false;
338 std::vector<VECTOR2D> ptListScaled;
352 char_count = ( char_count / 4 + 1 ) * 4 - 1;
355 glyphSize = baseGlyphSize;
361 else if( *chIt ==
'~' )
376 in_overbar = !in_overbar;
379 else if( *chIt ==
'^' )
381 auto lookahead = chIt;
383 if( ++lookahead != end && *lookahead ==
'{' )
387 in_super_or_subscript =
true;
388 glyphSize = baseGlyphSize * 0.8;
389 yOffset = -baseGlyphSize.
y * 0.3;
393 else if( *chIt ==
'_' )
395 auto lookahead = chIt;
397 if( ++lookahead != end && *lookahead ==
'{' )
401 in_super_or_subscript =
true;
402 glyphSize = baseGlyphSize * 0.8;
403 yOffset = baseGlyphSize.
y * 0.1;
407 else if( *chIt ==
'}' && in_super_or_subscript )
409 in_super_or_subscript =
false;
410 glyphSize = baseGlyphSize;
415 else if( in_overbar && ( *chIt ==
' ' || *chIt ==
'}' || *chIt ==
')' ) )
421 int dd = (signed) *chIt -
' ';
425 int substitute = *chIt ==
'\t' ?
' ' :
'?';
426 dd = substitute -
' ';
434 double overbar_start_x = xOffset;
436 double overbar_end_x = xOffset + glyphSize.
x * bbox.
GetEnd().
x;
437 double overbar_end_y = overbar_start_y;
439 if( !last_had_overbar )
442 overbar_start_x += overbar_italic_comp;
444 last_had_overbar =
true;
447 VECTOR2D startOverbar( overbar_start_x, overbar_start_y );
448 VECTOR2D endOverbar( overbar_end_x, overbar_end_y );
454 last_had_overbar =
false;
460 VECTOR2D startUnderline( xOffset, - vOffset );
461 VECTOR2D endUnderline( xOffset + glyphSize.
x * bbox.
GetEnd().
x, - vOffset );
466 for(
const std::vector<VECTOR2D>* ptList : *glyph )
469 ptListScaled.clear();
473 VECTOR2D scaledPt( pt.x * glyphSize.
x + xOffset, pt.y * glyphSize.
y + yOffset );
485 ptListScaled.push_back( scaledPt );
493 xOffset += glyphSize.
x * bbox.
GetEnd().
x;
530 double aGlyphThickness )
const 534 double maxX = 0.0, curX = 0.0;
536 double curScale = 1.0;
537 bool in_overbar =
false;
538 bool in_super_or_subscript =
false;
545 maxX = std::max( maxX, curX );
555 double addlSpace = 3.0 * spaces - std::fmod( curX, 4.0 * spaces );
563 else if( *it ==
'~' )
579 in_overbar = !in_overbar;
582 else if( *it ==
'^' || *it ==
'_' )
586 if( ++lookahead != end && *lookahead ==
'{' )
590 in_super_or_subscript =
true;
595 else if( *it ==
'}' && in_super_or_subscript )
597 in_super_or_subscript =
false;
602 else if( in_overbar && ( *it ==
' ' || *it ==
'}' || *it ==
')' ) )
608 int dd = (signed) *it -
' ';
612 int substitute = *it ==
'\t' ?
' ' :
'?';
613 dd = substitute -
' ';
617 curX += box.
GetEnd().
x * curScale;
620 string_bbox.
x = std::max( maxX, curX ) * aGlyphSize.
x;
621 string_bbox.
x += aGlyphThickness;
std::vector< std::vector< VECTOR2D > * > GLYPH
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
double m_maxGlyphWidth
The widest glyph in our set.
static constexpr std::string::size_type npos
float GetLineWidth() const
Get the line width.
The Cairo implementation of the graphics abstraction layer.
static double GetInterline(double aGlyphHeight)
Compute the distance (interline) between 2 lines of text (for multiline texts).
bool IsTextMirrored() const
static const double BOLD_FACTOR
Scale factor for a glyph.
uni_iter uend() const
Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
bool LoadNewStrokeFont(const char *const aNewStrokeFont[], int aNewStrokeFontSize)
Load the new stroke font.
static const double ITALIC_TILT
Factor that determines the pitch between 2 lines.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Return current text horizontal justification setting.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void Rotate(double aAngle)
Rotate the context.
const VECTOR2D & GetGlyphSize() const
uni_iter ubegin() const
Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
bool IsFontUnderlined() const
std::string::size_type find(char c) const
GAL * m_gal
Pointer to the GAL.
VECTOR2< double > VECTOR2D
VECTOR2D computeTextLineSize(const UTF8 &aText) const
Compute the X and Y size of a given text.
static const double UNDERLINE_POSITION_FACTOR
Factor that determines relative line width for bold text.
double computeUnderlineVerticalPosition() const
static const double INTERLINE_PITCH_RATIO
VECTOR2D ComputeStringBoundaryLimits(const UTF8 &aText, const VECTOR2D &aGlyphSize, double aGlyphThickness) const
Compute the boundary limits of aText (the bounding box of all shapes).
std::vector< BOX2D > * g_newStrokeFontGlyphBoundingBoxes
Bounding boxes of the glyphs.
std::vector< GLYPH * > GLYPH_LIST
bool IsFontItalic() const
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
GLYPH_LIST * g_newStrokeFontGlyphs
Glyph list.
void Draw(const UTF8 &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a string.
double computeOverbarVerticalPosition() const
Compute the vertical position of an overbar, sometimes used in texts.
double ComputeOverbarVerticalPosition(double aGlyphHeight) const
Compute the vertical position of an overbar, sometimes used in texts.
STROKE_FONT(GAL *aGal)
Constructor.
static const double STROKE_FONT_SCALE
Tilt factor for italic style (the is is the scaling factor on dY relative coordinates to give a tilt ...
void drawSingleLineText(const UTF8 &aText)
Draw a single line of text.
virtual void Restore()
Restore the context.
EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
Returns current text vertical justification setting.
unsigned linesCount(const UTF8 &aText) const
Returns number of lines for a given text.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
static const double OVERBAR_POSITION_FACTOR
const std::vector< BOX2D > * m_glyphBoundingBoxes
Bounding boxes of the glyphs.
std::string substr(size_t pos=0, size_t len=npos) const
virtual void Save()
Save the context.
const GLYPH_LIST * m_glyphs
Glyph list.
BOX2D computeBoundingBox(const GLYPH *aGlyph, double aGlyphWidth) const
Compute the bounding box of a given glyph.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
Abstract interface for drawing on a 2D-surface.