My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
MonoReporter - Report tool for Mono
Copyright (C) 2006,2007 Milton Pividori

This file is part of MonoReporter.

MonoReporter is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

MonoReporter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using Gtk;
using Gdk;
using Pango;
using Cairo;

namespace MonoReporter
{
public class Page
{
private const double HEADER_HEIGHT = (10*72/25.4);
PrintOperation printOperation;

public Page()
{
// All this is only a test.

Console.WriteLine("uno");
this.printOperation = new PrintOperation();

printOperation.NPages = 1;
printOperation.Unit = Unit.Mm;
printOperation.JobName = "PruebaConCairo";

// PrintSettings settings = new PrintSettings();
// settings.UseColor = true;
// printOperation.PrintSettings = settings;

Console.WriteLine("dos");
// printOperation.BeginPrint += this.BeginPrint;
printOperation.DrawPage += this.DrawPage;
printOperation.EndPrint += this.EndPrint;
}

// public void BeginPrint(object o, BeginPrintArgs args)
// {
// Console.WriteLine("BeginPrint");
// }

public void DrawPage(object o, DrawPageArgs args)
{
Console.WriteLine("DrawPage");

Pango.Layout layout;
int textWidth, textHeight;
double width;
FontDescription desc;

Cairo.Context con = args.Context.CairoContext;
width = args.Context.Width;

// Rectangle
con.Rectangle(0, 0, width, HEADER_HEIGHT);
con.Color = new Cairo.Color(1, 0.2, 0.2, 0.6);
con.FillPreserve();

// Draw another thing
con.Color = new Cairo.Color(0, 0, 0);
con.LineWidth = 1;
con.Stroke();

con.Color = new Cairo.Color(0, 0, 0);
con.MoveTo(20, 200);
con.CurveTo(40, 270, 120, 165, 70, 60);
con.Stroke();

con.MoveTo(30, 100);
con.LineTo(60, 80);
con.Stroke();

con.Color = new Cairo.Color(0, 0, 0);
layout = args.Context.CreatePangoLayout();
layout.SetText("Prueba con Pango");
desc = FontDescription.FromString("arial 14");
layout.FontDescription = desc;

layout.GetPixelSize(out textWidth, out textHeight);

if (textWidth > width) {
layout.Width = (int)width;
layout.Ellipsize = EllipsizeMode.Start;
layout.GetPixelSize(out textWidth, out textHeight);
}

con.MoveTo((width - textWidth)/2, (HEADER_HEIGHT - textHeight)/2);
Pango.CairoHelper.ShowLayout(con, layout);
}

public void EndPrint(object o, EndPrintArgs args)
{
Console.WriteLine("EndPrint");
}

public void Dispose()
{
printOperation.Dispose();
}

public void Run(Gtk.Window win)
{
Console.WriteLine("tres");
printOperation.Run(PrintOperationAction.PrintDialog, win);

// if (res == PrintOperationResult.Apply) {
// Console.WriteLine("Se apretó Apply");
// }
// else
// Console.WriteLine("ajajajajaj");
}
}
}
Show details Hide details

Change log

r73 by miltondp on Sep 30, 2007   Diff
Now it reads the stroke-width attribute
correctly from rectangles
Go to: 
Project members, sign in to write a code review

Older revisions

r68 by miltondp on Sep 20, 2007   Diff
- Tests with Cairo, GtkPrint, Rsvg and
images.

r67 by miltondp on Sep 18, 2007   Diff
- Minor changes.

r66 by miltondp on Sep 15, 2007   Diff
Minor changes.
All revisions of this file

File info

Size: 3365 bytes, 131 lines
Hosted by Google Code