ADDED: parameterize font metrics and allow customization of overbar height.

This commit is contained in:
Jeff Young 2023-08-06 20:20:53 +01:00
parent a0ebedc0ac
commit 5e112ca78e
64 changed files with 834 additions and 624 deletions

View File

@ -118,7 +118,8 @@ void BOARD_ADAPTER::addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aContaine
attrs.m_Angle = aText->GetDrawRotation();
font->Draw( &callback_gal, aText->GetShownText( true ), aText->GetDrawPos(), attrs );
font->Draw( &callback_gal, aText->GetShownText( true ), aText->GetDrawPos(), attrs,
aOwner->GetFontMetrics() );
}
}

View File

@ -58,9 +58,17 @@
#include <gr_basic.h>
#include <trigo.h>
#include <render_settings.h>
#include <font/font.h>
// ============================ BASE CLASS ==============================
const KIFONT::METRICS& DS_DRAW_ITEM_BASE::GetFontMetrics() const
{
return KIFONT::METRICS::Default();
}
void DS_DRAW_ITEM_BASE::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 1;

View File

@ -270,7 +270,8 @@ void KIGFX::DS_PAINTER::draw( const DS_DRAW_ITEM_TEXT* aItem, int aLayer ) const
attrs.m_StrokeWidth = std::max( aItem->GetEffectiveTextPenWidth(),
m_renderSettings.GetDefaultPenWidth() );
font->Draw( m_gal, aItem->GetShownText( true ), aItem->GetTextPos(), attrs );
font->Draw( m_gal, aItem->GetShownText( true ), aItem->GetTextPos(), attrs,
aItem->GetFontMetrics() );
}

View File

@ -22,11 +22,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file eda_text.cpp
* @brief Implementation of base KiCad text object.
*/
#include <algorithm> // for max
#include <stddef.h> // for NULL
#include <type_traits> // for swap
@ -473,6 +468,11 @@ KIFONT::FONT* EDA_TEXT::getDrawFont() const
}
const KIFONT::METRICS& EDA_TEXT::getFontMetrics() const
{
return KIFONT::METRICS::Default();
}
void EDA_TEXT::ClearRenderCache()
{
@ -508,7 +508,7 @@ EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolved
attrs.m_Angle = resolvedAngle;
font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
attrs );
attrs, getFontMetrics() );
m_render_cache_font = aFont;
m_render_cache_angle = resolvedAngle;
m_render_cache_text = forResolvedText;
@ -538,7 +538,7 @@ void EDA_TEXT::AddRenderCacheGlyph( const SHAPE_POLY_SET& aPoly )
int EDA_TEXT::GetInterline() const
{
return KiROUND( getDrawFont()->GetInterline( GetTextHeight() ) );
return KiROUND( getDrawFont()->GetInterline( GetTextHeight(), getFontMetrics() ) );
}
@ -577,20 +577,21 @@ BOX2I EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
VECTOR2D fontSize( GetTextSize() );
bool bold = IsBold();
bool italic = IsItalic();
VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic );
VECTOR2I extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
getFontMetrics() );
int overbarOffset = 0;
// Creates bounding box (rectangle) for horizontal, left and top justified text. The
// bounding box will be moved later according to the actual text options
VECTOR2I textsize = VECTOR2I( extents.x, extents.y );
VECTOR2I pos = drawPos;
int fudgeFactor = extents.y * 0.17;
int fudgeFactor = KiROUND( extents.y * 0.17 );
if( font->IsStroke() )
textsize.y += fudgeFactor;
if( IsMultilineAllowed() && aLine > 0 && aLine < (int) strings.GetCount() )
pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y ) );
pos.y -= KiROUND( aLine * font->GetInterline( fontSize.y, getFontMetrics() ) );
if( text.Contains( wxT( "~{" ) ) )
overbarOffset = extents.y / 6;
@ -606,13 +607,15 @@ BOX2I EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
for( unsigned ii = 1; ii < strings.GetCount(); ii++ )
{
text = strings.Item( ii );
extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic );
extents = font->StringBoundaryLimits( text, fontSize, thickness, bold, italic,
getFontMetrics() );
textsize.x = std::max( textsize.x, extents.x );
}
// interline spacing is only *between* lines, so total height is the height of the first
// line plus the interline distance (with interline spacing) for all subsequent lines
textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y ) );
textsize.y += KiROUND( ( strings.GetCount() - 1 ) * font->GetInterline( fontSize.y,
getFontMetrics() ) );
}
textsize.y += overbarOffset;
@ -780,7 +783,7 @@ void EDA_TEXT::printOneLineOfText( const RENDER_SETTINGS* aSettings, const VECTO
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
GRPrintText( DC, aOffset + aPos, aColor, aText, GetDrawRotation(), size, GetHorizJustify(),
GetVertJustify(), penWidth, IsItalic(), IsBold(), font );
GetVertJustify(), penWidth, IsItalic(), IsBold(), font, getFontMetrics() );
}
@ -949,7 +952,7 @@ std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangula
if( cache )
callback_gal.DrawGlyphs( *cache );
else
font->Draw( &callback_gal, shownText, drawPos, attrs );
font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
}
else
{
@ -969,7 +972,7 @@ std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangula
if( cache )
callback_gal.DrawGlyphs( *cache );
else
font->Draw( &callback_gal, shownText, drawPos, attrs );
font->Draw( &callback_gal, shownText, drawPos, attrs, getFontMetrics() );
}
return shape;

View File

@ -46,6 +46,15 @@
using namespace KIFONT;
METRICS g_defaultMetrics;
const METRICS& METRICS::Default()
{
return g_defaultMetrics;
}
FONT* FONT::s_defaultFont = nullptr;
std::map< std::tuple<wxString, bool, bool>, FONT*> FONT::s_fontMap;
@ -165,20 +174,21 @@ bool FONT::IsStroke( const wxString& aFontName )
void FONT::getLinePositions( const wxString& aText, const VECTOR2I& aPosition,
wxArrayString& aTextLines, std::vector<VECTOR2I>& aPositions,
std::vector<VECTOR2I>& aExtents, const TEXT_ATTRIBUTES& aAttrs ) const
std::vector<VECTOR2I>& aExtents, const TEXT_ATTRIBUTES& aAttrs,
const METRICS& aFontMetrics ) const
{
wxStringSplit( aText, aTextLines, '\n' );
int lineCount = aTextLines.Count();
aPositions.reserve( lineCount );
int interline = GetInterline( aAttrs.m_Size.y, aAttrs.m_LineSpacing );
int interline = GetInterline( aAttrs.m_Size.y, aFontMetrics ) * aAttrs.m_LineSpacing;
int height = 0;
for( int i = 0; i < lineCount; i++ )
{
VECTOR2I pos( aPosition.x, aPosition.y + i * interline );
VECTOR2I end = boundingBoxSingleLine( nullptr, aTextLines[i], pos, aAttrs.m_Size,
aAttrs.m_Italic );
aAttrs.m_Italic, aFontMetrics );
VECTOR2I bBox( end - pos );
aExtents.push_back( bBox );
@ -236,7 +246,8 @@ void FONT::getLinePositions( const wxString& aText, const VECTOR2I& aPosition,
* @param aAttrs are the styling attributes of the text, including its rotation
*/
void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosition,
const VECTOR2I& aCursor, const TEXT_ATTRIBUTES& aAttrs ) const
const VECTOR2I& aCursor, const TEXT_ATTRIBUTES& aAttrs,
const METRICS& aFontMetrics ) const
{
if( !aGal || aText.empty() )
return;
@ -248,7 +259,7 @@ void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosit
std::vector<VECTOR2I> positions;
std::vector<VECTOR2I> extents;
getLinePositions( aText, position, strings_list, positions, extents, aAttrs );
getLinePositions( aText, position, strings_list, positions, extents, aAttrs, aFontMetrics );
aGal->SetLineWidth( aAttrs.m_StrokeWidth );
@ -256,7 +267,7 @@ void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosit
{
drawSingleLineText( aGal, nullptr, strings_list[i], positions[i], aAttrs.m_Size,
aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, aAttrs.m_Italic,
aAttrs.m_Underlined );
aAttrs.m_Underlined, aFontMetrics );
}
}
@ -267,7 +278,8 @@ void FONT::Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosit
VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
const MARKUP::NODE* aNode, const VECTOR2I& aPosition,
const KIFONT::FONT* aFont, const VECTOR2I& aSize, const EDA_ANGLE& aAngle,
bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle )
bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle,
const METRICS& aFontMetrics )
{
VECTOR2I nextPosition = aPosition;
bool drawUnderline = false;
@ -307,7 +319,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* a
for( const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
{
nextPosition = drawMarkup( aBoundingBox, aGlyphs, child.get(), nextPosition, aFont,
aSize, aAngle, aMirror, aOrigin, textStyle );
aSize, aAngle, aMirror, aOrigin, textStyle, aFontMetrics );
}
}
@ -315,7 +327,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* a
{
// Shorten the bar a little so its rounded ends don't make it over-long
double barTrim = aSize.x * 0.1;
double barOffset = aFont->ComputeUnderlineVerticalPosition( aSize.y );
double barOffset = aFontMetrics.GetUnderlineVerticalPosition( aSize.y );
VECTOR2D barStart( aPosition.x + barTrim, aPosition.y - barOffset );
VECTOR2D barEnd( nextPosition.x - barTrim, nextPosition.y - barOffset );
@ -337,7 +349,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* a
{
// Shorten the bar a little so its rounded ends don't make it over-long
double barTrim = aSize.x * 0.1;
double barOffset = aFont->ComputeOverbarVerticalPosition( aSize.y );
double barOffset = aFontMetrics.GetOverbarVerticalPosition( aSize.y );
VECTOR2D barStart( aPosition.x + barTrim, aPosition.y - barOffset );
VECTOR2D barEnd( nextPosition.x - barTrim, nextPosition.y - barOffset );
@ -362,7 +374,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* a
VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
const wxString& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize,
const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin,
TEXT_STYLE_FLAGS aTextStyle ) const
TEXT_STYLE_FLAGS aTextStyle, const METRICS& aFontMetrics ) const
{
std::lock_guard<std::mutex> lock( s_markupCacheMutex );
@ -381,14 +393,14 @@ VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYP
wxASSERT( markup && markup->root );
return ::drawMarkup( aBoundingBox, aGlyphs, markup->root.get(), aPosition, this, aSize, aAngle,
aMirror, aOrigin, aTextStyle );
aMirror, aOrigin, aTextStyle, aFontMetrics );
}
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, bool aUnderline ) const
bool aItalic, bool aUnderline, const METRICS& aFontMetrics ) const
{
if( !aGal )
return;
@ -404,14 +416,14 @@ void FONT::drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const wxSt
std::vector<std::unique_ptr<GLYPH>> glyphs;
(void) drawMarkup( aBoundingBox, &glyphs, aText, aPosition, aSize, aAngle, aMirror, aOrigin,
textStyle );
textStyle, aFontMetrics );
aGal->DrawGlyphs( glyphs );
}
VECTOR2I FONT::StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSize, int aThickness,
bool aBold, bool aItalic ) const
bool aBold, bool aItalic, const METRICS& aFontMetrics ) const
{
// TODO do we need to parse every time - have we already parsed?
BOX2I boundingBox;
@ -424,7 +436,7 @@ VECTOR2I FONT::StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSiz
textStyle |= TEXT_STYLE::ITALIC;
(void) drawMarkup( &boundingBox, nullptr, aText, VECTOR2I(), aSize, ANGLE_0, false, VECTOR2I(),
textStyle );
textStyle, aFontMetrics );
if( IsStroke() )
{
@ -442,7 +454,7 @@ VECTOR2I FONT::StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSiz
VECTOR2I FONT::boundingBoxSingleLine( BOX2I* aBBox, const wxString& aText,
const VECTOR2I& aPosition, const VECTOR2I& aSize,
bool aItalic ) const
bool aItalic, const METRICS& aFontMetrics ) const
{
TEXT_STYLE_FLAGS textStyle = 0;
@ -450,7 +462,7 @@ VECTOR2I FONT::boundingBoxSingleLine( BOX2I* aBBox, const wxString& aText,
textStyle |= TEXT_STYLE::ITALIC;
VECTOR2I extents = drawMarkup( aBBox, nullptr, aText, aPosition, aSize, ANGLE_0, false,
VECTOR2I(), textStyle );
VECTOR2I(), textStyle, aFontMetrics );
return extents;
}

