예제 #1
0
            public void GetGlyphPoints(string fontFile, char character)
            {
                Typeface typeFace;

                using (var fs = Utility.ReadFile(Utility.FontDir + fontFile))
                {
                    var reader = new OpenFontReader();
                    typeFace = reader.Read(fs);
                }

                Glyph glyph = typeFace.Lookup(character);

                o.WriteLine("GlyphPoints of '{0}':", character);
                var glyphPoints = glyph.GlyphPoints;

                foreach (var p in glyphPoints)
                {
                    o.WriteLine("{0}, {1}", p.X, p.Y);
                }

                o.WriteLine("EndPoints of '{0}':", character);
                var endPoints = glyph.EndPoints;

                foreach (var end in endPoints)
                {
                    o.WriteLine(end.ToString());
                }
            }
예제 #2
0
        public ColorTypeface(string name)
        {
            m_gtf = GetGlyphTypeface(first_candidate: name);
            if (m_gtf == null)
            {
                return;
            }

            // Read the actual font data using Typography.OpenFont
            using (var s = m_gtf.GetFontStream())
            {
                var r = new OpenFontReader();
                m_openfont = r.Read(s, 0, ReadFlags.Full);
            }

            // Create a reusable layout for glyphs
            m_layout = new GlyphLayout()
            {
                Typeface = m_openfont,
                EnableBuiltinMathItalicCorrection = false, // not needed
                EnableComposition = true,
                EnableGpos        = true,
                EnableGsub        = true,
                EnableLigature    = true,
                PositionTechnique = PositionTechnique.OpenFont,
            };

            // Cache the glyph index for the zero-width joiner
            foreach (var g in StringToGlyphLayout("\u200d", use_gpos: false))
            {
                m_zwj_glyph = g.glyphIndex;
            }
        }
