Author: jordi
Date: 2006-01-15 16:20:32 -0500 (Sun, 15 Jan 2006)
New Revision: 55610

Modified:
   trunk/libgdiplus/src/ChangeLog
   trunk/libgdiplus/src/font.c
   trunk/libgdiplus/src/gdip.h
   trunk/libgdiplus/src/general.c
   trunk/libgdiplus/src/graphics.c
   trunk/libgdiplus/src/image.c
Log:
2006-01-15 Jordi Mas i Hernandez  <[EMAIL PROTECTED]>

        * graphics.c, image.c, gdip.h, general.c:
                - Implements PageUnit functionality
                - Converts units to Cairo user-space (postscript or display)
                - Each surface has its own x and y dpi
                - Allows setting Postscript dpy's



Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog      2006-01-15 21:20:28 UTC (rev 55609)
+++ trunk/libgdiplus/src/ChangeLog      2006-01-15 21:20:32 UTC (rev 55610)
@@ -1,3 +1,11 @@
+2006-01-15 Jordi Mas i Hernandez  <[EMAIL PROTECTED]>
+
+       * graphics.c, image.c, gdip.h, general.c:
+               - Implements PageUnit functionality
+               - Converts units to Cairo user-space (postscript or display)
+               - Each surface has its own x and y dpi
+               - Allows setting Postscript dpy's
+
 2006-01-13  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * graphics-path.c: Added checks for the number of points added when

Modified: trunk/libgdiplus/src/font.c
===================================================================
--- trunk/libgdiplus/src/font.c 2006-01-15 21:20:28 UTC (rev 55609)
+++ trunk/libgdiplus/src/font.c 2006-01-15 21:20:32 UTC (rev 55610)
@@ -551,7 +551,7 @@
 
        r = FcPatternGetString (family->pattern, FC_FAMILY, 0, &str);
        
-       gdip_unitConversion (unit, UnitPixel, emSize, &sizeInPixels);
+       gdip_unit_conversion (unit, UnitPixel, gdip_get_display_dpi(), 
gtMemoryBitmap, emSize, &sizeInPixels);
                
        result = (GpFont *) GdipAlloc (sizeof (GpFont));
        result->sizeInPixels = sizeInPixels;

Modified: trunk/libgdiplus/src/gdip.h
===================================================================
--- trunk/libgdiplus/src/gdip.h 2006-01-15 21:20:28 UTC (rev 55609)
+++ trunk/libgdiplus/src/gdip.h 2006-01-15 21:20:32 UTC (rev 55610)
@@ -208,7 +208,8 @@
     UnitPoint   = 3,
     UnitInch    = 4,
     UnitDocument = 5,
-    UnitMillimeter = 6
+    UnitMillimeter = 6,
+    UnitCairoPoint = 7
 } GpUnit, Unit;
 
 typedef enum {
@@ -744,6 +745,8 @@
        float           aa_offset_y;
        int             render_origin_x;
        int             render_origin_y;
+       float           dpi_x;
+       float           dpi_y;
 } GpGraphics;
 
 
@@ -1334,7 +1337,10 @@
 /* Utility*/
 int fcmp (double x1, double x2, double epsilon);
 float gdip_get_display_dpi();
-void gdip_unitConversion(Unit fromUnit, Unit toUnit, float nSrc, float* nTrg);
+float gdip_unitx_convgr (GpGraphics *graphics, float nSrc);
+float gdip_unity_convgr (GpGraphics *graphics, float nSrc);
+void gdip_unit_conversion (Unit from, Unit to, float dpi, GraphicsType type, 
float nSrc, float* nTrg);
+
 cairo_content_t from_cairoformat_to_content (cairo_format_t format);
 
 void gdip_rect_expand_by (GpRectF *rect, GpPointF *point);

Modified: trunk/libgdiplus/src/general.c
===================================================================
--- trunk/libgdiplus/src/general.c      2006-01-15 21:20:28 UTC (rev 55609)
+++ trunk/libgdiplus/src/general.c      2006-01-15 21:20:32 UTC (rev 55610)
@@ -219,62 +219,7 @@
        return dpis;
 }
 
