diff --git a/common/font/font.cpp b/common/font/font.cpp index 82206a24b4..60a94a6e79 100644 --- a/common/font/font.cpp +++ b/common/font/font.cpp @@ -119,7 +119,7 @@ void FONT::getLinePositions( const UTF8& aText, const VECTOR2I& aPosition, height += interline; } - wxPoint offset( 0, 0 ); + VECTOR2I offset( 0, 0 ); offset.y += aAttrs.m_Size.y; switch( aAttrs.m_Valign ) @@ -132,7 +132,7 @@ void FONT::getLinePositions( const UTF8& aText, const VECTOR2I& aPosition, for( int i = 0; i < lineCount; i++ ) { VECTOR2I lineSize = aExtents.at( i ); - wxPoint lineOffset( offset ); + VECTOR2I lineOffset( offset ); lineOffset.y += i * interline; @@ -188,7 +188,7 @@ void FONT::Draw( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2I& aPosition, */ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* aGlyphs, const std::unique_ptr& aNode, const VECTOR2I& aPosition, - const KIFONT::FONT* aFont, const VECTOR2D& aSize, const EDA_ANGLE& aAngle, + const KIFONT::FONT* aFont, const VECTOR2I& aSize, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) { VECTOR2I nextPosition = aPosition; @@ -229,7 +229,7 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* a VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector>* aGlyphs, - const UTF8& aText, const VECTOR2I& aPosition, const VECTOR2D& aSize, + const UTF8& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const { @@ -242,7 +242,7 @@ VECTOR2I FONT::drawMarkup( BOX2I* aBoundingBox, std::vector>* aGlyph VECTOR2I OUTLINE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector>* aGlyphs, - const UTF8& aText, const VECTOR2D& aSize, + const UTF8& aText, const VECTOR2I& aSize, const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const diff --git a/common/font/stroke_font.cpp b/common/font/stroke_font.cpp index ec7c1c6edb..7d9e82bb78 100644 --- a/common/font/stroke_font.cpp +++ b/common/font/stroke_font.cpp @@ -205,7 +205,7 @@ double STROKE_FONT::ComputeOverbarVerticalPosition( double aGlyphHeight ) const VECTOR2I STROKE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vector>* aGlyphs, - const UTF8& aText, const VECTOR2D& aSize, + const UTF8& aText, const VECTOR2I& aSize, const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index 308e880c2e..481f454a63 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -150,17 +150,11 @@ bool GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) } -void GAL::SetTextAttributes( const TEXT_ATTRIBUTES& aAttributes ) -{ - m_attributes = aAttributes; -} - - void GAL::ResetTextAttributes() { // Tiny but non-zero - this will always need setting // there is no built-in default - SetGlyphSize( { 1.0, 1.0 } ); + SetGlyphSize( { 1, 1 } ); SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER ); SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER ); @@ -260,51 +254,26 @@ COLOR4D GAL::getCursorColor() const } -void GAL::StrokeText( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle, - KIFONT::FONT* aFont, double aLineSpacing ) -{ - if( aText.IsEmpty() ) - return; - - if( !aFont ) - aFont = KIFONT::FONT::GetFont( wxEmptyString ); - - TEXT_ATTRIBUTES attributes; - attributes.m_Angle = EDA_ANGLE( aRotationAngle, EDA_ANGLE::RADIANS ); - attributes.m_Halign = GetHorizontalJustify(); - attributes.m_Valign = GetVerticalJustify(); - attributes.m_LineSpacing = aLineSpacing; - attributes.m_Size = GetGlyphSize(); - attributes.m_StrokeWidth = GetLineWidth(); - - aFont->Draw( this, aText, aPosition, attributes ); -} - - /* * Fallback for implementations that don't implement bitmap text: use stroke font */ -void GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle ) +void GAL::BitmapText( const wxString& aText, const VECTOR2I& aPosition, const EDA_ANGLE& aAngle ) { - // Handle flipped view - if( m_globalFlipX ) - m_attributes.m_Mirrored = !m_attributes.m_Mirrored; + KIFONT::FONT* font = KIFONT::FONT::GetFont(); + + if( aText.IsEmpty() ) + return; + + TEXT_ATTRIBUTES attrs = m_attributes; + attrs.m_Angle = aAngle; + attrs.m_Mirrored = m_globalFlipX; // Prevent text flipping when view is flipped // Bitmap font is slightly smaller and slightly heavier than the stroke font so we // compensate a bit before stroking - float saveLineWidth = m_lineWidth; - VECTOR2D saveGlyphSize = m_attributes.m_Size; - { - m_lineWidth *= 1.2f; - m_attributes.m_Size = m_attributes.m_Size * 0.8; + attrs.m_StrokeWidth *= 1.2f; + attrs.m_Size = attrs.m_Size * 0.8; - StrokeText( aText, aPosition, aRotationAngle ); - } - m_lineWidth = saveLineWidth; - m_attributes.m_Size = saveGlyphSize; - - if( m_globalFlipX ) - m_attributes.m_Mirrored = !m_attributes.m_Mirrored; + font->Draw( this, aText, aPosition, attrs ); } diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 2f66f817da..bc3ea180f5 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -1286,12 +1286,12 @@ void OPENGL_GAL::DrawBitmap( const BITMAP_BASE& aBitmap ) } -void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition, - double aRotationAngle ) +void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2I& aPosition, + const EDA_ANGLE& aAngle ) { // Fallback to generic impl (which uses the stroke font) on cases we don't handle if( IsTextMirrored() || aText.Contains( wxT( "^{" ) ) || aText.Contains( wxT( "_{" ) ) ) - return GAL::BitmapText( aText, aPosition, aRotationAngle ); + return GAL::BitmapText( aText, aPosition, aAngle ); const UTF8 text( aText ); VECTOR2D textSize; @@ -1306,7 +1306,7 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition, m_currentManager->Color( m_strokeColor.r, m_strokeColor.g, m_strokeColor.b, m_strokeColor.a ); m_currentManager->Translate( aPosition.x, aPosition.y, m_layerDepth ); - m_currentManager->Rotate( aRotationAngle, 0.0f, 0.0f, -1.0f ); + m_currentManager->Rotate( aAngle.AsRadians(), 0.0f, 0.0f, -1.0f ); double sx = SCALE * ( m_globalFlipX ? -1.0 : 1.0 ); double sy = SCALE * ( m_globalFlipY ? -1.0 : 1.0 ); @@ -1352,8 +1352,7 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition, for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt ) { - wxASSERT_MSG( *chIt != '\n' && *chIt != '\r', - wxT( "No support for multiline bitmap text yet" ) ); + wxASSERT_MSG( *chIt != '\n' && *chIt != '\r', "No support for multiline bitmap text yet" ); if( *chIt == '~' && overbarDepth == -1 ) { diff --git a/common/preview_items/preview_utils.cpp b/common/preview_items/preview_utils.cpp index 04164e2de0..13ed18a0ff 100644 --- a/common/preview_items/preview_utils.cpp +++ b/common/preview_items/preview_utils.cpp @@ -61,9 +61,10 @@ wxString KIGFX::PREVIEW::DimensionLabel( const wxString& prefix, double aVal, ED } -KIGFX::PREVIEW::TEXT_DIMS KIGFX::PREVIEW::SetConstantGlyphHeight( KIGFX::GAL* aGal, +KIGFX::PREVIEW::TEXT_DIMS KIGFX::PREVIEW::GetConstantGlyphHeight( KIGFX::GAL* aGal, int aRelativeSize ) { + constexpr double aspectRatio = 1.0; constexpr double hdpiSizes[] = { 8, 9, 11, 13, 15 }; constexpr double sizes[] = { 10, 12, 14, 16, 18 }; @@ -91,15 +92,12 @@ KIGFX::PREVIEW::TEXT_DIMS KIGFX::PREVIEW::SetConstantGlyphHeight( KIGFX::GAL* aG height /= aGal->GetWorldScale(); - VECTOR2D glyphSize = aGal->GetGlyphSize(); - glyphSize = glyphSize * ( height / glyphSize.y ); - aGal->SetGlyphSize( glyphSize ); - TEXT_DIMS textDims; - textDims.StrokeWidth = glyphSize.x * thicknessFactor; - textDims.ShadowWidth = glyphSize.x * shadowFactor; - textDims.LinePitch = glyphSize.y * linePitchFactor; + textDims.GlyphSize = VECTOR2I( height * aspectRatio, height ); + textDims.StrokeWidth = height * thicknessFactor; + textDims.ShadowWidth = height * shadowFactor; + textDims.LinePitch = height * linePitchFactor; return textDims; } @@ -120,10 +118,11 @@ void KIGFX::PREVIEW::DrawTextNextToCursor( KIGFX::VIEW* aView, const VECTOR2D& a bool aDrawingDropShadows ) { KIGFX::GAL* gal = aView->GetGAL(); - RENDER_SETTINGS* rs = aView->GetPainter()->GetSettings(); + KIFONT::FONT* font = KIFONT::FONT::GetFont(); // constant text size on screen - TEXT_DIMS textDims = SetConstantGlyphHeight( gal ); + TEXT_DIMS textDims = GetConstantGlyphHeight( gal ); + TEXT_ATTRIBUTES textAttrs; // radius string goes on the right of the cursor centre line with a small horizontal // offset (enough to keep clear of a system cursor if present) @@ -133,50 +132,42 @@ void KIGFX::PREVIEW::DrawTextNextToCursor( KIGFX::VIEW* aView, const VECTOR2D& a // if the text goes above the cursor, shift it up if( aTextQuadrant.y > 0 ) - { textPos.y -= textDims.LinePitch * ( aStrings.size() + 1 ); - } if( aTextQuadrant.x < 0 ) { if( viewFlipped ) - gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_RIGHT ); + textAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT; else - gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_LEFT ); + textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT; textPos.x += 15.0 / gal->GetWorldScale(); - - if( aDrawingDropShadows ) - textPos.x -= textDims.ShadowWidth; } else { if( viewFlipped ) - gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_LEFT ); + textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT; else - gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_RIGHT ); + textAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT; textPos.x -= 15.0 / gal->GetWorldScale(); - - if( aDrawingDropShadows ) - textPos.x += textDims.ShadowWidth; } - gal->SetIsFill( false ); - gal->SetStrokeColor( rs->GetLayerColor( LAYER_AUX_ITEMS ) ); - gal->SetLineWidth( textDims.StrokeWidth ); - gal->SetTextMirrored( viewFlipped ); // Prevent text flipping when view is flipped + gal->SetStrokeColor( aView->GetPainter()->GetSettings()->GetLayerColor( LAYER_AUX_ITEMS ) ); + textAttrs.m_Mirrored = viewFlipped; // Prevent text flipping when view is flipped + textAttrs.m_Size = textDims.GlyphSize; + textAttrs.m_StrokeWidth = textDims.StrokeWidth; if( aDrawingDropShadows ) { + textAttrs.m_StrokeWidth = textDims.StrokeWidth + ( 2 * textDims.ShadowWidth ); gal->SetStrokeColor( GetShadowColor( gal->GetStrokeColor() ) ); - gal->SetLineWidth( gal->GetLineWidth() + 2 * textDims.ShadowWidth ); } // write strings top-to-bottom for( const wxString& str : aStrings ) { textPos.y += textDims.LinePitch; - gal->StrokeText( str, textPos, 0.0 ); + font->Draw( gal, str, textPos, textAttrs ); } } diff --git a/common/preview_items/ruler_item.cpp b/common/preview_items/ruler_item.cpp index fd0a64a7e2..a5e4a5fe1c 100644 --- a/common/preview_items/ruler_item.cpp +++ b/common/preview_items/ruler_item.cpp @@ -150,43 +150,43 @@ static TICK_FORMAT getTickFormatForScale( double aScale, double& aTickSpace, EDA void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECTOR2D& aLine, double aMinorTickLen, EDA_UNITS aUnits, bool aDrawingDropShadows ) { - KIGFX::GAL* gal = aView->GetGAL(); - VECTOR2D tickLine = aLine.Rotate( -M_PI_2 ); - double tickSpace; - TICK_FORMAT tickF = getTickFormatForScale( gal->GetWorldScale(), tickSpace, aUnits ); + KIGFX::GAL* gal = aView->GetGAL(); + KIFONT::FONT* font = KIFONT::FONT::GetFont(); + VECTOR2D tickLine = aLine.Rotate( -M_PI_2 ); + double tickSpace; + TICK_FORMAT tickFormat = getTickFormatForScale( gal->GetWorldScale(), tickSpace, aUnits ); + double majorTickLen = aMinorTickLen * ( majorTickLengthFactor + 1 ); // number of ticks in whole ruler - int numTicks = (int) std::ceil( aLine.EuclideanNorm() / tickSpace ); + int numTicks = (int) std::ceil( aLine.EuclideanNorm() / tickSpace ); // work out which way up the tick labels go - TEXT_DIMS textDims = SetConstantGlyphHeight( gal, -1 ); - double textThickness = textDims.StrokeWidth; - double labelAngle = -tickLine.Angle(); - double textOffset = 0; + TEXT_DIMS labelDims = GetConstantGlyphHeight( gal, -1 ); + double labelAngle = -tickLine.Angle(); + VECTOR2I labelOffset = tickLine.Resize( majorTickLen ); if( aDrawingDropShadows ) { - textOffset = textDims.ShadowWidth; - textThickness += 2 * textDims.ShadowWidth; + labelOffset = { labelDims.ShadowWidth, labelDims.ShadowWidth }; + labelDims.StrokeWidth += 2 * labelDims.ShadowWidth; } - double majorTickLen = aMinorTickLen * ( majorTickLengthFactor + 1 ); - VECTOR2D labelOffset = tickLine.Resize( majorTickLen - textOffset ); - if( aView->IsMirroredX() ) - { - textOffset = -textOffset; labelOffset = -labelOffset; - } + + TEXT_ATTRIBUTES labelAttrs; + labelAttrs.m_Size = labelDims.GlyphSize; + labelAttrs.m_StrokeWidth = labelDims.StrokeWidth; if( aLine.Angle() > 0 ) { - gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_LEFT ); + labelAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT; + labelAttrs.m_Angle = EDA_ANGLE( labelAngle, EDA_ANGLE::RADIANS ); } else { - gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_RIGHT ); - labelAngle += M_PI; + labelAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT; + labelAttrs.m_Angle = EDA_ANGLE( labelAngle + M_PI, EDA_ANGLE::RADIANS ); } BOX2D viewportD = aView->GetViewport(); @@ -203,27 +203,26 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT continue; double length = aMinorTickLen; - bool drawLabel = false; + bool drawLabel = false; - if( i % tickF.majorStep == 0 ) + if( i % tickFormat.majorStep == 0 ) { drawLabel = true; length *= majorTickLengthFactor; } - else if( tickF.midStep && i % tickF.midStep == 0 ) + else if( tickFormat.midStep && i % tickFormat.midStep == 0 ) { drawLabel = true; length *= midTickLengthFactor; } - gal->SetLineWidth( textThickness / 2 ); + gal->SetLineWidth( labelAttrs.m_StrokeWidth / 2 ); gal->DrawLine( tickPos, tickPos + tickLine.Resize( length ) ); if( drawLabel ) { wxString label = DimensionLabel( "", tickSpace * i, aUnits, false ); - gal->SetLineWidth( textThickness ); - gal->StrokeText( label, tickPos + labelOffset, labelAngle ); + font->Draw( gal, label, tickPos + labelOffset, labelAttrs ); } } } @@ -245,7 +244,7 @@ void drawBacksideTicks( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECTO KIGFX::GAL* gal = aView->GetGAL(); const double backTickSpace = aLine.EuclideanNorm() / aNumDivisions; const VECTOR2D backTickVec = aLine.Rotate( M_PI_2 ).Resize( aTickLen ); - TEXT_DIMS textDims = SetConstantGlyphHeight( gal, -1 ); + TEXT_DIMS textDims = GetConstantGlyphHeight( gal, -1 ); BOX2D viewportD = aView->GetViewport(); BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) ); @@ -321,7 +320,7 @@ void RULER_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const gal->SetStrokeColor( GetShadowColor( gal->GetStrokeColor() ) ); gal->ResetTextAttributes(); - TEXT_DIMS textDims = SetConstantGlyphHeight( gal ); + TEXT_DIMS textDims = GetConstantGlyphHeight( gal ); // draw the main line from the origin to cursor gal->SetLineWidth( getTickLineWidth( textDims, drawingDropShadows ) ); diff --git a/common/view/view_overlay.cpp b/common/view/view_overlay.cpp index 2991773c22..f66696c0ee 100644 --- a/common/view/view_overlay.cpp +++ b/common/view/view_overlay.cpp @@ -229,7 +229,7 @@ struct VIEW_OVERLAY::COMMAND_SET_WIDTH : public VIEW_OVERLAY::COMMAND struct VIEW_OVERLAY::COMMAND_GLYPH_SIZE : public VIEW_OVERLAY::COMMAND { - COMMAND_GLYPH_SIZE( const VECTOR2D aSize ) : + COMMAND_GLYPH_SIZE( const VECTOR2I aSize ) : m_size( aSize ) { }; @@ -238,16 +238,17 @@ struct VIEW_OVERLAY::COMMAND_GLYPH_SIZE : public VIEW_OVERLAY::COMMAND aView->GetGAL()->SetGlyphSize( m_size ); } - VECTOR2D m_size; + VECTOR2I m_size; }; struct VIEW_OVERLAY::COMMAND_BITMAP_TEXT : public VIEW_OVERLAY::COMMAND { - COMMAND_BITMAP_TEXT( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle ) : + COMMAND_BITMAP_TEXT( const wxString& aText, const VECTOR2I& aPosition, + const EDA_ANGLE& aAngle ) : m_text( aText ), m_pos( aPosition ), - m_angle (aRotationAngle) + m_angle( aAngle ) { } virtual void Execute( VIEW* aView ) const override @@ -255,9 +256,9 @@ struct VIEW_OVERLAY::COMMAND_BITMAP_TEXT : public VIEW_OVERLAY::COMMAND aView->GetGAL()->BitmapText( m_text, m_pos, m_angle ); } - wxString m_text; - VECTOR2D m_pos; - double m_angle; + wxString m_text; + VECTOR2I m_pos; + EDA_ANGLE m_angle; }; VIEW_OVERLAY::VIEW_OVERLAY() @@ -381,16 +382,16 @@ void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled ) } -void VIEW_OVERLAY::SetGlyphSize( const VECTOR2D& aSize ) +void VIEW_OVERLAY::SetGlyphSize( const VECTOR2I& aSize ) { m_commands.push_back( new COMMAND_GLYPH_SIZE( aSize ) ); } -void VIEW_OVERLAY::BitmapText( const wxString& aText, const VECTOR2D& aPosition, - double aRotationAngle ) +void VIEW_OVERLAY::BitmapText( const wxString& aText, const VECTOR2I& aPosition, + const EDA_ANGLE& aAngle ) { - m_commands.push_back( new COMMAND_BITMAP_TEXT( aText, aPosition, aRotationAngle ) ); + m_commands.push_back( new COMMAND_BITMAP_TEXT( aText, aPosition, aAngle ) ); } diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index cd2fd00365..6dfb046226 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -1112,7 +1112,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer ) m_gal->SetFillColor( colour[i] ); TEXT_ATTRIBUTES attrs; - attrs.m_Size = VECTOR2D( size[i], size[i] ); + attrs.m_Size = VECTOR2I( size[i], size[i] ); attrs.m_Halign = hAlign; attrs.m_Valign = vAlign; attrs.m_Angle = aAngle; diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index 20917a6ba1..64a10d8017 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -84,7 +84,7 @@ int GERBER_DRAW_ITEM::GetLayer() const } -bool GERBER_DRAW_ITEM::GetTextD_CodePrms( int& aSize, VECTOR2I& aPos, double& aOrientation ) +bool GERBER_DRAW_ITEM::GetTextD_CodePrms( int& aSize, VECTOR2I& aPos, EDA_ANGLE& aOrientation ) { // calculate the best size and orientation of the D_Code text @@ -105,7 +105,7 @@ bool GERBER_DRAW_ITEM::GetTextD_CodePrms( int& aSize, VECTOR2I& aPos, double& aO else size = std::min( m_Size.x, m_Size.y ); - aOrientation = 0; + aOrientation = EDA_ANGLE::HORIZONTAL; if( m_Flashed ) { @@ -116,8 +116,9 @@ bool GERBER_DRAW_ITEM::GetTextD_CodePrms( int& aSize, VECTOR2I& aPos, double& aO { VECTOR2I delta = m_Start - m_End; - aOrientation = RAD2DECIDEG( atan2( (double)delta.y, (double)delta.x ) ); - NORMALIZE_ANGLE_90( aOrientation ); + double deci = RAD2DECIDEG( atan2( (double)delta.y, (double)delta.x ) ); + NORMALIZE_ANGLE_90( deci ); + aOrientation = EDA_ANGLE( deci, EDA_ANGLE::TENTHS_OF_A_DEGREE ); // A reasonable size for text is size/2 because text needs margin below and above it. // a margin = size/4 seems good, expecting the line len is large enough to show 3 chars, @@ -129,23 +130,6 @@ bool GERBER_DRAW_ITEM::GetTextD_CodePrms( int& aSize, VECTOR2I& aPos, double& aO } -bool GERBER_DRAW_ITEM::GetTextD_CodePrms( double& aSize, VECTOR2D& aPos, double& aOrientation ) -{ - // aOrientation is returned in radians - int size; - VECTOR2I pos; - - if( ! GetTextD_CodePrms( size, pos, aOrientation ) ) - return false; - - aPos = pos; - aSize = (double) size; - aOrientation = DECIDEG2RAD( aOrientation ); - - return true; -} - - VECTOR2I GERBER_DRAW_ITEM::GetABPosition( const VECTOR2I& aXYPosition ) const { /* Note: RS274Xrevd_e is obscure about the order of transforms: diff --git a/gerbview/gerber_draw_item.h b/gerbview/gerber_draw_item.h index e33b2c7fa2..2deb51b4aa 100644 --- a/gerbview/gerber_draw_item.h +++ b/gerbview/gerber_draw_item.h @@ -26,6 +26,7 @@ #define GERBER_DRAW_ITEM_H #include +#include #include #include #include @@ -87,13 +88,7 @@ public: * @param aOrientation is a reference to return the text orientation * @return true if the parameters can be calculated, false for unknown D_Code */ - bool GetTextD_CodePrms( int& aSize, VECTOR2I& aPos, double& aOrientation ); - - /** - * Return the best size and orientation to display the D_Code in GAL - * aOrientation is returned in radians. - */ - bool GetTextD_CodePrms( double& aSize, VECTOR2D& aPos, double& aOrientation ); + bool GetTextD_CodePrms( int& aSize, VECTOR2I& aPos, EDA_ANGLE& aOrientation ); /** * Optimize screen refresh (when no items are in background color refresh can be faster). diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp index 8cceb0e473..d4b13fb385 100644 --- a/gerbview/gerbview_painter.cpp +++ b/gerbview/gerbview_painter.cpp @@ -204,10 +204,10 @@ void GERBVIEW_PAINTER::draw( /*const*/ GERBER_DRAW_ITEM* aItem, int aLayer ) // Draw DCODE overlay text if( IsDCodeLayer( aLayer ) ) { - wxString codeText; - VECTOR2D textPosition; - double textSize; - double orient; + wxString codeText; + VECTOR2I textPosition; + int textSize; + EDA_ANGLE orient; if( !aItem->GetTextD_CodePrms( textSize, textPosition, orient ) ) return; diff --git a/include/font/font.h b/include/font/font.h index 548881fc31..dc731e175a 100644 --- a/include/font/font.h +++ b/include/font/font.h @@ -135,9 +135,9 @@ public: /** * Compute the boundary limits of aText (the bounding box of all shapes). * - * @return a VECTOR2D giving the width and height of text. + * @return a VECTOR2I giving the width and height of text. */ - VECTOR2I StringBoundaryLimits( const UTF8& aText, const VECTOR2D& aSize, int aThickness, + VECTOR2I StringBoundaryLimits( const UTF8& aText, const VECTOR2I& aSize, int aThickness, bool aBold, bool aItalic ) const; /** @@ -167,7 +167,7 @@ public: * @return text cursor position after this text */ virtual VECTOR2I GetTextAsGlyphs( BOX2I* aBBox, std::vector>* aGlyphs, - const UTF8& aText, const VECTOR2D& aSize, + const UTF8& aText, const VECTOR2I& aSize, const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const = 0; @@ -203,7 +203,7 @@ protected: * @return new cursor position in non-rotated, non-mirrored coordinates */ void drawSingleLineText( KIGFX::GAL* aGal, BOX2I* aBoundingBox, const UTF8& aText, - const VECTOR2I& aPosition, const VECTOR2D& aSize, + const VECTOR2I& aPosition, const VECTOR2I& aSize, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, bool aItalic ) const; @@ -218,14 +218,14 @@ protected: * @return new cursor position */ VECTOR2I boundingBoxSingleLine( BOX2I* aBBox, const UTF8& aText, const VECTOR2I& aPosition, - const VECTOR2D& aSize, bool aItalic ) const; + const VECTOR2I& aSize, bool aItalic ) const; void getLinePositions( const UTF8& aText, const VECTOR2I& aPosition, wxArrayString& aTextLines, std::vector& aPositions, std::vector& aExtents, const TEXT_ATTRIBUTES& aAttrs ) const; VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector>* aGlyphs, - const UTF8& aText, const VECTOR2I& aPosition, const VECTOR2D& aSize, + const UTF8& aText, const VECTOR2I& aPosition, const VECTOR2I& aSize, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const; diff --git a/include/font/outline_font.h b/include/font/outline_font.h index 2e97f538ed..bee6e5897f 100644 --- a/include/font/outline_font.h +++ b/include/font/outline_font.h @@ -98,7 +98,7 @@ public: double GetInterline( double aGlyphHeight = 0.0, double aLineSpacing = 1.0 ) const override; VECTOR2I GetTextAsGlyphs( BOX2I* aBoundingBox, std::vector>* aGlyphs, - const UTF8& aText, const VECTOR2D& aSize, const VECTOR2I& aPosition, + const UTF8& aText, const VECTOR2I& aSize, const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const override; diff --git a/include/font/stroke_font.h b/include/font/stroke_font.h index d7a8bfe991..2c551307e0 100644 --- a/include/font/stroke_font.h +++ b/include/font/stroke_font.h @@ -77,7 +77,7 @@ public: double GetInterline( double aGlyphHeight, double aLineSpacing = 1.0 ) const override; VECTOR2I GetTextAsGlyphs( BOX2I* aBoundingBox, std::vector>* aGlyphs, - const UTF8& aText, const VECTOR2D& aSize, const VECTOR2I& aPosition, + const UTF8& aText, const VECTOR2I& aSize, const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const override; diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 96b1c642f6..7945eb1990 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -343,44 +343,26 @@ public: // Text // ---- - /** - * Draw a vector type text using preloaded Newstroke font. - * - * @param aText is the text to be drawn. - * @param aPosition is the text position in world coordinates. - * @param aRotationAngle is the text rotation angle. - * @param aFont is the text font, or nullptr (defaults to newstroke) - * @param aLineSpacing is the line spacing for multiline text (defaults to 1.0) - */ - virtual void StrokeText( const wxString& aText, const VECTOR2D& aPosition, - double aRotationAngle, KIFONT::FONT* aFont = nullptr, - double aLineSpacing = 1.0 ); - /** * Draw a text using a bitmap font. It should be faster than StrokeText(), but can be used * only for non-Gerber elements. * * @param aText is the text to be drawn. * @param aPosition is the text position in world coordinates. - * @param aRotationAngle is the text rotation angle. + * @param aAngle is the text rotation angle. */ - virtual void BitmapText( const wxString& aText, const VECTOR2D& aPosition, - double aRotationAngle ); + virtual void BitmapText( const wxString& aText, const VECTOR2I& aPosition, + const EDA_ANGLE& aAngle ); /** - * Loads attributes of the text (bold/italic/underline/mirrored and so on). - */ - virtual void SetTextAttributes( const TEXT_ATTRIBUTES& aAttributes ); - - /** - * Reset text attributes to default styling. + * Reset text attributes to default styling. FONT TODO: do we need any of this in GAL anymore? * * Normally, custom attributes will be set individually after this, otherwise you can use * SetTextAttributes() */ void ResetTextAttributes(); - void SetGlyphSize( const VECTOR2D aSize ) { m_attributes.m_Size = aSize; } + void SetGlyphSize( const VECTOR2I aSize ) { m_attributes.m_Size = aSize; } const VECTOR2D& GetGlyphSize() const { return m_attributes.m_Size; } inline void SetFontBold( const bool aBold ) { m_attributes.m_Bold = aBold; } diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 4c96639fee..d4250f6578 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -162,8 +162,8 @@ public: void DrawBitmap( const BITMAP_BASE& aBitmap ) override; /// @copydoc GAL::BitmapText() - void BitmapText( const wxString& aText, const VECTOR2D& aPosition, - double aRotationAngle ) override; + void BitmapText( const wxString& aText, const VECTOR2I& aPosition, + const EDA_ANGLE& aAngle ) override; /// @copydoc GAL::DrawGrid() void DrawGrid() override; diff --git a/include/preview_items/preview_utils.h b/include/preview_items/preview_utils.h index 412fbd9e27..8eaf0da123 100644 --- a/include/preview_items/preview_utils.h +++ b/include/preview_items/preview_utils.h @@ -38,9 +38,10 @@ namespace PREVIEW struct TEXT_DIMS { - double StrokeWidth; - double ShadowWidth; - double LinePitch; + VECTOR2I GlyphSize; + int StrokeWidth; + int ShadowWidth; + double LinePitch; }; /** @@ -64,7 +65,7 @@ wxString DimensionLabel( const wxString& prefix, double aVal, EDA_UNITS aUnits, * will give larger and -1 etc. will give smaller. * @returns the text widths for the resulting glyph size. */ -TEXT_DIMS SetConstantGlyphHeight( KIGFX::GAL* aGal, int aRelativeSize = 0 ); +TEXT_DIMS GetConstantGlyphHeight( KIGFX::GAL* aGal, int aRelativeSize = 0 ); COLOR4D GetShadowColor( const COLOR4D& aColor ); diff --git a/include/view/view_overlay.h b/include/view/view_overlay.h index ec2b143234..086bdcc54e 100644 --- a/include/view/view_overlay.h +++ b/include/view/view_overlay.h @@ -90,14 +90,14 @@ public: void Polyline( const SHAPE_LINE_CHAIN& aPolyLine ); void Polygon( const VECTOR2D aPointList[], int aListSize ); - void BitmapText( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle ); + void BitmapText( const wxString& aText, const VECTOR2I& aPosition, const EDA_ANGLE& aAngle ); // Draw settings void SetIsFill( bool aIsFillEnabled ); void SetIsStroke( bool aIsStrokeEnabled ); void SetFillColor( const COLOR4D& aColor ); void SetStrokeColor( const COLOR4D& aColor ); - void SetGlyphSize( const VECTOR2D& aSize ); + void SetGlyphSize( const VECTOR2I& aSize ); void SetLineWidth( double aLineWidth ); const COLOR4D& GetStrokeColor() const { return m_strokeColor; } diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 71a1308803..2e032df55e 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include "pcbnew_settings.h" @@ -578,25 +579,25 @@ void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer ) if( length < 6 * width ) return; - const wxString& netName = UnescapeString( aTrack->GetShortNetname() ); - double textSize = width; - double penWidth = width / 12.0; - VECTOR2D textPosition = start + line / 2.0; // center of the track - double textOrientation; + const wxString& netName = UnescapeString( aTrack->GetShortNetname() ); + double textSize = width; + double penWidth = width / 12.0; + VECTOR2D textPosition = start + line / 2.0; // center of the track + EDA_ANGLE textOrientation; if( end.y == start.y ) // horizontal { - textOrientation = 0; + textOrientation = EDA_ANGLE::HORIZONTAL; textPosition.y += penWidth; } else if( end.x == start.x ) // vertical { - textOrientation = M_PI / 2; + textOrientation = EDA_ANGLE::VERTICAL; textPosition.x += penWidth; } else { - textOrientation = -atan( line.y / line.x ); + textOrientation = EDA_ANGLE( -atan( line.y / line.x ), EDA_ANGLE::RADIANS ); textPosition.x += penWidth / 1.4; textPosition.y += penWidth / 1.4; } @@ -772,7 +773,7 @@ void PCB_PAINTER::draw( const PCB_VIA* aVia, int aLayer ) m_gal->SetGlyphSize( namesize ); m_gal->SetLineWidth( namesize.x / 12.0 ); - m_gal->BitmapText( netname, textpos, 0.0 ); + m_gal->BitmapText( netname, textpos, EDA_ANGLE::HORIZONTAL ); m_gal->Restore(); @@ -929,7 +930,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) // We have already translated the GAL to be centered at the center of the pad's // bounding box - VECTOR2D textpos( 0.0, 0.0 ); + VECTOR2I textpos( 0, 0 ); // Divide the space, to display both pad numbers and netnames and set the Y text // position to display 2 lines @@ -966,7 +967,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) m_gal->SetGlyphSize( namesize ); m_gal->SetLineWidth( namesize.x / 12.0 ); - m_gal->BitmapText( netname, textpos, 0.0 ); + m_gal->BitmapText( netname, textpos, EDA_ANGLE::HORIZONTAL ); } if( displayPadNumber ) @@ -985,7 +986,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) m_gal->SetGlyphSize( numsize ); m_gal->SetLineWidth( numsize.x / 12.0 ); - m_gal->BitmapText( padNumber, textpos, 0.0 ); + m_gal->BitmapText( padNumber, textpos, EDA_ANGLE::HORIZONTAL ); } m_gal->Restore(); @@ -1714,8 +1715,7 @@ void PCB_PAINTER::draw( const PCB_GROUP* aGroup, int aLayer ) int unscaledSize = Mils2iu( ptSize ); // Scale by zoom a bit, but not too much - int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3; - int penWidth = textSize / 10; + int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3; VECTOR2I textOffset = VECTOR2I( width.x / 2, -KiROUND( textSize * 0.5 ) ); VECTOR2I titleHeight = VECTOR2I( 0, KiROUND( textSize * 2.0 ) ); @@ -1725,16 +1725,14 @@ void PCB_PAINTER::draw( const PCB_GROUP* aGroup, int aLayer ) m_gal->DrawLine( topLeft - titleHeight, topLeft + width - titleHeight ); m_gal->DrawLine( topLeft + width - titleHeight, topLeft + width ); - m_gal->SetFontBold( false ); - m_gal->SetFontItalic( true ); - m_gal->SetFontUnderlined( false ); - m_gal->SetTextMirrored( m_gal->IsFlippedX() ); - m_gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER ); - m_gal->SetVerticalJustify( GR_TEXT_V_ALIGN_BOTTOM ); - m_gal->SetIsFill( false ); - m_gal->SetGlyphSize( VECTOR2D( textSize, textSize ) ); - m_gal->SetLineWidth( penWidth ); - m_gal->StrokeText( aGroup->GetName(), topLeft + textOffset, 0.0 ); + TEXT_ATTRIBUTES attrs; + attrs.m_Italic = true; + attrs.m_Halign = GR_TEXT_H_ALIGN_CENTER; + attrs.m_Valign = GR_TEXT_V_ALIGN_BOTTOM; + attrs.m_Size = VECTOR2I( textSize, textSize ); + attrs.m_StrokeWidth = GetPenSizeForNormal( textSize ); + + KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs ); } } } diff --git a/qa/pns/playground.cpp b/qa/pns/playground.cpp index 4c32af7b05..53c52510ec 100644 --- a/qa/pns/playground.cpp +++ b/qa/pns/playground.cpp @@ -197,13 +197,14 @@ int playground_main_func( int argc, char* argv[] ) { overlay->SetStrokeColor( YELLOW ); overlay->Line( closestDist.A, closestDist.B ); - overlay->SetLineWidth( 10000.0 ); - overlay->SetGlyphSize( { 100000.0, 100000.0 } ); + overlay->SetLineWidth( 10000 ); + overlay->SetGlyphSize( { 100000, 100000 } ); overlay->BitmapText( wxString::Format( "dist=%d, l=%d", closestDist.Length() ), - closestDist.A + VECTOR2I( 0, -arcs[i].GetWidth() ), 0 ); + closestDist.A + VECTOR2I( 0, -arcs[i].GetWidth() ), + EDA_ANGLE::HORIZONTAL ); } - overlay->SetLineWidth( 10000.0 ); + overlay->SetLineWidth( 10000 ); overlay->SetStrokeColor( CYAN ); overlay->AnnotatedPoint( arcs[i].GetP0(), arcs[i].GetWidth() / 2 ); overlay->AnnotatedPoint( arcs[i + 1].GetP0(), arcs[i + 1].GetWidth() / 2 ); @@ -262,9 +263,10 @@ int drawShapes( int argc, char* argv[] ) { int mult = ( i % 2 ) ? 1 : -1; overlay->AnnotatedPoint( lc.GetPoint( i ), arc.GetWidth() * 2 ); - overlay->SetGlyphSize( { 800000.0, 800000.0 } ); + overlay->SetGlyphSize( { 800000, 800000 } ); overlay->BitmapText( wxString::Format( "x=%d, y=%d", lc.GetPoint( i ).x, lc.GetPoint( i ).y ), - lc.GetPoint( i ) + VECTOR2I( 0, mult*arc.GetWidth() * 4 ), 0 ); + lc.GetPoint( i ) + VECTOR2I( 0, mult*arc.GetWidth() * 4 ), + EDA_ANGLE::HORIZONTAL ); } arc.Collide( &lc, 100000 ); diff --git a/qa/pns/pns_log_viewer.cpp b/qa/pns/pns_log_viewer.cpp index b273b7da1a..6eee692357 100644 --- a/qa/pns/pns_log_viewer.cpp +++ b/qa/pns/pns_log_viewer.cpp @@ -99,7 +99,7 @@ void LABEL_MANAGER::Redraw( KIGFX::VIEW_OVERLAY* aOvl ) aOvl->SetLineWidth( 10000 ); aOvl->SetStrokeColor( lbl.m_color.Brighten( 0.7 ) ); aOvl->Rectangle( lbl.m_bbox.GetOrigin(), lbl.m_bbox.GetEnd() ); - aOvl->BitmapText( lbl.m_msg, lbl.m_bbox.Centre(), 0.0 ); + aOvl->BitmapText( lbl.m_msg, lbl.m_bbox.Centre(), EDA_ANGLE::HORIZONTAL ); VECTOR2I nearest = nearestBoxCorner( lbl.m_bbox, lbl.m_target ); aOvl->Line( lbl.m_target, nearest ); }