Loading Rakefile +184 −101 Original line number Diff line number Diff line Loading @@ -5,78 +5,125 @@ ## sudo apt install optipng icnsutils inkscape ## require 'fileutils' require 'yaml' ## ## CONFIGURATION ## output_directories = [ 'android', 'android/res', 'android/res/drawable-ldpi', 'android/res/drawable-mdpi', 'android/res/drawable-hdpi', 'android/res/drawable-xhdpi', 'mac', 'icons', 'icons/white', 'icons/black', 'icons/white/16', 'icons/white/22', 'icons/white/32', 'icons/white/64', 'icons/black/16', 'icons/black/22', 'icons/black/32', 'icons/black/64', 'icons/logo', 'web', 'web/22', 'web/32', 'web/64', 'web/128', 'web/qr', 'linux', 'linux/hicolor', 'linux/hicolor/24x24', 'linux/hicolor/24x24/apps', 'linux/hicolor/32x32', 'linux/hicolor/32x32/apps', 'linux/hicolor/48x48', 'linux/hicolor/48x48/apps', 'linux/hicolor/64x64', 'linux/hicolor/64x64/apps', 'linux/hicolor/128x128', 'linux/hicolor/128x128/apps', 'linux/hicolor/256x256', 'linux/hicolor/256x256/apps', 'linux/hicolor/scalable', 'linux/hicolor/scalable/apps', 'branding', 'branding/riseup', 'branding/riseup/linux', 'branding/riseup/mac', 'branding/riseup/android', 'branding/riseup/android/res', 'branding/riseup/android/res/drawable-ldpi', 'branding/riseup/android/res/drawable-mdpi', 'branding/riseup/android/res/drawable-hdpi', 'branding/riseup/android/res/drawable-xhdpi', 'branding/calyx', 'branding/calyx/linux', 'branding/calyx/mac', 'branding/calyx/android', 'branding/calyx/android/res', 'branding/calyx/android/res/drawable-ldpi', 'branding/calyx/android/res/drawable-mdpi', 'branding/calyx/android/res/drawable-hdpi', 'branding/calyx/android/res/drawable-xhdpi' output_directories = %[ android: res: drawable: drawable-land: drawable-ldpi: drawable-mdpi: drawable-sw600dp: drawable-sw600dp-port: drawable-xhdpi: drawable-xxhdpi: drawable-xxxhdpi: mipmap-hdpi: mipmap-mdpi: mipmap-xhdpi: mac: icons: white: 16: 22: 32: 64: black: 16: 22: 32: 64: logo: web: 22: 32: 64: 128: qr: linux: hicolor: 24x24: apps: 32x32: apps: 48x48: apps: 64x64: apps: 128x128: apps: 256x256: apps: scalable: apps: branding: riseup: linux: mac: android: res: drawable: drawable-land: drawable-sw600dp: drawable-sw600dp-port: mipmap-hdpi: mipmap-mdpi: mipmap-xhdpi: calyx: linux: mac: android: res: drawable: drawable-land: drawable-sw600dp: drawable-sw600dp-port: mipmap-hdpi: mipmap-mdpi: mipmap-xhdpi: ] android_launcher_target = [ {:size => 36, :dpi => 120, :dest => 'android/res/drawable-ldpi'}, {:size => 48, :dpi => 160, :dest => 'android/res/drawable-mdpi'}, {:size => 72, :dpi => 240, :dest => 'android/res/drawable-hdpi'}, {:size => 96, :dpi => 320, :dest => 'android/res/drawable-xhdpi'} {:size => 48, :dpi => 160, :dest => 'android/res/mipmap-mdpi/ic_launcher.png'}, {:size => 72, :dpi => 240, :dest => 'android/res/mipmap-hdpi/ic_launcher.png'}, {:size => 96, :dpi => 320, :dest => 'android/res/mipmap-xhdpi/ic_laucher.png'}, {:size => 96, :dpi => 320, :dest => 'android/res/drawable/ic_launcher.png'} ] android_background_drawer_target = [ {width: 1024, height: 512, dest: 'android/res/drawable/background_drawer.png'} ] android_background_target = [ {width: 793, height: 1586, dest: 'android/res/drawable/background_main.png'}, {width: 1365, height: 668, dest: 'android/res/drawable-land/background_main.png'}, {width: 1365, height: 928, dest: 'android/res/drawable-sw600dp/background_main.png'}, {width: 793, height: 1586, dest: 'android/res/drawable-sw600dp-port/background_main.png'} ] android_splash_target = [ {width: 945, height: 1889, dest: 'android/res/drawable/ic_splash_background.png'}, {width: 1365, height: 668, dest: 'android/res/drawable-land/ic_splash_background.png'}, {width: 1365, height: 928, dest: 'android/res/drawable-sw600dp/ic_splash_background.png'}, {width: 945, height: 1889, dest: 'android/res/drawable-sw600dp-port/ic_splash_background.png'} ] android_logo_target = [ {size: 171, dest: 'android/res/drawable/logo_square.png'} ] linux_launcher_target = [ {:size => 256, :dest => 'linux/launcher.png'} ] mac_launcher_target = [ {:size => 1024, :dest => 'mac/launcher.png'} ] android_icon_target = [ Loading Loading @@ -171,34 +218,21 @@ copy = [ ## CUSTOM BRANDS ## # # RiseupVPN # riseup_android_launcher = android_launcher_target.map {|i| i = i.clone; i[:dest] = "branding/riseup/" + i[:dest]; i} svg_to_raster += [ ['source/riseup/riseupvpn-launcher.svg', riseup_android_launcher], ['source/riseup/riseupvpn-launcher.svg', {:size => 512, :dest => 'branding/riseup/android/hi-res-icon.png'}], ['source/riseup/riseupvpn-feature-graphic.svg', {:width => 1024, :height => 512, :dest => 'branding/riseup/android/feature-graphic.png'}], ['source/riseup/riseupvpn-launcher.svg', {:size => 256, :dest => 'branding/riseup/linux/riseupvpn.png'}], ['source/riseup/riseupvpn-launcher.svg', {:size => 1024, :dest => 'branding/riseup/mac/riseupvpn.png'}] ] png_to_icns << ['riseup/mac/riseupvpn.png', {:dest => 'branding/riseup/mac/riseupvpn.icns'}] copy << ['source/riseup/riseupvpn-launcher.svg', {:dest => 'branding/riseup/linux/riseupvpn.svg'}] # # CalyxVPN # calyx_android_launcher = android_launcher_target.map {|i| i = i.clone; i[:dest] = "branding/calyx/" + i[:dest]; i} svg_to_raster += [ ['source/calyx/calyxvpn-launcher.svg', calyx_android_launcher], ['source/calyx/calyxvpn-launcher.svg', {:size => 512, :dest => 'branding/calyx/android/hi-res-icon.png'}], # ['source/calyx/calyxvpn-feature-graphic.svg', {:width => 1024, :height => 512, :dest => 'branding/calyx/android/feature-graphic.png'}], ['source/calyx/calyxvpn-launcher.svg', {:size => 256, :dest => 'branding/calyx/linux/calyxvpn.png'}], # ['source/calyx/calyxvpn-launcher.svg', {:size => 1024, :dest => 'branding/calyx/mac/calyxvpn.png'}] ] #png_to_icns << ['calyx/mac/calyxvpn.png', {:dest => 'branding/calyx/mac/calyxvpn.icns'}] copy << ['source/calyx/calyxvpn-launcher.svg', {:dest => 'branding/calyx/linux/calyxvpn.svg'}] def brand_path(prefix, paths) paths.map {|i| i = i.clone; i[:dest] = "branding/" + prefix + "/" + i[:dest]; i} end ['riseup', 'calyx'].each do |brand| svg_to_raster << ["source/#{brand}/launcher.svg", brand_path(brand, android_launcher_target)] svg_to_raster << ["source/#{brand}/logo.svg", brand_path(brand, android_logo_target)] svg_to_raster << ["source/#{brand}/feature.svg", brand_path(brand, android_background_drawer_target)] svg_to_raster << ["source/#{brand}/background.svg", brand_path(brand, android_background_target)] svg_to_raster << ["source/#{brand}/feature.svg", brand_path(brand, android_splash_target)] svg_to_raster << ["source/#{brand}/launcher.svg", brand_path(brand, linux_launcher_target)] svg_to_raster << ["source/#{brand}/launcher.svg", brand_path(brand, mac_launcher_target)] copy << ["source/#{brand}/launcher.svg", {:dest => "branding/#{brand}/linux/launcher.svg"}] png_to_icns << ["branding/#{brand}/mac/launcher.png", {:dest => "branding/#{brand}/mac/launcher.icns"}] end ## ## HELPERS Loading @@ -213,9 +247,20 @@ def run(cmd) end end # # inkscape command line tool only lets you grab dimensions of the image, # not the whole page. So, we just grep for the first height/width. # def dimensions(file) height = `grep -m 1 "height=" '#{file}' | sed 's/[^0-9]//g'`.to_i width = `grep -m 1 "width=" '#{file}' | sed 's/[^0-9]//g'`.to_i return [width, height] end def render_svg_to_raster(source, targets) render_changed(source, targets) do |src_file, dest_file, target| filetype = File.extname(dest_file) width = height = nil if target[:size] height = width = target[:size] else Loading @@ -226,10 +271,33 @@ def render_svg_to_raster(source, targets) real_dest_file = dest_file dest_file = dest_file.sub(/#{filetype}$/, '-tmp.png') end options = ["--file=#{src_file}", "--export-png=#{dest_file}", "--export-background=0xffffff", "--export-background-opacity=0x00"] options << "-w #{width}" if width options << "-h #{height}" if height options << "--export-dpi=#{target[:dpi]}" if target[:dpi] options = ["--file=#{src_file}", "--export-png=#{dest_file}"] if target[:clear] options << "--export-background=0xffffff" << "--export-background-opacity=0x00" end if width || height if width && height options << "-w #{width}" << "-h #{height}" src_width, src_height = dimensions(src_file) src_ratio = src_width.to_f / src_height ratio = width.to_f / height if ratio != src_ratio if target[:stretch].nil? || target[:stretch] == :height h = src_width / ratio options << "--export-area=%i:%i:%i:%i" % [0,0,src_width,h] elsif target[:stretch] == :width w = src_height * ratio options << "--export-area=%i:%i:%i:%i" % [0,0,w,src_height] end end elsif width options << "-w #{width}" elsif height options << "-h #{height}" end elsif target[:dpi] options << "--export-dpi=#{target[:dpi]}" end run("inkscape #{options.join ' '}") run("optipng #{dest_file}") if filetype != '.png' Loading Loading @@ -261,7 +329,15 @@ end # source and destination pair that needs rendering. # def render_changed(source, targets, &block) if source !~ /\*/ && !File.exist?(source) puts "Missing file: #{source}" return end Dir.glob(source).each do |src_file| if !File.exist?(src_file) puts "Missing file: #{src_file}" next end [targets].flatten.each do |target| if File.directory?(target[:dest]) dest_file = File.join(target[:dest], File.basename(src_file).sub(/\.svg$/,'.png')) Loading @@ -281,20 +357,27 @@ def progress STDOUT.flush end def create_directories(dir_hash) dir_hash.each do |k,v| FileUtils.mkdir_p(k.to_s) if v Dir.chdir(k.to_s) do create_directories(v) end end end end ## ## RENDER TASK ## require 'fileutils' task :default => :render desc "render SVG images" task :render do Dir.chdir(File.dirname(__FILE__)) do output_directories.each do |dir| FileUtils.mkdir_p(dir) end create_directories(YAML.parse(output_directories).to_ruby) svg_to_raster.each do |source, targets| render_svg_to_raster(source, targets) end Loading android/res/drawable-ldpi/mask-launcher.pngdeleted 100644 → 0 −1.7 KiB Loading image diff... android/res/drawable-xhdpi/mask-launcher.png→android/res/drawable/ic_launcher.png (4.36 KiB) File moved. View file android/res/drawable-hdpi/mask-launcher.png→android/res/mipmap-hdpi/ic_launcher.png (3.39 KiB) File moved. View file android/res/drawable-mdpi/mask-launcher.png→android/res/mipmap-mdpi/ic_launcher.png (2.2 KiB) File moved. View file Loading
Rakefile +184 −101 Original line number Diff line number Diff line Loading @@ -5,78 +5,125 @@ ## sudo apt install optipng icnsutils inkscape ## require 'fileutils' require 'yaml' ## ## CONFIGURATION ## output_directories = [ 'android', 'android/res', 'android/res/drawable-ldpi', 'android/res/drawable-mdpi', 'android/res/drawable-hdpi', 'android/res/drawable-xhdpi', 'mac', 'icons', 'icons/white', 'icons/black', 'icons/white/16', 'icons/white/22', 'icons/white/32', 'icons/white/64', 'icons/black/16', 'icons/black/22', 'icons/black/32', 'icons/black/64', 'icons/logo', 'web', 'web/22', 'web/32', 'web/64', 'web/128', 'web/qr', 'linux', 'linux/hicolor', 'linux/hicolor/24x24', 'linux/hicolor/24x24/apps', 'linux/hicolor/32x32', 'linux/hicolor/32x32/apps', 'linux/hicolor/48x48', 'linux/hicolor/48x48/apps', 'linux/hicolor/64x64', 'linux/hicolor/64x64/apps', 'linux/hicolor/128x128', 'linux/hicolor/128x128/apps', 'linux/hicolor/256x256', 'linux/hicolor/256x256/apps', 'linux/hicolor/scalable', 'linux/hicolor/scalable/apps', 'branding', 'branding/riseup', 'branding/riseup/linux', 'branding/riseup/mac', 'branding/riseup/android', 'branding/riseup/android/res', 'branding/riseup/android/res/drawable-ldpi', 'branding/riseup/android/res/drawable-mdpi', 'branding/riseup/android/res/drawable-hdpi', 'branding/riseup/android/res/drawable-xhdpi', 'branding/calyx', 'branding/calyx/linux', 'branding/calyx/mac', 'branding/calyx/android', 'branding/calyx/android/res', 'branding/calyx/android/res/drawable-ldpi', 'branding/calyx/android/res/drawable-mdpi', 'branding/calyx/android/res/drawable-hdpi', 'branding/calyx/android/res/drawable-xhdpi' output_directories = %[ android: res: drawable: drawable-land: drawable-ldpi: drawable-mdpi: drawable-sw600dp: drawable-sw600dp-port: drawable-xhdpi: drawable-xxhdpi: drawable-xxxhdpi: mipmap-hdpi: mipmap-mdpi: mipmap-xhdpi: mac: icons: white: 16: 22: 32: 64: black: 16: 22: 32: 64: logo: web: 22: 32: 64: 128: qr: linux: hicolor: 24x24: apps: 32x32: apps: 48x48: apps: 64x64: apps: 128x128: apps: 256x256: apps: scalable: apps: branding: riseup: linux: mac: android: res: drawable: drawable-land: drawable-sw600dp: drawable-sw600dp-port: mipmap-hdpi: mipmap-mdpi: mipmap-xhdpi: calyx: linux: mac: android: res: drawable: drawable-land: drawable-sw600dp: drawable-sw600dp-port: mipmap-hdpi: mipmap-mdpi: mipmap-xhdpi: ] android_launcher_target = [ {:size => 36, :dpi => 120, :dest => 'android/res/drawable-ldpi'}, {:size => 48, :dpi => 160, :dest => 'android/res/drawable-mdpi'}, {:size => 72, :dpi => 240, :dest => 'android/res/drawable-hdpi'}, {:size => 96, :dpi => 320, :dest => 'android/res/drawable-xhdpi'} {:size => 48, :dpi => 160, :dest => 'android/res/mipmap-mdpi/ic_launcher.png'}, {:size => 72, :dpi => 240, :dest => 'android/res/mipmap-hdpi/ic_launcher.png'}, {:size => 96, :dpi => 320, :dest => 'android/res/mipmap-xhdpi/ic_laucher.png'}, {:size => 96, :dpi => 320, :dest => 'android/res/drawable/ic_launcher.png'} ] android_background_drawer_target = [ {width: 1024, height: 512, dest: 'android/res/drawable/background_drawer.png'} ] android_background_target = [ {width: 793, height: 1586, dest: 'android/res/drawable/background_main.png'}, {width: 1365, height: 668, dest: 'android/res/drawable-land/background_main.png'}, {width: 1365, height: 928, dest: 'android/res/drawable-sw600dp/background_main.png'}, {width: 793, height: 1586, dest: 'android/res/drawable-sw600dp-port/background_main.png'} ] android_splash_target = [ {width: 945, height: 1889, dest: 'android/res/drawable/ic_splash_background.png'}, {width: 1365, height: 668, dest: 'android/res/drawable-land/ic_splash_background.png'}, {width: 1365, height: 928, dest: 'android/res/drawable-sw600dp/ic_splash_background.png'}, {width: 945, height: 1889, dest: 'android/res/drawable-sw600dp-port/ic_splash_background.png'} ] android_logo_target = [ {size: 171, dest: 'android/res/drawable/logo_square.png'} ] linux_launcher_target = [ {:size => 256, :dest => 'linux/launcher.png'} ] mac_launcher_target = [ {:size => 1024, :dest => 'mac/launcher.png'} ] android_icon_target = [ Loading Loading @@ -171,34 +218,21 @@ copy = [ ## CUSTOM BRANDS ## # # RiseupVPN # riseup_android_launcher = android_launcher_target.map {|i| i = i.clone; i[:dest] = "branding/riseup/" + i[:dest]; i} svg_to_raster += [ ['source/riseup/riseupvpn-launcher.svg', riseup_android_launcher], ['source/riseup/riseupvpn-launcher.svg', {:size => 512, :dest => 'branding/riseup/android/hi-res-icon.png'}], ['source/riseup/riseupvpn-feature-graphic.svg', {:width => 1024, :height => 512, :dest => 'branding/riseup/android/feature-graphic.png'}], ['source/riseup/riseupvpn-launcher.svg', {:size => 256, :dest => 'branding/riseup/linux/riseupvpn.png'}], ['source/riseup/riseupvpn-launcher.svg', {:size => 1024, :dest => 'branding/riseup/mac/riseupvpn.png'}] ] png_to_icns << ['riseup/mac/riseupvpn.png', {:dest => 'branding/riseup/mac/riseupvpn.icns'}] copy << ['source/riseup/riseupvpn-launcher.svg', {:dest => 'branding/riseup/linux/riseupvpn.svg'}] # # CalyxVPN # calyx_android_launcher = android_launcher_target.map {|i| i = i.clone; i[:dest] = "branding/calyx/" + i[:dest]; i} svg_to_raster += [ ['source/calyx/calyxvpn-launcher.svg', calyx_android_launcher], ['source/calyx/calyxvpn-launcher.svg', {:size => 512, :dest => 'branding/calyx/android/hi-res-icon.png'}], # ['source/calyx/calyxvpn-feature-graphic.svg', {:width => 1024, :height => 512, :dest => 'branding/calyx/android/feature-graphic.png'}], ['source/calyx/calyxvpn-launcher.svg', {:size => 256, :dest => 'branding/calyx/linux/calyxvpn.png'}], # ['source/calyx/calyxvpn-launcher.svg', {:size => 1024, :dest => 'branding/calyx/mac/calyxvpn.png'}] ] #png_to_icns << ['calyx/mac/calyxvpn.png', {:dest => 'branding/calyx/mac/calyxvpn.icns'}] copy << ['source/calyx/calyxvpn-launcher.svg', {:dest => 'branding/calyx/linux/calyxvpn.svg'}] def brand_path(prefix, paths) paths.map {|i| i = i.clone; i[:dest] = "branding/" + prefix + "/" + i[:dest]; i} end ['riseup', 'calyx'].each do |brand| svg_to_raster << ["source/#{brand}/launcher.svg", brand_path(brand, android_launcher_target)] svg_to_raster << ["source/#{brand}/logo.svg", brand_path(brand, android_logo_target)] svg_to_raster << ["source/#{brand}/feature.svg", brand_path(brand, android_background_drawer_target)] svg_to_raster << ["source/#{brand}/background.svg", brand_path(brand, android_background_target)] svg_to_raster << ["source/#{brand}/feature.svg", brand_path(brand, android_splash_target)] svg_to_raster << ["source/#{brand}/launcher.svg", brand_path(brand, linux_launcher_target)] svg_to_raster << ["source/#{brand}/launcher.svg", brand_path(brand, mac_launcher_target)] copy << ["source/#{brand}/launcher.svg", {:dest => "branding/#{brand}/linux/launcher.svg"}] png_to_icns << ["branding/#{brand}/mac/launcher.png", {:dest => "branding/#{brand}/mac/launcher.icns"}] end ## ## HELPERS Loading @@ -213,9 +247,20 @@ def run(cmd) end end # # inkscape command line tool only lets you grab dimensions of the image, # not the whole page. So, we just grep for the first height/width. # def dimensions(file) height = `grep -m 1 "height=" '#{file}' | sed 's/[^0-9]//g'`.to_i width = `grep -m 1 "width=" '#{file}' | sed 's/[^0-9]//g'`.to_i return [width, height] end def render_svg_to_raster(source, targets) render_changed(source, targets) do |src_file, dest_file, target| filetype = File.extname(dest_file) width = height = nil if target[:size] height = width = target[:size] else Loading @@ -226,10 +271,33 @@ def render_svg_to_raster(source, targets) real_dest_file = dest_file dest_file = dest_file.sub(/#{filetype}$/, '-tmp.png') end options = ["--file=#{src_file}", "--export-png=#{dest_file}", "--export-background=0xffffff", "--export-background-opacity=0x00"] options << "-w #{width}" if width options << "-h #{height}" if height options << "--export-dpi=#{target[:dpi]}" if target[:dpi] options = ["--file=#{src_file}", "--export-png=#{dest_file}"] if target[:clear] options << "--export-background=0xffffff" << "--export-background-opacity=0x00" end if width || height if width && height options << "-w #{width}" << "-h #{height}" src_width, src_height = dimensions(src_file) src_ratio = src_width.to_f / src_height ratio = width.to_f / height if ratio != src_ratio if target[:stretch].nil? || target[:stretch] == :height h = src_width / ratio options << "--export-area=%i:%i:%i:%i" % [0,0,src_width,h] elsif target[:stretch] == :width w = src_height * ratio options << "--export-area=%i:%i:%i:%i" % [0,0,w,src_height] end end elsif width options << "-w #{width}" elsif height options << "-h #{height}" end elsif target[:dpi] options << "--export-dpi=#{target[:dpi]}" end run("inkscape #{options.join ' '}") run("optipng #{dest_file}") if filetype != '.png' Loading Loading @@ -261,7 +329,15 @@ end # source and destination pair that needs rendering. # def render_changed(source, targets, &block) if source !~ /\*/ && !File.exist?(source) puts "Missing file: #{source}" return end Dir.glob(source).each do |src_file| if !File.exist?(src_file) puts "Missing file: #{src_file}" next end [targets].flatten.each do |target| if File.directory?(target[:dest]) dest_file = File.join(target[:dest], File.basename(src_file).sub(/\.svg$/,'.png')) Loading @@ -281,20 +357,27 @@ def progress STDOUT.flush end def create_directories(dir_hash) dir_hash.each do |k,v| FileUtils.mkdir_p(k.to_s) if v Dir.chdir(k.to_s) do create_directories(v) end end end end ## ## RENDER TASK ## require 'fileutils' task :default => :render desc "render SVG images" task :render do Dir.chdir(File.dirname(__FILE__)) do output_directories.each do |dir| FileUtils.mkdir_p(dir) end create_directories(YAML.parse(output_directories).to_ruby) svg_to_raster.each do |source, targets| render_svg_to_raster(source, targets) end Loading
android/res/drawable-xhdpi/mask-launcher.png→android/res/drawable/ic_launcher.png (4.36 KiB) File moved. View file
android/res/drawable-hdpi/mask-launcher.png→android/res/mipmap-hdpi/ic_launcher.png (3.39 KiB) File moved. View file
android/res/drawable-mdpi/mask-launcher.png→android/res/mipmap-mdpi/ic_launcher.png (2.2 KiB) File moved. View file