-void gdip_unitConversion(Unit fromUnit, Unit toUnit, float nSrc, float* nTrg)
-{
-    float inchs = 0;
-    *nTrg = 0;
 
-    switch (fromUnit) {
-    case UnitDisplay:
-      inchs = nSrc / 75.0f;
-      break;
-    case UnitDocument:
-      inchs = nSrc / 300.0f;
-      break;
-    case UnitInch:
-      inchs = nSrc;
-      break;
-    case UnitMillimeter:
-      inchs = nSrc / 25.4f;
-      break;
-    case UnitPixel:
-    case UnitWorld:
-      inchs = nSrc / gdip_get_display_dpi();
-      break;
-    case UnitPoint:
-      inchs = nSrc / 72.0f;
-      break;
-    default:
-      break;
-    }
-
-    switch (toUnit) {
-    case UnitDisplay:
-      *nTrg = inchs * 75.0f;
-      break;
-    case UnitDocument:
-      *nTrg = inchs * 300.0f;
-      break;
-    case UnitInch:
-      *nTrg = inchs;
-      break;
-    case UnitMillimeter:
-      *nTrg = inchs * 25.4f;
-      break;
-    case UnitPixel:
-    case UnitWorld:
-      *nTrg = inchs * gdip_get_display_dpi();
-      break;
-    case UnitPoint:
-      *nTrg = inchs * 72.0f;
-      break;
-    default:
-      break;
-    }
-
-}
-
-
 /* Curve handling
  *
  * See Richard Rasala, Explicit Cubic Spline Interpolation Formulas, in

Modified: trunk/libgdiplus/src/graphics.c
===================================================================
--- trunk/libgdiplus/src/graphics.c     2006-01-15 21:20:28 UTC (rev 55609)
+++ trunk/libgdiplus/src/graphics.c     2006-01-15 21:20:32 UTC (rev 55610)
@@ -41,7 +41,97 @@
 
 #define MAX_GRAPHICS_STATE_STACK 512
 
+float 
+gdip_unitx_convgr (GpGraphics *graphics, float nSrc)
+{
+       float nTrg;
+       gdip_unit_conversion (graphics->page_unit, UnitCairoPoint, 
graphics->dpi_x, graphics->type, nSrc, &nTrg);
+       return nTrg;
+}
+
+float 
+gdip_unity_convgr (GpGraphics *graphics, float nSrc)
+{
+       float nTrg;
+       gdip_unit_conversion (graphics->page_unit, UnitCairoPoint, 
graphics->dpi_y, graphics->type, nSrc, &nTrg);
+       return nTrg;
+}
+
 void
+gdip_unit_conversion (Unit from, Unit to, float dpi, GraphicsType type, float 
nSrc, float* nTrg)
+{      
+       float inchs = 0;
+       *nTrg = 0;
+
+       switch (from) {
+       case UnitDocument:
+               inchs = nSrc / 300.0f;
+               break;
+       case UnitInch:
+               inchs = nSrc;
+               break;
+       case UnitMillimeter:
+               inchs = nSrc / 25.4f;
+               break;
+       case UnitDisplay:
+               if (type == gtPostScript) { /* Uses 1/100th on printers */
+                       inchs = nSrc / 100;
+               } else { /* Pixel for video display */
+                       inchs = nSrc / dpi;
+               }
+               break;
+       case UnitPixel:
+       case UnitWorld:
+               inchs = nSrc / dpi;
+               break;
+       case UnitPoint:
+               inchs = nSrc / 72.0f;
+               break;
+       default:
+               *nTrg = nSrc;
+               return;
+       }
+
+       switch (to) {
+       case UnitDocument:
+               *nTrg = inchs * 300.0f;
+               break;
+       case UnitInch:
+               *nTrg = inchs;
+               break;
+       case UnitMillimeter:
+               *nTrg = inchs * 25.4f;
+               break;
+       case UnitDisplay:
+               if (type == gtPostScript) { /* Uses 1/100th on printers */
+                       *nTrg = inchs * 100;
+               } else { /* Pixel for video display */
+                       *nTrg = inchs * dpi;
+               }
+               break;
+
+       case UnitPixel:
+       case UnitWorld:
+               *nTrg = inchs * dpi;
+               break;
+       case UnitPoint:
+               *nTrg = inchs * 72.0f;
+               break;
+       case UnitCairoPoint:
+               if (type == gtPostScript) { /* Uses 1/100th on printers */
+                       *nTrg = inchs * 72.0f;
+               } else { /* Pixel for video display */
+                       *nTrg = inchs * dpi;
+               }
+               break;                  
+        default:
+               *nTrg = nSrc;
+               break;
+       }
+}
+
+
+void
 gdip_graphics_init (GpGraphics *graphics, cairo_surface_t *surface)
 {
        
@@ -72,6 +162,7 @@
        graphics->saved_status_pos = 0;
        graphics->render_origin_x = 0;
        graphics->render_origin_y = 0;
+       graphics->dpi_x = graphics->dpi_y = 0;
 
        GdipSetSmoothingMode(graphics, SmoothingModeNone);
 }
