Code

do calligraphic draw opacity correctly
authorbuliabyak <buliabyak@users.sourceforge.net>
Wed, 17 May 2006 06:57:31 +0000 (06:57 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Wed, 17 May 2006 06:57:31 +0000 (06:57 +0000)
src/desktop-style.cpp
src/desktop-style.h
src/dyna-draw-context.cpp

index afb3a104528f62dff82213ee53114ba488f13771..cf8f67442d59941d824090486ee57d7e41af7b75 100644 (file)
@@ -222,12 +222,12 @@ sp_desktop_get_color(SPDesktop *desktop, bool is_fill)
 }
 
 double
-sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool, bool op)
+sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool)
 {
     SPCSSAttr *css = NULL;
     gfloat value = 1.0; // default if nothing else found
     if (prefs_get_double_attribute(tool, "usecurrent", 0) != 0) {
-        css = sp_desktop_get_style(desktop, op);
+        css = sp_desktop_get_style(desktop, true);
     } else { 
         Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
         css = sp_repr_css_attr_inherited(tool_repr, "style");
@@ -240,6 +240,11 @@ sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool, bool op)
             value = 1.0; // things failed. set back to the default
         }
     }
+
+    if (css) {
+        sp_repr_css_attr_unref(css);
+    }
+
     return value;
 }
 guint32
@@ -247,10 +252,8 @@ sp_desktop_get_color_tool(SPDesktop *desktop, char const *tool, bool is_fill)
 {
     SPCSSAttr *css = NULL;
     guint32 r = 0; // if there's no color, return black
-    bool op = true;
-    double opacity = sp_desktop_get_opacity_tool(SP_ACTIVE_DESKTOP, "tools.calligraphic", op);
     if (prefs_get_int_attribute(tool, "usecurrent", 0) != 0) {
-        css = sp_desktop_get_style(desktop, is_fill);
+        css = sp_desktop_get_style(desktop, true);
     } else {
         Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
         css = sp_repr_css_attr_inherited(tool_repr, "style");
@@ -264,7 +267,12 @@ sp_desktop_get_color_tool(SPDesktop *desktop, char const *tool, bool is_fill)
             r = sp_svg_read_color(property, r);
         }
     }
-    return r | SP_COLOR_F_TO_U( opacity ); // return RGBA color
+
+    if (css) {
+        sp_repr_css_attr_unref(css);
+    }
+
+    return r | 0xff;
 }
 /**
  * Apply the desktop's current style or the tool style to repr.
@@ -283,7 +291,8 @@ sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, char
             sp_repr_css_attr_unref(css);
         }
     }
-    if (css_current) {sp_repr_css_attr_unref(css_current);
+    if (css_current) {
+        sp_repr_css_attr_unref(css_current);
     }
 }
 
index cec36aca523c73c2cdd1e4001344ed68ed3953d6..5171ae627f49842e2770bb67c5bbe1ca5fd12868 100644 (file)
@@ -54,7 +54,7 @@ void sp_desktop_set_color(SPDesktop *desktop, ColorRGBA const &color, bool is_re
 void sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change = true, bool write_current = true);
 SPCSSAttr *sp_desktop_get_style(SPDesktop *desktop, bool with_text);
 guint32 sp_desktop_get_color (SPDesktop *desktop, bool is_fill);
-double sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool, bool op);
+double sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool);
 guint32 sp_desktop_get_color_tool(SPDesktop *desktop, char const *tool, bool is_fill);
 double sp_desktop_get_font_size_tool (SPDesktop *desktop);
 void sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, char const *tool, bool with_text);
index ebabeef317eb06b74271a86c246a88b55480fdd7..ff570fb62b7b6d355eb4803294fe9fb2dbdc760f 100644 (file)
@@ -46,6 +46,7 @@
 #include "context-fns.h"
 #include "sp-item.h"
 #include "inkscape.h"
+#include "color.h"
 
 #define DDC_RED_RGBA 0xff0000ff
 
@@ -806,9 +807,10 @@ fit_and_split_calligraphics(SPDynaDrawContext *dc, gboolean release)
             SPCurve *curve = sp_curve_copy(dc->currentcurve);
             sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve);
             sp_curve_unref(curve);
-            guint32 fillColor = sp_desktop_get_color_tool(SP_ACTIVE_DESKTOP, "tools.calligraphic", true);
-            sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cbp), fillColor , SP_WIND_RULE_EVENODD);
 
+            guint32 fillColor = sp_desktop_get_color_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", true);
+            double opacity = sp_desktop_get_opacity_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic");
+            sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cbp), ((fillColor & 0xffffff00) | SP_COLOR_F_TO_U(opacity)), SP_WIND_RULE_EVENODD);
             sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cbp), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
             /* fixme: Cannot we cascade it to root more clearly? */
             g_signal_connect(G_OBJECT(cbp), "event", G_CALLBACK(sp_desktop_root_handler), SP_EVENT_CONTEXT(dc)->desktop);