コード例 #1
0
        protected override Rect GetRect(PrintElementBase element)
        {
            if (element is TextBlock)
            {
                TextBlock block = (TextBlock)element;

                if (block.Content != null)
                {
                    StringFormat fmt = GetFromBlock(block);

                    Font font = GetSDFontFromElement(block);

                    SizeF stringSize = this.StringRect(block.Content.ToString(), fmt,
                                                       Rectangle.Empty, font);

                    block.Bounds.Extend(new Rect(0, 0, stringSize.Width, stringSize.Height));
                }
            }
            else if (element is ImageElement)
            {
                ImageElement image = (ImageElement)element;

                if (image.SourceStream != Stream.Null)
                {
                    using (Bitmap bmp = new Bitmap(image.SourceStream))
                    {
                        Rect rc = new Rect(0, 0, bmp.Width, bmp.Height);

                        image.Bounds = rc;
                    }
                }
            }

            return(Rect.Empty);
        }
コード例 #2
0
        private void DrawBlock(Block block)
        {
            RectangleF bounds = new RectangleF(this.CurrentX, this.CurrentY, 0, 0);

            if (block.Content is String)
            {
                Rect b = block.Bounds;

                PrintElementBase parent = (PrintElementBase)block.Parent;
                b.Width      = printArgs.PageBounds.Width - parent.Bounds.Width;
                b.Height     = parent.Bounds.Height - this.CurrentY;
                block.Bounds = b;

                DrawContentString(block);

                bounds = this.Rect2Rectangle(block.Bounds);

                return;
            }

            if (block.Childs.Count > 0)
            {
                PrintElementBase prev = null;

                foreach (PrintElementBase current in block.Childs)
                {
                    if (current is LineBreak)
                    {
                        DrawLineBreak((LineBreak)current, prev);
                    }
                    else
                    {
                        current.Render(this);
                    }

                    prev = current;

                    if (bounds.Right < current.Bounds.Right)
                    {
                        bounds.Width = (current.Bounds.Right - bounds.Right) - bounds.Left;
                    }

                    if (bounds.Bottom < current.Bounds.Bottom)
                    {
                        bounds.Height = (current.Bounds.Bottom - bounds.Bottom) - bounds.Top;
                    }

                    block.Bounds = this.Rectangle2Rect(bounds);
                }
            }

            block.Bounds = this.Rectangle2Rect(bounds);

            this.currentY = bounds.Bottom;

            this.currentX = bounds.Right;
        }
コード例 #3
0
        void DrawContentString(TextElement element)
        {
            //Implement TextWrap

            Font font = this.GetSDFontFromElement(element);

            Color fontColor = element.Foreground.ToSystemDrawingColor();

            StringFormat fmt = new StringFormat();

            if (element is Block)
            {
                fmt = this.GetFromBlock((Block)element);
            }

            SizeF textSize = printArgs.Graphics.MeasureString(element.Content.ToString(),
                                                              font, (int)(this.printArgs.PageBounds.Width - this.currentX), fmt);

            if (textSize.Width < element.Bounds.Width)
            {
                textSize.Width = element.Bounds.Width;
            }

            if (textSize.Height < element.Bounds.Height)
            {
                textSize.Height = element.Bounds.Height;
            }

            RectangleF drawRect = new RectangleF(new PointF(this.CurrentX,
                                                            this.CurrentY), textSize);

            element.Bounds = this.Rectangle2Rect(drawRect);

            if (element.Bounds.Bottom >= printArgs.PageBounds.Bottom)
            {
                printArgs.HasMorePages = true;

                _CurrentElement = element;

                dontDrawNow = true;

                return;
            }

            printArgs.Graphics.DrawString(element.Content.ToString(),
                                          font,
                                          new SolidBrush(fontColor),
                                          this.Rect2Rectangle(element.Bounds), fmt);

            this.currentY += element.Bounds.Height;

            this.currentX = printArgs.MarginBounds.Left;
        }
コード例 #4
0
        void DrawLineBreak(LineBreak breakElement, PrintElementBase prevElement)
        {
            if (prevElement != null)
            {
                this.currentY = prevElement.Bounds.Bottom + breakElement.BreakHeight;
            }
            else
            {
                this.currentY += breakElement.BreakHeight;
            }

            breakElement.Bounds = new Rect(this.CurrentX, this.currentY,
                                           printArgs.PageBounds.Width - this.CurrentX, breakElement.BreakHeight);

            this.currentX = 0;
        }
