From 0a3c3fda73ae660daa369ae0a2b8fe974b6ce6d4 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Mon, 10 Feb 2025 14:39:57 +0100 Subject: [PATCH] viewBox for glyphpaths added --- src/graphic/QskGlyphTable.cpp | 14 +++++++++++++- tools/glyph2qvg/main.cpp | 8 ++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/graphic/QskGlyphTable.cpp b/src/graphic/QskGlyphTable.cpp index c5e63bcb..e166d5d7 100644 --- a/src/graphic/QskGlyphTable.cpp +++ b/src/graphic/QskGlyphTable.cpp @@ -326,6 +326,12 @@ static uint qskGlyphCount( const QRawFont& font ) return fontEngine ? fontEngine->glyphCount() : 0; } +static qreal qskPixelSize( const QRawFont& font ) +{ + const auto fontEngine = QRawFontPrivate::get( font )->fontEngine; + return fontEngine ? fontEngine->fontDef.pixelSize : 0.0; +} + static GlyphNameTable qskGlyphNameTable( const QRawFont& font ) { const auto count = qskGlyphCount( font ); @@ -452,10 +458,16 @@ QskGraphic QskGlyphTable::glyphGraphic( uint glyphIndex ) const if ( glyphIndex > 0 && qskGlyphCount( m_data->font ) > 0 ) { - const auto path = glyphPath( glyphIndex ); + auto path = glyphPath( glyphIndex ); if ( !path.isEmpty() ) { + // vertical glyph coordinates are from [-sz, 0.0] + const auto sz = qskPixelSize( m_data->font ); + + path.translate( 0.0, sz ); + graphic.setViewBox( QRectF( 0.0, 0.0, sz, sz ) ); + QPainter painter( &graphic ); painter.setRenderHint( QPainter::Antialiasing, true ); painter.fillPath( path, Qt::black ); diff --git a/tools/glyph2qvg/main.cpp b/tools/glyph2qvg/main.cpp index d86a7bb6..feea2643 100644 --- a/tools/glyph2qvg/main.cpp +++ b/tools/glyph2qvg/main.cpp @@ -34,9 +34,11 @@ int main( int argc, char* argv[] ) return -1; } + const int pixelSize = 24; // something + QGuiApplication app( argc, argv ); - QRawFont font( QString( argv[1] ), 16 ); + QRawFont font( QString( argv[1] ), pixelSize ); if ( !font.isValid() ) { qWarning() << "invalid font name:" << argv[1]; @@ -52,14 +54,16 @@ int main( int argc, char* argv[] ) return -3; } - const auto path = font.pathForGlyph( glyphIndex ); + auto path = font.pathForGlyph( glyphIndex ); if ( path.isEmpty() ) { qWarning() << "no glyph for index:" << argv[2]; return -3; } + path.translate( 0.0, pixelSize ); QskGraphic graphic; + graphic.setViewBox( QRectF( 0.0, 0.0, pixelSize, pixelSize ) ); QPainter painter( &graphic ); painter.setRenderHint( QPainter::Antialiasing, true );