示例#1
0
        /// <summary>
        /// (not currently used)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdGenSubRange_Click(object sender, EventArgs e)
        {
            useCartesian = false;
            //TODO - get dot here
            int cellIdx = 0;
            //int.TryParse((int)nudPageNumberBG.Value, out cellIdx);
            //Dot baseDot = new Dot() { Height = 3, Width = 3, tolerance = .2f, xStepDown = };
            Dot baseDot = Cartesian.ElementAt(cellIdx);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            PrintDocument pd = new PrintDocument();

            pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

            pd.PrinterSettings.DefaultPageSettings.PrinterResolution.X = 600;
            pd.PrinterSettings.DefaultPageSettings.PrinterResolution.Y = 600;
            pd.PrinterSettings.PrinterName = PrinterName;

            SubCartesian = (from xd1 in Constants.OverDownSub
                            from xo1 in Constants.OverDownSub
                            from yd1 in Constants.OverDownSub
                            from yo1 in Constants.OverDownSub
                            select new Dot()
            {
                Height = baseDot.Height,
                Width = baseDot.Width,
                tolerance = baseDot.tolerance,
                xStepDown = xd1 + baseDot.xStepDown,
                xStepOver = xo1 + baseDot.xStepOver,
                yStepDown = yd1 + baseDot.yStepDown,
                yStepOver = yo1 + baseDot.yStepOver,
                DrawThick = (xd1 == 0 && xo1 == 0 && yd1 == 0 && yo1 == 0)
            }).ToList();

            //Parallel.ForEach(Cartesian, x => x.RenderAndFill());
            foreach (Dot d in SubCartesian)
            {
                d.RenderAndFill();
            }

            var bytes = SubCartesian.Select(x => x.GetBytesAsString(true));

            SubCartesian.ElementAt(0).GetBytesAsString(true);
            float low  = MinDensity(Density) / 100f;
            float high = MaxDensity(Density) / 100f;

            //Do not filter
            //subCartesian = subCartesian.Where(x => low <= x.RFgridDensity && x.RFgridDensity <= high).ToList().GetRange(pages * Constants.CellsPerPage, Constants.CellsPerPage);

            Debug.Print(string.Format("Sub Count: {0}, Columns: {1}, Rows: {2}", SubCartesian.Count(), Constants.NumColumns, Constants.NumRows));

            pd.Print();
            pd.Dispose();

            sw.Stop();
            Debug.Print(string.Format("Sub Print took {0} sec.", sw.Elapsed.TotalSeconds));

            //pages++;
        }
示例#2
0
        /// <summary>
        /// Render the list of cells to a page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            g.PageUnit = GraphicsUnit.Pixel;

            List <int> lc = Enumerable.Range(0, Constants.NumColumns).ToList();
            List <int> lr = Enumerable.Range(0, Constants.NumRows).ToList();

            Brush stripeBrush = null;

            if (CurrentFG == null)
            {
                CurrentFG = Cartesian.First();
            }

            //Dot fg = GetDot(txtPageNumberFG.Text, txtCellFG.Text, "FG");
            //if (fg == null)
            //{
            //    stripeBrush = new SolidBrush(Color.Gray);
            //}
            //else
            //{
            int ms = CurrentFG.MinSize();

            bool[,] fgGrid = new bool[ms, ms];
            CurrentFG.RenderToGrid(fgGrid);
            Bitmap fgb = ConvertToBMP(fgGrid, false);

            stripeBrush = new TextureBrush(fgb);
            //}

            var results = lr./*AsParallel().*/ Select(
                r => lc./*AsParallel().*/ Select(
                    c => (r * Constants.NumColumns + c >= (useCartesian ? Cartesian.Count() : SubCartesian.Count()) ?
                          new Bitmap(Constants.cellW, Constants.cellH) :
                          DrawCell((useCartesian ? Cartesian.ElementAt(r * Constants.NumColumns + c) :
                                    SubCartesian.ElementAt(r * Constants.NumColumns + c)), stripeBrush, r * Constants.NumColumns + c))).ToList()).ToList();

            var results2 = results./*AsParallel().*/ Select(x => StitchBMPsHoriz(x)).ToList();

            //var results3 = StitchBMPsVert(results2);
            int row = Constants.shiftY;
            int pg  = 0;

            foreach (Bitmap b in results2)
            {
                b.SetResolution(Constants.DPI, Constants.DPI);
                g.DrawImage(b, new Rectangle(Constants.shiftX, row, b.Width, b.Height),
                            new Rectangle(0, 0, b.Width, b.Height), GraphicsUnit.Pixel);
                //g.DrawImageUnscaled(b, 0, row);
                row += b.Height;
                //if (row == 2)
                //    break;
                //WriteOutBMP("out" + pg.ToString(), b);
                pg++;
            }

            //int yy = Constants.shiftY;
            //int rowNum = 1;
            Font       f  = new Font("Arial", 10f, FontStyle.Regular);
            SolidBrush br = new SolidBrush(Color.Black);

            for (int y = 0; y < Constants.NumRows; y++)
            {
                g.DrawString((y + 1).ToString(), f, br, new PointF(0, y * Constants.cellH + Constants.shiftY));
            }

            //int xx = Constants.shiftX;
            char colNum = 'A';

            for (int x = 0; x < Constants.NumColumns; x++)
            {
                g.DrawString(colNum.ToString(), f, br, new PointF(x * Constants.cellW + Constants.shiftX, 0));
                colNum++;
            }
            //while (xx < Constants.PageW)
            //{
            //    g.DrawString(colNum.ToString(), f, br, new PointF(xx, 0));
            //    xx += Constants.cellW;
            //    colNum++;
            //}

            g.DrawString(string.Format("Page {0}, Darkness {1}", Page + 1, Density), f, br, new PointF(50, Constants.PageH - 50));
            e.HasMorePages = false;
        }
