void ReadAndRender(string fontfile, string text) { char testChar = text[0];//only 1 char int resolution = 96; var reader = new OpenTypeReader(); using (var fs = new FileStream(fontfile, FileMode.Open)) { //1. read typeface from font file Typeface typeFace = reader.Read(fs); #if DEBUG //----- //about typeface short ascender = typeFace.Ascender; short descender = typeFace.Descender; short lineGap = typeFace.LineGap; //NOpenType.Tables.UnicodeLangBits test = NOpenType.Tables.UnicodeLangBits.Thai; //NOpenType.Tables.UnicodeRangeInfo rangeInfo = test.ToUnicodeRangeInfo(); //bool doseSupport = typeFace.DoseSupportUnicode(test); List <int> outputGlyphIndice = new List <int>(); typeFace.Lookup(text.ToCharArray(), outputGlyphIndice); #endif float fontSizeInPoint = 96; RenderWithMiniAgg(typeFace, testChar, fontSizeInPoint); } }
public void LoadingFontReturnsATypeface(string filename) { var reader = new OpenTypeReader(); using (var fs = File.OpenRead($"{fontsRoot}/{filename}")) { var typeface = reader.Read(fs); Assert.NotNull(typeface); } }
void LoadGlyphs() { using (FileStream fs = new FileStream("tahoma.ttf", FileMode.Open)) { OpenTypeReader reader = new OpenTypeReader(); Typeface typeface = reader.Read(fs); var testChar = 'a'; var builder = new GlyphPathBuilderVxs(typeface); float sizeInPoint = 48; builder.Build(testChar, sizeInPoint); vxs = builder.GetVxs(); } }
public static FontFace LoadFont(string fontfile, string lang, HBDirection direction, int defaultScriptCode = 0) { //read font file OpenTypeReader openTypeReader = new OpenTypeReader(); Typeface typeface = null; using (FileStream fs = new FileStream(fontfile, FileMode.Open, FileAccess.Read, FileShare.Read)) { typeface = openTypeReader.Read(fs); if (typeface == null) { return null; } } //TODO:... //set shape engine *** return new NOpenTypeFontFace(typeface, typeface.Name, fontfile); }
float fontSizeInPoint = 14; //default void ReadAndRender(string fontfile) { if (string.IsNullOrEmpty(this.txtInputChar.Text)) { return; } var reader = new OpenTypeReader(); char testChar = txtInputChar.Text[0];//only 1 char int resolution = 96; using (var fs = new FileStream(fontfile, FileMode.Open)) { //1. read typeface from font file Typeface typeFace = reader.Read(fs); #if DEBUG //----- //about typeface short ascender = typeFace.Ascender; short descender = typeFace.Descender; short lineGap = typeFace.LineGap; NOpenType.Tables.UnicodeLangBits test = NOpenType.Tables.UnicodeLangBits.Thai; NOpenType.Tables.UnicodeRangeInfo rangeInfo = test.ToUnicodeRangeInfo(); bool doseSupport = typeFace.DoseSupportUnicode(test); //----- string inputstr = "ก่นกิ่น"; List<int> outputGlyphIndice = new List<int>(); typeFace.Lookup(inputstr.ToCharArray(), outputGlyphIndice); #endif RenderChoice renderChoice = (RenderChoice)this.cmbRenderChoices.SelectedItem; switch (renderChoice) { case RenderChoice.RenderWithMiniAgg: RenderWithMiniAgg(typeFace, testChar, fontSizeInPoint); break; case RenderChoice.RenderWithPlugableGlyphRasterizer: RenderWithPlugableGlyphRasterizer(typeFace, testChar, fontSizeInPoint, resolution); break; case RenderChoice.RenderWithTypePlanAndMiniAgg: RenderWithTextPrinterAndMiniAgg(typeFace, this.txtInputChar.Text, fontSizeInPoint, resolution); break; default: throw new NotSupportedException(); } } }