Exemplo n.º 1
0
 public PageFormat(string name, double width, double height, UoM units, bool isPortrait)
 {
     this.name       = name;
     this.width      = width;
     this.height     = height;
     this.units      = units;
     this.isPortrait = isPortrait;
 }
Exemplo n.º 2
0
        // ####### COMBOBOX INDEX CHANGED EVENTS #######

        /// <summary>
        /// On index change, updates the selected UoM variable,
        /// and changes the unit labels on the form to match
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBoxSizeUnits_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedUnit = (UoM)comboBoxUoM.SelectedItem;

            foreach (Label l in unitLabelsList)
            {
                l.Text = selectedUnit.ToString();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates UoM objects and adds them to the appropriate form control
        /// </summary>
        private void populateUnits()
        {
            cm   = new UoM("cm", 28.3465);
            inch = new UoM("in", 72);

            unitsList.Add(cm);
            unitsList.Add(inch);

            foreach (UoM u in unitsList)
            {
                comboBoxUoM.Items.Add(u);
            }
        }
Exemplo n.º 4
0
        private Size CalculatePageImageSize()
        {
            try
            {
                // check and convert page format units to selected units
                double selectedFormatWidth  = selectedFormat.Width();
                double selectedFormatHeight = selectedFormat.Height();

                if (selectedFormat.Units() != selectedUnit)
                {
                    if (selectedUnit == cm)
                    {
                        selectedFormatWidth  = UoM.ConvertInchToCM(selectedFormatWidth);
                        selectedFormatHeight = UoM.ConvertInchToCM(selectedFormatHeight);
                    }
                    else
                    {
                        selectedFormatWidth  = UoM.ConvertCMtoInch(selectedFormatWidth);
                        selectedFormatHeight = UoM.ConvertCMtoInch(selectedFormatHeight);
                    }
                }

                // account for margin
                double imageWidth  = selectedFormatWidth - marginSides * 2;
                double imageHeight = selectedFormatHeight - marginTop * 2;

                // calculate pixel dimensions
                int width  = selectedUnit.ToPixels(imageWidth);
                int height = selectedUnit.ToPixels(imageHeight);

                Size size = new Size(width, height);

                return(size);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                return(new Size(0, 0));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets the input variables to their default values
        /// and updates the form fields with the corresponding values
        /// </summary>
        private void SetInputDefaults()
        {
            // set variables
            selectedUnit   = cm;
            selectedFormat = A4_port;
            sizeWidth      = DEFAULT_SIZE;
            sizeHeight     = DEFAULT_SIZE;
            marginTop      = DEFAULT_MARGIN;
            overlapTop     = DEFAULT_OVERLAP;

            // set form fields
            comboBoxUoM.SelectedItem        = cm;
            comboBoxPageFormat.SelectedItem = A4_port;

            textBoxSizeWidth.Text  = sizeWidth.ToString("F2");
            textBoxSizeHeight.Text = sizeHeight.ToString("F2");
            textBoxMarginTop.Text  = marginTop.ToString("F2");
            textBoxOverlapTop.Text = overlapTop.ToString("F2");

            checkBoxMaintainSizeRatio.Checked = true;
            checkBoxMarginAllSides.Checked    = true;
            checkBoxOverlapAllSides.Checked   = true;
        }
Exemplo n.º 6
0
        private void GeneratePageImages(Size imageSize, double xScale, double yScale)
        {
            // clear old lists
            imageListPages.Images.Clear();
            pagesList.Clear();
            listViewPrintPreview.Clear();

            foreach (Image p in generatedPagesList)
            {
                p.Dispose();
            }

            generatedPagesList.Clear();

            // get size for cutting before resizing to page size
            Size cutImageSize = new Size((int)(imageSize.Width / xScale), (int)(imageSize.Height / xScale));

            Console.WriteLine("Calculated cut size from preview image: " + cutImageSize);

            // get overlap values in pixels to scale
            int pixelOverlapTop   = (int)(selectedUnit.ToPixels(overlapTop) / yScale);
            int pixelOverlapSides = (int)(selectedUnit.ToPixels(overlapSides) / xScale);

            // get margin values
            int pixelMarginTop   = selectedUnit.ToPixels(marginTop);
            int pixelMarginSides = selectedUnit.ToPixels(marginSides);

            // check and convert page format units to selected units
            double selectedFormatWidth  = selectedFormat.Width();
            double selectedFormatHeight = selectedFormat.Height();

            if (selectedFormat.Units() != selectedUnit)
            {
                if (selectedUnit == cm)
                {
                    selectedFormatWidth  = UoM.ConvertInchToCM(selectedFormatWidth);
                    selectedFormatHeight = UoM.ConvertInchToCM(selectedFormatHeight);
                }
                else
                {
                    selectedFormatWidth  = UoM.ConvertCMtoInch(selectedFormatWidth);
                    selectedFormatHeight = UoM.ConvertCMtoInch(selectedFormatHeight);
                }
            }

            // get graphics of edit image
            Graphics editGraphics = Graphics.FromImage(editImage);

            // create rectangle for cutting and drawing
            Rectangle cutRectangle = new Rectangle(0, 0, cutImageSize.Width, cutImageSize.Height);

            // create pen for drawing on preview
            Pen pen = new Pen(Color.Red, 2);

            // for entire height of image
            for (int y = 0; y < editImage.Height; y += (cutImageSize.Height - pixelOverlapTop))
            {
                // for each width of image
                for (int x = 0; x < editImage.Width; x += (cutImageSize.Width - pixelOverlapSides))
                {
                    cutRectangle.X = x;

                    cutRectangle.Y = y;

                    editGraphics.DrawRectangle(pen, cutRectangle);

                    // get cut out
                    Image cutout = new Bitmap(cutImageSize.Width, cutImageSize.Height);
                    using (Graphics g = Graphics.FromImage(cutout))
                    {
                        g.DrawImage(editImage, 0, 0, cutRectangle, GraphicsUnit.Pixel);

                        g.Dispose();
                    }

                    // resize cut out
                    Image newCutout = ResizeImage(cutout, imageSize.Width, imageSize.Height);

                    // create full page image
                    Image fullPageImage = new Bitmap(selectedUnit.ToPixels(selectedFormatWidth), selectedUnit.ToPixels(selectedFormatHeight));

                    using (Graphics g = Graphics.FromImage(fullPageImage))
                    {
                        // make page white
                        g.FillRectangle(Brushes.White, 0, 0, fullPageImage.Width, fullPageImage.Height);

                        // draw cutout onto page
                        g.DrawImage(newCutout, pixelMarginSides, pixelMarginTop);

                        g.Dispose();
                    }

                    generatedPagesList.Add(fullPageImage);


                    // create thumbnail of image
                    Bitmap thumb = GenerateThumbnail(fullPageImage);
                    this.imageListPages.Images.Add(thumb);

                    cutout.Dispose();
                    newCutout.Dispose();
                    // fullPageImage.Dispose();
                }
            }

            this.listViewPrintPreview.LargeImageList = this.imageListPages;

            for (int j = 0; j < this.imageListPages.Images.Count; j++)
            {
                ListViewItem item = new ListViewItem();
                item.ImageIndex = j;
                this.listViewPrintPreview.Items.Add(item);
            }

            editGraphics.Dispose();
        }