]> git.lyx.org Git - lyx.git/blobdiff - src/vspace.C
Fix paragraph spacing
[lyx.git] / src / vspace.C
index 03e6128afffa51670428c758a51ccd544f38900d..a314e312543f6d74e3cf4a839ec072eecf27a33b 100644 (file)
@@ -1,11 +1,10 @@
-// -*- C++ -*-
 /* This file is part of
  * ====================================================== 
  * 
  *           LyX, The Document Processor
  *      
  *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2000 The LyX Team.
+ *           Copyright 1995-2001 The LyX Team.
  *
  * ====================================================== */
 
@@ -15,6 +14,8 @@
 #pragma implementation "vspace.h"
 #endif
 
+#include <stdio.h>
+
 #include "lyx_main.h"
 #include "buffer.h"
 #include "vspace.h"
@@ -34,7 +35,8 @@ int const num_units = LyXLength::UNIT_NONE;
 // I am not sure if "mu" should be possible to select (Lgb)
 char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
                                      "mm", "pc", "cc", "cm",
-                                     "in", "ex", "em", "mu" }; 
+                                     "in", "ex", "em", "mu",
+                                     "%",  "c%", "p%", "l%" }; 
 
 
 /*  The following static items form a simple scanner for
@@ -104,7 +106,7 @@ char nextToken(string & data)
                        } else return 'E';
                }
                
-               i = data.find_first_not_of("abcdefghijklmnopqrstuvwxyz");
+               i = data.find_first_not_of("abcdefghijklmnopqrstuvwxyz%");
                if (i != 0) {
                        if (unit_index > 3) return 'E';
 
@@ -162,6 +164,13 @@ LaTeXLength table[] = {
 
 } // namespace anon
 
+const char * stringFromUnit(int unit)
+{
+    if (unit < 0 || unit >= num_units)
+       return 0;
+    return unit_name[unit];
+}
+
 
 LyXLength::UNIT unitFromString (string const & data)
 {
@@ -317,12 +326,34 @@ LyXLength::LyXLength(string const & data)
 
 string const LyXLength::asString() const
 {
-       std::ostringstream buffer;
+       ostringstream buffer;
        buffer << val << unit_name[uni]; // setw?
        return buffer.str().c_str();
 }
 
 
+string const LyXLength::asLatexString() const
+{
+       ostringstream buffer;
+       switch(uni) {
+       case PW:
+       case PE:
+           buffer << abs(static_cast<int>(val/100)) << "." << abs(static_cast<int>(val)%100) << "\\columnwidth";
+           break;
+       case PP:
+           buffer << "." << abs(static_cast<int>(val/100)) << "." << abs(static_cast<int>(val)%100) << "\\pagewidth";
+           break;
+       case PL:
+           buffer << "." << abs(static_cast<int>(val/100)) << "." << abs(static_cast<int>(val)%100) << "\\linewidth";
+           break;
+       default:
+           buffer << val << unit_name[uni]; // setw?
+           break;
+       }
+       return buffer.str().c_str();
+}
+
+
 /*  LyXGlueLength class
  */
 
@@ -345,7 +376,7 @@ LyXGlueLength::LyXGlueLength (string const & data)
 
 string const LyXGlueLength::asString() const
 {
-       std::ostringstream buffer;
+       ostringstream buffer;
 
        if (plus_val != 0.0)
                if (minus_val != 0.0)
@@ -399,7 +430,7 @@ string const LyXGlueLength::asString() const
 
 string const LyXGlueLength::asLatexString() const
 {
-       std::ostringstream buffer;
+       ostringstream buffer;
 
        if (plus_val != 0.0)
                if (minus_val != 0.0)
@@ -519,15 +550,17 @@ string const VSpace::asLatexCommand(BufferParams const & params) const
 int VSpace::inPixels(BufferView * bv) const
 {
        // Height of a normal line in pixels (zoom factor considered)
-       int height = bv->text->DefaultHeight(); // [pixels]
+       int height = bv->text->defaultHeight(); // [pixels]
        int skip = 0;
+       int width = bv->workWidth();
+
        if (kin == DEFSKIP)
            skip = bv->buffer()->params.getDefSkip().inPixels(bv);
 
-       return inPixels(height, skip);
+       return inPixels(height, skip, width);
 }
 
-int VSpace::inPixels(int default_height, int default_skip) const
+int VSpace::inPixels(int default_height, int default_skip, int default_width) const
 {
        // Height of a normal line in pixels (zoom factor considered)
        int height = default_height; // [pixels]
@@ -623,6 +656,12 @@ int VSpace::inPixels(int default_height, int default_skip) const
                        // math mode
                        result = zoom * value * height;
                        break;
+               case LyXLength::PW: // Always % of workarea
+               case LyXLength::PE:
+               case LyXLength::PP:
+               case LyXLength::PL:
+                       result = value * default_width / 100;
+                       break;
                case LyXLength::UNIT_NONE:
                        result = 0;  // this cannot happen
                        break;