@@ -127,17 +218,22 @@
 make_polygon (GpGraphics *graphics, GpPointF *points, int count, float 
aa_offset_x, float aa_offset_y)
 {
         int i;
-        cairo_move_to (graphics->ct, points [0].X + aa_offset_x, points [0].Y 
+ aa_offset_y);
+        cairo_move_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, points [0].X) + aa_offset_x, 
+               gdip_unity_convgr (graphics, points [0].Y) + aa_offset_y);
 
         for (i = 0; i < count; i++)
-                cairo_line_to (graphics->ct, points [i].X + aa_offset_x, 
points [i].Y + aa_offset_y);
+                cairo_line_to (graphics->ct, 
+                       gdip_unitx_convgr (graphics, points [i].X) + 
aa_offset_x, 
+                       gdip_unity_convgr (graphics, points [i].Y) + 
aa_offset_y);
 
         /*
          * Draw a line from the last point back to the first point if
          * they're not the same
          */
         if (points [0].X != points [count].X && points [0].Y != points 
[count].Y)
-                cairo_line_to (graphics->ct, points [0].X + aa_offset_x, 
points [0].Y + aa_offset_y);
+                cairo_line_to (graphics->ct, gdip_unitx_convgr (graphics, 
points [0].X) + aa_offset_x, 
+                       gdip_unity_convgr (graphics, points [0].Y) + 
aa_offset_y);
 
         cairo_close_path (graphics->ct);
 }
@@ -146,17 +242,23 @@
 make_polygon_from_integers (GpGraphics *graphics, GpPoint *points, int count, 
float aa_offset_x, float aa_offset_y)
 {
         int i;
-        cairo_move_to (graphics->ct, points [0].X + aa_offset_x, points [0].Y 
+ aa_offset_y);
+        cairo_move_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, points [0].X) + aa_offset_x, 
+               gdip_unity_convgr (graphics, points [0].Y) + aa_offset_y);
 
         for (i = 0; i < count; i++)
-                cairo_line_to (graphics->ct, points [i].X + aa_offset_x, 
points [i].Y + aa_offset_y);
+                cairo_line_to (graphics->ct, 
+                       gdip_unitx_convgr (graphics, points [i].X) + 
aa_offset_x, 
+                       gdip_unity_convgr (graphics, points [i].Y) + 
aa_offset_y);
 
         /*
          * Draw a line from the last point back to the first point if
          * they're not the same
          */
         if (points [0].X != points [count].X && points [0].Y != points 
[count].Y)
-                cairo_line_to (graphics->ct, points [0].X + aa_offset_x, 
points [0].Y + aa_offset_y);
+                cairo_line_to (graphics->ct, 
+                       gdip_unitx_convgr (graphics, points [0].X) + 
aa_offset_x, 
+                       gdip_unity_convgr (graphics, points [0].Y) + 
aa_offset_y);
 
         cairo_close_path (graphics->ct);
 }
@@ -331,6 +433,7 @@
            w, h);
                        
        *graphics = gdip_graphics_new (surface);
+       (*graphics)->dpi_x = (*graphics)->dpi_y = gdip_get_display_dpi ();
        cairo_surface_destroy (surface);
 
        if (!*graphics)
@@ -365,6 +468,7 @@
        
        
        *graphics = gdip_graphics_new(surface);
+       graphics->dpi_x = *graphics->dpi_y = gdip_get_display_dpi ();
        cairo_surface_destroy (surface);
        
        (*graphics)->bounds.Width = width;
@@ -399,6 +503,7 @@
        
        
        *graphics = gdip_graphics_new(surface);
+       (*graphics)->dpi_x = (*graphics)->dpi_y = gdip_get_display_dpi ();
        cairo_surface_destroy (surface);
 
        (*graphics)->type = gtX11Drawable;
@@ -657,7 +762,9 @@
         * have it set already.
         */
 
-       make_arcs (graphics, x, y, width, height, startAngle, sweepAngle, 
graphics->aa_offset_x, graphics->aa_offset_y);
+       make_arcs (graphics, gdip_unitx_convgr (graphics, x), gdip_unity_convgr 
(graphics, y), 
+               gdip_unitx_convgr (graphics, width), gdip_unity_convgr 
(graphics, height), 
+               startAngle, sweepAngle, graphics->aa_offset_x, 
graphics->aa_offset_y);
 
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
@@ -690,9 +797,18 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-        cairo_move_to (graphics->ct, x1 + graphics->aa_offset_x, y1 + 
graphics->aa_offset_y);
-        cairo_curve_to (graphics->ct, x2 + graphics->aa_offset_x, y2 + 
graphics->aa_offset_y, x3 + graphics->aa_offset_x, y3 + graphics->aa_offset_y, 
x4 + graphics->aa_offset_x, y4 + graphics->aa_offset_y);
+        cairo_move_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, x1) + graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, y1) + graphics->aa_offset_y);
 
