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

Pango change, first baby step !




Hello all,

  a first baby step; here's a patch which delegates render_gdk.c/draw_string()
to Pango. It's horribly crude:
	* it hard-codes the font name to "Courier"
	* it uses the old GdkFont-based method for extents computation
	(hence, if the alignment is not LEFT and there is any non-ASCII
	stuff, the bounding box will be wrong)
	* It is extremely inefficient; it will re-shape all strings each
	time a redraw is needed.
	* It is extremely inefficient; it will build GdkFonts it doesn't
	really uses.

Caveats:
	* My system seems to have a problem with displaying "Courier"
	Japanese and Chinese text (more exactly, it seems one of the Courier
	fonts mistakenly declares to cover the CJK areas, when in fact it has 
	no glyphs for that; then the Pango shaper gets confused)
	
However:
	* the mapping between Pango and dia units should be right.
	* try to display the same dia file with 0.90 !
	* We actually have latin0 and KOI8-R co-existing in the same string,
	which is a definite improvement.

In theory, and as far as the Win32 port uses render_gdk.c for on-screen
rendering, this should apply and display the same kind of results on Win32.
Hans, do you have the time to give it a shot?

	-- Cyrille

-- 
Grumpf.

? autom4te.cache
? gtk2
? lib/font.E
? lib/stCFJvM7
? lib/styJrClm
? lib/text.c.heldoff.patch
? plug-ins/metapost/Makefile
? plug-ins/metapost/Makefile.in
? po/POTFILES.in.new
? po/fr.po.utf
? samples/ER-demo.png
? samples/SADT.png
? samples/UML-demo.png
? samples/chronograms.png
? samples/grafcet.png
? shapes/Misc/Makefile
? shapes/Misc/Makefile.in
Index: app/render_gdk.c
===================================================================
RCS file: /cvs/gnome/dia/app/render_gdk.c,v
retrieving revision 1.37
diff -u -r1.37 render_gdk.c
--- app/render_gdk.c	12 Jun 2002 18:49:03 -0000	1.37
+++ app/render_gdk.c	21 Jun 2002 16:27:24 -0000
@@ -26,6 +26,8 @@
 #include "render_gdk.h"
 #include "message.h"
 
+#include <pango/pango.h>
+
 static void begin_render(RendererGdk *renderer, DiagramData *data);
 static void end_render(RendererGdk *renderer);
 static void set_linewidth(RendererGdk *renderer, real linewidth);
@@ -941,7 +943,50 @@
 }
 #endif
 
-static void
+static void set_layout_font(PangoLayout* layout, const char* text,
+                            guint font_height)
+{
+    PangoAttribute* attr;
+    PangoAttrList* list;
+    PangoFontDescription* desc;
+    guint len = strlen(text);
+
+    desc = pango_font_description_new();
+    pango_font_description_set_family_static(desc,"Courier");
+    pango_font_description_set_style(desc,PANGO_STYLE_NORMAL);
+    pango_font_description_set_variant(desc,PANGO_VARIANT_NORMAL);
+    pango_font_description_set_weight(desc,PANGO_WEIGHT_NORMAL);
+    pango_font_description_set_stretch(desc,PANGO_STRETCH_NORMAL);
+    
+    pango_font_description_set_size(desc,font_height * 1000);
+            
+    attr = pango_attr_font_desc_new(desc);
+    pango_font_description_free(desc);
+
+    attr->start_index = 0;
+    attr->end_index = len;
+
+    list = pango_attr_list_new();
+    pango_attr_list_insert(list,attr);
+    
+    pango_layout_set_attributes(layout,list);
+    pango_attr_list_unref(list);
+    
+    pango_layout_set_indent(layout,0);
+    pango_layout_set_justify(layout,FALSE);
+    pango_layout_set_alignment(layout,PANGO_ALIGN_LEFT);
+    
+}
+
+static gint get_layout_first_baseline(PangoLayout* layout) {
+    PangoLayoutIter* iter = pango_layout_get_iter(layout);
+    gint result = pango_layout_iter_get_baseline(iter) / PANGO_SCALE;
+    pango_layout_iter_free(iter);
+    return result;
+}
+
+
+void
 draw_string (RendererGdk *renderer,
 	    const char *text,
 	     Point *pos, Alignment alignment,
@@ -983,10 +1028,12 @@
   gdk_gc_set_function(renderer->render_gc, GDK_COPY);
 #else
   DDisplay *ddisp = renderer->ddisp;
+  GtkWidget* widget = ddisp->canvas;  
   GdkGC *gc = renderer->render_gc;
   GdkColor gdkcolor;
   int x,y;
   int iwidth;
+  PangoLayout* layout;
   
   ddisplay_transform_coords(ddisp, pos->x, pos->y,
 			    &x, &y);
@@ -1003,13 +1050,17 @@
     x -= iwidth;
     break;
   }
