Underline for hypertext rollovers.

This commit is contained in:
Jeff Young 2022-08-27 20:57:34 +01:00
parent 9a8ee2ca50
commit 560dc7d2b6
6 changed files with 71 additions and 4 deletions

View File

@ -176,7 +176,8 @@ void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosit
for( size_t i = 0; i < strings_list.GetCount(); i++ )
{
drawSingleLineText( aGal, nullptr, strings_list[i], positions[i], aAttrs.m_Size,
aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, aAttrs.m_Italic );
aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, aAttrs.m_Italic,
aAttrs.m_Underlined );
}
}
@ -245,7 +246,7 @@ VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYP
void FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxString& aText,
const VECTOR2I& aPosition, const VECTOR2I& aSize,
const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin,
bool aItalic ) const
bool aItalic, bool aUnderline ) const
{
if( !aGal )
return;
@ -255,6 +256,9 @@ void FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxSt
if( aItalic )
textStyle |= TEXT_STYLE::ITALIC;
if( aUnderline )
textStyle |= TEXT_STYLE::UNDERLINE;
std::vector<std::unique_ptr<GLYPH>> glyphs;
(void) drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, aAngle, aMirror, aOrigin,

View File

@ -141,6 +141,16 @@ double OUTLINE_FONT::ComputeOverbarVerticalPosition( double aGlyphHeight ) const
}
/**
* Compute the vertical position of an underline. This is the distance between the text
* baseline and the underline.
*/
double OUTLINE_FONT::ComputeUnderlineVerticalPosition( double aGlyphHeight ) const
{
return aGlyphHeight * m_underlineOffsetScaler;
}
/**
* Compute the distance (interline) between 2 lines of text (for multiline texts). This is
* the distance between baselines, not the space between line bounding boxes.

View File

@ -46,6 +46,9 @@ using namespace KIFONT;
///< Factor that determines relative vertical position of the overbar.
static constexpr double OVERBAR_POSITION_FACTOR = 1.33;
///< Factor that determines relative vertical position of the underline.
static constexpr double UNDERLINE_POSITION_FACTOR = -0.16;
///< Scale factor for a glyph
static constexpr double STROKE_FONT_SCALE = 1.0 / 21.0;
@ -210,6 +213,12 @@ double STROKE_FONT::ComputeOverbarVerticalPosition( double aGlyphHeight ) const
}
double STROKE_FONT::ComputeUnderlineVerticalPosition( double aGlyphHeight ) const
{
return aGlyphHeight * UNDERLINE_POSITION_FACTOR;
}
VECTOR2I STROKE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
const wxString& aText, const VECTOR2I& aSize,
const VECTOR2I& aPosition, const EDA_ANGLE& aAngle,
@ -313,6 +322,29 @@ VECTOR2I STROKE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_ptr
}
}
if( aTextStyle & TEXT_STYLE::UNDERLINE )
{
barOffset.y = ComputeUnderlineVerticalPosition( glyphSize.y );
if( aTextStyle & TEXT_STYLE::ITALIC )
barOffset.x = barOffset.y * ITALIC_TILT;
VECTOR2D barStart( aPosition.x + barOffset.x + barTrim, cursor.y - barOffset.y );
VECTOR2D barEnd( cursor.x + barOffset.x - barTrim, cursor.y - barOffset.y );
if( aGlyphs )
{
STROKE_GLYPH underlineGlyph;
underlineGlyph.AddPoint( barStart );
underlineGlyph.AddPoint( barEnd );
underlineGlyph.Finalize();
aGlyphs->push_back( underlineGlyph.Transform( { 1.0, 1.0 }, { 0, 0 }, false,
aAngle, aMirror, aOrigin ) );
}
}
if( aBBox )
{
aBBox->SetOrigin( aPosition );

View File

@ -46,7 +46,8 @@ enum TEXT_STYLE
ITALIC = 1 << 1,
SUBSCRIPT = 1 << 2,
SUPERSCRIPT = 1 << 3,
OVERBAR = 1 << 4
OVERBAR = 1 << 4,
UNDERLINE = 1 << 5
};
@ -159,6 +160,12 @@ public:
*/
virtual double ComputeOverbarVerticalPosition( double aGlyphHeight ) const = 0;
/**
* Compute the vertical position of an underline. This is the distance between the text
* baseline and the underline.
*/
virtual double ComputeUnderlineVerticalPosition( double aGlyphHeight ) const = 0;
/**
* Compute the distance (interline) between 2 lines of text (for multiline texts). This is
* the distance between baselines, not the space between line bounding boxes.
@ -218,7 +225,7 @@ protected:
void drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxString& aText,
const VECTOR2I& aPosition, const VECTOR2I& aSize,
const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin,
bool aItalic ) const;
bool aItalic, bool aUnderline ) const;
/**
* Computes the bounding box for a single line of text.

View File

@ -83,6 +83,12 @@ public:
*/
double ComputeOverbarVerticalPosition( double aGlyphHeight ) const override;
/**
* Compute the vertical position of an underline. This is the distance between the text
* baseline and the underline.
*/
double ComputeUnderlineVerticalPosition( double aGlyphHeight ) const override;
/**
* Compute the distance (interline) between 2 lines of text (for multiline texts). This is
* the distance between baselines, not the space between line bounding boxes.
@ -142,6 +148,8 @@ private:
// with 0.64.
static constexpr double m_subscriptSuperscriptSize = 0.64;
static constexpr double m_underlineOffsetScaler = -0.16;
int faceSize( int aSize ) const
{
return aSize * m_charSizeScaler * m_outlineFontSizeCompensation;

View File

@ -70,6 +70,12 @@ public:
*/
double ComputeOverbarVerticalPosition( double aGlyphHeight ) const override;
/**
* Compute the vertical position of an underline. This is the distance between the text
* baseline and the underline.
*/
double ComputeUnderlineVerticalPosition( double aGlyphHeight ) const override;
/**
* Compute the distance (interline) between 2 lines of text (for multiline texts). This is
* the distance between baselines, not the space between line bounding boxes.