예제 #1
0
        // TODO: Correctly Draw the Slide Annotation
        private void DrawSlide(DeckTraversalModel traversal, int index, System.Drawing.Rectangle rect, System.Drawing.Graphics buffer)
        {
            // Save the old state
            System.Drawing.Drawing2D.GraphicsState oldState;

            using (Synchronizer.Lock(traversal.SyncRoot)) {
                using (Synchronizer.Lock(traversal.Deck.SyncRoot)) {
                    using (Synchronizer.Lock(traversal.Deck.TableOfContents.SyncRoot)) {
                        TableOfContentsModel.Entry entry = traversal.Deck.TableOfContents.Entries[index];
                        using (Synchronizer.Lock(entry.Slide.SyncRoot)) {
                            //Draw the background color
                            //First see if there is a Slide BG, if not, try the Deck. Otherwise, use transparent.
                            if (entry.Slide.BackgroundColor != Color.Empty)
                            {
                                buffer.FillRectangle(new System.Drawing.SolidBrush(entry.Slide.BackgroundColor), rect);
                            }
                            else if (traversal.Deck.DeckBackgroundColor != Color.Empty)
                            {
                                buffer.FillRectangle(new System.Drawing.SolidBrush(traversal.Deck.DeckBackgroundColor), rect);
                            }
                            else
                            {
                                buffer.FillRectangle(new System.Drawing.SolidBrush(Color.Transparent), rect);
                            }
                            //Draw the background Template
                            if (entry.Slide.BackgroundTemplate != null)
                            {
                                using (BackgroundTemplateRenderer render = new BackgroundTemplateRenderer(entry.Slide.BackgroundTemplate)) {
                                    render.Zoom = entry.Slide.Zoom;
                                    render.DrawAll(buffer, rect);
                                }
                            }

                            //Get the Slide content and draw it
                            oldState = buffer.Save();
                            Model.Presentation.SlideModel.SheetCollection sheets = entry.Slide.ContentSheets;
                            for (int i = 0; i < sheets.Count; i++)
                            {
                                SlideDisplayModel display = new SlideDisplayModel(buffer, null);

                                Rectangle slide = rect;
                                float     zoom  = 1f;
                                if (entry.Slide != null)
                                {
                                    slide = entry.Slide.Bounds;
                                    zoom  = entry.Slide.Zoom;
                                }

                                System.Drawing.Drawing2D.Matrix pixel, ink;
                                display.FitSlideToBounds(System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink);
                                using (Synchronizer.Lock(display.SyncRoot)) {
                                    display.Bounds         = slide;
                                    display.PixelTransform = pixel;
                                    display.InkTransform   = ink;
                                }

                                Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet(display, sheets[i]);
                                r.Paint(new System.Windows.Forms.PaintEventArgs(buffer, rect));
                                r.Dispose();
                            }

                            //Restore the Old State
                            buffer.Restore(oldState);
                            oldState = buffer.Save();

                            //Get the Annotation content and draw it
                            sheets = entry.Slide.AnnotationSheets;
                            for (int i = 0; i < sheets.Count; i++)
                            {
                                SlideDisplayModel display = new SlideDisplayModel(buffer, null);

                                Rectangle slide = rect;
                                float     zoom  = 1f;
                                if (entry.Slide != null)
                                {
                                    slide = entry.Slide.Bounds;
                                    zoom  = entry.Slide.Zoom;
                                }

                                System.Drawing.Drawing2D.Matrix pixel, ink;
                                display.FitSlideToBounds(System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink);
                                using (Synchronizer.Lock(display.SyncRoot)) {
                                    display.Bounds         = slide;
                                    display.PixelTransform = pixel;
                                    display.InkTransform   = ink;
                                }

                                Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet(display, sheets[i]);
                                if (r is Viewer.Slides.InkSheetRenderer)
                                {
                                    ((Viewer.Slides.InkSheetRenderer)r).Paint(buffer, rect);
                                }
                                else
                                {
                                    r.Paint(new System.Windows.Forms.PaintEventArgs(buffer, rect));
                                }
                                r.Dispose();
                            }

                            //Restore the Old State
                            buffer.Restore(oldState);

/*
 *                          Microsoft.Ink.Renderer renderer = new Microsoft.Ink.Renderer();
 *                          for( int i = 0; i < sheets.Count; i++ ) {
 *                              SheetModel sm = sheets[i];
 *                              if( sm is InkSheetModel ) {
 *                                  InkSheetModel ism = sm as InkSheetModel;
 *                                  using( Synchronizer.Lock( ism.SyncRoot ) ) {
 *                                      foreach( Microsoft.Ink.Stroke stroke in ism.Ink.Strokes ) {
 *                                          renderer.Draw( buffer, stroke );
 *                                      }
 *                                  }
 *                              } else if( sm is TextSheetModel ) {
 *                                  TextSheetModel tsm = sm as TextSheetModel;
 *                                  using( Synchronizer.Lock( tsm.SyncRoot ) ) {
 *                                      buffer.DrawString( tsm.Text, tsm.Font, new SolidBrush( tsm.Color ), tsm.Bounds );
 *                                  }
 *                              } else if( sm is ImageSheetModel ) {
 *                                  //add any images in the AnnotationSheets
 *                                  ImageSheetModel image_sheet_model = (ImageSheetModel)sm;
 *                                  using( Synchronizer.Lock( image_sheet_model.SyncRoot ) ) {
 *                                       buffer.DrawImage( image_sheet_model.Image, image_sheet_model.Bounds );
 *                                  }
 *                              } else {
 *                                  //Unknown, skip it
 *                                  continue;
 *                              }
 *                          }
 */
                        }
                    }
                }
            }
        }
