Example #1
0
        /// <summary>
        /// Creates new TinyFont based on the rules from <see cref="TinyDefinition"/>.
        /// </summary>
        /// <param name="definition">Definition rules for font.</param>
        /// <returns>An instance of <see cref="TinyFont"/>.</returns>
        protected TinyFont ConvertWithState(TinyDefinition definition)
        {
            if (_builder == null)
            {
                _builder = new TinyFontBuilder();
                _builder.GlyphTransform = _transform;
#if TERKA_FEATURES
                _builder.OpenTypeCompiler = new Terka.FontBuilder.OpenTypeCompiler();
#endif
            }

            Type[]   type      = new Type[1];
            object[] parameter = new object[1];

            foreach (TinyCommandBase command in definition)
            {
                if (command != null)
                {
                    type[0]      = command.GetType();
                    parameter[0] = command;

                    MethodInfo processMethod = typeof(TFConvert).GetMethod("Process", BindingFlags.NonPublic | BindingFlags.Instance, null, type, null);

                    if (processMethod != null)
                    {
                        processMethod.Invoke(this, parameter);
                    }
                }
            }

            if (_noDefaultImport == false)
            {
                Process(new SetDefaultCharacter());
            }

            TinyFont font = _builder.Build();
            MakePostBuildAdjustments(font);
            return(font);
        }
 private static void DumpFont(TinyDefinition definition, TinyFont font, TextWriter textWriter)
 {
 }
        private static void Main(string[] args)
        {
            Console.InputEncoding  = Encoding.UTF8;
            Console.OutputEncoding = Encoding.UTF8;

            try { Line = CommandLineHelper.Parse <CommandLine>(args); }
            catch { Line = new CommandLine {
                        ShowHelp = true
                    }; }

            if (Line != null)
            {
                if (Line.ShowHelp || Line.IsValid == false)
                {
                    Line.WriteHelp(Console.Out);
                }
                else
                {
                    TinyDefinition definition = new TinyDefinition();
                    TextReader     definitionReader;

                    try
                    {
                        // separate try catch block for file issues for compatibility reasons
                        definitionReader = new StreamReader(Line.InputFile, Encoding.UTF8, true);
                    }
                    catch
                    {
                        Console.WriteLine("Cannot open '{0}'!", Line.InputFile);
                        return;
                    }

                    try
                    {
                        definition.Load(definitionReader);
                    }
                    catch (Exception e)
                    {
                        // the TFConvert exception messages correspond to the native error strings
                        Console.WriteLine(e.Message);
                        return;
                    }

                    try
                    {
                        definition.Validate();
                    }
                    catch (KeyNotFoundException)
                    {
                        // currently the only required command
                        Console.WriteLine("SelectFont command not found in .FNTDEF file");
                        return;
                    }

                    definitionReader.Close();

                    TinyFont font = TFConvert.Convert(definition);
                    DumpFont(definition, font, Console.Out);

                    try
                    {
                        font.Save(Line.OutputFile);
                    }
                    catch
                    {
                        Console.WriteLine("Cannot open '{0}' for writing!", Line.OutputFile);
                        return;
                    }
                }
            }
        }
Example #4
0
 /// <summary>
 /// Creates new TinyFont based on the rules from <see cref="TinyDefinition"/>.
 /// </summary>
 /// <param name="definition">Definition rules for font.</param>
 /// <returns>An instance of <see cref="TinyFont"/>.</returns>
 public static TinyFont Convert(TinyDefinition definition)
 {
     return(new TFConvert().ConvertWithState(definition));
 }