View File

@ -4,8 +4,6 @@
* Copyright (C) 2021 Ola Rinta-Koski <gitlab@rinta-koski.net>
* Copyright (C) 2021-2023 Kicad Developers, see AUTHORS.txt for contributors.
*
* Outline font class
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@ -146,47 +144,18 @@ FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName, int aFaceIndex )
}
/**
* Compute the vertical position of an overbar. This is the distance between the text
* baseline and the overbar.
*/
double OUTLINE_FONT::ComputeOverbarVerticalPosition( double aGlyphHeight ) const
{
// The overbar on actual text is positioned above the bounding box of the glyphs. However,
// that's expensive to calculate so we use an estimation here (as this is only used for
// calculating bounding boxes).
return aGlyphHeight * m_outlineFontSizeCompensation;
}
/**
* 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.
*/
double OUTLINE_FONT::GetInterline( double aGlyphHeight, double aLineSpacing ) const
double OUTLINE_FONT::GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const
{
double pitch = INTERLINE_PITCH_RATIO;
double glyphToFontHeight = 1.0;
if( GetFace()->units_per_EM )
pitch = GetFace()->height / GetFace()->units_per_EM;
glyphToFontHeight = GetFace()->height / GetFace()->units_per_EM;
double interline = aLineSpacing * aGlyphHeight * pitch * m_outlineFontSizeCompensation;
// FONT TODO this hack is an attempt to fix interline spacing by eyeballing it
static constexpr double interlineHackMultiplier = 1.2;
interline *= interlineHackMultiplier;
return interline;
return aFontMetrics.GetInterline( aGlyphHeight * glyphToFontHeight );
}
@ -241,7 +210,8 @@ BOX2I OUTLINE_FONT::getBoundingBox( const std::vector<std::unique_ptr<GLYPH>>& a
void OUTLINE_FONT::GetLinesAsGlyphs( std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
const wxString& aText, const VECTOR2I& aPosition,
const TEXT_ATTRIBUTES& aAttrs ) const
const TEXT_ATTRIBUTES& aAttrs,
const METRICS& aFontMetrics ) const
{
wxArrayString strings;
std::vector<VECTOR2I> positions;
@ -251,12 +221,12 @@ void OUTLINE_FONT::GetLinesAsGlyphs( std::vector<std::unique_ptr<GLYPH>>* aGlyph
if( aAttrs.m_Italic )
textStyle |= TEXT_STYLE::ITALIC;
getLinePositions( aText, aPosition, strings, positions, extents, aAttrs );
getLinePositions( aText, aPosition, strings, positions, extents, aAttrs, aFontMetrics );
for( size_t i = 0; i < strings.GetCount(); i++ )
{
(void) drawMarkup( nullptr, aGlyphs, strings.Item( i ), positions[i], aAttrs.m_Size,
aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, textStyle );
aAttrs.m_Angle, aAttrs.m_Mirrored, aPosition, textStyle, aFontMetrics );
}
}

View File

@ -6,8 +6,6 @@
* @author Maciej Suminski <maciej.suminski@cern.ch>
* Copyright (C) 2016-2023 Kicad Developers, see AUTHORS.txt for contributors.
*
* Stroke font class
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@ -43,12 +41,6 @@
using namespace KIFONT;
///< Factor that determines relative vertical position of the overbar.
static constexpr double OVERBAR_POSITION_FACTOR = 1.23;
///< 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;
@ -199,23 +191,11 @@ void STROKE_FONT::loadNewStrokeFont( const char* const aNewStrokeFont[], int aNe
}
double STROKE_FONT::GetInterline( double aGlyphHeight, double aLineSpacing ) const
double STROKE_FONT::GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const
{
// Do not add the glyph thickness to the interline. This makes bold text line-spacing
// different from normal text, which is poor typography.
return ( aGlyphHeight * aLineSpacing * INTERLINE_PITCH_RATIO );
}
static double LEGACY_FACTOR = 1.0435; // Adjustment to match legacy spacing
double STROKE_FONT::ComputeOverbarVerticalPosition( double aGlyphHeight ) const
{
return aGlyphHeight * OVERBAR_POSITION_FACTOR;
}
double STROKE_FONT::ComputeUnderlineVerticalPosition( double aGlyphHeight ) const
{
return aGlyphHeight * UNDERLINE_POSITION_FACTOR;
return aFontMetrics.GetInterline( aGlyphHeight ) * LEGACY_FACTOR;
}

View File

@ -18,7 +18,6 @@
*/
#include <font/text_attributes.h>
#include <font/outline_font.h>
@ -68,10 +67,10 @@ int TEXT_ATTRIBUTES::Compare( const TEXT_ATTRIBUTES& aRhs ) const
return m_StrokeWidth - aRhs.m_StrokeWidth;
if( m_Angle.AsDegrees() != aRhs.m_Angle.AsDegrees() )
return m_Angle.AsDegrees() - aRhs.m_Angle.AsDegrees();
return m_Angle.AsDegrees() < aRhs.m_Angle.AsDegrees() ? -1 : 1;
if( m_LineSpacing != aRhs.m_LineSpacing )
return m_LineSpacing - aRhs.m_LineSpacing;
return m_LineSpacing < aRhs.m_LineSpacing ? -1 : 1;
if( m_Halign != aRhs.m_Halign )
return m_Halign - aRhs.m_Halign;

View File

@ -273,7 +273,7 @@ void GAL::BitmapText( const wxString& aText, const VECTOR2I& aPosition, const ED
attrs.m_Size = VECTOR2I( m_attributes.m_Size.x, m_attributes.m_Size.y * 0.95 );
attrs.m_StrokeWidth = GetLineWidth() * 0.74;
font->Draw( this, aText, aPosition, attrs );
font->Draw( this, aText, aPosition, attrs, KIFONT::METRICS::Default() );
}

View File

@ -110,13 +110,14 @@ int Clamp_Text_PenSize( int aPenSize, const VECTOR2I& aSize, bool aStrict )
}
int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize,
int aThickness, bool aBold, bool aItalic )
int GRTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize,
int aThickness, bool aBold, bool aItalic, const KIFONT::METRICS& aFontMetrics )
{
if( !aFont )
aFont = KIFONT::FONT::GetFont();
return KiROUND( aFont->StringBoundaryLimits( aText, aSize, aThickness, aBold, aItalic ).x );
return KiROUND( aFont->StringBoundaryLimits( aText, aSize, aThickness, aBold, aItalic,
aFontMetrics ).x );
}
@ -141,7 +142,8 @@ int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I
void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const COLOR4D& aColor, const wxString& aText,
const EDA_ANGLE& aOrient, const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont )
int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics )
{
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
bool fill_mode = true;
@ -182,7 +184,7 @@ void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const COLOR4D& aColor, const
attributes.m_Valign = aV_justify;
attributes.m_Size = aSize;
aFont->Draw( &callback_gal, aText, aPos, attributes );
aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics );
}

View File

@ -863,19 +863,20 @@ bool containsNonAsciiChars( const wxString& string )
}
void DXF_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
void* aData )
void DXF_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
// Fix me: see how to use DXF text mode for multiline texts
if( aMultilineAllowed && !aText.Contains( wxT( "\n" ) ) )
@ -889,7 +890,7 @@ void DXF_PLOTTER::Text( const VECTOR2I& aPos,
// Perhaps multiline texts could be handled as DXF text entity
// but I do not want spend time about this (JPC)
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
aBold, aMultilineAllowed, aFont, aData );
aBold, aMultilineAllowed, aFont, aFontMetrics, aData );
}
else
{
@ -907,11 +908,13 @@ void DXF_PLOTTER::Text( const VECTOR2I& aPos,
}
void DXF_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData )
void DXF_PLOTTER::PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
TEXT_ATTRIBUTES attrs = aAttributes;
// Fix me: see how to use DXF text mode for multiline texts
@ -925,15 +928,16 @@ void DXF_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
// output text as graphics.
// Perhaps multiline texts could be handled as DXF text entity
// but I do not want spend time about that (JPC)
PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aData );
PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aFontMetrics, aData );
}
else
plotOneLineOfText( aPos, aColor, aText, attrs );
{
plotOneLineOfText( aPos, aColor, aText, attrs );
}
}
void DXF_PLOTTER::plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes )
const wxString& aText, const TEXT_ATTRIBUTES& aAttributes )
{
/* Emit text as a text entity. This loses formatting and shape but it's
more useful as a CAD object */
@ -989,9 +993,9 @@ void DXF_PLOTTER::plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor
"%d\n" // H alignment
" 73\n"
"%d\n", // V alignment
aAttributes.m_Bold ?
(aAttributes.m_Italic ? "KICADBI" : "KICADB")
: (aAttributes.m_Italic ? "KICADI" : "KICAD"), TO_UTF8( cname ),
aAttributes.m_Bold ? ( aAttributes.m_Italic ? "KICADBI" : "KICADB" )
: ( aAttributes.m_Italic ? "KICADI" : "KICAD" ),
TO_UTF8( cname ),
formatCoord( origin_dev.x ).c_str(), formatCoord( origin_dev.x ).c_str(),
formatCoord( origin_dev.y ).c_str(), formatCoord( origin_dev.y ).c_str(),
formatCoord( size_dev.y ).c_str(), formatCoord( fabs( size_dev.x / size_dev.y ) ).c_str(),

View File

@ -1976,19 +1976,20 @@ void GERBER_PLOTTER::FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiamet
}
void GERBER_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
void* aData )
void GERBER_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
@ -1996,22 +1997,24 @@ void GERBER_PLOTTER::Text( const VECTOR2I& aPos,
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth,
aItalic, aBold, aMultilineAllowed, aFont, aData );
aItalic, aBold, aMultilineAllowed, aFont, aFontMetrics, aData );
}
void GERBER_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData )
void GERBER_PLOTTER::PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
if( gbr_metadata )
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aData );
PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aFontMetrics, aData );
}
void GERBER_PLOTTER::SetLayerPolarity( bool aPositive )