+        cairo_curve_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, x2) + graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, y2) + graphics->aa_offset_y, 
+               gdip_unitx_convgr (graphics, x3) + graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, y3) + graphics->aa_offset_y, 
+               gdip_unitx_convgr (graphics, x4) + graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, y4) + graphics->aa_offset_y);
+
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
        cairo_stroke (graphics->ct);
@@ -729,15 +845,20 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-        cairo_move_to (graphics->ct, points [0].X + graphics->aa_offset_x, 
points [0].Y + graphics->aa_offset_y);
+        cairo_move_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, points [0].X) + 
graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, points [0].Y) + 
graphics->aa_offset_y);
 
         for (i = 0; i < count - 3; i += 3) {
                 j = i + 1;
                 k = i + 2;
                 cairo_curve_to (graphics->ct,
-                                points [i].X + graphics->aa_offset_x, points 
[i].Y + graphics->aa_offset_y,
-                                points [j].X + graphics->aa_offset_x, points 
[j].Y + graphics->aa_offset_y,
-                                points [k].X + graphics->aa_offset_x, points 
[k].Y + graphics->aa_offset_y);
+                               gdip_unitx_convgr (graphics, points [i].X) + 
graphics->aa_offset_x, 
+                               gdip_unity_convgr (graphics, points [i].Y) + 
graphics->aa_offset_y,
+                               gdip_unitx_convgr (graphics, points [j].X) + 
graphics->aa_offset_x, 
+                               gdip_unity_convgr (graphics, points [j].Y) + 
graphics->aa_offset_y,
+                               gdip_unitx_convgr (graphics, points [k].X) + 
graphics->aa_offset_x, 
+                               gdip_unity_convgr (graphics, points [k].Y) + 
graphics->aa_offset_y);
         }
 
        /* We do pen setup just before stroking. */
@@ -768,15 +889,20 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-        cairo_move_to (graphics->ct, points [0].X + graphics->aa_offset_x, 
points [0].Y + graphics->aa_offset_y);
+        cairo_move_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, points [0].X) + 
graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, points [0].Y) + 
graphics->aa_offset_y);
 
         for (i = 0; i < count - 3; i += 3) {
                 j = i + 1;
                 k = i + 2;
                 cairo_curve_to (graphics->ct,
-                                points [i].X + graphics->aa_offset_x, points 
[i].Y + graphics->aa_offset_y,
-                                points [j].X + graphics->aa_offset_x, points 
[j].Y + graphics->aa_offset_y,
-                                points [k].X + graphics->aa_offset_x, points 
[k].Y + graphics->aa_offset_y);
+                               gdip_unitx_convgr (graphics, points [i].X) + 
graphics->aa_offset_x, 
+                               gdip_unity_convgr (graphics, points [i].Y) + 
graphics->aa_offset_y,
+                               gdip_unitx_convgr (graphics, points [j].X) + 
graphics->aa_offset_x, 
+                               gdip_unity_convgr (graphics, points [j].Y) + 
graphics->aa_offset_y,
+                               gdip_unitx_convgr (graphics, points [k].X) + 
graphics->aa_offset_x, 
+                               gdip_unity_convgr (graphics, points [k].Y) + 
graphics->aa_offset_y);
         }
 
        /* We do pen setup just before stroking. */
@@ -801,7 +927,9 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-       make_ellipse (graphics, x, y, width, height, graphics->aa_offset_x, 
graphics->aa_offset_y);
+       make_ellipse (graphics, gdip_unitx_convgr (graphics, x), 
gdip_unity_convgr (graphics, y), 
+               gdip_unitx_convgr (graphics, width), gdip_unity_convgr 
(graphics, height), 
+               graphics->aa_offset_x, graphics->aa_offset_y);
 
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
@@ -837,9 +965,14 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-       cairo_move_to (graphics->ct, x1 + graphics->aa_offset_x, y1 + 
graphics->aa_offset_y);
-       cairo_line_to (graphics->ct, x2 + graphics->aa_offset_x, y2 + 
graphics->aa_offset_y);
+       cairo_move_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, x1) + graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, y1) + graphics->aa_offset_y);
 
