Code

now act on settings in dialogue
[inkscape.git] / src / extension / internal / cairo-render-context.cpp
index 61d40ea4eca2bea2d18e5210ca065e6a88866535..d7fbbc1aa90aac4939567c01612c4ace0a13290b 100644 (file)
@@ -16,8 +16,6 @@
 # include "config.h"
 #endif
 
-#ifdef HAVE_CAIRO_PDF
-
 #ifndef PANGO_ENABLE_BACKEND
 #define PANGO_ENABLE_BACKEND
 #endif
@@ -72,7 +70,7 @@
 #endif
 
 
-#ifndef PANGO_ENABLE_BACKEND
+#ifdef CAIRO_HAS_FT_FONT
 #include <cairo-ft.h>
 #endif
 
@@ -106,6 +104,11 @@ static cairo_status_t _write_callback(void *closure, const unsigned char *data,
 
 CairoRenderContext::CairoRenderContext(CairoRenderer *parent) :
     _dpi(72),
+    _pdf_level(0),
+    _ps_level(1),
+    _is_texttopath(FALSE),
+    _is_filtertobitmap(FALSE),
+    _bitmapresolution(72),
     _stream(NULL),
     _is_valid(FALSE),
     _vector_based_target(FALSE),
@@ -156,6 +159,7 @@ CairoRenderContext::setStateForStyle(SPStyle const *style)
     // only opacity & overflow is stored for now
     _state->opacity = SP_SCALE24_TO_FLOAT(style->opacity.value);
     _state->has_overflow = (style->overflow.set && style->overflow.value != SP_CSS_OVERFLOW_VISIBLE);
+    _state->has_filtereffect = (style->filter.set != 0) ? TRUE : FALSE;
 
     if (style->fill.isPaintserver() || style->stroke.isPaintserver())
         _state->merge_opacity = FALSE;
@@ -386,6 +390,46 @@ CairoRenderContext::setPsTarget(gchar const *utf8_fn)
     return true;
 }
 
