Recent

Author Topic: Full support for fonts with ligatures ?  (Read 8416 times)

guest58172

  • Guest
Full support for fonts with ligatures ?
« on: August 31, 2016, 01:08:07 pm »
This is a feature request. The other day I've landed here: https://github.com/tonsky/FiraCode. Then I've setup the font and tested it in Coedit, a D IDE that I develop and whose code editor is based on synedit.

It works fine as long as there's no selection (see the attachements, ligature is for => in a lambda). It seems that the ligature is lost when I select only the first char of a couple because of a special highlighting.

Would this be solvable by synedit ?

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Full support for fonts with ligatures ?
« Reply #1 on: September 01, 2016, 05:15:24 am »
Would this be solvable by synedit ?
I think it wouldn't.
AFAIK Ligature is showing one character when two defined chars are paired.
another famous ligature is the paired "fi" (see attachment)..
so by default the two chars (or two glyph in font-design world) f+i will be replaced with single glyph "fi".
When only one of them is selected, we should paint glyph "f" with background-color differently than glyph "i", this situation will require to "f" partially then "i" independently.
You know, when glyph "f" drawn independently then ligature wouldn't be applied, also the "i".
I think the Ligature is OS (font management system) feature rather than the SynEdit ability.


Further, CMIIW, your synedit never know about ligature at all. is it?


Anyway, the breaking rule of ligature (when one of the paired char was selected) is just correct. Nothing wrong with it.
I think that's the only chance user have to decide whether to delete only the selected char, or replace that with another, or just let user do whatever he/she wanted to do. 8-)

When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Full support for fonts with ligatures ?
« Reply #2 on: September 01, 2016, 05:19:15 am »
to prove, would you like to show us of that same line with the entire line selected ?
I guess your ligature is fine when both chars are selected.
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

guest58172

  • Guest
Re: Full support for fonts with ligatures ?
« Reply #3 on: September 01, 2016, 09:45:22 am »
When the two lines are selected the ligature is drawn. I also suspected that it was caused by the usage of TSynEdit.SetHighlightSearch which is used to make identifier markup (if you look at the second screenshot of the first post, all the = are highlighted, not only the one that's selected), but the ligature was also broken when I deactivated the feature.

But I can confirm that synedit is responsible. I've tested with Geany and the selection doesn't break the ligature.

Thaddy

  • Hero Member
  • *****
  • Posts: 14215
  • Probably until I exterminate Putin.
Re: Full support for fonts with ligatures ?
« Reply #4 on: September 01, 2016, 10:36:50 am »
Yes, geany works.
But it should be possible in synedit by implementing a look-ahead during selection
Specialize a type, not a var.

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: Full support for fonts with ligatures ?
« Reply #5 on: September 01, 2016, 02:48:22 pm »
This is probably caused by the way sysnedit draws the text.
It is drawn token by token, whichs means every change of background, color, style or borders causes a new token.
So the break is between = and > and the textoutput is also split into = and >.
While Geady perhaps draws the background and then the complete text where = and > are drawn at once.

To accomplish this synedit has to split the drawing of background an text. So that there can be other token breaks
for background an text. But this will also not work if you change the text style or color for selected text.
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Full support for fonts with ligatures ?
« Reply #6 on: September 10, 2016, 03:00:51 pm »
There are several textdrawing API in windows. The one used by SynEdit has a few limits. Most important SynEdit can only use it for monospaced text. The API can output proportional, but SynEdit would not be able to place the caret, or draw the next token in the correct pos.
To change this, SynEdit would need full support for proportional fonts. That is a huge rewrite...

So when talking ligatures the first distinction that must be made is: Does the ligature have the same wide as the individual chars.
- the ligature for "=>" may actually have the width of 2 monospaced chars
- the ligature for "fi" may be smaller
SynEdit can tell windows to force the width, but that can look extremely ugly.

If monospacing would be kept by the ligature, the next challenge is to find start and end of ligatures. Some fonts replace entire words with one ligature.

If it was only combinations of max 2 chars, then SynEdits textdrawer could re-output one extra char on both sides of each token, and use clipping to prevent them from being drawn (since they already are, or still will be drawn).
That would work for colors, but may have side effects if font-style (bold, italics) changes.

Also note, that synedit would still treat the ligature as individual chars, allowing the caret in the middle of it, or selecting half of it. (which is why changes to bold/italic could be awkward, if half the ligature was bold, and the other was not)

SynEdit does some of this for Arabic scripts (actually all RTL text), but it is very inefficient.

See
unit LazSynTextArea;
line 1509
    if ATokenInfo.RtlInfo.IsRtl then begin

You can look at this for your own copy of SynEdit.
For proper adding of this function, SynEdit would need to use a different drawing API. (And ideally support exchangeable classes for old/new drawing)

guest58172

  • Guest
Re: Full support for fonts with ligatures ?
« Reply #7 on: September 22, 2016, 09:43:15 am »
the case I'm talking about is a programming font so fixed-width. The editor that works, there are others but I've just tested with geany, selects the space that would be occupied by the equality symbol when only the first char of => is selected.

I'm not sure that the fi example is relevant. Here we talk about synedit so the font has to be monospaced, this is not an option.

Thaddy

  • Hero Member
  • *****
  • Posts: 14215
  • Probably until I exterminate Putin.
Re: Full support for fonts with ligatures ?
« Reply #8 on: September 22, 2016, 10:10:22 am »
the case I'm talking about is a programming font so fixed-width. The editor that works, there are others but I've just tested with geany, selects the space that would be occupied by the equality symbol when only the first char of => is selected.

I'm not sure that the fi example is relevant. Here we talk about synedit so the font has to be monospaced, this is not an option.
Actually, the type of font (as far as fixed or variable) does not matter at all. The issue is the look-ahead to determine if there is a pair.
If synedit would use the code for ttf -freetype fonts that is already in fpc libs the matter would be fixed by default. And yes, that has an inevitable speed penalty.
If Geany can do it, there is no case to be made that it should not be possible or slow: Geany does not even optimize with assembler and there is no reason fpc generated code would be slower than C.
« Last Edit: September 22, 2016, 10:29:15 am by Thaddy »
Specialize a type, not a var.

guest58172

  • Guest
Re: Full support for fonts with ligatures ?
« Reply #9 on: September 22, 2016, 10:02:05 pm »
Let's forget this if adding support implies an impact on the performances.
It was even not a formal feature request. Just a question.

 

TinyPortal © 2005-2018