Commit Graph

97 Commits

Author SHA1 Message Date
Jean-Marc Lasgouttes
d694701315 Last step of transition: use sortenIfNeeded again.
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 :)
2021-12-07 17:04:47 +01:00
Jean-Marc Lasgouttes
890fcc0872 Change the way the element's width is updated.
Remove the code that computed the width every 30 characters (yay!).
Make sure that finalizeLast() is called after inserting a row element in
a row in breakParagraph.
2021-12-07 17:04:47 +01:00
Jean-Marc Lasgouttes
963a0aa466 Implement Row::Element::row_flags
Move the enum definition RowFlags in its own include file, to avoid
loading Inset.h. Document it more thoroughly.

Rename RowAfter to AlwaysBreakAfter.

Add CanBreakInside (rows that can be themselves broken). This allow to
differentiate elements before bodyPos() and allows to remove a
parameter to shortenIfNeeded().

Make the Inset::rowFlags() method return int instead of RowFlags, as
should be done for all the bitwise flags. Remove the hand-made bitwise
operators.

Set R::E::row_flags when creating elements.
* INSET elements use the inset's rowFLags();
* virtual element forbid breaking before them, and inherit the *After
  flags from the previous element of the row;
* STRING elements usr CanBreakInside, except before bodyPos.

More stuff may be added later.
2021-12-07 17:04:47 +01:00
Jean-Marc Lasgouttes
a558f78aa5 Small Row cleanups
Move declaration of RowList to Row.h

Move initialization of POD members of Row and Row::Element to declaration.

Make method isVirtual() depend on type.

Add new row element type INVALID and method isValid()

Make methods R::E::left/right_pos inline.

Add method R::E::splitAt() that returns an element containing the
remaining stuff, or an invalid element if nothing was split. breakAt
is now a simple wrapper around this function.

Add method R::push_back().
2021-12-07 17:04:46 +01:00
Jean-Marc Lasgouttes
1831f6caac Change FontMetrics::breakAt to return a position
Since we intend to break the row element in two, it is not good to
truncate the string too early.

Moreover, the row element width is now set at this point, even if no
breaking occurs.
2021-12-07 17:04:46 +01:00
Jean-Marc Lasgouttes
e1261817d2 fix Row::findElement when there is a Virtual element 2021-01-06 18:49:41 +01:00
Jean-Marc Lasgouttes
51b37cd4d8 Remove some useless Row:: prefixes 2021-01-06 18:15:19 +01:00
Yuriy Skalko
59e2becdd8 Use iround function, amend c0ce79452f 2020-11-27 12:16:50 +02:00
Yuriy Skalko
196d9caeb0 Clean includes using the output of iwyu tool 2020-10-20 11:38:55 +03:00
Jean-Marc Lasgouttes
32f06d01ec Revert "Improve handling of top and bottom margin"
It turns out this is not ready at all.

This reverts commit ff7cdf1b74.
2020-07-13 00:00:36 +02:00
Jean-Marc Lasgouttes
ff7cdf1b74 Improve handling of top and bottom margin
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.
2020-07-12 20:32:04 +02:00
Jean-Marc Lasgouttes
3fea3b0096 Allow row-breaking after some insets
Add new RowFlags value CanBreakAfter, which says that the row can be
broken after the inset if needed. There is no CanBreakBefore yet,
because I do not know of an inset that needs it.

This makes screen closer to the actual behavior of insets.

Currently, only unprotected spaces and some special characters are
concerned. There may be more that need this handling.

Fixes bug #11621.
2020-06-23 23:34:49 +02:00
Jean-Marc Lasgouttes
f96e2f3a6a The hard-coding of word_wrap has been fixed at bf88ad49. 2020-06-23 00:10:41 +02:00
Jean-Marc Lasgouttes
ce950f1ea5 Fixup b321bb1a: set changebar when inset contains changes
Add Paragraph::isChanged() and InetText::isCgchanged() which indicate
the presence of a change in the relevant object.

Sets Row::needsChangebar() when adding an inset that contains changes.

Related to bug #8645.
2020-01-12 20:26:35 +01:00
Jean-Marc Lasgouttes
bf88ad495c Make Word Wrap property confiurable by language
It is now possible to specify in the lib/language file whether screen
rows can be broken anywhere (CJK languages) or only at work boundary.

Set WordWrap to false for the CJK languages (notice that japanese-cjk
had been forgotten before).

Moreover, remove a test for separators in row element that was not
really helpful.

Fixes part of ticket #10299.
2019-06-05 15:50:53 +02:00
Jean-Marc Lasgouttes
26c2811cc4 Some Asian langagues allow to wrap text at any position
This is hardcoded for now for simplicity and to allow backporting to
2.3.

The behavior is unchanged for all languages but Chinese, Japanese or
Korean.

Fixes part of bug #10299.
2019-05-15 17:38:26 +02:00
Jean-Marc Lasgouttes
6df593049c Revert "Try to compute row height like it should be done"
This is not done right at all. The best is to revert for now and
think about how to do it properly.

This reverts commit 66a3d64346.
2019-05-13 10:47:47 +02:00
Jean-Marc Lasgouttes
66a3d64346 Try to compute row height like it should be done
Currently, our computation of row height is not completely standard:
* we ignore completely the QFontMetrics::leading() parameter

* we add arbitrarily 2 hardcoded pixels to the height.

This patch reverses these two choices, which leads to
* slightly larger spacing for MinionPro (which has a big leading).

* an additional spacing of 20% font height that depends on dpi and zoom.

Visual inspection with LibreOffice seems to imply that it disregards
the font leading but uses a interline which is 20% larger than the
font height.
2019-01-16 11:04:53 +01:00
Jean-Marc Lasgouttes
654cded167 Partial cleanup of the row selection code
This is preliminary work, this code still feels too complicated for
its own good.

Let Row::isMarginSelected return false when Row::selection() is false
(the other changes are indentation).

This allows to remove the test for selection() in
setSelectionAndMargins, so that begin/end_margin_sel are always set
correctly.

Add clearSelectionAndMargins() instead of calling directly setSelection
(which is now private) with arguments (-1, -1).

Fixes bug #10972.
2018-01-15 17:20:34 +01:00
Jean-Marc Lasgouttes
0f18bb54cc Change parameter name
It was a same as a Row member

Fixes bug #10921.
2017-12-14 16:00:00 +01:00
Jean-Marc Lasgouttes
ae60749f89 Make sure that rows are repainted when they get (un)selected
The bug is the following: when selecting several paragraphs quickly
enough, some rows do not get selected.This is a consequence of the
removal of row crc, which lead to not taking into account the
selection status of the row in the decision to repaint.

The solution chosen here is to add a Row::change() helper function to
modify row members. This will set the Row changed status whenever the
value of the member changes.
2017-11-29 11:38:33 +01:00
Jean-Marc Lasgouttes
9e2da4a3ea Remove row crc computation
This computation did not make sense anymore since we began to put the
contents in the Row object. The fact that it worked was a coincidence.

Instead, we set rows as changed() on creation and reset that once they
have been drawn. This will allow in the future for a finer definition
of what to redraw or not.

Also update the PAINTING_ANALYSIS document
2017-11-11 13:24:08 +01:00
Jean-Marc Lasgouttes
4858bb3bb6 Store change bar information in row element
It is wrong to compute this at paint time. In general, painting a row
should not require any access to a paragraph object, but we are far
from there now.
2017-11-11 13:24:08 +01:00
Richard Heck
75bfed5507 Fix trailing whitespace in cpp files. 2017-07-03 13:53:14 -04:00
Jean-Marc Lasgouttes
20696ecb7e Try to preserve small details from eb4a2a19
Part of ticket #10569
2017-04-10 11:21:29 +02:00
Jean-Marc Lasgouttes
8769c0fb75 Row::Element::x2pos: go to nearest point also over insets
getPosNearX, which is the only user of x2pos, should always return the
nearest position.

In editXY, there is a need to return the position where the inset
stands, but it is done using checkInsetHit.

This is a simplification of commit eb4a2a19, which has been reverted
at 01f0ab64a.

Fixes part of bug #10569.
2017-04-06 15:18:15 +02:00
Jean-Marc Lasgouttes
01f0ab64a7 Revert "When selecting text with the mouse, inset selection happens in the middle"
This reverts commit eb4a2a190f.
2017-04-06 15:17:00 +02:00
Guillaume Munch
76f3f6eb01 Fix warning 2017-03-05 08:45:52 +01:00
Guillaume Munch
eb4a2a190f When selecting text with the mouse, inset selection happens in the middle 2017-02-18 23:03:53 +01:00
Jean-Marc Lasgouttes
1fca708c7f Move TextMetrics::findRowElement to Row class 2017-02-02 15:35:03 +01:00
Jean-Marc Lasgouttes
57c3a94730 Add RtL information to Row
This allows to somewhat simplify the text and avoid some uses of
Paragraph (in the long term, RowPainter should not have to access
these things).

At the same time do a small cleanup to RowPainter: rename
text_metrics_ to tm_, remove pm_ and width_.
2017-02-02 14:53:01 +01:00
Jean-Marc Lasgouttes
8e7d0c2002 Fix flushing of row that was cut after an hyphen
When using Qt stuff in breakAt, it may happen that the row is broken
after an hyphen (whereas the old code would only consider spaces).