View File

@ -1551,19 +1551,20 @@ function ShM(aEntries) {
}
void PDF_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
void* aData )
void PDF_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
// PDF files do not like 0 sized texts which create broken files.
if( aSize.x == 0 || aSize.y == 0 )
@ -1596,7 +1597,8 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
if( !aFont )
aFont = KIFONT::FONT::GetFont();
VECTOR2I full_box( aFont->StringBoundaryLimits( aText, t_size, aWidth, aBold, aItalic ) );
VECTOR2I full_box( aFont->StringBoundaryLimits( aText, t_size, aWidth, aBold, aItalic,
aFontMetrics ) );
VECTOR2I box_x( full_box.x, 0 );
VECTOR2I box_y( 0, full_box.y );
@ -1623,7 +1625,8 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
// Extract the changed width and rotate by the orientation to get the offset for the
// next word
VECTOR2I bbox( aFont->StringBoundaryLimits( word, t_size, aWidth, aBold, aItalic ).x, 0 );
VECTOR2I bbox( aFont->StringBoundaryLimits( word, t_size, aWidth,
aBold, aItalic, aFontMetrics ).x, 0 );
RotatePoint( bbox, aOrient );
pos += bbox;
@ -1647,15 +1650,17 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
// Plot the stroked text (if requested)
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
aBold, aMultilineAllowed, aFont );
aBold, aMultilineAllowed, aFont, aFontMetrics );
}
void PDF_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData )
void PDF_PLOTTER::PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
VECTOR2I size = aAttributes.m_Size;
@ -1666,12 +1671,9 @@ void PDF_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
if( aAttributes.m_Mirrored )
size.x = -size.x;
PDF_PLOTTER::Text( aPos, aColor, aText, aAttributes.m_Angle, size,
aAttributes.m_Halign, aAttributes.m_Valign,
aAttributes.m_StrokeWidth,
aAttributes.m_Italic, aAttributes.m_Bold,
aAttributes.m_Multiline,
aFont, aData );
PDF_PLOTTER::Text( aPos, aColor, aText, aAttributes.m_Angle, size, aAttributes.m_Halign,
aAttributes.m_Valign, aAttributes.m_StrokeWidth, aAttributes.m_Italic,
aAttributes.m_Bold, aAttributes.m_Multiline, aFont, aFontMetrics, aData );
}

View File

@ -333,15 +333,11 @@ int PSLIKE_PLOTTER::returnPostscriptTextWidth( const wxString& aText, int aXSize
: ( aItalic ? hvo_widths : hv_widths );
double tally = 0;
for( unsigned i = 0; i < aText.length(); i++ )
for( wchar_t asciiCode : aText)
{
wchar_t AsciiCode = aText[i];
// Skip the negation marks and untabled points.
if( AsciiCode != '~' && AsciiCode < 256 )
{
tally += width_table[AsciiCode];
}
if( asciiCode != '~' && asciiCode < 256 )
tally += width_table[asciiCode];
}
// Widths are proportional to height, but height is enlarged by a scaling factor.
@ -349,38 +345,6 @@ int PSLIKE_PLOTTER::returnPostscriptTextWidth( const wxString& aText, int aXSize
}
void PSLIKE_PLOTTER::postscriptOverlinePositions( const wxString& aText, int aXSize,
bool aItalic, bool aBold,
std::vector<int> *pos_pairs )
{
/* XXX This function is *too* similar to returnPostscriptTextWidth.
Consider merging them... */
const double *width_table = aBold ? ( aItalic ? hvbo_widths : hvb_widths )
: ( aItalic ? hvo_widths : hv_widths );
double tally = 0;
for( unsigned i = 0; i < aText.length(); i++ )
{
wchar_t AsciiCode = aText[i];
// Skip the negation marks and untabled points
if( AsciiCode != '~' && AsciiCode < 256 )
{
tally += width_table[AsciiCode];
}
else
{
if( AsciiCode == '~' )
pos_pairs->push_back( KiROUND( aXSize * tally / postscriptTextAscent ) );
}
}
// Special rule: we have to complete the last bar if the ~ aren't matched
if( pos_pairs->size() % 2 == 1 )
pos_pairs->push_back( KiROUND( aXSize * tally / postscriptTextAscent ) );
}
void PS_PLOTTER::SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
double aScale, bool aMirror )
{
@ -937,19 +901,20 @@ bool PS_PLOTTER::EndPlot()
void PS_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
void* aData )
void PS_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
SetCurrentLineWidth( aWidth );
SetColor( aColor );
@ -963,16 +928,17 @@ void PS_PLOTTER::Text( const VECTOR2I& aPos,
}
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
aBold, aMultilineAllowed, aFont, aData );
aBold, aMultilineAllowed, aFont, aFontMetrics, aData );
}
void PS_PLOTTER::PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData )
void PS_PLOTTER::PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
SetCurrentLineWidth( aAttributes.m_StrokeWidth );
SetColor( aColor );
@ -985,7 +951,7 @@ void PS_PLOTTER::PlotText( const VECTOR2I& aPos,
fprintf( m_outputFile, "%s %g %g phantomshow\n", ps_test.c_str(), pos_dev.x, pos_dev.y );
}
PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aData );
PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aFontMetrics, aData );
}

View File

@ -169,7 +169,6 @@ SVG_PLOTTER::SVG_PLOTTER()
m_brush_rgb_color = 0; // current color value (black)
m_brush_alpha = 1.0;
m_dashed = PLOT_DASH_TYPE::SOLID;
m_useInch = false; // millimeters are always the svg unit
m_precision = 4; // default: 4 digits in mantissa.
}
@ -778,19 +777,20 @@ bool SVG_PLOTTER::EndPlot()
}
void SVG_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
void* aData )
void SVG_PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
setFillMode( FILL_T::NO_FILL );
SetColor( aColor );
@ -817,7 +817,7 @@ void SVG_PLOTTER::Text( const VECTOR2I& aPos,
// aSize.x or aSize.y is < 0 for mirrored texts.
// The actual text size value is the absolute value
text_size.x = std::abs( GraphicTextWidth( aText, aFont, aSize, aWidth, aBold, aItalic ) );
text_size.x = std::abs( GRTextWidth( aText, aFont, aSize, aWidth, aBold, aItalic, aFontMetrics ) );
text_size.y = std::abs( aSize.x * 4/3 ); // Hershey font height to em size conversion
VECTOR2D anchor_pos_dev = userToDeviceCoordinates( aPos );
VECTOR2D text_pos_dev = userToDeviceCoordinates( text_pos );
@ -849,27 +849,26 @@ void SVG_PLOTTER::Text( const VECTOR2I& aPos,
TO_UTF8( XmlEsc( aText ) ) );
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
aBold, aMultilineAllowed, aFont );
aBold, aMultilineAllowed, aFont, aFontMetrics );
fputs( "</g>", m_outputFile );
}
void SVG_PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData )
void SVG_PLOTTER::PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
VECTOR2I size = aAttributes.m_Size;
if( aAttributes.m_Mirrored )
size.x = -size.x;
SVG_PLOTTER::Text( aPos, aColor, aText, aAttributes.m_Angle, size,
aAttributes.m_Halign, aAttributes.m_Valign,
aAttributes.m_StrokeWidth,
aAttributes.m_Italic, aAttributes.m_Bold,
aAttributes.m_Multiline,
aFont, aData );
SVG_PLOTTER::Text( aPos, aColor, aText, aAttributes.m_Angle, size, aAttributes.m_Halign,
aAttributes.m_Valign, aAttributes.m_StrokeWidth, aAttributes.m_Italic,
aAttributes.m_Bold, aAttributes.m_Multiline, aFont, aFontMetrics, aData );
}

View File

@ -153,7 +153,7 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL
plotter->Text( text->GetTextPos(), color, text->GetShownText( true ),
text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(),
text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(),
text->IsMultilineAllowed(), font );
text->IsMultilineAllowed(), font, text->GetFontMetrics() );
}
break;

View File

@ -712,19 +712,20 @@ void PLOTTER::PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill, int a
}
void PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aPenWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
void* aData )
void PLOTTER::Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aPenWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
@ -770,14 +771,16 @@ void PLOTTER::Text( const VECTOR2I& aPos,
if( !aFont )
aFont = KIFONT::FONT::GetFont();
aFont->Draw( &callback_gal, aText, aPos, attributes );
aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics );
}
void PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData )
void PLOTTER::PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData )
{
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
@ -812,5 +815,5 @@ void PLOTTER::PlotText( const VECTOR2I& aPos, const COLOR4D& aColor,
if( !aFont )
aFont = KIFONT::FONT::GetFont();
aFont->Draw( &callback_gal, aText, aPos, attributes );
aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics );
}

View File

@ -187,6 +187,6 @@ void KIGFX::PREVIEW::DrawTextNextToCursor( KIGFX::VIEW* aView, const VECTOR2D& a
for( const wxString& str : aStrings )
{
textPos.y += textDims.LinePitch;
font->Draw( gal, str, textPos, textAttrs );
font->Draw( gal, str, textPos, textAttrs, KIFONT::METRICS::Default() );
}
}

View File

