Commit Graph

308 Commits

Author SHA1 Message Date
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
Jean-Marc Lasgouttes
c6f8f51525 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.

It makes sens 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-08 16:18:56 -05:00
Jean-Marc Lasgouttes
9c55af4a22 Merge remote-tracking branch 'features/scroll-reloaded'
This implement horizontal scrolling of rows to allow editing insets
(math, tabular...) that are larger then the screen. The scrolling happens
as the cursor moves, in order to make sure that the cursor is always visible.
This effectively closes an 11 years old bug.

This feature is the result of the work of Hashini Senaratne as part of
Google Summer of Code 2013. The code has been cleaned-up for inclusion
and remaining bugs have been fixed.

Fixes bug: #1083.
2015-01-10 18:39:09 +01:00
Jean-Marc Lasgouttes
52236503d3 Add marks to indicate when a row is too large
A dotted line is shown on the left or on the right to indicate that a part of the row is not visible.

Add a color code for the scroll indicator
2015-01-07 22:55:11 +01:00
Jean-Marc Lasgouttes
c6e1db7682 Fix some display glitches
* When doing a redraw with drawing disabled (to set inset positions properly), take horizontal scroll offset in account

* reset horizontal scroll offset when it is smaller than the left margin.

* when drawing a paragraph, do not modify x globally, only for the row that is offset.
2015-01-07 22:55:11 +01:00
Jean-Marc Lasgouttes
fcaf5b5fc8 Remove the special horizontal scrolling support in InsetTabular
It is not necessary anymore now that there is a global mechanism.

Also, fix the clearing of rows in SingleParUpdate mode.
2015-01-07 22:55:11 +01:00
Hashini Senaratne
5a361b35cf Keyboard based horizontal scrolling for wide insets
[This commit is the output of the "horizontal scrolling" GSoC 2013
 project, by Hashini Senaratne. The code has been cleaned up, some
 variables have been renamed and moved from the Cursor class to
 BufferView::Private. This is the base from which I (jmarc) will polish
 the feature for landing on master.

 Below is the original commit log of Hashini, updated to reflect the
 changes that have been done.]

This feature also applicable for other insets; graphics and labels.

This implementation is capable of scrolling a single row when reaching
its content which is beyond the screen limits, using left and right
arrow keys.

The attribute 'horiz_scroll_offset_' introduced in the
BufferView::Private class plays a main role in horizontal scrolling of
the wide rows that grow beyond the screen limits. This attribute
represents by how much pixels the current row that the text cursor
lies in should be get scrolled.

The main logic that is responsible for drawing the scrolled rows is
within the BufferView class, BufferView::checkCursorScrollOffset.

 * The main logic is called via BufferView::draw.

 * What this does is set the horiz_scroll_offset_ attribute in in order to
 show the position that the text cursor lies in.

 * To make sure that BufferView::draw gets involved when Update flag is
 FitCursor, necessary changes are made in BufferView::processUpdateFlags.

Basically what the logic that used to set the horiz_scroll_offset_
does is,

 * The row which the text cursor lies in is identified by a
 CursorSlice that points to the beginning of the row. This is the
 'rowSlice' variable used in BufferView::checkCursorScrollOffset. Acessors
 are added to obtain this variable. Here row objects were not used to
 identify the current row, because it appears that row objects can
 disappear when doing a decoration update for example. This means that
 comparing row pointers is not a good idea, because they can change
 without notice.

 * Stop calculations of horiz_scroll_offset_ variable, if metrics have not been
 computed yet. Otherwise the calls to TextMetrics::parMetrics, calls
 redoParagraph and may change the row heigths. Therefore vertical scrolling
 feature may get disturbed. This is avoided.

 * Using BufferView::::setCurrentRowSlice resets horiz_scroll_offset_
 when changing cursor row. This is done in order to prevent unwanted
 scrolling that happens when changing the selected row using up and
 down arrow keys.

 * Recompute inset positions before checking scoll offset of the row, by
 painting the row insets with drawing disabled. This is done because the
 position of insets is computed within the drawing procedure.

 * Current x position of the text cursor is compared with the
 horiz_scroll_offset_ value and the other variables like row.width(),
 bv.workWidth(). Compute the new horiz_scroll_offset_ value in order
 to show where the text cursor lies in. The basics conditions that we
 check before recomputing it are, if the text cursor lies rightward to
 the current right screen boundary, if the text cursor lies leftward
 to the current left screen boundary, if the text cursor lies within
 screen boundaries but the length of the row is less than the left
 boundary of the screen (this happens when we delete some content of
 the row using delete key or backspace key).

 * Change update strategy when scrooll offset has changed. This allows to
 redraw the row when no drawing was scheduled. By doing so, it was
 possible to redraw a wide row when moving to the leftmost position of the
 wide row, from the leftmost position of the row below, using the left
 arrow key.

In TextMetrics::drawParagraph it is checked whether the current row is
what is drawing now. If it is so, the value used to the x value of the row
for drawing is adapted according to BufferView::horizScrollOffset.

The method used to pass boundary() was fixed to get row when cursor was in
a nested inset. This matter is considered in Cursor::textRow and it is
modified accordingly.

