13/04/2013 14:00, Uwe Stöhr:
That does not cure the problem. Attached is the updated patch.
The problem is that LyX requires a length. Length() stores
Length::UNIT_NONE
but this is translated during the reading of the buffer to the default
unit and this is "pt". As an empty value was stored "0" is used.
This is by design but as I said "0pt" is a valid length and not
comparable to no length. In case that no length is given, it is
automatically calculated by LaTeX so that the box has the minimal width
necessary for its content.

Here is a patch that should help in this respect. It maps empty length to the empty string.

Does it help?

JMarc



>From f5f11e3f417fa9e64d8a88b3f1903e9f696d71d2 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Mon, 15 Apr 2013 12:35:11 +0200
Subject: [PATCH] Improve support for empty lengths

Parse empty string as empty length
Output empty length as empty string when it makes sense (not for LaTeX strings, for example).
---
 src/Length.cpp       |   13 +++++++++++--
 src/lengthcommon.cpp |   10 ++++++++--
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/Length.cpp b/src/Length.cpp
index f8eb920..bb9ec6a 100644
--- a/src/Length.cpp
+++ b/src/Length.cpp
@@ -19,6 +19,7 @@
 #include "LyXRC.h"
 
 #include "support/docstream.h"
+#include "support/lassert.h"
 
 #include <sstream>
 #include <iomanip>
@@ -67,7 +68,8 @@ void Length::swap(Length & rhs)
 string const Length::asString() const
 {
 	ostringstream os;
-	os << val_ << unit_name[unit_]; // setw?
+	if (unit_ != UNIT_NONE)
+		os << val_ << unit_name[unit_]; // setw?
 	return os.str();
 }
 
@@ -75,7 +77,8 @@ string const Length::asString() const
 docstring const Length::asDocstring() const
 {
 	odocstringstream os;
-	os << val_ << unit_name[unit_]; // setw?
+	if (unit_ != UNIT_NONE)
+		os << val_ << unit_name[unit_]; // setw?
 	return os.str();
 }
 
@@ -102,6 +105,9 @@ string const Length::asLatexString() const
 	case PPH:
 		os << val_ / 100.0 << "\\paperheight";
 		break;
+	case UNIT_NONE:
+		// One should not try to ouput latex code for an empty length
+		LASSERT(false, break);
 	default:
 		os << val_ << unit_name[unit_];
 	  break;
@@ -363,6 +369,9 @@ GlueLength::GlueLength(string const & data)
 
 string const GlueLength::asString() const
 {
+	if (len_.empty())
+		return string();
+
 	ostringstream buffer;
 
 	buffer << len_.value();
diff --git a/src/lengthcommon.cpp b/src/lengthcommon.cpp
index 217c22b..72f5bbf 100644
--- a/src/lengthcommon.cpp
+++ b/src/lengthcommon.cpp
@@ -236,8 +236,11 @@ bool isValidGlueLength(string const & data, GlueLength * result)
 	// forward approach leads to very long, tedious code that would be
 	// much harder to understand and maintain. (AS)
 
-	if (data.empty())
+	if (data.empty()) {
+		if (result)
+			*result = GlueLength();
 		return true;
+	}
 	string buffer = ltrim(data);
 
 	// To make isValidGlueLength recognize negative values as
@@ -306,8 +309,11 @@ bool isValidLength(string const & data, Length * result)
 	// The parser may seem overkill for lengths without
 	// glue, but since we already have it, using it is
 	// easier than writing something from scratch.
-	if (data.empty())
+	if (data.empty()) {
+		if (result)
+			*result = Length();
 		return true;
+	}
 
 	string   buffer = data;
 	int      pattern_index = 0;
-- 
1.7.0.4

Reply via email to