星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ps2epsi 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/sh
  2. # $Id: ps2epsi 9619 2009-04-07 10:20:02Z ken $
  3. # This definition is changed on install to match the
  4. # executable name set in the makefile
  5. GS_EXECUTABLE=gs
  6. gs="`dirname $0`/$GS_EXECUTABLE"
  7. if test ! -x "$gs"; then
  8. gs="$GS_EXECUTABLE"
  9. fi
  10. GS_EXECUTABLE="$gs"
  11. # try to create a temporary file securely
  12. if test -z "$TMPDIR"; then
  13. TMPDIR=/tmp
  14. fi
  15. if which mktemp >/dev/null 2>/dev/null; then
  16. tmpfile="`mktemp $TMPDIR/ps2epsi.XXXXXX`"
  17. else
  18. tmpdir=$TMPDIR/ps2epsi.$$
  19. (umask 077 && mkdir "$tmpdir")
  20. if test ! -d "$tmpdir"; then
  21. echo "failed: could not create temporary file"
  22. exit 1
  23. fi
  24. tmpfile="$tmpdir"/ps2epsi$$
  25. fi
  26. trap "rm -rf \"$tmpfile\"" 0 1 2 3 7 13 15
  27. export outfile
  28. if [ $# -lt 1 -o $# -gt 2 ]; then
  29. echo "Usage: `basename $0` file.ps [file.epsi]" 1>&2
  30. exit 1
  31. fi
  32. infile=$1;
  33. if [ $# -eq 1 ]
  34. then
  35. case "${infile}" in
  36. *.ps) base=`basename "${infile}" .ps` ;;
  37. *.cps) base=`basename "${infile}" .cps` ;;
  38. *.eps) base=`basename "${infile}" .eps` ;;
  39. *.epsf) base=`basename "${infile}" .epsf` ;;
  40. *) base=`basename "${infile}"` ;;
  41. esac
  42. outfile=${base}.epsi
  43. else
  44. outfile=$2
  45. fi
  46. "$GS_EXECUTABLE" -q -dBATCH -dNOPAUSE -dSAFER -dDELAYSAFER -sDEVICE=bbox -sOutputFile=/dev/null "${infile}" 2>${outfile}
  47. ls -l "${infile}" |
  48. awk 'F==1 {
  49. cd="%%CreationDate: " $6 " " $7 " " $8;
  50. t="%%Title: " $9;
  51. f="%%For:" U " " $3;
  52. c="%%Creator: Ghostscript ps2epsi from " $9;
  53. next;
  54. }
  55. /^%!/ {next;}
  56. /^%%Title:/ {t=$0; next;}
  57. /^%%Creator:/ {c=$0; next;}
  58. /^%%CreationDate:/ {cd=$0; next;}
  59. /^%%For:/ {f=$0; next;}
  60. !/^%/ {
  61. print "/ps2edict 30 dict def";
  62. print "ps2edict begin";
  63. print "/epsititle (" t "\\n) def";
  64. print "/epsicreator (" c "\\n) def";
  65. print "/epsicrdt (" cd "\\n) def";
  66. print "/epsifor (" f "\\n) def";
  67. exit(0);
  68. }
  69. ' U="$USERNAME$LOGNAME" F=1 - F=2 "${infile}" >"$tmpfile"
  70. ls -l "${outfile}" |
  71. awk 'F==1 {
  72. b="%%BoundingBox: 0 0 0 0\\n";
  73. }
  74. /^%%BoundingBox:/ {b=$0; next;}
  75. /^%%HiResBoundingBox:/ {
  76. hb=$0;
  77. print "ps2edict where {pop} {/ps2edict 30 dict def} ifelse";
  78. print "ps2edict begin";
  79. print "/BBoxString (" b "\\n) def";
  80. print "/HiresBBoxString (" hb "\\n) def";
  81. print "end";
  82. exit(0);
  83. }
  84. ' F=1 - F=2 "${outfile}" >>"$tmpfile"
  85. "$GS_EXECUTABLE" -q -dNOPAUSE -dSAFER -dDELAYSAFER -r72 -sDEVICE=bit -sOutputFile=/dev/null "$tmpfile" ps2epsi.ps "$tmpfile" <"${infile}" 1>&2
  86. rm -f "$tmpfile"
  87. rm -rf "$tmpdir"
  88. (
  89. cat << BEGINEPS
  90. save countdictstack mark newpath /showpage {} def /setpagedevice /pop load def
  91. %%EndProlog
  92. %%Page 1 1
  93. BEGINEPS
  94. cat "${infile}" |
  95. LC_ALL=C \
  96. sed -e '/^%%BeginPreview:/,/^%%EndPreview[^!-\~]*$/d' -e '/^%!PS-Adobe/d'\
  97. -e '/^%%[A-Za-z][A-Za-z]*[^!-\~]*$/d' -e '/^%%[A-Za-z][A-Za-z]*: /d'
  98. cat << ENDEPS
  99. %%Trailer
  100. cleartomark countdictstack exch sub { end } repeat restore
  101. %%EOF
  102. ENDEPS
  103. ) >> "${outfile}"
  104. exit 0