+       cairo_line_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, x2) + graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, y2) + graphics->aa_offset_y);
+
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
        cairo_stroke (graphics->ct);
@@ -874,9 +1007,14 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-       cairo_move_to (graphics->ct, points [0].X + graphics->aa_offset_x, 
points [0].Y + graphics->aa_offset_y);
+       cairo_move_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, points [0].X) + 
graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, points [0].Y) + 
graphics->aa_offset_y);
+
        for (i = 1; i < count; i++)
-               cairo_line_to (graphics->ct, points [i].X + 
graphics->aa_offset_x, points [i].Y + graphics->aa_offset_y);
+               cairo_line_to (graphics->ct, 
+                       gdip_unitx_convgr (graphics, points [i].X) + 
graphics->aa_offset_x, 
+                       gdip_unity_convgr (graphics, points [i].Y) + 
graphics->aa_offset_y);
 
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
@@ -903,9 +1041,14 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-       cairo_move_to (graphics->ct, points [0].X + graphics->aa_offset_x, 
points [0].Y + graphics->aa_offset_y);
+       cairo_move_to (graphics->ct, 
+               gdip_unitx_convgr (graphics, points [0].X) + 
graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, points [0].Y) + 
graphics->aa_offset_y);
+
        for (i = 1; i < count; i++)
-               cairo_line_to (graphics->ct, points [i].X + 
graphics->aa_offset_x, points [i].Y + graphics->aa_offset_y);
+               cairo_line_to (graphics->ct, 
+                       gdip_unitx_convgr (graphics, points [i].X) + 
graphics->aa_offset_x, 
+                       gdip_unity_convgr (graphics, points [i].Y) + 
graphics->aa_offset_y);
 
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
@@ -933,11 +1076,15 @@
                /* mask the bits so that we get only the type value not the 
other flags */
                 switch (type & PathPointTypePathTypeMask) {
                 case PathPointTypeStart:
-                        cairo_move_to (graphics->ct, pt.X + aa_offset_x, pt.Y 
+ aa_offset_y);
+                        cairo_move_to (graphics->ct, 
+                               gdip_unitx_convgr (graphics, pt.X) + 
aa_offset_x, 
+                               gdip_unity_convgr (graphics, pt.Y) + 
aa_offset_y);
                         break;
 
                 case PathPointTypeLine:
-                        cairo_line_to (graphics->ct, pt.X + aa_offset_x, pt.Y 
+ aa_offset_y);
+                        cairo_line_to (graphics->ct, 
+                               gdip_unitx_convgr (graphics, pt.X) + 
aa_offset_x, 
+                               gdip_unity_convgr (graphics, pt.Y) + 
aa_offset_y);
                         break;
 
                 case PathPointTypeBezier:
@@ -950,9 +1097,12 @@
                         /* once we've added 3 pts, we can draw the curve */
                         if (idx == 3) {
                                 cairo_curve_to (graphics->ct,
-                                                pts [0].X + aa_offset_x, pts 
[0].Y + aa_offset_y,
-                                                pts [1].X + aa_offset_x, pts 
[1].Y + aa_offset_y,
-                                                pts [2].X + aa_offset_x, pts 
[2].Y + aa_offset_y);
+                                       gdip_unitx_convgr (graphics, pts [0].X) 
+ aa_offset_x, 
+                                       gdip_unity_convgr (graphics, pts [0].Y) 
+ aa_offset_y,
+                                       gdip_unitx_convgr (graphics, pts [1].X) 
+ aa_offset_x, 
+                                       gdip_unity_convgr (graphics, pts [1].Y) 
+ aa_offset_y,
+                                       gdip_unitx_convgr (graphics, pts [2].X) 
+ aa_offset_x, 
+                                       gdip_unity_convgr (graphics, pts [2].Y) 
+ aa_offset_y);
                                 idx = 0;
                         }
 
@@ -1007,7 +1157,9 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-       make_pie (graphics, x, y, width, height, startAngle, sweepAngle, 
graphics->aa_offset_x, graphics->aa_offset_y);
+       make_pie (graphics, gdip_unitx_convgr (graphics, x), gdip_unity_convgr 
(graphics, y), 
+               gdip_unitx_convgr (graphics, width), gdip_unity_convgr 
(graphics, height), 
+               startAngle, sweepAngle, graphics->aa_offset_x, 
graphics->aa_offset_y);
 
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
@@ -1091,7 +1243,11 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-       cairo_rectangle (graphics->ct, x + graphics->aa_offset_x, y + 
graphics->aa_offset_y, width, height);
+       cairo_rectangle (graphics->ct, 
+               gdip_unitx_convgr (graphics, x) + graphics->aa_offset_x, 
+               gdip_unity_convgr (graphics, y) + graphics->aa_offset_y, 
+               gdip_unitx_convgr (graphics, width), 
+               gdip_unity_convgr (graphics, height));
 
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
@@ -1127,7 +1283,11 @@
         * should have it set already.
         */
        for (i = 0; i < count; i++)
