public void DrawString(char[] text, int startAt, int len, double x, double y) { UpdateGlyphLayoutSettings(); _outputGlyphPlans.Clear(); // float pxscale = _currentTypeface.CalculateToPixelScaleFromPointSize(this.FontSizeInPoints); _glyphLayout.GenerateGlyphPlans(text, startAt, len, _outputGlyphPlans, null); //----- //we (fine) adjust horizontal fit here //----- DrawFromGlyphPlans(_outputGlyphPlans, (float)x, (float)y); }
public override void DrawString(char[] textBuffer, int startAt, int len, float xpos, float ypos) { UpdateGlyphLayoutSettings(); _outputGlyphPlans.Clear(); _glyphLayout.GenerateGlyphPlans(textBuffer, startAt, len, _outputGlyphPlans, null); DrawGlyphPlanList(_outputGlyphPlans, xpos, ypos); }
/// <summary> /// generate glyph run into a given textRun /// </summary> /// <param name="outputTextRun"></param> /// <param name="charBuffer"></param> /// <param name="start"></param> /// <param name="len"></param> public void GenerateGlyphRuns(TextRun outputTextRun, char[] charBuffer, int start, int len) { // layout glyphs with selected layout technique float sizeInPoints = this.FontSizeInPoints; outputTextRun.typeface = this.CurrentTypeFace; outputTextRun.sizeInPoints = sizeInPoints; //in this version we store original glyph into the mesh collection //and then we scale it later, so I just specific font size=0 (you can use any value) _glyphMeshCollection.SetCacheInfo(this.CurrentTypeFace, 0, this.HintTechnique); outputGlyphPlans.Clear(); glyphLayout.Typeface = this.CurrentTypeFace; glyphLayout.GenerateGlyphPlans(charBuffer, start, len, outputGlyphPlans, null); // render each glyph int planCount = outputGlyphPlans.Count; for (var i = 0; i < planCount; ++i) { pathTranslator.Reset(); //---- //glyph path //---- GlyphPlan glyphPlan = outputGlyphPlans[i]; // //1. check if we have this glyph in cache? //if yes, not need to build it again ProcessedGlyph processGlyph; float[] tessData = null; if (!_glyphMeshCollection.TryGetCacheGlyph(glyphPlan.glyphIndex, out processGlyph)) { //if not found the create a new one and register it var writablePath = new WritablePath(); pathTranslator.SetOutput(writablePath); currentGlyphPathBuilder.BuildFromGlyphIndex(glyphPlan.glyphIndex, sizeInPoints); currentGlyphPathBuilder.ReadShapes(pathTranslator); //------- //do tess int[] endContours; float[] flattenPoints = _curveFlattener.Flatten(writablePath._points, out endContours); int nTessElems; tessData = _tessTool.TessPolygon(flattenPoints, endContours, out nTessElems); //------- processGlyph = new ProcessedGlyph(tessData, (ushort)nTessElems); _glyphMeshCollection.RegisterCachedGlyph(glyphPlan.glyphIndex, processGlyph); } outputTextRun.AddGlyph( new GlyphRun(glyphPlan, processGlyph.tessData, processGlyph.tessNElements)); } }