From 6b970c0339e948c6091acda56e83b9a450699966 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Sun, 19 Jul 2009 22:08:58 +0000 Subject: [PATCH] GuiDocument.cpp: allow to use percent lengths for the paragraph skip separation; file format change git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30696 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 4 ++ lib/lyx2lyx/lyx_2_0.py | 61 ++++++++++++++++++++++++++----- src/Buffer.cpp | 2 +- src/frontends/qt4/GuiDocument.cpp | 2 - 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index ece447fbcf..ab57e82937 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,10 @@ LyX file-format changes ----------------------- +2009-07-20 Uwe Stöhr + * Format incremented to 366: allow to use percent lengths for the + paragraph skip separation. + 2009-07-19 Uwe Stöhr * Format incremented to 365: support for paragraph indentation. diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 4f6d7478de..a72f9bc158 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -184,39 +184,39 @@ def latex_length(string): percent = True value = string[:i] value = str(float(value)/100) - return value + "\\textwidth" + return "True," + value + "\\textwidth" i = string.find("col%") if i > -1: percent = True value = string[:i] value = str(float(value)/100) - return value + "\\columnwidth" + return "True," + value + "\\columnwidth" i = string.find("page%") if i > -1: percent = True value = string[:i] value = str(float(value)/100) - return value + "\\paperwidth" + return "True," + value + "\\paperwidth" i = string.find("line%") if i > -1: percent = True value = string[:i] value = str(float(value)/100) - return value + "\\linewidth" + return "True," + value + "\\linewidth" i = string.find("theight%") if i > -1: percent = True value = string[:i] value = str(float(value)/100) - return value + "\\textheight" + return "True," + value + "\\textheight" i = string.find("pheight%") if i > -1: percent = True value = string[:i] value = str(float(value)/100) - return value + "\\paperheight" + return "True," + value + "\\paperheight" if percent == False: - return string + return "False," + string #################################################################### @@ -808,6 +808,7 @@ def revert_paragraph_indentation(document): " Revert custom paragraph indentation to preamble code " i = 0 j = 0 + k = 0 while True: i = find_token(document.header, "\\paragraph_indentation", i) if i == -1: @@ -823,13 +824,51 @@ def revert_paragraph_indentation(document): j = document.header[i].find(" ") length = document.header[i][j+1:] # handle percent lengths - length = latex_length(length) + length = latex_length(length) + # latex_length returns "bool,length" + k = length.find(",") + length = length[k+1:] add_to_preamble(document, ["% this command was inserted by lyx2lyx"]) add_to_preamble(document, ["\\setlength{\\parindent}{" + length + "}"]) del document.header[i] i = i + 1 +def revert_percent_skip_lengths(document): + " Revert relative lengths for paragraph skip separation to preamble code " + i = 0 + j = 0 + k = 0 + l = 0 + while True: + i = find_token(document.header, "\\defskip", i) + if i == -1: + break + # only revert when a custom length was set and when + # it used a percent length + j = document.header[i].find("smallskip") + k = document.header[i].find("medskip") + l = document.header[i].find("bigskip") + if (j > -1) or (k > -1) or (l > -1): + break + else: + # search for the beginning of the value via the space + j = document.header[i].find(" ") + length = document.header[i][j+1:] + # handle percent lengths + length = latex_length(length) + # latex_length returns "bool,length" + l = length.find(",") + percent = length[:l] + length = length[l+1:] + if percent == "True": + add_to_preamble(document, ["% this command was inserted by lyx2lyx"]) + add_to_preamble(document, ["\\setlength{\\parskip}{" + length + "}"]) + # set defskip to medskip as default + document.header[i] = "\\defskip medskip" + i = i + 1 + + ## # Conversion hub # @@ -854,10 +893,12 @@ convert = [[346, []], [362, []], [363, []], [364, []], - [365, []] + [365, []], + [366, []] ] -revert = [[364, [revert_paragraph_indentation]], +revert = [[365, [revert_percent_skip_lengths]], + [364, [revert_paragraph_indentation]], [363, [revert_branch_filename]], [362, [revert_longtable_align]], [361, [revert_applemac]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index dfc32f3950..7bf4ac30e3 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -127,7 +127,7 @@ namespace { // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 365; // uwestoehr: support for custom paragraph indentation +int const LYX_FORMAT = 366; // uwestoehr: percent lengths for the paragraph skip separation typedef map DepClean; typedef map > RefCache; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 6286db3d99..8c068a371c 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -613,8 +613,6 @@ GuiDocument::GuiDocument(GuiView & lv) textLayoutModule->skipCO->addItem(qt_("MedSkip")); textLayoutModule->skipCO->addItem(qt_("BigSkip")); textLayoutModule->skipCO->addItem(qt_("Length")); - // remove the %-items from the unit choice - textLayoutModule->skipLengthCO->noPercents(); textLayoutModule->lspacingCO->insertItem( Spacing::Single, qt_("Single")); textLayoutModule->lspacingCO->insertItem( -- 2.39.2