mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 11:16:55 +00:00
use real LyXLength for minipages; new method LyXLength::inPixels
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3412 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
86aa40061e
commit
d8037e4bfd
@ -3302,7 +3302,7 @@ void BufferView::Pimpl::smartQuote()
|
||||
|
||||
if (style.pass_thru ||
|
||||
(!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
|
||||
Dispatch(LFUN_SELFINSERT, "\"");
|
||||
bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
2002-01-17 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* buffer.C (parseSingleLyXformat2Token): update because minipage
|
||||
width is now a LyXLength
|
||||
|
||||
* lyxlength.C (inPixels): new method, extracted from VSpace::inPixels
|
||||
|
||||
* BufferView_pimpl.C (smartQuote): fix insertion of quote inset in
|
||||
math insets
|
||||
|
||||
2002-01-17 Juergen Vigna <jug@sad.it>
|
||||
|
||||
* lyxfunc.C (dispatch): fixed PARAGRAPH_GOTO
|
||||
|
12
src/buffer.C
12
src/buffer.C
@ -1278,10 +1278,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
|
||||
}
|
||||
InsetMinipage * mini = new InsetMinipage;
|
||||
mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
|
||||
mini->pageWidth(par->params().pextraWidth());
|
||||
mini->pageWidth(LyXLength(par->params().pextraWidth()));
|
||||
if (!par->params().pextraWidthp().empty()) {
|
||||
lyxerr << "WP:" << mini->pageWidth() << endl;
|
||||
mini->pageWidth(tostr(par->params().pextraWidthp())+"%");
|
||||
lyxerr << "WP:" << mini->pageWidth().asString() << endl;
|
||||
mini->pageWidth(LyXLength((par->params().pextraWidthp())+"%"));
|
||||
}
|
||||
Paragraph * op = mini->firstParagraph();
|
||||
mini->inset.paragraph(par);
|
||||
@ -1359,10 +1359,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
|
||||
|
||||
InsetMinipage * mini = new InsetMinipage;
|
||||
mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
|
||||
mini->pageWidth(minipar->params().pextraWidth());
|
||||
mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
|
||||
if (!par->params().pextraWidthp().empty()) {
|
||||
lyxerr << "WP:" << mini->pageWidth() << endl;
|
||||
mini->pageWidth(tostr(par->params().pextraWidthp())+"%");
|
||||
lyxerr << "WP:" << mini->pageWidth().asString() << endl;
|
||||
mini->pageWidth(LyXLength((par->params().pextraWidthp())+"%"));
|
||||
}
|
||||
mini->inset.paragraph(minipar);
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
2002-01-17 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* ControlMinipage.h: change MinipageParams::pageWidth to LyXLength
|
||||
|
||||
* ControlExternal.C (Browse): add a std:: qualifier
|
||||
|
||||
2002-01-16 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
@ -34,7 +34,7 @@ struct MinipageParams {
|
||||
///
|
||||
MinipageParams(InsetMinipage const &);
|
||||
///
|
||||
string pageWidth;
|
||||
LyXLength pageWidth;
|
||||
///
|
||||
InsetMinipage::Position pos;
|
||||
};
|
||||
|
@ -1,3 +1,8 @@
|
||||
2002-01-17 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* FormMinipage.C (apply): change because MinipageParams::pageWidth
|
||||
is now a real LyXLength
|
||||
|
||||
2002-01-17 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* FormDocument.C: enable line spacing input properly
|
||||
|
@ -60,8 +60,8 @@ void FormMinipage::build()
|
||||
void FormMinipage::apply()
|
||||
{
|
||||
controller().params().pageWidth =
|
||||
getLengthFromWidgets(dialog_->input_width,
|
||||
dialog_->choice_width_units);
|
||||
LyXLength(getLengthFromWidgets(dialog_->input_width,
|
||||
dialog_->choice_width_units));
|
||||
|
||||
if (fl_get_button(dialog_->radio_top))
|
||||
controller().params().pos = InsetMinipage::top;
|
||||
|
@ -1,3 +1,10 @@
|
||||
2002-01-17 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||
|
||||
* insettabular.C (getMaxWidthOfCell): use LyXLength::inPixels
|
||||
|
||||
* insetminipage.[Ch]: change width_ and height_ to be LyXLength
|
||||
instead of string
|
||||
|
||||
2002-01-17 Juergen Vigna <jug@sad.it>
|
||||
|
||||
* insettabular.C (lockInsetInInset): same change as in insettext.
|
||||
|
@ -61,7 +61,7 @@ using std::endl;
|
||||
|
||||
InsetMinipage::InsetMinipage()
|
||||
: InsetCollapsable(), pos_(center),
|
||||
inner_pos_(inner_center)
|
||||
inner_pos_(inner_center), width_(100, LyXLength::PW)
|
||||
{
|
||||
setLabel(_("minipage"));
|
||||
LyXFont font(LyXFont::ALL_SANE);
|
||||
@ -79,7 +79,6 @@ InsetMinipage::InsetMinipage()
|
||||
setBackgroundColor(LColor::green);
|
||||
inset.setFrameColor(0, LColor::blue);
|
||||
setInsetName("Minipage");
|
||||
width_ = "100%"; // set default to 100% of column_width
|
||||
}
|
||||
|
||||
|
||||
@ -107,8 +106,8 @@ void InsetMinipage::write(Buffer const * buf, ostream & os) const
|
||||
os << getInsetName() << "\n"
|
||||
<< "position " << pos_ << "\n"
|
||||
<< "inner_position " << inner_pos_ << "\n"
|
||||
<< "height \"" << height_ << "\"\n"
|
||||
<< "width \"" << width_ << "\"\n";
|
||||
<< "height \"" << height_.asString() << "\"\n"
|
||||
<< "width \"" << width_.asString() << "\"\n";
|
||||
InsetCollapsable::write(buf, os);
|
||||
}
|
||||
|
||||
@ -146,7 +145,7 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
|
||||
string const token = lex.getString();
|
||||
if (token == "height") {
|
||||
lex.next();
|
||||
height_ = lex.getString();
|
||||
height_ = LyXLength(lex.getString());
|
||||
} else {
|
||||
lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
|
||||
<< endl;
|
||||
@ -159,7 +158,7 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
|
||||
string const token = lex.getString();
|
||||
if (token == "width") {
|
||||
lex.next();
|
||||
width_ = lex.getString();
|
||||
width_ = LyXLength(lex.getString());
|
||||
} else {
|
||||
lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
|
||||
<< endl;
|
||||
@ -241,7 +240,7 @@ int InsetMinipage::latex(Buffer const * buf,
|
||||
break;
|
||||
}
|
||||
os << "\\begin{minipage}[" << s_pos << "]{"
|
||||
<< LyXLength(width_).asLatexString() << "}%\n";
|
||||
<< width_.asLatexString() << "}%\n";
|
||||
|
||||
int i = inset.latex(buf, os, fragile, fp);
|
||||
|
||||
@ -286,13 +285,13 @@ void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
|
||||
}
|
||||
|
||||
|
||||
string const & InsetMinipage::pageHeight() const
|
||||
LyXLength const & InsetMinipage::pageHeight() const
|
||||
{
|
||||
return height_;
|
||||
}
|
||||
|
||||
|
||||
void InsetMinipage::pageHeight(string const & ll)
|
||||
void InsetMinipage::pageHeight(LyXLength const & ll)
|
||||
{
|
||||
if (height_ != ll) {
|
||||
height_ = ll;
|
||||
@ -301,13 +300,13 @@ void InsetMinipage::pageHeight(string const & ll)
|
||||
}
|
||||
|
||||
|
||||
string const & InsetMinipage::pageWidth() const
|
||||
LyXLength const & InsetMinipage::pageWidth() const
|
||||
{
|
||||
return width_;
|
||||
}
|
||||
|
||||
|
||||
void InsetMinipage::pageWidth(string const & ll)
|
||||
void InsetMinipage::pageWidth(LyXLength const & ll)
|
||||
{
|
||||
if (ll != width_) {
|
||||
width_ = ll;
|
||||
@ -332,17 +331,16 @@ int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (!width_.empty()) {
|
||||
LyXLength len(width_);
|
||||
switch(len.unit()) {
|
||||
if (!width_.zero()) {
|
||||
switch(width_.unit()) {
|
||||
case LyXLength::PW: // Always % of workarea
|
||||
case LyXLength::PE:
|
||||
case LyXLength::PP:
|
||||
case LyXLength::PL:
|
||||
return (InsetCollapsable::getMaxWidth(bv, inset) * (int)len.value()) / 100;
|
||||
return (InsetCollapsable::getMaxWidth(bv, inset) * (int)width_.value()) / 100;
|
||||
default:
|
||||
{
|
||||
int ww1 = VSpace(width_).inPixels(bv);
|
||||
int ww1 = width_.inPixels(bv);
|
||||
int ww2 = InsetCollapsable::getMaxWidth(bv, inset);
|
||||
if (ww2 > 0 && ww2 < ww1) {
|
||||
return ww2;
|
||||
|
@ -17,7 +17,7 @@
|
||||
#endif
|
||||
|
||||
#include "insetcollapsable.h"
|
||||
#include "vspace.h"
|
||||
#include "lyxlength.h"
|
||||
#include <sigc++/signal_system.h>
|
||||
|
||||
/** The minipage inset
|
||||
@ -71,13 +71,13 @@ public:
|
||||
///
|
||||
void innerPos(InnerPosition);
|
||||
///
|
||||
string const & pageHeight() const;
|
||||
LyXLength const & pageHeight() const;
|
||||
///
|
||||
void pageHeight(string const &);
|
||||
void pageHeight(LyXLength const &);
|
||||
///
|
||||
string const & pageWidth() const;
|
||||
LyXLength const & pageWidth() const;
|
||||
///
|
||||
void pageWidth(string const &);
|
||||
void pageWidth(LyXLength const &);
|
||||
///
|
||||
SigC::Signal0<void> hideDialog;
|
||||
///
|
||||
@ -93,9 +93,9 @@ private:
|
||||
///
|
||||
InnerPosition inner_pos_;
|
||||
///
|
||||
string height_;
|
||||
LyXLength height_;
|
||||
///
|
||||
string width_;
|
||||
LyXLength width_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -2115,10 +2115,7 @@ int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
|
||||
|
||||
if (len.zero())
|
||||
return -1;
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
|
||||
#endif
|
||||
return VSpace(len).inPixels(bv);
|
||||
return len.inPixels(bv);
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
#include "lyxlength.h"
|
||||
#include "lengthcommon.h"
|
||||
#include "lyxrc.h"
|
||||
#include "BufferView.h"
|
||||
#include "lyxtext.h"
|
||||
|
||||
#include "Lsstream.h"
|
||||
|
||||
@ -108,6 +111,98 @@ bool LyXLength::zero() const
|
||||
}
|
||||
|
||||
|
||||
int LyXLength::inPixels(BufferView const * bv) const
|
||||
{
|
||||
// Height of a normal line in pixels (zoom factor considered)
|
||||
int height = bv->text->defaultHeight(); // [pixels]
|
||||
int default_width = bv->workWidth();
|
||||
|
||||
// Zoom factor specified by user in percent
|
||||
double const zoom = lyxrc.zoom / 100.0; // [percent]
|
||||
|
||||
// DPI setting for monitor: pixels/inch
|
||||
double const dpi = lyxrc.dpi; // screen resolution [pixels/inch]
|
||||
|
||||
// Pixel values are scaled so that the ratio
|
||||
// between lengths and font sizes on the screen
|
||||
// is the same as on paper.
|
||||
|
||||
// we don't care about sign of value, we
|
||||
// display negative space with text too
|
||||
double result = 0.0;
|
||||
int val_sign = val_ < 0.0 ? -1 : 1;
|
||||
|
||||
switch (unit_) {
|
||||
case LyXLength::SP:
|
||||
// Scaled point: sp = 1/65536 pt
|
||||
result = zoom * dpi * val_
|
||||
/ (72.27 * 65536); // 4736286.7
|
||||
break;
|
||||
case LyXLength::PT:
|
||||
// Point: 1 pt = 1/72.27 inch
|
||||
result = zoom * dpi * val_
|
||||
/ 72.27; // 72.27
|
||||
break;
|
||||
case LyXLength::BP:
|
||||
// Big point: 1 bp = 1/72 inch
|
||||
result = zoom * dpi * val_
|
||||
/ 72; // 72
|
||||
break;
|
||||
case LyXLength::DD:
|
||||
// Didot: 1157dd = 1238 pt?
|
||||
result = zoom * dpi * val_
|
||||
/ (72.27 / (0.376 * 2.845)); // 67.559735
|
||||
break;
|
||||
case LyXLength::MM:
|
||||
// Millimeter: 1 mm = 1/25.4 inch
|
||||
result = zoom * dpi * val_
|
||||
/ 25.4; // 25.4
|
||||
break;
|
||||
case LyXLength::PC:
|
||||
// Pica: 1 pc = 12 pt
|
||||
result = zoom * dpi * val_
|
||||
/ (72.27 / 12); // 6.0225
|
||||
break;
|
||||
case LyXLength::CC:
|
||||
// Cicero: 1 cc = 12 dd
|
||||
result = zoom * dpi * val_
|
||||
/ (72.27 / (12 * 0.376 * 2.845)); // 5.6299779
|
||||
break;
|
||||
case LyXLength::CM:
|
||||
// Centimeter: 1 cm = 1/2.54 inch
|
||||
result = zoom * dpi * val_
|
||||
/ 2.54; // 2.54
|
||||
break;
|
||||
case LyXLength::IN:
|
||||
// Inch
|
||||
result = zoom * dpi * val_;
|
||||
break;
|
||||
case LyXLength::EX:
|
||||
// Ex: The height of an "x"
|
||||
result = zoom * val_ * height / 2; // what to / width?
|
||||
break;
|
||||
case LyXLength::EM: // what to / width?
|
||||
// Em: The width of an "m"
|
||||
result = zoom * val_ * height / 2; // Why 2?
|
||||
break;
|
||||
case LyXLength::MU: // This is probably only allowed in
|
||||
// math mode
|
||||
result = zoom * val_ * height;
|
||||
break;
|
||||
case LyXLength::PW: // Always % of workarea
|
||||
case LyXLength::PE:
|
||||
case LyXLength::PP:
|
||||
case LyXLength::PL:
|
||||
result = val_ * default_width / 100;
|
||||
break;
|
||||
case LyXLength::UNIT_NONE:
|
||||
result = 0; // this cannot happen
|
||||
break;
|
||||
}
|
||||
return static_cast<int>(result * val_sign + 0.5);
|
||||
}
|
||||
|
||||
|
||||
bool operator==(LyXLength const & l1, LyXLength const & l2)
|
||||
{
|
||||
return l1.value() == l2.value() && l1.unit() == l2.unit();
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include "LString.h"
|
||||
|
||||
class BufferView;
|
||||
|
||||
//
|
||||
/// LyXLength Class
|
||||
//
|
||||
@ -83,6 +85,8 @@ public:
|
||||
string const asString() const;
|
||||
///
|
||||
string const asLatexString() const;
|
||||
///
|
||||
int inPixels(BufferView const * bv) const;
|
||||
|
||||
/** If "data" is valid, the length represented by it is
|
||||
stored into "result", if that is not 0. */
|
||||
|
79
src/vspace.C
79
src/vspace.C
@ -468,84 +468,7 @@ int VSpace::inPixels(BufferView * bv) const
|
||||
case VFILL: return 3 * height;
|
||||
// leave space for the vfill symbol
|
||||
case LENGTH:
|
||||
// Pixel values are scaled so that the ratio
|
||||
// between lengths and font sizes on the screen
|
||||
// is the same as on paper.
|
||||
|
||||
// we don't care about sign of value, we
|
||||
// display negative space with text too
|
||||
result = 0.0;
|
||||
value = len_.len().value();
|
||||
int val_sign = value < 0.0 ? -1 : 1;
|
||||
|
||||
switch (len_.len().unit()) {
|
||||
case LyXLength::SP:
|
||||
// Scaled point: sp = 1/65536 pt
|
||||
result = zoom * dpi * value
|
||||
/ (72.27 * 65536); // 4736286.7
|
||||
break;
|
||||
case LyXLength::PT:
|
||||
// Point: 1 pt = 1/72.27 inch
|
||||
result = zoom * dpi * value
|
||||
/ 72.27; // 72.27
|
||||
break;
|
||||
case LyXLength::BP:
|
||||
// Big point: 1 bp = 1/72 inch
|
||||
result = zoom * dpi * value
|
||||
/ 72; // 72
|
||||
break;
|
||||
case LyXLength::DD:
|
||||
// Didot: 1157dd = 1238 pt?
|
||||
result = zoom * dpi * value
|
||||
/ (72.27 / (0.376 * 2.845)); // 67.559735
|
||||
break;
|
||||
case LyXLength::MM:
|
||||
// Millimeter: 1 mm = 1/25.4 inch
|
||||
result = zoom * dpi * value
|
||||
/ 25.4; // 25.4
|
||||
break;
|
||||
case LyXLength::PC:
|
||||
// Pica: 1 pc = 12 pt
|
||||
result = zoom * dpi * value
|
||||
/ (72.27 / 12); // 6.0225
|
||||
break;
|
||||
case LyXLength::CC:
|
||||
// Cicero: 1 cc = 12 dd
|
||||
result = zoom * dpi * value
|
||||
/ (72.27 / (12 * 0.376 * 2.845)); // 5.6299779
|
||||
break;
|
||||
case LyXLength::CM:
|
||||
// Centimeter: 1 cm = 1/2.54 inch
|
||||
result = zoom * dpi * value
|
||||
/ 2.54; // 2.54
|
||||
break;
|
||||
case LyXLength::IN:
|
||||
// Inch
|
||||
result = zoom * dpi * value;
|
||||
break;
|
||||
case LyXLength::EX:
|
||||
// Ex: The height of an "x"
|
||||
result = zoom * value * height / 2; // what to / width?
|
||||
break;
|
||||
case LyXLength::EM: // what to / width?
|
||||
// Em: The width of an "m"
|
||||
result = zoom * value * height / 2; // Why 2?
|
||||
break;
|
||||
case LyXLength::MU: // This is probably only allowed in
|
||||
// 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;
|
||||
}
|
||||
return static_cast<int>(result * val_sign + 0.5);
|
||||
return len_.len().inPixels(bv);
|
||||
}
|
||||
return 0; // never reached
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user