Work fork of an Android Jabber client for bridge users git.sr.ht/~singpolyma/cheogram-android
sopranica sgx xmpp jabber
0

Configure Feed

Select the types of activity you want to include in your feed.

reformat ruby render script

Daniel Gultsch (Dec 26, 2022, 3:21 PM +0100) a157d679 eb51b03d

+128 -139
+128 -139
art/render.rb
··· 1 1 #!/bin/env ruby 2 + # frozen_string_literal: true 2 3 3 4 require 'xml' 4 5 5 6 resolutions = { 6 - 'mdpi' => 1, 7 - 'hdpi' => 1.5, 8 - 'xhdpi' => 2, 9 - 'xxhdpi' => 3, 10 - 'xxxhdpi' => 4, 11 - } 7 + 'mdpi' => 1, 8 + 'hdpi' => 1.5, 9 + 'xhdpi' => 2, 10 + 'xxhdpi' => 3, 11 + 'xxxhdpi' => 4 12 + } 12 13 13 14 images = { 14 - 'main_logo.svg' => ['conversations/main_logo', 200], 15 - 'quicksy_main_logo.svg' => ['quicksy/main_logo', 200], 16 - 'splash_logo.svg' => ['conversations/splash_logo', 144], 17 - 'quicksy_splash_logo.svg' => ['quicksy/splash_logo', 144], 18 - 'ic_search_black.svg' => ['ic_search_background_black', 144], 19 - 'ic_search_white.svg' => ['ic_search_background_white', 144], 20 - 'ic_no_results_white.svg' => ['ic_no_results_background_white', 144], 21 - 'ic_no_results_black.svg' => ['ic_no_results_background_black', 144], 22 - 'play_video_white.svg' => ['play_video_white', 128], 23 - 'play_gif_white.svg' => ['play_gif_white', 128], 24 - 'play_video_black.svg' => ['play_video_black', 128], 25 - 'play_gif_black.svg' => ['play_gif_black', 128], 26 - 'open_pdf_black.svg' => ['open_pdf_black', 128], 27 - 'open_pdf_white.svg' => ['open_pdf_white', 128], 28 - 'conversations_mono.svg' => ['conversations/ic_notification', 24], 29 - 'quicksy_mono.svg' => ['quicksy/ic_notification', 24], 30 - 'flip_camera_android-black-24dp.svg' => ['ic_flip_camera_android_black_24dp', 24], 31 - 'ic_missed_call_notification.svg' => ['ic_missed_call_notification', 24], 32 - 'ic_send_text_offline.svg' => ['ic_send_text_offline', 36], 33 - 'ic_send_text_offline_white.svg' => ['ic_send_text_offline_white', 36], 34 - 'ic_send_text_online.svg' => ['ic_send_text_online', 36], 35 - 'ic_send_text_away.svg' => ['ic_send_text_away', 36], 36 - 'ic_send_text_dnd.svg' => ['ic_send_text_dnd', 36], 37 - 'ic_send_photo_online.svg' => ['ic_send_photo_online', 36], 38 - 'ic_send_photo_offline.svg' => ['ic_send_photo_offline', 36], 39 - 'ic_send_photo_offline_white.svg' => ['ic_send_photo_offline_white', 36], 40 - 'ic_send_photo_away.svg' => ['ic_send_photo_away', 36], 41 - 'ic_send_photo_dnd.svg' => ['ic_send_photo_dnd', 36], 42 - 'ic_send_location_online.svg' => ['ic_send_location_online', 36], 43 - 'ic_send_location_offline.svg' => ['ic_send_location_offline', 36], 44 - 'ic_send_location_offline_white.svg' => ['ic_send_location_offline_white', 36], 45 - 'ic_send_location_away.svg' => ['ic_send_location_away', 36], 46 - 'ic_send_location_dnd.svg' => ['ic_send_location_dnd', 36], 47 - 'ic_send_voice_online.svg' => ['ic_send_voice_online', 36], 48 - 'ic_send_voice_offline.svg' => ['ic_send_voice_offline', 36], 49 - 'ic_send_voice_offline_white.svg' => ['ic_send_voice_offline_white', 36], 50 - 'ic_send_voice_away.svg' => ['ic_send_voice_away', 36], 51 - 'ic_send_voice_dnd.svg' => ['ic_send_voice_dnd', 36], 52 - 'ic_send_cancel_online.svg' => ['ic_send_cancel_online', 36], 53 - 'ic_send_cancel_offline.svg' => ['ic_send_cancel_offline', 36], 54 - 'ic_send_cancel_offline_white.svg' => ['ic_send_cancel_offline_white', 36], 55 - 'ic_send_cancel_away.svg' => ['ic_send_cancel_away', 36], 56 - 'ic_send_cancel_dnd.svg' => ['ic_send_cancel_dnd', 36], 57 - 'ic_send_picture_online.svg' => ['ic_send_picture_online', 36], 58 - 'ic_send_picture_offline.svg' => ['ic_send_picture_offline', 36], 59 - 'ic_send_picture_offline_white.svg' => ['ic_send_picture_offline_white', 36], 60 - 'ic_send_picture_away.svg' => ['ic_send_picture_away', 36], 61 - 'ic_send_picture_dnd.svg' => ['ic_send_picture_dnd', 36], 62 - 'ic_send_videocam_online.svg' => ['ic_send_videocam_online', 36], 63 - 'ic_send_videocam_offline.svg' => ['ic_send_videocam_offline', 36], 64 - 'ic_send_videocam_offline_white.svg' => ['ic_send_videocam_offline_white', 36], 65 - 'ic_send_videocam_away.svg' => ['ic_send_videocam_away', 36], 66 - 'ic_send_videocam_dnd.svg' => ['ic_send_videocam_dnd', 36], 67 - 'ic_notifications_none_white80.svg' => ['ic_notifications_none_white80', 24], 68 - 'ic_notifications_off_white80.svg' => ['ic_notifications_off_white80', 24], 69 - 'ic_notifications_paused_white80.svg' => ['ic_notifications_paused_white80', 24], 70 - 'ic_notifications_white80.svg' => ['ic_notifications_white80', 24], 71 - 'ic_verified_fingerprint.svg' => ['ic_verified_fingerprint', 36], 72 - 'qrcode-scan.svg' => ['ic_qr_code_scan_white_24dp', 24], 73 - 'message_bubble_received.svg' => ['message_bubble_received.9', 0], 74 - 'message_bubble_received_grey.svg' => ['message_bubble_received_grey.9', 0], 75 - 'message_bubble_received_dark.svg' => ['message_bubble_received_dark.9', 0], 76 - 'message_bubble_received_warning.svg' => ['message_bubble_received_warning.9', 0], 77 - 'message_bubble_received_white.svg' => ['message_bubble_received_white.9', 0], 78 - 'message_bubble_sent.svg' => ['message_bubble_sent.9', 0], 79 - 'message_bubble_sent_grey.svg' => ['message_bubble_sent_grey.9', 0], 80 - 'date_bubble_white.svg' => ['date_bubble_white.9', 0], 81 - 'date_bubble_grey.svg' => ['date_bubble_grey.9', 0], 82 - 'marker.svg' => ['marker', 0] 83 - } 15 + 'main_logo.svg' => ['conversations/main_logo', 200], 16 + 'quicksy_main_logo.svg' => ['quicksy/main_logo', 200], 17 + 'splash_logo.svg' => ['conversations/splash_logo', 144], 18 + 'quicksy_splash_logo.svg' => ['quicksy/splash_logo', 144], 19 + 'ic_search_black.svg' => ['ic_search_background_black', 144], 20 + 'ic_search_white.svg' => ['ic_search_background_white', 144], 21 + 'ic_no_results_white.svg' => ['ic_no_results_background_white', 144], 22 + 'ic_no_results_black.svg' => ['ic_no_results_background_black', 144], 23 + 'play_video_white.svg' => ['play_video_white', 128], 24 + 'play_gif_white.svg' => ['play_gif_white', 128], 25 + 'play_video_black.svg' => ['play_video_black', 128], 26 + 'play_gif_black.svg' => ['play_gif_black', 128], 27 + 'open_pdf_black.svg' => ['open_pdf_black', 128], 28 + 'open_pdf_white.svg' => ['open_pdf_white', 128], 29 + 'conversations_mono.svg' => ['conversations/ic_notification', 24], 30 + 'quicksy_mono.svg' => ['quicksy/ic_notification', 24], 31 + 'flip_camera_android-black-24dp.svg' => ['ic_flip_camera_android_black_24dp', 24], 32 + 'ic_send_text_offline.svg' => ['ic_send_text_offline', 36], 33 + 'ic_send_text_offline_white.svg' => ['ic_send_text_offline_white', 36], 34 + 'ic_send_text_online.svg' => ['ic_send_text_online', 36], 35 + 'ic_send_text_away.svg' => ['ic_send_text_away', 36], 36 + 'ic_send_text_dnd.svg' => ['ic_send_text_dnd', 36], 37 + 'ic_send_photo_online.svg' => ['ic_send_photo_online', 36], 38 + 'ic_send_photo_offline.svg' => ['ic_send_photo_offline', 36], 39 + 'ic_send_photo_offline_white.svg' => ['ic_send_photo_offline_white', 36], 40 + 'ic_send_photo_away.svg' => ['ic_send_photo_away', 36], 41 + 'ic_send_photo_dnd.svg' => ['ic_send_photo_dnd', 36], 42 + 'ic_send_location_online.svg' => ['ic_send_location_online', 36], 43 + 'ic_send_location_offline.svg' => ['ic_send_location_offline', 36], 44 + 'ic_send_location_offline_white.svg' => ['ic_send_location_offline_white', 36], 45 + 'ic_send_location_away.svg' => ['ic_send_location_away', 36], 46 + 'ic_send_location_dnd.svg' => ['ic_send_location_dnd', 36], 47 + 'ic_send_voice_online.svg' => ['ic_send_voice_online', 36], 48 + 'ic_send_voice_offline.svg' => ['ic_send_voice_offline', 36], 49 + 'ic_send_voice_offline_white.svg' => ['ic_send_voice_offline_white', 36], 50 + 'ic_send_voice_away.svg' => ['ic_send_voice_away', 36], 51 + 'ic_send_voice_dnd.svg' => ['ic_send_voice_dnd', 36], 52 + 'ic_send_cancel_online.svg' => ['ic_send_cancel_online', 36], 53 + 'ic_send_cancel_offline.svg' => ['ic_send_cancel_offline', 36], 54 + 'ic_send_cancel_offline_white.svg' => ['ic_send_cancel_offline_white', 36], 55 + 'ic_send_cancel_away.svg' => ['ic_send_cancel_away', 36], 56 + 'ic_send_cancel_dnd.svg' => ['ic_send_cancel_dnd', 36], 57 + 'ic_send_picture_online.svg' => ['ic_send_picture_online', 36], 58 + 'ic_send_picture_offline.svg' => ['ic_send_picture_offline', 36], 59 + 'ic_send_picture_offline_white.svg' => ['ic_send_picture_offline_white', 36], 60 + 'ic_send_picture_away.svg' => ['ic_send_picture_away', 36], 61 + 'ic_send_picture_dnd.svg' => ['ic_send_picture_dnd', 36], 62 + 'ic_send_videocam_online.svg' => ['ic_send_videocam_online', 36], 63 + 'ic_send_videocam_offline.svg' => ['ic_send_videocam_offline', 36], 64 + 'ic_send_videocam_offline_white.svg' => ['ic_send_videocam_offline_white', 36], 65 + 'ic_send_videocam_away.svg' => ['ic_send_videocam_away', 36], 66 + 'ic_send_videocam_dnd.svg' => ['ic_send_videocam_dnd', 36], 67 + 'ic_notifications_none_white80.svg' => ['ic_notifications_none_white80', 24], 68 + 'ic_notifications_off_white80.svg' => ['ic_notifications_off_white80', 24], 69 + 'ic_notifications_paused_white80.svg' => ['ic_notifications_paused_white80', 24], 70 + 'ic_notifications_white80.svg' => ['ic_notifications_white80', 24], 71 + 'ic_verified_fingerprint.svg' => ['ic_verified_fingerprint', 36], 72 + 'qrcode-scan.svg' => ['ic_qr_code_scan_white_24dp', 24], 73 + 'message_bubble_received.svg' => ['message_bubble_received.9', 0], 74 + 'message_bubble_received_grey.svg' => ['message_bubble_received_grey.9', 0], 75 + 'message_bubble_received_dark.svg' => ['message_bubble_received_dark.9', 0], 76 + 'message_bubble_received_warning.svg' => ['message_bubble_received_warning.9', 0], 77 + 'message_bubble_received_white.svg' => ['message_bubble_received_white.9', 0], 78 + 'message_bubble_sent.svg' => ['message_bubble_sent.9', 0], 79 + 'message_bubble_sent_grey.svg' => ['message_bubble_sent_grey.9', 0], 80 + 'date_bubble_white.svg' => ['date_bubble_white.9', 0], 81 + 'date_bubble_grey.svg' => ['date_bubble_grey.9', 0], 82 + 'marker.svg' => ['marker', 0] 83 + } 84 84 85 - # Executable paths for Mac OSX 86 - # "/Applications/Inkscape.app/Contents/Resources/bin/inkscape" 87 - 88 - inkscape = "inkscape" 89 - imagemagick = "magick" 85 + inkscape = 'inkscape' 86 + imagemagick = 'convert' 90 87 91 88 def execute_cmd(cmd) 92 - puts cmd 93 - system cmd 89 + puts cmd 90 + system cmd 94 91 end 95 92 96 93 images.each do |source_filename, settings| 97 - svg_content = File.read(source_filename) 94 + svg_content = File.read(source_filename) 95 + output_filename, base_size = settings 98 96 99 - svg = XML::Document.string(svg_content) 100 - base_width = svg.root["width"].to_i 101 - base_height = svg.root["height"].to_i 97 + svg = XML::Document.string(svg_content) 98 + base_width = svg.root['width'].to_i 99 + base_height = svg.root['height'].to_i 102 100 103 - guides = svg.find(".//sodipodi:guide","sodipodi:http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd") 101 + guides = svg.find('.//sodipodi:guide', 'sodipodi:http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd') 104 102 105 - resolutions.each do |resolution, factor| 106 - output_filename, base_size = settings 103 + resolutions.each do |resolution, factor| 104 + if base_size.positive? 105 + width = factor * base_size 106 + height = factor * base_size 107 + else 108 + width = factor * base_width 109 + height = factor * base_height 110 + end 107 111 108 - if base_size > 0 109 - width = factor * base_size 110 - height = factor * base_size 111 - else 112 - width = factor * base_width 113 - height = factor * base_height 114 - end 112 + output_parts = output_filename.split('/') 115 113 116 - output_parts = output_filename.split('/') 114 + path = if output_parts.count != 2 115 + "../src/main/res/drawable-#{resolution}/#{output_filename}.png" 116 + else 117 + "../src/#{output_parts[0]}/res/drawable-#{resolution}/#{output_parts[1]}.png" 118 + end 119 + execute_cmd "#{inkscape} #{source_filename} -C -w #{width.to_i} -h #{height.to_i} --export-filename=#{path}" 117 120 118 - if output_parts.count != 2 119 - path = "../src/main/res/drawable-#{resolution}/#{output_filename}.png" 120 - else 121 - path = "../src/#{output_parts[0]}/res/drawable-#{resolution}/#{output_parts[1]}.png" 122 - end 123 - execute_cmd "#{inkscape} #{source_filename} -C -w #{width} -h #{height} -e #{path}" 121 + top = [] 122 + right = [] 123 + bottom = [] 124 + left = [] 124 125 125 - top = [] 126 - right = [] 127 - bottom = [] 128 - left = [] 126 + guides.each do |guide| 127 + orientation = guide['orientation'] 128 + x, y = guide['position'].split(',') 129 + x = x.to_i 130 + y = y.to_i 129 131 130 - guides.each do |guide| 131 - orientation = guide["orientation"] 132 - x, y = guide["position"].split(",") 133 - x, y = x.to_i, y.to_i 134 - 135 - if orientation == "1,0" and y == base_height 136 - top.push(x * factor) 137 - end 132 + top.push(x * factor) if (orientation == '1,0') && (y == base_height) 138 133 139 - if orientation == "0,1" and x == base_width 140 - right.push((base_height - y) * factor) 141 - end 134 + right.push((base_height - y) * factor) if (orientation == '0,1') && (x == base_width) 142 135 143 - if orientation == "1,0" and y == 0 144 - bottom.push(x * factor) 145 - end 136 + bottom.push(x * factor) if (orientation == '1,0') && y.zero? 146 137 147 - if orientation == "0,1" and x == 0 148 - left.push((base_height - y) * factor) 149 - end 150 - end 138 + left.push((base_height - y) * factor) if (orientation == '0,1') && x.zero? 139 + end 151 140 152 - next if top.length != 2 153 - next if right.length != 2 154 - next if bottom.length != 2 155 - next if left.length != 2 141 + next if top.length != 2 142 + next if right.length != 2 143 + next if bottom.length != 2 144 + next if left.length != 2 156 145 157 - execute_cmd "#{imagemagick} -background none PNG32:#{path} -gravity center -extent #{width+2}x#{height+2} PNG32:#{path}" 146 + execute_cmd "#{imagemagick} -background none PNG32:#{path} -gravity center -extent #{width + 2}x#{height + 2} PNG32:#{path}" 158 147 159 - draw_format = "-draw \"line %d,%d %d,%d\"" 160 - top_line = draw_format % [top.min + 1, 0, top.max, 0] 161 - right_line = draw_format % [width + 1, right.min + 1, width + 1, right.max] 162 - bottom_line = draw_format % [bottom.min + 1, height + 1, bottom.max, height + 1] 163 - left_line = draw_format % [0, left.min + 1, 0, left.max] 164 - draws = "#{top_line} #{right_line} #{bottom_line} #{left_line}" 148 + draw_format = '-draw "line %d,%d %d,%d"' 149 + top_line = format(draw_format, top.min + 1, 0, top.max, 0) 150 + right_line = format(draw_format, width + 1, right.min + 1, width + 1, right.max) 151 + bottom_line = format(draw_format, bottom.min + 1, height + 1, bottom.max, height + 1) 152 + left_line = format(draw_format, 0, left.min + 1, 0, left.max) 153 + draws = "#{top_line} #{right_line} #{bottom_line} #{left_line}" 165 154 166 - execute_cmd "#{imagemagick} -background none PNG32:#{path} -fill black -stroke none #{draws} PNG32:#{path}" 167 - end 155 + execute_cmd "#{imagemagick} -background none PNG32:#{path} -fill black -stroke none #{draws} PNG32:#{path}" 156 + end 168 157 end