Inheritance: IReportRenderer
 public static void ExportToPdf(this Report report ,string path)
 {
     using (PdfSurface pdfSurface = new PdfSurface (
         path,report.WidthWithMargins,report.HeightWithMargins)) {
         Cairo.Context cr = new Cairo.Context (pdfSurface);
         cr.Translate(report.Margin.Left,report.Margin.Top);
         ReportRenderer renderer = new ReportRenderer (){ Context = cr};
         renderer.RegisterRenderer (typeof(TextBlock), new TextBlockRenderer ());
         renderer.RegisterRenderer (typeof(Line), new LineRenderer ());
         renderer.RegisterRenderer (typeof(Image), new ImageRenderer (){ PixbufRepository = new PixbufRepository(report.ResourceRepository)});
         SectionRenderer sr = new SectionRenderer();
         renderer.RegisterRenderer(typeof(ReportHeaderSection), sr);
         renderer.RegisterRenderer(typeof(ReportFooterSection), sr);
         renderer.RegisterRenderer(typeof(DetailSection), sr);
         renderer.RegisterRenderer(typeof(PageHeaderSection), sr);
         renderer.RegisterRenderer(typeof(PageFooterSection), sr);
         MonoReports.Model.Engine.ReportEngine engine = new MonoReports.Model.Engine.ReportEngine (report,renderer);
         engine.Process ();
         for (int i = 0; i < report.Pages.Count; ++i) {
             renderer.RenderPage (report.Pages [i]);
             cr.ShowPage ();
         }
         pdfSurface.Finish ();
         (cr as IDisposable).Dispose ();
     }
 }
 public DesignService(IWorkspaceService workspaceService,ReportRenderer renderer,PixbufRepository pixbufRepository,CompilerService compilerService, Report report)
 {
     this.PixbufRepository = pixbufRepository;
     this.WorkspaceService = workspaceService;
     this.Compiler = compilerService;
     this.renderer = renderer;
     controlViewFactory = new ControlViewFactory (renderer);
     IsDesign = true;
     Report = report;
     Zoom = 1;
     Render = true;
     IsDirty = true;
 }
        public ControlViewFactory(ReportRenderer reportRenderer)
        {
            this.reportRenderer = reportRenderer;
            controlViewDictionary = new Dictionary<System.Type, Func<MonoReports.Model.Controls.Control,SectionView,ControlViewBase> >();

            controlViewDictionary
                .Add(
                     typeof(TextBlock),
                     	(ctrl, section) => {
                             	var renderer = reportRenderer.RenderersDictionary[typeof(TextBlock)] as TextBlockRenderer;
                                return new TextBlockView(ctrl as TextBlock,renderer,section);
                        }
                );

            controlViewDictionary
                .Add(
                     typeof(Line),
                     	(ctrl, section) => {
                                var renderer = reportRenderer.RenderersDictionary[typeof(Line)] as LineRenderer;
                                return new LineView(ctrl as Line,renderer,section);
                        }
                );

            controlViewDictionary
                .Add(
                     typeof(Image),
                     	(ctrl, section) => {
                                var renderer = reportRenderer.RenderersDictionary[typeof(Image)] as ImageRenderer;
                                var image = ctrl as Image;
                                return new ImageView(image,renderer,section);
                        }
                );

            controlViewDictionary
                .Add(
                     typeof(SubReport),
                     	(ctrl, section) => {
                                var renderer = reportRenderer.RenderersDictionary[typeof(Image)] as SubreportRenderer;
                                var subreport = ctrl as SubReport;
                                return new SubreportView(subreport,renderer,section);
                        }
                );
        }
        public MonoreportsDesignerControl()
        {
            Build ();
              		MonoReports.Model.Engine.ReportEngine.EvaluatorInit();

            Report startReport = newReportTemplate();

            double resolutionX = ((double)  Gdk.Screen.Default.Width) / ((double) Gdk.Screen.Default.WidthMm) * 25.4;

            compilerService = new CompilerService(ReportExtensions.ScriptTemplateForDataSourceEvaluation);

            pixbufRepository = new PixbufRepository () { Report = startReport };
            workspaceService = new WorkspaceService (this,maindesignview1.DesignDrawingArea,maindesignview1.PreviewDrawingArea,mainPropertygrid, StatusBarLabel);
            var reportRenderer = new ReportRenderer(){ ResolutionX =  resolutionX};
            reportRenderer.RegisterRenderer(typeof(Controls.TextBlock), new TextBlockRenderer());
            reportRenderer.RegisterRenderer(typeof(Controls.Line), new LineRenderer());
            reportRenderer.RegisterRenderer(typeof(MonoReports.Model.Controls.Image),
                new ImageRenderer(){ PixbufRepository = pixbufRepository});
            SectionRenderer sr = new SectionRenderer();
            reportRenderer.RegisterRenderer(typeof(Controls.ReportHeaderSection), sr);
            reportRenderer.RegisterRenderer(typeof(Controls.ReportFooterSection), sr);
            reportRenderer.RegisterRenderer(typeof(Controls.DetailSection), sr);
            reportRenderer.RegisterRenderer(typeof(Controls.PageHeaderSection), sr);
            reportRenderer.RegisterRenderer(typeof(Controls.PageFooterSection), sr);
            designService = new DesignService (workspaceService,reportRenderer,pixbufRepository,compilerService, startReport);

            toolBoxService = new ToolBoxService ();
            designService.ToolBoxService = toolBoxService;
            maindesignview1.DesignService = designService;
            maindesignview1.WorkSpaceService = workspaceService;
            maindesignview1.ReportRenderer = reportRenderer;
            workspaceService.InvalidateDesignArea ();
            reportExplorer.DesignService = designService;
            reportExplorer.Workspace = workspaceService;
            toolBoxService.AddTool (new ZoomTool (designService));
            toolBoxService.AddTool (new LineTool (designService));
            toolBoxService.AddTool (new LineToolV (designService));
            toolBoxService.AddTool (new LineToolH (designService));
            toolBoxService.AddTool (new TextBlockTool (designService));
            //TODO 3tk: currently not supported
            //toolBoxService.AddTool (new SubreportTool (designService));
            toolBoxService.AddTool (new SectionTool (designService));
            toolBoxService.AddTool (new ImageTool (designService));
            toolBoxService.AddTool (new RectTool (designService));
            toolBoxService.BuildToolBar (mainToolbar);

            ToolBarButton exportPdfToolButton = new ToolBarButton ("pdf.png","exportPdf",Catalog.GetString("Export to pdf"));
            exportPdfToolButton.Clicked += delegate(object sender, EventArgs e) {
            designService.ExportToPdf();
            };

            var sep = new Gtk.SeparatorToolItem();

            mainToolbar.Insert (sep,mainToolbar.NItems);
            mainToolbar.Insert (exportPdfToolButton,mainToolbar.NItems);

            //ToolBarButton btn = new ToolBarButton("gtk-media-play","execute","Execute report");
            //mainToolbar.Insert (btn,mainToolbar.NItems);

            mainPropertygrid.LoadMonoreportsExtensions();
             		designService.Report = startReport;
        }
        public MainDesignView()
        {
            this.Build ();
            buildPreviewToolbar ();
            reportRenderer = new ReportRenderer();
            Gtk.Drag.DestSet (DesignDrawingArea, DestDefaults.All, new TargetEntry[]{new TargetEntry ("Field", TargetFlags.OtherWidget,2)}, DragAction.Copy);
            codeTextview.Buffer.Changed += HandleCodeTextviewBufferChanged;

            DesignDrawingArea.DragDrop += delegate(object o, DragDropArgs args) {
                    var source = Gtk.Drag.GetSourceWidget (args.Context);
                        if (source.GetType () == typeof(TreeView)){
                        TreeIter item;
                        TreeView treeView = ((TreeView)source) as TreeView;
                        treeView.Selection.GetSelected (out item);
                        var model = treeView.Model as Gtk.TreeStore;
                        var wrapper = model.GetValue (item, 0) as TreeItemWrapper;
                        Gtk.Drag.Finish (args.Context, true, false, 0);

                        if(wrapper.Object is Field) {
                            Field f = wrapper.Object as Field;
                            designService.CreateTextBlockAtXY (f.Name,f.Name, f.FieldKind,args.X, args.Y);
                        } else if(wrapper.Object is KeyValuePair<string,byte[]>) {
                            var kvp = (KeyValuePair<string,byte[]>)wrapper.Object;
                            designService.CreateImageAtXY(kvp.Key, args.X, args.Y);
                        }
                    }
            };

            previewDrawingArea.ModifyBg(Gtk.StateType.Normal,base.Style.Background (StateType.Insensitive));
            DesignDrawingArea.ModifyBg(Gtk.StateType.Normal,base.Style.Background (StateType.Insensitive));
            GuiStream error_stream = new GuiStream ("Error", (x, y) => Output (x, y));
            StreamWriter gui_output = new StreamWriter (error_stream);
            gui_output.AutoFlush = true;
            Console.SetError (gui_output);

            GuiStream stdout_stream = new GuiStream ("Stdout", (x, y) => Output (x, y));
            gui_output = new StreamWriter (stdout_stream);
            gui_output.AutoFlush = true;
            Console.SetOut (gui_output);
        }
        public MonoreportsDesignerControl()
        {
            Build ();
            dpi =   Gdk.Screen.Default.Resolution;

            Report startReport = new Report(){
            DataScript = @"
            datasource = new [] {
             new { Name=""Alfred"", Surname = ""Tarski"", Age = ""82"" },
             new { Name=""Saul"", Surname = ""Kripke"", Age = ""70"" },
             new { Name=""Gotlob"", Surname = ""Frege"", Age = ""85"" },
             new { Name=""Kurt"", Surname = ""Gödel"", Age = ""72"" },
            };

            parameters.Add(""Title"",new { Title = ""The Logicans"", SubTitle = ""...and philosophers...""});

            "};

            string template = @"
            using System;
            using System.Collections.Generic;
            {0}

            public sealed class GenerateDataSource {{
            public object Generate()
            {{
            object datasource = null;
            Dictionary<string,object> parameters = new Dictionary<string,object>();
             {1}
            return new object[] {{datasource,parameters}};
            }}
            }}

            ";

            compilerService = new CompilerService(template);
            workspaceService = new WorkspaceService (this,maindesignview1.DesignDrawingArea,maindesignview1.PreviewDrawingArea,mainPropertygrid, StatusBarLabel);

            designService = new DesignService (workspaceService,compilerService,startReport);
            toolBoxService = new ToolBoxService ();
            designService.ToolBoxService = toolBoxService;
            maindesignview1.DesignService = designService;
            maindesignview1.WorkSpaceService = workspaceService;
            maindesignview1.Compiler = compilerService;

            var reportRenderer = new ReportRenderer();
            reportRenderer.RegisterRenderer(typeof(Controls.TextBlock), new TextBlockRenderer(){ DPI = dpi});
            reportRenderer.RegisterRenderer(typeof(Controls.Line), new LineRenderer(){ DPI = dpi});
            reportRenderer.RegisterRenderer(typeof(MonoReports.Model.Controls.Image), new ImageRenderer(){ PixbufRepository = designService.PixbufRepository, DPI = dpi});
            SectionRenderer sr = new SectionRenderer() { DPI = dpi};
            reportRenderer.RegisterRenderer(typeof(Controls.ReportHeaderSection), sr);
            reportRenderer.RegisterRenderer(typeof(Controls.ReportFooterSection), sr);
            reportRenderer.RegisterRenderer(typeof(Controls.DetailSection), sr);
            reportRenderer.RegisterRenderer(typeof(Controls.PageHeaderSection), sr);
            reportRenderer.RegisterRenderer(typeof(Controls.PageFooterSection), sr);

            maindesignview1.ReportRenderer = reportRenderer;
            workspaceService.InvalidateDesignArea ();
            reportExplorer.DesignService = designService;
            reportExplorer.Workspace = workspaceService;
            toolBoxService.AddTool (new ZoomTool (designService));
            toolBoxService.AddTool (new LineTool (designService));
            toolBoxService.AddTool (new LineToolV (designService));
            toolBoxService.AddTool (new LineToolH (designService));

            toolBoxService.AddTool (new TextBlockTool (designService));
            toolBoxService.AddTool (new SubreportTool (designService));
            toolBoxService.AddTool (new SectionTool (designService));
            toolBoxService.AddTool (new ImageTool (designService));
            toolBoxService.AddTool (new RectTool (designService));
            toolBoxService.BuildToolBar (mainToolbar);

            ToolBarButton exportPdfToolButton = new ToolBarButton ("pdf.png","exportPdf","export to pdf");
            exportPdfToolButton.Clicked += delegate(object sender, EventArgs e) {
            designService.ExportToPdf();
            };

            mainToolbar.Insert (exportPdfToolButton,7);

            mainPropertygrid.LoadMonoreportsExtensions();
        }
        public static void ExportToPdf(this Report report ,string path)
        {
            report.EvalDataSource();
            double unitMultiplier = CairoExtensions.UnitMultiplier;
            double realFontMultiplier = CairoExtensions.RealFontMultiplier;
            ReportRenderer renderer = new ReportRenderer ();
            renderer.ResolutionX = 72;

            using (PdfSurface pdfSurface = new PdfSurface (
                path,report.WidthWithMargins * renderer.UnitMultipilier,
                report.HeightWithMargins * renderer.UnitMultipilier)) {

                Cairo.Context cr = new Cairo.Context (pdfSurface);
                cr.Antialias = Antialias.None;
                renderer.Context = cr;
                renderer.RegisterRenderer (typeof(TextBlock), new TextBlockRenderer ());
                renderer.RegisterRenderer (typeof(Line), new LineRenderer ());
                PixbufRepository pbr = new PixbufRepository();
                pbr.Report = report;

                renderer.RegisterRenderer (typeof(Image), new ImageRenderer (){PixbufRepository = pbr});
                SectionRenderer sr = new SectionRenderer();
                renderer.RegisterRenderer(typeof(ReportHeaderSection), sr);
                renderer.RegisterRenderer(typeof(ReportFooterSection), sr);
                renderer.RegisterRenderer(typeof(DetailSection), sr);
                renderer.RegisterRenderer(typeof(PageHeaderSection), sr);
                renderer.RegisterRenderer(typeof(PageFooterSection), sr);

                MonoReports.Model.Engine.ReportEngine engine = new MonoReports.Model.Engine.ReportEngine (report,renderer);
                engine.Process ();

                Cairo.Context cr1 = new Cairo.Context (pdfSurface);
                renderer.Context = cr1;
                cr1.Translate(report.Margin.Left * renderer.UnitMultipilier,report.Margin.Top * renderer.UnitMultipilier);
                engine.RenderPages(renderer,report);
                pdfSurface.Finish ();
                (cr as IDisposable).Dispose ();
                (cr1 as IDisposable).Dispose ();
            }

            CairoExtensions.UnitMultiplier = unitMultiplier;
            CairoExtensions.RealFontMultiplier = realFontMultiplier;
        }