@ -248,7 +248,7 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT
if( drawLabel )
{
wxString label = DimensionLabel( "", tickSpace * i, aIuScale, aUnits, false );
font->Draw( gal, label, tickPos + labelOffset, labelAttrs );
font->Draw( gal, label, tickPos + labelOffset, labelAttrs, KIFONT::METRICS::Default() );
}
}
}

View File

@ -110,6 +110,7 @@ bool PANEL_SETUP_FORMATTING::TransferDataToWindow()
ctrl->SetValue( EDA_UNIT_UTILS::UI::StringFromValue( unityScale, units, value ) )
SET_VALUE( m_textOffsetRatioCtrl, EDA_UNITS::PERCENT, settings.m_TextOffsetRatio * 100.0 );
SET_VALUE( m_overbarHeightCtrl, EDA_UNITS::PERCENT, settings.m_FontMetrics.m_OverbarHeight * 100.0 );
SET_VALUE( m_dashLengthCtrl, EDA_UNITS::UNSCALED, settings.m_DashedLineDashRatio );
SET_VALUE( m_gapLengthCtrl, EDA_UNITS::UNSCALED, settings.m_DashedLineGapRatio );
SET_VALUE( m_labelSizeRatioCtrl, EDA_UNITS::PERCENT, settings.m_LabelSizeRatio * 100.0 );
@ -166,6 +167,7 @@ bool PANEL_SETUP_FORMATTING::TransferDataFromWindow()
#define GET_VALUE( units, str ) EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, units, str )
settings.m_TextOffsetRatio = GET_VALUE( EDA_UNITS::PERCENT, m_textOffsetRatioCtrl->GetValue() ) / 100.0;
settings.m_FontMetrics.m_OverbarHeight = GET_VALUE( EDA_UNITS::PERCENT, m_overbarHeightCtrl->GetValue() ) / 100.0;
settings.m_DashedLineDashRatio = GET_VALUE( EDA_UNITS::UNSCALED, m_dashLengthCtrl->GetValue() );
settings.m_DashedLineGapRatio = GET_VALUE( EDA_UNITS::UNSCALED, m_gapLengthCtrl->GetValue() );
settings.m_LabelSizeRatio = GET_VALUE( EDA_UNITS::PERCENT, m_labelSizeRatioCtrl->GetValue() ) / 100.0;

View File

@ -63,6 +63,17 @@ PANEL_SETUP_FORMATTING_BASE::PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWi
m_textSizeUnits->Wrap( -1 );
fgSizer2->Add( m_textSizeUnits, 0, wxALIGN_CENTER_VERTICAL|wxFIXED_MINSIZE, 5 );
m_overbarHieghtLabel = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Overbar offset ratio:"), wxDefaultPosition, wxDefaultSize, 0 );
m_overbarHieghtLabel->Wrap( -1 );
fgSizer2->Add( m_overbarHieghtLabel, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_overbarHeightCtrl = new wxTextCtrl( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_overbarHeightCtrl, 0, wxEXPAND, 5 );
m_overbarHeightUnits = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("%"), wxDefaultPosition, wxDefaultSize, 0 );
m_overbarHeightUnits->Wrap( -1 );
fgSizer2->Add( m_overbarHeightUnits, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_textOffsetRatioLabel = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Label offset ratio:"), wxDefaultPosition, wxDefaultSize, 0 );
m_textOffsetRatioLabel->Wrap( -1 );
m_textOffsetRatioLabel->SetToolTip( _("Percentage of the text size to offset labels above (or below) a wire, bus, or pin") );
@ -78,7 +89,7 @@ PANEL_SETUP_FORMATTING_BASE::PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWi
m_offsetRatioUnits->Wrap( -1 );
fgSizer2->Add( m_offsetRatioUnits, 0, wxALIGN_CENTER_VERTICAL|wxFIXED_MINSIZE, 5 );
m_labelSizeRatioLabel = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Global label margin:"), wxDefaultPosition, wxDefaultSize, 0 );
m_labelSizeRatioLabel = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Global label margin ratio:"), wxDefaultPosition, wxDefaultSize, 0 );
m_labelSizeRatioLabel->Wrap( -1 );
m_labelSizeRatioLabel->SetToolTip( _("Percentage of the text size to use as space around a global label") );

View File

@ -430,6 +430,192 @@
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Overbar offset ratio:</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_overbarHieghtLabel</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_overbarHeightCtrl</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">%</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_overbarHeightUnits</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL</property>
@ -648,7 +834,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Global label margin:</property>
<property name="label">Global label margin ratio:</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>

View File

@ -45,6 +45,9 @@ class PANEL_SETUP_FORMATTING_BASE : public wxPanel
wxStaticText* m_textSizeLabel;
wxTextCtrl* m_textSizeCtrl;
wxStaticText* m_textSizeUnits;
wxStaticText* m_overbarHieghtLabel;
wxTextCtrl* m_overbarHeightCtrl;
wxStaticText* m_overbarHeightUnits;
wxStaticText* m_textOffsetRatioLabel;
wxTextCtrl* m_textOffsetRatioCtrl;
wxStaticText* m_offsetRatioUnits;

View File

@ -155,7 +155,7 @@ void LIB_FIELD::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
GRPrintText( DC, text_pos, color, text, GetTextAngle(), GetTextSize(), GetHorizJustify(),
GetVertJustify(), penWidth, IsItalic(), IsBold(), font );
GetVertJustify(), penWidth, IsItalic(), IsBold(), font, GetFontMetrics() );
}
@ -402,7 +402,7 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs
attrs.m_Angle = orient;
attrs.m_Multiline = false;
aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font );
aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font, GetFontMetrics() );
}

View File

@ -137,6 +137,12 @@ const wxString& LIB_ITEM::GetDefaultFont() const
}
const KIFONT::METRICS& LIB_ITEM::GetFontMetrics() const
{
return KIFONT::METRICS::Default();
}
void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
const TRANSFORM& aTransform, bool aDimmed )
{

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -38,6 +38,13 @@ class PLOTTER;
class LIB_PIN;
class MSG_PANEL_ITEM;
namespace KIFONT
{
class FONT;
class METRICS;
}
using KIGFX::RENDER_SETTINGS;
extern const int fill_tab[];
@ -172,6 +179,8 @@ public:
const wxString& GetDefaultFont() const;
const KIFONT::METRICS& GetFontMetrics() const;
virtual int GetEffectivePenWidth( const RENDER_SETTINGS* aSettings ) const
{
// For historical reasons, a stored value of 0 means "default width" and negative

View File

@ -448,14 +448,14 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos
x = x1 + aTextInside;
GRPrintText( DC, VECTOR2I( x, y1 ), nameColor, name, ANGLE_HORIZONTAL,
pinNameSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER,
namePenWidth, false, false, font );
namePenWidth, false, false, font, GetFontMetrics() );
}
else // Orient == PIN_LEFT
{
x = x1 - aTextInside;
GRPrintText( DC, VECTOR2I( x, y1 ), nameColor, name, ANGLE_HORIZONTAL,
pinNameSize, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER,
namePenWidth, false, false, font );
namePenWidth, false, false, font, GetFontMetrics() );
}
}
@ -463,7 +463,8 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos
{
GRPrintText( DC, VECTOR2I(( x1 + aPinPos.x) / 2, y1 - num_offset ), numColor,
number, ANGLE_HORIZONTAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER,
GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font );
GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font,
GetFontMetrics() );
}
}
else /* Its a vertical line. */
@ -477,14 +478,15 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos
{
GRPrintText( DC, VECTOR2I( x1, y ), nameColor, name, ANGLE_VERTICAL,
pinNameSize, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER,
namePenWidth, false, false, font );
namePenWidth, false, false, font, GetFontMetrics() );
}
if( aDrawPinNum )
{
GRPrintText( DC, VECTOR2I( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
number, ANGLE_VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER,
GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font );
GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font,
GetFontMetrics() );
}
}
else /* PIN_UP */
@ -495,14 +497,15 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos
{
GRPrintText( DC, VECTOR2I( x1, y ), nameColor, name, ANGLE_VERTICAL,
pinNameSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER,
namePenWidth, false, false, font );
namePenWidth, false, false, font, GetFontMetrics() );
}
if( aDrawPinNum )
{
GRPrintText( DC, VECTOR2I( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
number, ANGLE_VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER,
GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font );
GR_TEXT_V_ALIGN_BOTTOM, numPenWidth, false, false, font,
GetFontMetrics() );
}
}
}
@ -518,14 +521,14 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos
x = ( x1 + aPinPos.x ) / 2;
GRPrintText( DC, VECTOR2I( x, y1 - name_offset ), nameColor, name, ANGLE_HORIZONTAL,
pinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM,
namePenWidth, false, false, font );
namePenWidth, false, false, font, GetFontMetrics() );
}
if( aDrawPinNum )
{
x = ( x1 + aPinPos.x ) / 2;
GRPrintText( DC, VECTOR2I( x, y1 + num_offset ), numColor, number, ANGLE_HORIZONTAL,
pinNumSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP,
numPenWidth, false, false, font );
numPenWidth, false, false, font, GetFontMetrics() );
}
}
else /* Its a vertical line. */
@ -535,14 +538,14 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos
y = ( y1 + aPinPos.y) / 2;
GRPrintText( DC, VECTOR2I( x1 - name_offset, y ), nameColor, name, ANGLE_VERTICAL,
pinNameSize, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM,
namePenWidth, false, false, font );
namePenWidth, false, false, font, GetFontMetrics() );
}
if( aDrawPinNum )
{
GRPrintText( DC, VECTOR2I( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
number, ANGLE_VERTICAL, pinNumSize, GR_TEXT_H_ALIGN_CENTER,
GR_TEXT_V_ALIGN_TOP, numPenWidth, false, false, font );
GR_TEXT_V_ALIGN_TOP, numPenWidth, false, false, font, GetFontMetrics() );
}
}
}
@ -612,7 +615,7 @@ void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECT
}
GRPrintText( DC, txtpos, color, typeName, orient, VECTOR2I( textSize, textSize ), hjustify,
GR_TEXT_V_ALIGN_CENTER, pensize, false, false, font );
GR_TEXT_V_ALIGN_CENTER, pensize, false, false, font, GetFontMetrics() );
}
@ -826,7 +829,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIE
attrs.m_Valign = vJustify;
attrs.m_Multiline = false;
aPlotter->PlotText( VECTOR2I( px, py ), color, text, attrs, font );
aPlotter->PlotText( VECTOR2I( px, py ), color, text, attrs, font, GetFontMetrics() );
};
/* Draw the text inside, but the pin numbers outside. */
@ -1231,8 +1234,10 @@ void LIB_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxStri
VECTOR2D fontSize( aSize, aSize );
int penWidth = GetPenSizeForNormal( aSize );
aCache->m_Extents.x = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false ).x;
aCache->m_Extents.y = aFont->StringBoundaryLimits( hText, fontSize, penWidth, false, false ).y;
aCache->m_Extents.x = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false,
GetFontMetrics() ).x;
aCache->m_Extents.y = aFont->StringBoundaryLimits( hText, fontSize, penWidth, false, false,
GetFontMetrics() ).y;
}
@ -1293,7 +1298,8 @@ const BOX2I LIB_PIN::GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNa
double stroke = fontSize / 8.0;
VECTOR2I typeTextSize = font->StringBoundaryLimits( GetElectricalTypeName(),
VECTOR2D( fontSize, fontSize ),
KiROUND( stroke ), false, false );
KiROUND( stroke ), false, false,
GetFontMetrics() );
typeTextLength = typeTextSize.x + schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + TARGET_PIN_RADIUS;
minsizeV = std::max( minsizeV, typeTextSize.y / 2 );
@ -1313,7 +1319,7 @@ const BOX2I LIB_PIN::GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNa
// pin name is inside the body (or invisible)
// pin number is above the line
begin.y = std::max( minsizeV, numberTextHeight + PIN_TEXT_OFFSET );
begin.x = std::min( -typeTextLength, m_length - ( numberTextLength / 2) );
begin.x = std::min( -typeTextLength, m_length - ( numberTextLength / 2 ) );
end.x = m_length + nameTextLength;
end.y = std::min( -minsizeV, -nameTextHeight / 2 );

