Exemplo n.º 1
0
        public void LoadData()
        {
            //File.Seek(0);

            UnitsPerEm = File.GetUint16();
            XMin       = File.GetInt16();
            YMin       = File.GetInt16();
            XMax       = File.GetInt16();
            YMax       = File.GetInt16();

            var c = File.GetInt32();

            for (int i = 0; i < c; i++)
            {
                var g = new CGLFGlyph();

                g.YMin = File.GetInt16();
                g.YMax = File.GetInt16();
                g.XMax = File.GetInt16();
                g.XMin = File.GetInt16();

                var triangleCount = File.GetInt32();

                for (int j = 0; j < triangleCount; j++)
                {
                    var at      = new Point(File.GetInt32(), File.GetInt32());
                    var bt      = new Point(File.GetInt32(), File.GetInt32());
                    var ct      = new Point(File.GetInt32(), File.GetInt32());
                    var trianle = new Triangle(at, bt, ct);

                    g.Triangles.Add(trianle);
                    Glyphs.Add(g);
                }
            }
        }
Exemplo n.º 2
0
        public static void LoadGlyphs()
        {
            // Construct a directory of Glyphs
            var glyphDirectory = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Assembly), "Glyphs"));

            // Loop through all of the directories and map the glyphs to their appropriate libraries
            foreach (var directory in glyphDirectory.EnumerateDirectories())
            {
                // Instantiate the dictionary with the name of the library
                Glyphs.Add(directory.Name, new Dictionary <string, LazyImage>());
                // Iterate through all of the glyphs in this dictionary
                foreach (var glyph in directory.EnumerateFiles("*.png", SearchOption.AllDirectories))
                {
                    try
                    {
                        // Created a lazily loaded glyph that points to the appropriate path
                        Glyphs[directory.Name].Add(Path.GetFileNameWithoutExtension(glyph.Name), new LazyImage {
                            Path = new Uri(glyph.FullName, UriKind.RelativeOrAbsolute)
                        });
                    }
                    catch (Exception)
                    {
                        // An error occurred when creating the glyph, ignore it (it will be handled in the provider)
                    }
                }
            }
        }
Exemplo n.º 3
0
        void BuildGlyphs()
        {
            if (Glyphs == null)
            {
                Glyphs = new List <Glyph>();
            }

            Glyphs.Clear();
            float innerWidth  = Size.X - Border.X * 2;
            float innerHeight = Size.Y - Border.Y * 2;

            Glyphs.Add(GetGlyph(Orientation.TopLeft, new Vector3(0, 0, 0), new Vector2(Border.X, Border.Y), TextureSize));
            Glyphs.Add(GetGlyph(Orientation.Top, new Vector3(Border.X, 0, 0), new Vector2(innerWidth, Border.Y), TextureSize));
            Glyphs.Add(GetGlyph(Orientation.TopRight, new Vector3(Border.X + innerWidth, 0, 0), new Vector2(Border.X, Border.Y), TextureSize));
            Glyphs.Add(GetGlyph(Orientation.Left, new Vector3(0, Border.Y, 0), new Vector2(Border.X, innerHeight), TextureSize));
            Glyphs.Add(GetGlyph(Orientation.Right, new Vector3(Border.X + innerWidth, Border.Y, 0), new Vector2(Border.X, innerHeight), TextureSize));
            Glyphs.Add(GetGlyph(Orientation.BottomLeft, new Vector3(0, Border.Y + innerHeight, 0), new Vector2(Border.X, Border.Y), TextureSize));
            Glyphs.Add(GetGlyph(Orientation.Bottom, new Vector3(Border.X, Border.Y + innerHeight, 0), new Vector2(innerWidth, Border.Y), TextureSize));
            Glyphs.Add(GetGlyph(Orientation.BottomRight, new Vector3(Border.X + innerWidth, Border.Y + innerHeight, 0), new Vector2(Border.X, Border.Y), TextureSize));

            if (BackgroundStyle == BorderBackgroundStyle.Inner)
            {
                Glyphs.Add(GetGlyph(Orientation.Center, new Vector3(Border.X, Border.Y, 0), new Vector2(innerWidth, innerHeight), TextureSize));
            }
            else
            {
                Glyphs.Add(GetGlyph(Orientation.Center, new Vector3(0, 0, 0), new Vector2(Border.X, Border.Y), TextureSize));
            }
        }
