예제 #1
0
        public override FieldFont Process(FontDescription input, ContentProcessorContext context)
        {
            var msdfgen = Path.Combine(Directory.GetCurrentDirectory(), this.ExternalPath);
            var objPath = Path.Combine(Directory.GetCurrentDirectory(), "obj");

            if (File.Exists(msdfgen))
            {
                var glyphs = new FieldGlyph[input.Characters.Count];

                // Generate a distance field for each character using msdfgen
                Parallel.For(
                    0,
                    input.Characters.Count,
                    i =>
                {
                    var c     = input.Characters[i];
                    glyphs[i] = CreateFieldGlyphForCharacter(c, input, msdfgen, objPath);
                });

                var kerning = ReadKerningInformation(input.Path, input.Characters);
                return(new FieldFont(input.Path, glyphs, kerning, this.Range));
            }

            throw new FileNotFoundException(
                      "Could not find msdfgen. Check your content processor parameters",
                      msdfgen);
        }
예제 #2
0
        private FieldGlyph CreateFieldGlyphForCharacter(char c, FontDescription input, string msdfgen, string objPath)
        {
            var metrics = CreateDistanceFieldForCharacter(input, msdfgen, objPath, c);
            var path    = GetOuputPath(objPath, input, c);
            var bytes   = File.ReadAllBytes(path);
            var glyph   = new FieldGlyph(c, bytes, metrics);

            return(glyph);
        }
예제 #3
0
        public override FieldFont Process(FontDescription input, ContentProcessorContext context)
        {
            System.Diagnostics.Debugger.Break();

            string msdfgen = Path.Combine(Directory.GetCurrentDirectory(), ExternalPath);
            string objPath;
            string simplePath = "";

            if (PackTextures)
            {
                // Garbage
                objPath = Path.Combine(Directory.GetCurrentDirectory(), "obj");
            }
            else
            {
                // Store
                objPath = Path.Combine(Path.GetDirectoryName(input.Path), TextureFolder);

                Uri fullPath = new Uri(objPath, UriKind.Absolute);
                Uri rootPath = new Uri(Directory.GetCurrentDirectory() + "/", UriKind.Absolute);
                Uri relUri   = rootPath.MakeRelativeUri(fullPath);
                simplePath = relUri.ToString();
            }

            Console.WriteLine(objPath);
            Console.WriteLine(simplePath);


            if (File.Exists(msdfgen))
            {
                var glyphs = new FieldGlyph[input.Characters.Count];

                // Generate a distance field for each character using msdfgen

                /*Parallel.For(
                 *  0,
                 *  input.Characters.Count,
                 *  i =>
                 *  {
                 *      var c = input.Characters[i];
                 *      glyphs[i] = CreateFieldGlyphForCharacter(c, input, msdfgen, objPath, simplePath);
                 *  });*/
                for (int i = 0; i < input.Characters.Count; i++)
                {
                    var c = input.Characters[i];
                    glyphs[i] = CreateFieldGlyphForCharacter(c, input, msdfgen, objPath, simplePath);
                }

                var kerning = ReadKerningInformation(input.Path, input.Characters);
                return(new FieldFont(input.Path, glyphs, kerning, Range, Resolution));
            }

            throw new FileNotFoundException(
                      "Could not find msdfgen. Check your content processor parameters",
                      msdfgen);
        }
예제 #4
0
        private GlyphInfo GetInfo(char c)
        {
            FieldGlyph glyph = GetGlyph(c);

            if (glyph == null)
            {
                return(null);
            }

            return(new GlyphInfo(c, GetGlyph(c).Metrics));
        }
예제 #5
0
        private FieldGlyph CreateFieldGlyphForCharacter(char c, FontDescription input, string msdfgen, string objPath, string simplePath)
        {
            var        metrics = CreateDistanceFieldForCharacter(input, msdfgen, objPath, c);
            var        path    = GetOuputPath(objPath, input, c);
            FieldGlyph glyph;

            if (PackTextures)
            {
                glyph = new FieldGlyph(c, File.ReadAllBytes(path), metrics);
            }
            else
            {
                string name        = Path.GetFileNameWithoutExtension(input.Path);
                string contentPath = Path.Combine(simplePath, $"{name}-{(int)c}");
                if (UseCVars)
                {
                    contentPath = CVarPrefix + "character_" + (int)c;
                }
                glyph = new FieldGlyph(c, contentPath, metrics);
            }

            return(glyph);
        }