[Gd-chatter] r11469 - branches/opendylan-melange/gtk-duim

andreas at gwydiondylan.org andreas at gwydiondylan.org
Fri Oct 19 01:58:21 CEST 2007


Author: andreas
Date: Fri Oct 19 01:58:20 2007
New Revision: 11469

Modified:
   branches/opendylan-melange/gtk-duim/gtk-draw.dylan
   branches/opendylan-melange/gtk-duim/gtk-fonts.dylan
Log:
job: fd

Calculation of text rendering extents, and rendering using pango.


Modified: branches/opendylan-melange/gtk-duim/gtk-draw.dylan
==============================================================================
--- branches/opendylan-melange/gtk-duim/gtk-draw.dylan	(original)
+++ branches/opendylan-melange/gtk-duim/gtk-draw.dylan	Fri Oct 19 01:58:20 2007
@@ -459,6 +459,12 @@
   let length :: <integer> = size(string);
   let (drawable :: <GdkDrawable>, gcontext :: <GdkGC>)
     = update-drawing-state(medium, font: font);
+  let screen = gdk-drawable-get-screen(drawable);
+//  let renderer = gdk-pango-renderer-get-default(screen);
+//  gdk-pango-renderer-set-gc(renderer, gcontext);
+  let context = gdk-pango-context-get-for-screen(screen);
+  let layout = pango-layout-new(context);
+  pango-layout-set-font-description(layout, font.%font-description);
   let transform = medium-device-transform(medium);
   with-device-coordinates (transform, x, y)
     when (towards-x & towards-y)
@@ -466,44 +472,40 @@
     end;
     //---*** What about x and y alignment?
     if (do-tabs?)
-      ignoring("draw-text with do-tabs?: #t");
-      /*---*** Not yet implemented!
       let tab-width  = text-size(medium, " ") * 8;
       let tab-origin = if (do-tabs? == #t) x else do-tabs? end;
       let x = 0;
       let s = _start;
       block (break)
 	while (#t)
-	  let e = position(string, '\t', start: s, end: _end);
-	  //---*** It would be great if 'with-c-string' took start & end!
+	  let e = position(string, '\t', start: s, end: _end) | string.size;
 	  let substring = copy-sequence(string, start: s, end: e);
-	  with-c-string (c-string = substring)
-	    gdk-draw-text(drawable, font, gcontext,
-			  tab-origin + x, y, string, e - s)
-	  end;
+          pango-layout-set-text(layout, substring, e - s);
+//          pango-layout-context-changed(layout);
+//          pango-renderer-draw-layout(renderer, layout, tab-origin + x, y);
+          gdk-draw-line(drawable, gcontext, 0, 0, 100, 100);
+          gdk-draw-layout(drawable, gcontext, tab-origin + x, y + 50, layout);
 	  if (e = _end)
 	    break()
 	  else
-	    let (x1, y1, x2, y2) = GET-STRING-EXTENT(drawable, string, font, s, e);
-	    ignore(x1, y1, y2);
-	    x := floor/(x + x2 + tab-width, tab-width) * tab-width;
-	    s := min(e + 1, _end)
+            with-stack-structure (rectangle :: <PangoRectangle>)
+              pango-layout-get-pixel-extents(layout, null-pointer(<PangoRectangle>), rectangle);
+              x := floor/(x + rectangle.PangoRectangle-x + rectangle.PangoRectangle-width 
+                            + tab-width, tab-width) * tab-width;
+              s := min(e + 1, _end)
+            end;
 	  end
 	end
       end
-      */
     else
-      ignoring("draw-text");
-      /*---*** Fonts not working yet!
-      //---*** It would be great if 'with-c-string' took start & end!
       let substring
 	= if (_start = 0 & _end = length) string
 	  else copy-sequence(string, start: _start, end: _end) end;
-      with-c-string (c-string = substring)
-	gdk-draw-string(drawable, font, gcontext,
-			x, y, c-string)
-      end
-      */
+      pango-layout-set-text(layout, substring, -1);
+      //pango-layout-context-changed(layout);
+      //pango-renderer-draw-layout(renderer, layout, x, y);
+      gdk-draw-layout(drawable, gcontext, x, y, layout);
     end
   end
 end method draw-text;
+

Modified: branches/opendylan-melange/gtk-duim/gtk-fonts.dylan
==============================================================================
--- branches/opendylan-melange/gtk-duim/gtk-fonts.dylan	(original)
+++ branches/opendylan-melange/gtk-duim/gtk-fonts.dylan	Fri Oct 19 01:58:20 2007
@@ -96,10 +96,15 @@
   if (found?)
     font
   else
+    let size = if (instance?(text-style-size(text-style), <integer>))
+                 text-style-size(text-style)
+               else
+                 second(find-pair($gtk-logical-sizes, text-style-size(text-style)))
+               end;
     let font-name
       = format-to-string("%s %d",
                          second(find-pair($gtk-font-families, text-style-family(text-style))),
-                         text-style-size(text-style));
+                         size);
     let font-description = pango-font-description-from-string(font-name); 
     let font = make(<gtk-font>, name: font-name, description: font-description);
     table[text-style] := font;
@@ -178,18 +183,22 @@
   gtk-font-metrics(font, _port)
 end method font-metrics;
 
+define function gtk-get-pango-context-from-port (port :: <gtk-port>) => (context :: <pangocontext>)
+  let widget = port.port-displays.first.sheet-children.first.sheet-direct-mirror.mirror-widget; // YUCK!
+  gtk-widget-get-pango-context(widget);
+end;
+
 define sealed method gtk-font-metrics
     (font :: <gtk-font>, _port :: <gtk-port>)
  => (font :: <gtk-font>,
      width :: <integer>, height :: <integer>, ascent :: <integer>, descent :: <integer>)
-  let widget = _port.port-displays.first.sheet-children.first.sheet-direct-mirror.mirror-widget; // YUCK!
-  let pango-context = gtk-widget-get-pango-context(widget);
+  let pango-context = gtk-get-pango-context-from-port(_port);
   let metrics = pango-context-get-metrics(pango-context, font.%font-description, pango-language-get-default());
   values(font,
-         truncate/(pango-font-metrics-get-approximate-char-width(metrics), $PANGO-SCALE),
-         truncate/(pango-font-description-get-size(font.%font-description), $PANGO-SCALE),
-         truncate/(pango-font-metrics-get-ascent(metrics), $PANGO-SCALE),
-         truncate/(pango-font-metrics-get-descent(metrics), $PANGO-SCALE));
+         round/(pango-font-metrics-get-approximate-char-width(metrics), $PANGO-SCALE),
+         round/(pango-font-metrics-get-ascent(metrics) + pango-font-metrics-get-descent(metrics), $PANGO-SCALE),
+         round/(pango-font-metrics-get-ascent(metrics), $PANGO-SCALE),
+         round/(pango-font-metrics-get-descent(metrics), $PANGO-SCALE));
 end method gtk-font-metrics;
 
 
@@ -224,8 +233,16 @@
 	     _start :: <integer>, _end :: <integer>)
 	 => (x1 :: <integer>, y1 :: <integer>, 
 	     x2 :: <integer>, y2 :: <integer>)
-	  ignoring("measure-string");
-	  values(0, 0, 100, 10)
+          let layout = pango-layout-new(gtk-get-pango-context-from-port(_port));
+          pango-layout-set-text(layout,
+                                copy-sequence(string, start: _start, end: _end),
+                                _end - _start); 
+          with-stack-structure (rectangle :: <PangoRectangle>)
+            pango-layout-get-pixel-extents(layout, null-pointer(<PangoRectangle>), rectangle);
+            values(rectangle.PangoRectangle-x, rectangle.PangoRectangle-y,
+                   rectangle.PangoRectangle-x + rectangle.PangoRectangle-width,
+                   rectangle.PangoRectangle-y + rectangle.PangoRectangle-height)
+          end;
 	end method measure-string;
   case
     do-tabs? & do-newlines? =>
@@ -279,3 +296,9 @@
       values(x2, y2 - y1, x2, y2 - y1, ascent);
   end
 end method text-size;
+
+
+
+
+
+



More information about the chatter mailing list