Commit Graph

3113 Commits

Author SHA1 Message Date
Guillaume MM
b382b246b6 MathAtom is a unique_ptr
Fix coverity suggestion of defining a move constructor
2017-04-07 23:31:34 +02:00
Jean-Marc Lasgouttes
7b0e732eeb Check both lower and upper bound for tainted loop limit
In these cases, the lower bound is not that important, but coverity insists on it.
2017-04-05 11:36:40 +02:00
Enrico Forestieri
66aa52ff20 Fix bug #10581
Tell the math parser that we are parsing a macro definition, so that
it doesn't try to return a verbatim copy in case of failure.
2017-04-03 00:26:49 +02:00
Jean-Marc Lasgouttes
758de9577d Improve drawing of math roots (\sqrt and \root)
This is preliminary work to make roots look more like in TeX output:

* correct font size for root order

* set minimum size of the root from the max ascent descent of the
  font. This is what TeX does.

* fix drawing, and in particular horizontal size.

More needs to be done, in particular:

* handle zooming and dpi correctly by removing hardcoded pixel values.

* factor the code for the two types of roots in one.
2017-03-31 18:55:08 +02:00
Jean-Marc Lasgouttes
555338048d Add possibility for command inset to inherit enclosing font
The RenderButton object now has this property. It is set depending on
the value of inheritFont() method that is currently only set for
InsetRef, InsetBibtex and InsetCitation.

Fixes bug #10258
2017-03-28 13:57:34 +02:00
Jean-Marc Lasgouttes
31cd421bcd Limit multirow to 100 columns in mathed
Spotted by coverity, this avoids a blocking loop when parsing.
2017-03-28 11:43:12 +02:00
Jean-Marc Lasgouttes
bc7704a78e Limit the amount of derivatives in external CAS
The (arbitrary) limit is 1000.

Pointed out by coverity. A bad value could lock LyX.
2017-03-28 11:17:35 +02:00
Jean-Marc Lasgouttes
4ea0fd6af4 Two places where coverity urges us to limit string length
These two issues make sense, but there are probably others.
2017-03-24 15:27:22 +01:00
Jean-Marc Lasgouttes
f5fe3c17be Reduce horizontal spacing for simple inline equations 2017-03-24 10:22:32 +01:00
Jean-Marc Lasgouttes
a48581f48c Linearize macros in box edit mode too.
The special mode used by macros where the macro name is displayed as
grey text in a box is now one of the possible marker types for any
inset. The new code puts the macro name below the text, which means
that only the text below the current line will be moved. This makes
edition much more comfortable. The grey border around the contents has
been removed too.

The marker_type enum has been moved from Inset to InsetMath. A
markerMargin() function returns the horizontal margin required on each
side for the marker. Only the corner-type markers MARKER and MARKER2
need some.

A new BOX_MARKER enum value has been added and is taken care of in
afterMetricsMarkers (renamed from metricsMarkerVertical) and
drawMarkers.

The InsetMath::marker() macro now takes a BufferView pointer as
argument, so that the marker type can depend on editing state.

MathRow::metrics now makes changes to the MathRow object when needed.

The specific metrics/draw code in MathMacro has been removed and
replaced by assertions. Code in addToMathRow and marker is adapted to
reflect the cases where linearization is possible.
2017-03-23 10:17:07 +01:00
Jean-Marc Lasgouttes
b8c0891427 Remove optimization that avoids drawing some math inset cells.
It is not clear that the optimization is a gain, but it is clear that
it has a cost: some elements of formulas will not be present in the
position cache.

Fixes bug #10520.
2017-03-13 11:44:48 +01:00
Jean-Marc Lasgouttes
a69bae0c99 Make InsetMathNest::editXY more robust
If no reasonable cell has been found to put the cursor in (maybe
because the cell exist but is not in the cache), exit gracefully.

Fixes bug #10520
2017-03-13 11:44:22 +01:00
Jean-Marc Lasgouttes
9a013637bb Experiment: limit size of strings read from lib/symbols
Coverity complains that we might read strings that are arbitrary
large, and that this can be a security issue. This is a problem in
particular, when we feed these strings to from_utf8(), which coverity
flags as dangerous for some reason.

The best solution would be IMO to model from_utf8() properly, but I do
not know how to do that. Here I try a different solution, where I
cannot read a string larger than 64k from the file.