Exemplo n.º 4
0
        public override Glyph GetGlyph(char c)
        {
            Glyph glyph;

            if (!Glyphs.TryGetValue(c, out glyph))
            {
                uint glyphIndex = Face.GetCharIndex(c);
                if (glyphIndex == 0)
                {
                    return(null);
                }

                byte[] bufferData;
                Face.LoadGlyph(glyphIndex, LoadFlags.Default, LoadTarget.Normal);
                if (Face.Glyph.Metrics.Width == 0)
                {
                    bufferData = new Byte[0];
                }
                else
                {
                    Face.Glyph.RenderGlyph(RenderMode.Normal);
                    bufferData = Face.Glyph.Bitmap.BufferData;
                }
                glyph = new TTFGlyph(c, glyphIndex, bufferData, Face.Glyph.Metrics, Face.Glyph.BitmapLeft, Graphics);
                Glyphs.Add(c, glyph);
            }

            return(glyph);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Function to build the list of glyphs for the font.
        /// </summary>
        /// <param name="glyphData">The glyph data used to create the glyphs.</param>
        /// <param name="kerningData">The kerning information used to handle spacing adjustment between glyphs.</param>
        private void GenerateGlyphs(Dictionary <char, GlyphInfo> glyphData, Dictionary <char, ABC> kerningData)
        {
            foreach (KeyValuePair <char, GlyphInfo> glyph in glyphData)
            {
                int advance = 0;

                if (kerningData.TryGetValue(glyph.Key, out ABC kernData))
                {
                    advance = kernData.A + (int)kernData.B + kernData.C;
                }

                // For whitespace, we add a dummy glyph (no texture, offset, etc...).
                if (char.IsWhiteSpace(glyph.Key))
                {
                    Glyphs.Add(new GorgonGlyph(glyph.Key, glyph.Value.Region.Width)
                    {
                        Offset = DX.Point.Zero
                    });
                    continue;
                }

                var newGlyph = new GorgonGlyph(glyph.Key, advance)
                {
                    Offset        = glyph.Value.Offset,
                    OutlineOffset = HasOutline ? glyph.Value.OutlineOffset : DX.Point.Zero
                };

                // Assign the texture to each glyph (and its outline if needed).
                newGlyph.UpdateTexture(glyph.Value.Texture, glyph.Value.Region, HasOutline ? glyph.Value.OutlineRegion : DX.Rectangle.Empty, glyph.Value.TextureArrayIndex);

                Glyphs.Add(newGlyph);
            }
        }
Exemplo n.º 6
0
        public DigitalFont()
        {
            Glyphs.Add('0', Zero());
            Glyphs.Add('1', One());
            Glyphs.Add('2', Two());
            Glyphs.Add('3', Three());
            Glyphs.Add('4', Four());
            Glyphs.Add('5', Five());
            Glyphs.Add('6', Six());
            Glyphs.Add('7', Seven());
            Glyphs.Add('8', Eight());
            Glyphs.Add('9', Nine());
            Glyphs.Add(':', Colon());
            Glyphs.Add('-', Dash());
            Glyphs.Add('/', Slash());
            Glyphs.Add('\\', Backslash());

            Glyphs.Add('F', F());
            Glyphs.Add('P', P());
            Glyphs.Add('A', A());
            Glyphs.Add('M', M());
            Glyphs.Add('S', S());

            Glyphs.Add(' ', Space());
            Glyphs.Add('\t', Tab());
        }
Exemplo n.º 7
0
        public Grapheme(List <Glyph> glyphs)
        {
            Initialize();

            var glyphChain = new GlyphChain(glyphs);

            Glyphs.Add(glyphChain);
            Graph = glyphChain.ToString();
        }
Exemplo n.º 8
0
        private void DrawTextureAtlas(System.Drawing.Font font)
        {
            using (var g = System.Drawing.Graphics.FromImage(Image))
            {
                g.Clear(System.Drawing.Color.Transparent);
                g.SmoothingMode     = SmoothingMode.HighQuality;
                g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                var brString  = new SolidBrush(System.Drawing.Color.White);
                var brOutline = new SolidBrush(System.Drawing.Color.Black);

                for (int i = 0; i < chars.Length; i++)
                {
                    if (Glyphs.ContainsKey(chars[i]))
                    {
                        continue;
                    }

                    var x    = locations[i].X;
                    var y    = locations[i].Y;
                    var size = sizes[i];

                    var c = chars[i].ToString();

                    if (Outline)
                    {
                        g.DrawString(c, font, brOutline, x - 1, y, StringFormat.GenericTypographic);
                        g.DrawString(c, font, brOutline, x + 1, y, StringFormat.GenericTypographic);
                        g.DrawString(c, font, brOutline, x, y - 1, StringFormat.GenericTypographic);
                        g.DrawString(c, font, brOutline, x, y + 1, StringFormat.GenericTypographic);
                    }
                    g.DrawString(c, font, brString, x, y, StringFormat.GenericTypographic);

                    var glyph = new Glyph
                    {
                        Size = size,
                        UV   = new[]
                        {
                            new Vector2(x / Image.Width, y / Image.Height),
                            new Vector2(
                                (x + size.Width) / Image.Width,
                                (y + size.Height) / Image.Height
                                ),
                        },
                        Code = chars[i]
                    };

                    Glyphs.Add(chars[i], glyph);
                }

                brString.Dispose();
                brOutline.Dispose();
            }

            Image.Save(string.Format("{0} {1}.png", font.FontFamily.Name, (int)font.Size), ImageFormat.Png);
        }
Exemplo n.º 9
0
        public Grapheme(Glyph glyph)
        {
            Initialize();

            var glyphChain = new GlyphChain(new List <Glyph>()
            {
                glyph
            });

            Glyphs.Add(glyphChain);
            Graph = glyph.ToString();
        }
Exemplo n.º 10
0
 public void GenerateBounds()
 {
     Color[] colors = new Color[Texture.Width * Texture.Height];
     Texture.GetData(colors);
     for (int j = 0; j < Rows; j++)
     {
         for (int i = 0; i < Cols; i++)
         {
             char c = (char)(((j * Cols) + i) + 32);
             Glyphs.Add(c, CreateGlyphFromSheet(c, i, j, colors));
             LineHeight = Math.Max(LineHeight, Glyphs[c].Height);
         }
     }
 }
Exemplo n.º 11
0
        public void Read(Stream inputStream)
        {
            BinaryReader reader = new BinaryReader(inputStream, Encoding.Default, true);

            Unknown1 = reader.ReadInt32();
            Unknown2 = reader.ReadInt16();
            short glyphCount = reader.ReadInt16();
            int   size       = reader.ReadInt32();

            Unknown3 = reader.ReadInt32();
            for (int i = 0; i < glyphCount; i++)
            {
                Glyphs.Add(Glyph.ReadGlyph(inputStream));
            }
        }
Exemplo n.º 12
0
        public void AddGlyphChain(List <Glyph> glyphs)
        {
            var glyphChain = new GlyphChain(glyphs);

            if (Glyphs != null)
            {
                if (Glyphs.Count == 0)
                {
                    Graph = glyphChain.ToString();
                }

                if (!Glyphs.Contains(glyphChain))
                {
                    Glyphs.Add(glyphChain);
                }
            }
        }
Exemplo n.º 13
0
        public static void Update()
        {
            // Keep the frame stuck so we can do a bunch of injecting at once.
            using (StyxWoW.Memory.AcquireFrame())
            {
                CurrentSpec = StyxWoW.Me.Specialization;

                Talents.Clear();
                TalentId = new int[6];

                // Always 18 talents. 6 rows of 3 talents.
                for (int index = 1; index <= 6 * 3; index++)
                {
                    var selected =
                        Lua.GetReturnVal <bool>(
                            string.Format(
                                "local t= select(5,GetTalentInfo({0})) if t == true then return 1 end return nil", index),
                            0);
                    var t = new Talent {
                        Index = index, Selected = selected
                    };
                    Talents.Add(t);

                    TalentId[(index - 1) / 3] = index;
                }

                Glyphs.Clear();
                GlyphId = new int[6];

                // 6 glyphs all the time. Plain and simple!
                for (int i = 1; i <= 6; i++)
                {
                    List <string> glyphInfo = Lua.GetReturnValues(String.Format("return GetGlyphSocketInfo({0})", i));

                    // add check for 4 members before access because empty sockets weren't returning 'nil' as documented
                    if (glyphInfo != null && glyphInfo.Count >= 4 && glyphInfo[3] != "nil" &&
                        !string.IsNullOrEmpty(glyphInfo[3]))
                    {
                        GlyphId[i - 1] = int.Parse(glyphInfo[3]);
                        Glyphs.Add(WoWSpell.FromId(GlyphId[i - 1]).Name.Replace("Glyph of ", ""));
                    }
                }
            }
        }
Exemplo n.º 14
0
        public void AddGlyphChain(Glyph glyph)
        {
            var glyphChain = new GlyphChain(new List <Glyph>()
            {
                glyph
            });

            if (Glyphs != null)
            {
                if (Glyphs.Count == 0)
                {
                    Graph = glyph.ToString();
                }

                if (!Glyphs.Contains(glyphChain))
                {
                    Glyphs.Add(glyphChain);
                }
            }
        }
Exemplo n.º 15
0
        protected Glyph RegisterGlyph(
            uint charCode,
            Rectangle sourceArea,
            double bearingX,
            double bearingY,
            double width,
            double height,
            double advanceX,
            double advanceY
            )
        {
            Glyph glyph = new Glyph(
                sourceArea,
                bearingX,
                bearingY,
                width,
                height,
                advanceX,
                advanceY
                );

            Glyphs.Add(charCode, glyph);
            return(glyph);
        }
Exemplo n.º 16
0
 public void AddGlyph(CGLFGlyph g)
 {
     Glyphs.Add(g);
 }