gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog backend/render_handler_cairo.cpp


From: Bastiaan Jacques
Subject: [Gnash-commit] gnash ChangeLog backend/render_handler_cairo.cpp
Date: Tue, 27 May 2008 04:11:34 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Bastiaan Jacques <bjacques>     08/05/27 04:11:34

Modified files:
        .              : ChangeLog 
        backend        : render_handler_cairo.cpp 

Log message:
        Don't apply the shape matrix to
        patterns, because that's already taken care of in
        draw_shape_character. Implement focal gradients. Shift all pixel
        positions by one half, so that single width lines will show up.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6714&r2=1.6715
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/render_handler_cairo.cpp?cvsroot=gnash&r1=1.42&r2=1.43

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6714
retrieving revision 1.6715
diff -u -b -r1.6714 -r1.6715
--- ChangeLog   26 May 2008 22:13:32 -0000      1.6714
+++ ChangeLog   27 May 2008 04:11:32 -0000      1.6715
@@ -1,5 +1,12 @@
 2008-05-26 Bastiaan Jacques <address@hidden>
 
+       * backend/render_handler_cairo.cpp: Don't apply the shape matrix to
+       patterns, because that's already taken care of in
+       draw_shape_character. Implement focal gradients. Shift all pixel
+       positions by one half, so that single width lines will show up.
+
+2008-05-26 Bastiaan Jacques <address@hidden>
+
        * gui/aqua.cpp: Remove function reports and define _width and
        _height.
        * gui/aqua_ogl_glue.cpp: Enable the accumulation buffer. Don't

Index: backend/render_handler_cairo.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/render_handler_cairo.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- backend/render_handler_cairo.cpp    23 May 2008 11:00:50 -0000      1.42
+++ backend/render_handler_cairo.cpp    27 May 2008 04:11:34 -0000      1.43
@@ -21,7 +21,6 @@
 // - The current coordinate system 
 //
 // TODOs:
-// - Implement focal gradients.
 // - Implement unimplemented methods.
 // - Would be nice to have a header/implementation separation.
 // - Document workings of Cairo and this renderer.
@@ -33,7 +32,7 @@
 //
 // Already implemented:
 // - outlines
-// - fills: solid, linear, radial and bitmap
+// - fills: solid, linear, radial, focal and bitmap
 // - bitmaps
 // - fonts
 // - masks
@@ -342,6 +341,17 @@
     cairo_device_to_user(cr, &x, &y);
   }
 
+  static void
+  snap_to_half_pixel(cairo_t* cr, double& x, double& y)
+  {
+    cairo_user_to_device(cr, &x, &y);
+
+    x = std::floor(x + 0.5) + 0.5;
+    y = std::floor(y + 0.5) + 0.5;
+   
+    cairo_device_to_user(cr, &x, &y);
+  }
+
   virtual void  begin_display(
     const rgba& bg_color,
     int viewport_x0, int viewport_y0,
@@ -479,19 +489,23 @@
     _masks.pop_back();
   }
 
