Inheritance: Control, IResizable, IDataControl
 public TextBlockView(TextBlock textBlock,TextBlockRenderer textBlockRenderer, SectionView parentSection)
     : base(textBlock)
 {
     this.ParentSection = parentSection;
     TextBlockRenderer = textBlockRenderer;
     invaildateBound();
 }
Example #2
0
 public TextBlockView(TextBlock textBlock,SectionView parentSection)
     : base(textBlock)
 {
     this.ParentSection = parentSection;
     AbsoluteBound = new Rectangle (parentSection.AbsoluteDrawingStartPoint.X + textBlock.Location.X,
                                     parentSection.AbsoluteDrawingStartPoint.Y + textBlock.Location.Y, textBlock.Width, textBlock.Height);
     TextBlockRenderer = new TextBlockRenderer(){ DesignMode = true};
 }
Example #3
0
        public override void CreateNewControl(SectionView sectionView)
        {
            var startPoint = sectionView.PointInSectionByAbsolutePoint (designService.StartPressPoint.X, designService.StartPressPoint.Y);

            var tb = new TextBlock { Location = new MonoReports.Model.Point (startPoint.X, startPoint.Y), Text="text", FontName="Helvetica", FontSize=11, Size = new Size(70,14) };

            TextBlockView textBlockView = sectionView.CreateControlView (tb) as TextBlockView;

            sectionView.Section.Controls.Add (tb);
            textBlockView.ParentSection = sectionView;
            designService.SelectedControl = textBlockView;
        }
Example #4
0
        /// <summary>
        /// Get character index after which layout should be broken to not exceed maxHeight
        /// </summary>
        /// <returns>
        ///  -1 if maxHeight is smaller than top padding. -2 if maxHeight is after text and character index if maxHeight is in the middle of the text.
        /// </returns>
        /// <param name='g'>
        /// G.
        /// </param>
        /// <param name='tb'>
        /// Tb.
        /// </param>
        /// <param name='maxHeight'>
        /// Max height.
        /// </param>
        public static int GetBreakLineCharacterIndexbyMaxHeight(this Context g,TextBlock tb, double maxHeight)
        {
            int result = 0;
            Pango.Rectangle unused;
            Pango.Rectangle te;
            double vertAlgSpan = 0;
            int chi = 0;
            int gi = 0;

            if (maxHeight > 0) {
                Pango.Layout layout = createLayoutFromTextBlock(g,tb);
                layout.GetExtents (out unused, out te);
                double measuredHeight = te.Height / Pango.Scale.PangoScale;

                if(tb.VerticalAlignment != VerticalAlignment.Top)
                    vertAlgSpan = measureVerticlaSpan(tb,measuredHeight);

                double realTbStart = tb.Padding.Top + vertAlgSpan;

                if(realTbStart >= maxHeight) {
                    result = -1;
                } else if (maxHeight > realTbStart + measuredHeight)
                    return -2;
                else {
                    layout.XyToIndex(0, (int)((maxHeight - realTbStart) * Pango.Scale.PangoScale), out chi, out gi);
                    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(tb.Text);
                    int o = System.Text.Encoding.UTF8.GetCharCount(bytes,0, chi);
                    result = o;
                }

                (layout as IDisposable).Dispose();

            }

            return result;
        }
Example #5
0
        public static Rectangle DrawTextBlock(this Context g, TextBlock tb, bool render)
        {
            double topBottomSpan = tb.Padding.Top + tb.Padding.Bottom;
            double leftRightSpan = tb.Padding.Left + tb.Padding.Right;
            double vertAlgSpan = 0;
            g.Save ();
            Pango.Layout layout = createLayoutFromTextBlock(g,tb);
            g.Color = tb.FontColor.ToCairoColor();

            Pango.Rectangle unused;
            Pango.Rectangle te;
            layout.GetExtents (out unused, out te);
            double measuredHeight = te.Height / Pango.Scale.PangoScale;

            if(tb.VerticalAlignment != VerticalAlignment.Top)
                vertAlgSpan = measureVerticlaSpan(tb,measuredHeight);

            g.MoveTo (tb.Left + tb.Padding.Left, tb.Top + tb.Padding.Top + vertAlgSpan);

            if (render) {
                Pango.CairoHelper.ShowLayout(g, layout);
            }

            layout.GetExtents (out unused, out te);
            (layout as IDisposable).Dispose();
            g.Restore ();
            return new Rectangle( tb.Left - tb.Padding.Left + te.X / Pango.Scale.PangoScale, tb.Top - tb.Padding.Top + te.Y / Pango.Scale.PangoScale, (te.Width / Pango.Scale.PangoScale) + leftRightSpan , (te.Height/ Pango.Scale.PangoScale) + topBottomSpan);
        }
