From 6bf6c8453d05105af9b49e29eacd0d20076872d6 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 16 Feb 2007 18:29:48 +0000 Subject: [PATCH] add pure ASCII encoding for LaTeX export git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17224 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 4 ++++ lib/encodings | 4 ++++ lib/lyx2lyx/LyX.py | 2 +- lib/lyx2lyx/lyx_1_5.py | 18 ++++++++++++++++-- src/buffer.C | 2 +- src/bufferparams.C | 3 ++- src/encoding.C | 3 +++ src/output_latex.C | 1 + 8 files changed, 32 insertions(+), 5 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 4949e868cc..6c13a96444 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,10 @@ LyX file-format changes -----------------------§ +2007-02-16 Georg Baum + + * format incremented to 260: Allow ascii \inputencoding + 2007-02-14 Georg Baum * format incremented to 261: \output_changes is now considered diff --git a/lib/encodings b/lib/encodings index db90f31121..1c60fc7ece 100644 --- a/lib/encodings +++ b/lib/encodings @@ -114,3 +114,7 @@ End Encoding pt254 pt254 PT254 End + +# Pure 7bit ASCII encoding (partially hardcoded in LyX) +Encoding ascii ascii ascii +End diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 1b1ba26ed1..306b736be5 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -74,7 +74,7 @@ format_relation = [("0_06", [200], generate_minor_versions("0.6" , 4)), ("1_2", [220], generate_minor_versions("1.2" , 4)), ("1_3", [221], generate_minor_versions("1.3" , 7)), ("1_4", range(222,246), generate_minor_versions("1.4" , 3)), - ("1_5", range(246,262), generate_minor_versions("1.5" , 0))] + ("1_5", range(246,263), generate_minor_versions("1.5" , 0))] def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_5.py b/lib/lyx2lyx/lyx_1_5.py index e6120b929f..48150cd767 100644 --- a/lib/lyx2lyx/lyx_1_5.py +++ b/lib/lyx2lyx/lyx_1_5.py @@ -1210,6 +1210,18 @@ def convert_changes(document): document.header[j] = "\\output_changes false" +def revert_ascii(document): + " Set ascii encoding to auto. " + i = find_token(document.header, "\\inputencoding", 0) + if i == -1: + document.header.append("\\inputencoding auto") + else: + inputenc = get_value(document.header, "\\inputencoding", i) + if inputenc == "ascii": + document.header[i] = "\\inputencoding auto" + document.inputencoding = get_value(document.header, "\\inputencoding", 0) + + ## # Conversion hub # @@ -1230,9 +1242,11 @@ convert = [[246, []], [258, [convert_lyxline]], [259, [convert_accent, normalize_font_whitespace]], [260, []], - [261, [convert_changes]]] + [261, [convert_changes]], + [262, []]] -revert = [[260, []], +revert = [[261, [revert_ascii]], + [260, []], [259, [revert_utf8x]], [258, []], [257, []], diff --git a/src/buffer.C b/src/buffer.C index ed2075a07d..11a3df0cc7 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -141,7 +141,7 @@ using std::string; namespace { -int const LYX_FORMAT = 261; +int const LYX_FORMAT = 262; } // namespace anon diff --git a/src/bufferparams.C b/src/bufferparams.C index 03d3758a83..d7e58ef4d7 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -876,7 +876,8 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, os << "]{inputenc}\n"; texrow.newline(); } - } else if (inputenc != "default" && inputenc != "tis620-0") { + } else if (inputenc != "default" && inputenc != "tis620-0" && + inputenc != "ascii") { os << "\\usepackage[" << from_ascii(inputenc) << "]{inputenc}\n"; texrow.newline(); diff --git a/src/encoding.C b/src/encoding.C index 985f5bb98a..0c0e678d47 100644 --- a/src/encoding.C +++ b/src/encoding.C @@ -211,6 +211,9 @@ CharInfoMap unicodesymbols; Encoding::Encoding(string const & n, string const & l, string const & i) : Name_(n), LatexName_(l), iconvName_(i) { + if (n == "ascii") + // ASCII can encode 128 code points and nothing else + start_encodable_ = 128; if (n == "utf8" || n == "utf8x") // UTF8 can encode all 1<<20 + 1<<16 UCS4 code points start_encodable_ = 0x110000; diff --git a/src/output_latex.C b/src/output_latex.C index 51843b7019..fa96ec758b 100644 --- a/src/output_latex.C +++ b/src/output_latex.C @@ -592,6 +592,7 @@ int switchEncoding(odocstream & os, BufferParams const & bparams, // only, but it is the best we can do. if ((bparams.inputenc == "auto" || bparams.inputenc == "default") && oldEnc.name() != newEnc.name() && + oldEnc.name() != "ascii" && newEnc.name() != "ascii" && oldEnc.name() != "tis620-0" && newEnc.name() != "tis620-0") { lyxerr[Debug::LATEX] << "Changing LaTeX encoding from " << oldEnc.name() << " to "