-  void add_path(cairo_t* cr, const path& cur_path)
+  void add_path(cairo_t* cr, const path& cur_path, bool round_to_half = false)
   {  
-    cairo_move_to(cr, cur_path.ap.x, cur_path.ap.y);
+    double x = cur_path.ap.x;
+    double y = cur_path.ap.y;
     
-    int prev_x = cur_path.ap.x,
-        prev_y = cur_path.ap.y;
+    snap_to_half_pixel(cr, x, y);
+    cairo_move_to(cr, x, y);
     
     for (std::vector<edge>::const_iterator it = cur_path.m_edges.begin(),
          end = cur_path.m_edges.end(); it != end; ++it) {
       const edge& cur_edge = *it;
       
       if (cur_edge.is_straight()) {
-        cairo_line_to(cr, cur_edge.ap.x, cur_edge.ap.y);
+        x = cur_edge.ap.x;
+        y = cur_edge.ap.y;
+        snap_to_half_pixel(cr, x, y);
+        cairo_line_to(cr, x, y);
       } else {
       
         // Cairo expects a cubic Bezier curve, while Flash gives us a
@@ -500,24 +514,22 @@
         const float two_thirds = 2.0/3.0;
         const float one_third = 1 - two_thirds;
         
-        float x1 = prev_x + two_thirds * (cur_edge.cp.x - prev_x);
-        float y1 = prev_y + two_thirds * (cur_edge.cp.y - prev_y);
+        double x1 = x + two_thirds * (cur_edge.cp.x - x);
+        double y1 = y + two_thirds * (cur_edge.cp.y - y);
         
-        float x2 = cur_edge.cp.x + one_third * (cur_edge.ap.x - cur_edge.cp.x);
-        float y2 = cur_edge.cp.y + one_third * (cur_edge.ap.y - cur_edge.cp.y);
+        double x2 = cur_edge.cp.x + one_third * (cur_edge.ap.x - 
cur_edge.cp.x);
+        double y2 = cur_edge.cp.y + one_third * (cur_edge.ap.y - 
cur_edge.cp.y);
         
-        const int& x3 = cur_edge.ap.x;
-        const int& y3 = cur_edge.ap.y;
+        x = cur_edge.ap.x;
+        y = cur_edge.ap.y;
     
+        snap_to_half_pixel(cr, x1, y1);
+        snap_to_half_pixel(cr, x2, y2);
+        snap_to_half_pixel(cr, x, y);    
     
-        cairo_curve_to(cr, x1, y1, x2, y2, x3, y3);
+        cairo_curve_to(cr, x1, y1, x2, y2, x, y);
       }
-      
-      prev_x = cur_edge.ap.x;
-      prev_y = cur_edge.ap.y;
-      
     }
-  
   }
   
   
@@ -546,8 +558,10 @@
     float width = style.getThickness();
 
     if ( width == 0.0 ) {
-      // TODO: test this!
-      cairo_set_line_width(_cr, 20.0); // expected: 1 pixel
+      double hwidth = 1.0;
+
+      cairo_device_to_user_distance(_cr, &hwidth, &hwidth);
+      cairo_set_line_width(_cr, hwidth);
     } else {
       // TODO: this is correct for !style.scaleThicknessVertically() 
       //       and !style.scaleThicknessHorizontally().
@@ -609,9 +623,6 @@
       case SWF::FILL_LINEAR_GRADIENT:
       {
         matrix m = style.get_gradient_matrix();
-        matrix cm;
-        cm.set_inverse(mat);
-        m.concatenate(cm);         
       
         cairo_matrix_t mat;
         init_cairo_matrix(&mat, m);
@@ -624,13 +635,11 @@
         break;
       }
       case SWF::FILL_RADIAL_GRADIENT:
+      case SWF::FILL_FOCAL_GRADIENT:
       {        
         matrix m = style.get_gradient_matrix();
-        matrix cm;
-        cm.set_inverse(mat);
-        m.concatenate(cm);
         
-        // move the center of the radial fill to where it should be, according 
to Udo
+        // Undo the translation our parser applied.
         gnash::matrix transl;
         transl.concatenate_translation(-32.0f, -32.0f);
         transl.concatenate(m);  
@@ -638,19 +647,19 @@
         cairo_matrix_t mat;
         init_cairo_matrix(&mat, transl);
         
-        pattern = cairo_pattern_create_radial(0.0, 0.0, 0.0, 0.0, 0.0, 32.0);
+        double focal_pos = 0;
+        
+        if (fill_type == SWF::FILL_FOCAL_GRADIENT) {
+          focal_pos = 32.0f * style.get_focal_point();
+        }
+
+        pattern = cairo_pattern_create_radial(focal_pos, 0.0, 0.0, 0.0, 0.0, 
32.0);
 
         cairo_pattern_set_matrix (pattern, &mat);          
         
         pattern_add_color_stops(style, pattern, cx);
         break;
       }
-      case SWF::FILL_FOCAL_GRADIENT:
-      {
-        log_unimpl("focal gradient fill");
-        
-        break;
-      }              
       case SWF::FILL_TILED_BITMAP_HARD:
       case SWF::FILL_TILED_BITMAP:
       case SWF::FILL_CLIPPED_BITMAP:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]