-               cairo_rectangle (graphics->ct, rects [i].X + 
graphics->aa_offset_x, rects [i].Y + graphics->aa_offset_y, rects [i].Width, 
rects [i].Height);
+               cairo_rectangle (graphics->ct, 
+                       gdip_unitx_convgr (graphics, rects [i].X) + 
graphics->aa_offset_x, 
+                       gdip_unity_convgr (graphics, rects [i].Y) + 
graphics->aa_offset_y, 
+                       gdip_unitx_convgr (graphics, rects [i].Width), 
+                       gdip_unity_convgr (graphics, rects [i].Height));
 
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
@@ -1155,7 +1315,11 @@
         * should have it set already.
         */
        for (i = 0; i < count; i++)
-               cairo_rectangle (graphics->ct, rects [i].X, rects [i].Y, rects 
[i].Width, rects [i].Height);
+               cairo_rectangle (graphics->ct, 
+                       gdip_unitx_convgr (graphics, rects [i].X), 
+                       gdip_unity_convgr (graphics, rects [i].Y), 
+                       gdip_unitx_convgr (graphics, rects [i].Width), 
+                       gdip_unity_convgr (graphics, rects [i].Height));
 
        /* We do pen setup just before stroking. */
        gdip_pen_setup (graphics, pen);
@@ -1188,14 +1352,14 @@
                 int j = i - 1;
                 int k = (i < count) ? i : 0;
 
-                double x1 = points [j].X + tangents [j].X;
-                double y1 = points [j].Y + tangents [j].Y;
+                double x1 = gdip_unitx_convgr (graphics, points [j].X + 
tangents [j].X);
+                double y1 = gdip_unity_convgr (graphics, points [j].Y + 
tangents [j].Y);
 
-                double x2 = points [k].X - tangents [k].X;
-                double y2 = points [k].Y - tangents [k].Y;
+                double x2 = gdip_unitx_convgr (graphics, points [k].X - 
tangents [k].X);
+                double y2 = gdip_unity_convgr (graphics, points [k].Y - 
tangents [k].Y);
 
-                double x3 = points [k].X;
-                double y3 = points [k].Y;
+                double x3 = gdip_unitx_convgr (graphics, points [k].X);
+                double y3 = gdip_unity_convgr (graphics, points [k].Y);
 
                 cairo_curve_to (
                         graphics->ct,
@@ -1355,7 +1519,8 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-       make_ellipse (graphics, x, y, width, height, 0, 0);
+       make_ellipse (graphics, gdip_unitx_convgr (graphics, x), 
gdip_unity_convgr (graphics, y), 
+               gdip_unitx_convgr (graphics, width), gdip_unity_convgr 
(graphics, height), 0, 0);
        
        /* We do brush setup just before filling. */
        gdip_brush_setup (graphics, brush);
@@ -1386,7 +1551,8 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-       cairo_rectangle (graphics->ct, x, y, width, height);
+       cairo_rectangle (graphics->ct, gdip_unitx_convgr (graphics, x), 
gdip_unity_convgr (graphics, y), 
+               gdip_unitx_convgr (graphics, width), gdip_unity_convgr 
(graphics, height));
 
        /* We do brush setup just before filling. */
        gdip_brush_setup (graphics, brush);
@@ -1421,7 +1587,9 @@
         * should have it set already.
         */
        for (i = 0; i < count; i++)
-               cairo_rectangle (graphics->ct, rects [i].X, rects [i].Y, rects 
[i].Width, rects [i].Height);
+               cairo_rectangle (graphics->ct, 
+                       gdip_unitx_convgr (graphics, rects [i].X), 
gdip_unity_convgr (graphics, rects [i].Y), 
+                       gdip_unitx_convgr (graphics, rects [i].Width), 
gdip_unity_convgr (graphics, rects [i].Height));
 
        /* We do brush setup just before filling. */
        gdip_brush_setup (graphics, brush);
@@ -1449,7 +1617,9 @@
         * should have it set already.
         */
        for (i = 0; i < count; i++)
-               cairo_rectangle (graphics->ct, rects [i].X, rects [i].Y, rects 
[i].Width, rects [i].Height);
+               cairo_rectangle (graphics->ct, 
+                       gdip_unitx_convgr (graphics, rects [i].X), 
gdip_unity_convgr (graphics, rects [i].Y), 
+                       gdip_unitx_convgr (graphics, rects [i].Width), 
gdip_unity_convgr (graphics, rects [i].Height));
 
        /* We do brush setup just before filling. */
        gdip_brush_setup (graphics, brush);
@@ -1476,7 +1646,9 @@
        /* We use graphics->copy_of_ctm matrix for path creation. We
         * should have it set already.
         */
-       make_pie (graphics, x, y, width, height, startAngle, sweepAngle, 0, 0);
+       make_pie (graphics, gdip_unitx_convgr (graphics, x), gdip_unity_convgr 
(graphics, y), 
+               gdip_unitx_convgr (graphics, width), gdip_unity_convgr 
(graphics, height), 
+               startAngle, sweepAngle, 0, 0);
 
        /* We do brush setup just before filling. */
        gdip_brush_setup (graphics, brush);
@@ -1663,7 +1835,9 @@
         * should have it set already.
         */
         for (i = 0, rect = region->rects; i < region->cnt; i++, rect++)
-               cairo_rectangle (graphics->ct, rect->X, rect->Y, rect->Width, 
rect->Height);
+               cairo_rectangle (graphics->ct, 
+                       gdip_unitx_convgr (graphics, rect->X), 
gdip_unity_convgr (graphics, rect->Y), 
+                       gdip_unitx_convgr (graphics, rect->Width), 
gdip_unity_convgr (graphics, rect->Height));
 
        /* We do brush setup just before filling. */
        gdip_brush_setup (graphics, brush);
@@ -1750,7 +1924,7 @@
 #endif
 
 GpStatus
-MeasureOrDrawString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int 
length, GDIPCONST GpFont *font, GDIPCONST RectF *rc, GDIPCONST GpStringFormat 
*format, GpBrush *brush, RectF *boundingBox, int *codepointsFitted, int 
*linesFilled, int draw)
+MeasureOrDrawString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int 
length, GDIPCONST GpFont *font, GDIPCONST RectF *rc_org, GDIPCONST 
GpStringFormat *format, GpBrush *brush, RectF *boundingBox, int 
*codepointsFitted, int *linesFilled, int draw)
 {
        unsigned char           *String;                /* Holds the UTF8 
version of our sanitized string */
        WCHAR                   *CleanString;           /* Holds the unicode 
version of our sanitized string */
@@ -1782,12 +1956,18 @@
        cairo_font_extents_t    FontExtent;             /* Info about our font 
*/
        bool                    SetClipping=FALSE;      /* If clipping has been 
set */
        cairo_font_options_t    *FontOptions;
+       RectF                   rc_coords, *rc = &rc_coords;
 
        /* Sanity; should we check for length==0? */
        if (!graphics || !stringUnicode || !font) {
                return(InvalidParameter);
        }
 
+       rc->X = gdip_unitx_convgr (graphics, rc_org->X);
+       rc->Y = gdip_unity_convgr (graphics, rc_org->Y);
+       rc->Width = gdip_unitx_convgr (graphics, rc_org->Width);
+       rc->Height = gdip_unity_convgr (graphics, rc_org->Height);
+
 #ifdef DRAWSTRING_DEBUG
        printf("GdipDrawString(...) called (length=%d, fontsize=%d)\n", length, 
(int)font->sizeInPixels);
 #endif
@@ -3252,7 +3432,7 @@
        g_return_val_if_fail (graphics != NULL, InvalidParameter);
        g_return_val_if_fail (dpi != NULL, InvalidParameter);
 
-       *dpi = gdip_get_display_dpi ();
+       *dpi = graphics->dpi_x;
         return Ok;
 }
 
@@ -3262,7 +3442,7 @@
        g_return_val_if_fail (graphics != NULL, InvalidParameter);
        g_return_val_if_fail (dpi != NULL, InvalidParameter);
 
-       *dpi = gdip_get_display_dpi ();
+       *dpi = graphics->dpi_y;
         return Ok;
 }
 
@@ -3816,6 +3996,9 @@
        if (!graphics) 
                return InvalidParameter;
 
+       if (unit == UnitWorld || unit == UnitMillimeter)
+               return InvalidParameter;
+
        graphics->page_unit = unit;
        return Ok;
 }

Modified: trunk/libgdiplus/src/image.c
===================================================================
--- trunk/libgdiplus/src/image.c        2006-01-15 21:20:28 UTC (rev 55609)
+++ trunk/libgdiplus/src/image.c        2006-01-15 21:20:32 UTC (rev 55610)
@@ -137,6 +137,7 @@
                                bmp->data.Width, bmp->data.Height, 
bmp->data.Stride);
 
        gfx = gdip_graphics_new (surface);
+       gfx->dpi_x = gfx->dpi_y = gdip_get_display_dpi ();
        cairo_surface_destroy (surface);
 
        gfx->image = bmp;
@@ -151,7 +152,7 @@
 #include <cairo-ps.h>
 
 GpStatus 
-GdipGetPostScriptGraphicsContext (char* filename, int width, int height, 
GpGraphics **graphics)
+GdipGetPostScriptGraphicsContext (char* filename, int width, int height, 
double dpix, double dpiy, GpGraphics **graphics)
 {
        GpGraphics *gfx;
        cairo_surface_t *surface;
@@ -160,8 +161,11 @@
                return InvalidParameter;
 
        surface = cairo_ps_surface_create (filename, (double) width, (double) 
height);
+       cairo_ps_surface_set_dpi (surface, dpix, dpiy);
 
        gfx = gdip_graphics_new (surface);
+       gfx->dpi_x = dpix;
+       gfx->dpi_y = dpiy;
        cairo_surface_destroy (surface);
 
        gfx->type = gtPostScript;
@@ -207,6 +211,11 @@
        g_return_val_if_fail (graphics != NULL, InvalidParameter);
        g_return_val_if_fail (image != NULL, InvalidParameter);
        g_return_val_if_fail (image->type == imageBitmap, InvalidParameter);
+
+       x = gdip_unitx_convgr (graphics, x);
+       y = gdip_unity_convgr (graphics, y);
+       width = gdip_unitx_convgr (graphics, width);
+       height = gdip_unity_convgr (graphics, height);
        
        cairo_new_path(graphics->ct);
 
@@ -339,7 +348,6 @@
 {
        return GdipDrawImagePointRect (graphics, image, x, y, srcx, srcy, 
srcwidth, srcheight, srcUnit);
 }
-
 GpStatus
 GdipDrawImageRectRect (GpGraphics *graphics, GpImage *image,
                        float dstx, float dsty, float dstwidth, float dstheight,
@@ -380,14 +388,14 @@
        }
 
        if (srcUnit != UnitPixel && srcUnit != UnitWorld) {
-               gdip_unitConversion(srcUnit, UnitPixel, dstx, &dstx);
-               gdip_unitConversion(srcUnit, UnitPixel, dsty, &dsty);
-               gdip_unitConversion(srcUnit, UnitPixel, dstwidth, &dstwidth);
-               gdip_unitConversion(srcUnit, UnitPixel, dstheight, &dstheight);
-               gdip_unitConversion(srcUnit, UnitPixel, srcx, &srcx);
-               gdip_unitConversion(srcUnit, UnitPixel, srcy, &srcy);
-               gdip_unitConversion(srcUnit, UnitPixel, srcwidth, &dstwidth);
-               gdip_unitConversion(srcUnit, UnitPixel, srcheight, &srcheight);
+               gdip_unit_conversion (srcUnit, UnitCairoPoint, graphics->type, 
graphics->dpi_x, dstx, &dstx);
+               gdip_unit_conversion (srcUnit, UnitCairoPoint, graphics->type, 
graphics->dpi_y, dsty, &dsty);
+               gdip_unit_conversion (srcUnit, UnitCairoPoint, graphics->type, 
graphics->dpi_x, dstwidth, &dstwidth);
+               gdip_unit_conversion (srcUnit, UnitCairoPoint, graphics->type, 
graphics->dpi_y, dstheight, &dstheight);
+               gdip_unit_conversion (srcUnit, UnitCairoPoint, graphics->type, 
graphics->dpi_x, srcx, &srcx);
+               gdip_unit_conversion (srcUnit, UnitCairoPoint, graphics->type, 
graphics->dpi_y, srcy, &srcy);
+               gdip_unit_conversion (srcUnit, UnitCairoPoint, graphics->type, 
graphics->dpi_x, srcwidth, &dstwidth);
+               gdip_unit_conversion (srcUnit, UnitCairoPoint, graphics->type, 
graphics->dpi_y, srcheight, &srcheight);
        }
 
        org = dest = bitmap->data.Scan0; 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to