This file is indexed.

/usr/share/lyx/scripts/fig2pdftex.py is in lyx-common 2.2.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
# -*- coding: utf-8 -*-

# file fig2pdf.py
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.
#
# \author Angus Leeming
# \author Bo Peng
#
# Full author contact details are available in file CREDITS


# This script converts an XFIG image to something that pdflatex can process
# into high quality PDF.

# Usage:
#   python fig2pdftex.py ${base}.fig ${base}.pdft
# This command generates
#   ${base}.pdf  the converted pdf file
#   ${base}.pdft a tex file that can be included in your latex document
#       using '\input{${base}.pdft}'
#
# Note:
#   Do not use this command as
#     python fig2pdftex.py file.fig file.pdf
#   the real pdf file will be overwritten by a tex file named file.pdf.
#


import os, sys, re


def runCommand(cmd):
    ''' Utility function:
        run a command, quit if fails
    '''
    if os.system(cmd) != 0:
        print "Command '%s' fails." % cmd
        sys.exit(1)


# We expect two args, the names of the input and output files.
if len(sys.argv) != 3:
    sys.exit(1)

input, output = sys.argv[1:]

# Fail silently if the file doesn't exist
if not os.path.isfile(input):
    sys.exit(0)

# Strip the extension from ${output}
outbase = os.path.splitext(output)[0]

# Ascertain whether fig2dev is "modern enough".
# If it is, then the help info will mention "pdftex_t" as one of the
# available outputs.
fout = os.popen('fig2dev -h')
help_msg = fout.read()
fout.close()


if 'pdftex_t' in help_msg:
    # Modern versions of xfig can output the image without "special" text as
    # a PDF file ${base}.pdf and place the text in a LaTeX file
    # ${base}.pdftex_t for typesetting by pdflatex itself.
    runCommand('fig2dev -Lpdftex -p1 %s %s.pdf' % (input, outbase))
    runCommand('fig2dev -Lpdftex_t -p%s %s %s' % (outbase, input, output))
else:
    # Older versions of xfig cannot do this, so we emulate the behaviour using
    # pstex and pstex_t output.
    runCommand('fig2dev -Lpstex %s %s.pstex' % (input, outbase))
    runCommand('fig2dev -Lpstex_t -p %s %s %s' % (outbase, input, output))

    # manipulates the Bounding Box info to enable gs to produce
    # the appropriate PDF file from an EPS one.
    # The generated PostScript commands are extracted from epstopdf, distributed
    # with tetex.
    epsfile = outbase + '.pstex'
    tmp = mkstemp()
    boundingboxline = re.compile('%%BoundingBox:\s+(\d*)\s+(\d*)\s+(\d*)\s+(\d*)')
    for line in open(epsfile).xreadlines():
        if line[:13] == '%%BoundingBox':
            (llx, lly, urx, ury) = map(int, boundingboxline.search(line).groups())
            width = urx - llx
            height = ury - lly
            xoffset = - llx
            yoffset = - lly
            tmp.write('''%%%%BoundingBox: 0 0 %d %d
<< /PageSize  [%d %d] >> setpagedevice
gsave %d %d translate
''' % (width, height, width, height, xoffset, yoffset))
        else:
            tmp.write(line)
    tmp.close()
    # direct move(rename) may fail under windows
    os.unlink(epsfile)
    os.rename(epsfile + '.??', epsfile)

    # Convert the ${pstex} EPS file (free of "special" text) to PDF format
    # using gs
    runCommand('gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile=%s.pdf %s.pstex'\
      % (outbase, outbase))
    os.unlink(epsfile)