mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-15 07:16:48 +00:00
Fix LaTeX length export of big numbers, part 2 (bug #9416)
LaTeX lengths must not use scientific notation, since the + sign has a different meaning (glue lengths). This is the GUI part of bug 9416, on top of part 1 [59e4d16ab/lyxgit].
This commit is contained in:
parent
2ac45cc4d2
commit
8b86af7298
@ -28,6 +28,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace lyx::support;
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ string const Length::asString() const
|
|||||||
{
|
{
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
if (unit_ != UNIT_NONE)
|
if (unit_ != UNIT_NONE)
|
||||||
os << val_ << unit_name[unit_]; // setw?
|
os << formatFPNumber(val_) << unit_name[unit_]; // setw?
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ docstring const Length::asDocstring() const
|
|||||||
{
|
{
|
||||||
odocstringstream os;
|
odocstringstream os;
|
||||||
if (unit_ != UNIT_NONE)
|
if (unit_ != UNIT_NONE)
|
||||||
os << val_ << unit_name[unit_]; // setw?
|
os << formatFPNumber(val_) << unit_name[unit_]; // setw?
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,27 +87,27 @@ string const Length::asLatexString() const
|
|||||||
// LaTeX (bug 9416)
|
// LaTeX (bug 9416)
|
||||||
switch (unit_) {
|
switch (unit_) {
|
||||||
case PTW:
|
case PTW:
|
||||||
os << support::formatFPNumber(val_ / 100.0) << "\\textwidth";
|
os << formatFPNumber(val_ / 100.0) << "\\textwidth";
|
||||||
break;
|
break;
|
||||||
case PCW:
|
case PCW:
|
||||||
os << support::formatFPNumber(val_ / 100.0) << "\\columnwidth";
|
os << formatFPNumber(val_ / 100.0) << "\\columnwidth";
|
||||||
break;
|
break;
|
||||||
case PPW:
|
case PPW:
|
||||||
os << support::formatFPNumber(val_ / 100.0) << "\\paperwidth";
|
os << formatFPNumber(val_ / 100.0) << "\\paperwidth";
|
||||||
break;
|
break;
|
||||||
case PLW:
|
case PLW:
|
||||||
os << support::formatFPNumber(val_ / 100.0) << "\\linewidth";
|
os << formatFPNumber(val_ / 100.0) << "\\linewidth";
|
||||||
break;
|
break;
|
||||||
case PTH:
|
case PTH:
|
||||||
os << support::formatFPNumber(val_ / 100.0) << "\\textheight";
|
os << formatFPNumber(val_ / 100.0) << "\\textheight";
|
||||||
break;
|
break;
|
||||||
case PPH:
|
case PPH:
|
||||||
os << support::formatFPNumber(val_ / 100.0) << "\\paperheight";
|
os << formatFPNumber(val_ / 100.0) << "\\paperheight";
|
||||||
break;
|
break;
|
||||||
case UNIT_NONE:
|
case UNIT_NONE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
os << support::formatFPNumber(val_) << unit_name[unit_];
|
os << formatFPNumber(val_) << unit_name[unit_];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
@ -121,7 +122,7 @@ string const Length::asHTMLString() const
|
|||||||
case BP:
|
case BP:
|
||||||
case DD:
|
case DD:
|
||||||
// close enough
|
// close enough
|
||||||
os << val_ << "pt";
|
os << formatFPNumber(val_) << "pt";
|
||||||
break;
|
break;
|
||||||
case MM:
|
case MM:
|
||||||
case CM:
|
case CM:
|
||||||
@ -129,13 +130,13 @@ string const Length::asHTMLString() const
|
|||||||
case IN:
|
case IN:
|
||||||
case EX:
|
case EX:
|
||||||
case EM:
|
case EM:
|
||||||
os << val_ << unit_name[unit_];
|
os << formatFPNumber(val_) << unit_name[unit_];
|
||||||
break;
|
break;
|
||||||
case CC:
|
case CC:
|
||||||
os << val_/12.0 << "pt";
|
os << formatFPNumber(val_ / 12.0) << "pt";
|
||||||
break;
|
break;
|
||||||
case MU:
|
case MU:
|
||||||
os << val_/18.0 << "em";
|
os << formatFPNumber(val_ / 18.0) << "em";
|
||||||
break;
|
break;
|
||||||
case PTW:
|
case PTW:
|
||||||
case PPW:
|
case PPW:
|
||||||
@ -145,7 +146,7 @@ string const Length::asHTMLString() const
|
|||||||
case PPH:
|
case PPH:
|
||||||
// what it's a percentage of probably won't make sense for HTML,
|
// what it's a percentage of probably won't make sense for HTML,
|
||||||
// so we'll assume people have chosen these appropriately
|
// so we'll assume people have chosen these appropriately
|
||||||
os << val_ << '%';
|
os << formatFPNumber(val_) << '%';
|
||||||
break;
|
break;
|
||||||
case SP:
|
case SP:
|
||||||
case UNIT_NONE:
|
case UNIT_NONE:
|
||||||
@ -377,7 +378,7 @@ string const GlueLength::asString() const
|
|||||||
|
|
||||||
ostringstream buffer;
|
ostringstream buffer;
|
||||||
|
|
||||||
buffer << len_.value();
|
buffer << formatFPNumber(len_.value());
|
||||||
|
|
||||||
if (plus_.zero() && minus_.zero()) {
|
if (plus_.zero() && minus_.zero()) {
|
||||||
buffer << unit_name[len_.unit()];
|
buffer << unit_name[len_.unit()];
|
||||||
@ -388,7 +389,7 @@ string const GlueLength::asString() const
|
|||||||
if (minus_.zero()) {
|
if (minus_.zero()) {
|
||||||
if (len_.unit() != plus_.unit())
|
if (len_.unit() != plus_.unit())
|
||||||
buffer << unit_name[len_.unit()];
|
buffer << unit_name[len_.unit()];
|
||||||
buffer << '+' << plus_.value();
|
buffer << '+' << formatFPNumber(plus_.value());
|
||||||
buffer << unit_name[plus_.unit()];
|
buffer << unit_name[plus_.unit()];
|
||||||
return buffer.str();
|
return buffer.str();
|
||||||
}
|
}
|
||||||
@ -397,7 +398,7 @@ string const GlueLength::asString() const
|
|||||||
if (plus_.zero()) {
|
if (plus_.zero()) {
|
||||||
if (len_.unit() != minus_.unit())
|
if (len_.unit() != minus_.unit())
|
||||||
buffer << unit_name[len_.unit()];
|
buffer << unit_name[len_.unit()];
|
||||||
buffer << '-' << minus_.value();
|
buffer << '-' << formatFPNumber(minus_.value());
|
||||||
buffer << unit_name[minus_.unit()];
|
buffer << unit_name[minus_.unit()];
|
||||||
return buffer.str();
|
return buffer.str();
|
||||||
}
|
}
|
||||||
@ -408,7 +409,7 @@ string const GlueLength::asString() const
|
|||||||
if (minus_ == plus_) {
|
if (minus_ == plus_) {
|
||||||
if (len_.unit() != minus_.unit())
|
if (len_.unit() != minus_.unit())
|
||||||
buffer << unit_name[len_.unit()];
|
buffer << unit_name[len_.unit()];
|
||||||
buffer << "+-" << minus_.value();
|
buffer << "+-" << formatFPNumber(minus_.value());
|
||||||
buffer << unit_name[minus_.unit()];
|
buffer << unit_name[minus_.unit()];
|
||||||
return buffer.str();
|
return buffer.str();
|
||||||
}
|
}
|
||||||
@ -416,8 +417,8 @@ string const GlueLength::asString() const
|
|||||||
// this is so rare a case, why bother minimising units ?
|
// this is so rare a case, why bother minimising units ?
|
||||||
|
|
||||||
buffer << unit_name[len_.unit()];
|
buffer << unit_name[len_.unit()];
|
||||||
buffer << '+' << plus_.value() << unit_name[plus_.unit()];
|
buffer << '+' << formatFPNumber(plus_.value()) << unit_name[plus_.unit()];
|
||||||
buffer << '-' << minus_.value() << unit_name[minus_.unit()];
|
buffer << '-' << formatFPNumber(minus_.value()) << unit_name[minus_.unit()];
|
||||||
|
|
||||||
return buffer.str();
|
return buffer.str();
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
|||||||
combo->setCurrentItem(len.unit());
|
combo->setCurrentItem(len.unit());
|
||||||
QLocale loc;
|
QLocale loc;
|
||||||
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
||||||
input->setText(loc.toString(Length(len).value()));
|
input->setText(formatLocFPNumber(Length(len).value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +204,15 @@ void doubleToWidget(QLineEdit * input, string const & value, char f, int prec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString formatLocFPNumber(double d)
|
||||||
|
{
|
||||||
|
QString result = toqstr(formatFPNumber(d));
|
||||||
|
QLocale loc;
|
||||||
|
result.replace('.', loc.decimalPoint());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void setValid(QWidget * widget, bool valid)
|
void setValid(QWidget * widget, bool valid)
|
||||||
{
|
{
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
@ -67,6 +67,11 @@ void doubleToWidget(QLineEdit * input, double const & value,
|
|||||||
/// method to set a (localized) double value in a widget (QLineEdit)
|
/// method to set a (localized) double value in a widget (QLineEdit)
|
||||||
void doubleToWidget(QLineEdit * input, std::string const & value,
|
void doubleToWidget(QLineEdit * input, std::string const & value,
|
||||||
char f = 'g', int prec = 6);
|
char f = 'g', int prec = 6);
|
||||||
|
/**
|
||||||
|
* method to format localized floating point numbers without
|
||||||
|
* ever using scientific notation
|
||||||
|
*/
|
||||||
|
QString formatLocFPNumber(double d);
|
||||||
|
|
||||||
/// colors a widget red if invalid
|
/// colors a widget red if invalid
|
||||||
void setValid(QWidget * widget, bool valid);
|
void setValid(QWidget * widget, bool valid);
|
||||||
|
Loading…
Reference in New Issue
Block a user