View File

@ -327,7 +327,7 @@ void LIB_TEXT::Plot( PLOTTER* plotter, bool aBackground, const VECTOR2I& offset,
attrs.m_StrokeWidth = penWidth;
attrs.m_Angle = t1 ? ANGLE_HORIZONTAL : ANGLE_VERTICAL;
plotter->PlotText( pos, color, GetText(), attrs, font );
plotter->PlotText( pos, color, GetText(), attrs, font, GetFontMetrics() );
}
@ -411,7 +411,7 @@ void LIB_TEXT::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
GRPrintText( DC, txtpos, color, GetShownText( true ), orient, GetTextSize(),
GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(),
font );
font, GetFontMetrics() );
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -323,7 +323,7 @@ void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
GRPrintText( DC, text.GetDrawPos(), color, text.GetShownText( true ), text.GetTextAngle(),
text.GetTextSize(), text.GetHorizJustify(), text.GetVertJustify(), penWidth,
text.IsItalic(), text.IsBold(), font );
text.IsItalic(), text.IsBold(), font, GetFontMetrics() );
}
@ -472,7 +472,8 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
{
aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font );
aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font,
GetFontMetrics() );
}
}

View File

@ -310,7 +310,8 @@ SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forP
{
m_renderCache.clear();
outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs );
outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs,
GetFontMetrics() );
m_renderCachePos = forPosition;
m_renderCacheValid = true;
@ -402,7 +403,7 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
GRPrintText( DC, textpos, color, GetShownText( true ), orient, GetTextSize(),
GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(),
font );
font, GetFontMetrics() );
}
@ -1204,7 +1205,7 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const
attrs.m_Angle = orient;
attrs.m_Multiline = false;
aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font );
aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font, GetFontMetrics() );
if( IsHypertext() )
{

View File

@ -270,6 +270,8 @@ public:
protected:
KIFONT::FONT* getDrawFont() const override;
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
private:
int m_id; ///< Field index, @see enum MANDATORY_FIELD_T

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -323,6 +323,15 @@ const wxString& SCH_ITEM::GetDefaultFont() const
}
const KIFONT::METRICS& SCH_ITEM::GetFontMetrics() const
{
if( SCHEMATIC* schematic = Schematic() )
return schematic->Settings().m_FontMetrics;
return KIFONT::METRICS::Default();
}
bool SCH_ITEM::RenderAsBitmap( double aWorldScale ) const
{
if( IsHypertext() )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -42,12 +42,15 @@ class SCH_SHEET_PATH;
class SCHEMATIC;
class LINE_READER;
class SCH_EDIT_FRAME;
class wxFindReplaceData;
class PLOTTER;
class NETLIST_OBJECT;
class NETLIST_OBJECT_LIST;
class PLOTTER;
namespace KIFONT
{
class METRICS;
}
using KIGFX::RENDER_SETTINGS;
@ -272,6 +275,8 @@ public:
const wxString& GetDefaultFont() const;
const KIFONT::METRICS& GetFontMetrics() const;
bool RenderAsBitmap( double aWorldScale ) const override;
/**

View File

@ -1074,7 +1074,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const
}
else
{
aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font );
aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font, GetFontMetrics() );
if( s_poly.size() )
aPlotter->PlotPoly( s_poly, FILL_T::NO_FILL, penWidth );

View File

@ -607,7 +607,7 @@ static bool isFieldsLayer( int aLayer )
void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttrs )
const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
{
KIFONT::FONT* font = aAttrs.m_Font;
@ -620,7 +620,7 @@ void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition,
m_gal->SetIsFill( font->IsOutline() );
m_gal->SetIsStroke( font->IsStroke() );
font->Draw( m_gal, aText, aPosition, aAttrs );
font->Draw( m_gal, aText, aPosition, aAttrs, aFontMetrics );
}
@ -640,7 +640,7 @@ void SCH_PAINTER::bitmapText( const wxString& aText, const VECTOR2D& aPosition,
void SCH_PAINTER::knockoutText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttrs )
const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
{
TEXT_ATTRIBUTES attrs( aAttrs );
KIFONT::FONT* font = aAttrs.m_Font;
@ -664,7 +664,7 @@ void SCH_PAINTER::knockoutText( const wxString& aText, const VECTOR2D& aPosition
callback_gal.SetIsFill( false );
callback_gal.SetIsStroke( true );
callback_gal.SetLineWidth( (float) attrs.m_StrokeWidth );
font->Draw( &callback_gal, aText, aPosition, attrs );
font->Draw( &callback_gal, aText, aPosition, attrs, aFontMetrics );
BOX2I bbox = knockouts.BBox( attrs.m_StrokeWidth * 2 );
SHAPE_POLY_SET finalPoly;
@ -686,7 +686,7 @@ void SCH_PAINTER::knockoutText( const wxString& aText, const VECTOR2D& aPosition
void SCH_PAINTER::boxText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttrs )
const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
{
KIFONT::FONT* font = aAttrs.m_Font;
@ -697,7 +697,7 @@ void SCH_PAINTER::boxText( const wxString& aText, const VECTOR2D& aPosition,
}
VECTOR2I extents = font->StringBoundaryLimits( aText, aAttrs.m_Size, aAttrs.m_StrokeWidth,
aAttrs.m_Bold, aAttrs.m_Italic );
aAttrs.m_Bold, aAttrs.m_Italic, aFontMetrics );
BOX2I box( aPosition, VECTOR2I( extents.x, aAttrs.m_Size.y ) );
switch( aAttrs.m_Halign )
@ -1078,7 +1078,8 @@ void SCH_PAINTER::draw( const LIB_FIELD* aField, int aLayer, bool aDimmed )
if( drawingShadows )
attrs.m_StrokeWidth += getShadowWidth( !aField->IsSelected() );
strokeText( UnescapeString( aField->GetShownText( true ) ), textpos, attrs );
strokeText( UnescapeString( aField->GetShownText( true ) ), textpos, attrs,
aField->GetFontMetrics() );
}
// Draw the umbilical line when in the schematic editor
@ -1174,7 +1175,7 @@ void SCH_PAINTER::draw( const LIB_TEXT* aText, int aLayer, bool aDimmed )
// vertically centered.
attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER;
strokeText( shownText, pos, attrs );
strokeText( shownText, pos, attrs, aText->GetFontMetrics() );
}
}
@ -1205,7 +1206,7 @@ void SCH_PAINTER::draw( const LIB_TEXTBOX* aTextBox, int aLayer, bool aDimmed )
attrs.m_Angle = aTextBox->GetDrawRotation();
attrs.m_StrokeWidth = KiROUND( getTextThickness( aTextBox ) );
strokeText( shownText, aTextBox->GetDrawPos(), attrs );
strokeText( shownText, aTextBox->GetDrawPos(), attrs, aTextBox->GetFontMetrics() );
};
m_gal->SetStrokeColor( color );
@ -1417,7 +1418,7 @@ void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed )
attrs.m_StrokeWidth = GetPenSizeForDemiBold( textSize );
attrs.m_Color = m_schSettings.GetLayerColor( LAYER_OP_CURRENTS );
knockoutText( aPin->GetOperatingPoint(), mid, attrs );
knockoutText( aPin->GetOperatingPoint(), mid, attrs, aPin->GetFontMetrics() );
}
}
@ -1694,11 +1695,11 @@ void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed )
if( drawingShadows && !attrs.m_Font->IsOutline() )
{
strokeText( text[i], aPos, attrs );
strokeText( text[i], aPos, attrs, aPin->GetFontMetrics() );
}
else if( drawingShadows )
{
boxText( text[i], aPos, attrs );
boxText( text[i], aPos, attrs, aPin->GetFontMetrics() );
}
else if( nonCached( aPin ) && renderTextAsBitmap )
{
@ -1707,7 +1708,7 @@ void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed )
}
else
{
strokeText( text[i], aPos, attrs );
strokeText( text[i], aPos, attrs, aPin->GetFontMetrics() );
const_cast<LIB_PIN*>( aPin )->SetFlags( IS_SHOWN_AS_BITMAP );
}
};
@ -1931,7 +1932,7 @@ void SCH_PAINTER::draw( const SCH_LINE* aLine, int aLayer )
attrs.m_StrokeWidth = GetPenSizeForDemiBold( textSize );
attrs.m_Color = m_schSettings.GetLayerColor( LAYER_OP_VOLTAGES );
knockoutText( aLine->GetOperatingPoint(), pos, attrs );
knockoutText( aLine->GetOperatingPoint(), pos, attrs, aLine->GetFontMetrics() );
}
if( drawingOP )
@ -2168,7 +2169,7 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer )
else if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_90 )
text_offset.y += fudge;
strokeText( shownText, aText->GetDrawPos() + text_offset, attrs );
strokeText( shownText, aText->GetDrawPos() + text_offset, attrs, aText->GetFontMetrics() );
}
else if( drawingShadows )
@ -2224,7 +2225,8 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer )
}
else
{
strokeText( shownText, aText->GetDrawPos() + text_offset, attrs );
strokeText( shownText, aText->GetDrawPos() + text_offset, attrs,
aText->GetFontMetrics() );
}
const_cast<SCH_TEXT*>( aText )->ClearFlags( IS_SHOWN_AS_BITMAP );
@ -2268,7 +2270,7 @@ void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer )
}
else
{
strokeText( shownText, aTextBox->GetDrawPos(), attrs );
strokeText( shownText, aTextBox->GetDrawPos(), attrs, aTextBox->GetFontMetrics() );
}
};
@ -2653,7 +2655,7 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
}
else
{
strokeText( shownText, textpos, attributes );
strokeText( shownText, textpos, attributes, aField->GetFontMetrics() );
}
const_cast<SCH_FIELD*>( aField )->ClearFlags( IS_SHOWN_AS_BITMAP );

View File

@ -195,13 +195,13 @@ private:
void triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c );
void strokeText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttributes );
const TEXT_ATTRIBUTES& aAttributes, const KIFONT::METRICS& aFontMetrics );
void bitmapText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttributes );
void knockoutText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttrs );
const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics );
void boxText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttrs );
const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics );
wxString expandLibItemTextVars( const wxString& aSourceText, const SCH_SYMBOL* aSymbolContext );

View File

@ -488,7 +488,7 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground ) const
{
VECTOR2I textpos = positions[ii] + text_offset;
wxString& txt = strings_list.Item( ii );
aPlotter->PlotText( textpos, color, txt, attrs, font );
aPlotter->PlotText( textpos, color, txt, attrs, font, GetFontMetrics() );
}
if( HasHyperlink() )

View File

@ -233,6 +233,8 @@ public:
protected:
KIFONT::FONT* getDrawFont() const override;
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
protected:
/**
* The orientation of text and any associated drawing elements of derived objects.

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -431,7 +431,8 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground ) const
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
{
aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font );
aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font,
GetFontMetrics() );
}
if( HasHyperlink() )

View File

@ -123,6 +123,8 @@ public:
protected:
KIFONT::FONT* getDrawFont() const override;
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
protected:
bool m_excludeFromSim;
};

View File

@ -132,6 +132,9 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin
m_params.emplace_back( new PARAM<double>( "drawing.label_size_ratio",
&m_LabelSizeRatio, DEFAULT_LABEL_SIZE_RATIO, 0.0, 2.0 ) );
m_params.emplace_back( new PARAM<double>( "drawing.overbar_offset_ratio",
&m_FontMetrics.m_OverbarHeight, m_FontMetrics.m_OverbarHeight ) );
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size",
&m_PinSymbolSize, schIUScale.MilsToIU( defaultPinSymbolSize ), schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 1000 ),
1 / schIUScale.IU_PER_MILS ) );
@ -188,15 +191,15 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin
m_TemplateFieldNames.AddTemplateFieldNames( cfg->m_Drawing.field_names );
}, {} ) );
m_params.emplace_back(
new PARAM<BOM_PRESET>( "bom_settings", &m_BomSettings, BOM_PRESET::GroupedByValue() ) );
m_params.emplace_back(
new PARAM_LIST<BOM_PRESET>( "bom_presets", &m_BomPresets, {} ) );
m_params.emplace_back( new PARAM<BOM_PRESET>( "bom_settings",
&m_BomSettings, BOM_PRESET::GroupedByValue() ) );
m_params.emplace_back( new PARAM_LIST<BOM_PRESET>( "bom_presets",
&m_BomPresets, {} ) );
m_params.emplace_back(
new PARAM<BOM_FMT_PRESET>( "bom_fmt_settings", &m_BomFmtSettings, BOM_FMT_PRESET::CSV() ) );
m_params.emplace_back(
new PARAM_LIST<BOM_FMT_PRESET>( "bom_fmt_presets", &m_BomFmtPresets, {} ) );
m_params.emplace_back( new PARAM<BOM_FMT_PRESET>( "bom_fmt_settings",
&m_BomFmtSettings, BOM_FMT_PRESET::CSV() ) );
m_params.emplace_back( new PARAM_LIST<BOM_FMT_PRESET>( "bom_fmt_presets",
&m_BomFmtPresets, {} ) );
m_params.emplace_back( new PARAM<wxString>( "page_layout_descr_file",
&m_SchDrawingSheetFileName, "" ) );

View File

@ -24,6 +24,7 @@
#include <settings/nested_settings.h>
#include <settings/bom_settings.h>
#include <template_fieldnames.h>
#include <font/font.h>
class NGSPICE_SETTINGS;
@ -86,13 +87,15 @@ public:
TEMPLATES m_TemplateFieldNames;
/// List of stored BOM presets
BOM_PRESET m_BomSettings;
std::vector<BOM_PRESET> m_BomPresets;
BOM_PRESET m_BomSettings;
std::vector<BOM_PRESET> m_BomPresets;
/// List of stored BOM format presets
BOM_FMT_PRESET m_BomFmtSettings;
std::vector<BOM_FMT_PRESET> m_BomFmtPresets;
KIFONT::METRICS m_FontMetrics;
/**
* Ngspice simulator settings.
*/

View File

@ -42,6 +42,11 @@ class SHAPE;
class PCB_GROUP;
class FOOTPRINT;
namespace KIFONT
{
class METRICS;
}
/**
* Conditionally flashed vias and pads that interact with zones of different priority can be
@ -191,6 +196,8 @@ public:
virtual STROKE_PARAMS GetStroke() const;
virtual void SetStroke( const STROKE_PARAMS& aStroke );
const KIFONT::METRICS& GetFontMetrics() const;
/**
* Return the primary layer this item is on.
*/

View File

@ -75,6 +75,8 @@ public:
return 1;
}
const KIFONT::METRICS& GetFontMetrics() const;
// The function to print a WS_DRAW_ITEM
virtual void PrintWsItem( const RENDER_SETTINGS* aSettings )
{
@ -346,6 +348,9 @@ public:
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif
protected:
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
};

