public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Data();
            //ExStart: 1
            string fileName = dataDir + "courier.pfb"; //Font file name with full path

            FontDefinition fd   = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new FileSystemStreamSource(fileName)));
            Type1Font      font = Aspose.Font.Font.Open(fd) as Type1Font;

            bool latinText = true;


            for (uint code = 65; code < 123; code++)
            {
                GlyphId gid = font.Encoding.DecodeToGid(code);
                if (gid == null || gid == GlyphUInt32Id.NotDefId)
                {
                    latinText = false;
                }
            }

            if (latinText)
            {
                Console.WriteLine(string.Format("Font {0} supports latin symbols.", font.FontName));
            }
            else
            {
                Console.WriteLine(string.Format("Latin symbols are not supported by font {0}.", font.FontName));
            }
            //ExEnd: 1
        }
Esempio n. 2
0
        public bool TryGetGlyphImage(Font font, int codepoint, out SubTexture texture, out ResourceHandle<Material> material)
        {
            material = textMaterial;

            var glyphId = new GlyphId(font, codepoint);
            if (glyphSubTextures.TryGetValue(glyphId, out texture))
                return true;

            var nativeFont = font.EngineFont.Resolve();
            var imageHandle = nativeFont.CreateGlyphImage(codepoint, font.Size);

            if (imageHandle.Id == ResourceHandle<Resource>.Invalid)
                return false;

            if (!textureAtlas.AddImage(imageHandle))
            {
                throw new Exception("Atlas full");
            }

            if (!textureAtlas.GetImageSubTexture(imageHandle, out texture))
                return false;

            glyphSubTextures.Add(glyphId, texture);

            return true;
        }
Esempio n. 3
0
        //Default constructor
        public Glyph(GlyphId glyphId, string nName, int nVarargs, byte nArgs, string nSyntax, string nDesc)
        {
            Name = nName;

            glyph = glyphId;
            Id    = (byte)glyph;

            Varargs = nVarargs;
            Args    = nArgs;
            Syntax  = nSyntax;
            Desc    = nDesc;
        }
Esempio n. 4
0
        public bool TryGetGlyphInfo(Font font,int codepoint, out Glyph glyph)
        {
            var glyphId = new GlyphId(font, codepoint);
            if (glyphInfos.TryGetValue(glyphId, out glyph))
                return true;

            var nativeFont = font.EngineFont.Resolve();

            if (!nativeFont.GetGlyphInfo(codepoint, font.Size, out glyph))
                return false;

            glyphInfos[glyphId] = glyph;
            return true;
        }
Esempio n. 5
0
        //ExEnd: 2

        //ExStart: 3
        static void DrawText(string text, IFont font, double fontSize,
                             Brush backgroundBrush, Brush textBrush, string outFile)
        {
            //Get glyph identifiers for every symbol in text line
            GlyphId[] gids = new GlyphId[text.Length];
            for (int i = 0; i < text.Length; i++)
            {
                gids[i] = font.Encoding.DecodeToGid(text[i]);
            }
            // set common drawing settings
            double dpi = 300;

            double resolutionCorrection = dpi / 72; // 72 is font's internal dpi
            // prepare output bitmap
            Bitmap outBitmap = new Bitmap(960, 720);

            outBitmap.SetResolution((float)dpi, (float)dpi);
            Graphics outGraphics = Graphics.FromImage(outBitmap);

            outGraphics.FillRectangle(backgroundBrush, 0, 0, outBitmap.Width, outBitmap.Height);
            outGraphics.SmoothingMode = SmoothingMode.HighQuality;
            //declare coordinate variables and previous gid
            GlyphId previousGid      = null;
            double  glyphXCoordinate = 0;
            double  glyphYCoordinate = fontSize * resolutionCorrection;

            //loop which paints every glyph in gids
            foreach (GlyphId gid in gids)
            {
                // if the font contains the gid
                if (gid != null)
                {
                    Glyph glyph = font.GlyphAccessor.GetGlyphById(gid);
                    if (glyph == null)
                    {
                        continue;
                    }

                    // path that accepts drawing instructions
                    GraphicsPath path = new GraphicsPath();

                    // Create IGlyphOutlinePainter implementation
                    GlyphOutlinePainter outlinePainter = new GlyphOutlinePainter(path);

                    // Create the renderer
                    Aspose.Font.Renderers.IGlyphRenderer renderer = new
                                                                    Aspose.Font.Renderers.GlyphOutlineRenderer(outlinePainter);

                    // get common glyph properties
                    double kerning = 0;

                    // get kerning value
                    if (previousGid != null)
                    {
                        kerning = (font.Metrics.GetKerningValue(previousGid, gid) /
                                   glyph.SourceResolution) * fontSize * resolutionCorrection;
                        kerning += FontWidthToImageWith(font.Metrics.GetGlyphWidth(previousGid),
                                                        glyph.SourceResolution, fontSize);
                    }

                    // glyph positioning - increase glyph X coordinate according to kerning distance
                    glyphXCoordinate += kerning;

                    // Glyph placement matrix
                    TransformationMatrix glyphMatrix =
                        new TransformationMatrix(
                            new double[]
                    {
                        fontSize *resolutionCorrection,
                        0,
                        0,
                        // negative because of bitmap coordinate system begins from the top
                        -fontSize *resolutionCorrection,
                        glyphXCoordinate,
                        glyphYCoordinate
                    });

                    // render current glyph
                    renderer.RenderGlyph(font, gid, glyphMatrix);
                    // fill the path
                    path.FillMode = FillMode.Winding;
                    outGraphics.FillPath(textBrush, path);
                }
                //set current gid as previous to get correct kerning for next glyph
                previousGid = gid;
            }
            //Save results
            outBitmap.Save(outFile);
        }