public IGeometryImpl BuildGlyphRunGeometry(GlyphRun glyphRun) { if (glyphRun.GlyphTypeface.PlatformImpl is not GlyphTypefaceImpl glyphTypeface) { throw new InvalidOperationException("PlatformImpl can't be null."); } var pathGeometry = new SharpDX.Direct2D1.PathGeometry(Direct2D1Factory); using (var sink = pathGeometry.Open()) { var glyphs = new short[glyphRun.GlyphIndices.Count]; for (int i = 0; i < glyphRun.GlyphIndices.Count; i++) { glyphs[i] = (short)glyphRun.GlyphIndices[i]; } glyphTypeface.FontFace.GetGlyphRunOutline((float)glyphRun.FontRenderingEmSize, glyphs, null, null, false, !glyphRun.IsLeftToRight, sink); sink.Close(); } var(baselineOriginX, baselineOriginY) = glyphRun.BaselineOrigin; var transformedGeometry = new SharpDX.Direct2D1.TransformedGeometry( Direct2D1Factory, pathGeometry, new RawMatrix3x2(1.0f, 0.0f, 0.0f, 1.0f, (float)baselineOriginX, (float)baselineOriginY)); return(new TransformedGeometryWrapper(transformedGeometry)); }
public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun, out double width) { var glyphTypeface = (GlyphTypefaceImpl)glyphRun.GlyphTypeface.PlatformImpl; var glyphCount = glyphRun.GlyphIndices.Length; var run = new SharpDX.DirectWrite.GlyphRun { FontFace = glyphTypeface.FontFace, FontSize = (float)glyphRun.FontRenderingEmSize }; var indices = new short[glyphCount]; for (var i = 0; i < glyphCount; i++) { indices[i] = (short)glyphRun.GlyphIndices[i]; } run.Indices = indices; run.Advances = new float[glyphCount]; width = 0; for (var i = 0; i < glyphCount; i++) { run.Advances[i] = (float)glyphRun.GlyphAdvances[i]; width += run.Advances[i]; } run.Offsets = new GlyphOffset[glyphCount]; for (var i = 0; i < glyphCount; i++) { var offset = glyphRun.GlyphOffsets[i]; run.Offsets[i] = new GlyphOffset { AdvanceOffset = (float)offset.X, AscenderOffset = (float)offset.Y }; } return(new GlyphRunImpl(run)); }
public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun) { var glyphTypeface = (GlyphTypefaceImpl)glyphRun.GlyphTypeface.PlatformImpl; var glyphCount = glyphRun.GlyphIndices.Length; var run = new SharpDX.DirectWrite.GlyphRun { FontFace = glyphTypeface.FontFace, FontSize = (float)glyphRun.FontRenderingEmSize }; var indices = new short[glyphCount]; for (var i = 0; i < glyphCount; i++) { indices[i] = (short)glyphRun.GlyphIndices[i]; } run.Indices = indices; run.Advances = new float[glyphCount]; var scale = (float)(glyphRun.FontRenderingEmSize / glyphTypeface.DesignEmHeight); if (glyphRun.GlyphAdvances.IsEmpty) { for (var i = 0; i < glyphCount; i++) { var advance = glyphTypeface.GetGlyphAdvance(glyphRun.GlyphIndices[i]) * scale; run.Advances[i] = advance; } } else { for (var i = 0; i < glyphCount; i++) { var advance = (float)glyphRun.GlyphAdvances[i]; run.Advances[i] = advance; } } if (glyphRun.GlyphOffsets.IsEmpty) { return(new GlyphRunImpl(run)); } run.Offsets = new GlyphOffset[glyphCount]; for (var i = 0; i < glyphCount; i++) { var(x, y) = glyphRun.GlyphOffsets[i]; run.Offsets[i] = new GlyphOffset { AdvanceOffset = (float)x, AscenderOffset = (float)y }; } return(new GlyphRunImpl(run)); }