コード例 #5
0
        void Reset(PrintElementBase element)
        {
            this.currentX = 0;
            this.currentY = 0;

            element.Bounds = Rect.Empty;

            IHaveChild haveChilds = element as IHaveChild;

            if (haveChilds != null)
            {
                foreach (PrintElementBase current in haveChilds.Childs)
                {
                    Reset(current);
                }
            }
        }
コード例 #6
0
 protected abstract void DoRealignContent(PrintElementBase element);
コード例 #7
0
 protected abstract Rect GetRect(PrintElementBase element);
コード例 #8
0
ファイル: BasePrintingContext.cs プロジェクト: viticm/pap2
 protected abstract void DoRealignContent(PrintElementBase element);
コード例 #9
0
ファイル: BasePrintingContext.cs プロジェクト: viticm/pap2
 protected abstract Rect GetRect(PrintElementBase element);
コード例 #10
0
ファイル: FlowRowElement.cs プロジェクト: westybsa/MP.LSharp
 public FlowRowElement(PrintElementBase element)
 {
     _PrintElementBase = element;
 }
コード例 #11
0
        protected override Rect GetRect(PrintElementBase element)
        {
            if (element is TextBlock)
            {
                TextBlock block = (TextBlock)element;

                if (block.Content != null)
                {

                    StringFormat fmt = GetFromBlock(block);

                    Font font = GetSDFontFromElement(block);

                    SizeF stringSize = this.StringRect(block.Content.ToString(), fmt,
                        Rectangle.Empty, font);

                    block.Bounds.Extend(new Rect(0, 0, stringSize.Width, stringSize.Height));
                }
            }
            else if (element is ImageElement)
            {
                ImageElement image = (ImageElement)element;

                if (image.SourceStream != Stream.Null)
                {
                    using (Bitmap bmp = new Bitmap(image.SourceStream))
                    {
                        Rect rc = new Rect(0, 0, bmp.Width, bmp.Height);

                        image.Bounds = rc;
                    }
                }
            }

            return Rect.Empty;
        }
コード例 #12
0
        void Reset(PrintElementBase element)
        {
            this.currentX = 0;
            this.currentY = 0;

            element.Bounds = Rect.Empty;

            IHaveChild haveChilds = element as IHaveChild;

            if (haveChilds != null)
            {
                foreach (PrintElementBase current in haveChilds.Childs)
                {
                    Reset(current);
                }
            }
        }
コード例 #13
0
        void DrawContentString(TextElement element)
        {
            //Implement TextWrap

            Font font = this.GetSDFontFromElement(element);

            Color fontColor = element.Foreground.ToSystemDrawingColor();

            StringFormat fmt = new StringFormat();             

            if (element is Block)
            {
                fmt = this.GetFromBlock((Block)element);
            }

            SizeF textSize = printArgs.Graphics.MeasureString(element.Content.ToString(),
                font, (int)(this.printArgs.PageBounds.Width - this.currentX), fmt);

            if (textSize.Width < element.Bounds.Width)
            {
                textSize.Width = element.Bounds.Width;
            }

            if (textSize.Height < element.Bounds.Height)
            {
                textSize.Height = element.Bounds.Height;
            }

            RectangleF drawRect = new RectangleF(new PointF(this.CurrentX,
                this.CurrentY), textSize);

            element.Bounds = this.Rectangle2Rect(drawRect);

            if (element.Bounds.Bottom >= printArgs.PageBounds.Bottom)
            {
                printArgs.HasMorePages = true;

                _CurrentElement = element;

                dontDrawNow = true;

                return;
            }

            printArgs.Graphics.DrawString(element.Content.ToString(),
                 font,
                 new SolidBrush(fontColor),
                 this.Rect2Rectangle(element.Bounds), fmt);

            this.currentY += element.Bounds.Height;

            this.currentX = printArgs.MarginBounds.Left;
        }
コード例 #14
0
        void DrawLineBreak(LineBreak breakElement,PrintElementBase prevElement)
        {
            
           
            if (prevElement != null)
            {
                this.currentY = prevElement.Bounds.Bottom + breakElement.BreakHeight;
            }
            else
            {
                this.currentY += breakElement.BreakHeight;
            }

            breakElement.Bounds = new Rect(this.CurrentX, this.currentY, 
                printArgs.PageBounds.Width - this.CurrentX, breakElement.BreakHeight);

            this.currentX = 0;
        }
コード例 #15
0
 public FlowRowElement(PrintElementBase element)
 {
     _PrintElementBase = element;
 }