avoid viewBox translation

This commit is contained in:
Uwe Rathmann 2025-02-10 15:14:41 +01:00
parent 0a3c3fda73
commit 88a501d998
2 changed files with 9 additions and 10 deletions

View File

@ -458,15 +458,13 @@ QskGraphic QskGlyphTable::glyphGraphic( uint glyphIndex ) const
if ( glyphIndex > 0 && qskGlyphCount( m_data->font ) > 0 ) if ( glyphIndex > 0 && qskGlyphCount( m_data->font ) > 0 )
{ {
auto path = glyphPath( glyphIndex ); const auto path = glyphPath( glyphIndex );
if ( !path.isEmpty() ) if ( !path.isEmpty() )
{ {
// vertical glyph coordinates are from [-sz, 0.0] // vertical glyph coordinates are in the range [-sz, 0.0]
const auto sz = qskPixelSize( m_data->font ); const auto sz = qskPixelSize( m_data->font );
graphic.setViewBox( QRectF( 0.0, -sz, sz, sz ) );
path.translate( 0.0, sz );
graphic.setViewBox( QRectF( 0.0, 0.0, sz, sz ) );
QPainter painter( &graphic ); QPainter painter( &graphic );
painter.setRenderHint( QPainter::Antialiasing, true ); painter.setRenderHint( QPainter::Antialiasing, true );

View File

@ -34,11 +34,11 @@ int main( int argc, char* argv[] )
return -1; return -1;
} }
const int pixelSize = 24; // something const int sz = 24; // something
QGuiApplication app( argc, argv ); QGuiApplication app( argc, argv );
QRawFont font( QString( argv[1] ), pixelSize ); QRawFont font( QString( argv[1] ), sz );
if ( !font.isValid() ) if ( !font.isValid() )
{ {
qWarning() << "invalid font name:" << argv[1]; qWarning() << "invalid font name:" << argv[1];
@ -54,16 +54,17 @@ int main( int argc, char* argv[] )
return -3; return -3;
} }
auto path = font.pathForGlyph( glyphIndex ); const auto path = font.pathForGlyph( glyphIndex );
if ( path.isEmpty() ) if ( path.isEmpty() )
{ {
qWarning() << "no glyph for index:" << argv[2]; qWarning() << "no glyph for index:" << argv[2];
return -3; return -3;
} }
path.translate( 0.0, pixelSize );
QskGraphic graphic; QskGraphic graphic;
graphic.setViewBox( QRectF( 0.0, 0.0, pixelSize, pixelSize ) );
// vertical glyph coordinates are in the range [-sz, 0.0]
graphic.setViewBox( QRectF( 0.0, -sz, sz, sz ) );
QPainter painter( &graphic ); QPainter painter( &graphic );
painter.setRenderHint( QPainter::Antialiasing, true ); painter.setRenderHint( QPainter::Antialiasing, true );