A Django site.
April 17, 2008

John Anderson
sontek
sontek ( John M. Anderson )
» Printing in GTK#

I just finished porting Tomboy’s print code to GTK so that we would be more portable and I thought other Mono apps looking to move from libgnomeprint or wanting to add printing support might find a code example helpful.

First, To start printing you do something like:

private void PrintButtonClicked (object sender, EventArgs args)
{
Gtk.PrintOperation op = new PrintOperation ();
op.BeginPrint += new BeginPrintHandler (OnBeginPrint);
op.DrawPage += new DrawPageHandler(OnDrawPage);

op.Run (Gtk.PrintOperationAction.PrintDialog, this.Window);
}

after the PrintOperation is set off you need to handle the BeginPrint event. The main things that need to be done are finding out how many lines will fit on a page and how many lines you have:

public void OnBeginPrint(object sender, Gtk.BeginPrintArgs args)
{
PrintOperation op = (PrintOperation)sender;
lines_per_page = (int)Math.Floor ((double)args.Context.Height / (double)font_size);
Gtk.TextIter start_iter, end_iter;
this.Buffer.GetBounds (out start_iter, out end_iter);
lines = this.Buffer.GetText (start_iter, end_iter, false).Split ('\n');
op.NPages = (int)Math.Ceiling ((double)lines.Length / (double)lines_per_page);
}

Finally, now that you have the printing setup, you need to actually render the data to be printed:

public void OnDrawPage(object sender, Gtk.DrawPageArgs args)
{
PrintOperation op = (PrintOperation)sender;
Cairo.Context cr = args.Context.CairoContext;

int line = args.PageNr * lines_per_page;
int num_lines = 0;
if (args.PageNr+1 != op.NPages)
num_lines = line + lines_per_page;
else
num_lines = lines.Length;

cr.MoveTo (0, 0);

for (int i = 0; i < lines_per_page && line < num_lines; i++)
{
Pango.Layout layout = args.Context.CreatePangoLayout ();
Pango.FontDescription desc = Pango.FontDescription.FromString (”sans ” + font_size);
desc.Size = (int)(font_size * Pango.Scale.PangoScale);
layout.FontDescription = desc;

layout.SetText (lines[line]);
Pango.CairoHelper.ShowLayout (cr, layout);
cr.RelMoveTo (0, font_size);
line++;
}
}

This does not take into account styles but will give you the basic idea of what needs to be done.

March 5, 2008

Dennis Muhlestein
nonic
All My Brain
» Gentoo with an Intel DQ35MP Motherboard

I'm slightly sad to see my old radeon 9600 card with Compiz being obsoleted. My motherboard in that machine shorted out somewhere and I was left with a bricked machine. Since the product was essentially about 5 years old, I decided to go ahead and buy new equipment. I'm now the proud owner [...]

November 27, 2007

Dennis Muhlestein
nonic
All My Brain
» Gentoo and the Next ATI Drivers (Catalyist 7.11)

As of a couple days ago, ATI released their next drivers for Linux. The drivers were previously announced to be versioned 8.43.x but ATI has converted to a new numbering system that follows the popular YEAR.MONTH notation. The 7.11 drivers therefore accurately represent their release date in November, 2007 and are what would [...]

November 2, 2007

Dennis Muhlestein
nonic
All My Brain
» Upgrading to Xorg-X11 7.3 with ati-drivers 8.42.3 on Gentoo

I’m a sucker for bleeding edge technology. After posting before about upgrading to the 8.42.3 ati drivers, I realized I was using Xorg-X11 7.2, not 7.3, which is the latest. The latest 7.3 ebuild contains a block on the ati drivers. The block is no longer necessary though because the 8.42.3 drivers [...]

November 20, 2007

Dennis Muhlestein
nonic
All My Brain
» AIGLX, Compiz-Fusion, Gentoo, and my ATI Radeon 9600 Card with 8.42.3

Update: As of the last couple days (11/18/07), an ebuild has been added to portage for these drivers. It’s no longer necessary to create your own. So the Long Anticipated ATI drivers that support AIGLX are released. I’ve been wishing for this long before anyone ever mentioned it was a possibility. I’ve [...]

October 12, 2007

John Anderson
sontek
sontek ( John M. Anderson )
» Horizontal Scroll Bug in Firefox

An annoying bug in Firefox is that it detects the horizontal scroll sent by synaptic as the back/forward actions rather than scrolling. To fix this you need to go into firefox and type about:config in the location bar.  And then filter for mousewheel.horizscroll.withnokey.

You need to set the action to be 1 (2 is forward/back) and  set sysnumlines to true.

so it should look like:

mousehweel.horizscroll.withnokey.action = 1
mousewheel.horizscroll.withnokey.sysnumlines = true

and then you will be able scroll properly!

You can also disable the scroll completely if you don’t want it at all by adding Option “HorizScrollDelta” “0″ to the input section of xorg.conf