[PyQt] SVG Glyphs in PyQt

Colin McPhail colin.mcphail at talktalk.net
Tue Sep 14 11:52:26 BST 2010


On 13 Sep 2010, at 19:24, Kyle Covington wrote:

> Recently I found that svg files generated by Cairo do not plot properly in pyqt.  The error comes from the use of glyphs which seem not to be shown in pyqt (this might be wrong but I couldn't find any way of getting glyphs to render). 
> 
> ...
> 
> I just wanted people to have these so they wouldn't have to search high and low like I did to find a way to render glyphs in pyqt. 
> 
> ...

I can't speak for Cairo-generated SVG files, but PyQt4 doesn't have a problem displaying glyphs from SVG font files generated by FontForge, for example.  Assuming that file  /Users/colin/MyFonts/MagicFont.svg  contains a valid <font id="MagicFont" ...> ... </font> definition then a test file such as the following should cause "Sample text here" to be displayed using glyphs from MagicFont:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN" "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
<svg width="400px" height="300px" version="1.1"
     xmlns = 'http://www.w3.org/2000/svg'
     xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
    <font-face font-family="MagicFont">
        <font-face-src>
            <font-face-uri
                xlink:href="file:///Users/colin/MyFonts/MagicFont.svg#MagicFont"/>
        </font-face-src>
    </font-face>
</defs>

<text font-size="32" x="20" y="40" style="font-family: MagicFont;">
	Sample text here
</text>

</svg>

I used the svgviewer example from the PyQt4 demo to display the sample text.

Hope this helps.
-- Colin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100914/5fa756ca/attachment.html>


More information about the PyQt mailing list