Commit Graph

339 Commits

Author SHA1 Message Date
Jean-Marc Lasgouttes
731dbddd11 Annotate source code to please coverity
This code is signalled as a copy and paste error, but it is a false
positive.

According to the documentation, adding a comment starting with
  // coverity[name_of_error]
should be enough to flag the false positive.
2016-06-09 15:51:07 +02:00
Jean-Marc Lasgouttes
5e5440f2f3 Fix right_boundary properly after a row is shortened
Instead of resetting it to false, do a proper test to see whether
there is a separator at the end of the row.

Fixes bug #10180.
2016-06-09 10:48:15 +02:00
Jean-Marc Lasgouttes
508518ad95 Take inset dimension into account in row signature
In some cases, the insets may change height or width without changing
the other apsects of the row.

Fixes bug #6991 and #10182.
2016-06-03 11:21:09 +02:00
Jean-Marc Lasgouttes
0311718215 Split TextMetrics::setRowHeight in three parts
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.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
e39e4cf96b Do not require an extra pit parameter when a row is available
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.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
656b7f5ab7 Set vertical margins in redoParagraph, not setRowHeight
It is actually easier to set the 20 pixels margin in redoParagraph, since it is not necessary to take newlines in account when deciding what is the real last row of the paragraph.

Moreover this solves the following bug (present in 2.1.x too): when the document ends with a newling, the bottom margin disappears.

Update PAINTING_ANALYSIS with new tasks.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
ac759b4368 Rewrite setRowHeight using row information
The initial values for maxasc and maxdes (renamed from maxdesc) is obtained as a maximum of max ascents/descents of all row elements.

This allows to get rid of Paragraph::highestFontInRange and FontList::highestInRange.

Some auxilliary variables declarations are also moved to where they are needed.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
1751626776 Simplify redoParagraph by merging duplicate code
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.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
fc73ebc16c Make the non-drawing cases faster in TextMetrics::drawParagraph
There are two main cases:
* when drawing is disabled from the start, use a simplified code that only paints insets (in order to cache positions).
* when the row is not visible, do the same.

The goal of this optimization is to be able to always run a no-drawing draw after the metrics have been computed.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
96fee0ed7a Move some horizontal scrolling code from TextMetrics to BufferView
It is better to have all the code in the same place, and it will avoid code duplication later.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
83d8e12cc1 Rename Cursor::setSelection(bool) to selection(bool)
The old name would be confusing wrt setSelection(), which does additional checks.
This one is a pure acessor, and the more complete methods are
* setSelection(), which avoids empty selections
* clearSelection(), which resets anchor, and sets word selection and mark more to false.

Most of the code should use these two instead of selection(bool), but this is for later.
2016-05-29 17:55:46 -04:00
Jean-Marc Lasgouttes
641691bc12 TextMetrics: Use shorter names for font metrics
This keeps code easier to read.
2016-05-29 17:55:45 -04:00
Jean-Marc Lasgouttes
4fb8e9b639 Use isMainText() instead of doing explicit tests 2016-05-29 17:55:45 -04:00
Jean-Marc Lasgouttes
1639abb8ed Let getPosNearX take horizontal scrolling into account
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.
2016-05-29 17:55:42 -04:00
Jean-Marc Lasgouttes
a879bc2575 Fix horizontal scrolling in full-width collapsable insets
While a one paragraph large collapsable inset (containing for example a tabular) could be very wide and trigger horizontal scrolling, the code that makes collapsable insets wide when they contain several paragraphs would actually make them narrower in this case.

