lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Removing white space from svg output


From: paul booker
Subject: Removing white space from svg output
Date: Mon, 1 Feb 2016 12:36:28 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

While trying to achieve svg output comparable to png output, I have reached
a workaround which comes close enough for my purposes. Now I have a question
at the other end of this!
I have this in my "defs.ily" file:

#(set-default-paper-size "a6" 'landscape) 
\paper{    
    indent=0\mm  
    top-margin = 0\mm
    right-margin = 0\mm
    left-margin = 0\mm 
    print-page-number = ##f   
    oddFooterMarkup=##f
    oddHeaderMarkup=##f
    bookTitleMarkup = ##f
    scoreTitleMarkup = ##f
}

Essentially minimises anything top and left of the "page". It may be more
than necessary.
I produce the png image (at 300dpi) and svg image, and file them in their
own folders.
>From the parent folder I run this shell script. This uses the pixel size of
the png to set the size of the svg, by changing the svg's width, height and
viewport sizes.

###########################start###########################
#!/bin/sh
# GNU bash, version 4.3.42(4)-release (x86_64-pc-msys)
# Assumes svg in svg folder and png in png folder with the same name for sizing
myfile=filenameNoSuffix
# ImageMagick identifies the size of the png image
well=$(identify -format "%w" png/$myfile.png)
hell=$(identify -format "%h" png/$myfile.png)
#Check that the variables now hold the size in pixels
echo well = $well
echo hell = $hell
# If png is 300dpi, divide sizes by 30 (if 100dpi, divide by 10)
wim=$(awk -v w=$well 'BEGIN { print w / 30 }')
him=$(awk -v h=$hell 'BEGIN { print h / 30 }')
# Again, check the result
echo wim = $wim
echo him = $him
# the 'sed' command replaces a line containing '<svg'  with the line below
# svg is sized in pixels by default so doesn't require units for width and
height
# Viewport also adds 1px to y value, which works for me
sed -i '
/<svg/ c\
\<svg xmlns="http://www.w3.org/2000/svg"; version="1.2" width="'$well'"
height="'$hell'" viewBox="0 1 '$wim' '$him'">
' svg/$myfile.svg
# "read" just keeps the window open to check values
read -p "Done, press ENTER"
##########################finish#########################

This might need tweaking for other shells.
My question is:
Can anyone see this becoming a scheme function which could sit in my
defs.ily file and save this ugly step?
I guess I mean an internal to Lilypond rather than external solution.
I'm not at all familiar with Scheme, but I did peek at "svg-output.scm". I
can't find the equivalent for png output.
Regards
Paul




reply via email to

[Prev in Thread] Current Thread [Next in Thread]