Hi,

I've translated some C header files to be able to use pangocairo in
my application. Preliminary patch that adds these bindings (and some
missing things in pango and glib) is attached. Please review it (
comments requested :) ).

My questions:

1. I've chosen to put pangocairo.pas into separate subdirectory
under packages/gtk2/src/, is this okay?

2. This unit needs to be included into build system. This is where I
need some help as I'm not familiar with build system yet. What needs
to be done to integrate this unit? Is somewhere a document that
describes how freepascal build system works?

As I have only old fpc 2.2.0 installed on my ubuntu hardy system (I
did not have time to set up newer version and build newest compiler
yet), I could not check if this patch builds as a whole, but it
should. I checked pangocairo.pas (with some minor modifications to
build without dependencies) and mods in pango and successfully used
them to display text on cairo surface.

Other related questions:

3. PGChar is defined as ^char, but string in PGchar is encoded using
UTF-8 and automatic conversion from (wide)string to pchar does not
use this encoding so I have to use conversion function like

function StringToGChar(str:WideString):Pgchar;
begin
  Result := Pgchar(UTF8Encode(str));
end;

for every string argument to be able to use non-ascii characters in
gtk/pango. Maybe we could add overloaded assignment operator that
would handle this conversion. That would, however, break backward
compatibility with programs using non-ascii characters that handle
this conversion on their own.

4. On Windows, my program requires cairo.dll to be present, but
there only exists libcairo-2.dll in windows gtk2 binaries (simple
renaming that to cairo.dll fixes it). Also there are two versions of
cairo in ubuntu hardy (libcairo.so and libcairo.so.2). Maybe we
could update the library name in cairo package (I'm willing to
provide the neccessary (two-line) patch if you think using new
library name is good idea ;) to a name with "2" included.

That's all for now :)

Thanks.

Best Regards,

