/// <summary> /// read fitting output /// </summary> /// <param name="tx">glyph translator</param> public static void ReadOutput(this GlyphFitOutline glyphOutline, IGlyphTranslator tx, float pxScale) { if (glyphOutline == null) { return; } // //----------------------------------------------------------- //create fit contour //this version use only Agg's vertical hint only **** //(ONLY vertical fitting , NOT apply horizontal fit) //----------------------------------------------------------- //create outline //then create List <GlyphContour> contours = glyphOutline.Contours; int j = contours.Count; tx.BeginRead(j); for (int i = 0; i < j; ++i) { //new contour CreateFitShape(tx, contours[i], pxScale, false, true, false); tx.CloseContour(); } tx.EndRead(); }
static GlyphFitOutline TessWithPolyTri(List <GlyphContour> contours) { List <Poly2Tri.TriangulationPoint> points = new List <Poly2Tri.TriangulationPoint>(); int cntCount = contours.Count; GlyphContour cnt = contours[0]; Poly2Tri.Polygon polygon = CreatePolygon2(contours[0]);//first contour bool isHoleIf = !cnt.IsClockwise; //if (cntCount > 0) //{ // //debug only for (int n = 1; n < cntCount; ++n) { cnt = contours[n]; //IsHole is correct after we Analyze() the glyph contour polygon.AddHole(CreatePolygon2(cnt)); //if (cnt.IsClockwise == isHoleIf) //{ // polygon.AddHole(CreatePolygon2(cnt)); //} //else //{ // //eg i // //the is a complete separate dot (i head) over i body //} } //} //------------------------------------------ Poly2Tri.P2T.Triangulate(polygon); //that poly is triangulated GlyphFitOutline glyphFitOutline = new GlyphFitOutline(polygon, contours); glyphFitOutline.Analyze(); //------------------------------------------ #if DEBUG List <GlyphTriangle> triAngles = glyphFitOutline.dbugGetTriangles(); int triangleCount = triAngles.Count; for (int i = 0; i < triangleCount; ++i) { //--------------- GlyphTriangle tri = triAngles[i]; AssignPointEdgeInvolvement(tri.e0); AssignPointEdgeInvolvement(tri.e1); AssignPointEdgeInvolvement(tri.e2); } #endif return(glyphFitOutline); }
void Build(ushort glyphIndex, Glyph glyph) { //------------------------------------------- //1. start with original points/contours from glyph this._outputGlyphPoints = glyph.GlyphPoints; this._outputContours = glyph.EndPoints; //------------------------------------------- Typeface currentTypeFace = this._typeface; _recentPixelScale = currentTypeFace.CalculateFromPointToPixelScale(SizeInPoints); //*** _useAutoHint = false; //reset //------------------------------------------- //2. process glyph points if (UseTrueTypeInstructions && currentTypeFace.HasPrepProgramBuffer && glyph.HasGlyphInstructions) { _trueTypeInterpreter.UseVerticalHinting = this.UseVerticalHinting; //output as points, this._outputGlyphPoints = _trueTypeInterpreter.HintGlyph(glyphIndex, SizeInPoints); //all points are scaled from _trueTypeInterpreter, //so not need further scale.=> set _recentPixelScale=1 _recentPixelScale = 1; } else { //not use interperter so we need to scale it with our machnism //this demonstrate our auto hint engine *** //you can change this to your own hint engine*** if (this.UseVerticalHinting) { _useAutoHint = true; if (!_fitoutlineCollection.TryGetValue(glyphIndex, out _fitOutline)) { _fitOutline = _fitShapeAnalyzer.Analyze( this._outputGlyphPoints, this._outputContours); _fitoutlineCollection.Add(glyphIndex, _fitOutline); } } } }
public void Hint(GlyphPointF[] glyphPoints, ushort[] glyphContours, float pxScale = 1) { this.pxScale = pxScale; var analyzer1 = new GlyphContourReader(); analyzer1.Read(glyphPoints, glyphContours); //master outline analysis contours = analyzer1.GetContours(); int j = contours.Count; var analyzer = new GlyphPartAnalyzer(); analyzer.NSteps = 4; analyzer.PixelScale = pxScale; for (int i = 0; i < j; ++i) { contours[i].Analyze(analyzer); } glyphOutline = TessWithPolyTri(contours, pxScale); }
protected override void FitCurrentGlyph(ushort glyphIndex, Glyph glyph) { //not use interperter so we need to scale it with our machnism //this demonstrate our auto hint engine *** //you can change this to your own hint engine*** if (this.UseTrueTypeInstructions) { base.FitCurrentGlyph(glyphIndex, glyph); } else { if (this.UseVerticalHinting) { if (!_fitoutlineCollection.TryGetValue(glyphIndex, out _fitOutline)) { _fitOutline = _fitShapeAnalyzer.Analyze( this._outputGlyphPoints, this._outputContours); _fitoutlineCollection.Add(glyphIndex, _fitOutline); } } } }