示例#1
0
文件: Gui.cs 项目: jonasoster/smul
    void Draw(Context cr, int width, int height)
    {
        cr.LineWidth = 1.0;
        cr.Color = new Color(1.0, 1.0, 1.0);
        cr.Rectangle(0, 0, width, height);
        cr.Fill();

        cr.Save();
        cr.Scale(scale_factor, scale_factor);
        try
        {
            if(diagram != null)
            {
                DiagramRenderer dr = new DiagramRenderer(cr, width, height, diagram);
                cr.Color = new Color(0.0, 0.0, 0.0);
                dr.Render();
                dr.Draw();
            }
        }
        catch
        {
            error_counter++;
        }
        cr.Restore();
    }
示例#2
0
    public static void Write(string fileName)
    {
        Diagram diagram = Program.Load(fileName);
        string pdfName = System.IO.Path.ChangeExtension(fileName, "pdf");

        if(diagram != null)
        {
            try
            {
                using(PdfSurface pdfs = new PdfSurface(pdfName, 595, 842))
                {
                    using(Context cr = new Context(pdfs))
                    {
                        DiagramRenderer dr = new DiagramRenderer(cr, 0, 0, diagram);

                        cr.LineWidth = 1.0;
                        cr.Color = new Color(0.0, 0.0, 0.0);
                        dr.Render();
                        pdfs.SetSize(dr.width, dr.height);
                        dr.Draw();

                        cr.ShowPage();
                    }
                }

                Console.WriteLine("Wrote {0}", pdfName);
            }
            catch
            {
                Console.WriteLine("Error writing {0}", pdfName);
            }
        }
    }
示例#3
0
    public static void Write(string fileName)
    {
        Diagram diagram = Program.Load(fileName);
        string psName = System.IO.Path.ChangeExtension(fileName, "ps");

        if(diagram != null)
        {
            try
            {
                // It seems the page size cannot be made smaller
                // using SetSize(), only larger. Start with a
                // small surface and enlarge it after layout.
                using(PSSurface pss = new PSSurface(psName, 10, 10))
                {
                    using(Context cr = new Context(pss))
                    {
                        DiagramRenderer dr = new DiagramRenderer(cr, 0, 0, diagram);

                        cr.LineWidth = 1.0;
                        cr.Color = new Color(0.0, 0.0, 0.0);
                        dr.Render();
                        pss.SetSize(dr.width, dr.height);
                        dr.Draw();

                        cr.ShowPage();
                    }
                }

                Console.WriteLine("Wrote {0}", psName);
            }
            catch
            {
                Console.WriteLine("Error writing {0}", psName);
            }
        }
    }