Example #6
0
        static double measureVerticlaSpan(TextBlock tb, double measuredHeight)
        {
            double vertAlgSpan = 0;

            if (tb.VerticalAlignment == VerticalAlignment.Center) {

                    double controlHeightWithoutPadding = (tb.Height - tb.Padding.Top) - tb.Padding.Bottom;

                    if (measuredHeight < controlHeightWithoutPadding) {
                        vertAlgSpan = (controlHeightWithoutPadding  - measuredHeight) / 2;
                    }
            }else if (tb.VerticalAlignment == VerticalAlignment.Bottom) {
                double controlHeightWithoutPadding = (tb.Height - tb.Padding.Bottom);
                if (measuredHeight < controlHeightWithoutPadding) {
                    vertAlgSpan = (controlHeightWithoutPadding  - measuredHeight) ;
                }
            }

            return vertAlgSpan;
        }
Example #7
0
        static Pango.Layout createLayoutFromTextBlock(Context g, TextBlock tb)
        {
            double leftRightSpan = tb.Padding.Left + tb.Padding.Right;
            Pango.Layout layout = Pango.CairoHelper.CreateLayout (g);

            layout.Wrap = Pango.WrapMode.Word;
            layout.Width = (int)((tb.Width - leftRightSpan) * Pango.Scale.PangoScale);
            Pango.FontDescription fd = new Pango.FontDescription ();
            fd.Family = tb.FontName;

            fd.Style = ReportToPangoSlant (tb.FontSlant);
            fd.Weight = ReportToPangoWeight (tb.FontWeight);

            fd.AbsoluteSize = tb.FontSize * Pango.Scale.PangoScale;
            layout.FontDescription = fd;

            layout.Spacing = (int)(tb.LineSpan * Pango.Scale.PangoScale);
            //layout.Indent = (int)(0 * Pango.Scale.PangoScale);
            layout.Alignment = ReportToPangoAlignment (tb.HorizontalAlignment);
            layout.SetText (tb.Text);
            return layout;
        }
