internal Glyph(Renderer renderer, PointF[] points, int[] contours, float linearHorizontalAdvance) { this.renderer = renderer; this.points = points; this.contours = contours; // find the bounding box var min = new Vector2(float.MaxValue, float.MaxValue); var max = new Vector2(float.MinValue, float.MinValue); var pointCount = points.Length - 4; for (int i = 0; i < pointCount; i++) { min = Vector2.Min(min, points[i].P); max = Vector2.Max(max, points[i].P); } // save the "pure" size of the glyph, in fractional pixels var size = max - min; Width = size.X; Height = size.Y; // find the "render" size of the glyph, in whole pixels var shiftX = (int)Math.Floor(min.X); var shiftY = (int)Math.Floor(min.Y); RenderWidth = (int)Math.Ceiling(max.X) - shiftX; RenderHeight = (int)Math.Ceiling(max.Y) - shiftY; // translate the points so that 0,0 is at the bottom left corner var offset = new Vector2(-shiftX, -shiftY); for (int i = 0; i < pointCount; i++) { points[i] = points[i].Offset(offset); } HorizontalMetrics = new GlyphMetrics(new Vector2(min.X, max.Y), points[pointCount + 1].P.X - points[pointCount].P.X, linearHorizontalAdvance); // TODO: vertical metrics }
internal Glyph(Renderer renderer, PointF[] points, int[] contours, float linearHorizontalAdvance) { this.renderer = renderer; this.points = points; this.contours = contours; // find the bounding box var min = new Vector2(float.MaxValue, float.MaxValue); var max = new Vector2(float.MinValue, float.MinValue); var pointCount = points.Length - 4; for (int i = 0; i < pointCount; i++) { min = Vector2.Min(min, points[i].P); max = Vector2.Max(max, points[i].P); } // save the "pure" size of the glyph, in fractional pixels var size = max - min; Width = size.X; Height = size.Y; // find the "render" size of the glyph, in whole pixels var shiftX = (int)Math.Floor(min.X); var shiftY = (int)Math.Floor(min.Y); RenderWidth = (int)Math.Ceiling(max.X) - shiftX; RenderHeight = (int)Math.Ceiling(max.Y) - shiftY; // translate the points so that 0,0 is at the bottom left corner var offset = new Vector2(-shiftX, -shiftY); for (int i = 0; i < pointCount; i++) points[i] = points[i].Offset(offset); HorizontalMetrics = new GlyphMetrics(new Vector2(min.X, max.Y), points[pointCount + 1].P.X - points[pointCount].P.X, linearHorizontalAdvance); // TODO: vertical metrics }