User Tools

Site Tools


software:inkscape_scripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
software:inkscape_scripts [2016/05/08 01:26] adminsoftware:inkscape_scripts [2016/05/08 01:41] – [make path objects] admin
Line 41: Line 41:
 if [ -d ${INPD}${SFX} ] if [ -d ${INPD}${SFX} ]
 then then
- cd ${INPD}${SFX} || exit 1+  cd ${INPD}${SFX} || exit 1
   rm -f ${SLCT}   rm -f ${SLCT}
- cd ${INPD} +  cd ${INPD} 
- for f in ${INPD}${SLCT} +  for f in ${INPD}${SLCT} 
- do +  do 
- TMP=$(basename $f) +    TMP=$(basename $f) 
- DNM=$(dirname $f) +    DNM=$(dirname $f) 
-   NF=${TMP%.*}_${SFX}${SLCT#"*"+    NF=${TMP%.*}_${SFX}${SLCT#"*"
- echo "Copying ${TMP} to ${NF} and analyzing file..." +    echo "Copying ${TMP} to ${NF} and analyzing file..." 
- cp ${f} "${DNM}/${SFX}/${NF}"+    cp ${f} "${DNM}/${SFX}/${NF}"
  
- # Extract the remaining part after the first occurrence of 'font-style', +    # Extract the remaining part after the first occurrence of 'font-style', 
- # then extract the part between double quotes after 'id=' +    # then extract the part between double quotes after 'id=' 
- idt=$(sed '1,/style=\"font-style/d' "${DNM}/${SFX}/${NF}" | sed -n '/id=/{p;q;}' | sed 's/.*"\(.*\)"[^"]*$/\1/'+    idt=$(sed '1,/style=\"font-style/d' "${DNM}/${SFX}/${NF}" | sed -n '/id=/{p;q;}' | sed 's/.*"\(.*\)"[^"]*$/\1/'
- if [ -n "$idt" ]; then +    if [ -n "$idt" ]; then 
- echo "   First text object ID found: ${idt}" +      echo "   First text object ID found: ${idt}" 
- CMND=" --select=$idt --verb EditSelectSameObjectType --verb ObjectToPath" +      CMND=" --select=$idt --verb EditSelectSameObjectType --verb ObjectToPath" 
- else +    else 
- echo "   Did not found any text object ID at all."  +      echo "   Did not found any text object ID at all."         
- fi+    fi
  
- echo -n "   Scanning for path object IDs" +    echo -n "   Scanning for path object IDs" 
- # Copy the svg file into variable +    # Copy the svg file into variable 
- svg="$(cat ${DNM}/${SFX}/${NF})"+    svg="$(cat ${DNM}/${SFX}/${NF})"
  
- # Strip everything until after the first appearance of '<path' +    # Strip everything until after the first appearance of '<path' 
-  svg="${svg#*<path}" +    svg="${svg#*<path}" 
-  +     
- # As long as the string is not empty, analyse the current 'path' tag. +    # As long as the string is not empty, analyse the current 'path' tag. 
- # When analysed, strip everything until after the first appearance of '<path'+    # When analysed, strip everything until after the first appearance of '<path'
- # If there is no remaining '<path' in the string, then empty the string and +    # If there is no remaining '<path' in the string, then empty the string and 
- # continue processing. +    # continue processing. 
- while [ -n "$svg" ]; do +    while [ -n "$svg" ]; do 
- # $svg starts with <path, then chop off to be shortest /> +      # $svg starts with <path, then chop off to be shortest /> 
- # http://wiki.bash-hackers.org/syntax/pe#substring_removal +      # http://wiki.bash-hackers.org/syntax/pe#substring_removal 
- pid=${svg%%/>*} +      pid=${svg%%/>*} 
- # if the string contains sodipodi and the stroke-dasharray:[0-9] text, then +      # if the string contains sodipodi and the stroke-dasharray:[0-9] text, then 
- # extract the part between double quotes after 'id=' +      # extract the part between double quotes after 'id=' 
- mln=$(echo $pid | grep sodipodi | grep -E "stroke-dasharray:[0-9]" | grep -Po 'id="\K.*?(?=")'+      mln=$(echo $pid | grep sodipodi | grep -E "stroke-dasharray:[0-9]" | grep -Po 'id="\K.*?(?=")'
- if [ -n "$mln" ]; then +      if [ -n "$mln" ]; then 
- CMND="$CMND --select=$mln --verb=StrokeToPath" +        CMND="$CMND --select=$mln --verb=StrokeToPath" 
- echo -n "X" +        echo -n "X" 
- else +      else 
- echo -n "." +        echo -n "." 
- fi +      fi 
-  +       
- # check if $svg still contains '<path', if yes, cut off everything until after the next first <path: +      # check if $svg still contains '<path', if yes, cut off everything until after the next first <path: 
- if [[ $svg == *"<path"* ]]; then +      if [[ $svg == *"<path"* ]]; then 
- svg="${svg#*<path}" +        svg="${svg#*<path}" 
- else +      else 
- svg="" +        svg="" 
- fi +      fi 
- done+    done
  
- if [ -n "$CMND" ]; then +    if [ -n "$CMND" ]; then 
- echo -e -n "\n   Converting to path..." +      echo -e -n "\n   Converting to path..." 
- /usr/bin/inkscape $CMND --verb FileSave --verb FileQuit ${DNM}/${SFX}/${NF} &> /dev/null +      /usr/bin/inkscape $CMND --verb FileSave --verb FileQuit ${DNM}/${SFX}/${NF} &> /dev/null 
- echo " finished." +      echo " finished." 
- else +    else 
- echo -e -n "\n   No path or text ID found, skipping path conversion." +      echo -e -n "\n   No path or text ID found, skipping path conversion." 
- fi +    fi 
- /usr/bin/inkscape -f "${DNM}/${SFX}/${NF}" -A "${DNM}/${SFX}/${NF}".pdf +    /usr/bin/inkscape -f "${DNM}/${SFX}/${NF}" -A "${DNM}/${SFX}/${NF}".pdf 
- FILES="${FILES} ${DNM}/${SFX}/${NF}.pdf" +    FILES="${FILES} ${DNM}/${SFX}/${NF}.pdf" 
- done +  done 
- echo "Merging all pdf files..." +  echo -n "Creating ${INPD}${OUTF}, containing all svg files..." 
- /usr/bin/gs -dBATCH -sPAPERSIZE=a4 -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=${INPD}${OUTF} $FILES +  /usr/bin/gs -dBATCH -sPAPERSIZE=a4 -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=${INPD}${OUTF} $FILES 
- rm $FILES+  rm $FILES 
 +  echo " done."
 else else
- echo -e "Please create a placeholder directory '${SFX}' where\nthe converted files can be stored, then restart script..."+  echo -e "Please create a placeholder directory '${SFX}' where\nthe converted files can be stored, then restart script..."
 fi fi
 </code> </code>
software/inkscape_scripts.txt · Last modified: 2016/05/11 21:47 by admin