Fine tune image generation

This commit is contained in:
Georg Baum 2012-12-31 17:17:45 +01:00
parent 9c33bddffa
commit a98f7ad02d
2 changed files with 63 additions and 12 deletions

View File

@ -41,7 +41,8 @@ def getlist(lyxexe, lyxfile):
regexp = re.compile(r'.*: read symbol \'(\S+)\s+inset:\s+(\S+)') regexp = re.compile(r'.*: read symbol \'(\S+)\s+inset:\s+(\S+)')
# These insets are more complex than simply symbols, so the images need to # These insets are more complex than simply symbols, so the images need to
# be created manually # be created manually
skipinsets = ['big', 'font', 'matrix', 'mbox', 'oldfont', 'ref', 'space'] skipinsets = ['big', 'font', 'lyxblacktext', 'matrix', 'mbox', 'oldfont', \
'ref', 'split', 'space', 'style']
symbols = [] symbols = []
for line in stderr.split('\n'): for line in stderr.split('\n'):
m = regexp.match(line) m = regexp.match(line)
@ -52,17 +53,33 @@ def getlist(lyxexe, lyxfile):
return symbols return symbols
def createimage(name, path, template, lyxexe, tempdir): def getreplacements(filename):
replacements = {}
replacements['|'] = 'vert'
replacements['/'] = 'slash'
replacements['\\'] = 'backslash'
replacements['*'] = 'ast'
replacements['AA'] = 'textrm_AA'
replacements['O'] = 'textrm_O'
cppfile = open(filename, 'rt')
regexp = re.compile(r'.*"([^"]+)",\s*"([^"]+)"')
found = False
for line in cppfile.readlines():
if found:
m = regexp.match(line)
if m:
replacements[m.group(1)] = m.group(2)
else:
return replacements
elif line.find('PngMap sorted_png_map') == 0:
found = True
def createimage(name, path, template, lyxexe, tempdir, replacements):
""" Create the image file for symbol name in path. """ """ Create the image file for symbol name in path. """
if name == '|': if name in replacements.keys():
filename = 'vert' filename = replacements[name]
elif name == '/':
filename = 'slash'
elif name == '\\':
filename = 'backslash'
elif name == '*':
filename = 'ast'
elif name.startswith('lyx'): elif name.startswith('lyx'):
print 'Skipping ' + name print 'Skipping ' + name
return return
@ -121,13 +138,15 @@ def main(argv):
if len(argv) == 3: if len(argv) == 3:
(base, ext) = os.path.splitext(argv[0]) (base, ext) = os.path.splitext(argv[0])
symbols = getlist(argv[1], base) symbols = getlist(argv[1], base)
cppfile = os.path.join(os.path.dirname(base), '../../src/frontends/qt4/GuiApplication.cpp')
replacements = getreplacements(cppfile)
lyxtemplate = base + '.lyx' lyxtemplate = base + '.lyx'
templatefile = open(base + '.lyx', 'rt') templatefile = open(base + '.lyx', 'rt')
template = templatefile.read() template = templatefile.read()
templatefile.close() templatefile.close()
tempdir = tempfile.mkdtemp() tempdir = tempfile.mkdtemp()
for i in symbols: for i in symbols:
createimage(i, argv[2], template, argv[1], tempdir) createimage(i, argv[2], template, argv[1], tempdir, replacements)
shutil.rmtree(tempdir) shutil.rmtree(tempdir)
else: else:
error(usage(argv[0])) error(usage(argv[0]))

View File

@ -234,18 +234,33 @@ private:
// this must be sorted alphabetically // this must be sorted alphabetically
// Upper case comes before lower case // Upper case comes before lower case
// Please don't change the formatting, this list is parsed by
// development/tools/generate_symbols_images.py.
PngMap sorted_png_map[] = { PngMap sorted_png_map[] = {
{ "Arrownot", "arrownot2"}, { "Arrownot", "arrownot2"},
{ "Arrowvert", "arrowvert2"},
{ "Bowtie", "bowtie2" },
{ "Box", "box2" },
{ "Bumpeq", "bumpeq2" }, { "Bumpeq", "bumpeq2" },
{ "Cap", "cap2" }, { "Cap", "cap2" },
{ "Circle", "circle2" },
{ "Colonapprox", "colonapprox2" },
{ "Coloneq", "coloneq2" },
{ "Coloneqq", "coloneqq2" },
{ "Colonsim", "colonsim2" },
{ "Cup", "cup2" }, { "Cup", "cup2" },
{ "Delta", "delta2" }, { "Delta", "delta2" },
{ "Diamond", "diamond2" }, { "Diamond", "diamond2" },
{ "Doteq", "doteq2" },
{ "Downarrow", "downarrow2" }, { "Downarrow", "downarrow2" },
{ "Eqcolon", "eqcolon2" },
{ "Eqqcolon", "eqqcolon2" },
{ "Gamma", "gamma2" }, { "Gamma", "gamma2" },
{ "LHD", "lhd2" },
{ "Lambda", "lambda2" }, { "Lambda", "lambda2" },
{ "Lbag", "lbag2"}, { "Lbag", "lbag2"},
{ "Leftarrow", "leftarrow2" }, { "Leftarrow", "leftarrow2" },
{ "Leftcircle", "leftcircle2" },
{ "Leftrightarrow", "leftrightarrow2" }, { "Leftrightarrow", "leftrightarrow2" },
{ "Longarrownot", "longarrownot2"}, { "Longarrownot", "longarrownot2"},
{ "Longleftarrow", "longleftarrow2" }, { "Longleftarrow", "longleftarrow2" },
@ -261,12 +276,16 @@ PngMap sorted_png_map[] = {
{ "Phi", "phi2" }, { "Phi", "phi2" },
{ "Pi", "pi2" }, { "Pi", "pi2" },
{ "Psi", "psi2" }, { "Psi", "psi2" },
{ "RHD", "rhd2" },
{ "Rbag", "rbag2"}, { "Rbag", "rbag2"},
{ "Rightarrow", "rightarrow2" }, { "Rightarrow", "rightarrow2" },
{ "Rightcircle", "rightcircle2" },
{ "Sigma", "sigma2" }, { "Sigma", "sigma2" },
{ "Square", "square2" },
{ "Subset", "subset2" }, { "Subset", "subset2" },
{ "Supset", "supset2" }, { "Supset", "supset2" },
{ "Theta", "theta2" }, { "Theta", "theta2" },
{ "Thorn", "thorn2" },
{ "Uparrow", "uparrow2" }, { "Uparrow", "uparrow2" },
{ "Updownarrow", "updownarrow2" }, { "Updownarrow", "updownarrow2" },
{ "Upsilon", "upsilon2" }, { "Upsilon", "upsilon2" },
@ -277,12 +296,25 @@ PngMap sorted_png_map[] = {
{ "nLeftrightarrow", "nleftrightarrow2" }, { "nLeftrightarrow", "nleftrightarrow2" },
{ "nRightarrow", "nrightarrow2" }, { "nRightarrow", "nrightarrow2" },
{ "nVDash", "nvdash3" }, { "nVDash", "nvdash3" },
{ "nVdash", "nvdash4" },
{ "nvDash", "nvdash2" }, { "nvDash", "nvdash2" },
{ "textrm \\AA", "textrm_AA"}, { "textrm \\AA", "textrm_AA"},
{ "textrm \\O", "textrm_O"}, { "textrm \\O", "textrm_O"},
{ "vDash", "vdash2" } { "vDash", "vdash2" },
{ "varDelta", "vardelta2" },
{ "varGamma", "vargamma2" },
{ "varLambda", "varlambda2" },
{ "varOmega", "varomega2" },
{ "varPhi", "varphi2" },
{ "varPi", "varpi2" },
{ "varPsi", "varpsi2" },
{ "varSigma", "varsigma2" },
{ "varTheta", "vartheta2" },
{ "varUpsilon", "varupsilon2" },
{ "varXi", "varxi2" }
}; };
size_t const nr_sorted_png_map = sizeof(sorted_png_map) / sizeof(PngMap); size_t const nr_sorted_png_map = sizeof(sorted_png_map) / sizeof(PngMap);