예제 #3
0
        public void ShowGlyphAsTextMesh_Builtin()
        {
            //load the glyph
            Typeface typeFace;

            using (var fs = Utility.ReadFile(Utility.FontDir + fontFileName))
            {
                var reader = new OpenFontReader();
                typeFace = reader.Read(fs);
            }

            Bounds boundingBox = typeFace.Bounds;
            short  ascender    = typeFace.Ascender;
            Glyph  glyph       = typeFace.Lookup(character);

            //read polygons and quadratic bezier segments
            GlyphLoader.Read(glyph, out var polygons, out var quadraticBezierSegments);

            //construct text mesh
            TextMesh textMesh         = new TextMesh();
            Color    polygonFillColor = Color.Argb(128, 10, 10, 10);

            textMesh.AddTriangles(polygons, polygonFillColor,
                                  new Vector(0, ascender), Vector.Zero, 1, false);
            textMesh.AddBezierSegments(quadraticBezierSegments, polygonFillColor,
                                       new Vector(0, ascender), Vector.Zero, 1, false);
            var command = textMesh.Commands[^ 1];
예제 #4
0
        public FormTess()
        {
            InitializeComponent();

            rdoSimpleIncCurveFlattener.Checked         = true;
            rdoSimpleIncCurveFlattener.CheckedChanged += (s, e) => UpdateOutput();
            //
            rdoSubdivCureveFlattener.CheckedChanged += (s, e) => UpdateOutput();

            textBox1.KeyUp += (s, e) => UpdateOutput();


            rdoTessPoly2Tri.CheckedChanged        += (s, e) => UpdateOutput();
            rdoTessSGI.CheckedChanged             += (s, e) => UpdateOutput();
            chkShowContourAnalysis.CheckedChanged += (s, e) => UpdateOutput();

            txtIncrementalTessStep.KeyUp      += (s, e) => UpdateOutput();
            txtDivCurveRecursiveLimit.KeyUp   += (s, e) => UpdateOutput();
            txtDivAngleTolerenceEpsilon.KeyUp += (s, e) => UpdateOutput();

            string testFont = "c:\\Windows\\Fonts\\Tahoma.ttf";

            using (FileStream fs = new FileStream(testFont, FileMode.Open, FileAccess.Read))
            {
                OpenFontReader reader = new OpenFontReader();
                _typeface = reader.Read(fs);
            }

            _tovxs            = new GlyphTranslatorToVxs();
            _glyphPathBuilder = new GlyphOutlineBuilder(_typeface);
            //
            _tessTool = new TessTool();
        }
예제 #5
0
 public static void RestoreUp(this Typeface typeface, RestoreTicket ticket, OpenFontReader openFontReader, Stream fontStream)
 {
     if (typeface.IsTrimmed())
     {
         openFontReader.Read(typeface, ticket, fontStream);
     }
 }
예제 #6
0
        public void SetCurrentFont(string fontname, InstalledFontStyle fontStyle, float fontSizeInPts, ScriptLang scLang = null)
        {
            InstalledFont installedFont = _hub._openFontStore.GetFont(fontname, fontStyle);

            if (installedFont == null)
            {
                return;                       //not found request font
            }
            if (scLang != null)
            {
                _glyphLayout.ScriptLang = scLang;
            }

            var key = new TextShapingContextKey(installedFont, _glyphLayout.ScriptLang);

            if (!_registerShapingContexts.TryGetValue(key, out _currentShapingContext))
            {
                //not found
                //the create the new one
                Typeface typeface;
                using (var fs = new System.IO.FileStream(installedFont.FontPath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    var reader = new OpenFontReader();
                    typeface = reader.Read(fs);
                }
                var shapingContext = new TextShapingContext(typeface, _glyphLayout.ScriptLang);
                //shaping context setup ...
                _registerShapingContexts.Add(key, shapingContext);
                _currentShapingContext = shapingContext;
            }
            _fontSizeInPts = fontSizeInPts;
        }
예제 #7
0
파일: Fonts.cs 프로젝트: m1090c/CSharpMath
        static Typefaces GetGlobalTypefaces()
        {
            var reader = new OpenFontReader();

            Typeface LoadFont(string fileName)
            {
                var typeface = reader.Read(
                    System.Reflection.Assembly.GetExecutingAssembly()
                    .GetManifestResourceStream($"CSharpMath.Rendering.Reference_Fonts.{fileName}")
                    );

                if (typeface == null)
                {
                    throw new Structures.InvalidCodePathException("Invalid predefined font!");
                }
                typeface.UpdateAllCffGlyphBounds();
                return(typeface);
            }

            var globalTypefaces = new Typefaces(LoadFont("latinmodern-math.otf"));

            globalTypefaces.AddOverride(LoadFont("AMS-Capital-Blackboard-Bold.otf"));
            globalTypefaces.AddSupplement(LoadFont("cyrillic-modern-nmr10.otf"));
            return(globalTypefaces);
        }
예제 #8
0
        private void InitGlyphPointsAndContourEnds(char c)
        {
            try {
                using (FileStream fs = File.OpenRead(ttfPath)) {
                    OpenFontReader reader   = new OpenFontReader();
                    Typeface       typeface = reader.Read(fs);

                    var builder = new GlyphPathBuilder(typeface);
                    builder.BuildFromGlyphIndex(typeface.LookupIndex(c), 300);

                    var txToPath     = new GlyphTranslatorToPath();
                    var writablePath = new WritablePath();
                    txToPath.SetOutput(writablePath);
                    builder.ReadShapes(txToPath);

                    var     curveFlattener = new SimpleCurveFlattener();
                    float[] flattenPoints  = curveFlattener.Flatten(
                        writablePath._points, out _contourEnds);
                    _glyphPoints2 = flattenPoints;
                }
            }
            catch (Exception) {
                ClearGlyphData();
                pnlGlyph.Invalidate();
            }
        }
예제 #9
0
        private void cmdShowFontAtlas_Click(object sender, EventArgs e)
        {
            if (_selectedAtlasItemSourceFile != null)
            {
                //check if this is a font file?
                Typeface selectedTypeface = null;
                switch (_selectedAtlasItemSourceFile.Extension)
                {
                case ".ttf":
                case ".otf":
                {
                    using (FileStream fs = new FileStream(_selectedAtlasItemSourceFile.AbsoluteFilename, FileMode.Open))
                    {
                        OpenFontReader reader = new OpenFontReader();
                        selectedTypeface = reader.Read(fs);
                    }
                }
                break;
                }

                if (selectedTypeface != null)
                {
                    SampleWinForms.FormFontAtlas formFontAtlas = new SampleWinForms.FormFontAtlas();
                    formFontAtlas.SetFont(selectedTypeface, 34);//load with init size
                    formFontAtlas.ShowDialog();
                }
            }
        }
예제 #10
0
        static void CreateSampleMsdfTextureFont(
            string fontfile, float sizeInPoint,
            char[] chars, string outputFile)
        {
            //sample
            var reader = new OpenFontReader();

            using (var fs = new FileStream(fontfile, FileMode.Open))
            {
                //1. read typeface from font file
                Typeface typeface = reader.Read(fs);
                //sample: create sample msdf texture
                //-------------------------------------------------------------
                var builder = new GlyphPathBuilder(typeface);
                //builder.UseTrueTypeInterpreter = this.chkTrueTypeHint.Checked;
                //builder.UseVerticalHinting = this.chkVerticalHinting.Checked;
                //-------------------------------------------------------------
                var atlasBuilder = new SimpleFontAtlasBuilder();

                MsdfGenParams msdfGenParams = new MsdfGenParams();

                int j = chars.Length;
                for (int i = 0; i < j; ++i)
                {
                    //build glyph
                    ushort gindex = typeface.LookupIndex(chars[i]);
                    builder.BuildFromGlyphIndex(gindex, -1);

                    var glyphToContour = new GlyphContourBuilder();
                    //glyphToContour.Read(builder.GetOutputPoints(), builder.GetOutputContours());
                    builder.ReadShapes(glyphToContour);
                    msdfGenParams.shapeScale = 1f / 64;
                    GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(glyphToContour, msdfGenParams);
                    atlasBuilder.AddGlyph(gindex, glyphImg);
                    int w = glyphImg.Width;
                    int h = glyphImg.Height;
                    using (Bitmap bmp = new Bitmap(glyphImg.Width, glyphImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                    {
                        var   bmpdata   = bmp.LockBits(new System.Drawing.Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                        int[] imgBuffer = glyphImg.GetImageBuffer();
                        System.Runtime.InteropServices.Marshal.Copy(imgBuffer, 0, bmpdata.Scan0, imgBuffer.Length);
                        bmp.UnlockBits(bmpdata);
                        bmp.Save("d:\\WImageTest\\a001_xn2_" + (chars[i]) + ".png");
                    }
                }

                var glyphImg2 = atlasBuilder.BuildSingleImage();
                using (Bitmap bmp = new Bitmap(glyphImg2.Width, glyphImg2.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImg2.Width, glyphImg2.Height),
                                               System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                    int[] intBuffer = glyphImg2.GetImageBuffer();

                    System.Runtime.InteropServices.Marshal.Copy(intBuffer, 0, bmpdata.Scan0, intBuffer.Length);
                    bmp.UnlockBits(bmpdata);
                    bmp.Save("d:\\WImageTest\\a_total.png");
                }
                atlasBuilder.SaveFontInfo("d:\\WImageTest\\a_info.xml");
            }
        }
예제 #11
0
        void Issue119(PaintEventArgs e)
        {
            Text = "Issue 119 Demo";
            const float z = 80;
            var         m = GetType().Assembly;
            var         t = new OpenFontReader().Read
                                (m.GetManifestResourceStream
                                    (Array.Find(m.GetManifestResourceNames(), n => n.EndsWith("otf"))));

            t.UpdateAllCffGlyphBounds();
            var c = t.CalculateScaleToPixelFromPointSize(z);
            var b = new B(t);
            var r = new SampleWinForms.GlyphTranslatorToGdiPath();
            var g = t.GetGlyphByName("radical.v4");
            var o = g.Bounds;
            var k = R.FromLTRB(o.XMin * c, o.YMin * c, o.XMax * c, o.YMax * c);

            b.BuildFromGlyph(g, z);
            b.ReadShapes(r);
            e.Graphics.ScaleTransform(1, -1);
            e.Graphics.TranslateTransform(0, -Height / 2.5f);
            e.Graphics.FillRectangle(Pens.Red.Brush, k.X, k.Y, k.Width, k.Height);
            e.Graphics.DrawRectangle(Pens.Blue, k.X, k.Y, t.GetHAdvanceWidthFromGlyphIndex(g.GlyphIndex) * c, k.Height);
            e.Graphics.FillPath(Pens.Black.Brush, r.ResultGraphicsPath);
            e.Graphics.ResetTransform();
            e.Graphics.DrawString("Blue = GetHAdvanceWidthFromGlyphIndex,\nRed = Glyph.Bounds of radical.v4", Font, Pens.Black.Brush, 0, 0);
        }
예제 #12
0
        void ResolveItems()
        {
            _typefaces.Clear();
            foreach (AtlasItemSourceFile atlasSrcItem in Items)
            {
                //check file
                if (!File.Exists(atlasSrcItem.AbsoluteFilename))
                {
                    throw new NotSupportedException();
                }

                switch (atlasSrcItem.Extension)
                {
                case ".ttc":
                case ".otf":
                case ".ttf":
                case ".otc":
                {
                    atlasSrcItem.Kind = AtlasItemSourceKind.Font;
                    using (FileStream fs = new FileStream(atlasSrcItem.AbsoluteFilename, FileMode.Open))
                    {
                        OpenFontReader reader = new OpenFontReader();
                        _typefaces.Add(Path.GetFileName(atlasSrcItem.AbsoluteFilename), reader.Read(fs));
                    }
                }
                break;

                case ".css":
                case ".html":
                case ".htm":
                case ".svg":
                    atlasSrcItem.Kind = AtlasItemSourceKind.Text;
                    break;

                case ".png":
                case ".jpg":
                    atlasSrcItem.Kind    = AtlasItemSourceKind.Image;
                    IsBitmapAtlasProject = true;
                    break;

                case ".xml":
                {
                    atlasSrcItem.Kind = AtlasItemSourceKind.Data;
                    TryReadConfigFile(atlasSrcItem);
                    switch (atlasSrcItem.Kind)
                    {
                    case AtlasItemSourceKind.FontAtlasConfig:
                        IsFontAtlasProject = true;
                        break;

                    case AtlasItemSourceKind.ResourceConfig:
                        IsResourceProject = true;
                        break;
                    }
                }
                break;
                }
            }
        }
예제 #13
0
 public TypographyTest()
 {
     using (var fs = new FileStream(FontFile, FileMode.Open))
     {
         var fontReader = new OpenFontReader();
         typeFace = fontReader.Read(fs);
     }
 }
예제 #14
0
        static Fonts()
        {
            var bytes             = Resources.LatinModernMath;
            var reader            = new OpenFontReader();
            var latinMathTypeface = reader.Read(new MemoryStream(bytes, false));

            latinMathTypeface.UpdateAllCffGlyphBounds();
            GlobalTypefaces = new Typefaces(latinMathTypeface);
        }
예제 #15
0
        void ReadAndRender(string fontfile)
        {
            if (string.IsNullOrEmpty(this.txtInputChar.Text))
            {
                p.Clear(PixelFarm.Drawing.Color.White);
                return;
            }
            var  reader     = new OpenFontReader();
            char testChar   = txtInputChar.Text[0];//only 1 char
            int  resolution = 96;
            //1. read typeface from font file

            RenderChoice renderChoice = (RenderChoice)this.cmbRenderChoices.SelectedItem;

            switch (renderChoice)
            {
            case RenderChoice.RenderWithMiniAgg:
            {
                using (var fs = new FileStream(fontfile, FileMode.Open))
                {
                    Typeface typeFace = reader.Read(fs);
                    RenderWithMiniAgg(typeFace, testChar, fontSizeInPoint);
                }
            }
            break;

            case RenderChoice.RenderWithGdiPlusPath:
            {
                using (var fs = new FileStream(fontfile, FileMode.Open))
                {
                    Typeface typeFace = reader.Read(fs);
                    RenderWithGdiPlusPath(typeFace, testChar, fontSizeInPoint, resolution);
                }
            }
            break;

            case RenderChoice.RenderWithTextPrinterAndMiniAgg:
            {
                RenderWithTextPrinterAndMiniAgg(fontfile, this.txtInputChar.Text, fontSizeInPoint, resolution);
            }
            break;

            case RenderChoice.RenderWithMsdfGen:
            case RenderChoice.RenderWithSdfGen:
            {
                using (var fs = new FileStream(fontfile, FileMode.Open))
                {
                    Typeface typeFace = reader.Read(fs);
                    RenderWithMsdfImg(typeFace, testChar, fontSizeInPoint);
                }
            }
            break;

            default:
                throw new NotSupportedException();
            }
        }
예제 #16
0
        static SimpleFontAtlasBuilder CreateSampleMsdfTextureFont(string fontfile,
                                                                  float sizeInPoint,
                                                                  ushort startGlyphIndex, ushort endGlyphIndex)
        {
            //read type face from file
            Typeface typeface;

            using (var fs = new FileStream(fontfile, FileMode.Open, FileAccess.Read))
            {
                var reader = new OpenFontReader();
                //1. read typeface from font file
                typeface = reader.Read(fs);
            }
            //sample: create sample msdf texture
            //-------------------------------------------------------------
            var builder = new MyGlyphPathBuilder(typeface);
            //builder.UseTrueTypeInterpreter = this.chkTrueTypeHint.Checked;
            //builder.UseVerticalHinting = this.chkVerticalHinting.Checked;
            //-------------------------------------------------------------
            var atlasBuilder = new SimpleFontAtlasBuilder();
            var msdfBuilder  = new MsdfGlyphGen();

            for (ushort n = startGlyphIndex; n <= endGlyphIndex; ++n)
            {
                //build glyph
                builder.BuildFromGlyphIndex(n, sizeInPoint);

                var msdfGlyphGen = new MsdfGlyphGen();
                var actualImg    = msdfGlyphGen.CreateMsdfImage(
                    builder.GetOutputPoints(),
                    builder.GetOutputContours(),
                    builder.GetPixelScale());
                atlasBuilder.AddGlyph((int)n, actualImg);

                //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                //{
                //    var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                //    System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
                //    bmp.UnlockBits(bmpdata);
                //    bmp.Save("d:\\WImageTest\\a001_xn2_" + n + ".png");
                //}
            }

            return(atlasBuilder);
            //var glyphImg2 = atlasBuilder.BuildSingleImage();
            //using (Bitmap bmp = new Bitmap(glyphImg2.Width, glyphImg2.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            //{
            //    var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImg2.Width, glyphImg2.Height),
            //        System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
            //    int[] intBuffer = glyphImg2.GetImageBuffer();

            //    System.Runtime.InteropServices.Marshal.Copy(intBuffer, 0, bmpdata.Scan0, intBuffer.Length);
            //    bmp.UnlockBits(bmpdata);
            //    bmp.Save("d:\\WImageTest\\a_total.png");
            //}
            //atlasBuilder.SaveFontInfo("d:\\WImageTest\\a_info.xml");
        }
예제 #17
0
        internal Typeface Read(BinaryReader reader)
        {
            //WOFF File
            //WOFFHeader        File header with basic font type and version, along with offsets to metadata and private data blocks.
            //TableDirectory    Directory of font tables, indicating the original size, compressed size and location of each table within the WOFF file.
            //FontTables        The font data tables from the input sfnt font, compressed to reduce bandwidth requirements.
            //ExtendedMetadata  An optional block of extended metadata, represented in XML format and compressed for storage in the WOFF file.
            //PrivateData       An optional block of private data for the font designer, foundry, or vendor to use.
            _header = ReadWOFFHeader(reader);
            if (_header == null)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine("can't read ");
#endif
                return(null); //notify user too
            }

            //
            WoffTableDirectory[] woffTableDirs = ReadTableDirectories(reader);
            if (woffTableDirs == null)
            {
                return(null);
            }
            //
            //try read each compressed table
            if (DecompressHandler == null)
            {
                if (WoffDefaultZlibDecompressFunc.DecompressHandler != null)
                {
                    DecompressHandler = WoffDefaultZlibDecompressFunc.DecompressHandler;
                }
                else
                {
#if DEBUG
                    System.Diagnostics.Debug.WriteLine("no Zlib DecompressHandler ");
#endif
                    return(null); //notify user too
                }
            }

            TableEntryCollection tableEntryCollection = CreateTableEntryCollection(woffTableDirs);

            using (MemoryStream decompressStream = new MemoryStream())
            {
                if (Extract(reader, woffTableDirs, decompressStream))
                {
                    using (ByteOrderSwappingBinaryReader reader2 = new ByteOrderSwappingBinaryReader(decompressStream))
                    {
                        decompressStream.Position = 0;
                        OpenFontReader openFontReader = new OpenFontReader();
                        return(openFontReader.ReadTableEntryCollection(tableEntryCollection, reader2));
                    }
                }
            }
            return(null);
        }
예제 #18
0
파일: Form1.cs 프로젝트: ywscr/Typography
        private void button3_Click(object sender, EventArgs e)
        {
            string filename = "Test/Sarabun-Regular.woff2";

            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                OpenFontReader  openFontReader  = new OpenFontReader();
                PreviewFontInfo previewFontInfo = openFontReader.ReadPreview(fs);
            }
        }
예제 #19
0
 public static FontFace LoadFont(string fontpath)
 {
     using (FileStream fs = new FileStream(fontpath, FileMode.Open, FileAccess.Read))
     {
         var      reader = new OpenFontReader();
         Typeface t      = reader.Read(fs);
         t.Filename = fontpath;
         return(LoadFont(t));
     }
 }
예제 #20
0
        static void CreateSampleMsdfTextureFont(string fontfile, float sizeInPoint, ushort startGlyphIndex, ushort endGlyphIndex, string outputFile)
        {
            //sample
            var reader = new OpenFontReader();

            using (var fs = new FileStream(fontfile, FileMode.Open))
            {
                //1. read typeface from font file
                Typeface typeface = reader.Read(fs);
                //sample: create sample msdf texture
                //-------------------------------------------------------------
                var builder = new GlyphPathBuilder(typeface);
                //builder.UseTrueTypeInterpreter = this.chkTrueTypeHint.Checked;
                //builder.UseVerticalHinting = this.chkVerticalHinting.Checked;
                //-------------------------------------------------------------
                var atlasBuilder = new SimpleFontAtlasBuilder();


                for (ushort gindex = startGlyphIndex; gindex <= endGlyphIndex; ++gindex)
                {
                    //build glyph
                    builder.BuildFromGlyphIndex(gindex, sizeInPoint);

                    var glyphToContour = new GlyphContourBuilder();
                    //glyphToContour.Read(builder.GetOutputPoints(), builder.GetOutputContours());
                    var genParams = new MsdfGenParams();
                    builder.ReadShapes(glyphToContour);
                    genParams.shapeScale = 1f / 64; //we scale later (as original C++ code use 1/64)
                    GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(glyphToContour, genParams);
                    atlasBuilder.AddGlyph(gindex, glyphImg);

                    //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                    //{
                    //    var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                    //    System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
                    //    bmp.UnlockBits(bmpdata);
                    //    bmp.Save("d:\\WImageTest\\a001_xn2_" + n + ".png");
                    //}
                }

                var glyphImg2 = atlasBuilder.BuildSingleImage();
                using (Bitmap bmp = new Bitmap(glyphImg2.Width, glyphImg2.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImg2.Width, glyphImg2.Height),
                                               System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                    int[] intBuffer = glyphImg2.GetImageBuffer();

                    System.Runtime.InteropServices.Marshal.Copy(intBuffer, 0, bmpdata.Scan0, intBuffer.Length);
                    bmp.UnlockBits(bmpdata);
                    bmp.Save("d:\\WImageTest\\a_total.png");
                }
                atlasBuilder.SaveFontInfo("d:\\WImageTest\\a_info.xml");
            }
        }
예제 #21
0
 public static FontFace LoadFont(
     string fontfile,
     TextureFontCreationParams creationParams,
     out SimpleFontAtlas fontAtlas)
 {
     using (FileStream fs = new FileStream(fontfile, FileMode.Open, FileAccess.Read))
     {
         var      reader   = new OpenFontReader();
         Typeface typeface = reader.Read(fs);
         return(LoadFont(typeface, creationParams, out fontAtlas));
     }
 }
예제 #22
0
        static void TestLoadAndReload(string filename)
        {
            //Trimmable feature tests:
            //[A] read the font file as usual => get full information about the font
            Typeface typeface = null;

            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                //read in full mode
                OpenFontReader openFontReader = new OpenFontReader();
                typeface = openFontReader.Read(fs);
            }

            //before
            bool     hasColor1  = typeface.HasColorTable();
            bool     hasSvg1    = typeface.HasSvgTable();
            bool     hasCff1    = typeface.IsCffFont;
            TrimMode glyphMode1 = typeface.GetTrimMode();
            Glyph    g1_1       = typeface.GetGlyph(1);

            //---------------------------------------------------------
            //[B] if you create paths from glyphs, or atlas from glyph
            //   and you don't want any glyph-building-detail (eg. to reduce memory usuage)
            //   but you still want to use the typeface for text-layout
            //   you can trim it down
            RestoreTicket ticket = typeface.TrimDown();//***

            //[C] you can GetGlyph() but this is ANOTHER NEW GLYPH
            //without building instruction( eg. no cff,ttf,svg data,bitmap)

            Glyph g1_2 = typeface.GetGlyph(1);

            //** if you cache the the old version of 'full-info' glyph**
            // the info is still cache on the old glyph and it can be used as 'full-info' glyph
            // TrimDown() DOES NOT go to delete that glyph.

            bool hasColor2 = typeface.HasColorTable();
            bool hasSvg2   = typeface.HasSvgTable();
            bool hasCff2   = typeface.IsCffFont;

            TrimMode glyphMode2 = typeface.GetTrimMode();

            //---------------------------------------------------------

            //[D] can we load glyph detail again?
            //yes=> this need 'ticket' from latest TrimDown()
            //if you don't have it, you can't restore it.

            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                typeface.RestoreUp(ticket, fs);
            }
        }
예제 #23
0
 void LoadFont()
 {
     if (_latinModernMathFont == null)
     {
         using (FileStream fs = new FileStream("Fonts/latinmodern-math.otf", FileMode.Open))
         //using (FileStream fs = new FileStream("Fonts/Asana-Math.otf", FileMode.Open))
         {
             OpenFontReader reader = new OpenFontReader();
             _latinModernMathFont = reader.Read(fs);
         }
     }
 }
예제 #24
0
 public static FontFace LoadFont(
     string fontpath,
     ScriptLang scriptLang,
     WriteDirection writeDirection = WriteDirection.LTR)
 {
     using (FileStream fs = new FileStream(fontpath, FileMode.Open, FileAccess.Read))
     {
         var      reader = new OpenFontReader();
         Typeface t      = reader.Read(fs);
         t.Filename = fontpath;
         return(LoadFont(t, scriptLang, writeDirection));
     }
 }
예제 #25
0
 public void Print(float size, string str, List <GlyphPlan> glyphPlanBuffer)
 {
     if (_currentTypeface == null)
     {
         OpenFontReader reader = new OpenFontReader();
         using (FileStream fs = new FileStream(_currentFontFilename, FileMode.Open))
         {
             _currentTypeface = reader.Read(fs);
         }
     }
     //-----------
     Print(_currentTypeface, size, str, glyphPlanBuffer);
 }
예제 #26
0
        static Fonts()
        {
            var reader            = new OpenFontReader();
            var latinMathTypeface = reader.Read(new MemoryStream(Resources.LatinModernMath, false));

            latinMathTypeface.UpdateAllCffGlyphBounds();
            GlobalTypefaces = new Typefaces(latinMathTypeface);

            var amsBlackboardBoldTypeface = reader.Read(new MemoryStream(Resources.AMSCapitalBlackboardBold, false));

            amsBlackboardBoldTypeface.UpdateAllCffGlyphBounds();
            GlobalTypefaces.AddStart(amsBlackboardBoldTypeface);
        }
예제 #27
0
        /// <summary>
        /// Create a new font instance
        /// </summary>
        /// <param name="fontStream">Stream to the font data</param>
        /// <param name="fontSizeInPixels">The desired font size in pixels</param>
        public Font(Stream fontStream, float fontSizeInPixels)
        {
            SetupWoffDecompressorIfRequired();

            FontSizeInPoints = fontSizeInPixels * PIXELS_TO_POINTS;
            loadedGlyphs     = new Dictionary <char, Glyph>();

            var reader = new OpenFontReader();

            typeface = reader.Read(fontStream);

            pathBuilder    = new GlyphPathBuilder(typeface);
            pathTranslator = new GlyphTranslatorToVertices();
        }
예제 #28
0
        public bool AddFont(FontStreamSource src)
        {
            //preview data of font
            using (Stream stream = src.ReadFontStream())
            {
                var             reader      = new OpenFontReader();
                PreviewFontInfo previewFont = reader.ReadPreview(stream);
                if (previewFont == null || string.IsNullOrEmpty(previewFont.Name))
                {
                    //err!
                    return(false);
                }
                //***
                if (previewFont.IsFontCollection)
                {
                    int  mbCount = previewFont.MemberCount;
                    bool passAll = true;
                    for (int i = 0; i < mbCount; ++i)
                    {
                        PreviewFontInfo member = previewFont.GetMember(i);

                        if (!RegisterFont(new InstalledFont(
                                              member.Name,
                                              member.SubFamilyName,
                                              member.TypographicFamilyName,
                                              member.TypographicSubFamilyName,
                                              src.PathName,
                                              member.Weight)
                        {
                            StreamOffset = member.ActualStreamOffset
                        }))
                        {
                            passAll = false;
                        }
                    }
                    return(passAll);
                }
                else
                {
                    return(RegisterFont(new InstalledFont(
                                            previewFont.Name,
                                            previewFont.SubFamilyName,
                                            previewFont.TypographicFamilyName,
                                            previewFont.TypographicSubFamilyName,
                                            src.PathName,
                                            previewFont.Weight)));
                }
            }
        }
예제 #29
0
 public bool AddFont(FontStreamSource src)
 {
     //preview data of font
     using (Stream stream = src.ReadFontStream())
     {
         var             reader      = new OpenFontReader();
         PreviewFontInfo previewFont = reader.ReadPreview(stream);
         if (string.IsNullOrEmpty(previewFont.fontName))
         {
             //err!
             return(false);
         }
         return(RegisterFont(new InstalledFont(previewFont.fontName, previewFont.fontSubFamily, src.PathName)));
     }
 }
예제 #30
0
        public bool LoadTTF(Stream stream)
        {
            var reader = new OpenFontReader();

            ttfTypeFace = reader.Read(stream);
            if (ttfTypeFace != null)
            {
                this.ascent     = ttfTypeFace.Ascender;
                this.descent    = ttfTypeFace.Descender;
                this.unitsPerEm = ttfTypeFace.UnitsPerEm;
                return(true);
            }

            return(false);
        }