Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect spacing and bounding box #32

Open
11 tasks
sadqiang opened this issue Jan 26, 2019 · 30 comments
Open
11 tasks

Incorrect spacing and bounding box #32

sadqiang opened this issue Jan 26, 2019 · 30 comments
Assignees
Labels
Status/1. Blocked Requires another issue or pull request to be completed before being ready. Type/Bug

Comments

@sadqiang
Copy link
Contributor

sadqiang commented Jan 26, 2019

Describe the bug
There are incorrect spacing and bounding boxes as indicated by green ellipses.
The top is created by LaTeX and the bottom is created by CSharpMath.

  • comparer-05
  • comparer-00
  • comparer-01
  • comparer-02
  • comparer-04
  • comparer-07
  • comparer-08
  • comparer-09

To Reproduce
Make sure you have TeX distribution installed.
Download the VS solution from my rep: https://github.com/sadqiang/GitHubReport/tree/master/GitHubReport.

Questions

  • 1. What causes the size of LaTeX output to be smaller than that of Skia's ? I already set 12pt for both actually.
  • 2. Why can't we use the following?
\Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr)
y=\cfrac{x}{1+\cfrac{x}{1+\cfrac{x}{1}}}
\mathscr{L}\left\{f(t)\right\} = F(s) 
  • 3. Can we change the math font from the default to, for example, Palatino, Bera, etc?
@Happypig375
Copy link
Collaborator

Some of these are deficiencies from iosMath that this library was ported from. I'll keep this in mind in the upcoming rewrite.

@sadqiang
Copy link
Contributor Author

sadqiang commented Feb 1, 2019

@Happypig375 : Is there a roadmap (a schedule of updates, versioning, etc) for CSharpMath ?

@Happypig375
Copy link
Collaborator

See the bottom part of #29, basically CSharpMath is in a process of being rewritten.

@Happypig375 Happypig375 added the Status/1. Ready This issue has been confirmed and is ready to be worked on. label Jun 1, 2020
@Happypig375 Happypig375 added Status/2. Work in progress A branch has been created or a user has taken the work to implement this issue. and removed Status/1. Ready This issue has been confirmed and is ready to be worked on. labels Jun 8, 2020
@Happypig375 Happypig375 self-assigned this Jun 8, 2020
@Happypig375
Copy link
Collaborator

comparer-00
The 𝑃 case is interesting. It has a smaller glyph advance than the whole character width which makes sense for italic characters following it, but causes problems for non-italic characters such as ).
image
wpf-math, iosMath, CSharpMath and Typography follow the glyph advance resulting in the same output, while MathJax and KaTeX follow the character width, ignoring the glyph advance.

@prepare would ignoring the glyph advance be more suitable?

@prepare
Copy link

prepare commented Jun 9, 2020

I think in this case for math expression + math-font,
Exact glyph bounds should be used. (ignore glyph's advance)
(since each glyph position is controled by Math layout engine)

But if you want to layout 'human text' with general font.
It should use glyph's advance (since the result glyph advances
are processed by GSUB, GPOS)


math-asana
GSUB, GPOS with AsanaMath, LatinModernMath, XITSMath


(𝑃𝑃𝑃)
latin_modern_notepad
Notepad, LatinModernMath


@brezza92 (Typography-based MathML implementation)
What do you think about this?,

Did you use glyph's advance or exact glyph bounds?

@brezza92
Copy link

My MathML implement use glyph's advance this it my result. It has same problem.
Capture13

@prepare
Copy link

prepare commented Jun 10, 2020

I have an idea that,
a cluster of letter may be treated as a human text (eg. some variable name may need GSUB/GPOS).
and then find exact bounds of a cluster.

other else (eg math signs + - * / etc) should use exact bounds.

so (𝑃𝑃𝑃) should be split to 3 parts as image below (edited by hand).
(central part 𝑃𝑃𝑃 => a cluster of letter, can use GSUB/GPOS)

idea01
a cluster of 𝑃𝑃𝑃 with GSUB/GPOS

@Happypig375
Copy link
Collaborator

What about when italic characters are mixed with upright characters?

@prepare
Copy link

prepare commented Jun 11, 2020

What about when italic characters are mixed with upright characters?

please give me some example and your expected result

@Happypig375
Copy link
Collaborator

image

@prepare
Copy link

prepare commented Jun 11, 2020

Sure, That side effect will happen in the same GSUB/GPOS layout block

ppp_01

Then, It should be considered that => the block of consecutive letter need gsub/gpos layout process or not.

In latin script=> may not,

but in other script => may be, some script need GSUB/GPOS to get correct final output.
(eg. if the math expression contains some variable in non-latin letter).

@Happypig375
Copy link
Collaborator

So what should be considered as "a block of consecutive letters"? Same Unicode block? Same Unicode category?

@prepare
Copy link

prepare commented Jun 11, 2020

not sure if https://docs.microsoft.com/en-us/dotnet/api/system.char.isletter?view=netcore-3.1 is OK?

If all letters are latin or math char=> it is OK to use only exact bounds, no need for GSUB,GPOS.

In math layout, When to use GSUB/GPOS?,

I think when we found a char from other script. (some unicode ranges that related to script)