View File

@ -49,6 +49,11 @@ namespace KIGFX
class COLOR4D;
}
namespace KIFONT
{
class METRICS;
}
using KIGFX::RENDER_SETTINGS;
using KIGFX::COLOR4D;
@ -59,12 +64,10 @@ using KIGFX::COLOR4D;
/**
* This is the "default-of-the-default" hardcoded text size; individual
* application define their own default policy starting with this
* (usually with a user option or project).
* This is the "default-of-the-default" hardcoded text size; individual application define their
* own default policy starting with this (usually with a user option or project).
*/
#define DEFAULT_SIZE_TEXT 50 // default text height (in mils, i.e. 1/1000")
#define DIM_ANCRE_TEXTE 2 // Anchor size for text
/**
@ -233,8 +236,8 @@ public:
* @param aColor text color.
* @param aDisplay_mode #FILLED or #SKETCH.
*/
void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
const COLOR4D& aColor, OUTLINE_MODE aDisplay_mode = FILLED );
void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, const COLOR4D& aColor,
OUTLINE_MODE aDisplay_mode = FILLED );
/**
* build a list of segments (SHAPE_SEGMENT) to describe a text shape.
@ -363,6 +366,8 @@ public:
protected:
virtual KIFONT::FONT* getDrawFont() const;
virtual const KIFONT::METRICS& getFontMetrics() const;
void cacheShownText();
/**

View File

@ -2,7 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2021 Ola Rinta-Koski
* Copyright (C) 2021-2022 Kicad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021-2023 Kicad Developers, see AUTHORS.txt for contributors.
*
* Font abstract base class
*
@ -42,12 +42,12 @@ class GAL;
enum TEXT_STYLE
{
BOLD = 1,
ITALIC = 1 << 1,
SUBSCRIPT = 1 << 2,
BOLD = 1,
ITALIC = 1 << 1,
SUBSCRIPT = 1 << 2,
SUPERSCRIPT = 1 << 3,
OVERBAR = 1 << 4,
UNDERLINE = 1 << 5
OVERBAR = 1 << 4,
UNDERLINE = 1 << 5
};
@ -87,17 +87,42 @@ inline bool IsSubscript( TEXT_STYLE_FLAGS aFlags )
}
inline bool IsOverbar( TEXT_STYLE_FLAGS aFlags )
{
return aFlags & TEXT_STYLE::OVERBAR;
}
std::string TextStyleAsString( TEXT_STYLE_FLAGS aFlags );
namespace KIFONT
{
class METRICS
{
public:
/**
* Compute the vertical position of an overbar. This is the distance between the text
* baseline and the overbar.
*/
double GetOverbarVerticalPosition( double aGlyphHeight ) const
{
return aGlyphHeight * m_OverbarHeight;
}
/**
* Compute the vertical position of an underline. This is the distance between the text
* baseline and the underline.
*/
double GetUnderlineVerticalPosition( double aGlyphHeight ) const
{
return aGlyphHeight * m_UnderlineOffset;
}
double GetInterline( double aFontHeight ) const
{
return aFontHeight * m_InterlinePitch;
}
static const METRICS& Default();
public:
double m_InterlinePitch = 1.68;
double m_OverbarHeight = 1.23;
double m_UnderlineOffset = -0.16;
};
/**
* FONT is an abstract base class for both outline and stroke fonts
*/
@ -132,12 +157,13 @@ public:
* @param aAttrs are the styling attributes of the text, including its rotation
*/
void Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosition,
const VECTOR2I& aCursor, const TEXT_ATTRIBUTES& aAttrs ) const;
const VECTOR2I& aCursor, const TEXT_ATTRIBUTES& aAttributes,
const METRICS& aFontMetrics ) const;
void Draw( KIGFX::GAL* aGal, const wxString& aText, const VECTOR2I& aPosition,
const TEXT_ATTRIBUTES& aAttributes ) const
const TEXT_ATTRIBUTES& aAttributes, const METRICS& aFontMetrics ) const
{
Draw( aGal, aText, aPosition, VECTOR2I( 0, 0 ), aAttributes );
Draw( aGal, aText, aPosition, VECTOR2I( 0, 0 ), aAttributes, aFontMetrics );
}
/**
@ -146,7 +172,7 @@ public:
* @return a VECTOR2I giving the width and height of text.
*/
VECTOR2I StringBoundaryLimits( const wxString& aText, const VECTOR2I& aSize, int aThickness,
bool aBold, bool aItalic ) const;
bool aBold, bool aItalic, const METRICS& aFontMetrics ) const;
/**
* Insert \n characters into text to ensure that no lines are wider than \a aColumnWidth.
@ -154,23 +180,11 @@ public:
void LinebreakText( wxString& aText, int aColumnWidth, const VECTOR2I& aGlyphSize,
int aThickness, bool aBold, bool aItalic ) const;
/**
* Compute the vertical position of an overbar. This is the distance between the text
* baseline and the overbar.
*/
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.
*/
virtual double GetInterline( double aGlyphHeight, double aLineSpacing = 1.0 ) const = 0;
virtual double GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const = 0;
/**
* Convert text string to an array of GLYPHs.
@ -225,7 +239,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, bool aUnderline ) const;
bool aItalic, bool aUnderline, const METRICS& aFontMetrics ) const;
/**
* Computes the bounding box for a single line of text.
@ -238,23 +252,22 @@ protected:
* @return new cursor position
*/
VECTOR2I boundingBoxSingleLine( BOX2I* aBBox, const wxString& aText, const VECTOR2I& aPosition,
const VECTOR2I& aSize, bool aItalic ) const;
const VECTOR2I& aSize, bool aItalic, const METRICS& aFontMetrics ) const;
void getLinePositions( const wxString& aText, const VECTOR2I& aPosition,
wxArrayString& aTextLines, std::vector<VECTOR2I>& aPositions,
std::vector<VECTOR2I>& aExtents, const TEXT_ATTRIBUTES& aAttrs ) const;
std::vector<VECTOR2I>& aExtents, const TEXT_ATTRIBUTES& aAttrs,
const METRICS& aFontMetrics ) const;
VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
const wxString& aText, const VECTOR2I& aPosition,
const VECTOR2I& aSize, const EDA_ANGLE& aAngle, bool aMirror,
const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const;
const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle,
const METRICS& aFontMetrics ) const;
void wordbreakMarkup( std::vector<std::pair<wxString, int>>* aWords, const wxString& aText,
const VECTOR2I& aSize, TEXT_STYLE_FLAGS aTextStyle ) const;
///< Factor that determines the pitch between 2 lines.
static constexpr double INTERLINE_PITCH_RATIO = 1.61; // The golden mean
private:
static FONT* getDefaultFont();

