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
software:inkscape_scripts [2016/05/08 01:26] adminsoftware:inkscape_scripts [2016/05/11 21:47] (current) 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}" +    # grep $svg first to prevent the subsequent substring removal to freeze 
-  +    # in case of embedded images in svg files. 
- # As long as the string is not empty, analyse the current 'path' tag. +    svg=$(echo $svg | grep -oP '<path.*') 
- # When analysed, strip everything until after the first appearance of '<path'+    svg="${svg#*<path}" 
- # If there is no remaining '<path' in the string, then empty the string and +     
- # continue processing. +    # As long as the string is not empty, analyse the current 'path' tag. 
- while [ -n "$svg" ]; do +    # When analysed, strip everything until after the first appearance of '<path'
- # $svg starts with <path, then chop off to be shortest /> +    # If there is no remaining '<path' in the string, then empty the string and 
- # http://wiki.bash-hackers.org/syntax/pe#substring_removal +    # continue processing. 
- pid=${svg%%/>*} +    while [ -n "$svg" ]; do 
- # if the string contains sodipodi and the stroke-dasharray:[0-9] text, then +      # $svg starts with <path, then chop off to be shortest /> 
- # extract the part between double quotes after 'id=' +      # http://wiki.bash-hackers.org/syntax/pe#substring_removal 
- mln=$(echo $pid | grep sodipodi | grep -E "stroke-dasharray:[0-9]" | grep -Po 'id="\K.*?(?=")'+      pid=${svg%%/>*} 
- if [ -n "$mln" ]; then +      # if the string contains sodipodi and the stroke-dasharray:[0-9] text, then 
- CMND="$CMND --select=$mln --verb=StrokeToPath" +      # extract the part between double quotes after 'id=' 
- echo -n "X" +      mln=$(echo $pid | grep sodipodi | grep -E "stroke-dasharray:[0-9]" | grep -Po 'id="\K.*?(?=")'
- else +      if [ -n "$mln" ]; then 
- echo -n "." +        CMND="$CMND --select=$mln --verb=StrokeToPath" 
- fi +        echo -n "X" 
-  +      else 
- # check if $svg still contains '<path', if yes, cut off everything until after the next first <path: +        echo -n "." 
- if [[ $svg == *"<path"* ]]; then +      fi 
- svg="${svg#*<path}" +       
- else +      # check if $svg still contains '<path', if yes, cut off everything until after the next first <path: 
- svg="" +      if [[ $svg == *"<path"* ]]; then 
- fi +        # Strip everything until after the first appearance of '<path': 
- done+        # grep $svg first to prevent the subsequent substring removal to freeze 
 +        # in case of embedded images in svg files. 
 +        svg=$(echo $svg | grep -oP '<path.*'
 +        svg="${svg#*<path}" 
 +      else 
 +        svg="" 
 +      fi 
 +    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.1462663582.txt.gz · Last modified: 2016/05/08 01:26 by admin