Example #1
0
        private void AddPage2(PageItem it)
        {
            if (InvokeRequired)
            {
                Invoke((AddPage2Delegate)this.AddPage2, it); return;
            }

            Panel p = new Panel();

            p.Size       = sizeThumb;
            p.Parent     = flp;
            p.MouseDown += new MouseEventHandler(p_MouseDown);
            p.Paint     += new PaintEventHandler(p_Paint);
            p.Tag        = it;
        }
Example #2
0
        private void PicForm_Paint(object sender, PaintEventArgs e)
        {
            if (imageRender == null)
            {
                return;
            }

            Rectangle rcPage = pictureBox1.Bounds;

            rcPage.Inflate(-5, -5);
            int       cw       = Math.Max(imageRender.Width, imageRender.Height);
            Rectangle rcBox    = jtifedit.Fitrect.FitScaled(rcPage, new Size(cw, cw));
            Rectangle rcTarget = jtifedit.Fitrect.FitScaled(rcBox, imageRender.Size);

            e.Graphics.DrawImage(imageRender, rcTarget);

            if (pageIndex < 0)
            {
                return;
            }

            PageItem pageItem = pageItems[pageIndex];
            Graphics cv       = e.Graphics;

            if (pageItem.isDeleted)
            {
                //cv.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                Rectangle rcX      = rcPage;
                int       minWidth = Math.Min(rcX.Width, rcX.Height);
                rcX.X     = (rcX.Width - minWidth) / 2;
                rcX.Y     = (rcX.Height - minWidth) / 2;
                rcX.Width = rcX.Height = minWidth;
                cv.DrawLine(redPen, rcX.X, rcX.Y, rcX.Right, rcX.Bottom);
                cv.DrawLine(redPen, rcX.Right, rcX.Y, rcX.X, rcX.Bottom);
            }
            if (pageItem.isSep)
            {
                cv.FillRectangle(Brushes.Blue, Rectangle.FromLTRB(rcPage.X, rcPage.Y, rcPage.X + 3, rcPage.Bottom));
            }
        }
Example #3
0
        void p_MouseDown(object sender, MouseEventArgs e)
        {
            Panel    p        = (Panel)sender;
            PageItem pageItem = (PageItem)p.Tag;

            if (0 != (e.Button & MouseButtons.Left))
            {
                if (0 != (Form.ModifierKeys & Keys.Shift))
                {
                    using (PicForm form = new PicForm()) {
                        form.pageItems = pageItems;
                        form.pageIndex = pageItems.IndexOf(pageItem);
                        form.ShowDialog();
                        Invalidate(true);
                    }
                }
                else
                {
                    if (0 != (Form.ModifierKeys & Keys.Alt))
                    {
                        p.Dispose();
                        RePageNum();
                    }
                    else
                    {
                        pageItem.isDeleted = !pageItem.isDeleted;
                    }
                    p.Invalidate();
                }
            }
            if (0 != (e.Button & MouseButtons.Right))
            {
                pageItem.isSep = !pageItem.isSep;
                p.Invalidate();
            }
        }
Example #4
0
        void p_Paint(object sender, PaintEventArgs e)
        {
            Panel    p        = (Panel)sender;
            PageItem pageItem = (PageItem)p.Tag;

            {
                Graphics  cv    = e.Graphics;
                Rectangle rcPic = new Rectangle(Point.Empty, p.Size);
                rcPic.Inflate(-10, -10);
                Rectangle rcTarget = Fitrect.Fit(rcPic, pageItem.picThumb.Size);
                cv.DrawImage(pageItem.picThumb, rcTarget);
                if (pageItem.isDeleted)
                {
                    //cv.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    cv.DrawLine(redPen, 0, 0, p.Width, p.Height);
                    cv.DrawLine(redPen, 0, p.Height, p.Width, 0);
                }
                if (pageItem.isSep)
                {
                    cv.FillRectangle(Brushes.Blue, Rectangle.FromLTRB(0, 0, 3, p.Height));
                }
                cv.DrawString(String.Format("{0}", pageItem.index + 1), Font, SystemBrushes.WindowText, new Rectangle(Point.Empty, p.Size), sfBC);
            }
        }
Example #5
0
        bool SaveThem()
        {
            List <PageItem> pageItems = this.pageItems;

            List <int[]> pageRefsArray = new List <int[]>();

            {
                List <int> pageRefs = new List <int>();
                for (int x = 0, cx = pageItems.Count; x < cx; x++)
                {
                    PageItem pageItem = pageItems[x];
                    if (pageRefs.Count != 0 && (pageItem.isSep))
                    {
                        pageRefsArray.Add(pageRefs.ToArray());
                        pageRefs.Clear();
                    }
                    if (!pageItem.isDeleted)
                    {
                        pageRefs.Add(x);
                    }
                    if (pageRefs.Count != 0 && (x == cx - 1))
                    {
                        pageRefsArray.Add(pageRefs.ToArray());
                        pageRefs.Clear();
                    }
                }
            }

            if (pageRefsArray.Count == 0)
            {
                MessageBox.Show(this, "出力するものはありません。", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            if (saveDir == null)
            {
                if (fbdSave.ShowDialog(this) != DialogResult.OK)
                {
                    return(false);
                }
                saveDir = fbdSave.SelectedPath;
            }

            bool anyPDF = false;

            foreach (int[] pageRefs in pageRefsArray)
            {
                foreach (int pageRef in pageRefs)
                {
                    anyPDF |= pageItems[pageRef].provider.IsPDF;
                }
            }

            if (anyPDF)
            {
                using (ConvDpiForm form = new ConvDpiForm()) {
                    if (form.ShowDialog() != DialogResult.OK)
                    {
                        return(false);
                    }
                }
            }

            int    nTotal = 0, nSuccess = 0;
            String errs = "";

            using (AH2 ah2 = new AH2())
                using (WaitNow wip = new WaitNow()) {
                    wip.Cover(this);

                    int fileNum = 1;
                    for (int t = 0; t < pageRefsArray.Count; t++)
                    {
                        int[] pageRefs = pageRefsArray[t];
                        for (int c = 0; c < 10000; c++, fileNum++)
                        {
                            String fpsave = Path.Combine(saveDir, String.Format("分割#{0:0000}.tif", fileNum));
                            if (File.Exists(fpsave))
                            {
                                continue;
                            }

                            for (int x = 0; x < pageRefs.Length; x++)
                            {
                                PageItem pageItem  = pageItems[pageRefs[x]];
                                String   fpTempTIF = tempFiles.NewFile(".tif");
                                nTotal++;
                                if (pageItem.provider.SaveTIF(fpTempTIF, Settings.Default.ConvDpi))
                                {
                                    if (Settings.Default.Mono && !pageItem.provider.IsMono)
                                    {
                                        FIBITMAP dib = FreeImage.LoadEx(fpTempTIF);
                                        try {
                                            FIBITMAP dib2 = FreeImage.Threshold(dib, 128);
                                            try {
                                                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, dib2, fpTempTIF, FREE_IMAGE_SAVE_FLAGS.TIFF_CCITTFAX4);
                                            }
                                            finally {
                                                FreeImage.UnloadEx(ref dib2);
                                            }
                                        }
                                        finally {
                                            FreeImage.UnloadEx(ref dib);
                                        }
                                    }
                                    if (Tiffcp.Run(fpsave, fpTempTIF, Settings.Default.Mono, x != 0))
                                    {
                                        nSuccess++;
                                    }
                                    else
                                    {
                                        errs += String.Format("{0:#,##0} ページ目の保存に失敗\n", 1 + pageItem.index);
                                    }
                                }
                                else
                                {
                                    errs += String.Format("{0:#,##0} ページ目の保存に失敗\n", 1 + pageItem.index);
                                }
                            }
                            break;
                        }
                    }
                }

            MessageBox.Show(this, (nTotal == nSuccess) ? "保存しました。" : "部分的に保存が成功しました。\n\n---\n" + errs, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            return(true);
        }
Example #6
0
        private void AddPage2(PageItem it)
        {
            if (InvokeRequired) { Invoke((AddPage2Delegate)this.AddPage2, it); return; }

            Panel p = new Panel();
            p.Size = sizeThumb;
            p.Parent = flp;
            p.MouseDown += new MouseEventHandler(p_MouseDown);
            p.Paint += new PaintEventHandler(p_Paint);
            p.Tag = it;
        }
Example #7
0
 private void AddPage(PicProvider prov)
 {
     PageItem it = new PageItem();
     it.picThumb = prov.Thumb;
     it.provider = prov;
     it.index = flp.Controls.Count;
     AddPage2(it);
 }