-  
+
   color_convert(color, &gdkcolor);
   gdk_gc_set_foreground(gc, &gdkcolor);
-
-  gdk_draw_string(renderer->pixmap,
-		  renderer->gdk_font, gc,
-		  x,y, text);
+  
+  layout = gtk_widget_create_pango_layout(widget,text);
+  set_layout_font(layout,text,renderer->font_height);
+      
+  gdk_draw_layout(renderer->pixmap,gc,
+                  x,y - get_layout_first_baseline(layout),
+                  layout);
+  g_object_unref(G_OBJECT(layout));
 #endif
 }
 
<?xml version="1.0" encoding="UTF-8"?>
<dia:diagram
xmlns:dia="http://www.lysator.liu.se/~alla/dia/";><dia:diagramdata><dia:attribute
name="background"><dia:color
val="#ffffff"/></dia:attribute><dia:attribute
name="paper"><dia:composite type="paper"><dia:attribute
name="name"><dia:string>#A4#</dia:string></dia:attribute><dia:attribute
name="tmargin"><dia:real val="2.8222"/></dia:attribute><dia:attribute
name="bmargin"><dia:real val="2.8222"/></dia:attribute><dia:attribute
name="lmargin"><dia:real val="2.8222"/></dia:attribute><dia:attribute
name="rmargin"><dia:real val="2.8222"/></dia:attribute><dia:attribute
name="is_portrait"><dia:boolean
val="true"/></dia:attribute><dia:attribute name="scaling"><dia:real
val="1"/></dia:attribute><dia:attribute name="fitto"><dia:boolean
val="false"/></dia:attribute></dia:composite></dia:attribute><dia:attribute
name="grid"><dia:composite type="grid"><dia:attribute
name="width_x"><dia:real val="1"/></dia:attribute><dia:attribute
name="width_y"><dia:real val="1"/></dia:attribute><dia:attribute
name="visible_x"><dia:int val="1"/></dia:attribute><dia:attribute
name="visible_y"><dia:int
val="1"/></dia:attribute></dia:composite></dia:attribute><dia:attribute
name="guides"><dia:composite type="guides"><dia:attribute
name="hguides"/><dia:attribute
name="vguides"/></dia:composite></dia:attribute></dia:diagramdata><dia:layer
name="Arrière-plan" visible="true"><dia:object type="Standard - Text"
version="0" id="O0"><dia:attribute name="obj_pos"><dia:point
val="6,7"/></dia:attribute><dia:attribute name="obj_bb"><dia:rectangle
val="6,6.33286;18.458,7.28286"/></dia:attribute><dia:attribute
name="text"><dia:composite type="text"><dia:attribute name="string">

<dia:string>#Créer une classe クラスの作成 Создать класс 创建一个类 €uro.#</dia:string>

</dia:attribute><dia:attribute name="font"><dia:font name="Courier"/></dia:attribute><dia:attribute name="height"><dia:real val="0.8"/></dia:attribute><dia:attribute name="pos"><dia:point val="6,7"/></dia:attribute><dia:attribute name="color"><dia:color val="#000000"/></dia:attribute><dia:attribute name="alignment"><dia:enum val="0"/></dia:attribute></dia:composite></dia:attribute></dia:object><dia:object type="Standard - Text" version="0" id="O1"><dia:attribute name="obj_pos"><dia:point val="12,9"/></dia:attribute><dia:attribute name="obj_bb"><dia:rectangle val="6.0732,8.33286;17.9768,9.28286"/></dia:attribute><dia:attribute name="text"><dia:composite type="text"><dia:attribute name="string"><dia:string>#Simple text, no frills.#</dia:string></dia:attribute><dia:attribute name="font"><dia:font name="Courier"/></dia:attribute><dia:attribute name="height"><dia:real val="0.8"/></dia:attribute><dia:attribute name="pos"><dia:point val="12,9"/></dia:attribute><dia:attribute name="color"><dia:color val="#000000"/></dia:attribute><dia:attribute name="alignment"><dia:enum val="1"/></dia:attribute></dia:composite></dia:attribute></dia:object></dia:layer></dia:diagram>

pangocap.png



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK