void RunSampleF(PixelFarm.Drawing.Painter p) { //version 4: p.Clear(PixelFarm.Drawing.Color.White); p.UseSubPixelLcdEffect = this.EnableSubPix; //-------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 2.0f; p.DrawLine(2, 0, 10, 15); int lineLen = 10; int x = 30; int y = 30; p.FillColor = PixelFarm.Drawing.Color.Black; VertexStorePool pool = new VertexStorePool(); using (System.IO.FileStream fs = new System.IO.FileStream("c:\\Windows\\Fonts\\tahoma.ttf", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { Typography.OpenFont.OpenFontReader reader = new Typography.OpenFont.OpenFontReader(); Typography.OpenFont.Typeface typeface = reader.Read(fs); var builder = new Typography.Contours.GlyphPathBuilder(typeface); builder.BuildFromGlyphIndex((ushort)typeface.LookupIndex('C'), 16); PixelFarm.Drawing.Fonts.GlyphTranslatorToVxs tovxs = new Drawing.Fonts.GlyphTranslatorToVxs(); builder.ReadShapes(tovxs); VertexStore vxs = new VertexStore(); tovxs.WriteOutput(vxs); p.Fill(vxs); } p.FillRect(0, 0, 20, 20); }
public static PixelFarm.Drawing.Fonts.FontFace LoadFont(string fontpath) { // Typeface: Typography.OpenFont // GlyphPathBuilder: Typography.Contours // Typography.OpenFont: OpenFontReader using (FileStream fs = new FileStream(fontpath, FileMode.Open, FileAccess.Read)) { var reader = new OpenFontReader(); Typeface t = reader.Read(fs); t.Filename = fontpath; // t.IsCffFont // (CFF: Compact Font Format) https://www.linotype.com/8120/the-difference-between-cff-and-ttf.html t.GetAdvanceWidth(123); // font->potm->otmfsType = pOS2->fsType & 0x30e; int otmfsType = t.OS2Table.fsType & 0x30e; short a = t.Ascender; short b = t.Descender; short c = t.LineGap; // t.CalculateScaleToPixelFromPointSize // t.CalculateScaleToPixel // var list = t.GetRawGlyphList(); //list[0]. // t.GetGlyphByIndex(123); var gi = t.GetGlyphByIndex(t.LookupIndex('g')); // gi.Bounds.Equals // t.GetGlyphByIndex(t.LookupIndex('g')).MathGlyphInfo. var builder = new Typography.Contours.GlyphPathBuilder(t); return(LoadFont(t)); } }
private void FormTess_Load(object sender, EventArgs e) { g = this.pnlGlyph.CreateGraphics(); //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.Contours.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(); }