Ejemplo n.º 1
0
        private static string GetFaceCountText(PrintFace face)
        {
            string result = "Page No. " + face.FaceNumber;

            if (face.BatchPaperNumber > -1)
            {
                result += ", Batch Paper: " + (face.BatchPaperNumber + 1);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public Bitmap BuildFace(PrintFace face, int spW, int spH, int padding, bool colors, bool parentText)
        {
            Bitmap result = null;

            if (face.Left == face.Right) // double
            {
                if (
                    face.Right.SideType != SingleSideType.MANGA &&
                    face.Right.SideType != SingleSideType.ANTI_SPOILER
                    )
                {
                    throw new Exception(
                              string.Format("Got type {0} in double in duplex. It's unexpected.", face.Right.SideType)
                              );
                }

                result = TemplateDouble(face, spW, spH, padding);
            }
            else
            {
                if (face.Right.SideType == SingleSideType.ANTI_SPOILER)
                {
                    throw new Exception(
                              string.Format("Got type {0} in right single in duplex. It's unexpected.", face.Right.SideType)
                              );
                }
                if (face.Right.SideType == SingleSideType.ANTI_SPOILER)
                {
                    throw new Exception(
                              string.Format("Got type {0} in left single in duplex. It's unexpected.", face.Left.SideType)
                              );
                }

                result = TemplateSingle(face, spW, spH, padding, parentText);
            }

            if (result != null && !colors)
            {
                result = GraphicsUtils.MakeGrayscale3(result);
            }
            // TODO: dispose bitmaps?
            return(result);
        }
Ejemplo n.º 3
0
        private static void HandleFace(ref bool isFirst, List <PrintFace> Faces, MangaChapter ch, MangaPage p, SingleSideType sideType = SingleSideType.MANGA)
        {
            if (isFirst && !p.IsDouble)
            {
                PrintFace face = new PrintFace()
                {
                    PrintFaceType = FaceType.SINGLES, IsRTL = ch.IsRTL
                };
                Faces.Add(face);

                PrintSide side = null;
                if (sideType == SingleSideType.MANGA)
                {
                    side = new PrintSide()
                    {
                        SideType            = SingleSideType.MANGA,
                        MangaPageSource     = p,
                        MangaPageSourceType = SideMangaPageType.ALL
                    };
                }
                else
                {
                    side = new PrintSide()
                    {
                        MangaPageSource = p,
                        SideType        = sideType,
                    };
                }

                if (ch.IsRTL)
                {
                    face.Right = side;
                }
                else
                {
                    face.Left = side;
                }

                isFirst = false;
            }
            else if (isFirst && p.IsDouble)
            {
                PrintFace face = new PrintFace()
                {
                    PrintFaceType = FaceType.DOUBLE, IsRTL = ch.IsRTL
                };
                Faces.Add(face);

                PrintSide side = new PrintSide()
                {
                    SideType            = SingleSideType.MANGA,
                    MangaPageSource     = p,
                    MangaPageSourceType = SideMangaPageType.ALL // only in booklet we need to know right\left
                };

                face.Left = face.Right = side;

                isFirst = true;
            }
            else if (!isFirst && !p.IsDouble)
            {
                PrintFace face = Faces.Last();

                PrintSide side = null;
                if (sideType == SingleSideType.MANGA)
                {
                    side = new PrintSide()
                    {
                        SideType            = SingleSideType.MANGA,
                        MangaPageSource     = p,
                        MangaPageSourceType = SideMangaPageType.ALL
                    };
                }
                else
                {
                    side = new PrintSide()
                    {
                        SideType        = sideType,
                        MangaPageSource = p,
                    };
                }

                if (ch.IsRTL)
                {
                    face.Left = side;
                }
                else
                {
                    face.Right = side;
                }

                isFirst = true;
            }
            else if (!isFirst && p.IsDouble)
            {
                // Add FILLER
                PrintFace face = Faces.Last();

                PrintSide side = new PrintSide()
                {
                    SideType = SingleSideType.BEFORE_DOUBLE,
                };

                if (ch.IsRTL)
                {
                    face.Left = side;
                }
                else
                {
                    face.Right = side;
                }

                // Add Double
                face = new PrintFace()
                {
                    PrintFaceType = FaceType.DOUBLE, IsRTL = ch.IsRTL
                };
                Faces.Add(face);

                side = new PrintSide()
                {
                    SideType            = SingleSideType.MANGA,
                    MangaPageSource     = p,
                    MangaPageSourceType = SideMangaPageType.ALL // only in booklet we need to know right\left
                };

                face.Left = face.Right = side;
                isFirst   = true;
            }
        }
Ejemplo n.º 4
0
        public List <PrintPage> Build(List <MangaChapter> chapters, bool addStartPage, bool addEndPage, int addAntiSpoiler = 0, bool parentFolder = true)
        {
            // For loop from 1 to end and add pages as necessary.
            // Double Template should have 0px between 2 pages.

            List <PrintPage> pc = new List <PrintPage>();


            bool             isFirst = true; // Starting page
            List <PrintFace> Faces   = new List <PrintFace>();

            foreach (MangaChapter ch in chapters)
            {
                MangaPage SinglePageNULL = new MangaPage()
                {
                    IsDouble = false, Chapter = ch
                };

                if (addStartPage)
                {
                    HandleFace(ref isFirst, Faces, ch, SinglePageNULL, SingleSideType.INTRO);
                }

                foreach (MangaPage p in ch.Pages)
                {
                    HandleFace(ref isFirst, Faces, ch, p);
                }

                if (addEndPage)
                {
                    HandleFace(ref isFirst, Faces, ch, SinglePageNULL, SingleSideType.OUTRO);
                }

                if (isFirst)
                {
                    // ignore empty side
                }
                else
                {
                    PrintFace face = Faces.Last();

                    PrintSide side = new PrintSide()
                    {
                        SideType = SingleSideType.MAKE_EVEN,
                    };

                    if (ch.IsRTL)
                    {
                        face.Left = side;
                    }
                    else
                    {
                        face.Right = side;
                    }

                    isFirst = true;
                }
            }

            // ----------- Anti Spoiler
            if (addAntiSpoiler > 1)
            {
                int faceIndex = 0;
                while (faceIndex < Faces.Count)
                {
                    PrintSide s = new PrintSide()
                    {
                        SideType = SingleSideType.ANTI_SPOILER
                    };
                    PrintFace f = new PrintFace()
                    {
                        PrintFaceType = FaceType.DOUBLE, IsRTL = true
                    };                                                                               // RTL not important
                    f.Left = f.Right = s;
                    Faces.Insert(faceIndex, f);
                    if (faceIndex == 0)
                    {
                        if (Faces.Count > 1)
                        {
                            f.IsRTL = Faces[1].IsRTL;
                        }
                    }
                    else
                    {
                        f.IsRTL = Faces[faceIndex - 1].IsRTL;
                    }
                    faceIndex += addAntiSpoiler * 2;
                }

                if (Faces.Count > 1)
                {
                    // Add spoiler to the last page:
                    PrintSide _s = new PrintSide()
                    {
                        SideType = SingleSideType.ANTI_SPOILER
                    };
                    PrintFace _f = new PrintFace()
                    {
                        PrintFaceType = FaceType.DOUBLE, IsRTL = true
                    };                                                                                // RTL not important
                    _f.Left = _f.Right = _s;
                    Faces.Add(_f);
                    _f.IsRTL = Faces[Faces.Count - 1 - 1].IsRTL;
                }
            }

            if (Faces.Count % 2 == 1)
            {
                // Add a face for even faces to occupy entire double-sided pages.
                PrintFace face = new PrintFace()
                {
                    PrintFaceType = FaceType.SINGLES, IsRTL = true
                };
                Faces.Add(face);

                // but add as 2 singels because there is no template for double make_even
                PrintSide sideLeft = new PrintSide()
                {
                    SideType = SingleSideType.MAKE_EVEN
                };

                PrintSide sideRight = new PrintSide()
                {
                    SideType = SingleSideType.MAKE_EVEN
                };

                face.Left  = sideLeft;
                face.Right = sideRight;
            }

            int pageIndex   = 1;
            int sideCounter = 1;

            for (int i = 0; i < Faces.Count; i += 2)
            {
                for (int j = 0; j < 2; j++)
                {
                    Faces[i + j].BatchPaperNumber = (addAntiSpoiler > 0) ? ((i / 2) % addAntiSpoiler) : -1;

                    if (Faces[i + j].Right == Faces[i + j].Left)//double
                    {
                        Faces[i + j].Right.SideNumber = sideCounter++;
                        sideCounter++; // count another for double
                    }
                    else
                    {
                        if (Faces[i + j].IsRTL)
                        {
                            Faces[i + j].Right.SideNumber = sideCounter++;
                            Faces[i + j].Left.SideNumber  = sideCounter++;
                        }
                        else
                        {
                            Faces[i + j].Left.SideNumber  = sideCounter++;
                            Faces[i + j].Right.SideNumber = sideCounter++;
                        }
                    }
                }
                PrintPage pp = new PrintPage()
                {
                    PageNumber = pageIndex++,
                    Front      = Faces[i],
                    Back       = Faces[i + 1]
                };
                pp.Front.FaceNumber = (i) + 1; // not stating from zero
                pp.Back.FaceNumber  = (i + 1) + 1;
                pc.Add(pp);
            }

            return(pc);
        }
Ejemplo n.º 5
0
        private Bitmap TemplateDouble(PrintFace face, int spW, int spH, int padding)
        {
            int tmpW = spW * 2 + padding * 2;
            int tmpH = spH + padding * 2;

            int contentW = tmpW - padding * 2;
            int contentH = tmpH - padding * 2;

            int sideTextW = contentW / 2;
            int sideTextH = padding;

            int arrowW = contentW;
            int arrowH = padding;

            bool isRTL = face.IsRTL;

            Bitmap b = new Bitmap(tmpW, tmpH);

            using (Graphics g = Graphics.FromImage(b))
            {
                int    sideIndex = face.Right.SideNumber;
                string sideLeftText, sideRightText;
                string FaceCountText = GetFaceCountText(face);

                if (isRTL)
                {
                    sideRightText = "[ " + sideIndex + " ]";
                    sideLeftText  = "[ " + (sideIndex + 1) + " ]";

                    GraphicsUtils.DrawArrowHeadRow(g, blackPen,
                                                   new Point(tmpW - padding, padding / 2),
                                                   new Point(padding, padding / 2),
                                                   padding);
                }
                else
                {
                    sideLeftText  = "[ " + sideIndex + " ]";
                    sideRightText = "[ " + (sideIndex + 1) + " ]";

                    GraphicsUtils.DrawArrowHeadRow(g, blackPen,
                                                   new Point(padding, padding / 2),
                                                   new Point(tmpW - padding, padding / 2),
                                                   padding);
                }

                GraphicsUtils.FontScaled sideLeftFS  = GraphicsUtils.FindFontSizeByContent(g, sideLeftText, new Size(sideTextW, sideTextH), fontSide);
                GraphicsUtils.FontScaled sideRightFS = GraphicsUtils.FindFontSizeByContent(g, sideRightText, new Size(sideTextW, sideTextH), fontSide);
                GraphicsUtils.FontScaled faceCountFS = GraphicsUtils.FindFontSizeByContent(g, FaceCountText, new Size(sideTextW, sideTextH), fontSide);

                GraphicsUtils.DrawTextCenterd(g, sideLeftText, sideLeftFS, blackBrush,
                                              new PointF(padding + contentW / 4, padding + contentH + padding / 2)
                                              );
                GraphicsUtils.DrawTextCenterd(g, sideRightText, sideRightFS, blackBrush,
                                              new PointF(tmpW - padding - contentW / 4, padding + contentH + padding / 2)
                                              );
                GraphicsUtils.DrawTextCenterd(g, FaceCountText, faceCountFS, blackBrush,
                                              new PointF(tmpW / 2, padding + contentH + padding / 2)
                                              );

                Bitmap page = null;
                switch (face.Left.SideType)
                {
                case SingleSideType.ANTI_SPOILER:
                    page = GraphicsUtils.createImageWithText(sideTextConsts(SingleSideType.ANTI_SPOILER),
                                                             contentH, contentW);
                    break;

                case SingleSideType.MANGA:
                    page = GraphicsUtils.loadFileZoomedCentered(face.Left.MangaPageSource.ImagePath,
                                                                contentH, contentW);
                    break;
                }
                g.DrawImage(page, new Point(padding, padding));
                page.Dispose();

                // border
                //g.DrawRectangle(blackPen, new Rectangle(padding, padding, contentW, contentH));
            }

            return(b);
        }
Ejemplo n.º 6
0
        private Bitmap TemplateSingle(PrintFace face, int spW, int spH, int padding, bool parentText)
        {
            int tmpW = spW * 2 + padding * 3;
            int tmpH = spH + padding * 2;

            int arrowW = tmpW - padding * 2;
            int arrowH = padding;

            int pageW = (tmpW - padding * 3) / 2; // one padding between pages
            int pageH = tmpH - padding * 2;

            int sideTextW = pageW;
            int sideTextH = padding;

            bool isRTL = face.IsRTL;

            Bitmap b = new Bitmap(tmpW, tmpH);

            using (Graphics g = Graphics.FromImage(b))
            {
                string sideLeft  = "[ " + face.Left.SideNumber + " ]";
                string sideRight = "[ " + face.Right.SideNumber + " ]";
                string FaceIndex = GetFaceCountText(face);

                GraphicsUtils.FontScaled sideLeftFont  = GraphicsUtils.FindFontSizeByContent(g, sideLeft, new Size(sideTextW, sideTextH), fontSide);
                GraphicsUtils.FontScaled sideRightFont = GraphicsUtils.FindFontSizeByContent(g, sideRight, new Size(sideTextW, sideTextH), fontSide);
                GraphicsUtils.FontScaled faceFont      = GraphicsUtils.FindFontSizeByContent(g, FaceIndex, new Size(sideTextW, sideTextH), fontSide);

                if (isRTL)
                {
                    GraphicsUtils.DrawArrowHeadRow(g, blackPen,
                                                   new Point(tmpW - padding, padding / 2),
                                                   new Point(padding, padding / 2),
                                                   padding);
                }
                else
                {
                    GraphicsUtils.DrawArrowHeadRow(g, blackPen,
                                                   new Point(padding, padding / 2),
                                                   new Point(tmpW - padding, padding / 2),
                                                   padding);
                }

                GraphicsUtils.DrawTextCenterd(g, sideLeft, sideLeftFont, blackBrush,
                                              new PointF(padding + pageW / 2, padding + pageH + padding / 2)
                                              );
                GraphicsUtils.DrawTextCenterd(g, sideRight, sideRightFont, blackBrush,
                                              new PointF(padding + pageW + padding + pageW / 2, padding + pageH + padding / 2)
                                              );
                GraphicsUtils.DrawTextCenterd(g, FaceIndex, faceFont, blackBrush,
                                              new PointF(tmpW / 2, padding + pageH + padding / 2)
                                              );


                DrawSide(pageW, pageH, g, face.Left, new Point(padding, padding), parentText);
                DrawSide(pageW, pageH, g, face.Right, new Point(padding * 2 + pageW, padding), parentText);

                // border
                //g.DrawRectangle(blackPen, new Rectangle(padding, padding, pageW, pageH));
            }

            return(b);
        }