예제 #2
0
        private void DrawSlide2(DeckTraversalModel traversal, int index, System.Drawing.Rectangle displayBounds, System.Drawing.Graphics g)
        {
            float width_scale  = g.DpiX / 100f;
            float height_scale = g.DpiY / 100f;

            Rectangle bounds = new Rectangle(0, 0, (int)(displayBounds.Width * 3f), (int)(displayBounds.Height * 3f));

            // Create an image using temporary graphics and graphics buffer object
            Bitmap imageForPrinting = new Bitmap(bounds.Width, bounds.Height);

            using (Graphics graphicsImage = Graphics.FromImage(imageForPrinting)) {
                using (DibGraphicsBuffer dib = new DibGraphicsBuffer()) {
                    // Create temporary screen Graphics
                    System.Windows.Forms.Form tempForm = new System.Windows.Forms.Form();
                    Graphics screenGraphics            = tempForm.CreateGraphics();

                    // Create temporary Graphics from the Device Independent Bitmap
                    using (Graphics graphicsTemp = dib.RequestBuffer(screenGraphics, imageForPrinting.Width, imageForPrinting.Height)) {
                        // Save the old state
                        System.Drawing.Drawing2D.GraphicsState oldState;

                        using (Synchronizer.Lock(traversal.SyncRoot)) {
                            using (Synchronizer.Lock(traversal.Deck.SyncRoot)) {
                                using (Synchronizer.Lock(traversal.Deck.TableOfContents.SyncRoot)) {
                                    TableOfContentsModel.Entry entry = traversal.Deck.TableOfContents.Entries[index];
                                    using (Synchronizer.Lock(entry.Slide.SyncRoot)) {
                                        //Draw the background color
                                        //First see if there is a Slide BG, if not, try the Deck. Otherwise, use transparent.

                                        if (entry.Slide.BackgroundColor != Color.Empty)
                                        {
                                            graphicsTemp.Clear(entry.Slide.BackgroundColor);
                                        }
                                        else if (traversal.Deck.DeckBackgroundColor != Color.Empty)
                                        {
                                            graphicsTemp.Clear(traversal.Deck.DeckBackgroundColor);
                                        }
                                        else
                                        {
                                            graphicsTemp.Clear(Color.Transparent);
                                        }

                                        //Get the Slide content and draw it
                                        oldState = graphicsTemp.Save();
                                        Model.Presentation.SlideModel.SheetCollection sheets = entry.Slide.ContentSheets;
                                        for (int i = 0; i < sheets.Count; i++)
                                        {
                                            SlideDisplayModel display = new SlideDisplayModel(graphicsTemp, null);

                                            Rectangle rect  = new Rectangle(0, 0, bounds.Width, bounds.Height);
                                            Rectangle slide = new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
                                            float     zoom  = 1f;
                                            if (entry.Slide != null)
                                            {
                                                slide = entry.Slide.Bounds;
                                                zoom  = entry.Slide.Zoom;
                                            }

                                            System.Drawing.Drawing2D.Matrix pixel, ink;
                                            display.FitSlideToBounds(System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink);
                                            using (Synchronizer.Lock(display.SyncRoot)) {
                                                display.Bounds         = slide;
                                                display.PixelTransform = pixel;
                                                display.InkTransform   = ink;
                                            }

                                            Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet(display, sheets[i]);
                                            r.Paint(new System.Windows.Forms.PaintEventArgs(graphicsTemp, bounds));
                                            r.Dispose();
                                        }
                                    }
                                }
                            }
                        }

                        //Restore the Old State
                        graphicsTemp.Restore(oldState);

                        // Use the buffer to paint onto the final image
                        dib.PaintBuffer(graphicsImage, 0, 0);

                        // Draw this image onto the printer graphics,
                        // adjusting for printer margins
                        g.DrawImage(imageForPrinting, displayBounds);

                        //Cleanup
                        graphicsTemp.Dispose();
                        screenGraphics.Dispose();
                        tempForm.Dispose();
                        dib.Dispose();
                        graphicsImage.Dispose();
                        imageForPrinting.Dispose();
                    }
                }
            }
        }