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

How to interpret Placement and MarkPlacement? #37

Closed
fschutt opened this issue Dec 8, 2020 · 4 comments
Closed

How to interpret Placement and MarkPlacement? #37

fschutt opened this issue Dec 8, 2020 · 4 comments
Labels

Comments

@fschutt
Copy link
Contributor

fschutt commented Dec 8, 2020

The Info struct is not documented, so I sadly have to ask if I understand it correctly:

  • MarkPlacement (together with is_mark) is necessary if the glyph is a diacritic mark (such as a ´ for example)
    • What do the fields (usize, Anchor, Anchor) on the MarkPlacement represent? What are the anchors relative to and why are there two of them? I could guess that the usize represents the order of the mark, but that's just my guess.
  • Placement is the placement of the glyph, respective to the glyph origin, but independent of the horizontal advance, correct?
    • I can understand the Distance(x, y), but what is the Anchor field - what are the Anchors relative to?
  • If I want to implement letter-spacing in Hebrew, is it correct to not advance the cursor x position if is_mark is set?
  • Wouldn't it be better if the position is a enum { Glyph(Placement), MarkGlyph(MarkPlacement) } - can a glyph have a Placement and MarkPlacement at the same time?

Thanks.

@wezm
Copy link
Contributor

wezm commented Dec 8, 2020

I worked on an example that covered this yesterday. I'll have it ready soon. Currently the code that we have for this is part of the Prince codebase, implemented in Mercury, so I'm needing to understand and port that as part of the example.

@wezm
Copy link
Contributor

wezm commented Dec 8, 2020

In case it's helpful in the meantime these are the docs I added to Placement and MarkPlacement yesterday:

#[derive(Debug)]
pub enum Placement {
    None,
    /// Placement offset by distance delta.
    ///
    /// Fields
    /// (delta x, delta y)
    Distance(i32, i32),
    /// Cursive anchored placement.
    ///
    /// Fields:
    /// (entry anchor point, exit anchor point)
    Anchor(Anchor, Anchor),
}

#[derive(Debug)]
pub enum MarkPlacement {
    None,
    /// An anchored mark.
    ///
    /// This is a mark where its anchor is aligned with the base glyph anchor.
    ///
    /// Fields:
    /// (base glyph index, base glyph anchor, mark anchor)
    MarkAnchor(usize, Anchor, Anchor),
    /// An overprint mark.
    ///
    /// This mark is shown at the same position as the base glyph.
    ///
    /// Fields:
    /// (base glyph index)
    MarkOverprint(usize),
}

Where the indexes are the index in the Vec<Info>

@fschutt
Copy link
Contributor Author

fschutt commented Dec 10, 2020

Cursive anchored placement

What does that mean? What is an "anchor"? What is a "cursive anchored placement", I can't find anything about that on Google. How do I calculate the final (x, y) position of the glyph from an "anchor"? Thanks.

@wezm
Copy link
Contributor

wezm commented Dec 10, 2020

What is an "anchor"?

An anchor is a point that the designer puts on a glyph to allow other glyphs to be aligned to. These FontForge docs describe it from a designer perspective. http://designwithfontforge.com/en-US/Diacritics_and_Accents.html#using-anchor-points-to-place-diacritics

What is a "cursive anchored placement",

It is gpos lookup type 3: https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-3-cursive-attachment-positioning-subtable

I can't find anything about that on Google. How do I calculate the final (x, y) position of the glyph from an "anchor"? Thanks.

You can use my in-progress code at https://github.com/yeslogic/allsorts-tools/pull/14/files as a reference. If you're able to wait a few more days, I'm working in this area each day at work. I'm currently working on SVG output support in order to be able to test Allsorts against the unicode text-rendering-tests, which will:

  1. Test the glyph positioning code that I've written.
  2. Necessitate implementing a mechanism to decompose the contours into drawing instructions. (Solving How to get the contours of a glyph? #38)
  3. Generate SVG from the drawing instructions.

The intention is for the contour decomposition and positioning code to make it back into Allsorts, so you won't need to tackle this yourself.

You may be wondering why we don't already have code to do that. The reason is Allsorts was created and extracted from Prince. The non-Rust Prince code currently handles glyph positioning for us. Additionally, since our target medium is PDF, we never need to interpret the glyphs themselves. We are interested in building out the library to be more general though, which is what I'm working on now.

@wezm wezm added the question label Jan 3, 2023
@wezm wezm closed this as completed Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants