From d8037e4bfdd8524ccbf3a1fccfc9d5264644b99e Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 17 Jan 2002 23:09:31 +0000 Subject: [PATCH] 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 --- src/BufferView_pimpl.C | 2 +- src/ChangeLog | 10 +++ src/buffer.C | 12 +-- src/frontends/controllers/ChangeLog | 2 + src/frontends/controllers/ControlMinipage.h | 2 +- src/frontends/xforms/ChangeLog | 5 ++ src/frontends/xforms/FormMinipage.C | 4 +- src/insets/ChangeLog | 7 ++ src/insets/insetminipage.C | 30 +++---- src/insets/insetminipage.h | 14 +-- src/insets/insettabular.C | 5 +- src/lyxlength.C | 95 +++++++++++++++++++++ src/lyxlength.h | 4 + src/vspace.C | 79 +---------------- 14 files changed, 156 insertions(+), 115 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 11506b505e..b0d7bdbdeb 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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, "\""); } diff --git a/src/ChangeLog b/src/ChangeLog index 76cd984f9d..975827fc00 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2002-01-17 Jean-Marc Lasgouttes + + * 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 * lyxfunc.C (dispatch): fixed PARAGRAPH_GOTO diff --git a/src/buffer.C b/src/buffer.C index c396b1ebad..e2ee686197 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1278,10 +1278,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, } InsetMinipage * mini = new InsetMinipage; mini->pos(static_cast(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(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); diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index b32614b81e..266cc9a6a1 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,5 +1,7 @@ 2002-01-17 Jean-Marc Lasgouttes + * ControlMinipage.h: change MinipageParams::pageWidth to LyXLength + * ControlExternal.C (Browse): add a std:: qualifier 2002-01-16 Jean-Marc Lasgouttes diff --git a/src/frontends/controllers/ControlMinipage.h b/src/frontends/controllers/ControlMinipage.h index b0edc466f1..0e9a9e7187 100644 --- a/src/frontends/controllers/ControlMinipage.h +++ b/src/frontends/controllers/ControlMinipage.h @@ -34,7 +34,7 @@ struct MinipageParams { /// MinipageParams(InsetMinipage const &); /// - string pageWidth; + LyXLength pageWidth; /// InsetMinipage::Position pos; }; diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 310909aa47..029e8eb244 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2002-01-17 Jean-Marc Lasgouttes + + * FormMinipage.C (apply): change because MinipageParams::pageWidth + is now a real LyXLength + 2002-01-17 John Levon * FormDocument.C: enable line spacing input properly diff --git a/src/frontends/xforms/FormMinipage.C b/src/frontends/xforms/FormMinipage.C index b06603c76b..4e9ec3a126 100644 --- a/src/frontends/xforms/FormMinipage.C +++ b/src/frontends/xforms/FormMinipage.C @@ -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; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index ef5bcda5be..3374d6ac7a 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,10 @@ +2002-01-17 Jean-Marc Lasgouttes + + * insettabular.C (getMaxWidthOfCell): use LyXLength::inPixels + + * insetminipage.[Ch]: change width_ and height_ to be LyXLength + instead of string + 2002-01-17 Juergen Vigna * insettabular.C (lockInsetInInset): same change as in insettext. diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 8ab1df6a96..dcb8f6018b 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -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; diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index 8f07025fb4..b44524897c 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -17,7 +17,7 @@ #endif #include "insetcollapsable.h" -#include "vspace.h" +#include "lyxlength.h" #include /** 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 hideDialog; /// @@ -93,9 +93,9 @@ private: /// InnerPosition inner_pos_; /// - string height_; + LyXLength height_; /// - string width_; + LyXLength width_; }; #endif diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 0990b8db48..0478b2020a 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -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); } diff --git a/src/lyxlength.C b/src/lyxlength.C index c1e08dd444..2cc2e853b2 100644 --- a/src/lyxlength.C +++ b/src/lyxlength.C @@ -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(result * val_sign + 0.5); +} + + bool operator==(LyXLength const & l1, LyXLength const & l2) { return l1.value() == l2.value() && l1.unit() == l2.unit(); diff --git a/src/lyxlength.h b/src/lyxlength.h index 8b75cb62ff..caba9ee171 100644 --- a/src/lyxlength.h +++ b/src/lyxlength.h @@ -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. */ diff --git a/src/vspace.C b/src/vspace.C index ec023d8577..ae5cc6438d 100644 --- a/src/vspace.C +++ b/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(result * val_sign + 0.5); + return len_.len().inPixels(bv); } return 0; // never reached } -- 2.39.2