GuiWorkArea::Private::showCursor() is modified to show the cursor position
in a scrolled row.
2015-01-07 22:55:11 +01:00
Jean-Marc Lasgouttes
38dc763e50 Turn a double variable into an int.
This is a better fix than 0ad9d46068, and was just as simple.
2015-01-07 22:42:14 +01:00
Jean-Marc Lasgouttes
0ad9d46068 Fix some warnings 2015-01-07 21:27:53 +01:00
Jean-Marc Lasgouttes
e32a3e7f57 Reduce use of double variables in Row
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
2014-12-22 14:07:24 +01:00
Richard Heck
8b57600a1c Fix warnings. 2014-10-27 10:42:03 -04:00
Jean-Marc Lasgouttes
2737f82139 Fix bug #9288: Cannot position cursor near the end of a line.
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.
2014-10-19 15:38:38 +02:00
Jean-Marc Lasgouttes
ac018bd8db Fix ticket #9224: text overflows through adjacent insets
The logic of Row::shortenIfNeeded is completely changed to look at the row from the start and not the end. This leads to clearer code.
2014-10-16 14:53:54 +02:00
Jean-Marc Lasgouttes
d605048b5c Fix ticket #9276: Labeling cursor off by several characters
The length of STRING row elements is not updated until finalizeLast() is called.
2014-10-09 22:09:33 +02:00
Jean-Marc Lasgouttes
37fd7b24ba Use enum instead of int in TextMetrics::getAlign
This is just a code cleanup, no (intented) effect.
2014-07-29 11:05:14 +02:00
Jean-Marc
f29e78039d More tweaking of boundary setting at end of row 2014-07-28 23:31:32 +02:00
Jean-Marc Lasgouttes
f9caebd29f Fix compilation warnings on windows. 2014-07-28 09:46:13 +02:00
Jean-Marc Lasgouttes
8fb1aa51f8 Whitespace only 2014-07-25 22:40:48 +02:00
Jean-Marc Lasgouttes
5e126d2920 Whitespace only 2014-07-25 22:36:20 +02:00
Jean-Marc Lasgouttes
b54deb3683 Rename rowpainter.* to RowPainter.*
This is the convention for files that define classes.
2014-07-25 21:55:08 +02:00
Jean-Marc Lasgouttes
bbe6e9f593 Revert optimization where several words are drawn at the same time
This can only be done where splitting of string is identical in row breaking and display. It will be possible to reintroduce this when row painting uses the tokenized row information.
2014-07-20 18:54:31 +02:00
Jean-Marc Lasgouttes
45eb314a86 Get rid of rtl_support preference
This variable was introduced to guard against any bad consequence of the then-new right-to-left
languages support. Let's be bold and get rid of it altogether!

Now right to left support is always enabled.
2014-07-09 21:11:08 +02:00
Jean-Marc Lasgouttes
f3924a52b3 Reintroduce the code related to InsetEnvSeparator
This commits (tries to) reintroduce properly the code that was reverted at the beginning of this branch. This had to be done because these patches interefered with the big refactoring of TextMetrics.cpp.

This commit reintroduces the changes to TextMetrics.cpp contained in c668ebf6, c85dbfea9 and 061509bf.
2014-07-08 21:30:06 +02:00
Jean-Marc Lasgouttes
e1c4cb7146 Fix breaking of loooong word in RTL languages
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
2014-07-08 21:30:05 +02:00
Jean-Marc Lasgouttes
b0543270a9 Remove debug code from TextMetrics
After this, it is possible to remove one parameter to getPosNearX.
2014-07-08 21:29:52 +02:00
Jean-Marc Lasgouttes
b8170e0e01 Fix various selection-related problems
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.
2014-07-08 21:23:59 +02:00
Jean-Marc Lasgouttes
1a4b3201e7 Update README and do a small code cleanup 2014-07-08 21:23:58 +02:00
Jean-Marc Lasgouttes
f686375eec Change getColumnNearX to getPosNearX
The semantics was bad: the old implementation would return pos - row.pos(), and then all user of the function had to re-add row.pos().
2014-07-08 21:10:47 +02:00
Jean-Marc Lasgouttes
79014c7551 More fixes to cursorX
In Row::Element::pos2x, handle the boundaries in a cleaner way.
2014-06-25 17:55:30 +02:00
Jean-Marc Lasgouttes
8649ac7fe6 Some fixes related to RTL text
* 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.
2014-06-25 17:55:30 +02:00
Jean-Marc Lasgouttes
443a453427 New reverseRTL implementation
The old version was a bit complicated and wrong for RtL paragraphs
containing LtR text. THe new one is clearer.
2014-06-25 17:55:30 +02:00
Jean-Marc Lasgouttes
059de2d04c Fix getColumnNearX for nested insets
The horizontal position of the inset was not taken in account.
The rounding is not always the same as with the old code, but this
is not really important.

Additional changes:

 * improve debug output of rows

 * remove Bidi& argument of the RowPainter constructor, since it is always
   an empty Bifi that is passed. This means that the Bidi class is not
   used at all any more in TextMetrics.cpp. The only remaining user is
   RowPainter.
2014-06-25 17:55:30 +02:00