-
Notifications
You must be signed in to change notification settings - Fork 86
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
Comments
I wonder if every glyph needs the method from #44. Using that for now. I feel that something better can be done though. |
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;
} |
you can calculate once at original size => then scale it later to specific point size. |
How to calculate at original size then? |
How to get Cff Glyph's Boundssee the example on 4f11b87 please test it. |
please use branch https://github.com/LayoutFarm/Typography/tree/math_table There are some MathGlyph Data that are exposed from OpenType's MathTable. |
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?
The text was updated successfully, but these errors were encountered: