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_.
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.
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.
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.
Change the various paint* helpers to take a single row element as argument.
Do not update x_ in the various paint* helpers. Constify them. Update x_ in paintText and paintOnlyInsets instead.
Remove an empty call to paintForeignMark in paintInset (the call did nothing since orig_x == x_ at this point).
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.
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!).
* 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).
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.
All the code that is run before row metrics have been computed should use int arithmetic. After metrics have been computed, we still need doubles because fully justified rows use double for Row::Element::extra.
Rename Row::x to Row::left_margin and change its type to int.
Rename Row::Element::width() to full_width(). In some places of the code, use dim.wid (the int version without the extra separator) because metrics have not been computed.
Let Row::Element::x2pos take a int& argument instead of double&
Let Row::Element::breakAt take a int argument instead of double
The problem was that some parts of the code assume that the right margin is part of the width of the row. This is not the case, only the left margin (Row::x) is counted.
The code has been fixed and documented to reflect this.
Moreover, breaks row at insets when there is no suitable separator.
Also make the code of Row::shorten_if_needed somewhat simpler by using
iterators and factoring the code.
Fixes: #9120
The old implementation of Row::Element::pos2x and x2pos did not work
correctly with Arabic text, because characters can have shapes that
depend on context.
This new implementation leverages QTextLayout in a simplified way,
since only one word is added to the layout.
This allows to make Row::Element::x2pos more readable.
Fixes: #9115.
All these problems are related to what happens at the extreme points of rows
* since VIRTUAL elements have a width but no contents, they have to
be treated specially at some places. It would have been better to
avoid testing for them explicitly, but I did not find a way.
* Improve and cleanup the code in breakRow and fix in passing a crash
when clicking on the right of an incomplete MARGIN_MANUAL
paragraph.
* improve the computation of row width in TextMetrics::computeRowMetrics.
* handle properly the case where a position if not found on the row
in both cursorX and getPosNearX (actually, this happens when
selecting).
* Some code cleanup and comments.
* fix handling of boundary situations in Row::Elements::x2pos;
* fix handling of boundary situations in TextMetrics::getColumnNearX;
* make sure to always use Font::isVisibleRightToLeft instead of Font::isRightToLeft;
* Improve debug messages.
Break words longer than the screen width. The code is more complicated
than I would like, but I have no better idea right now.
Implement properly the notion of a row broken by a display inset. This is useful in different places.
Also fix a bug with last line of a paragraph spotted by Kornel.
Use proper font everywhere for end-of-par marker
Fix getColumnNearX for RTL text and for centered/right-justified paragraphs.
Let computeRowMetrics update the row width.
* 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()
* Row now contains a vector of Elements
* replace Row::dump by a proper << operator
* the width is updated as elements are added
* breakRow is reimplmented to use this infrastructure
1. When a listing is inserted in a bit of text, the line above the listing is not drawn over the full width like it is done for lines above other insets. This is because InsetListing has a AlignLeft alignment. Now, if you start selecting downwards with the mouse in this empty area, strange selection drawings appear (see attachment).
This is caused by the fact that starting your selection at such a place, causes beg.boundary() to be true in TextMetrics::drawRowSelection(..). This is correct, but this value is true for _all_ selected lines. Now, the selection acts as if it is RTL text. Therefore, just like for end.boundary, this value needs to be reset for every line.
2. Starting your selection in an end margin often causes the selection in this end margin to be painted later. This is because when starting your selection in an end margin, you may have set a (possible empty) selection before really selecting the end margin. The problem is that the checksum (computed later) is the same for this empty selection and for the end margin selection. Therfore, we need a call to cur.setSelection() before evaluating cur.selection().
3. In the following two lines, it is assumed that there is only an end margin to be painted if the selection extends to the next paragraph. This is not true for the above described case of an AlignLeft Inset. Then, the margin has also be drawn within a paragraph
4. The end and begin margins are only painted when the selection extends into the following or previous paragraph. This difference is not resembled in the checksum if you first select a row completely and then procede to the next or previous paragraph as the selection remains at the end of a row. This also holds for the AlignLeft case. Therefore I added a term to the checksum to monitor whether the end and begin margins need to be drawn.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26399 a592a061-630c-0410-9148-cb99ea01b6c8
* ParagraphMetrics::computeRowSignature(): Integrate row's dimensions and selection status in the row signature.
* TextMetrics::drawParagraph(): compute the row signature here and rely on that to decide if a redraw is needed or not.
* BufferView::Private: get rid of the ViewMetricsInfo member. Just keep the ScreenUpdateStrategy.
* BufferView::draw(): full screen update even for singlePar case because the row signature will detect if something needs to be redrawn.
* Text3.cpp: get rid of hack following architecture update.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21650 a592a061-630c-0410-9148-cb99ea01b6c8
- Modifier on return type ignored
- Ambigous else
- Ambigous logical operators
- Semi-colon instead of empty block
- Missing header files
- Missing using std::XX
- Initialization out of order
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20304 a592a061-630c-0410-9148-cb99ea01b6c8
* Row:
- setSelection(): set selection begin and end for this row.
- sel_beg, sel_end: new public members.
* BufferView::draw()
- do not trigger a full repaint for selection.
- use TextMetrics::draw() instead of hand calling TextMetrics::drawParagraph().
* InsetText::draw(): don't call TextMetrics::drawSelection().
* InsetMathMBox::drawSelection(): remove.
* TextMetrics:
- drawSelection(): simplify a bit. Now private.
- redoParagraph(): memorize Row selection status.
- x2pos(): fix crash when selecting with PageDown.
- draw(): fill-in the ParPos cache before everything else and not in drawParagraph().
- drawParagraph(): take care of row selection painting.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20066 a592a061-630c-0410-9148-cb99ea01b6c8
^ Row:
- changed_: new boolean to inform change status at draw time.
- crc_: new crc_ signature
- inline pos() and endpos()
- replace width(), ascent() and descent() direct access with dimension().
* ParagraphMetrics
- do not maintain row_signature_ anymore
- rename calculateRowSignature() to computeRowSignature() and make it public
* TextMetrics
- redoParagraph(): don't clear the ParagraphMetrics row list, reuse and update it.
- rowHeight(), rowWidth(), rowBreakPoint(): take first/end positions instead of Row.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19895 a592a061-630c-0410-9148-cb99ea01b6c8