mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Length.cpp: add new unit representing \baselineskip
- fileformat change
This commit is contained in:
parent
b3b1cf7e98
commit
b3b7675f54
@ -7,6 +7,10 @@ changes happened in particular if possible. A good example would be
|
||||
|
||||
-----------------------
|
||||
|
||||
2017-04-02 Uwe Stöhr <uwestoehr@web.de>
|
||||
* Format incremented to 539: support for \baselineskip.
|
||||
- new length unit BLS
|
||||
|
||||
2017-04-05 Uwe Stöhr <uwestoehr@web.de>
|
||||
* Format incremented to 538: support for document class option "fleqn"
|
||||
and for length \mathindent.
|
||||
|
@ -2002,6 +2002,67 @@ def revert_mathindent(document):
|
||||
del document.header[i + 1]
|
||||
|
||||
|
||||
def revert_baselineskip(document):
|
||||
" Revert baselineskips to TeX code "
|
||||
i = 0
|
||||
vspaceLine = 0
|
||||
hspaceLine = 0
|
||||
while True:
|
||||
regexp = re.compile(r'^.*baselineskip%.*$')
|
||||
i = find_re(document.body, regexp, i)
|
||||
if i == -1:
|
||||
return
|
||||
vspaceLine = find_token(document.body, "\\begin_inset VSpace", i)
|
||||
if vspaceLine == i:
|
||||
# output VSpace inset as TeX code
|
||||
# first read out the values
|
||||
beg = document.body[i].rfind("VSpace ");
|
||||
end = document.body[i].rfind("baselineskip%");
|
||||
baselineskip = float(document.body[i][beg + 7:end]);
|
||||
# we store the value in percent, thus divide by 100
|
||||
baselineskip = baselineskip/100;
|
||||
baselineskip = str(baselineskip);
|
||||
# check if it is the starred version
|
||||
if document.body[i].find('*') != -1:
|
||||
star = '*'
|
||||
else:
|
||||
star = ''
|
||||
# now output TeX code
|
||||
endInset = find_end_of_inset(document.body, i)
|
||||
if endInset == -1:
|
||||
document.warning("Malformed LyX document: Missing '\\end_inset' of VSpace inset.")
|
||||
return
|
||||
else:
|
||||
document.body[vspaceLine: endInset + 1] = put_cmd_in_ert("\\vspace" + star + '{' + baselineskip + "\\baselineskip}")
|
||||
hspaceLine = find_token(document.body, "\\begin_inset space \\hspace", i - 1)
|
||||
document.warning("hspaceLine: " + str(hspaceLine))
|
||||
document.warning("i: " + str(i))
|
||||
if hspaceLine == i - 1:
|
||||
# output space inset as TeX code
|
||||
# first read out the values
|
||||
beg = document.body[i].rfind("\\length ");
|
||||
end = document.body[i].rfind("baselineskip%");
|
||||
baselineskip = float(document.body[i][beg + 7:end]);
|
||||
document.warning("baselineskip: " + str(baselineskip))
|
||||
# we store the value in percent, thus divide by 100
|
||||
baselineskip = baselineskip/100;
|
||||
baselineskip = str(baselineskip);
|
||||
# check if it is the starred version
|
||||
if document.body[i-1].find('*') != -1:
|
||||
star = '*'
|
||||
else:
|
||||
star = ''
|
||||
# now output TeX code
|
||||
endInset = find_end_of_inset(document.body, i)
|
||||
if endInset == -1:
|
||||
document.warning("Malformed LyX document: Missing '\\end_inset' of space inset.")
|
||||
return
|
||||
else:
|
||||
document.body[hspaceLine: endInset + 1] = put_cmd_in_ert("\\hspace" + star + '{' + baselineskip + "\\baselineskip}")
|
||||
|
||||
i = i + 1
|
||||
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
#
|
||||
@ -2037,10 +2098,12 @@ convert = [
|
||||
[535, [convert_dashligatures]],
|
||||
[536, []],
|
||||
[537, []],
|
||||
[538, [convert_mathindent]]
|
||||
[538, [convert_mathindent]],
|
||||
[539, []]
|
||||
]
|
||||
|
||||
revert = [
|
||||
[538, [revert_baselineskip]],
|
||||
[537, [revert_mathindent]],
|
||||
[536, [revert_xout]],
|
||||
[535, [revert_noto]],
|
||||
|
@ -107,6 +107,9 @@ string const Length::asLatexString() const
|
||||
case PPH:
|
||||
os << formatFPNumber(val_ / 100.0) << "\\paperheight";
|
||||
break;
|
||||
case BLS:
|
||||
os << formatFPNumber(val_ / 100.0) << "\\baselineskip";
|
||||
break;
|
||||
case UNIT_NONE:
|
||||
break;
|
||||
default:
|
||||
@ -147,6 +150,7 @@ string const Length::asHTMLString() const
|
||||
case PCW:
|
||||
case PTH:
|
||||
case PPH:
|
||||
case BLS:
|
||||
// what it's a percentage of probably won't make sense for HTML,
|
||||
// so we'll assume people have chosen these appropriately
|
||||
os << formatFPNumber(val_) << '%';
|
||||
@ -291,6 +295,12 @@ double Length::inInch(double text_width, double em_width) const
|
||||
case Length::PPH:
|
||||
result = val_ * text_width * 2.2 / 100;
|
||||
break;
|
||||
case Length::BLS:
|
||||
// baselineskip is approximately 1.2 times the font size for the cmr fonts
|
||||
// The value actually depends on the current paragraph (see TextMetrics::setRowHeight),
|
||||
// but we do not have this information here.
|
||||
result = val_ * em_width * 1.2 / 100;
|
||||
break;
|
||||
case Length::UNIT_NONE:
|
||||
result = 0; // this cannot happen
|
||||
break;
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
PLW, //< Percent of LineWidth
|
||||
PTH, //< Percent of TextHeight // Herbert 2002-05-16
|
||||
PPH, //< Percent of PaperHeight // Herbert 2002-05-16
|
||||
BLS, //< Percent of BaselineSkip // uwestoehr 2017-04-01
|
||||
UNIT_NONE ///< no unit
|
||||
};
|
||||
|
||||
|
@ -413,6 +413,7 @@ docstring InsetGraphics::toDocbookLength(Length const & len) const
|
||||
case Length::PLW: // Percent of LineWidth
|
||||
case Length::PTH: // Percent of TextHeight
|
||||
case Length::PPH: // Percent of PaperHeight
|
||||
case Length::BLS: // Percent of BaselineSkip
|
||||
// Sigh, this will go wrong.
|
||||
result << len.value() << "%";
|
||||
break;
|
||||
|
@ -32,7 +32,7 @@ char const * const unit_name[] = {
|
||||
"bp", "cc", "cm", "dd", "em", "ex", "in", "mm", "mu",
|
||||
"pc", "pt", "sp",
|
||||
"text%", "col%", "page%", "line%",
|
||||
"theight%", "pheight%", "" };
|
||||
"theight%", "pheight%", "baselineskip%", "" };
|
||||
|
||||
int const num_units = int(sizeof(unit_name) / sizeof(unit_name[0]) - 1);
|
||||
|
||||
@ -42,7 +42,7 @@ char const * const unit_name_gui[] = {
|
||||
N_("ex"), N_("in[[unit of measure]]"), N_("mm"), N_("mu[[unit of measure]]"), N_("pc"),
|
||||
N_("pt"), N_("sp"), N_("Text Width %"),
|
||||
N_("Column Width %"), N_("Page Width %"), N_("Line Width %"),
|
||||
N_("Text Height %"), N_("Page Height %"), "" };
|
||||
N_("Text Height %"), N_("Page Height %"), N_("Line Distance %"), "" };
|
||||
|
||||
|
||||
Length::UNIT unitFromString(string const & data)
|
||||
|
@ -492,6 +492,7 @@ Lines can have a vfill \vfill in the middle.
|
||||
Lines can have a vfill \vspace{\fill} in the middle.
|
||||
Lines can have a protected vfill \vspace*{\fill} in the middle.
|
||||
Lines can have a vertical absolute space \vspace{2cm} in the middle.
|
||||
Lines can have a baselineskip \vspace{1.2\baselineskip} in the middle.
|
||||
Lines can have a vertical relative space \vspace{0.09\columnwidth} in the middle.
|
||||
Lines can have a vertical glue-length space \vspace{2cm minus 2bp plus 1cc} in the middle.
|
||||
Lines can have protected vertical space \vspace*{2cm} in the middle.
|
||||
|
@ -413,6 +413,9 @@ bool translate_len(string const & length, string & valstring, string & unit)
|
||||
} else if (unit == "\\textheight") {
|
||||
valstring = percentval;
|
||||
unit = "theight%" + endlen;
|
||||
} else if (unit == "\\baselineskip") {
|
||||
valstring = percentval;
|
||||
unit = "baselineskip%" + endlen;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -4518,7 +4521,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
// therefore handle them separately
|
||||
if (unit == "\\paperwidth" || unit == "\\columnwidth"
|
||||
|| unit == "\\textwidth" || unit == "\\linewidth"
|
||||
|| unit == "\\textheight" || unit == "\\paperheight")
|
||||
|| unit == "\\textheight" || unit == "\\paperheight"
|
||||
|| unit == "\\baselineskip")
|
||||
known_unit = true;
|
||||
break;
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
|
||||
|
||||
// Do not remove the comment below, so we get merge conflict in
|
||||
// independent branches. Instead add your own.
|
||||
#define LYX_FORMAT_LYX 538 // uwestoehr: support for formula indentation
|
||||
#define LYX_FORMAT_TEX2LYX 538
|
||||
#define LYX_FORMAT_LYX 539 // uwestoehr: support for \baselineskip
|
||||
#define LYX_FORMAT_TEX2LYX 539
|
||||
|
||||
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
||||
#ifndef _MSC_VER
|
||||
|
Loading…
Reference in New Issue
Block a user