32 #include <wx/string.h> 36 using namespace KIGFX;
53 m_glyphBoundingBoxes( nullptr )
73 for(
int j = 0; j < aNewStrokeFontSize; j++ )
76 double glyphStartX = 0.0;
77 double glyphEndX = 0.0;
78 double glyphWidth = 0.0;
80 std::vector<VECTOR2D>* pointList =
nullptr;
85 while( aNewStrokeFont[j][i] )
88 if( aNewStrokeFont[j][i] ==
' ' && aNewStrokeFont[j][i+1] ==
'R' )
94 glyph->reserve( strokes + 1 );
98 while( aNewStrokeFont[j][i] )
101 char coordinate[2] = { 0, };
103 for(
int k : { 0, 1 } )
104 coordinate[k] = aNewStrokeFont[j][i + k];
111 glyphWidth = glyphEndX - glyphStartX;
113 else if( ( coordinate[0] ==
' ' ) && ( coordinate[1] ==
'R' ) )
116 pointList->shrink_to_fit();
132 #define FONT_OFFSET -10 140 pointList =
new std::vector<VECTOR2D>;
141 glyph->push_back( pointList );
144 pointList->push_back( point );
151 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 lastHadOverbar =
false;
333 int overbarDepth = -1;
334 int superSubDepth = -1;
335 int braceNesting = 0;
339 std::vector<VECTOR2D> ptListScaled;
353 char_count = ( char_count / 4 + 1 ) * 4 - 1;
354 xOffset = baseGlyphSize.
x * char_count;
356 glyphSize = baseGlyphSize;
359 else if( *chIt ==
'^' && superSubDepth == -1 )
363 if( ++lookahead != end && *lookahead ==
'{' )
366 superSubDepth = braceNesting;
369 glyphSize = baseGlyphSize * 0.8;
370 yOffset = -baseGlyphSize.
y * 0.3;
374 else if( *chIt ==
'_' && superSubDepth == -1 )
378 if( ++lookahead != end && *lookahead ==
'{' )
381 superSubDepth = braceNesting;
384 glyphSize = baseGlyphSize * 0.8;
385 yOffset = baseGlyphSize.
y * 0.1;
389 else if( *chIt ==
'~' && overbarDepth == -1 )
393 if( ++lookahead != end && *lookahead ==
'{' )
396 overbarDepth = braceNesting;
401 else if( *chIt ==
'{' )
405 else if( *chIt ==
'}' )
407 if( braceNesting > 0 )
410 if( braceNesting == superSubDepth )
414 glyphSize = baseGlyphSize;
419 if( braceNesting == overbarDepth )
427 int dd = (signed) *chIt -
' ';
431 int substitute = *chIt ==
'\t' ?
' ' :
'?';
432 dd = substitute -
' ';
438 if( overbarDepth != -1 )
440 double overbar_start_x = xOffset;
442 double overbar_end_x = xOffset + glyphSize.
x * bbox.
GetEnd().
x;
443 double overbar_end_y = overbar_start_y;
445 if( !lastHadOverbar )
448 overbar_start_x += overbar_italic_comp;
450 lastHadOverbar =
true;
453 VECTOR2D startOverbar( overbar_start_x, overbar_start_y );
454 VECTOR2D endOverbar( overbar_end_x, overbar_end_y );
460 lastHadOverbar =
false;
466 VECTOR2D startUnderline( xOffset, - vOffset );
467 VECTOR2D endUnderline( xOffset + glyphSize.
x * bbox.
GetEnd().
x, - vOffset );
472 for(
const std::vector<VECTOR2D>* ptList : *glyph )
475 ptListScaled.clear();
479 VECTOR2D scaledPt( pt.x * glyphSize.
x + xOffset, pt.y * glyphSize.
y + yOffset );
491 ptListScaled.push_back( scaledPt );
499 xOffset += glyphSize.
x * bbox.
GetEnd().
x;
536 double aGlyphThickness )
const 540 double maxX = 0.0, curX = 0.0;
542 double curScale = 1.0;
543 int overbarDepth = -1;
544 int superSubDepth = -1;
545 int braceNesting = 0;
552 maxX = std::max( maxX, curX );
562 double addlSpace = 3.0 * spaces - std::fmod( curX, 4.0 * spaces );
567 else if( (*chIt ==
'^' || *chIt ==
'_') && superSubDepth == -1 )
571 if( ++lookahead != end && *lookahead ==
'{' )
575 superSubDepth = braceNesting;
582 else if( *chIt ==
'~' && overbarDepth == -1 )
586 if( ++lookahead != end && *lookahead ==
'{' )
589 overbarDepth = braceNesting;
594 else if( *chIt ==
'{' )
598 else if( *chIt ==
'}' )
600 if( braceNesting > 0 )
603 if( braceNesting == overbarDepth )
609 if( braceNesting == superSubDepth )
619 int dd = (signed) *chIt -
' ';
623 int substitute = *chIt ==
'\t' ?
' ' :
'?';
624 dd = substitute -
' ';
628 curX += box.
GetEnd().
x * curScale;
631 string_bbox.
x = std::max( maxX, curX ) * aGlyphSize.
x;
632 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.
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.