Typical example is a wide tabular and a caption in a table float, where horizontal scrolling would not trigger.
2016-05-29 17:55:42 -04:00
Richard Heck
0e1834f2d9 Updates to splitting of consecutive environments.
From Enrico.
2016-05-28 17:43:01 -04:00
Jean-Marc Lasgouttes
ba7e2113f3 Fix some display bugs related to end of paragraph markers
There are two regressions that are fixed here:

 * empty rows at the end of a paragraph (think after newline at end of
   paragraph or empty line in Verbatim) do not have an end-of-par
   marker. This is fixed by removing the early return in breakRow and
   letting the whole function be executed. This requires to relax an
   assertion in Paragraph::fontSpan. It makes sense here to query
   position at the end of the paragraph.

 * a newline at the end of a paragraph will be followed by and
   end-of-par marker. This is fixed by skipping the end-of-par marker
   when a new row has been requested.
2016-03-25 22:22:45 +01:00
Jean-Marc Lasgouttes
3b6919217b Do not set cursor to the right of newline with mouse
When a row is broken by for example a display math inset, it is
possible to put the cursor at the end of the previous line using the
boundary setting of cursor.

For newline insets and separator insets, we want to force the cursor
to be before this inset. Also, in the other cases, do not force
boundary property (effectively reverts part of f29e7803).
2016-03-12 12:49:00 +01:00
Jean-Marc Lasgouttes
5f9053d6d3 Reset right_boundary row property when row is shortened
Fixes bug #10003.
2016-03-09 09:57:14 +01:00
Jean-Marc Lasgouttes
b4d85944a6 Set margins correctly for empty rows
Calling breakRow ensures that everything is set correctly.
2016-03-05 14:10:02 +01:00
Jean-Marc Lasgouttes
8009edd3d4 Avoid endless loop when the window is too narrow
* breakRow: remove wrong condition that would silently eat the contents of the
   paragraph when the window is narrower than left margin

 * breakRow: make sure that there is at least one element in each row

 * breakAt: when force-breaking a row element, make sure it is not empty. Doing
   so may create empty rows and therefore a endless loop.

Fixes bugs #9962 and #10001.
2016-03-03 18:08:11 +01:00
Jean-Marc Lasgouttes
8d091cfe78 Avoid making tabular too large when using a caption in longtable mode
This is a fixup to commit cdb9f043, which fixed bug #9757.

It is necessary to make a special case for inserting an InsetCaption
in a tabular cell, because this commonly happens in longtable mode.

Fixes bug #9945.
2016-01-29 10:05:48 +01:00
Jean-Marc Lasgouttes
7dbd63e2b9 When counting hfills, make sure that they are active
The active/inactive status of hfills was not checked in numberOfHFills.

The code is reorganized a bit, but the important part is the change in the above function.

Part of bug #9870.
2015-12-09 17:16:00 +01:00
Jean-Marc Lasgouttes
39e33d5138 Fix width of row when there are active hfills
It is important to make sure in computeRowMetrics that the row width
is correct at the end, because we rely on it in several places.

Fixes bug #9870.
2015-12-01 09:14:22 +01:00
Jean-Marc Lasgouttes
1f0305509b Fix length of hfills
The computation of the legth of expanded hfills did not take into account their unexpanded size. This is done now by increasing the dimension (+=) instead of merely setting it.

Moreover, since the insets sizes are integer number, rounding effects have to be taken in account. To this end, the extra number of pixels is added to the last hfill in the row.

This fixes part of bug #9860.

Note not everything is fixed by this patch: the logic of ParagraphMetrics::hfillExpansion seems bogus to me. I do not see why consecutive hfills at the beginning of a row should not be all expanded. Since I do not know what are the peculiarities of hfill handling in LaTeX, I did not change it (yet).