Let's see whether this removes part of coverity warnings.
2017-03-10 16:29:09 +01:00
Jean-Marc Lasgouttes
ce0c11ba4e Remove unreachable return statements
They were needed long ago to avoid gcc warnings, but now all they do
is create coverity warnings.
2017-03-09 15:05:33 +01:00
Jean-Marc Lasgouttes
000dcb8672 Make a false positive explicit
Pleases coverity
2017-03-08 16:50:03 +01:00
Jean-Marc Lasgouttes
25d64bf43a Fix test to make coverity happy
It is not obvious that cur is not null iff thisSlice is not -1, but
this is what happens in the caller.
2017-03-07 11:56:59 +01:00
Jean-Marc Lasgouttes
55957c4576 Fix test to make coverity happy
It is not obvious that cur is not null iff thisSlice is not -1, but
this is what happens in the caller.
2017-03-07 11:48:32 +01:00
Jean-Marc Lasgouttes
5ad8815a51 Please coverity properly 2017-03-02 14:47:31 +01:00
Jean-Marc Lasgouttes
9251a360a9 Initialize class member to please coverity 2017-03-01 16:31:00 +01:00
Jean-Marc Lasgouttes
d2ad9ae6e2 Rewrite selection code in mathed
Now the selection is not done by the inset, but by the MathData
itself. This allows for some code simplification and avoids an
extra redraw.

Additionally, this fixes the selection inside macros, which was broken
by the new MathRow code.
2017-02-22 11:00:30 +01:00
Jean-Marc Lasgouttes
1c1b3519f9 Use a plain font in macro edit box
Without this, the font would be mathcal in a mathcal environment.
Additionally, set the font size to tiny when computing metrics too.
2017-02-21 11:49:12 +01:00
Jean-Marc Lasgouttes
b9d45e5ef6 Set the cursor a bit on the left in empty cells 2017-02-21 09:53:52 +01:00
Jean-Marc Lasgouttes
fc02744119 Revert "Linearize macros in box edit mode too."
Guillaume tells me that there are problems. We'll return to it later.