Example #8
0
        public static void Main(string[] args)
        {
            Report r = new Report ();

            //----------------------
            // report header section
            //----------------------

            var invTextTb = new TextBlock (){
                Text = "Invoice",
                Width = r.Width,
                FontWeight = FontWeight.Bold,
                Height = 20,
                FontSize = 18,
                HorizontalAlignment = HorizontalAlignment.Center,
            };
            r.ReportHeaderSection.Controls.Add (invTextTb);

            var invNumberTb = new TextBlock (){
                FieldName ="invoice.Number",
                FieldKind = FieldKind.Parameter,
                Text = "Invoice",
                Width = r.Width,
                Height = 20,
                FontSize = 18,
                Top = 20,
                HorizontalAlignment = HorizontalAlignment.Center,
                FontColor = new Color (1,1,1)
            };
            r.ReportHeaderSection.Height = 50;
            r.ReportHeaderSection.Controls.Add (invNumberTb);
            r.ReportHeaderSection.BackgroundColor = new Color (0.8,0.8,0.8);

            //-------------------
            //page header section
            //-------------------

            var phLine = new Line (){ Location = new Point(0,10), End = new Point(r.Width,10), ExtendToBottom = true, LineWidth = 1};
            r.PageHeaderSection.Height = 16;
            r.PageHeaderSection.Controls.Add (phLine);

            //index label
            var indhTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Ind", Width = 40, Height = 14};
            r.PageHeaderSection.Controls.Add (indhTb);

            // description label
            var deschTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Description", Left = 42, Height = 14};
            r.PageHeaderSection.Controls.Add (deschTb);

            // quantity label
            var qnthTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Quantity", Left = 170, Height = 14};
            r.PageHeaderSection.Controls.Add (qnthTb);

            // price field
            var prthTb = new TextBlock () {FontWeight = FontWeight.Bold,Text = "Price", Left = 230,Width = 60,  Height = 14};
            r.PageHeaderSection.Controls.Add (prthTb);

            //---------------
            //details section
            //---------------

            //do not allow break detail section across page
            r.DetailSection.KeepTogether = true;
            r.DetailSection.Height = 16;

            //index field
            var indTb = new TextBlock () { FieldName = "Index",  FieldKind = FieldKind.Data, Text = "00", Left = 1.2, Width = 40, Height = 14};
            r.DetailSection.Controls.Add (indTb);

            // description field
            var descTb = new TextBlock () { FieldName = "Description",FieldKind =  FieldKind.Data, Text = "Desc", Left = 42, Width =128,  Height = 14};
            r.DetailSection.Controls.Add (descTb);

            // quantity field
            var qntTb = new TextBlock () { FieldName = "Quantity",FieldKind =  FieldKind.Data, Text = "0", Left = 170, Width = 20, Height = 14};
            r.DetailSection.Controls.Add (qntTb);

            // price field
            var prtTb = new TextBlock () { FieldName = "PricePerUnitGross", FieldTextFormat = "{0:C}", FieldKind =  FieldKind.Data, Text = "0", Left = 230,Width = 60,  Height = 14};
            r.DetailSection.Controls.Add (prtTb);

            var line = new Line (){ Location = new Point(0,10), End = new Point(r.Width,10), ExtendToBottom = true, LineWidth = 1};
            r.DetailSection.Controls.Add (line);

            //just before processing we can change section properties
            r.DetailSection.OnBeforeControlProcessing += delegate(ReportContext rc, Control c) {
                if(rc.RowIndex % 2 == 0)
                    c.BackgroundColor = new Color(0.91,0.91,0.91);
                else
                    ( (TextBlock) (c as Section).Controls[1]).FontColor = new Color(1,0.7,0.2);
            };

            var lv0 = new Line (){ Location = new Point(0.5,0), End = new Point(0.5,10), ExtendToBottom = true, LineWidth = 1};
            r.DetailSection.Controls.Add (lv0);

            var lineV = new Line (){ Location = new Point(291,0), End = new Point(291,10), LineType = LineType.Dash, ExtendToBottom = true, LineWidth = 1};
            r.DetailSection.Controls.Add (lineV);

            //---------------
            //Report footer
            //---------------

             	// price field

            var prtTotalLabelTb = new TextBlock () {
                FontWeight = FontWeight.Bold,
              	HorizontalAlignment = HorizontalAlignment.Right,
                FontSize = 22,
                FieldKind =  FieldKind.Parameter,
                Text = "Total: ",
                Left = 130,
                Width = 100
                };

            r.ReportFooterSection.Controls.Add (prtTotalLabelTb);

            var prtTotalTb = new TextBlock () {
                FontWeight = FontWeight.Bold,
                FieldName = "invoice.TotalGross",
                FieldTextFormat = "{0:C}",
                FontSize = 22,
                FieldKind =  FieldKind.Parameter,
                Text = "0",
                Left = 230,
                Width = 150,
                Height = 14};

            r.ReportFooterSection.Controls.Add (prtTotalTb);

            //---------------
            //Page footer
            //---------------
            var fl = new Line (){ Location = new Point(0,1), End = new Point(r.Width,1),  LineWidth = 1};
            r.PageFooterSection.Controls.Add (fl);

            var pnTb = new TextBlock () {
                FieldName = "#PageNumber",
                FieldTextFormat = "{0:C}",
                FieldKind =  FieldKind.Expression,
                Text = "0",
                Left = r.Width-30,
                Width = 30,
                HorizontalAlignment = HorizontalAlignment.Right,
                Top = 2,
                Height = 14};

            r.PageFooterSection.Controls.Add (pnTb);

            #region example invoice datasource

            //example invoice class...
            Invoice invoice = new Invoice () {
                Number = "01/12/2010",
                CreationDate = DateTime.Now,
                Positions = new List<InvoicePosition>()
            };

            for (int i = 0; i < 82; i++) {
                invoice.Positions.Add (
                    new InvoicePosition ()
                    {
                        Index = i+1,
                        Quantity = 1,
                        Description = "Reporting services " + (i + 1).ToString(),
                        PricePerUnitGross = ((i * 50) / (i + 1)) + 1
                    }
                );
            }

            invoice.Positions[11].Description = "here comes longer position text to see if position will extend section height";

            //Total gross ...
            invoice.TotalGross = invoice.Positions.Sum (p => p.PricePerUnitGross * p.Quantity);
            #endregion

            r.DataSource = invoice.Positions;

            r.ExportToPdf ("invoice.pdf", new Dictionary<string,object>{ {"invoice",invoice}});
        }
        public void BreakOffControlAtMostAtHeight_WithHeightInText_FirstControlAlwaysLowerOrEqualThanHeight()
        {
            TextBlockRenderer tbr = new TextBlockRenderer();
            using(Cairo.PdfSurface pdf = new Cairo.PdfSurface( System.IO.Path.Combine( System.Environment.CurrentDirectory, "monoreports_tmp_test.pdf"),600,800)) {

                var cr = new  Cairo.Context(pdf);

                TextBlock tb = new TextBlock();
                tb.Text = loremIpsum;
                tb.Location = new Point(10,50);
                tb.Width = 89;
                tb.Height = 40;

                Control[] tab = null;

                tab = tbr.BreakOffControlAtMostAtHeight(cr,tb,120);

                Assert.LessOrEqual(tab[0].Height,120);

                tab = tbr.BreakOffControlAtMostAtHeight(cr,tb,330);

                Assert.LessOrEqual(tab[0].Height,330);

                //chhamge padding

                tb.Padding = new Thickness(4,22,8,8);

                tab = tbr.BreakOffControlAtMostAtHeight(cr,tb,20);

                Assert.LessOrEqual(tab[0].Height,20);

                tab = tbr.BreakOffControlAtMostAtHeight(cr,tb,47);

                Assert.LessOrEqual(tab[0].Height,47);

                pdf.Finish();
            }
        }
        public static Rectangle DrawTextBlock(this Context g, TextBlock tb, bool render)
        {
            double topBottomSpan = tb.Padding.Top + tb.Padding.Bottom;
            double leftRightSpan = tb.Padding.Left + tb.Padding.Right;
            double vertAlgSpan = 0;
            g.Save ();
            Pango.Layout layout = createLayoutFromTextBlock(g,tb);
            g.Color = tb.FontColor.ToCairoColor();

            Pango.Rectangle inkRect1;
            Pango.Rectangle logicalRect;
            layout.GetExtents (out inkRect1, out logicalRect);
            double measuredHeight = (logicalRect.Height) / (Pango.Scale.PangoScale * UnitMultiplier);
            double measuredY = logicalRect.Y / (Pango.Scale.PangoScale * UnitMultiplier);

            if(tb.VerticalAlignment != VerticalAlignment.Top)
                vertAlgSpan = measureVerticlaSpan(tb,measuredHeight);

            g.MoveTo ((tb.Left + tb.Padding.Left) * UnitMultiplier, (tb.Top + tb.Padding.Top + vertAlgSpan - measuredY) * UnitMultiplier);

            if (render) {
                Pango.CairoHelper.ShowLayout(g, layout);
            }

            layout.GetExtents (out inkRect1, out logicalRect);
            measuredHeight = (logicalRect.Height) / (Pango.Scale.PangoScale * UnitMultiplier);
            double measuredWidth = logicalRect.Width / (Pango.Scale.PangoScale * UnitMultiplier);
            measuredY = logicalRect.Y / (Pango.Scale.PangoScale * UnitMultiplier);

            if ( DebugTextBlock && render ) {

                Pango.Rectangle  inklineRect = new Pango.Rectangle();
                Pango.Rectangle logLineRect = new Pango.Rectangle();

                {
                    double span = measuredY;
                    for(int d = 0 ; d < layout.LinesReadOnly.Length;d++){
                        var item = layout.LinesReadOnly[d];

                    item.GetExtents(ref inklineRect,ref logLineRect);
                    //seems like when measuring line logLineRect.Y is not needed but i don't know why
                    double h = ((logLineRect.Height / Pango.Scale.PangoScale));
                    double x = ((tb.Left + tb.Padding.Left) * UnitMultiplier + (logLineRect.X / Pango.Scale.PangoScale));
                    double y = (tb.Top + tb.Padding.Top) * UnitMultiplier  + span;
                    DrawDebugRect(g,
                        new Cairo.Rectangle(
                         x, y,
                        ((logLineRect.Width / Pango.Scale.PangoScale)) ,
                        h
                        ));

                        span += h;
                    }
                }
            }

            (layout as IDisposable).Dispose();
            g.Restore ();
            return new Rectangle( tb.Left , tb.Top, measuredWidth + leftRightSpan , measuredHeight + topBottomSpan);
        }
        /// <summary>
        /// Get character index after which layout should be broken to not exceed maxHeight
        /// </summary>
        /// <returns>
        ///  -1 if maxHeight is smaller than top padding. -2 if maxHeight is after text and character index if maxHeight is in the middle of the text.
        /// </returns>
        /// <param name='g'>
        /// G.
        /// </param>
        /// <param name='tb'>
        /// Tb.
        /// </param>
        /// <param name='maxHeight'>
        /// Max height.
        /// </param>
        public static int GetBreakLineCharacterIndexbyMaxHeight(
			this Context g,
			TextBlock tb,
			double maxHeight)
        {
            int result = 0;
            Pango.Rectangle inkRect;
            Pango.Rectangle logRect;
            double vertAlgSpan = 0;
            int chi = 0;
            int gi = 0;

            if (maxHeight > 0) {
                Pango.Layout layout = createLayoutFromTextBlock(g,tb);
                layout.GetExtents (out inkRect, out logRect);
                double measuredHeight = inkRect.Height / (Pango.Scale.PangoScale * UnitMultiplier);
                //double measuredY = inkRect.Y / (Pango.Scale.PangoScale * UnitMultiplier);

                if(tb.VerticalAlignment != VerticalAlignment.Top)
                    vertAlgSpan = measureVerticlaSpan(tb,measuredHeight);

                double realTbStart = (tb.Padding.Top + vertAlgSpan);

                if(realTbStart >= maxHeight) {
                    result = -1;
                } else if (maxHeight > realTbStart + measuredHeight)
                    return -2;
                else {
                    int line = 0;
                    int x = 0;
                    layout.XyToIndex(0, (int)((maxHeight - realTbStart) * UnitMultiplier * Pango.Scale.PangoScale) + inkRect.Y , out chi, out gi);
                    layout.IndexToLineX(chi,false,out line,out x);
                    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(tb.Text);
                    int o = System.Text.Encoding.UTF8.GetCharCount(bytes,0, chi);
                    result = o;
                }

                (layout as IDisposable).Dispose();

            }

            return result;
        }
