[Gnome-print] Re: class method checks ..



On Thu, 27 Apr 2000, Michael Meeks wrote:

> > Are there any reason, gnome-print-xxx methods do not test the presence
> > of applicable method, i.e.
> >
> > if (GNOME_PRINT_CONTEXT_CLASS (((GtkObject *) pc)->klass)->xxx)
> >       GNOME_PRINT_CONTEXT_CLASS (((GtkObject *) pc)->klass)->xxx)(args)
> 
>         Since the PRINT_CONTEXT_CLASS does an expensive type
> check it would be preferably to bloat the code to:
> 
>         GnomePrintContextClass *klass = GNOME_PRINT_CONTEXT_CLASS
>                                             ((GTK_OBJECT (pc))->klass);
>         if (klass->xxx)
>                 klass->xxx (args);
>         else
>                 g_warning ("Mega serious error in context '%s'",
>                            gtk_type_name (klass->parent_class.type));

In production code it probably does not make any difference:
- gtk checks will be disabled
- compiler optimizes multiple indirections
Most important is to implement consistent syntax thorougly (nicer code :))

> > I can imagine context not implementing many methods (plotters and
> cutters
> > for example), and it seems unnecessary to fill such classes with empty
> > functions simply to avoid segfaults.
> 
>         I'm really not convinced that it is a good idea to allow NULL
> pointers in the context's class data.

It depends how much and how complicated printing methods will be
implemented in future. And how much GnomePrintContext there will be. If
MOST printers remain to be handled via GS, then probably there will not be
many. But still one nice possibility would be to use print contexts for
exporting vector file formats.
If GnomePrintContext will implement only the bare minimum of methods, then
it is advisable not to allow NULL pointers. Otherwise we overpopulate all
derived contexts with empty methods.
I would divide class methods into mandatory and facultative ones:
Mandatory:
newpath, moveto, lineto, curveto, closepath, setrgbcolor, setlinewidth,
setdash, stroke, strokepath, concat, setmatix, gsave, grestore, setfont,
show, showpage
Facultative:
- fill, eofill (not present in cutters, plotters)
- setmiterlimit, setlinejoin, setlinecap (hard to emulate sometimes)
- clip, eoclip - maybe mandatory, as any path can be clipped
- grayimage (can be emulated with rgbimage, rgbaimage)
- rgbimage (can be emulated with grayimage, rgbaimage)
- textline (can be emulated)
- beginpage (meaningless in many contexts)
- setopacity
- rgbaimage (is already emulated with rgbimage, can be also with
  grayimage)
Forcing all context to implement these methods will result much
duplication in emulation code.

The other, maybe more interesting approach would be to create emulation
context, which takes care about its derivatives. It should then implement
also Graphic Context handling, so derived context could do without gsave,
grestore, clip, eoclip, strokepath, maybe also without setfont and show

Regards,
Lauris






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]