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

Bounding boxes for CFF glyphs #110

Closed
Happypig375 opened this issue May 22, 2018 · 6 comments
Closed

Bounding boxes for CFF glyphs #110

Happypig375 opened this issue May 22, 2018 · 6 comments

Comments

@Happypig375
Copy link
Contributor

Currently the Bounds property is not assigned and remains zero. I can figure out how to get the horizontal bounds by looking at the GlyphWidth operation, but I cannot find any information about the vertical bounds. Any idea on how this can be done?

@Happypig375
Copy link
Contributor Author

Happypig375 commented May 22, 2018

I wonder if every glyph needs the method from #44. Using that for now. I feel that something better can be done though.
Edit: Nope, that method still requires Glyph.Bounds. Moving on...

@Happypig375
Copy link
Contributor Author

Happypig375 commented May 22, 2018

I don't know about the performance, but this seems to be okay:

using System.Drawing;
class GlyphPathBuilder : Typography.Contours.GlyphPathBuilderBase
{
    public GlyphPathBuilder(Typography.OpenFont.Typeface typeface) : base(typeface)
    {
    }
}
    public RectangleF[] GetBoundingRectsForGlyphs((Typeface Typeface, float PointSize) font, Glyph[] glyphs)
    {
      var rects = new RectangleF[glyphs.Length];
      var b = new GlyphPathBuilder(font.Typeface);
      var tx = new Typography.Contours.GlyphContourBuilder();
      var flattener = new Typography.Contours.GlyphPartFlattener();
      for (int i = 0; i < glyphs.Length; i++) {
        b.BuildFromGlyph(glyphs[i], font.PointSize);
        b.ReadShapes(tx);
        tx.CloseContour();
        float _minX = 0f, _maxX = 0f, _minY = 0f, _maxY = 0f,
               minX = float.MaxValue, maxX = float.MinValue, minY = float.MaxValue, maxY = float.MinValue;
        foreach (var c in tx.GetContours()) {
          c.Flatten(flattener);
          c.FindBounds(ref _minX, ref _minY, ref _maxX, ref _maxY);
          if (_minX < minX) minX = _minX;
          if (_minY < minY) minY = _minY;
          if (_maxX > maxX) maxX = _maxX;
          if (_maxY > maxY) maxY = _maxY;
        }
        rects[i] = RectangleF.FromLTRB(minX, minY, maxX, maxY);
      }
      return rects;
    }

@prepare
Copy link
Member

prepare commented May 22, 2018

you can calculate once at original size => then scale it later to specific point size.

@Happypig375
Copy link
Contributor Author

How to calculate at original size then?

@prepare
Copy link
Member

prepare commented May 22, 2018

How to get Cff Glyph's Bounds

see the example on 4f11b87

please test it.


@prepare prepare closed this as completed May 22, 2018
@prepare
Copy link
Member

prepare commented May 22, 2018

@Happypig375 ,

please use branch https://github.com/LayoutFarm/Typography/tree/math_table

There are some MathGlyph Data that are exposed from OpenType's MathTable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants