Advertisement
howtophil

PRS-600 Notepad Drawing To SVG Bash Script

Feb 15th, 2022 (edited)
1,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.71 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ###########################################################################
  4. # This script is for people who have drawings on a Sony PRS-600 and want
  5. # to convert those drawings to SVG for opening in Inkscape, GIMP, etc.
  6. # It may also work with "Notepad" drawings on the PRS-650 etc.
  7. #
  8. # Are there more elegant ways to do this? Yes.
  9. # Do I really care? Well, this works, so I don't care too much.
  10. # I know the first several lines of every drawing note file are
  11. # junk that needs to go, as well as several of the last lines.
  12. # So, I strip those off.
  13. #
  14. # I know xs1: needs to be gone from the file so
  15. # I delete all instances of it.
  16. #
  17. # So far, I end up with a working svg every time.
  18. #
  19. # The use is pretty simple, from a terminal you call the script
  20. # with an input filename of the note drawing you want to convert
  21. # and an optional output name. The script will default to a
  22. # output of the input filename with ".svg" tacked on the end
  23. # if you don't specify a different name.
  24. #
  25. # ./note2svg.sh [the prs-600 drawing note file] [optione output filename]
  26. #
  27. # Phillip J Rhoades 2022-02-15
  28. ###########################################################################
  29.  
  30. #---------------------------------------------
  31. # Setting up some named variables
  32. # and either using the note filename
  33. # as a base for the output filename
  34. # or using one designated by the second
  35. # argument passed to the script
  36. #---------------------------------------------
  37. notefile="$1"
  38. if [ -z "$2" ];
  39.     then
  40.         #echo "Output file undefined. Defaulting to $notefile.svg";
  41.         outfile="$notefile.svg"
  42.     else
  43.         #echo "Output file is defined as $2";
  44.         outfile="$2"
  45. fi
  46.  
  47. #-------------------------------------------
  48. # pop an xml header into the output first
  49. #-------------------------------------------
  50. echo '<?xml version="1.0" encoding="UTF-8"?>' >"$outfile"
  51.  
  52. #--------------------------------------------------
  53. # Trim and delete stuff that needs to go,
  54. # add back an <svg> that needs to be there, etc
  55. # to make a real SVG file.
  56. # Leave the last </svg> in place
  57. #--------------------------------------------------
  58. # This opens the svg container
  59. echo '<svg width="600" height="710" xml:base="undefined" shape-rendering="optimizeQuality" transform="">' >>"$outfile"
  60. # This gives the SVG a white background
  61. 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"
  62. # this strips out stuff we don't need
  63. head -n -3 "$notefile" | tail -n +6 |sed 's/xs1\://g' >>"$outfile"
  64.  
  65. # Give the user some feedback
  66. echo "Conversion of $notefile to SVG complete at $outfile"
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement