Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# file unciodesymbols.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
|
|
|
# author Georg Baum
|
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS
|
|
|
|
|
|
|
|
# This script reads a unicode symbol file and completes it in the given range
|
|
|
|
|
|
|
|
|
|
|
|
import os, re, string, sys, unicodedata
|
|
|
|
|
|
|
|
def usage(prog_name):
|
|
|
|
return ("Usage: %s start stop inputfile outputfile\n" % prog_name +
|
|
|
|
"or %s start stop <inputfile >outputfile" % prog_name)
|
|
|
|
|
|
|
|
|
|
|
|
def error(message):
|
|
|
|
sys.stderr.write(message + '\n')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def trim_eol(line):
|
|
|
|
" Remove end of line char(s)."
|
|
|
|
if line[-2:-1] == '\r':
|
|
|
|
return line[:-2]
|
|
|
|
elif line[-1:] == '\r' or line[-1:] == '\n':
|
|
|
|
return line[:-1]
|
|
|
|
else:
|
|
|
|
# file with no EOL in last line
|
|
|
|
return line
|
|
|
|
|
|
|
|
|
|
|
|
def read(input):
|
|
|
|
" Read input file and strip lineendings."
|
|
|
|
lines = list()
|
|
|
|
while 1:
|
|
|
|
line = input.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
line = trim_eol(line)
|
|
|
|
tokens = line.split()
|
|
|
|
char = -1
|
|
|
|
if len(tokens) > 0:
|
|
|
|
if tokens[0][0:2] == "0x":
|
|
|
|
char = int(tokens[0][2:], 16)
|
|
|
|
elif tokens[0][0:3] == "#0x":
|
|
|
|
char = int(tokens[0][3:], 16)
|
|
|
|
lines.append([char, line])
|
|
|
|
return lines
|
|
|
|
|
|
|
|
|
|
|
|
def write(output, lines):
|
|
|
|
" Write output file with native lineendings."
|
|
|
|
for line in lines:
|
|
|
|
output.write(line[1] + os.linesep)
|
|
|
|
|
|
|
|
|
|
|
|
def complete(lines, start, stop):
|
|
|
|
l = 0
|
|
|
|
for i in range(start, stop):
|
|
|
|
# This catches both comments (lines[l][0] == -1) and code points less than i
|
|
|
|
while l < len(lines) and lines[l][0] < i:
|
2007-02-13 19:55:56 +00:00
|
|
|
# print lines[l]
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
l = l + 1
|
|
|
|
continue
|
|
|
|
if l >= len(lines) or lines[l][0] != i:
|
|
|
|
c = unichr(i)
|
|
|
|
name = unicodedata.name(c, "")
|
|
|
|
if name != "":
|
|
|
|
if unicodedata.combining(c):
|
|
|
|
combining = "combining"
|
|
|
|
else:
|
|
|
|
combining = ""
|
2008-06-02 01:35:42 +00:00
|
|
|
line = [i, '#0x%04x "" "" "%s" "" "" # %s' % (i, combining, name)]
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
lines.insert(l, line)
|
2007-02-13 19:55:56 +00:00
|
|
|
# print lines[l]
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
l = l + 1
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
|
|
|
|
# Open files
|
|
|
|
if len(argv) == 3:
|
|
|
|
input = sys.stdin
|
|
|
|
output = sys.stdout
|
|
|
|
elif len(argv) == 5:
|
|
|
|
input = open(argv[3], 'rb')
|
|
|
|
output = open(argv[4], 'wb')
|
|
|
|
else:
|
|
|
|
error(usage(argv[0]))
|
|
|
|
if argv[1][:2] == "0x":
|
|
|
|
start = int(argv[1][2:], 16)
|
|
|
|
else:
|
|
|
|
start = int(argv[1])
|
|
|
|
if argv[2][:2] == "0x":
|
|
|
|
stop = int(argv[2][2:], 16)
|
|
|
|
else:
|
|
|
|
stop = int(argv[2])
|
|
|
|
|
|
|
|
# Do the real work
|
|
|
|
lines = read(input)
|
|
|
|
complete(lines, start, stop)
|
|
|
|
write(output, lines)
|
|
|
|
|
|
|
|
# Close files
|
|
|
|
if len(argv) == 3:
|
|
|
|
input.close()
|
|
|
|
output.close()
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv)
|