View File

@ -2,7 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2021 Ola Rinta-Koski
* Copyright (C) 2021-2022 Kicad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021-2023 Kicad Developers, see AUTHORS.txt for contributors.
*
* Outline font class
*
@ -89,23 +89,11 @@ public:
*/
static OUTLINE_FONT* LoadFont( const wxString& aFontFileName, bool aBold, bool aItalic );
/**
* Compute the vertical position of an overbar. This is the distance between the text
* baseline and the overbar.
*/
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.
*/
double GetInterline( double aGlyphHeight = 0.0, double aLineSpacing = 1.0 ) const override;
double GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const override;
VECTOR2I GetTextAsGlyphs( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
const wxString& aText, const VECTOR2I& aSize,
@ -113,7 +101,8 @@ public:
const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const override;
void GetLinesAsGlyphs( std::vector<std::unique_ptr<GLYPH>>* aGlyphs, const wxString& aText,
const VECTOR2I& aPosition, const TEXT_ATTRIBUTES& aAttrs ) const;
const VECTOR2I& aPosition, const TEXT_ATTRIBUTES& aAttrs,
const METRICS& aFontMetrics ) const;
const FT_Face& GetFace() const { return m_face; }

View File

@ -64,23 +64,11 @@ public:
*/
static STROKE_FONT* LoadFont( const wxString& aFontName );
/**
* Compute the vertical position of an overbar. This is the distance between the text
* baseline and the overbar.
*/
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.
*/
double GetInterline( double aGlyphHeight, double aLineSpacing = 1.0 ) const override;
double GetInterline( double aGlyphHeight, const METRICS& aFontMetrics ) const override;
VECTOR2I GetTextAsGlyphs( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* aGlyphs,
const wxString& aText, const VECTOR2I& aSize,

View File

@ -23,7 +23,7 @@
#include <math/vector2d.h>
#include <gal/color4d.h>
#include "../../libs/kimath/include/geometry/eda_angle.h"
#include <geometry/eda_angle.h>
namespace KIFONT
@ -82,9 +82,7 @@ public:
bool m_Multiline;
VECTOR2I m_Size;
/**
* If true, keep rotation angle between -90...90 degrees for readability
*/
// If true, keep rotation angle between -90...90 degrees for readability
bool m_KeepUpright;
};

View File

@ -33,19 +33,10 @@ namespace KIGFX
class COLOR4D;
}
/**
* Minimum dimension in pixel for drawing/no drawing a text used in Pcbnew to decide to
* draw (or not) some texts ( like net names on pads/tracks ).
*
* When a text height is smaller than MIN_TEXT_SIZE, it is not drawn by Pcbnew.
*/
#define MIN_TEXT_SIZE 5
/* Absolute minimum dimension in pixel to draw a text as text or a line
* When a text height is smaller than MIN_DRAWABLE_TEXT_SIZE,
* it is drawn, but like a line by the draw text function
*/
#define MIN_DRAWABLE_TEXT_SIZE 3
namespace KIFONT
{
class METRICS;
}
class PLOTTER;
@ -105,12 +96,10 @@ inline int GetKnockoutTextMargin( const VECTOR2I& aSize, int aThickness )
/**
* The full X size is GraphicTextWidth + the thickness of graphic lines.
*
* @return the X size of the graphic text.
*/
int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize,
int aThickness, bool aBold, bool aItalic );
int GRTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I& aSize,
int aThickness, bool aBold, bool aItalic, const KIFONT::METRICS& aFontMetrics );
/**
* Print a graphic text through wxDC.
@ -133,7 +122,8 @@ int GraphicTextWidth( const wxString& aText, KIFONT::FONT* aFont, const VECTOR2I
void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const KIGFX::COLOR4D& aColor,
const wxString& aText, const EDA_ANGLE& aOrient, const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont );
int aWidth, bool aItalic, bool aBold, KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics );
#endif /* GR_TEXT_H */

View File