Example #12
0
 public override Control CreateControl()
 {
     TextBlock textBlock = new TextBlock();
     CopyBasicProperties(textBlock);
     textBlock.CanGrow = CanGrow;
     textBlock.CanShrink = CanShrink;
     textBlock.Border = (Border) Border.Clone();
     textBlock.FontName = FontName;
     textBlock.LineSpan = LineSpan;
     textBlock.Padding = new Thickness(Padding.Left,Padding.Top, Padding.Right, Padding.Bottom);
     textBlock.FontSize = FontSize;
     textBlock.FontSlant =   FontSlant;
     textBlock.FontWeight =   FontWeight;
     textBlock.FontColor =   new Color(FontColor.R,FontColor.G,FontColor.B,FontColor.A);
     textBlock.FieldName =   FieldName;
     textBlock.FieldKind =   FieldKind;
     textBlock.FieldTextFormat = FieldTextFormat;
     textBlock.HorizontalAlignment =   HorizontalAlignment;
     textBlock.VerticalAlignment =   VerticalAlignment;
     textBlock.Text =   Text;
     return textBlock;
 }
Example #13
0
        public static void Main(string[] args)
        {
            Report r = new Report ();
            //----------------------
            // report header section
            //----------------------

            var invTextTb = new TextBlock (){
                Text = "Invoice",
                Width = r.Width,
                FontWeight = FontWeight.Bold,
                FontSize = 14,
                HorizontalAlignment = HorizontalAlignment.Center,
            };
            r.ReportHeaderSection.Controls.Add (invTextTb);

            var invNumberTb = new TextBlock (){
                FieldName ="invoice.Number",
                FieldKind = FieldKind.Parameter,
                Text = "Invoice",
                Width = r.Width,
                FontSize = 14,
                Top = 5.mm(),
                HorizontalAlignment = HorizontalAlignment.Center,
                FontColor = Color.White
            };
            r.ReportHeaderSection.Height = 30.mm ();
            r.ReportHeaderSection.Controls.Add (invNumberTb);
            r.ReportHeaderSection.BackgroundColor = Color.Silver;

            //-------------------
            //page header section
            //-------------------

            var phLine = new Line (){
                Location = new Point(0,10.mm()), End = new Point(r.Width,10.mm()), ExtendToBottom = true};

            r.PageHeaderSection.Controls.Add (phLine);

            //index label
            var indhTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Ind", Width = 10.mm()};
            r.PageHeaderSection.Controls.Add (indhTb);

            // description label
            var deschTb = new TextBlock () {FontWeight = FontWeight.Bold,Text = "Description", Left = 12.mm(), Width = 20.mm()};
            r.PageHeaderSection.Controls.Add (deschTb);

            // quantity label
            var qnthTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Quantity", Left = 42.mm()};
            r.PageHeaderSection.Controls.Add (qnthTb);

            // price field
            var prthTb = new TextBlock () {FontWeight = FontWeight.Bold,Text = "Price", Left = 60.mm(),Width = 30.mm()};
            r.PageHeaderSection.Controls.Add (prthTb);

            //---------------
            //details section
            //---------------

            //do not allow break detail section across page
            r.DetailSection.KeepTogether = true;
            r.DetailSection.Height = 6.mm ();

            //index field
            var indTb = new TextBlock () { FieldName = "Index",  FieldKind = FieldKind.Data, Text = "00", Left = 1.2.mm(), Width = 10.mm()};
            r.DetailSection.Controls.Add (indTb);

            // description field
            var descTb = new TextBlock () { FieldName = "Description",  FieldKind =  FieldKind.Data, Text = "Desc", Left = 12.mm(), Width = 35.mm()};
            r.DetailSection.Controls.Add (descTb);

            // quantity field
            var qntTb = new TextBlock () { FieldName = "Quantity",  FieldKind =  FieldKind.Data, Text = "0", Left = 47.mm(), Width = 5.mm(), };
            r.DetailSection.Controls.Add (qntTb);

            // price field
            var prtTb = new TextBlock () { FieldName = "PricePerUnitGross", FieldTextFormat = "{0:C}", FieldKind =  FieldKind.Data, Text = "0", Left = 62.mm(),Width = 20.mm()};
            r.DetailSection.Controls.Add (prtTb);

            var line = new Line (){ Location = new Point(0,2.mm()), End = new Point(r.Width,2.mm()), ExtendToBottom = true};
            r.DetailSection.Controls.Add (line);

            //just before processing we can change section properties
            r.DetailSection.OnBeforeControlProcessing += delegate(ReportContext rc, Control c) {
                if (rc.RowIndex % 2 == 0) {
                    c.BackgroundColor = Color.LightGray;
                }
                else {
                    ((TextBlock)(c as Section).Controls [1]).FontColor = Color.PaleVioletRed;
                }
            };

            var lv0 = new Line (){
                Location = new Point(1,0),
                End = new Point(1,2.mm()),
                ExtendToBottom = true};
            r.DetailSection.Controls.Add (lv0);

            var lineV = new Line (){ Location = new Point(r.Width,2.mm()), End = new Point(r.Width,2.mm()), LineType = LineType.Dash, ExtendToBottom = true};
            r.DetailSection.Controls.Add (lineV);

            //---------------
            //Report footer
            //---------------

            // price field

            var prtTotalLabelTb = new TextBlock () {
                FontWeight = FontWeight.Bold,
                    HorizontalAlignment = HorizontalAlignment.Right,
                FontSize = 12,
                FieldKind =  FieldKind.Parameter,
                Text = "Total: ",
                Left = 50.mm(),
                Width = 10.mm()
                };

            r.ReportFooterSection.Controls.Add (prtTotalLabelTb);

            var prtTotalTb = new TextBlock () {
                FontWeight = FontWeight.Bold,
                FieldName = "invoice.TotalGross",
                FieldTextFormat = "{0:C}",
                FontSize = 12,
                FieldKind =  FieldKind.Parameter,
                Text = "0",
                Left = 62.mm(),
                Width = 40.mm()
                };

            r.ReportFooterSection.Controls.Add (prtTotalTb);

            //---------------
            //Page footer
            //---------------
            var fl = new Line (){ Location = new Point(0,1), End = new Point(r.Width,1)};
            r.PageFooterSection.Controls.Add (fl);

            var pnTb = new TextBlock () {
                FieldName = "#PageNumber",
                FieldTextFormat = "{0:C}",
                FieldKind =  FieldKind.Expression,
                Text = "0",
                Left = (r.Width-30).mm(),
                Width = 10.mm(),
                HorizontalAlignment = HorizontalAlignment.Right,
                Top = 2.mm()};

            r.PageFooterSection.Controls.Add (pnTb);
            r.PageFooterSection.BackgroundColor = Color.LightBlue;

            #region example invoice datasource

            //example invoice class...
            Invoice invoice = new Invoice () {
                Number = "01/12/2010",
                CreationDate = DateTime.Now,
                Positions = new List<InvoicePosition>()
            };

            for (int i = 0; i < 82; i++) {
                invoice.Positions.Add (
                    new InvoicePosition ()
                    {
                        Index = i+1,
                        Quantity = 1,
                        Description = "Reporting services " + (i + 1).ToString(),
                        PricePerUnitGross = ((i * 50) / (i + 1)) + 1
                    }
                );
            }

            invoice.Positions [4].Description = "here comes longer position text to see if position will extend section height";

            invoice.Positions [11].Description = "another longer position text to see if position will extend section height";

            //Total gross ...
            invoice.TotalGross = invoice.Positions.Sum (p => p.PricePerUnitGross * p.Quantity);
            #endregion
            ObjectDataSource<InvoicePosition> objectDataSource = new ObjectDataSource<InvoicePosition>(invoice.Positions);
            objectDataSource.AddField ("Index",x=>x.Index);
            objectDataSource.AddField ("Description",x=>x.Description);
            objectDataSource.AddField ("Quantity",x=>x.Quantity);
            objectDataSource.AddField ("PricePerUnitGross",x=>x.PricePerUnitGross);

            r.DataSource = objectDataSource;

            //we can get cairo context before and after rendering each page
            //to draw custom shapes, texts (e.g watermarks etc)
            //here modified example from http://www.mono-project.com/Mono.Cairo
            r.OnAfterPageRender += delegate(ReportContext rc, Page p) {
                if (rc.CurrentPageIndex % 2 > 0) {
                    Cairo.Context gr = rc.RendererContext as Cairo.Context;
                    gr.MoveTo (50.mm (), 100.mm ());

                    gr.CurveTo (50.mm (), 50.mm (), 50.mm (), 50.mm (), 100.mm (), 50.mm ());
                    gr.CurveTo (100.mm (), 100.mm (), 100.mm (), 100.mm (), 50.mm (), 100.mm ());
                    gr.ClosePath ();

                    // Save the state to restore it later. That will NOT save the path
                    gr.Save ();
                    Cairo.Gradient pat = new Cairo.LinearGradient (50.mm (),100.mm (), 100.mm (),50.mm ());
                    pat.AddColorStop (0, new Cairo.Color (0,0,0,0.3));
                    pat.AddColorStop (1, new Cairo.Color (1,0,0,0.2));
                    gr.Pattern = pat;

                    // Fill the path with pattern
                    gr.FillPreserve ();

                    // We "undo" the pattern setting here
                    gr.Restore ();

                    // Color for the stroke
                    gr.Color = new Cairo.Color (0,0,0);

                    gr.LineWidth = 1.px ();
                    gr.Stroke ();
                }

            };
            var parameters = new Dictionary<string,object>{
                {"invoice.Number",invoice.Number},
                {"invoice.CreationDate",invoice.CreationDate},
                {"invoice.TotalGross",invoice.TotalGross},
            };

            r.ExportToPdf ("invoice.pdf", parameters);
            r.Save ("report.mrp");
        }
Example #14
0
 public override ControlViewBase CreateNewControl(SectionView sectionView)
 {
     var startPoint = sectionView.PointInSectionByAbsolutePoint (designService.StartPressPoint.X, designService.StartPressPoint.Y);
     var tb = new TextBlock { Location = new MonoReports.Model.Point (startPoint.X, startPoint.Y), Text=Catalog.GetString("text") };
     return AddControl(sectionView, tb);
 }