Results 1 to 4 of 4

Thread: SVG alpha mask not loading properly?

  1. #1
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Unix/X11 Windows

    Unhappy SVG alpha mask not loading properly?

    I can't get my svg file to render it's alpha mask.

    maxIcon16.svg:
    Qt Code:
    1. <svg baseProfile="tiny" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
    2. <defs>
    3. <mask id="maskedRect1">
    4. <path d="m4,2h10v10h-10z" fill="#fff"/>
    5. <path d="m5,3h8v8h-8z"/>
    6. <path d="m3,5h8v8h-8z"/>
    7. </mask>
    8. <mask id="maskedRect2">
    9. <path d="m2,4h10v10h-10z" fill="#fff"/>
    10. <path d="m3,5h8v8h-8z"/>
    11. </mask>
    12. </defs>
    13. <title>Maximized</title>
    14. <path d="m4,2h10v10h-10z" mask="url(#maskedRect1)"/>
    15. <path d="m2,4h10v10h-10z" mask="url(#maskedRect2)"/>
    16. </svg>
    To copy to clipboard, switch view to plain text mode 

    maxIcon16.pyw:
    Qt Code:
    1. # !/usr/bin/env python3
    2. # encoding: utf-8
    3. #
    4. import sys
    5. from PyQt4.QtCore import QSize
    6. from PyQt4.QtGui import QApplication
    7. from PyQt4.QtSvg import QSvgWidget
    8.  
    9. if __name__ == '__main__':
    10. app = QApplication(sys.argv)
    11.  
    12. widget = QSvgWidget('./maxIcon16.svg')
    13. widget.setMinimumSize(QSize(128, 128))
    14. widget.show()
    15.  
    16. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    I went about it using QPixmap and QIcon as well but without any luck...

    Here's the same svg only with size constraints and in a slightly more readable syntax:

    maxIcon16_RAW.svg:
    Qt Code:
    1. <?xml version="1.0" standalone="no"?>
    2. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
    3. <svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink/" baseProfile="tiny" version="1.2">
    4. <title>Maximized</title>
    5. <defs>
    6. <mask id="maskedRect1">
    7. <rect x="4" y="2" width="10" height="10" style="fill:white"/>
    8. <rect x="5" y="3" width="8" height="8" style="fill:black"/>
    9. <rect x="3" y="5" width="8" height="8" style="fill:black"/>
    10. </mask>
    11. <mask id="maskedRect2">
    12. <rect x="2" y="4" width="10" height="10" style="fill:white"/>
    13. <rect x="3" y="5" width="8" height="8" style="fill:black"/>
    14. </mask>
    15. </defs>
    16. <rect x="4" y="2" width="10" height="10" style="fill:black" mask="url(#maskedRect1)"/>
    17. <rect x="2" y="4" width="10" height="10" style="fill:black" mask="url(#maskedRect2)"/>
    18. </svg>
    To copy to clipboard, switch view to plain text mode 

    I wrote the svg using a text editor so I can't be 100% sure it's not the svg it's self. But it's just a simple mask and it loads just fine in firefox and illustrator...

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: SVG alpha mask not loading properly?

    Still, the first thing to do is obviously to check the SVG with a SVG validator, such as the one from W3C
    http://validator.w3.org/check

  3. The following user says thank you to mvuori for this useful post:

    Grain (2nd November 2012)

  4. #3
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: SVG alpha mask not loading properly?

    Quote Originally Posted by mvuori View Post
    Still, the first thing to do is obviously to check the SVG with a SVG validator, such as the one from W3C
    http://validator.w3.org/check
    Thanks for the tip !
    The first svg passed as an xml while the second didn't pass nothing I'll review the specification again to make sure I'm using everything by the book. Thanks !

    EDIT: In case anyone curious: It seems SVG Tiny 1.1 doesn't support mask quite the same (if at all?) as SVG 1.1 . SVG Tiny 1.2 doesn't even mention it in the specs excepts mentioning full backwards compatibility. I might still be able to mask it since "Also, in SVGB, clipping paths are restricted to rectangles ('rect' elements or references to 'rect' elements through 'use')"(tiny 1.1 specs) but I'll have to try and make sure...

    2nd EDIT: I can't even make the SVG Test Suite example for clipPath to work (http://www.w3.org/Graphics/SVG/Test/...Path-BE-01.svg). I'm guessing that when the specs said "SVGT does not support element opacity, fill-opacity, stroke-opacity properties" - SVGT meaning SVG Tiny - Qt figured it's ok to drop opacity of any kind - masking and clipping included - altogether. Google'ing "qt clip-path" lead me to places like these http://qt-project.org/forums/viewthread/420 so I think I'll be avoiding clipping and masking in svgs from now on.
    Last edited by Grain; 2nd November 2012 at 18:19. Reason: Hopefully the final words on the subject.

  5. #4
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: SVG alpha mask not loading properly?

    Quote Originally Posted by mvuori View Post
    Still, the first thing to do is obviously to check the SVG with a SVG validator, such as the one from W3C
    http://validator.w3.org/check
    Thanks for the tip !
    The first svg passed as an xml while the second didn't pass nothing I'll review the specification again to make sure I'm using everything by the book. Thanks !

    EDIT: In case anyone curious: It seems SVG Tiny 1.1 doesn't support mask quite the same (if at all?) as SVG 1.1 . SVG Tiny 1.2 doesn't even mention it in the specs excepts mentioning full backwards compatibility. I might still be able to mask it since "Also, in SVGB, clipping paths are restricted to rectangles ('rect' elements or references to 'rect' elements through 'use')"(tiny 1.1 specs) but I'll have to try and make sure...

    2nd EDIT: I can't even make the SVG Test Suite example for clipPath to work (http://www.w3.org/Graphics/SVG/Test/...Path-BE-01.svg). I'm guessing that when the specs said "SVGT does not support element opacity, fill-opacity, stroke-opacity properties" - SVGT meaning SVG Tiny - Qt figured it's ok to drop opacity of any kind - masking and clipping included - altogether. Google'ing "qt clip-path" lead me to places like these http://qt-project.org/forums/viewthread/420 so I think I'll be avoiding clipping and masking in svgs from now on.

Similar Threads

  1. Replies: 3
    Last Post: 2nd August 2012, 13:46
  2. Building qwt with qt5 alpha
    By alizadeh91 in forum Qwt
    Replies: 9
    Last Post: 9th July 2012, 13:04
  3. Alpha mask on QScrollArea
    By JonnyJP in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2012, 16:12
  4. How it create a true alpha mask from a QImage?
    By nokkie in forum Qt Programming
    Replies: 1
    Last Post: 3rd May 2010, 21:07
  5. image alpha
    By murko81 in forum Qt Programming
    Replies: 13
    Last Post: 28th October 2006, 19:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.