Here is an update for the DemoPrinting. I have wrapped Pango.Cairo (some of it) and made a patch for it.
1. unpack pangocairo.tar.gz in base gtk-sharp.
2. Copy DemoPrinting.cs to samples/GtkDemo
3. Patch it with PangoCairoPrinting.patch
4. run bootstrap-2.10
There is no more manually wrapping in DemoPrinting.
Could someone take a look at it and see if it can go into svn or if it needs more work and give me some feedback !!
Bye
Med Venlig Hilsen
|
/* Printing * * GtkPrintOperation offers a simple API to support printing in a cross-platform way. */
using System;
using System.IO;
using System.Reflection;
using Gtk;
using Cairo;
namespace GtkDemo
{
[Demo ("Printing", "DemoPrinting.cs")]
public class DemoPrinting
{
private static double headerHeight = (10*72/25.4);
private static double headerGap = (3*72/25.4);
private static int pangoScale = 1024;
private PrintOperation print;
private string fileName = "DemoPrinting.cs";
private double fontSize = 12.0;
private int linesPerPage;
private string[] lines;
private int numLines;
private int numPages;
public DemoPrinting ()
{
print = new PrintOperation ();
print.BeginPrint += OnBeginPrint;
print.DrawPage += OnDrawPage;
print.EndPrint += OnEndPrint;
print.Run (PrintOperationAction.PrintDialog, null);
}
private void OnBeginPrint (object obj, Gtk.BeginPrintArgs args)
{
string contents;
double height;
PrintContext context = args.Context;
height = context.Height;
linesPerPage = (int)Math.Floor(height / fontSize);
contents = LoadFile("DemoPrinting.cs");
lines = contents.Split('\n');
numLines = lines.Length;
numPages = (numLines - 1) / linesPerPage + 1;
print.NPages = numPages;
}
private string LoadFile (string filename)
{
Stream file = Assembly.GetExecutingAssembly ().GetManifestResourceStream
(filename);
if (file == null && File.Exists (filename)) {
file = File.OpenRead (filename);
}
if (file == null) {
return "File not found";
}
StreamReader sr = new StreamReader (file);
return sr.ReadToEnd ();
}
private void OnDrawPage (object obj, Gtk.DrawPageArgs args)
{
PrintContext context = args.Context;
Cairo.Context cr = context.CairoContext;
double width = context.Width;
cr.Rectangle (0, 0, width, headerHeight);
cr.SetSourceRGB (0.8, 0.8, 0.8);
cr.FillPreserve ();
cr.SetSourceRGB (0, 0, 0);
cr.LineWidth = 1;
cr.Stroke();
Pango.Layout layout = context.CreatePangoLayout ();
Pango.FontDescription desc = Pango.FontDescription.FromString ("sans 14");
layout.FontDescription = desc;
layout.SetText (fileName);
layout.Width = (int)width;
layout.Alignment = Pango.Alignment.Center;
int layoutWidth, layoutHeight;
layout.GetSize (out layoutWidth, out layoutHeight);
double textHeight = (double)layoutHeight / (double)pangoScale;
cr.MoveTo (width/2, (headerHeight - textHeight) / 2);
Pango.Cairo.ShowLayout (cr, layout);
string pageStr = String.Format ("{0}/{1}", args.PageNr + 1, numPages);
layout.SetText (pageStr);
layout.Alignment = Pango.Alignment.Right;
cr.MoveTo (width - 2, (headerHeight - textHeight) / 2);
Pango.Cairo.ShowLayout (cr, layout);
layout = null;
layout = context.CreatePangoLayout ();
desc = Pango.FontDescription.FromString ("mono");
desc.Size = (int)(fontSize * pangoScale);
layout.FontDescription = desc;
cr.MoveTo (0, headerHeight + headerGap);
int line = args.PageNr * linesPerPage;
for (int i=0; i < linesPerPage && line < numLines; i++)
{
layout.SetText (lines[line]);
Pango.Cairo.ShowLayout (cr, layout);
cr.RelMoveTo (0, fontSize);
line++;
}
layout = null;
}
private void OnEndPrint (object obj, Gtk.EndPrintArgs args)
{
}
}
}
pangocairo.tar.gz
Description: application/compressed-tar
Index: sample/GtkDemo/Makefile.am
===================================================================
--- sample/GtkDemo/Makefile.am (revision 63504)
+++ sample/GtkDemo/Makefile.am (working copy)
@@ -1,5 +1,5 @@
-assemblies = ../../glib/glib-sharp.dll ../../pango/pango-sharp.dll ../../atk/atk-sharp.dll ../../gdk/gdk-sharp.dll ../../gtk/gtk-sharp.dll
-references = $(addprefix /r:, $(assemblies))
+assemblies = ../../glib/glib-sharp.dll ../../pango/pango-sharp.dll ../../pangocairo/pangocairo-sharp.dll ../../atk/atk-sharp.dll ../../gdk/gdk-sharp.dll ../../gtk/gtk-sharp.dll
+references = $(addprefix /r:, $(assemblies)) -r:Mono.Cairo
TARGETS = GtkDemo.exe
DEBUGS = $(addsuffix .mdb, $(TARGETS))
CLEANFILES = $(TARGETS) $(DEBUGS)
@@ -31,7 +31,8 @@
DemoStockBrowser.cs \
DemoTextView.cs \
DemoTreeStore.cs \
- DemoUIManager.cs
+ DemoUIManager.cs \
+ DemoPrinting.cs
images = \
images/gnome-foot.png,gnome-foot.png \
Index: sources/gtk-sharp-2.10-sources.xml
===================================================================
--- sources/gtk-sharp-2.10-sources.xml (revision 63504)
+++ sources/gtk-sharp-2.10-sources.xml (working copy)
@@ -44,6 +44,26 @@
</namespace>
</library>
</api>
+ <api filename="../pangocairo/pangocairo-api-2.10.raw">
+ <library name="libpangocairo-1.0-0.dll">
+ <namespace name="Pango">
+ <file>pango-1.12.3/pango/pangocairo.h</file>
+ <file>pango-1.12.3/pango/pangocairo-atsuifont.h</file>
+ <file>pango-1.12.3/pango/pangocairo-atsuifont.c</file>
+ <file>pango-1.12.3/pango/pangocairo-atsuifontmap.c</file>
+ <file>pango-1.12.3/pango/pangocairo-atsui.h</file>
+ <file>pango-1.12.3/pango/pangocairo-fcfont.c</file>
+ <file>pango-1.12.3/pango/pangocairo-fcfontmap.c</file>
+ <file>pango-1.12.3/pango/pangocairo-font.c</file>
+ <file>pango-1.12.3/pango/pangocairo-fontmap.c</file>
+ <file>pango-1.12.3/pango/pangocairo-private.h</file>
+ <file>pango-1.12.3/pango/pangocairo-render.c</file>
+ <file>pango-1.12.3/pango/pangocairo-win32font.c</file>
+ <file>pango-1.12.3/pango/pangocairo-win32fontmap.c</file>
+ <file>pango-1.12.3/pango/pangocairo-win32.h</file>
+ </namespace>
+ </library>
+ </api>
<api filename="../gdk/gdk-api-2.10.raw">
<library name="libgdk-win32-2.0-0.dll">
<namespace name="Gdk">
Index: gtk/gtk-sharp-2.0.pc.in
===================================================================
--- gtk/gtk-sharp-2.0.pc.in (revision 63504)
+++ gtk/gtk-sharp-2.0.pc.in (working copy)
@@ -7,6 +7,6 @@
Name: Gtk#
Description: Gtk# - GNOME .NET Binding
Version: @VERSION@
-Cflags: -I:${gapidir}/pango-api.xml -I:${gapidir}/atk-api.xml -I:${gapidir}/gdk-api.xml -I:${gapidir}/gtk-api.xml
-Libs: -r:${libdir}/mono/@PACKAGE_VERSION@/pango-sharp.dll -r:${libdir}/mono/@PACKAGE_VERSION@/atk-sharp.dll -r:${libdir}/mono/@PACKAGE_VERSION@/gdk-sharp.dll -r:${libdir}/mono/@PACKAGE_VERSION@/gtk-sharp.dll
+Cflags: -I:${gapidir}/pango-api.xml -I:${gapidir}/pangocairo-api.xml -I:${gapidir}/atk-api.xml -I:${gapidir}/gdk-api.xml -I:${gapidir}/gtk-api.xml
+Libs: -r:${libdir}/mono/@PACKAGE_VERSION@/pango-sharp.dll -r:${libdir}/mono/@PACKAGE_VERSION@/pangocairo-sharp.dll -r:${libdir}/mono/@PACKAGE_VERSION@/atk-sharp.dll -r:${libdir}/mono/@PACKAGE_VERSION@/gdk-sharp.dll -r:${libdir}/mono/@PACKAGE_VERSION@/gtk-sharp.dll
Requires: glib-sharp-2.0
Index: makefile.win32
===================================================================
--- makefile.win32 (revision 63504)
+++ makefile.win32 (working copy)
@@ -1,4 +1,4 @@
-DIRS=generator parser glib pango atk gdk gtk glade gtkdotnet
+DIRS=generator parser glib pango pangocairo atk gdk gtk glade gtkdotnet
ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT)))
#pesky spaces - blame zbowling if this fails
PROGFILES=`cygpath \`cygpath -m -s "$(PROGRAMFILES)"\``
Index: bootstrap-generic
===================================================================
--- bootstrap-generic (revision 63504)
+++ bootstrap-generic (working copy)
@@ -22,6 +22,7 @@
-e "s/@ASSEMBLY_VERSION@/$ASSEMBLY_VERSION/" $srcdir/configure.in.in > $srcdir/configure.in
ln -f $srcdir/pango/pango-api-$GTK_API_TAG.raw $srcdir/pango/pango-api.raw
+ln -f $srcdir/pangocairo/pangocairo-api-$GTK_API_TAG.raw $srcdir/pangocairo/pangocairo-api.raw
ln -f $srcdir/atk/atk-api-$GTK_API_TAG.raw $srcdir/atk/atk-api.raw
ln -f $srcdir/gdk/gdk-api-$GTK_API_TAG.raw $srcdir/gdk/gdk-api.raw
ln -f $srcdir/gtk/gtk-api-$GTK_API_TAG.raw $srcdir/gtk/gtk-api.raw
Index: configure.in.in
===================================================================
--- configure.in.in (revision 63504)
+++ configure.in.in (working copy)
@@ -215,6 +215,8 @@
pango/Makefile
pango/pango-sharp.dll.config
pango/glue/Makefile
+pangocairo/Makefile
+pangocairo/pangocairo-sharp.dll.config
atk/Makefile
atk/atk-sharp.dll.config
gdk/Makefile
Index: Makefile.am
===================================================================
--- Makefile.am (revision 63504)
+++ Makefile.am (working copy)
@@ -1,4 +1,4 @@
-SUBDIRS = sources generator parser glib pango atk gdk gtk glade gtkdotnet sample doc
+SUBDIRS = sources generator parser glib pango pangocairo atk gdk gtk glade gtkdotnet sample doc
EXTRA_DIST = \
gtk-sharp.snk \
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Gtk-sharp-list maillist - [email protected] http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
