示例#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
        // NOTE: Eventually this code should be converted to use SlideRenderer instead of each SheetRenderer. There were some issues with doing
        // this initially so for the time being we will keep it like this.
        public static Bitmap DrawSlide(TableOfContentsModel.Entry currentEntry, System.Drawing.Color background, SheetDisposition dispositions)
        {
            // Save the old state
            System.Drawing.Drawing2D.GraphicsState oldState;

            using (Synchronizer.Lock(currentEntry.Slide.SyncRoot)) {
                Rectangle rect = new Rectangle(0, 0, currentEntry.Slide.Bounds.Width, currentEntry.Slide.Bounds.Height);

                //Note: Uses DibGraphicsBuffer from TPC SDK to do antialiasing
                //See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/tbconprintingink.asp
                /// create the bitmap we're exporting to
                Bitmap toExport = new Bitmap(rect.Width, rect.Height);
                /// create what we will be drawing on to the export
                Graphics toSave = Graphics.FromImage(toExport);

                /// draw the slide data on a temporary graphics object in a temporary form
                System.Windows.Forms.Form tempForm = new System.Windows.Forms.Form();
                Graphics          screenGraphics   = tempForm.CreateGraphics();
                DibGraphicsBuffer dib          = new DibGraphicsBuffer();
                Graphics          tempGraphics = dib.RequestBuffer(screenGraphics, rect.Width, rect.Height);

                //Add the background color
                //First see if there is a Slide BG, if not, try the Deck.  Otherwise, use transparent.
                tempGraphics.Clear(background);

                //Get the Slide content and draw it
                oldState = tempGraphics.Save();

                Model.Presentation.SlideModel.SheetCollection sheets = currentEntry.Slide.ContentSheets;
                for (int i = 0; i < sheets.Count; i++)
                {
                    Model.Viewer.SlideDisplayModel display = new Model.Viewer.SlideDisplayModel(tempGraphics, null);

                    Rectangle slide = rect;
                    float     zoom  = 1f;
                    if (currentEntry.Slide != null)
                    {
                        slide = currentEntry.Slide.Bounds;
                        zoom  = currentEntry.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.SheetDisposition = dispositions;
                        display.Bounds           = slide;
                        display.PixelTransform   = pixel;
                        display.InkTransform     = ink;
                    }

                    Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet(display, sheets[i]);
                    if ((r.Sheet.Disposition & dispositions) != 0)
                    {
                        r.Paint(new System.Windows.Forms.PaintEventArgs(tempGraphics, rect));
                    }
                    r.Dispose();
                }

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

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

                    Rectangle slide = rect;
                    float     zoom  = 1f;
                    if (currentEntry.Slide != null)
                    {
                        slide = currentEntry.Slide.Bounds;
                        zoom  = currentEntry.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.SheetDisposition = dispositions;
                        display.Bounds           = slide;
                        display.PixelTransform   = pixel;
                        display.InkTransform     = ink;
                    }

                    Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet(display, sheets[i]);
                    if ((r.Sheet.Disposition & dispositions) != 0)
                    {
                        r.Paint(new System.Windows.Forms.PaintEventArgs(tempGraphics, rect));
                    }
                    r.Dispose();
                }

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

                //Export the image
                //Merge the graphics
                dib.PaintBuffer(toSave, 0, 0);

                //Dispose all the graphics
                toSave.Dispose();
                screenGraphics.Dispose();
                tempGraphics.Dispose();

                return(toExport);
            }
        }
示例#3
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();
                    }
                }
            }
        }