The code is not ready for situations where some paragraphs that are
not visible have metrics available. This has been made visible by
a4d9315b, which removes a couple of full metrics updates: the screen
was not correctly scrolled after a scrollToCursor() call.
In PararagraphMetrics, some methods are added to be able to handle the
fact that paragraphs have or do not have a position.
In TextMetrics, a new method returns the first visible paragraph.
Finally, in BufferView::updateMetrics, the paragraphs' positions are
reset (in the case where everything is not cleared) and some care is
taken to skip the ones that are not relevant.
The assumption outside of this method is that all the paragraphs that
are in the TextMetrics are visible (we are talking about top-level
TextMetrics here). This could be changed (in order to avoid
recomputing paragraph metrics), but the cost is high in terms of
complexity and it is not clear that the gain in terms of performance
would be important.
The most visible part of this commit is the move of part of
BufferView::updateMetrics to a new TextMetrics::updateMetrics. This
new method makes sure that metrics are known for all visible paragraphs
(starting from anchor), and that the positions of the paragraphs have
been recorded.
This method is called up to 3 times in BufferView::updateMetrics:
* unconditionally, to update all visible metrics,
* then, if the bottom of the document is visible and too high, after
updating the anchor ypos,
* and similarly if the top of the document is visible and too low.
This fixes for example the case where one jumps to Section 5.3 at the
end of Tutorial and 'scroll_below_document' is false.
Some now redundant code is removed from BufferView::scrollToCursor.
The anchor-setting code in BufferView::draw is not clearly useful, but
left here just in case. It generates a debug warning, though.
Part of bug #12297.
Replace flag parameter for updateMetrics() by a `force' boolean. When
it is false, the method keeps the metrics of paragraphs that are still
visible in WorkArea instead of computing everything afresh. All it has
to do is update their positions.
Add code to updateMetrics() to update the value of the anchor pit/ypos
(similar to the one in draw()).
Update processUpdateFlags() to use this when update flag is ForceDraw.
Modify scrollDocView() to just change the anchor paragraph position
when the scrolling operation would re-use some of the existing
paragraphs.
The time needed to update the metrics when scrolling with mouse in the
branch-test.lyx document is now divided by 20!
Part of bug #12297.
This patch reuses the code of TextMetrics::displayFont() that handles
the label part of LABEL_MANUAL paragraphs to create a new
labelDisplayFont() method usable for things like Itemize labels.
To this end, and new magic value is used as position to force the
label case in displayFont(). The code is also factored a bit and
cleaned up.
Fixes bug #12810.
The spacing of Labeling, Description and friends shall be computed
when breaking the row, not when tokenizing it. Indeed, this is the
right place to determine its correct value.
To this end add a new MARGINSPACE row element type.
This allows to remove TextMetrics::labelEnd, which is not used anymore.
Change semantics of Row::shortenIfNeeded: instead of breaking the row
and returning a boolean, it returns the list of row elements that have
been removed (or broken) from the row. The logic of the method remains
the same.
Use shortenIfNeeded in breakParagraph. This was the last missing block.
Remove Row::breakAt and the old breakRow. Only bugs remain now :)
Still many features missing:
- handle insets that break rows (display math, newline, ...)
- handle rows that are too long by replacing the single call to
breakAt with a call to a reworked Row::shortenIfNeeded.
- some easy things at the end of breakRow (bidi text, etc.).
This contains large parts of breakRow, but creates a unique row for the paragraph.
The parts taken or not in redoParagraph are annotated.
The new method is not used yet.
When a paragraph is empty, it was not possible to query what the left
margin would be for an hypothetical second row.
Modify TextMetrics::leftMargin so that it does not test
whether position is after the last position of the paragraph.
Cosmetics: set the size of label to "small" for Abstract layout in
standard classes and reduce the spacing between label and text.
Fixes remainder of #11939.
It did access par_metrics_[] directly because there was no non-const
parMetrics().
This patch adds one and unfriends BufferView. The code is equivalent
since in all these cases, the metrics have just been computed with
redoParagraph().
The 20px space on top and bottom of document have traditionally been
obtained by adding the to the ascent/descent of the first/last row.
This reads to annoyances like selections that are drawn in these
margins and issues with the nesting marker.
The change is to add the values to a separate member of the Row
object, and to add new Row::total(Ascent|Descent) methods that add the
effect of this padding.
Moreover, some methods are added to TextMetrics to simplify the
BufferView code.
Fixes bug #9545.
This is done by declaring unimplemented private copy constructor and
assignment operator.
This breaks compilation in BufferView::textMetrics, which does a copy when
inserting a TextMetrics object in the cache. Some C++11 wizardry I will not
pretend to completely understand saves the day.
See the following page for details:
https://en.cppreference.com/w/cpp/container/map/emplace
This avoids real world bugs like #11512.
The goal of this commit is to simplify the logic in TextMetrics::draw.
Now, rows are repainted depending on their changed() status.
Instead of checking whether rows have been scrolled horizontally at
draw time, the code marks the row as changed when testing for
horizontal scrolling.
To this end a new method TestMetrics::setRowChanged is added, that
searches a row in the text metrics cache and marks it changed if
found.
The old code that remembered the previously scrolled row can now be
removed.
When several lines of text are in the same variable-width tabular
cell, it is not possible to align properly the rows until the cell
width is known.
Therefore a parameter is added to redoParagraph to skip this
computation, so that it can be done later in TextMetrics::metrics.
Other calls to redoParagraph in the code are not affected. It is not
clear at this point whether they may create artefacts.
computeRowMetrics has been renamed to setRowAlignment to better
reflect its use.
Fixes bug #11447.
This effectively enables linebreaks, multipars and layout changes in
non-fixed width (i.e., standard) table columns.
Fixes: #6577
TODO: metrics are wrong (too wide) on screen with linebreaks.
This patch makes sure that, every time a ParagraphMetrics has its
position set, the inset positions for the insets held by this
paragraph are remembered too.
This is complementary to BufferView::updatePosCache, but I do not have
hard evidence that this is required other than to increase robustness.
It may help in some cases when scrolling the document (scrollbar,
cursor up/down, page up/down).
In some (not yet understood) situations, the paragraph metrics cache
is empty in generateSyntheticMouseEvent(). We just avoid a crash in
this case, but there is probably an underlying problem that deserves
being fixed.
Fixes bug #10324.
The test added at 359aef92 was incorrect. Actually, Inset::editXY
returns the inset when it is edited and also when it is not, which
can be confusing. So if we are unlucky and the slices positions in the
text area and in the inner inset match, the code below triggers and
many bad things can happen.
Also improve the documentation of Inset::editXY and TextMetrics::editXY.
Fixes#10691.
The new functions parBottomSpaging and parTopSapcing return below/above each paragraph.
This allows to remove the TopBottomSpace argument and makes the code a
bit clearer.
Now that Row has a pit() member, it is possible to use it instead of passing an extra pit_type parameter to a function which already has access to a Row.
Let breakRow return a boolean indicating whether an additional row is
required (after a newline) and use that to replace the code that added
an extra row when a paragraph ends with a newline.
If we do not do that, it is not possible to position the cursor after
a long inset with the mouse.
To do this, it is necessary to add the pit information to the Row
object. This is a good idea in any case, and will allow to simplify
some code later on.
Fixes bug #10094.
This is done by implementing contentAlignment() for this inset.
In order to display properly 'stretch' alignment, the code for TextMetrics::getAlign is rewritten to include some code that was in computeRowMetrics.
New method TextMetrics::findRowElement, excerpted from CursorX.
Reimplement getSurroundingPos using Row information. This is easy when
the cursor is inside a row element. At row element edges, different
situations can occur; hopefully all these situations are taken into
account.
Rename the old getSurroundingPos to getSurroundingPosOrig and
transform getSurroundingPos into a wrapper that compares the two
methods. This will be removed when we are confident that the new
function is equivalent to the old one.
It will then be possible to remove also the Bidi class (at last!).
These were all found by cppcheck. Even in constructors that are there "only
because of std containers" the class should be initialized correctly. You can
never know whether such an object does not get used, and then a nice crash
caused by dereferencing a NULL-pointer is better than undefined behaviour.
* convert cursorX to new scheme; old computation is still there for the sake of comparison.
* use Row to compute separator width in computeRowMetrics; again, the old code is retained for now.
* Get rid of rowWidth()
This fixes a crash in examples/fa/splash.lyx when selecting text
representing menu entries. This happens because menu names are in LTR
English, while the inset itself is in RTL.
The problem is that the current code relies on the fact that
1. getColumnNearX and checkInsetHit share the same idea about cursor
position.
2. pos and pos + 1 are in general consecutive on screen.
It seems that 1. is wrong here (for reasons I did not try to
understand); the second assumption is definitely false with
bi-directional text. This makes editXY very fragile.
The new code should be more robust in this respect. The logic is:
* if checkInsetHit finds an inset, use its position,
* otherwise, ask getColumnNearX for the cursor position.
Fixes: #9142