Ticket #40109: rasterize_svg_icon.diff

File rasterize_svg_icon.diff, 2.7 KB (added by elelay (Eric Le Lay), 11 years ago)
  • port1.0/group/app-1.0.tcl

     
    8787# The default is empty; if no icon graphic is available for this software, this
    8888# is fine. You can supply the path to an existing .icns file, or the path to a
    8989# .png or other graphic file that the makeicns program can convert. A build
    90 # dependency on makeicns will be automatically added if needed. Paths may
    91 # absolute or relative to ${worksrcpath}.
     90# dependency on makeicns will be automatically added if needed. You can also
     91# supply the path to a .svg file and it will be rasterized to the different icon
     92# formats. A build dependency on librsvg will be automatically added if needed.
     93# Paths may be absolute or relative to ${worksrcpath}.
    9294#
    9395# Relates to Info.plist key CFBundleIconFile.
    9496
     
    192194                if {[file extension ${icon}] == ".icns"} {
    193195                    xinstall -m 644 ${icon} ${destroot}${applications_dir}/${app.name}.app/Contents/Resources/${app.name}.icns
    194196
     197                # If app.icon is svg, rasterize and convert it.
     198                } elseif {[file extension ${icon}] == ".svg"} {
     199                    set makeicnsargs {}
     200                    foreach w {16 32 128 256 512} {
     201                        lappend makeicnsargs -$w ${worksrcpath}/${w}.png
     202                       
     203                        if {[catch {exec ${prefix}/bin/rsvg-convert -w $w -h $w ${icon} > ${worksrcpath}/$w.png }]} {
     204                            return -code error "app.icon ${app.icon} could not be converted to png: $::errorInfo"
     205                        }
     206                    }
     207                    if {[catch {eval exec ${prefix}/bin/makeicns $makeicnsargs -out ${destroot}${applications_dir}/${app.name}.app/Contents/Resources/${app.name}.icns 2>@1}]} {
     208                        return -code error "app.icns could not be created: $::errorInfo"
     209                    }
     210               
    195211                # If app.icon is another type of image file, convert it.
    196212                } else {
    197213                    if {[catch {exec ${prefix}/bin/makeicns -in ${icon} -out ${destroot}${applications_dir}/${app.name}.app/Contents/Resources/${app.name}.icns 2>@1}]} {
     
    279295    } elseif {${needs_dep} && !${has_dep}} {
    280296        depends_build-append port:makeicns
    281297    }
     298    set has_dep [expr {[info exists depends_build] ? [lsearch ${depends_build} port:librsvg] != -1 : 0}]
     299    set needs_dep [expr {[file extension ${option}] == ".svg"}]
     300    if {${has_dep} && !${needs_dep}} {
     301        depends_build-delete port:librsvg
     302    } elseif {${needs_dep} && !${has_dep}} {
     303        depends_build-append port:librsvg
     304    }
    282305}
    283306
    284307