public GameUtilsFont(TrueTypeFile trueTypeData) { FontName = trueTypeData.FamilyName; Style = trueTypeData.Style; UnitsPerEm = trueTypeData.UnitsPerEm; glyphDictionary = trueTypeData.GlyphDictionary; ascend = trueTypeData.Ascend; descend = trueTypeData.Descend; lineGap = trueTypeData.LineGap; glyphs = new TriangulatedGlyph[trueTypeData.Glyphs.Length]; for (int i = 0; i < glyphs.Length; i++) glyphs[i] = new TriangulatedGlyph(trueTypeData.Glyphs[i], trueTypeData.GlyphMetrics[i]); }
private void button1_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialog()) { if (ofd.ShowDialog() == DialogResult.OK) { var fontFile = new TrueTypeFile(ofd.FileName); var font = new GameUtilsFont(fontFile); font.Save(font.FontName + ".guf"); //glyph = fontFile.Glyphs[fontFile.GlyphDictionary[' ']]; //triGlyph = font.glyphs[font.glyphDictionary[' ']]; //Invalidate(); } } }
public GameUtilsFont(TrueTypeFile trueTypeData) { FontName = trueTypeData.FamilyName; Style = trueTypeData.Style; UnitsPerEm = trueTypeData.UnitsPerEm; glyphDictionary = trueTypeData.GlyphDictionary; ascend = trueTypeData.Ascend; descend = trueTypeData.Descend; lineGap = trueTypeData.LineGap; glyphs = new TriangulatedGlyph[trueTypeData.Glyphs.Length]; for (int i = 0; i < glyphs.Length; i++) { glyphs[i] = new TriangulatedGlyph(trueTypeData.Glyphs[i], trueTypeData.GlyphMetrics[i]); } }
public TriangulatedGlyph(Glyph glyphData, TrueTypeFile.HorizontalMetric horizontalMetric) { indices = new List<int>(); vertices = new List<Vertex>(); advanceWidth = horizontalMetric.AdvanceWidth; leftSideBearing = horizontalMetric.LeftSideBearing; if (glyphData.IsCompound) { } else { if (glyphData.Contours.Length == 0) return; List<Triangle> triangles; List<LinkedList<ControlPoint>> contours = CreateContours(glyphData, out triangles); int count = 0; bool split; do { split = SplitTriangles(ref triangles); count++; } while (split && count < 4); foreach (var triangle in triangles) { ControlPoint p = (triangle.B + triangle.C) / 2; int windingNumber = GetWindingNumber(p, glyphData); triangle.IsInside = windingNumber == 0; if (triangle.IsInside) triangle.Contour.AddAfter(triangle.BNode, triangle.A); } PolyTree tree = ClipperHelper.Combine(contours.Select(contour => contour.ToList()).ToList()); int pointIndex = 0; var inputGeometry = new InputGeometry(); SearchTree(inputGeometry, ref pointIndex, tree); if (inputGeometry.Count > 0) { var mesh = new Mesh(); mesh.Triangulate(inputGeometry); int highestIndex = 0; var indexDict = new Dictionary<int, int>(); foreach (TriangleNet.Data.Triangle triangle in mesh.Triangles) { int[] newIndices; List<Vertex> newVertices = IndexVertices(triangle, indexDict, ref highestIndex, out newIndices); indices.AddRange(newIndices); vertices.AddRange(newVertices); } foreach (var triangle in triangles) { indices.Add(vertices.Count); vertices.Add(new Vertex((float)triangle.B.X, (float)triangle.B.Y, 0, 0, triangle.IsInside)); indices.Add(vertices.Count); vertices.Add(new Vertex((float)triangle.A.X, (float)triangle.A.Y, 0.5f, 0, triangle.IsInside)); indices.Add(vertices.Count); vertices.Add(new Vertex((float)triangle.C.X, (float)triangle.C.Y, 1, 1, triangle.IsInside)); } } } }