Esempio n. 1
0
        /** Break the sheet into pages */
        private void SplitIntoPages()
        {
            int            currheight = TitleHeight;
            SheetMusicPage page       = new SheetMusicPage();

            if (numtracks == 2 && (staffs.Count % 2) == 0)
            {
                for (int i = 0; i < staffs.Count; i += 2)
                {
                    int heights = staffs[i].Height + staffs[i + 1].Height;
                    if (currheight + heights > PageHeight)
                    {
                        pages.Add(page);
                        page       = new SheetMusicPage();
                        currheight = heights;
                    }
                    else
                    {
                        currheight += heights;
                    }
                    // TODO: Do double staffs need to be handled specially, i.e. broken into tracks?
                    page.staffs.Add(staffs[i]);
                    page.staffs.Add(staffs[i + 1]);
                }
            }
            else
            {
                foreach (Staff staff in staffs)
                {
                    if (currheight + staff.Height > PageHeight)
                    {
                        pages.Add(page);
                        page       = new SheetMusicPage();
                        currheight = staff.Height;
                    }
                    else
                    {
                        currheight += staff.Height;
                    }
                    page.staffs.Add(staff);
                }
            }

            // Add final page
            if (!page.IsEmpty())
            {
                pages.Add(page);
            }
        }
Esempio n. 2
0
        /** Print the given page of the sheet music.
         * Page numbers start from 1.
         * A staff should fit within a single page, not be split across two pages.
         * If the sheet music has exactly 2 tracks, then two staffs should
         * fit within a single page, and not be split across two pages.
         */
        public void DoPrint(Graphics g, int pagenumber)
        {
            int leftmargin   = 20;
            int topmargin    = 20;
            int rightmargin  = 20;
            int bottommargin = 20;

            float scale = (g.VisibleClipBounds.Width - leftmargin - rightmargin) / PageWidth;

            g.PageScale = scale;

            int viewPageHeight = (int)((g.VisibleClipBounds.Height - topmargin - bottommargin) / scale);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.FillRectangle(Brushes.White, 0, 0,
                            g.VisibleClipBounds.Width,
                            g.VisibleClipBounds.Height);

            Rectangle clip = new Rectangle(0, 0, PageWidth, PageHeight);

            int ypos = TitleHeight;

            SheetMusicPage page = pages[pagenumber - 1]; // Convert to zero indexing

            if (pagenumber == 1)
            {
                DrawTitle(g);
                ypos = TitleHeight;
            }
            else
            {
                ypos = 0;
            }
            foreach (Staff staff in page.staffs)
            {
                g.TranslateTransform(leftmargin, topmargin + ypos);
                staff.Draw(g, clip, pen);
                g.TranslateTransform(-leftmargin, -(topmargin + ypos));
                ypos += staff.Height;
            }

            /* Draw the page number */
            Font font = new Font("Arial", 10, FontStyle.Bold);

            g.DrawString("" + pagenumber, font, Brushes.Black,
                         PageWidth - leftmargin, topmargin + viewPageHeight - 12);
            font.Dispose();
        }