public MeasuredStringBox MeasureString(char[] textBuffer, int startAt, int len) { //1. update UpdateGlyphLayoutSettings(); //2. unscale layout, in design unit this._glyphLayout.Layout(textBuffer, startAt, len); //3. scale to specific font size _outputGlyphPlans.Clear(); GlyphLayoutExtensions.GenerateGlyphPlan( _glyphLayout.ResultUnscaledGlyphPositions, _currentTypeface.CalculateScaleToPixelFromPointSize(this.FontSizeInPoints), false, _outputGlyphPlans); // float pxscale = this.Typeface.CalculateScaleToPixelFromPointSize(this.FontSizeInPoints); return(new MeasuredStringBox( _outputGlyphPlans.AccumAdvanceX * pxscale, _currentTypeface.Ascender * pxscale, _currentTypeface.Descender * pxscale, _currentTypeface.LineGap * pxscale, Typography.OpenFont.Extensions.TypefaceExtensions.CalculateRecommendLineSpacing(_currentTypeface) * pxscale)); }
void InternalDrawString(char[] textBuffer, int startAt, int len, float x, float y) { UpdateGlyphLayoutSettings(); //unscale layout, with design unit scale _glyphLayout.Layout(textBuffer, startAt, len); // // _outputGlyphPlans.Clear(); // if (this._pxScaleEngine != null) { //scale to specific font size _pxScaleEngine.Layout(_glyphLayout.ResultUnscaledGlyphPositions, _outputGlyphPlans); } else { //no custom engine //then use default scale GlyphLayoutExtensions.GenerateGlyphPlan( _glyphLayout.ResultUnscaledGlyphPositions, _currentFontSizePxScale, false, _outputGlyphPlans); } DrawFromGlyphPlans(_outputGlyphPlans, x, y); }
public GlyphPlanList StringToGlyphPlanList(string s, double font_size) { GlyphPlanList l = new GlyphPlanList(); m_layout.Layout(s.ToCharArray(), 0, s.Length); var scale = m_openfont.CalculateScaleToPixelFromPointSize((float)font_size); GlyphLayoutExtensions.GenerateGlyphPlan(m_layout.ResultUnscaledGlyphPositions, scale, snapToGrid: true, outputGlyphPlanList: l); return(l); }
public virtual void GenerateGlyphPlan( char[] textBuffer, int startAt, int len, GlyphPlanList outputGlyphPlanList, List <UserCharToGlyphIndexMap> charToGlyphMapList) { this.GlyphLayoutMan.Layout(textBuffer, startAt, len); GlyphLayoutExtensions.GenerateGlyphPlan(this.GlyphLayoutMan.ResultUnscaledGlyphPositions, this.Typeface.CalculateScaleToPixelFromPointSize(this.FontSizeInPoints), false, outputGlyphPlanList); }
GlyphPlanList _outputGlyphPlans = new GlyphPlanList();//for internal use public override void DrawString(char[] textBuffer, int startAt, int len, float x, float y) { //1. update UpdateGlyphLayoutSettings(); //2. unscale layout, in design unit this._glyphLayout.Layout(textBuffer, startAt, len); //3. scale to specific font size _outputGlyphPlans.Clear(); GlyphLayoutExtensions.GenerateGlyphPlan( _glyphLayout.ResultUnscaledGlyphPositions, _currentTypeface.CalculateScaleToPixelFromPointSize(this.FontSizeInPoints), false, _outputGlyphPlans); DrawFromGlyphPlans(_outputGlyphPlans, x, y); }
public MeasuredStringBox Measure(char[] textBuffer, int startAt, int len) { glyphLayout.Typeface = this.CurrentTypeFace; float pxscale = CurrentTypeFace.CalculateScaleToPixelFromPointSize(this.FontSizeInPoints); glyphLayout.Layout(textBuffer, startAt, len); _reusableGlyphPlanList.Clear(); IGlyphPositions glyphPositions = glyphLayout.ResultUnscaledGlyphPositions; GlyphLayoutExtensions.GenerateGlyphPlan(glyphLayout.ResultUnscaledGlyphPositions, pxscale, false, _reusableGlyphPlanList); return(new MeasuredStringBox( _reusableGlyphPlanList.AccumAdvanceX * pxscale, CurrentTypeFace.Ascender * pxscale, CurrentTypeFace.Descender * pxscale, CurrentTypeFace.LineGap * pxscale, Typography.OpenFont.Extensions.TypefaceExtensions.CalculateRecommendLineSpacing(CurrentTypeFace) * pxscale)); }
/// <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); glyphLayout.Typeface = this.CurrentTypeFace; glyphLayout.Layout(charBuffer, start, len); float pxscale = this.CurrentTypeFace.CalculateScaleToPixelFromPointSize(sizeInPoints); outputGlyphPlans.Clear(); GlyphLayoutExtensions.GenerateGlyphPlan( glyphLayout.ResultUnscaledGlyphPositions, pxscale, false, outputGlyphPlans); // 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)); } }