Not sure that If it possible to put a char from other script (eg arabic, chinese, emoji),
into math-expression or not,

If it possible, and no glyph inside a math-font, How to present it ?

and it means that block of text may need GSUB/GPOS.

@pstricks-fans
Copy link

David Carlisle told me that we cannot win. See section 7.5.5-7.5.6.

@Happypig375
Copy link
Collaborator

@pstricks-fans What is "we cannot win"?

@Happypig375
Copy link
Collaborator

@prepare

System.Char.IsLetter("𝑃P", 0) // true => 𝑃 is a letter
System.Char.IsLetter("𝑃P", 2) // true => P is a letter

@pstricks-fans
Copy link

@Happypig375 : I am not sure the meaning. It might mean it is impossible to get it right. Here is his statement.

@Happypig375
Copy link
Collaborator

@pstricks-fans I'd say that at least getting the spacing specified in the original post counts as fixing this case.

@prepare
Copy link

prepare commented Jun 12, 2020

@prepare

System.Char.IsLetter("𝑃P", 0) // true => 𝑃 is a letter
System.Char.IsLetter("𝑃P", 2) // true => P is a letter

Yes ?

ppp_01

Sure, That side effect will happen in the same GSUB/GPOS layout block


This is limitation of 𝑃P , if you put it in the same GSUB/GPOS block,

in the real world => It should be rarely used?

@prepare
Copy link

prepare commented Jun 12, 2020

After reading ...
from http://texdoc.net/texmf-dist/doc/context/documents/general/manuals/luatex.pdf#page=116

7.5.6 Script and kerning
...
...
... In 2018 fonts like Latin Modern and Pagella rely on cheatswith the boundingbox, Cambria uses staircase kerns and Lucida a mixture. Depending on howfonts evolve we might add some more control over what one can turn on and off.

EDIT:
I'm not sure that GSUB/GPOS technique is good for layout some Math fonst or not?
not sure that some Math fonts are designed with the GSUB,GPOS mechanism in mind or not?

Do you know who create/maintenance/update Latin-modern math font?

SORRY about what I've said, =>it come from my little knowledge :(

see => #32 (comment)

@Happypig375
Copy link
Collaborator

Happypig375 commented Jun 12, 2020

Latin Modern Math's last update is 6 years old and is pretty much unmaintained. However, I love its glyphs and would like to retain it as the default font.

@prepare
Copy link

prepare commented Jun 13, 2020

Useful information about Math symbols advance width

https://docs.microsoft.com/en-us/typography/develop/character-design-standards/math

@Happypig375
Copy link
Collaborator

@prepare What about storing an italic measure (glyph.MathGlyphInfo?.ItalicCorrection) when positioning each glyph? So if the current character has less italic correction than the previous character, the difference becomes additional spacing?

@prepare
Copy link

prepare commented Jun 17, 2020

I've overlooked that info!

The Math Font file (eg Latin Modern Math, Asana Math)

contain that info.

It may be used in this situation.

When a run of slanted characters is followed by a straight character (such as an operator or a delimiter), the italics correction of the last glyph is added to its advance width.

see detail more detail =>

https://docs.microsoft.com/en-us/typography/opentype/spec/math#mathitalicscorrectioninfo-table

@prepare
Copy link

prepare commented Jun 17, 2020

@brezza92, please check this info (#32 (comment)) too.

@prepare
Copy link

prepare commented Jun 25, 2020

Math Layout in "In-span" italic correction

from #32
and should be solved by (#32 (comment)
and #32 (comment))

math_italic_not_set_scriptLang
pic 1: No italic correction if not set ScriptLang property to "math"


Users can layout math manually entire process by their own MathLayout engine.

But the GlyphLayout class also have a help for layouting "in-span" italic glyph.

  1. EnableBuiltinMathItalicCorrection (LayoutFarm/Typography@ccad43b) is true by default

BUT

  1. GlyphLayout ScriptLang must be set to new ScriptLang("math") too.

see detail impl =>
LayoutFarm/Typography@ccad43b#diff-b705c14388c05643560a455e65eaf449R468


math_italic_set_scriptLang
pic 2: 'in-span' math italic correction

f_italic
pic 3: latin modern math, 20pt, math italic correction

[A] (𝐹𝐹𝐹), [B] (FFF), [C] (𝐹F𝐹)

@prepare
Copy link

prepare commented Jun 25, 2020

Please test it :)

@Happypig375
Copy link
Collaborator

Will do, thanks

@Happypig375 Happypig375 added Status/1. Ready This issue has been confirmed and is ready to be worked on. and removed Status/2. Work in progress A branch has been created or a user has taken the work to implement this issue. labels Jun 26, 2020
@Happypig375 Happypig375 added Status/1. Blocked Requires another issue or pull request to be completed before being ready. and removed Status/1. Ready This issue has been confirmed and is ready to be worked on. labels Jul 14, 2020
@Happypig375
Copy link
Collaborator

Blocked on #107 (comment)

@kevcrooks
Copy link

@Happypig375 We're having this issue too for Matrices, seems like it's the same issue?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status/1. Blocked Requires another issue or pull request to be completed before being ready. Type/Bug
Projects
None yet
Development

No branches or pull requests

6 participants