The fact that we abuse the Row::right_boundary() property to detect when
a row should be flushed broke justification when a row is cut at an
hyphen.

Fix this by introducing a new Row::flushed() property and set it as needed.
2017-01-27 16:09:03 +01:00
Jean-Marc Lasgouttes
8491962c6b Fix wrong splitting of text row
The code that tries to decide whether it is worth splitting a given
text row element had a shortcoming: it did not take into account the
left margin of the new row that would be created.

The problem is that this left margin is not the same as the left
margin of the current row, because there can be for example
indentation effects.

To fix this problem, we pass the amount of available space on the
next row as a parameter of Row::shortenIfNeeded.

Note that there is no need to care about RtL row elements at this
point, since the bidi algorithm will be applied to the row
subsequently.
2017-01-26 14:16:24 +01:00
Guillaume Munch
34b6b474ea Amend b30f8d3c
Fix assertion. Thanks Scott for the bisect and the trace.
2016-11-21 12:09:48 +01:00
Guillaume Munch
b30f8d3c4b On-screen justification: stretch in proportion with the em, up to a limit
1) Distinguish expanding characters from separators, to fit with Qt's notion of
expanding character which comes from the Unicode std.  CountExpanders() is moved
to FontMetrics to fix a discrepancy with the duplicate implementation from
598f7e4a.

2) Make these expanders stretch on-screen proportionally to the em of the font.
If a row mixes large and small text, LyX let us see which spaces are set in the
bigger font.

3) Now that the stretch is defined in ems, add a limit such that an expander
never stretches more than 1.5em to avoid weird and hard to read justified lines.

4) Add a return boolean to setSeparatorExtraWidth for future use.
2016-11-06 12:20:00 +01: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
Richard Heck
0e1834f2d9 Updates to splitting of consecutive environments.
From Enrico.
2016-05-28 17:43:01 -04: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
31471496fd Allow breaking a row element at a leading/trailing space
When an inset is separated from the adjacent string by a space, it is
reasonable to be able to break the string after the space.
Unfortunately, QTextLayout does not do that.

This patch reverts the workaround inserted in 71378268 and replaces it
with a different trick: the string is enlosed between a pair of
zero-width non breaking space characters, so that the leading/trailing
spaces are now normal spaces, where QTextLayout will agree to break
the string.

    Fixes bug #9921 for good.
2016-02-04 08:45:27 +01:00
Jean-Marc Lasgouttes
7137826896 Allow breaking a row element at a leading space
When an inset is separated from the next strng by a space, it is reasonable to be able to break the string after its leading space.

Fixes bug #9921
2016-01-19 09:55:31 +01:00
Jean-Marc Lasgouttes
b5871decc0 Justify row correctly after double space
The wordSpacing property of a QFont object applies only once when there are multiple spaces between words. Therefore Row::Element::countSeparators shall not count spaces, but groups of spaces.

Fixes bug #9808.
2015-10-28 14:03:01 +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
8b89709fc9 New helper method Row::Element::isRTL() 2015-09-21 14:03:54 +02:00
Jean-Marc Lasgouttes
f921c2e8ec Fix some row breaking problems with large insets
When a row is too large due to a wide inset, it does not make sense to
break text before if the problem is the same in the next row.
Therefore give up breaking in this case.

Note that this was explicitely taken care of in the old-world
rowBreakPoint code.

Fixes bug #9691.
2015-08-24 14:09:19 +02:00
Jean-Marc Lasgouttes
d893400f93 Another go at improving row shortening
Instead of remembering the last breakable element in the row, search
backward in the row and consider all string elements one by one until
a correct place to break is found.

This fixes the case where the row ends with a string, but there is no
space soon enough in the string to break it here. In this case, we
need to consider the previous row.
2015-07-23 00:39:27 +02:00
Jean-Marc Lasgouttes
7d19265ba0 Do not break row at inset boundary if possible
The first change is to concentrate on the last ro elements that contain separators and try to break it a a width that is shorter than both
- its current width (we want to break it, after all)
- the amount of space available.

This simple heuristic seems to give good results.
2015-07-22 11:54:04 +02:00
Jean-Marc Lasgouttes
371bd2b1e5 Get rid of SEPARATOR row element type
It is not used anymore.

Also get rid of a comment made irrelevant by recent changes.
2015-07-21 09:51:52 +02:00
Jean-Marc
25727ee5a8 Only compute string length every 30 characters
This makes paragraph rebreaking muh much faster, at least on my ancient iMac Core 2 Duo.
2015-07-21 00:20:42 +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