+void CairoRenderContext::setPSLevel(unsigned int level)
+{
+    _ps_level = level;
+}
+
+unsigned int CairoRenderContext::getPSLevel(void)
+{
+    return _ps_level;
+}
+
+void CairoRenderContext::setPDFLevel(unsigned int level)
+{
+    _pdf_level = level;
+}
+
+void CairoRenderContext::setTextToPath(bool texttopath)
+{
+    _is_texttopath = texttopath;
+}
+
+void CairoRenderContext::setFilterToBitmap(bool filtertobitmap)
+{
+    _is_filtertobitmap = filtertobitmap;
+}
+
+bool CairoRenderContext::getFilterToBitmap(void)
+{
+    return _is_filtertobitmap;
+}
+
+void CairoRenderContext::setBitmapResolution(int resolution)
+{
+    _bitmapresolution = resolution;
+}
+
+int CairoRenderContext::getBitmapResolution(void)
+{
+    return _bitmapresolution;
+}
+
 cairo_surface_t*
 CairoRenderContext::getSurface(void)
 {
@@ -450,6 +494,7 @@ CairoRenderContext::_createState(void)
     CairoRenderState *state = (CairoRenderState*)g_malloc(sizeof(CairoRenderState));
     g_assert( state != NULL );
 
+    state->has_filtereffect = FALSE;
     state->merge_opacity = TRUE;
     state->opacity = 1.0;
     state->need_layer = FALSE;
@@ -649,6 +694,10 @@ CairoRenderContext::addClippingRect(double x, double y, double width, double hei
 bool
 CairoRenderContext::setupSurface(double width, double height)
 {
+    // Is the surface already set up?
+    if (_is_valid)
+        return true;
+
     if (_vector_based_target && _stream == NULL)
         return false;
 
@@ -665,6 +714,12 @@ CairoRenderContext::setupSurface(double width, double height)
 #ifdef CAIRO_HAS_PS_SURFACE
         case CAIRO_SURFACE_TYPE_PS:
             surface = cairo_ps_surface_create_for_stream(Inkscape::Extension::Internal::_write_callback, _stream, width, height);
+#if (CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 2))
+            if(CAIRO_STATUS_SUCCESS != cairo_surface_status(surface)) {
+                return FALSE;
+            }
+            cairo_ps_surface_restrict_to_level (surface, (cairo_ps_level_t)_ps_level);
+#endif
             break;
 #endif
         default:
@@ -672,6 +727,32 @@ CairoRenderContext::setupSurface(double width, double height)
             break;
     }
 
+    return _finishSurfaceSetup (surface);
+}
+
+bool
+CairoRenderContext::setSurfaceTarget(cairo_surface_t *surface, bool is_vector)
+{
+    if (_is_valid || !surface)
+        return false;
+
+    _vector_based_target = is_vector;
+    bool ret = _finishSurfaceSetup (surface);
+    if (ret)
+        cairo_surface_reference (surface);
+    return ret;
+}
+
+bool
+CairoRenderContext::_finishSurfaceSetup(cairo_surface_t *surface)
+{
+    if(surface == NULL) {
+        return FALSE;
+    }
+    if(CAIRO_STATUS_SUCCESS != cairo_surface_status(surface)) {
+        return FALSE;
+    }
+
     _cr = cairo_create(surface);
     _surface = surface;
 
@@ -708,7 +789,7 @@ CairoRenderContext::finish(void)
 
     _is_valid = FALSE;
 
-    if (_vector_based_target) {
+    if (_vector_based_target && _stream) {
         /* Flush stream to be sure. */
         (void) fflush(_stream);
 
@@ -1170,7 +1251,7 @@ CairoRenderContext::renderPath(NRBPath const *bpath, SPStyle const *style, NRRec
                 cairo_set_fill_rule(_cr, CAIRO_FILL_RULE_WINDING);
             }
             cairo_fill(_cr);
-            cairo_surface_write_to_png (_surface, "gtar2.png");
+            TEST(cairo_surface_write_to_png (_surface, "pathmask.png"));
         }
         return true;
     }
@@ -1323,7 +1404,7 @@ CairoRenderContext::_showGlyphs(cairo_t *cr, PangoFont *font, std::vector<CairoG
         i++;
     }
 
-    if (is_stroke)
+    if (is_stroke || _is_texttopath)
         cairo_glyph_path(cr, glyphs, num_glyphs - num_invalid_glyphs);
     else
         cairo_show_glyphs(cr, glyphs, num_glyphs - num_invalid_glyphs);
@@ -1345,7 +1426,7 @@ CairoRenderContext::renderGlyphtext(PangoFont *font, NRMatrix const *font_matrix
 
     cairo_save(_cr);
 
-#ifndef PANGO_ENABLE_BACKEND
+#ifdef CAIRO_HAS_FT_FONT
     cairo_font_face_t *font_face = cairo_ft_font_face_create_for_pattern(fc_pattern);
     cairo_set_font_face(_cr, font_face);
 
@@ -1364,25 +1445,21 @@ CairoRenderContext::renderGlyphtext(PangoFont *font, NRMatrix const *font_matrix
             } else {
                 cairo_set_fill_rule(_cr, CAIRO_FILL_RULE_WINDING);
             }
-            cairo_set_source_rgba (_cr, 1.0, 1.0, 1.0, 1.0);
-            cairo_rectangle (_cr, 0, 0, 30, 40);
-            cairo_fill (_cr);
             _showGlyphs(_cr, font, glyphtext, FALSE);
-            //cairo_fill(_cr);
         } else {
             // just add the glyph paths to the current context
             _showGlyphs(_cr, font, glyphtext, TRUE);
         }
     } else {
 
-        if (style->fill.type == SP_PAINT_TYPE_COLOR || style->fill.type == SP_PAINT_TYPE_PAINTSERVER) {
+        if (style->fill.isColor() || style->fill.isPaintserver()) {
             // set fill style
             _setFillStyle(style, NULL);
 
             _showGlyphs(_cr, font, glyphtext, FALSE);
         }
 
-        if (style->stroke.type == SP_PAINT_TYPE_COLOR || style->stroke.type == SP_PAINT_TYPE_PAINTSERVER) {
+        if (style->stroke.isColor() || style->stroke.isPaintserver()) {
             // set stroke style
             _setStrokeStyle(style, NULL);
 
@@ -1398,6 +1475,8 @@ CairoRenderContext::renderGlyphtext(PangoFont *font, NRMatrix const *font_matrix
 #else
     (void)size;
     (void)fc_pattern;
+
+    cairo_restore(_cr);
 #endif
 
     return true;
@@ -1502,8 +1581,6 @@ _write_callback(void *closure, const unsigned char *data, unsigned int length)
 
 /* End of GNU GPL code */
 
-#endif /* HAVE_CAIRO_PDF */
-
 
 /*
   Local Variables: