Пример #1
0
int 
connpointline_adjust_count(ConnPointLine *cpl,
			   int newcount, Point *where)
{
  int oldcount,delta;

  oldcount = cpl->num_connections;

  if (newcount < 0) newcount = 0;

  delta = newcount - oldcount;
  if (delta != 0) {
    ObjectChange *change;
    /*g_message("going to adjust %d (to be %d)",delta,shouldbe);*/
   
    if (delta > 0) {
      change = connpointline_add_points(cpl, where, delta);
    } else { 
      change = connpointline_remove_points(cpl, where, -delta);
    }
    if (change->free) change->free(change);
    g_free(change); /* we don't really need this change object. */
  }    


  return oldcount;
}
Пример #2
0
/*!
 */
void
DiaOutputDev::_fill (GfxState *state, bool winding)
{
  GArray *points = g_array_new (FALSE, FALSE, sizeof(BezPoint));
  DiaObject *obj = NULL;
  GfxPath *path = state->getPath();
  bool haveClose = true;

  if (doPath (points, state, path, haveClose) && points->len > 2) {
    if (path->getNumSubpaths() == 1 && haveClose)
      obj = create_standard_beziergon (points->len, &g_array_index (points, BezPoint, 0));
    else
      obj = create_standard_path (points->len, &g_array_index (points, BezPoint, 0));
    applyStyle (obj, true);
    if (this->pattern) {
      ObjectChange *change = dia_object_set_pattern (obj, this->pattern);
      if (change) {
	change->free (change);
	g_free (change);
      }
    }
  }
  g_array_free (points, TRUE);
  if (obj) {
    // Useful for debugging but high performance penalty 
    // dia_object_set_meta (obj, "fill-rule", winding ? "winding" : "even-odd");
    addObject (obj);
  }
}
Пример #3
0
static ObjectChange *
flow_set_type_callback (DiaObject* obj, Point* clicked, gpointer data)
{
  ObjectChange *change;

  change = type_create_change((Flow *)obj, GPOINTER_TO_INT(data));
  change->apply(change, obj);

  return change;
}
Пример #4
0
static ObjectChange *
box_set_aspect_callback (DiaObject* obj, Point* clicked, gpointer data)
{
  ObjectChange *change;

  change = aspect_create_change((Box*)obj, (AspectType)data);
  change->apply(change, obj);

  return change;
}
Пример #5
0
ObjectChange *
connpointline_remove_points(ConnPointLine *cpl, 
			     Point *clickedpoint, int count)
{
  int pos;
  ObjectChange *change;

  pos = cpl_get_pointbefore(cpl,clickedpoint);
  change = cpl_create_change(cpl,pos,-count);

  change->apply(change, (DiaObject *)cpl);
  return change;
}
Пример #6
0
/*!
 * \brief Draw an image to Dia's _Image
 * \todo use maskColors to have some alpha support
 */
void
DiaOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
			int width, int height, GfxImageColorMap *colorMap,
			GBool interpolate, int *maskColors, GBool inlineImg)
{
  DiaObject *obj;
  GdkPixbuf *pixbuf;
  Point pos;
  ObjectChange *change;
  double *ctm = state->getCTM();

  pos.x = ctm[4] * scale;
  // there is some undocumented magic done with the ctm for drawImage
  // deduced from SplashOutputDev::drawImage()
  // cmt[2] and ctm[3] being negative - use that for y postion
  // ctm[0] and ctm[3] have width and height in device coordinates
  pos.y = (ctm[5] + ctm[3]) * scale;

  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, maskColors ? TRUE : FALSE, 8, width, height);

  {
     // 3 channels, 8 bit
    ImageStream imgStr(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
    Guchar *line;
    int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
    guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
    int y;

    imgStr.reset(); // otherwise getLine() is crashing right away
    line = imgStr.getLine ();
    for (y = 0; y < height && line; ++y) {
      guchar *dest = pixels + y * rowstride;

      colorMap->getRGBLine (line, dest, width);

      // ToDo: respect maskColors

      line = imgStr.getLine ();
    }
  }
  obj = create_standard_image (pos.x, pos.y, 
			       ctm[0]  * scale,
			       ctm[3]  * scale, NULL);
  if ((change = dia_object_set_pixbuf (obj, pixbuf)) != NULL)
    change->free (change); /* reference transfered */
  else
    g_object_unref (pixbuf);

  addObject (obj);
}
Пример #7
0
Файл: menus.c Проект: GNOME/dia
static void
plugin_callback (GtkWidget *widget, gpointer data)
{
  DiaCallbackFilter *cbf = data;

  /* check if the callback filter is still available */
  if (!g_list_find (filter_get_callbacks (), cbf)) {
    message_error (_("The function is not available anymore."));
    return;
  }
  /* and finally invoke it */
  if (cbf->callback) {
    DDisplay *ddisp = NULL;
    DiagramData* diadata = NULL;
    ObjectChange *change;
    /* stuff from the toolbox menu should never get a diagram to modify */
    if (strncmp (cbf->menupath, TOOLBOX_MENU, strlen (TOOLBOX_MENU)) != 0) {
      ddisp = ddisplay_active();
      diadata = ddisp ? ddisp->diagram->data : NULL;
    }
    change = cbf->callback (diadata, ddisp ? ddisp->diagram->filename : NULL, 0, cbf->user_data);
    if (change != NULL) {
      if (ddisp) {
        undo_object_change(ddisp->diagram, NULL, change);
	/*
	 * - can not call object_add_update() w/o object
	 * - could call object_add_updates_list() with the selected objects,
	 *   but that would just be an educated guess (layout working on selection)
	 */
	diagram_add_update_all(ddisp->diagram);
        diagram_modified(ddisp->diagram);
        diagram_update_extents(ddisp->diagram);
        undo_set_transactionpoint(ddisp->diagram->undo);
      } else { /* no diagram to keep the change, throw it away */
        if (change->free)
          change->free(change);
        g_free(change);
      }
    }
  }
}
Пример #8
0
/*!
 * \brief Draw an image to Dia's _Image
 * \todo use maskColors to have some alpha support
 */
void
DiaOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
			int width, int height, GfxImageColorMap *colorMap,
			GBool interpolate, int *maskColors, GBool inlineImg)
{
  DiaObject *obj;
  GdkPixbuf *pixbuf;
  Point pos;
  ObjectChange *change;
  double *ctm = state->getCTM();

  pos.x = ctm[4] * scale;
  // there is some undocumented magic done with the ctm for drawImage
  // deduced from SplashOutputDev::drawImage()
  // cmt[2] and ctm[3] being negative - use that for y postion
  // ctm[0] and ctm[3] have width and height in device coordinates
  pos.y = (ctm[5] + ctm[3]) * scale;
#ifdef USE_IMAGE_CACHE /* bogus: neither 'ref' nor  'str' work as unique key */
  // rather than creating the image over and over again we try to cache them
  // via the given 'stream' object
  if ((pixbuf = static_cast<GdkPixbuf*>(g_hash_table_lookup (this->image_cache, str))) != NULL) {
    g_object_ref (pixbuf);
  } else {
#endif
    pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, maskColors ? TRUE : FALSE, 8, width, height);

    {
       // 3 channels, 8 bit
      ImageStream imgStr(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
      Guchar *line;
      int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
      guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
      int y;

      imgStr.reset(); // otherwise getLine() is crashing right away
      line = imgStr.getLine ();
      for (y = 0; y < height && line; ++y) {
	guchar *dest = pixels + y * rowstride;

	colorMap->getRGBLine (line, dest, width);

	if (maskColors) {
	  for (int x = 0; x < width; x++) {
	    bool is_opaque = false;
	    for (int i = 0; i < colorMap->getNumPixelComps(); ++i) {
	      if (line[i] < maskColors[2*i] ||
		  line[i] > maskColors[2*i+1]) {
		is_opaque = true;
		break;
	      }
	    }
	    if (is_opaque)
	      *dest |= 0xff000000;
	    else
	      *dest = 0;
	    dest++;
	    line += colorMap->getNumPixelComps();
	  }
	}

	line = imgStr.getLine ();
      }
    }
#ifdef USE_IMAGE_CACHE
    // insert the new image into our cache
    g_hash_table_insert (this->image_cache, str, g_object_ref (pixbuf));
  }
#endif
  obj = create_standard_image (pos.x, pos.y, 
			       ctm[0]  * scale,
			       ctm[3]  * scale, NULL);
  if ((change = dia_object_set_pixbuf (obj, pixbuf)) != NULL) {
    change->free (change);
    g_free (change);
  }

  g_object_unref (pixbuf);

  addObject (obj);
}