private void InitGlyphPointsAndContourEnds(char c) { try { using (FileStream fs = File.OpenRead(ttfPath)) { OpenFontReader reader = new OpenFontReader(); Typeface typeface = reader.Read(fs); var builder = new GlyphPathBuilder(typeface); builder.BuildFromGlyphIndex(typeface.LookupIndex(c), 300); var txToPath = new GlyphTranslatorToPath(); var writablePath = new WritablePath(); txToPath.SetOutput(writablePath); builder.ReadShapes(txToPath); var curveFlattener = new SimpleCurveFlattener(); float[] flattenPoints = curveFlattener.Flatten( writablePath._points, out _contourEnds); _glyphPoints2 = flattenPoints; } } catch (Exception) { ClearGlyphData(); pnlGlyph.Invalidate(); } }
//------------- public TextPrinter() { FontSizeInPoints = 14; ScriptLang = ScriptLangs.Latin; // _curveFlattener = new SimpleCurveFlattener(); _tessTool = new Tesselate.TessTool(); }
private void FormTess_Load(object sender, EventArgs e) { g = this.pnlGlyph.CreateGraphics(); pnlGlyph.MouseDown += PnlGlyph_MouseDown; //string testFont = "d:\\WImageTest\\DroidSans.ttf"; string testFont = "c:\\Windows\\Fonts\\Tahoma.ttf"; using (FileStream fs = new FileStream(testFont, FileMode.Open, FileAccess.Read)) { OpenFontReader reader = new OpenFontReader(); Typeface typeface = reader.Read(fs); //-- var builder = new Typography.Rendering.GlyphPathBuilder(typeface); builder.BuildFromGlyphIndex(typeface.LookupIndex('a'), 256); var txToPath = new GlyphTranslatorToPath(); var writablePath = new WritablePath(); txToPath.SetOutput(writablePath); builder.ReadShapes(txToPath); //from contour to var curveFlattener = new SimpleCurveFlattener(); float[] flattenPoints = curveFlattener.Flatten(writablePath._points, out contourEnds); glyphPoints2 = flattenPoints; ////-------------------------------------- ////raw glyph points //int j = glyphPoints.Length; //float scale = typeface.CalculateToPixelScaleFromPointSize(256); //glyphPoints2 = new float[j * 2]; //int n = 0; //for (int i = 0; i < j; ++i) //{ // GlyphPointF pp = glyphPoints[i]; // glyphPoints2[n] = pp.X * scale; // n++; // glyphPoints2[n] = pp.Y * scale; // n++; //} ////-------------------------------------- } }
private void TextBox1_KeyUp(object sender, KeyEventArgs e) { string oneChar = this.textBox1.Text.Trim(); if (string.IsNullOrEmpty(oneChar)) { return; } // char selectedChar = oneChar[0]; // // //selectedChar = 'e'; if (_g == null) { _g = this.pnlGlyph.CreateGraphics(); } _g.Clear(Color.White); //string testFont = "d:\\WImageTest\\DroidSans.ttf"; //string testFont = "c:\\Windows\\Fonts\\Tahoma.ttf"; string testFont = "d:\\WImageTest\\Alfa_Slab.ttf"; using (FileStream fs = new FileStream(testFont, FileMode.Open, FileAccess.Read)) { OpenFontReader reader = new OpenFontReader(); Typeface typeface = reader.Read(fs); //-- var builder = new Typography.Contours.GlyphPathBuilder(typeface); builder.BuildFromGlyphIndex(typeface.LookupIndex(selectedChar), 300); var txToPath = new GlyphTranslatorToPath(); var writablePath = new WritablePath(); txToPath.SetOutput(writablePath); builder.ReadShapes(txToPath); //from contour to var curveFlattener = new SimpleCurveFlattener(); float[] flattenPoints = curveFlattener.Flatten(writablePath._points, out _contourEnds); _glyphPoints2 = flattenPoints; ////-------------------------------------- ////raw glyph points //int j = glyphPoints.Length; //float scale = typeface.CalculateToPixelScaleFromPointSize(256); //glyphPoints2 = new float[j * 2]; //int n = 0; //for (int i = 0; i < j; ++i) //{ // GlyphPointF pp = glyphPoints[i]; // glyphPoints2[n] = pp.X * scale; // n++; // glyphPoints2[n] = pp.Y * scale; // n++; //} ////-------------------------------------- } DrawOutput(); }
void UpdateOutput() { string oneChar = this.textBox1.Text.Trim(); if (string.IsNullOrEmpty(oneChar)) { return; } // char selectedChar = oneChar[0]; // // //selectedChar = 'e'; if (_g == null) { _g = this.panel1.CreateGraphics(); } _g.Clear(Color.White); //------- //string testFont = "c:\\Windows\\Fonts\\Tahoma.ttf"; //string testFont = @"D:\projects\Typography\Demo\Windows\TestFonts\SourceSerifPro-Regular.otf"; string testFont = @"D:\projects\Typography\Demo\Windows\TestFonts\SourceSansPro-Light.ttf"; //string testFont = @"D:\projects\Typography\Demo\Windows\TestFonts\Sarabun-Regular.ttf"; using (FileStream fs = new FileStream(testFont, FileMode.Open, FileAccess.Read)) { OpenFontReader reader = new OpenFontReader(); Typeface typeface = reader.Read(fs); //-- var builder = new Typography.Contours.GlyphPathBuilder(typeface); builder.BuildFromGlyphIndex(typeface.LookupIndex(selectedChar), 300); var txToPath = new GlyphTranslatorToPath(); var writablePath = new WritablePath(); txToPath.SetOutput(writablePath); builder.ReadShapes(txToPath); //------ // //**flatten contour before send to Tess*** var curveFlattener = new SimpleCurveFlattener(); if (rdoSimpleIncCurveFlattener.Checked) { if (int.TryParse(txtIncrementalTessStep.Text, out int incSteps)) { curveFlattener.IncrementalStep = incSteps; } curveFlattener.FlattenMethod = CurveFlattenMethod.Inc; } else { if (double.TryParse(txtDivAngleTolerenceEpsilon.Text, out double angleTolerenceEpsilon)) { //convert degree to rad curveFlattener.DivCurveAngleTolerenceEpsilon = DegToRad(angleTolerenceEpsilon); } if (int.TryParse(txtDivCurveRecursiveLimit.Text, out int recuvesiveLim)) { curveFlattener.DivCurveRecursiveLimit = recuvesiveLim; } curveFlattener.FlattenMethod = CurveFlattenMethod.Div; } _glyphPoints2 = curveFlattener.Flatten(writablePath._points, out _contourEnds); ////-------------------------------------- ////raw glyph points //int j = glyphPoints.Length; //float scale = typeface.CalculateToPixelScaleFromPointSize(256); //glyphPoints2 = new float[j * 2]; //int n = 0; //for (int i = 0; i < j; ++i) //{ // GlyphPointF pp = glyphPoints[i]; // glyphPoints2[n] = pp.X * scale; // n++; // glyphPoints2[n] = pp.Y * scale; // n++; //} ////-------------------------------------- } DrawOutput(); }