示例#3
0
        private void ProcessPrintFullPanto(Step step)
        {
            if (step != Step.Next && step != Step.Back)  //invalid
            {
                return;
            }

            if (step == Step.Back)
            {
                state = P2WizardState.FailReason;
                return;
            }
#if !Print
            state = P2WizardState.IsValidPanto;
            return;
#endif

            Dot bg = GetDot((int)nudPageNumberBG.Value, (int)nudDarknessBG.Value, txtCellBG.Text, "BG");
            if (bg == null)
            {
                MessageBox.Show("You have entered an invalid page number or cell index.  Please correct and try again");
                return;
            }
            if (CurrentFG == null)
            {
                CurrentFG = Cartesian.First();
            }
            byte[] data   = bg.GetBytes(true);
            byte[] dataFg = CurrentFG.GetBytes(true);

            //MessageBox.Show("TODO - Print pantograph based on entered cell");

            CustomConfiguration cc = new CustomConfiguration();

            //Using interference pattern?
            if (!string.IsNullOrEmpty(IntfFontPath))
            {
                //Set the interference enabled bit and chessboard bit
                cc.PantographConfiguration = "257";
            }
            else
            {
                //Set only the chessboard bit
                cc.PantographConfiguration = "1";
                IntfFontPath = Application.StartupPath;  //TBD Temporary until I fix the panto builder.  Does not like a blank string.
            }
            cc.PageOrientation = PageOrientationType.poPortrait;
            cc.PageType        = PageType.ptLetter;
            cc.UseDefaultInclusionForPaperSize = true;
            cc.InterferencePatternId           = 20;
            cc.CellList.Clear();

            //Create a cell with the text COPY and id = 10
            PantographCellDescriptorType pcdt = new PantographCellDescriptorType();
            pcdt.msg  = "COPY";
            pcdt.pidx = 10;
            cc.CellList.Add(pcdt);

            //Set the custom pattern
            cc.CustomBackgroundPatternData = data;
            //TBD use real foreground
            cc.CustomForegroundPatternData = dataFg;

            //Create the full page pantograph
            string filename = "PantographProfile1Page1.pcl";

            var    xser      = new XmlSerializer(typeof(CustomConfiguration));
            string cfilename = IntfFontPath + "TroyPantographConfiguration.xml";
            var    writer    = new StreamWriter(cfilename);
            xser.Serialize(writer, cc);

            var bp = new BuildPantographWrap.Wrapper();
            int rc = bp.ManagedCreatePantograph(IntfFontPath);

            //Print the pantograph file
            PrinterLib.PrintToSpooler.SendFileToPrinter(PrinterName, filename, "Test");

            //TBD Temporary kluge to make the other temporary kluge work properly
            if (cc.PantographConfiguration == "1")
            {
                IntfFontPath = "";
            }

            state = P2WizardState.IsValidPanto;
        }