@ -22,12 +22,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
*
* @file plotter.h
*/
#ifndef PLOT_COMMON_H_
#define PLOT_COMMON_H_
@ -426,26 +420,28 @@ public:
* @param aData is a parameter used by some plotters in SetCurrentLineWidth(),
* not directly used here.
*/
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aPenWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
void* aData = nullptr );
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aPenWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr );
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData = nullptr );
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr );
/**
* Create a clickable hyperlink with a rectangular click area
*

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -17,12 +17,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Plotting engine (DXF)
*
* @file plotter_dxf.h
*/
#pragma once
#include "plotter.h"
@ -162,16 +156,19 @@ public:
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed = false,
KIFONT::FONT* aFont = nullptr,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
/**
* Set the units to use for plotting the DXF file.
*
@ -215,9 +212,8 @@ protected:
const EDA_ANGLE& aEndAngle, double aRadius, FILL_T aFill,
int aWidth = USE_DEFAULT_LINE_WIDTH ) override;
void plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes );
void plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor, const wxString& aText,
const TEXT_ATTRIBUTES& aAttrs );
bool m_textAsLines;
COLOR4D m_currentColor;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -18,12 +18,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Plotting engine (Gerber)
*
* @file plotter_gerber.h
*/
#pragma once
#include "plotter.h"
@ -110,27 +104,29 @@ public:
virtual void PenTo( const VECTOR2I& pos, char plume ) override;
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed = false,
KIFONT::FONT* aFont = nullptr,
void* aData = nullptr ) override;
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
/**
* Filled circular flashes are stored as apertures

View File

@ -83,9 +83,8 @@ public:
void* aData ) override;
/**
* The SetColor implementation is split with the subclasses:
* The PSLIKE computes the rgb values, the subclass emits the
* operator to actually do it
* The SetColor implementation is split with the subclasses: the PSLIKE computes the rgb
* values, the subclass emits the operator to actually do it
*/
virtual void SetColor( const COLOR4D& color ) override;
@ -93,9 +92,8 @@ protected:
/**
* This is the core for postscript/PDF text alignment.
*
* It computes the transformation matrix to generate a user space
* system aligned with the text. Even the PS uses the concat
* operator to simplify PDF generation (concat is everything PDF
* It computes the transformation matrix to generate a user space system aligned with the text.
* Even the PS uses the concat operator to simplify PDF generation (concat is everything PDF
* has to modify the CTM. Lots of parameters, both in and out.
*/
void computeTextParameters( const VECTOR2I& aPos,
@ -117,15 +115,6 @@ protected:
double *ctm_f,
double *heightFactor );
/**
* Computes the x coordinates for the overlining in a string of text.
* Fills the passed vector with couples of (start, stop) values to be
* used in the text coordinate system (use computeTextParameters to
* obtain the parameters to establish such a system)
*/
void postscriptOverlinePositions( const wxString& aText, int aXSize, bool aItalic, bool aBold,
std::vector<int> *pos_pairs );
/// convert a wxString unicode string to a char string compatible with the accepted
/// string plotter format (convert special chars and non ascii7 chars)
virtual std::string encodeStringForPlotter( const wxString& aUnicode );
@ -137,10 +126,9 @@ protected:
static const double postscriptTextAscent; // = 0.718;
/**
* Sister function for the GraphicTextWidth in drawtxt.cpp
* Does the same processing (i.e. calculates a text string width) but
* using postscript metrics for the Helvetica font (optionally used for
* PS and PDF plotting
* Sister function for the GRTextWidth in gr_text.cpp
* Does the same processing (i.e. calculates a text string width) but using postscript metrics
* for the Helvetica font (optionally used for PS and PDF plotting
*/
int returnPostscriptTextWidth( const wxString& aText, int aXSize, bool aItalic, bool aBold );
@ -217,26 +205,28 @@ public:
double aScaleFactor ) override;
virtual void PenTo( const VECTOR2I& pos, char plume ) override;
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed = false,
KIFONT::FONT* aFont = nullptr,
void* aData = nullptr ) override;
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
protected:
@ -347,26 +337,28 @@ public:
virtual void PenTo( const VECTOR2I& pos, char plume ) override;
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed = false,
KIFONT::FONT* aFont = nullptr,
void* aData = nullptr ) override;
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
void HyperlinkBox( const BOX2I& aBox, const wxString& aDestinationURL ) override;
@ -605,27 +597,29 @@ public:
*/
virtual void EndBlock( void* aData ) override;
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed = false,
KIFONT::FONT* aFont = nullptr,
void* aData = nullptr ) override;
virtual void Text( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const EDA_ANGLE& aOrient,
const VECTOR2I& aSize,
enum GR_TEXT_H_ALIGN_T aH_justify,
enum GR_TEXT_V_ALIGN_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
void* aData = nullptr ) override;
virtual void PlotText( const VECTOR2I& aPos,
const COLOR4D& aColor,
const wxString& aText,
const TEXT_ATTRIBUTES& aAttributes,
KIFONT::FONT* aFont,
const KIFONT::METRICS& aFontMetrics,
void* aData = nullptr ) override;
protected:
virtual void Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
@ -665,9 +659,6 @@ protected:
// color, pen size, fill mode ...
// the new SVG stype must be output on file
PLOT_DASH_TYPE m_dashed; // plot line style
bool m_useInch; // is 0 if the step size is 10**-n*mm
// is 1 if the step size is 10**-n*inch
// Where n is given from m_precision
unsigned m_precision; // How fine the step size is
// Use 3-6 (3 means um precision, 6 nm precision) in PcbNew
// 3-4 in other modules (avoid values >4 to avoid overflow)

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -92,6 +92,12 @@ void BOARD_ITEM::SetStroke( const STROKE_PARAMS& aStroke )
}
const KIFONT::METRICS& BOARD_ITEM::GetFontMetrics() const
{
return KIFONT::METRICS::Default();
}
wxString BOARD_ITEM::GetLayerName() const
{
const BOARD* board = GetBoard();

View File

@ -26,6 +26,7 @@
#include <plotters/plotter_gerber.h>
#include <plotters/plotters_pslike.h>
#include <eda_item.h>
#include <font/font.h>
#include <confirm.h>
#include <string_utils.h>
#include <locale_io.h>
@ -275,7 +276,8 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_
attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER;
attrs.m_Multiline = false;
plotter->PlotText( VECTOR2I( plotX, plotY ), COLOR4D::UNSPECIFIED, Text, attrs, nullptr /* stroke font */ );
plotter->PlotText( VECTOR2I( plotX, plotY ), COLOR4D::UNSPECIFIED, Text, attrs,
nullptr /* stroke font */, KIFONT::METRICS::Default() );
// For some formats (PS, PDF SVG) we plot the drill size list on more than one column
// because the list must be contained inside the printed page
@ -334,7 +336,8 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_
if( tool.m_Hole_NotPlated )
msg += wxT( " (not plated)" );
plotter->PlotText( VECTOR2I( plotX, y ), COLOR4D::UNSPECIFIED, msg, attrs, nullptr /* stroke font */ );
plotter->PlotText( VECTOR2I( plotX, y ), COLOR4D::UNSPECIFIED, msg, attrs,
nullptr /* stroke font */, KIFONT::METRICS::Default() );
intervalle = KiROUND( ( ( charSize * charScale ) + TextWidth ) * 1.2 );

View File

@ -1893,7 +1893,7 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
void PCB_PAINTER::strokeText( const wxString& aText, const VECTOR2I& aPosition,
const TEXT_ATTRIBUTES& aAttrs )
const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
{
KIFONT::FONT* font = aAttrs.m_Font;
@ -1919,7 +1919,7 @@ void PCB_PAINTER::strokeText( const wxString& aText, const VECTOR2I& aPosition,
pos += fudge;
}
font->Draw( m_gal, aText, pos, aAttrs );
font->Draw( m_gal, aText, pos, aAttrs, aFontMetrics );
}
@ -2045,7 +2045,7 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer )
}
else
{
strokeText( resolvedText, aText->GetTextPos(), attrs );
strokeText( resolvedText, aText->GetTextPos(), attrs, aText->GetFontMetrics() );
}
}
@ -2158,7 +2158,7 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer )
}
else
{
strokeText( resolvedText, aTextBox->GetDrawPos(), attrs );
strokeText( resolvedText, aTextBox->GetDrawPos(), attrs, aTextBox->GetFontMetrics() );
}
}
@ -2292,7 +2292,8 @@ void PCB_PAINTER::draw( const PCB_GROUP* aGroup, int aLayer )
attrs.m_Size = VECTOR2I( textSize, textSize );
attrs.m_StrokeWidth = GetPenSizeForNormal( textSize );
KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs );
KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs,
aGroup->GetFontMetrics() );
}
}
}
@ -2466,7 +2467,7 @@ void PCB_PAINTER::draw( const PCB_DIMENSION_BASE* aDimension, int aLayer )
}
else
{
strokeText( resolvedText, aDimension->GetTextPos(), attrs );
strokeText( resolvedText, aDimension->GetTextPos(), attrs, aDimension->GetFontMetrics() );
}
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
@ -59,6 +59,12 @@ class NET_SETTINGS;
class NETINFO_LIST;
class TEXT_ATTRIBUTES;
namespace KIFONT
{
class FONT;
class METRICS;
}
namespace KIGFX
{
class GAL;
@ -209,7 +215,7 @@ protected:
virtual int getViaDrillSize( const PCB_VIA* aVia ) const;
void strokeText( const wxString& aText, const VECTOR2I& aPosition,
const TEXT_ATTRIBUTES& aAttrs );
const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics );
protected:
PCB_RENDER_SETTINGS m_pcbSettings;

View File

@ -484,7 +484,7 @@ void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance,
textShape.Append( point.x, point.y );
} );
font->Draw( &callback_gal, GetShownText( true ), GetTextPos(), attrs );
font->Draw( &callback_gal, GetShownText( true ), GetTextPos(), attrs, GetFontMetrics() );
textShape.Simplify( SHAPE_POLY_SET::PM_FAST );
if( IsKnockout() )

View File

@ -176,6 +176,8 @@ protected:
virtual void swapData( BOARD_ITEM* aImage ) override;
int getKnockoutMargin() const;
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
};
#endif // #define PCB_TEXT_H

View File

@ -476,7 +476,7 @@ void PCB_TEXTBOX::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearanc
buffer.Append( point.x, point.y );
} );
font->Draw( &callback_gal, GetShownText( true ), GetDrawPos(), GetAttributes() );
font->Draw( &callback_gal, GetShownText( true ), GetDrawPos(), GetAttributes(), GetFontMetrics() );
if( aClearance > 0 || aErrorLoc == ERROR_OUTSIDE )
{

View File

@ -136,6 +136,8 @@ public:
protected:
virtual void swapData( BOARD_ITEM* aImage ) override;
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
};
#endif // #define PCB_TEXTBOX_H

View File

@ -44,6 +44,12 @@ class ZONE;
class REPORTER;
class wxFileName;
namespace KIFONT
{
class FONT;
class METRICS;
}
// Define min and max reasonable values for plot/print scale
#define PLOT_MIN_SCALE 0.01
@ -82,7 +88,8 @@ public:
void PlotDimension( const PCB_DIMENSION_BASE* aDim );
void PlotPcbTarget( const PCB_TARGET* aMire );
void PlotZones( const ZONE* aZone, PCB_LAYER_ID aLayer, const SHAPE_POLY_SET& aPolysList );
void PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout );
void PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout,
const KIFONT::METRICS& aFontMetrics );
void PlotShape( const PCB_SHAPE* aShape );
/**

View File

@ -282,7 +282,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint )
if( GetPlotReference() && m_layerMask[textLayer]
&& ( textItem->IsVisible() || GetPlotInvisibleText() ) )
{
PlotText( textItem, textLayer, textItem->IsKnockout() );
PlotText( textItem, textLayer, textItem->IsKnockout(), textItem->GetFontMetrics() );
}
textItem = &aFootprint->Value();
@ -291,7 +291,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint )
if( GetPlotValue() && m_layerMask[textLayer]
&& ( textItem->IsVisible() || GetPlotInvisibleText() ) )
{
PlotText( textItem, textLayer, textItem->IsKnockout() );
PlotText( textItem, textLayer, textItem->IsKnockout(), textItem->GetFontMetrics() );
}
@ -333,7 +333,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint )
if( text->GetText() == wxT( "${VALUE}" ) && !GetPlotValue() )
continue;
PlotText( text, textLayer, text->IsKnockout() );
PlotText( text, textLayer, text->IsKnockout(), text->GetFontMetrics() );
}
}
@ -349,14 +349,14 @@ void BRDITEMS_PLOTTER::PlotBoardGraphicItem( const BOARD_ITEM* item )
case PCB_TEXT_T:
{
const PCB_TEXT* text = static_cast<const PCB_TEXT*>( item );
PlotText( text, text->GetLayer(), text->IsKnockout() );
PlotText( text, text->GetLayer(), text->IsKnockout(), text->GetFontMetrics() );
break;
}
case PCB_TEXTBOX_T:
{
const PCB_TEXTBOX* textbox = static_cast<const PCB_TEXTBOX*>( item );
PlotText( textbox, textbox->GetLayer(), textbox->IsKnockout() );
PlotText( textbox, textbox->GetLayer(), textbox->IsKnockout(), textbox->GetFontMetrics() );
PlotShape( textbox );
break;
}
@ -390,7 +390,7 @@ void BRDITEMS_PLOTTER::PlotDimension( const PCB_DIMENSION_BASE* aDim )
// the white items are not seen on a white paper or screen
m_plotter->SetColor( color != WHITE ? color : LIGHTGRAY);
PlotText( aDim, aDim->GetLayer(), false );
PlotText( aDim, aDim->GetLayer(), false, aDim->GetFontMetrics() );
PCB_SHAPE temp_item;
@ -513,7 +513,8 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint )
if( m_layerMask[ textbox->GetLayer() ] )
{
PlotText( textbox, textbox->GetLayer(), textbox->IsKnockout() );
PlotText( textbox, textbox->GetLayer(), textbox->IsKnockout(),
textbox->GetFontMetrics() );
PlotShape( textbox );
}
@ -546,7 +547,8 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint )
#include <font/stroke_font.h>
void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout )
void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout,
const KIFONT::METRICS& aFontMetrics )
{
KIFONT::FONT* font = aText->GetFont();
@ -609,12 +611,12 @@ void BRDITEMS_PLOTTER::PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, boo
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
{
wxString& txt = strings_list.Item( ii );
m_plotter->PlotText( positions[ii], color, txt, attrs, font, &gbr_metadata );
m_plotter->PlotText( positions[ii], color, txt, attrs, font, aFontMetrics, &gbr_metadata );
}
}
else
{
m_plotter->PlotText( pos, color, shownText, attrs, font, &gbr_metadata );
m_plotter->PlotText( pos, color, shownText, attrs, font, aFontMetrics, &gbr_metadata );
}
}