コード例 #1
0
        void RunSampleF(PixelFarm.Drawing.Painter p)
        {
            //version 4:
            p.Clear(PixelFarm.Drawing.Color.White);
            p.UseSubPixelLcdEffect = this.EnableSubPix;
            //--------------------------
            p.StrokeColor = PixelFarm.Drawing.Color.Black;
            p.StrokeWidth = 2.0f;
            p.DrawLine(2, 0, 10, 15);

            int lineLen = 10;
            int x       = 30;
            int y       = 30;

            p.FillColor = PixelFarm.Drawing.Color.Black;

            VertexStorePool pool = new VertexStorePool();

            using (System.IO.FileStream fs = new System.IO.FileStream("c:\\Windows\\Fonts\\tahoma.ttf", System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                Typography.OpenFont.OpenFontReader reader   = new Typography.OpenFont.OpenFontReader();
                Typography.OpenFont.Typeface       typeface = reader.Read(fs);


                var builder = new Typography.Contours.GlyphPathBuilder(typeface);
                builder.BuildFromGlyphIndex((ushort)typeface.LookupIndex('C'), 16);
                PixelFarm.Drawing.Fonts.GlyphTranslatorToVxs tovxs = new Drawing.Fonts.GlyphTranslatorToVxs();
                builder.ReadShapes(tovxs);
                VertexStore vxs = new VertexStore();
                tovxs.WriteOutput(vxs);
                p.Fill(vxs);
            }
            p.FillRect(0, 0, 20, 20);
        }
コード例 #2
0
ファイル: TypeFace.cs プロジェクト: ruicraveiro87/agg-sharp
        public bool LoadTTF(Stream stream)
        {
            var reader = new Typography.OpenFont.OpenFontReader();

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

            return(false);
        }
コード例 #3
0
        public bool LoadTTF(Stream stream)
        {
            var reader = new Typography.OpenFont.OpenFontReader();

            _ofTypeface = reader.Read(stream);
            if (_ofTypeface != null)
            {
                this.ascent             = _ofTypeface.Ascender;
                this.descent            = _ofTypeface.Descender;
                this.unitsPerEm         = _ofTypeface.UnitsPerEm;
                this.underline_position = _ofTypeface.UnderlinePosition;
                var bounds = _ofTypeface.Bounds;
                this.boundingBox = new RectangleInt(bounds.XMin, bounds.YMin, bounds.XMax, bounds.YMax);
                return(true);
            }

            return(false);
        }
コード例 #4
0
        public static void BuildFontAtlas(AtlasProject atlasProj)
        {
            foreach (AtlasItemSourceFile atlasSourceFile in atlasProj.Items)
            {
                if (atlasSourceFile.Kind == AtlasItemSourceKind.FontAtlasConfig &&
                    atlasSourceFile.FontBuilderConfig != null)
                {
                    FontBuilderConfig config = atlasSourceFile.FontBuilderConfig;
                    foreach (FontBuilderTask builderTask in config.BuilderTasks)
                    {
                        //1. create glyph-texture-bitmap generator
                        var glyphTextureGen = new GlyphTextureBitmapGenerator();
                        glyphTextureGen.SetSvgBmpBuilderFunc(SvgBuilderHelper.ParseAndRenderSvg);
                        //2. generate the glyphs
                        if (builderTask.TextureKind == TextureKind.Msdf)
                        {
                            glyphTextureGen.MsdfGenVersion = 3;
                        }

                        Typography.OpenFont.Typeface typeface = atlasProj.GetTypeface(config.FontFilename);

                        //TODO: add other font styles
                        RequestFont reqFont = new RequestFont(typeface.Name, builderTask.Size, FontStyle.Regular);


                        string textureName = typeface.Name.ToLower() + "_" + reqFont.FontKey;
                        string outputDir   = Path.GetDirectoryName(atlasProj.OutputFilename);
                        FontAtlasBuilderHelper builderHelper = new FontAtlasBuilderHelper();

                        builderHelper.TextureInfoFilename = outputDir + Path.DirectorySeparatorChar + textureName;
                        builderHelper.OutputImgFilename   = outputDir + Path.DirectorySeparatorChar + textureName + ".png";

                        builderHelper.Build(glyphTextureGen,
                                            typeface,
                                            builderTask.Size,
                                            builderTask.TextureKind,
                                            builderTask.TextureBuildDetails.ToArray(),
                                            reqFont.FontKey
                                            );
                    }
                }
            }
        }
コード例 #5
0
        void RunSampleF(PixelFarm.Drawing.Painter p)
        {
            //version 4:
            p.Clear(PixelFarm.Drawing.Color.White);
            p.UseLcdEffectSubPixelRendering = this.EnableSubPix;
            //--------------------------
            p.StrokeColor = PixelFarm.Drawing.Color.Black;
            p.StrokeWidth = 2.0f;
            //p.DrawLine(2, 0, 10, 15);

            int lineLen = 10;
            int x       = 30;
            int y       = 30;

            p.FillColor = PixelFarm.Drawing.Color.Black;


            using (System.IO.FileStream fs = new System.IO.FileStream("c:\\Windows\\Fonts\\tahoma.ttf", System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                Typography.OpenFont.OpenFontReader reader   = new Typography.OpenFont.OpenFontReader();
                Typography.OpenFont.Typeface       typeface = reader.Read(fs);


                var builder = new Typography.OpenFont.Contours.GlyphOutlineBuilder(typeface);
                builder.BuildFromGlyphIndex((ushort)typeface.GetGlyphIndex('C'), 24);

                var tovxs = new Typography.OpenFont.Contours.GlyphTranslatorToVxs();
                builder.ReadShapes(tovxs);

                using (Tools.BorrowVxs(out var vxs))
                {
                    tovxs.WriteOutput(vxs);
                    p.Fill(vxs);
                }
            }
            // p.FillRect(0, 0, 20, 20);
        }
コード例 #6
0
 public GlyphOutlineBuilder(Typography.OpenFont.Typeface typeface) : base(typeface)
 {
 }
コード例 #7
0
 public GlyphPathBuilder(Typography.OpenFont.Typeface typeface) : base(typeface)
 {
 }
コード例 #8
0
ファイル: Glyph.cs プロジェクト: zzxxhhzxh/CSharpMath
 public Glyph(Typography.OpenFont.Typeface typeface, Typography.OpenFont.Glyph info)
 {
     Typeface = typeface ?? throw new System.ArgumentNullException(nameof(typeface));
     Info     = info ?? throw new System.ArgumentNullException(nameof(info));
 }
コード例 #9
0
ファイル: Glyph.cs プロジェクト: zzxxhhzxh/CSharpMath
 public void Deconstruct
     (out Typography.OpenFont.Typeface typeface, out Typography.OpenFont.Glyph glyph)
 {
     typeface = Typeface; glyph = Info;
 }
コード例 #10
0
ファイル: Form1.cs プロジェクト: jgimness/Typography
        private void cmdMeasureTextSpan_Click(object sender, System.EventArgs e)
        {
            //set some Gdi+ props...
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.Clear(Color.White);
            //credit:
            //http://stackoverflow.com/questions/1485745/flip-coordinates-when-drawing-to-control
            g.ScaleTransform(1.0F, -1.0F);           // Flip the Y-Axis
            g.TranslateTransform(0.0F, -(float)300); // Translate the drawing area accordingly

            //--------------------------------
            //textspan measurement sample
            //--------------------------------
            _currentTextPrinter.HintTechnique     = (HintTechnique)lstHintList.SelectedItem;
            _currentTextPrinter.PositionTechnique = (PositionTechnique)cmbPositionTech.SelectedItem;
            //render at specific pos
            float x_pos = 0, y_pos = 100;

            char[] textBuffer = txtInputChar.Text.ToCharArray();

            //Example 1: this is a basic draw sample
            _currentTextPrinter.FillColor      = Color.Black;
            _currentTextPrinter.TargetGraphics = g;
            _currentTextPrinter.DrawString(
                textBuffer,
                0,
                textBuffer.Length,
                x_pos,
                y_pos
                );
            //
            //--------------------------------------------------
            //Example 2: print glyph plan to 'user' list-> then draw it (or hold it/ not draw)
            //you can create you own class to hold userGlyphPlans.***
            //2.1

            _reusableUnscaledGlyphPlanList.Clear();
            _currentTextPrinter.GenerateGlyphPlan(textBuffer, 0, textBuffer.Length, _reusableUnscaledGlyphPlanList);
            //2.2
            //and we can print the formatted glyph plan later.
            y_pos -= _currentTextPrinter.FontLineSpacingPx;
            _currentTextPrinter.FillColor = Color.Red;

            _currentTextPrinter.DrawFromGlyphPlans(
                new GlyphPlanSequence(_reusableUnscaledGlyphPlanList),
                x_pos,
                y_pos
                );

            //Example 3: MeasureString

            Typography.OpenFont.Typeface typeface = _currentTextPrinter.Typeface;

            UnscaledGlyphPlanList userGlyphPlans = new UnscaledGlyphPlanList();

            _currentTextPrinter.GlyphLayoutMan.GenerateUnscaledGlyphPlans(userGlyphPlans);

            MeasuredStringBox strBox = new MeasuredStringBox();

            throw new System.NotSupportedException();

            //_currentTextPrinter.GlyphLayoutMan.LayoutAndMeasureString(
            //  textBuffer, 0, textBuffer.Length,
            //  _currentTextPrinter.FontSizeInPoints,
            //  true,
            //  userGlyphPlans);

            float x_pos2 = x_pos + strBox.width + 10;

            g.DrawRectangle(Pens.Red, x_pos, y_pos + strBox.descending, strBox.width, strBox.CalculateLineHeight());
            g.DrawLine(Pens.Blue, x_pos, y_pos, x_pos2, y_pos);                                          //baseline
            g.DrawLine(Pens.Green, x_pos, y_pos + strBox.descending, x_pos2, y_pos + strBox.descending); //descending
            g.DrawLine(Pens.Magenta, x_pos, y_pos + strBox.ascending, x_pos2, y_pos + strBox.ascending); //ascending


            Typography.OpenFont.TypefaceExtension2.UpdateAllCffGlyphBounds(typeface);
            float pxscale = typeface.CalculateScaleToPixelFromPointSize(_currentTextPrinter.FontSizeInPoints);

            int j = userGlyphPlans.Count;

            for (int i = 0; i < j; ++i)
            {
                UnscaledGlyphPlan         glyphPlan = userGlyphPlans[i];
                Typography.OpenFont.Glyph glyph     = typeface.GetGlyphByIndex(glyphPlan.glyphIndex);
                //
                Typography.OpenFont.Bounds b = glyph.Bounds;
                //
                float xmin = b.XMin * pxscale;
                float ymin = b.YMin * pxscale;
                //
                float xmax = b.XMax * pxscale;
                float ymax = b.YMax * pxscale;
                //
                float glyph_x = x_pos + glyphPlan.OffsetX;
                g.DrawRectangle(Pens.Red, glyph_x + xmin, y_pos + ymin, xmax - xmin, ymax - ymin);
            }


            //------------
            _currentTextPrinter.FillColor = Color.Black;
            //transform back
            g.ScaleTransform(1.0F, -1.0F);           // Flip the Y-Axis
            g.TranslateTransform(0.0F, -(float)300); // Translate the drawing area accordingly
        }