Ejemplo n.º 1
0
        /// <summary>
        /// Output the Zpl string using given context
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public List <string> Render(ZplRenderOptions context)
        {
            var result = new List <string>();

            if (context.AddStartEndFormat)
            {
                result.Add("^XA");
            }

            if (context.AddDefaultLabelHome)
            {
                result.Add("^LH0,0");
            }

            result.Add(context.ChangeInternationalFontEncoding);

            foreach (var element in this.Where(x => x.IsEnabled))
            {
                //Empty line
                if (context.AddEmptyLineBeforeElementStart)
                {
                    result.Add("");
                }

                //Comments
                if (context.DisplayComments)
                {
                    if (element.Comments.Any())
                    {
                        result.Add("^FX");
                        element.Comments.ForEach(x => result.Add("//" + x.Replace("^", "[caret]").Replace("~", "[tilde]")));
                    }
                }

                //Actual element
                if (context.CompressedRendering)
                {
                    result.Add(string.Join("", element.Render(context)));
                }
                else
                {
                    result.AddRange(element.Render(context));
                }
            }

            if (context.AddStartEndFormat)
            {
                result.Add("^XZ");
            }

            return(result);
        }
Ejemplo n.º 2
0
 public string ToZplString(ZplRenderOptions context)
 {
     return(string.Join("\n", Render(context)));
 }