Am 25.07.2010 05:57, schrieb Uwe Stöhr:

In my patch I failed to look in Length.cpp what is the current fontsize. Calling
bv.buffer().params().fontsize doesn't work. Can you please help me here? All 
other things work as
they should.

There was also a bug in the lyx2lyx routine. Better patch attached.

regards Uwe
Index: lib/lyx2lyx/lyx_2_0.py
===================================================================
--- lib/lyx2lyx/lyx_2_0.py	(revision 35011)
+++ lib/lyx2lyx/lyx_2_0.py	(working copy)
@@ -2057,6 +2057,48 @@
       i += 1
 
 
+def revert_baselineskip(document):
+    " Revert baselineskips to corresponding value in pt "
+    i = 0
+    end = len(document.body) - 1
+    star = ''
+    quote = ''
+    p = find_token(document.header, '\\paperfontsize', 0)
+    if p != -1:
+      if document.header[p].find("default") != -1:
+        fontsize = "10"
+      else:
+        r = document.header[p].rfind(" ")
+        fontsize = document.header[p][r:]
+    while True:
+      k = document.body[i].find("baselineskip%")
+      if k != -1:
+        # check if there is a star
+        if document.body[i].rfind("*") != -1:
+          star = "*"
+        # check if there is a "
+        if document.body[i].rfind('"') != -1:
+          quote = '"'
+        # find the last space
+        j = document.body[i].rfind(" ")
+        value = document.body[i][j:]
+        # we now have 'xyyybaselineskip%zx'
+        m = value.rfind("b")
+        value = value[:m]
+        # we now have 'xyyy' where x can be a " character
+        if value.find('"') != -1:
+          value = value[2:]
+        # 1\baselineskip = 1.2 * font size
+        new_value = float(value) / 100 * 1.2 * float(fontsize)
+        string = document.body[i][:j + 1] + quote + str(new_value) + "pt" + star + quote
+        document.body[i] = string
+      if i == end:
+        break
+      i += 1
+      star = ''
+      quote = ''
+
+
 ##
 # Conversion hub
 #
@@ -2117,7 +2159,7 @@
            [398, []]
           ]
 
-revert =  [[397, [revert_mathrsfs]],
+revert =  [[397, [revert_baselineskip, revert_mathrsfs]],
            [396, []],
            [395, [revert_nameref]],
            [394, [revert_DIN_C_pagesizes]],
Index: src/insets/InsetGraphics.cpp
===================================================================
--- src/insets/InsetGraphics.cpp	(revision 35011)
+++ src/insets/InsetGraphics.cpp	(working copy)
@@ -393,7 +393,8 @@
 		case Length::PPW: // Percent of PageWidth
 		case Length::PLW: // Percent of LineWidth
 		case Length::PTH: // Percent of TextHeight
-		case Length::PPH: // Percent of Paper
+		case Length::PPH: // Percent of PaperHeight
+		case Length::BLS: // Percent of BaselineSkip
 			// Sigh, this will go wrong.
 			result << len.value() << "%";
 			break;
Index: src/Length.cpp
===================================================================
--- src/Length.cpp	(revision 35012)
+++ src/Length.cpp	(working copy)
@@ -15,9 +15,11 @@
 
 #include <config.h>
 
+#include "BufferView.h"
 #include "Length.h"
 #include "LyXRC.h"
 
+#include "support/convert.h"
 #include "support/docstream.h"
 
 #include <sstream>
@@ -102,6 +104,9 @@
 	case PPH:
 		os << val_ / 100.0 << "\\paperheight";
 		break;
+	case BLS:
+		os << val_ / 100.0 << "\\baselineskip";
+		break;
 	default:
 		os << val_ << unit_name[unit_];
 	  break;
@@ -140,6 +145,7 @@
 	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 << val_ << '%';
@@ -204,6 +210,10 @@
 	// but this estimate might not be more accurate as the screen font
 	// is different then the latex font.
 
+	// current font size
+	//BufferView const & bv;
+	//double font_size = convert<double>(bv.buffer().params().fontsize);
+
 	// Pixel values are scaled so that the ratio
 	// between lengths and font sizes on the screen
 	// is the same as on paper.
@@ -283,6 +293,11 @@
 	case Length::PPH:
 		result = val_ * text_width * 2.2 / 100;
 		break;
+	case Length::BLS:
+		// baselineskip is approx. 1.2 times the font size for the cmr fonts
+		// replace em_width with font_size!
+		result = val_ * em_width * 1.2 / 100;
+		break;
 	case Length::UNIT_NONE:
 		result = 0;  // this cannot happen
 		break;
Index: src/Length.h
===================================================================
--- src/Length.h	(revision 35011)
+++ src/Length.h	(working copy)
@@ -20,6 +20,8 @@
 
 namespace lyx {
 
+class BufferView;
+
 // Solaris/x86 version 9 and earlier define these
 #undef PC
 #undef SP
@@ -56,6 +58,7 @@
 		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 2010-07-25
 		UNIT_NONE ///< no unit
 	};
 
Index: src/lengthcommon.cpp
===================================================================
--- src/lengthcommon.cpp	(revision 35011)
+++ src/lengthcommon.cpp	(working copy)
@@ -28,7 +28,7 @@
 	"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);
 
@@ -38,7 +38,7 @@
 	N_("ex"), N_("in"), 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)
 {

Reply via email to