Martin Sucha
Index: packages/gtk2/src/pangocairo/pangocairo.pas
===================================================================
--- packages/gtk2/src/pangocairo/pangocairo.pas	(revision 0)
+++ packages/gtk2/src/pangocairo/pangocairo.pas	(revision 0)
@@ -0,0 +1,116 @@
+unit pangocairo;
+
+interface
+uses glib2, pango, cairo;
+
+const
+{$ifdef win32}
+  {$define pangowin}
+  pangocairolib = 'libpangocairo-1.0-0.dll';
+  {$IFDEF FPC}
+    {$ifndef NO_SMART_LINK}
+      {$smartlink on}
+    {$endif}
+  {$ENDIF}
+{$else}
+  {$ifdef UseCustomLibs}
+  pangocairolib = '';
+  {$else}
+  pangocairolib = 'libpangocairo-1.0.so.0';
+  {$endif}
+{$endif}
+
+{$IFNDEF KYLIX}
+  {$PACKRECORDS C}
+{$ELSE}
+  {$ALIGN 4}
+  {$WEAKPACKAGEUNIT}
+  {$WARNINGS OFF}
+{$ENDIF}
+
+Type
+  PPangoCairoFont = pointer;   
+  PPangoCairoFontMap = pointer;
+  PangoCairoShapeRendererFunc = procedure (cr:Pcairo_t; attr:PPangoAttrShape; do_path:gboolean; data:gpointer);cdecl;
+    
+{$IFDEF FPC}
+{$PACKRECORDS C}
+{$ENDIF}
+
+function PANGO_TYPE_CAIRO_FONT : GType;
+function PANGO_CAIRO_FONT(objekt : pointer) : PPangoCairoFont;    
+function PANGO_IS_CAIRO_FONT(objekt : pointer) : boolean;    
+
+function PANGO_TYPE_CAIRO_FONT_MAP : GType;
+function PANGO_CAIRO_FONT_MAP(objekt : pointer) : PPangoCairoFontMap;    
+function PANGO_IS_CAIRO_FONT_MAP(objekt : pointer) : boolean;    
+
+function pango_cairo_font_map_get_type():GType;cdecl;external pangocairolib;
+function pango_cairo_font_map_new:PPangoFontMap;cdecl;external pangocairolib;
+function pango_cairo_font_map_new_for_font_type(fonttype:cairo_font_type_t):PPangoFontMap;cdecl;external pangocairolib;
+function pango_cairo_font_map_get_default:PPangoFontMap;cdecl;external pangocairolib;
+procedure pango_cairo_font_map_set_default(fontmap:PPangoCairoFontMap);cdecl;external pangocairolib;
+function pango_cairo_font_map_get_font_type(fontmap:PPangoCairoFontMap):cairo_font_type_t;cdecl;external pangocairolib;
+procedure pango_cairo_font_map_set_resolution(fontmap:PPangoCairoFontMap; dpi:double);cdecl;external pangocairolib;
+function pango_cairo_font_map_get_resolution(fontmap:PPangoCairoFontMap):double;cdecl;external pangocairolib;
+
+{$ifndef PANGO_DISABLE_DEPRECATED}
+function pango_cairo_font_map_create_context(fontmap:PPangoCairoFontMap):PPangoContext;cdecl;external pangocairolib;
+{$endif}
+    
+function pango_cairo_font_get_type():GType;cdecl;external pangocairolib;
+function pango_cairo_font_get_scaled_font(font:PPangoCairoFont):Pcairo_scaled_font_t;cdecl;external pangocairolib;
+procedure pango_cairo_update_context(cr:Pcairo_t; context:PPangoContext);cdecl;external pangocairolib;
+procedure pango_cairo_context_set_font_options(context:PPangoContext; options:Pcairo_font_options_t);cdecl;external pangocairolib;
+function pango_cairo_context_get_font_options(context:PPangoContext):Pcairo_font_options_t;cdecl;external pangocairolib;
+procedure pango_cairo_context_set_resolution(context:PPangoContext; dpi:double);cdecl;external pangocairolib;
+function pango_cairo_context_get_resolution(context:PPangoContext):double;cdecl;external pangocairolib;
+procedure pango_cairo_context_set_shape_renderer(context:PPangoContext; func:PangoCairoShapeRendererFunc; data:gpointer; dnotify:GDestroyNotify);cdecl;external pangocairolib;
+function pango_cairo_context_get_shape_renderer(context:PPangoContext; data:Pgpointer):PangoCairoShapeRendererFunc;cdecl;external pangocairolib;
+function pango_cairo_create_context(cr:Pcairo_t):PPangoContext;cdecl;external pangocairolib;
+function pango_cairo_create_layout(cr:Pcairo_t):PPangoLayout;cdecl;external pangocairolib;
+procedure pango_cairo_update_layout(cr:Pcairo_t; layout:PPangoLayout);cdecl;external pangocairolib;
+procedure pango_cairo_show_glyph_string(cr:Pcairo_t; font:PPangoFont; glyphs:PPangoGlyphString);cdecl;external pangocairolib;
+procedure pango_cairo_show_glyph_item(cr:Pcairo_t; text:Pchar; glyph_item:PPangoGlyphItem);cdecl;external pangocairolib;
+procedure pango_cairo_show_layout_line(cr:Pcairo_t; line:PPangoLayoutLine);cdecl;external pangocairolib;
+procedure pango_cairo_show_layout(cr:Pcairo_t; layout:PPangoLayout);cdecl;external pangocairolib;
+procedure pango_cairo_show_error_underline(cr:Pcairo_t; x:double; y:double; width:double; height:double);cdecl;external pangocairolib;
+procedure pango_cairo_glyph_string_path(cr:Pcairo_t; font:PPangoFont; glyphs:PPangoGlyphString);cdecl;external pangocairolib;
+procedure pango_cairo_layout_line_path(cr:Pcairo_t; line:PPangoLayoutLine);cdecl;external pangocairolib;
+procedure pango_cairo_layout_path(cr:Pcairo_t; layout:PPangoLayout);cdecl;external pangocairolib;
+procedure pango_cairo_error_underline_path(cr:Pcairo_t; x:double; y:double; width:double; height:double);cdecl;external pangocairolib;
+
+implementation
+
+function PANGO_TYPE_CAIRO_FONT : GType;
+begin
+  PANGO_TYPE_CAIRO_FONT:=pango_cairo_font_get_type;
+end;
+
+function PANGO_CAIRO_FONT(objekt : pointer) : PPangoCairoFont;
+begin
+  PANGO_CAIRO_FONT:=G_TYPE_CHECK_INSTANCE_CAST(objekt,PANGO_TYPE_CAIRO_FONT);
+end;
+
+function PANGO_IS_CAIRO_FONT(objekt : pointer) : boolean;
+begin
+  PANGO_IS_CAIRO_FONT:=G_TYPE_CHECK_INSTANCE_TYPE(objekt,PANGO_TYPE_CAIRO_FONT);
+end;
+
+function PANGO_TYPE_CAIRO_FONT_MAP : GType;
+begin
+  PANGO_TYPE_CAIRO_FONT_MAP:=pango_cairo_font_map_get_type;
+end;
+
+function PANGO_CAIRO_FONT_MAP(objekt : pointer) : PPangoCairoFontMap;
+begin
+  PANGO_CAIRO_FONT_MAP:=G_TYPE_CHECK_INSTANCE_CAST(objekt,PANGO_TYPE_CAIRO_FONT_MAP);
+end;
+
+function PANGO_IS_CAIRO_FONT_MAP(objekt : pointer) : boolean;
+begin
+  PANGO_IS_CAIRO_FONT_MAP:=G_TYPE_CHECK_INSTANCE_TYPE(objekt,PANGO_TYPE_CAIRO_FONT_MAP);
+end;
+
+
+end.
Index: packages/gtk2/src/pango/pango-glyph-item.inc
===================================================================
--- packages/gtk2/src/pango/pango-glyph-item.inc	(revision 0)
+++ packages/gtk2/src/pango/pango-glyph-item.inc	(revision 0)
@@ -0,0 +1,66 @@
+// included by pango.pp
+{$IFDEF read_forward_definitions}
+{$ENDIF read_forward_definitions}
+
+//------------------------------------------------------------------------------
+
+{$IFDEF read_interface_types}
+
+PPangoGlyphItem = ^TPangoGlyphItem;
+TPangoGlyphItem = record
+  item : PPangoItem;
+  glyphs : PPangoGlyphString;
+end;
+PPangoGlyphItemIter = ^TPangoGlyphItemIter;
+TPangoGlyphItemIter = record
+  glyph_item : PPangoGlyphItem;
+  text : Pgchar;
+  start_glyph : longint;
+  start_index : longint;
+  start_char : longint;
+  end_glyph : longint;
+  end_index : longint;
+  end_char : longint;
+end;
+
+{$ENDIF read_interface_types}
+
+//------------------------------------------------------------------------------
+
+{$IFDEF read_interface_functions}
+
+function PANGO_TYPE_GLYPH_ITEM : GType;
+  
+function pango_glyph_item_get_type():GType;cdecl;external pangolib;
+function pango_glyph_item_split(orig:PPangoGlyphItem; text:Pchar; split_index:longint):PPangoGlyphItem;cdecl;external pangolib;
+function pango_glyph_item_copy(orig:PPangoGlyphItem):PPangoGlyphItem;cdecl;external pangolib;
+procedure pango_glyph_item_free(glyph_item:PPangoGlyphItem);cdecl;external pangolib;
+function pango_glyph_item_apply_attrs(glyph_item:PPangoGlyphItem; text:Pchar; list:PPangoAttrList):PGSList;cdecl;external pangolib;
+procedure pango_glyph_item_letter_space(glyph_item:PPangoGlyphItem; text:Pchar; log_attrs:PPangoLogAttr; letter_spacing:longint);cdecl;external pangolib;
+
+function PANGO_TYPE_GLYPH_ITEM_ITER : GType;
+function pango_glyph_item_iter_get_type():GType;cdecl;external pangolib;
+function pango_glyph_item_iter_copy(orig:PPangoGlyphItemIter):PPangoGlyphItemIter;cdecl;external pangolib;
+procedure pango_glyph_item_iter_free(iter:PPangoGlyphItemIter);cdecl;external pangolib;
+function pango_glyph_item_iter_init_start(iter:PPangoGlyphItemIter; glyph_item:PPangoGlyphItem; text:Pchar):gboolean;cdecl;external pangolib;
+function pango_glyph_item_iter_init_end(iter:PPangoGlyphItemIter; glyph_item:PPangoGlyphItem; text:Pchar):gboolean;cdecl;external pangolib;
+function pango_glyph_item_iter_next_cluster(iter:PPangoGlyphItemIter):gboolean;cdecl;external pangolib;
+function pango_glyph_item_iter_prev_cluster(iter:PPangoGlyphItemIter):gboolean;cdecl;external pangolib;
+
+{$endif read_interface_functions}
+
+//------------------------------------------------------------------------------
+
+{$IFDEF read_implementation}
+
+function PANGO_TYPE_GLYPH_ITEM : GType;
+begin
+  PANGO_TYPE_GLYPH_ITEM:=pango_glyph_item_get_type;
+end;
+
+function PANGO_TYPE_GLYPH_ITEM_ITER : GType;
+begin
+  PANGO_TYPE_GLYPH_ITEM_ITER:=pango_glyph_item_iter_get_type;
+end;
+
+{$ENDIF}
Index: packages/gtk2/src/pango/pangoincludes.inc
===================================================================
--- packages/gtk2/src/pango/pangoincludes.inc	(revision 13054)
+++ packages/gtk2/src/pango/pangoincludes.inc	(working copy)
@@ -11,6 +11,7 @@
 {$include pango-fontmap.inc}
 {$include pango-glyph.inc}
 {$include pango-item.inc}
+{$include pango-glyph-item.inc}
 {$include pango-layout.inc}
 {$include pango-matrix.inc}
 { $include pango-enum-types.inc}
Index: packages/gtk2/src/glib/gdataset.inc
===================================================================
--- packages/gtk2/src/glib/gdataset.inc	(revision 13054)
+++ packages/gtk2/src/glib/gdataset.inc	(working copy)
@@ -9,6 +9,7 @@
 
 {$IFDEF read_interface_types}
   TGDataForeachFunc = procedure (key_id:TGQuark; data:gpointer; user_data:gpointer);cdecl;
+  GDestroyNotify = procedure (data:gpointer);cdecl;
 {$ENDIF read_interface_types}
 
 {$IFDEF read_interface_rest}
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to