howtophil icon

PRS-600 Notepad Drawing To SVG Bash Script

howtophil | PRO | 02/16/22 02:33:25 AM UTC (Edited) | 0 ⭐ | 1835 👁️ | Never ⏰ | []
Bash |

2.71 KB

|

None

|

0 👍

/

0 👎

#!/bin/bash
 
###########################################################################
# This script is for people who have drawings on a Sony PRS-600 and want
# to convert those drawings to SVG for opening in Inkscape, GIMP, etc.
# It may also work with "Notepad" drawings on the PRS-650 etc.
#
# Are there more elegant ways to do this? Yes.
# Do I really care? Well, this works, so I don't care too much.
# I know the first several lines of every drawing note file are
# junk that needs to go, as well as several of the last lines.
# So, I strip those off.
#
# I know xs1: needs to be gone from the file so
# I delete all instances of it.
#
# So far, I end up with a working svg every time.
#
# The use is pretty simple, from a terminal you call the script
# with an input filename of the note drawing you want to convert
# and an optional output name. The script will default to a 
# output of the input filename with ".svg" tacked on the end
# if you don't specify a different name.
#
# ./note2svg.sh [the prs-600 drawing note file] [optione output filename]
#
# Phillip J Rhoades 2022-02-15
###########################################################################
 
#---------------------------------------------
# Setting up some named variables
# and either using the note filename
# as a base for the output filename
# or using one designated by the second
# argument passed to the script
#---------------------------------------------
notefile="$1"
if [ -z "$2" ];
    then
        #echo "Output file undefined. Defaulting to $notefile.svg";
        outfile="$notefile.svg" 
    else
        #echo "Output file is defined as $2";
        outfile="$2"
fi
 
#-------------------------------------------
# pop an xml header into the output first
#-------------------------------------------
echo '<?xml version="1.0" encoding="UTF-8"?>' >"$outfile"
 
#--------------------------------------------------
# Trim and delete stuff that needs to go,
# add back an <svg> that needs to be there, etc
# to make a real SVG file.
# Leave the last </svg> in place
#--------------------------------------------------
# This opens the svg container
echo '<svg width="600" height="710" xml:base="undefined" shape-rendering="optimizeQuality" transform="">' >>"$outfile"
# This gives the SVG a white background
echo '<rect style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" id="rect4418" width="600" height="710" x="0" y="-8.631984e-15" />' >>"$outfile"
# this strips out stuff we don't need
head -n -3 "$notefile" | tail -n +6 |sed 's/xs1\://g' >>"$outfile"
 
# Give the user some feedback
echo "Conversion of $notefile to SVG complete at $outfile"
 

Comments