This reverts commit 0140348118.
2017-02-21 05:43:38 +01:00
Guillaume Munch
7337c968b3 Fix InsetMathRef mouse behaviour (#10568)
Fix mouse-selection behaviour.

Don't open dialog when releasing if it was not a real click.
2017-02-18 23:03:54 +01:00
Guillaume Munch
63be456c8d When pressing math with the mouse, move to the closest edge (#9748)
Unless it has some dialog that we want to activate.
2017-02-18 23:03:54 +01:00
Guillaume Munch
faeb199793 When selecting math with the mouse, selection happens in the middle (#9748) 2017-02-18 23:03:54 +01:00
Guillaume Munch
86d9abeea7 Move cursor in front of InsetMathSpace before opening the dialog (#7749) 2017-02-18 23:03:53 +01:00
Guillaume Munch
71623b88b2 Generalise the deletion protection mechanism from math to text (#9540)
Now backspace and delete in text will select non-empty math and text insets
before deleting them. This is consistent with what happens in math already.

This is implemented for InsetText as well but can be disabled in case of
negative feedback.

This can be set for any sort of inset with the new virtual method
Inset::confirmDeletion.

New option "force" for the LFUN_*_DELETE_* commands, that bypasses the
confirmDeletion check.
2017-02-18 23:03:23 +01:00
Jean-Marc Lasgouttes
0140348118 Linearize macros in box edit mode too.
The special mode used by macros where the macro name is displayed as
grey text in a box is now one of the possible marker types for any
inset. The new code puts the macro name below the text, which means
that only the text below the current line will be moved. This makes
edition much more comfortable.

The marker_type enum has been moved from Inset to InsetMath.

A new BOX_MARKER enum value has been added and is taken care of in
afterMetricsMarkers (renamed from metricsMarkerVertical) and
drawMarkers.

The InsetMath::marker() macro now takes a BufferView pointer as
argument, so that the marker type can depend on editing state.

MathRow::metrics now makes changes to the MathRow object when needed.

The specific metrics/draw code in MathMacro has been removed and
replaced by assertions. Code in addToMathRow and marker is adapted to
reflect the cases where linearization is possible.
2017-02-14 01:02:00 +01:00
Guillaume Munch
527cc8ca9c Disable InsetMathKern with invalid lengths (#10539)
From now on \kern and \mkern remain as ERT as long as the length is invalid.

Fixes #10539 (regression at 10c8d51b).

The only way to produce an InsetMathKern now is via parsing (i.e. file opening
or copy-paste). This is because there has never been any sensible way to input a
valid InsetMathKern, but this is another issue.
2017-02-11 21:52:09 +01:00
Jean-Marc Lasgouttes
ace5dc157c Compilation fix: missing header for std::max 2017-02-07 11:43:06 +01:00
Jean-Marc Lasgouttes
6763301c05 Better fix for cursor in "blue box"
Since in InsetMathNest::cursorPos we do not know what is the value of
the row element before value of a given BOX, it does not make sense to
set the cursor at a given offset from the start of the MathData
object.

Therefore here we set the cursor in the middle of the MathData object,
which unfortunately may or may not be visually centered wrt the BOX.

The best solution would be to use the MathRow data here, but
unfortunately this is not completely trivial.

This patch replaces 7917ebcc4.
2017-02-06 17:23:00 +01:00
Jean-Marc Lasgouttes
e12b27e16b Some clean-up to markers handling code.
Horizontal space is now added for linearized macros too.

Vertical space handling is done in a separate method.

This is in preparation for handling of 'box' macro editing mode in
MathRow.
2017-02-06 17:17:56 +01:00
Jean-Marc Lasgouttes
7917ebcc40 Fix cursor positionning in empty math arrays (blue box) 2017-02-06 11:59:39 +01:00
Jean-Marc Lasgouttes
ad79ac406f Fixup 89662a68: remove markers that should not be there
InsetMathDelim does not need markers because the delimiters are
visually enough.

CommandInset (like InsetMathRef) does have cells, but they are hidden
(only for storage). Therefore the default InsetMath::markers() method
mistakenly added markers. In practice, the markers were never active
(since the cursor cannot go into the inset), but some space was
reserved for them.
2017-02-03 10:52:53 +01:00
Jean-Marc Lasgouttes
e0024231d3 Fix drawing of rectangle in old-style macro editing mode
The width was a bit to short.
2017-02-02 14:33:38 +01:00
Jean-Marc Lasgouttes
ec676a1dec Make MathRow tokens completely generic
The enum values BEG_MACRO/END_MACRO and BEG_AR/END_AR are replaced by a
single BEGIN/END pair.

The MathRow code now only knows about insets and math arrays.
2017-02-01 17:46:53 +01:00
Jean-Marc Lasgouttes
6c13af3f29 Introduce hooks to encapsulate macro code of MathRow
New hooks (before|after)(Metrics|Draw) are run by the MathRow code
as needed. They are actually also used internally by the MathMacro
code.

The gain is that most traces of explicit macro handling (and
the MathRow::Element::macro member) have been removed from MathRw.cpp.

The next step will be to extend the tokenizing process to allow for
linearizing insets other than macros.
2017-02-01 15:20:06 +01:00
Jean-Marc Lasgouttes
f86dacc292 Linearize macros also when editing them
In the case of inline editing, this avoids unpleasant jumping issues.

This may requires to enter monochrome mode before painting the macro
elements.
2017-02-01 12:21:15 +01:00
Guillaume Munch
03a4b8c932 Implement rule 17
* Convert the kerning into a proper right margin for mathnormal, mathscr and
  mathcal (fonts with \fontdimen2 == 0 as per rule 17 from TeXBook).

* Simulate the fact that characters in mathnormal fonts have a 0-width left
  bearing.

* Implement subscript positioning in the case of rule 17 using negative italic
  correction (kerning_).
2017-01-31 22:55:00 +01:00
Jean-Marc Lasgouttes
1f352b390c Avoid markers for macros without arguments
An example was the \neq macro, which exhibited white markers when selecting.
2017-01-23 10:14:20 +01:00
Jean-Marc Lasgouttes
d712c67be9 BOX tweak
Add a pixel gap around boxes.

When a box is invisible, its width should be null (but keep the weight
to avoid drawing problems (think empty sqrt in a macro).
2017-01-19 17:07:21 +01:00
Jean-Marc Lasgouttes
5982d2abd7 Revert "BOX tweak"
This reverts commit 596c9065e6.
2017-01-17 16:31:34 +01:00
Jean-Marc Lasgouttes
f73bb3f16e Fix glitch in drawing fractions
This is a fixup to 89662a68.
2017-01-17 16:28:48 +01:00
Jean-Marc Lasgouttes
596c9065e6 BOX tweak 2017-01-16 15:35:45 +01:00
Guillaume Munch
fdf805956b Fix font of macro template name 2017-01-14 23:13:14 +01:00
Guillaume Munch
3391fed36a Make the generation of children's tocs more robust
Let the children directly access the TocBuilders, instead of concatenating
after the fact.
2017-01-14 23:13:14 +01:00
Jean-Marc Lasgouttes
cdc847fd30 Fix drawing of empty boxes
They were actually bigger than their metrics.
2017-01-12 12:15:17 +01:00
Jean-Marc Lasgouttes
8361fb603e Rename InsetMathNest::metrics to cellsMetrics
Re-using the name of a virtual method with different semantics is not
a good idea anyway.
2017-01-12 11:22:51 +01:00
Jean-Marc Lasgouttes
4cea47d1eb Implement mathClass() for \big and friends
The information here is obtained by reading LaTeX sources.
2017-01-12 10:28:52 +01:00