I did not either try to investigate the label hfill part, because I do not even know what is so special about it. I think there is a lot of old logic that nobody ever tried to question.
2015-11-24 10:11:17 +01:00
Jean-Marc Lasgouttes
d8719ade59 Implement on screen rendering of alignment in LR boxes.
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.
2015-11-23 11:40:36 +01:00
Jean-Marc Lasgouttes
89dca6d3a9 Be careful about accounting for the right margin
In computeRowMetrics, the right margin of the row shall be taken in account when the text is not left-aligned. Rewrite the code in terms of the available width `w' to avoid this pitfall.
2015-11-06 14:35:21 +01:00
Jean-Marc Lasgouttes
f7e639c818 Fix commit 32edb659
A bad test meant an embarassing red line on the left.

This is still bug #9807.
2015-10-26 11:39:58 +01:00
Jean-Marc Lasgouttes
32edb65985 Avoid showing vertical scroll mark when not necessary
Now the mark if only shown when editable text is outside of the row.

Fixes bug #9807.
2015-10-26 00:01:28 +01:00
Jean-Marc Lasgouttes
26eb5092fb Get rid of ParagraphMetrics::insetDimension
We already have a CoordCache of insets dimensions. It is not necessary
to store the same information in two places.

Give a name to CoordCache tables types to improve code readability.

Remove ParagraphMetrics::singleWidth, which is not used anymore.
2015-10-19 13:17:16 +02:00
Georg Baum
359aef92f8 Fix cursor movement for large logos (#9628)
Previously, if one clicked onto a large non-editable inset like the new LyX
logo inset, the cursor was always positioned in front of the inset, even if
the click was almost at the back edge. Now the cursor is positioned at the
correct edge. I tested this also with RTL contents, where from means right
and back means left, but the inset anchor position anchor point is still
at the left, and the right edge is dim.wid pixels to the right of it.
2015-10-11 14:21:45 +02:00
Jean-Marc Lasgouttes
e5f42f67d0 Fix display of perenthesis in Hebrew documents
This was a regression from 2.1.x. I failed to copy the horrible hack that was present for the special case of () in Hebrew.

There is a real need for someone who understands RTL language stuff to fix this. Currently () are wrong in .lyx files IMO. We should not have to swap them for display.
2015-10-09 16:16:13 +02:00
Jean-Marc Lasgouttes
21c30a09e1 Rewrite Cursor::getSurroundingPos without Bidi class
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!).
2015-09-27 22:17:46 +02:00
Jean-Marc Lasgouttes
cc241bdaaf Repeat after me: into account, into account, into account 2015-09-27 21:38:20 +02:00
Jean-Marc Lasgouttes
cdb9f04395 Make text insets wide as soon as they contain a display inset
This also handles the case of a paragraph ended by a newline.

Fixes bug #9757.
2015-09-21 17:53:52 +02:00
Jean-Marc Lasgouttes
8b89709fc9 New helper method Row::Element::isRTL() 2015-09-21 14:03:54 +02:00
Jean-Marc Lasgouttes
b68f391232 Re-implement text justification
* GuiFontMetrics::pos2x, x2pos: add support for inter-word spacing.
* GuiPainter::text: idem

* Row::Element::countSeparators:
  Row::countSeparators: new methods that count spaces in strings.
  Row::setSeparatorExtraWidth: new method (code lifted from TextMetrics.cpp).

* TextMetrics::computeRowMetrics: rely on the above methods.

* RowPainter::paintMispelledMarked: pass only a Row::Element object reference
  RowPainter::paintStringAndSel: idem; do not rely on values returned by
      Painter::text (trailing spaces do not honor wordspacing value).
2015-07-20 23:43:05 +02:00
Jean-Marc Lasgouttes
f65f3adbf7 Do not break row elements at spaces
The goal of this commit is to make painting faster by reducing the
number of strings to paint. To this end, it is necessary to include
spaces in row elements.

Also importantly, this commit should fix existing problems with line
breaking in chinese text.

* TextMetrics::breakRow: do not do anything special for word separators.

* Row::add: when adding a character to a row element, keep the string
  width updated. If need be, it is possible to tweak this by updating
  every 10 characters, for example.

* GuiFontMetrics::breakAt (new): use QTextLayout to break text either
  at word boundary or at an arbitrary width.

* Row::Element::breakAt: use the above method.

* Row::shortenIfNeeded: simplify now that because there is no need for
  handling separator elements. This will be taken care of by the
  improved breakAt.

Two things remain to be done:

* remove all traces of separator row element

* re-implement text justification.
2015-07-20 21:22:53 +02:00
Jean-Marc Lasgouttes
d328fb2021 Rewrite Cursor::posVisToRowExtremity without Bidi class
It is trivial to implement it using TextMetrics::getPosNearX.
2015-07-18 00:39:55 +02:00
Jean-Marc Lasgouttes
412a724aaf Some fixups to row margins
In breakRow set left and right margin properly for RTL paragraphs.
Remove corresponding code from ComputeRowMetrics.

In row painter, check the use of left and right margin depending on
context. The problem in the original text is that the various
leftMargin() methods actually represent right margin for RTL
paragraphs. This should be fixed eventually.
2015-07-18 00:17:00 +02:00
Jean-Marc Lasgouttes
75640b66e5 When adding completion to a row, add also the unique part
The unique and non-unique parts of the completion are show in different colors.
2015-07-15 21:38:55 +02:00
Jean-Marc Lasgouttes
c783ef962d Fix cursor setting in right-aligned text
Fixes bug #9619.
2015-06-13 12:09:53 +02:00
Juergen Spitzmueller
5f20d05b1b Fix left margin with some nested layouts (#9538) 2015-05-12 15:47:38 +02:00
Stephan Witt
93b0f9c080 #9514 contents inside of LyX insets with spell check disabled should be ignored by spell checker.
The document iterator now skips math insets and insets like notes where spell check is disabled.
The continuous spell checking is part of the row painter drawing and the spell check disabled state
has to be passed down recursively while doing the inset painting.
2015-05-06 18:39:24 +02:00
Jean-Marc
bdaa6fbb26 Do not remove separators at end of rows.
I am not sure why I addd this code at the time. I do not think there was a good reason.

Fixes bug #9447.
2015-04-16 11:39:33 +02:00
Jean-Marc Lasgouttes
11ca140667 Clean-up the undo API
* Remove the UndoKind parameter in the general interface
* move recordUndoInset to Cursor
* remove one variant of Undo::recordUndo.
* get rid of Text::recUndo.
2015-04-01 14:18:23 +02:00
Jean-Marc Lasgouttes
66fa801e74 Improve support for on screen length calculation
The computation of length on screen depend in particular of the computation of the size of an em. Many places of the code used to rely on the width of the M character, which is not really correct:
http://en.wikipedia.org/wiki/Em_%28typography%29

In digital typography, the best value to use is the point size of the font.

* Implement FontMetrics::em(), which returns the value in pixels of the EM unit.
 Convert code to use it.

* Introduce Length::inPixel(MetricsBase const &), which takes the textwidth and em information from the MetricsBase object. Convert code to use it.

* Fix several places where Length::inPixel is used without a proper em value.

* add mathed_font_em() helper function. It should eventually be removed like some other functions in MathSupport.

* Add dummy implementation of FontMetrics to tex2lyx for linking purposes.
2015-03-26 17:10:15 +01:00
Jean-Marc Lasgouttes
b627b8701b Some performance stuff reported by cppcheck 2015-02-24 18:38:20 +01:00
Jean-Marc Lasgouttes
51cc1a1cbe Do not modify the changed() status of rows when no drawing has taken place
There are several places in the code where a row is painted with drawing disabled in the painter. The goal is only to recompute inset positions.

Such a case happens in BufferView::checkCursorScrollOffset, as part of the horizontal scrolling patch. Note that this particular piece of code should eventually be removed, since it is a performance problem.

It makes sense to consider that only a real painting of a row should change its status. However, I would not be surprised if this change would break other things.

Fixes: #9388
2015-02-09 15:16:41 +01:00
Scott Kostyshak
d81fe084a6 Revert "Do not modify the changed() status of rows when no drawing has taken place"
This reverts commit c6f8f51525.

I accidentally committed this patch, which I am testing as
a fix to 9388.
2015-02-08 16:39:06 -05:00