예제 #1
0
        /// <summary>
        /// 画文字
        /// </summary>
        /// <param name="startX">文字起始x坐标</param>
        /// <param name="startY">文字起始y坐标</param>
        /// <param name="text">内容</param>
        /// <param name="fontSize">字体大小</param>
        /// <param name="fontZoom">字体缩放</param>
        /// <param name="rotate">旋转角度</param>
        /// <param name="bold">是否加粗</param>
        /// <param name="reverse">是否颠倒</param>
        /// <param name="underline">是否下划线</param>
        public ZicoxPrintClient DrawText(int startX, int startY, string text, int fontSize, int fontZoom, int rotate,
                                         bool bold, bool reverse, bool underline)
        {
            var item = new DrawTextItem
            {
                X         = startX,
                Y         = startY,
                Text      = text,
                FontSize  = fontSize,
                FontZoom  = fontZoom,
                Rotate    = rotate,
                Bold      = bold,
                Reverse   = reverse,
                Underline = underline
            };

            this.TextList.Add(item);
            return(this);
        }
        /// <summary>
        /// 画文本
        /// </summary>
        /// <param name="pageWidth">页宽度</param>
        /// <param name="pageHeight">页高度</param>
        /// <param name="item">画文字明细</param>
        public void DrawText(int pageWidth, int pageHeight, DrawTextItem item)
        {
            // 写入下划线
            Writer.WriteLine(item.Underline ? "UNDERLINE ON" : "UNDERLINE OFF");
            // 写入加粗
            Writer.WriteLine(item.Bold ? "SETBOLD 1" : "SETBOLD 0");
            var computeFontSizeResult = Helper.ComputeFontSize(item.FontSize);

            // 设置字体缩放
            Writer.WriteLine($"SETMAG {computeFontSizeResult.scale} {computeFontSizeResult.scale} ");
            // 写入文本
            var cmd = Helper.GetTextRotateCommand(item.Rotate);

            Writer.WriteLine(
                $"{cmd} {computeFontSizeResult.font} {computeFontSizeResult.size} {item.X} {item.Y} {item.Text}");
            // 写入颠倒文本
            if (item.Reverse)
            {
                Inverse(item.X, item.Y, item.X + computeFontSizeResult.size / 2 * item.Text.Length, item.Y,
                        computeFontSizeResult.size);
            }
            Writer.WriteLine("SETMAG 1 1");
        }