Exemplo n.º 1
0
//pen dash
static void do_drawing(cairo_t *cr)
{
  cairo_set_source_rgba(cr, 0, 0, 0, 1);

  static const double dashed1[] = {4.0, 21.0, 2.0};
  static int len1  = sizeof(dashed1) / sizeof(dashed1[0]);

  static const double dashed2[] = {14.0, 6.0};
  static int len2  = sizeof(dashed2) / sizeof(dashed2[0]);

  static const double dashed3[] = {1.0};

  cairo_set_line_width(cr, 1.5);

  cairo_set_dash(cr, dashed1, len1, 0);

  cairo_move_to(cr, 40, 30);  
  cairo_line_to(cr, 200, 30);
  cairo_stroke(cr);

  cairo_set_dash(cr, dashed2, len2, 1);

  cairo_move_to(cr, 40, 50);  
  cairo_line_to(cr, 200, 50);
  cairo_stroke(cr);

  cairo_set_dash(cr, dashed3, 1, 0);

  cairo_move_to(cr, 40, 70);  
  cairo_line_to(cr, 200, 70);
  cairo_stroke(cr);  
}
Exemplo n.º 2
0
/**
 * uber_line_graph_stylize_line:
 * @graph: A #UberLineGraph.
 *
 * XXX
 *
 * Returns: None.
 * Side effects: None.
 */
static void
uber_line_graph_stylize_line (UberLineGraph *graph, /* IN */
                              LineInfo      *info,  /* IN */
                              cairo_t       *cr)    /* IN */
{
	UberLineGraphPrivate *priv;

	g_return_if_fail(UBER_IS_LINE_GRAPH(graph));
	g_return_if_fail(info != NULL);

	priv = graph->priv;
	if (info->dashes) {
		cairo_set_dash(cr, info->dashes, info->num_dashes, info->dash_offset);
	} else {
		cairo_set_dash(cr, NULL, 0, 0);
	}
	cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
	cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
	cairo_set_line_width(cr, info->width);
	cairo_set_antialias(cr, priv->antialias);
	cairo_set_source_rgba(cr,
	                      info->color.red / 65535.,
	                      info->color.green / 65535.,
	                      info->color.blue / 65535.,
	                      info->alpha);
}
Exemplo n.º 3
0
void iupDrawPolygon(IdrawCanvas* dc, int* points, int count, unsigned char r, unsigned char g, unsigned char b, int style)
{
  int i;

  cairo_set_source_rgba(dc->image_cr, iupCOLOR8ToDouble(r),
                                       iupCOLOR8ToDouble(g),
                                       iupCOLOR8ToDouble(b),
                                       1.0);

  if (style!=IUP_DRAW_FILL)
  {
    if (style==IUP_DRAW_STROKE_DASH)
    {
      double dashes[2];
      dashes[0] = 6.0;  dashes[1] = 2.0;
      cairo_set_dash(dc->image_cr, dashes, 2, 0);
    }
    else
      cairo_set_dash(dc->image_cr, 0, 0, 0);
  }

  cairo_move_to(dc->image_cr, points[0], points[1]);
  for (i=0; i<count; i++)
    cairo_line_to(dc->image_cr, points[2*i], points[2*i+1]);

  if (style==IUP_DRAW_FILL)
    cairo_fill(dc->image_cr);
  else
    cairo_stroke(dc->image_cr);
}
Exemplo n.º 4
0
int renderLineCairo(imageObj *img, shapeObj *p, strokeStyleObj *stroke) {
    int i,j;
    cairo_renderer *r = CAIRO_RENDERER(img);
    assert(stroke->color);
    cairo_new_path(r->cr);
    msCairoSetSourceColor(r->cr,stroke->color);
    for(i=0;i<p->numlines;i++) {
        lineObj *l = &(p->line[i]);
        cairo_move_to(r->cr,l->point[0].x,l->point[0].y);
        for(j=1;j<l->numpoints;j++) {
            cairo_line_to(r->cr,l->point[j].x,l->point[j].y);
        }
    }
    if(stroke->patternlength>0) {
        cairo_set_dash(r->cr,stroke->pattern,stroke->patternlength,0);
    }
    switch(stroke->linecap) {
        case MS_CJC_BUTT:
            cairo_set_line_cap(r->cr,CAIRO_LINE_CAP_BUTT);
            break;
        case MS_CJC_SQUARE:
            cairo_set_line_cap(r->cr,CAIRO_LINE_CAP_SQUARE);
            break;
        case MS_CJC_ROUND:
        case MS_CJC_NONE:
        default:
            cairo_set_line_cap(r->cr,CAIRO_LINE_CAP_ROUND);
    }
    cairo_set_line_width (r->cr, stroke->width);
    cairo_stroke (r->cr);
    if(stroke->patternlength>0) {
        cairo_set_dash(r->cr,stroke->pattern,0,0);
    }
    return MS_SUCCESS;
}
Exemplo n.º 5
0
void draw_links(struct ScreenContext *screenContext)
{
	struct Item *anEntry;
  	struct RGBO fillColor;
	double dashes[]={4.0, 4.0};
	int ndash = sizeof(dashes)/sizeof(dashes[0]);
	double offset = -10.0;

	fillColor.red = 255;
	fillColor.green = 0;
	fillColor.blue = 0;
	fillColor.opacity = 255;

	cairo_set_line_join(screenContext->cr_on_screen, CAIRO_LINE_JOIN_ROUND);
	cairo_set_line_cap(screenContext->cr_on_screen, CAIRO_LINE_CAP_BUTT);
	cairo_set_dash(screenContext->cr_on_screen, dashes, ndash, offset);

	anEntry = screenContext->links.head;
	while(anEntry != NULL) {
	      draw_single_road(screenContext, screenContext->cr_on_screen, anEntry->datap, &fillColor);
	      anEntry = anEntry->next;
	}

	cairo_set_dash(screenContext->cr_on_screen, dashes, 0, offset);	
}
Exemplo n.º 6
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    double dashes[2] = {20, 20};
    int a=0, b=0, c=0;

    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_paint (cr);

    for (a=0; a<4; a++)
    for (b=0; b<5; b++)
    for (c=0; c<5; c++) {
	cairo_move_to (cr, ((b*5)+c)*60+10, a*60+10);
	cairo_rel_line_to (cr, 0, b*10);
	cairo_rel_line_to (cr, c*10, 0);

	cairo_set_source_rgb (cr, 1, 1, 1);
	cairo_set_line_width (cr, 8);
	cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
	cairo_set_dash (cr, dashes, 2, a*10);
	cairo_stroke_preserve (cr);

	cairo_set_source_rgb (cr, 0, 0.5, 1);
	cairo_set_line_width (cr, 2);
	cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
	cairo_set_dash (cr, 0, 0, 0);
	cairo_stroke (cr);
    }
    return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 7
0
void GraphicsContext::setPlatformStrokeStyle(StrokeStyle strokeStyle)
{
    static double dashPattern[] = {5.0, 5.0};
    static double dotPattern[] = {1.0, 1.0};

    if (paintingDisabled())
        return;

    switch (strokeStyle) {
    case NoStroke:
        // FIXME: is it the right way to emulate NoStroke?
        cairo_set_line_width(platformContext()->cr(), 0);
        break;
    case SolidStroke:
#if ENABLE(CSS3_TEXT_DECORATION)
    case DoubleStroke:
    case WavyStroke: // FIXME: https://bugs.webkit.org/show_bug.cgi?id=94110 - Needs platform support.
#endif // CSS3_TEXT_DECORATION
        cairo_set_dash(platformContext()->cr(), 0, 0, 0);
        break;
    case DottedStroke:
        cairo_set_dash(platformContext()->cr(), dotPattern, 2, 0);
        break;
    case DashedStroke:
        cairo_set_dash(platformContext()->cr(), dashPattern, 2, 0);
        break;
    }
}
Exemplo n.º 8
0
void
gnm_style_border_set_dash (GnmStyleBorderType const i,
			   cairo_t *context)
{
	GdkLineStyle style = GDK_LINE_SOLID;
	int w;

	g_return_if_fail (context != NULL);
	g_return_if_fail (i >= GNM_STYLE_BORDER_NONE);
	g_return_if_fail (i < GNM_STYLE_BORDER_MAX);

	if (style_border_data[i].pattern != NULL)
		style = GDK_LINE_ON_OFF_DASH;

	w = style_border_data[i].width;
	if (w == 0)
		w = 1;
	cairo_set_line_width (context,((double) w));

	if (style_border_data[i].pattern != NULL) {
		struct LineDotPattern const * const pat =
			style_border_data[i].pattern;
		cairo_set_dash (context, pat->pattern_d, pat->elements,
				style_border_data[i].offset);
	} else
		cairo_set_dash (context, NULL, 0, 0);
}
Exemplo n.º 9
0
void iupDrawRectangle(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style)
{
  cairo_set_source_rgba(dc->image_cr, iupCOLOR8ToDouble(r),
                                       iupCOLOR8ToDouble(g),
                                       iupCOLOR8ToDouble(b),
                                       1.0);

  if (style==IUP_DRAW_FILL)
  {
    cairo_rectangle(dc->image_cr, x1, y1, x2-x1+1, y2-y1+1);
    cairo_fill(dc->image_cr);
  }
  else
  {
    if (style==IUP_DRAW_STROKE_DASH)
    {
      double dashes[2];
      dashes[0] = 6.0;  dashes[1] = 2.0;
      cairo_set_dash(dc->image_cr, dashes, 2, 0);
    }
    else
      cairo_set_dash(dc->image_cr, 0, 0, 0);

    cairo_rectangle(dc->image_cr, x1, y1, x2-x1, y2-y1);  /* outlined rectangle is actually of size w+1,h+1 */
    cairo_stroke(dc->image_cr);
  }
}
Exemplo n.º 10
0
void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle& strokeStyle)
{
    static double dashPattern[] = {5.0, 5.0};
    static double dotPattern[] = {1.0, 1.0};

    if (paintingDisabled())
        return;

    switch (strokeStyle) {
    case NoStroke:
        // FIXME: is it the right way to emulate NoStroke?
        cairo_set_line_width(m_data->cr, 0);
        break;
    case SolidStroke:
        cairo_set_dash(m_data->cr, 0, 0, 0);
        break;
    case DottedStroke:
        cairo_set_dash(m_data->cr, dotPattern, 2, 0);
        break;
    case DashedStroke:
        cairo_set_dash(m_data->cr, dashPattern, 2, 0);
        break;
    default:
        notImplemented();
        break;
    }
}
Exemplo n.º 11
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    const double dashes_1[] = { 10, 0 };
    const double dashes_2[] = { 10, 0, 10, 10};
    const double dashes_3[] = { 10, 0, 10, 0};

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);
    cairo_set_source_rgb (cr, 0, 0, 0);

    cairo_set_line_width (cr, 6);

    cairo_set_dash (cr, NULL, 0, 0);
    cairo_rectangle (cr, 10, 10, 30, 30);
    cairo_stroke (cr);

    cairo_translate (cr, 50, 0);
    cairo_set_dash (cr, dashes_1, 2, 0);
    cairo_rectangle (cr, 10, 10, 30, 30);
    cairo_stroke (cr);

    cairo_translate (cr, 0, 50);
    cairo_set_dash (cr, dashes_2, 4, 0);
    cairo_rectangle (cr, 10, 10, 30, 30);
    cairo_stroke (cr);

    cairo_translate (cr, -50, 0);
    cairo_set_dash (cr, dashes_3, 4, 0);
    cairo_rectangle (cr, 10, 10, 30, 30);
    cairo_stroke (cr);

    return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 12
0
void render_track_crossing(sem_render_context* ctx, sem_coordinate coord, sem_track* track) {
	render_track_path(ctx, coord, track);
	cairo_set_line_width(ctx->cr, ctx->style->track_crossing_width);
	const double dash[] = {0.2, 0.1};
	cairo_set_dash(ctx->cr, dash, 2, -0.1);
	cairo_stroke(ctx->cr);
	cairo_set_dash(ctx->cr, dash, 0, 0);
}
Exemplo n.º 13
0
static void
overlay_draw (GtkDrawingArea *da,
              cairo_t        *cr,
              int             width,
              int             height,
              gpointer        data)
{
  GtkWidget *widget = GTK_WIDGET (da);
  PangoLayout *layout;
  const double dashes[] = { 6, 18 };
  GtkAllocation label_allocation;
  GtkRequisition minimum_size, natural_size;
  GtkWidget *label = data;
  gint x, y;

  cairo_translate (cr, -0.5, -0.5);
  cairo_set_line_width (cr, 1);

  cairo_set_source_rgb (cr, 1, 1, 1);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_fill (cr);

  gtk_widget_translate_coordinates (label, widget, 0, 0, &x, &y);
  layout = gtk_widget_create_pango_layout (widget, "");

  gtk_widget_get_preferred_size (label, &minimum_size, &natural_size); 

  pango_layout_set_markup (layout,
    "<span color='#c33'>\342\227\217 requisition</span>\n"
    "<span color='#3c3'>\342\227\217 natural size</span>\n"
    "<span color='#33c'>\342\227\217 allocation</span>", -1);

  pango_cairo_show_layout (cr, layout);
  g_object_unref (layout);

  gtk_widget_get_allocation (label, &label_allocation);

  cairo_rectangle (cr,
                   x + 0.5 * (label_allocation.width - minimum_size.width),
                   y + 0.5 * (label_allocation.height - minimum_size.height),
                   minimum_size.width, minimum_size.height);
  cairo_set_source_rgb (cr, 0.8, 0.2, 0.2);
  cairo_set_dash (cr, NULL, 0, 0);
  cairo_stroke (cr);

  cairo_rectangle (cr, x, y, label_allocation.width, label_allocation.height);
  cairo_set_source_rgb (cr, 0.2, 0.2, 0.8);
  cairo_set_dash (cr, dashes, 2, 0.5);
  cairo_stroke (cr);

  cairo_rectangle (cr,
                   x + 0.5 * (label_allocation.width - natural_size.width),
                   y + 0.5 * (label_allocation.height - natural_size.height),
                   natural_size.width, natural_size.height);
  cairo_set_source_rgb (cr, 0.2, 0.8, 0.2);
  cairo_set_dash (cr, dashes, 2, 12.5);
  cairo_stroke (cr);
}
Exemplo n.º 14
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    double dashes[] = { 1 };

    /* We draw in the default black, so paint white first. */
    cairo_save (cr);
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
    cairo_paint (cr);
    cairo_restore (cr);

    cairo_set_line_width (cr, 2);

    /* Basic 1-1 dash pattern */
    cairo_set_dash (cr, dashes, 1, 0.);

    cairo_move_to (cr,  1, 2);
    cairo_line_to (cr, 18, 2);
    cairo_stroke (cr);

    /* Adjust path by 0.5. Ideally this would give a constant 50%
     * gray, (but does not due to the location of the regular sample
     * grid points. */
    cairo_move_to (cr, 1.5, 5);
    cairo_line_to (cr, 18., 5);
    cairo_stroke (cr);

    /* Offset dash by 0.5, rather than the path */
    cairo_set_dash (cr, dashes, 1, 0.5);

    cairo_move_to (cr,  1, 8);
    cairo_line_to (cr, 18, 8);
    cairo_stroke (cr);

    /* Now, similar tests with negative dash offsets. */

    /* Basic 1-1 dash pattern dashing */
    cairo_set_dash (cr, dashes, 1, -4);

    cairo_move_to (cr,  1, 11);
    cairo_line_to (cr, 18, 11);
    cairo_stroke (cr);

    /* Adjust path by 0.5 */
    cairo_move_to (cr, 1.5, 14);
    cairo_line_to (cr, 18., 14);
    cairo_stroke (cr);

    /* Offset dash by 0.5 */
    cairo_set_dash (cr, dashes, 1, -3.5);

    cairo_move_to (cr,  1, 17);
    cairo_line_to (cr, 18, 17);
    cairo_stroke (cr);

    return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 15
0
void distance_get_linestyle ( Distance d, cairo_t *draw )
{
    if ( d.style == DASH ) {
        const double dashes[1] = { 4 };
        cairo_set_dash ( draw, dashes, 1, 0.0 );
    }
    else {
        cairo_set_dash ( draw, NULL, 0, 0.0 );
    }
}
Exemplo n.º 16
0
void
Grid::PostRender (Context *ctx, Region *region, bool skip_children)
{
	// render our chidren if we need to
	if (!skip_children) {
		VisualTreeWalker walker = VisualTreeWalker (this, ZForward, false);
		while (UIElement *child = walker.Step ())
			child->DoRender (ctx, region);
	}
	
	if (GetShowGridLines () && ctx->IsMutable ()) {
		double offset = 0;
		double dash = 4;
		ColumnDefinitionCollection *cols = GetColumnDefinitionsNoAutoCreate ();
		RowDefinitionCollection *rows = GetRowDefinitionsNoAutoCreate ();
		cairo_t *cr = ctx->Cairo ();
		int col_count = cols ? cols->GetCount () : 0;
		int row_count = rows ? rows->GetCount () : 0;
		
		cairo_save (cr);
		RenderLayoutClip (cr);
		cairo_set_line_width(cr, 1.0);
		// Initially render a blue color
		cairo_set_dash (cr, &dash, 1, offset);
		cairo_set_source_rgb (cr, 0.4, 0.4, 1.0);
		cairo_new_path (cr);

		// Draw gridlines between each pair of columns/rows
		for (int count = 0; count < 2; count++) {
			for (int i = 0, offset = 0; i < col_count - 1; i++) {
				ColumnDefinition *def = cols->GetValueAt (i)->AsColumnDefinition ();
				offset += def->GetActualWidth ();
				cairo_move_to (cr, offset, 0);
				cairo_line_to (cr, offset, GetActualHeight ());
			}
			
			for (int i = 0, offset = 0; i < row_count - 1; i++) {
				RowDefinition *def = rows->GetValueAt (i)->AsRowDefinition ();
				offset += def->GetActualHeight ();
				cairo_move_to (cr, 0, offset);
				cairo_line_to (cr, GetActualWidth (), offset);
			}
			
			cairo_stroke (cr);
			
			// For the second pass render a yellow color in the gaps between the previous dashes
			cairo_set_dash (cr, &dash, 1, dash);
			cairo_set_source_rgb (cr, 1.0, 1.0, 0.3);
		}
		cairo_restore (cr);
	}		

	// Chain up, but skip children since we've already rendered them here.
	UIElement::PostRender (ctx, region, true);
}
Exemplo n.º 17
0
void iupDrawArc(IdrawCanvas* dc, int x1, int y1, int x2, int y2, double a1, double a2, unsigned char r, unsigned char g, unsigned char b, int style)
{
  int xc, yc, w, h;

  cairo_set_source_rgba(dc->image_cr, iupCOLOR8ToDouble(r),
                                       iupCOLOR8ToDouble(g),
                                       iupCOLOR8ToDouble(b),
                                       1.0);

  if (style!=IUP_DRAW_FILL)
  {
    if (style==IUP_DRAW_STROKE_DASH)
    {
      double dashes[2];
      dashes[0] = 6.0;  dashes[1] = 2.0;
      cairo_set_dash(dc->image_cr, dashes, 2, 0);
    }
    else
      cairo_set_dash(dc->image_cr, 0, 0, 0);
  }

  w = x2-x1+1;
  h = y2-y1+1;
  xc = x1 + w/2;
  yc = y1 + h/2;

  if (w == h)
  {
    cairo_arc(dc->image_cr, xc, yc, 0.5*w, a1, a2);

    if (style==IUP_DRAW_FILL)
      cairo_fill(dc->image_cr);
    else
      cairo_stroke(dc->image_cr);
  }
  else  /* Ellipse: change the scale to create from the circle */
  {
    cairo_save(dc->image_cr);  /* save to use the local transform */

    cairo_translate(dc->image_cr, xc, yc);
    cairo_scale(dc->image_cr, w/h, 1.0);
    cairo_translate(dc->image_cr, -xc, -yc);

    cairo_arc(dc->image_cr, xc, yc, 0.5*h, a1, a2);

    if (style==IUP_DRAW_FILL)
      cairo_fill(dc->image_cr);
    else
      cairo_stroke(dc->image_cr);

    cairo_restore(dc->image_cr);  /* restore from local */
  }
}
Exemplo n.º 18
0
static void
draw_crosses(cairo_t *cr, gint width, gint height)
{
   gint x, y;
   gdouble dash[4] = { 7., grid_height - 7., 7., grid_width - 7. };

   cairo_set_dash (cr, dash, 2, 4.5 - grid_top);
   for (x = grid_left % grid_width; x < width; x += grid_width)
      draw_line(cr, x, 1, x, height);
   cairo_set_dash (cr, dash+2, 2, 4.5 - grid_left);
   for (y = grid_top % grid_height; y < height; y += grid_height)
      draw_line(cr, 1, y, width, y);
}
Exemplo n.º 19
0
static int 
VGUI_begin(void) {
 //printf("VGUI_begin\n");
 if (vdevice.bgnmode == VLINE) {
  /* Dash transfer was shamelessly copied from the VOGL X11.c driver... */
  //65535=solid
  if (VGUI.line_style != 0xffff) {
   double dashes[16];
   int     i, n, a, b;

   for (i = 0; i < 16; i++) dashes[i] = 0;

   for (i = 0; i < 16; i++)        /* Over 16 bits */
    if ((VGUI.line_style & (1 << i))) break;

#define ON  1
#define OFF 0

   a = b = OFF;
   if (VGUI.line_style & (1 << 0)) a = b = ON;

   n = 0;
   for (i = 0; i < 16; i++) {      /* Over 16 bits */
    if (VGUI.line_style & (1 << i)) a = ON;
    else               a = OFF;

    if (a != b) {
     b = a;
     n++;
    }
    dashes[n]++;
   }
   n++;

#undef ON
#undef OFF
   cairo_set_dash (VGUI.cr,dashes,n,0);
  } else {
   /* Solid lines are the default anyway */
   gdk_threads_enter();
   cairo_set_dash (VGUI.cr,NULL,0,0);
   gdk_threads_leave();
  }

  gdk_cairo_set_source_rgba(VGUI.cr,&VGUI.palette[VGUI.fg]);
  cairo_set_line_width(VGUI.cr,VGUI.line_width);
  VGUI.draw_lastx=VGUI.draw_lasty= -1;
 }
 return (1);
};
Exemplo n.º 20
0
static void cairogen_set_penstyle(GVJ_t *job, cairo_t *cr)
{
    obj_state_t *obj = job->obj;

    if (obj->pen == PEN_DASHED) {
	cairo_set_dash (cr, dashed, dashed_len, 0.0);
    } else if (obj->pen == PEN_DOTTED) {
	cairo_set_dash (cr, dotted, dotted_len, 0.0);
    } else {
	cairo_set_dash (cr, dashed, 0, 0.0);
    }
    cairo_set_line_width (cr, obj->penwidth);

}
Exemplo n.º 21
0
static int ui_set_dash(lua_State *L)
{
	struct context *c = lua_touserdata(L, 1);

	// TODO expand api
	if (lua_tonumber(L, 2)) {
		double dashes[2] = { lua_tonumber(L, 2), lua_tonumber(L, 2) }; 
		cairo_set_dash(c->cr, dashes, 2, 0);
	}
	else {
		cairo_set_dash(c->cr, NULL, 0, 0);
	}
	return 0;
}
Exemplo n.º 22
0
static VALUE
cr_set_dash (int argc, VALUE *argv, VALUE self)
{
  VALUE dash_array, rb_offset;
  double offset;
  cairo_bool_t is_num;

  rb_scan_args(argc, argv, "11", &dash_array, &rb_offset);

  is_num = rb_cairo__is_kind_of (dash_array, rb_cNumeric);
  if (!(NIL_P (dash_array) || is_num))
    {
      Check_Type (dash_array, T_ARRAY);
    }

  if (NIL_P (rb_offset))
    offset = 0.0;
  else
    offset = NUM2DBL (rb_offset);

  if (is_num)
    {
      double values[1];
      values[0] = NUM2DBL (dash_array);
      cairo_set_dash (_SELF, values, 1, offset);
    }
  else if (NIL_P (dash_array) || RARRAY_LEN (dash_array) == 0)
    {
      cairo_set_dash (_SELF, NULL, 0, offset);
    }
  else
    {
      int i, length;
      double *values;
      length = RARRAY_LEN (dash_array);
      values = ALLOCA_N (double, length);
      if (!values)
        {
          rb_cairo_check_status (CAIRO_STATUS_NO_MEMORY);
        }
      for (i = 0; i < length; i++)
        {
          values[i] = NUM2DBL (RARRAY_PTR (dash_array)[i]);
        }
      cairo_set_dash (_SELF, values, length, offset);
    }

  cr_check_status (_SELF);
  return self;
}
Exemplo n.º 23
0
Arquivo: circle.c Projeto: EQ4/lad
static void
ganv_circle_draw(GanvItem* item,
                 cairo_t* cr, double cx, double cy, double cw, double ch)
{
	GanvNode*       node   = GANV_NODE(item);
	GanvCircle*     circle = GANV_CIRCLE(item);
	GanvCircleImpl* impl   = circle->impl;

	double r, g, b, a;

	double x = impl->coords.x;
	double y = impl->coords.y;
	ganv_item_i2w(item, &x, &y);

	double dash_length, border_color, fill_color;
	ganv_node_get_draw_properties(
		&circle->node, &dash_length, &border_color, &fill_color);

	cairo_arc(cr,
	          x,
	          y,
	          impl->coords.radius,
	          0, 2 * G_PI);

	// Fill
	color_to_rgba(fill_color, &r, &g, &b, &a);
	cairo_set_source_rgba(cr, r, g, b, a);
	cairo_fill_preserve(cr);

	// Border
	color_to_rgba(border_color, &r, &g, &b, &a);
	cairo_set_source_rgba(cr, r, g, b, a);
	cairo_set_line_width(cr, impl->coords.width);
	if (dash_length > 0) {
		cairo_set_dash(cr, &dash_length, 1, circle->node.impl->dash_offset);
	} else {
		cairo_set_dash(cr, &dash_length, 0, 0);
	}
	cairo_stroke(cr);

	// Draw label
	if (node->impl->label) {
		GanvItem* label_item = GANV_ITEM(node->impl->label);

		if (label_item->object.flags & GANV_ITEM_VISIBLE) {
			GANV_ITEM_GET_CLASS(label_item)->draw(
				label_item, cr, cx, cy, cw, ch);
		}
	}
}
Exemplo n.º 24
0
void render_depot(sem_render_context* ctx, sem_coordinate coord, sem_track* track) {
	render_track_path(ctx, coord, track);
	cairo_set_source_rgb(ctx->cr, 0.0, 0.0, 0.0);
	cairo_set_line_width(ctx->cr, ctx->style->depot_back_width);
	cairo_stroke_preserve(ctx->cr);

	cairo_set_source(ctx->cr, ctx->style->canvas);
	cairo_set_line_width(ctx->cr, ctx->style->depot_front_width);
	const double dash[] = {0.233, 0.1};
	cairo_set_dash(ctx->cr, dash, 2, -0.05);
	cairo_stroke(ctx->cr);
	cairo_set_dash(ctx->cr, dash, 0, 0);

	render_track(ctx, coord, track);
}
Exemplo n.º 25
0
static void
set_stroke_params_from_gc(cairo_t *cairo, struct graphics_gc_priv *gc)
{
	set_drawing_color(cairo, gc->c);
	cairo_set_dash(cairo, gc->dashes, gc->ndashes, gc->offset);
	cairo_set_line_width(cairo, gc->linewidth);
}
Exemplo n.º 26
0
void LcCairoPainter::set_dash(const double* dashes, const int num_dashes, double offset, bool scaled) {
    if (scaled) {
        double scaledDashes[num_dashes];
        memcpy(&scaledDashes, dashes, num_dashes * sizeof(double));

        double _scale = scale();

        for (unsigned short c = 0; c < num_dashes; c++) {
            scaledDashes[c] = scaledDashes[c] / _scale;
        }

        cairo_set_dash(_cr, scaledDashes, num_dashes, offset);
    } else {
        cairo_set_dash(_cr, dashes, num_dashes, offset);
    }
}
Exemplo n.º 27
0
static gboolean
preview_expose(GtkWidget *widget, GdkEventExpose *event)
{
   cairo_t *cr;
   gint width = preview_get_width (widget);
   gint height = preview_get_height (widget);

   cr = gdk_cairo_create (event->window);
   gdk_cairo_region (cr, event->region);
   cairo_clip (cr);
   cairo_set_line_width (cr, 1.);
   draw_grid (cr, width, height);
   
   draw_shapes (cr);

   if (_tmp_obj)
   {
      /* this is a bit of a hack */
      gdouble dash = 4.;
      _tmp_obj->selected |= 4;
      cairo_set_source_rgb (cr, 1., 0., 1.);
      cairo_set_dash (cr, &dash, 1, dash);
      object_draw (_tmp_obj, cr);
   }

   cairo_destroy (cr);
   return FALSE;
}
static PyObject *
pycairo_set_dash (PycairoContext *o, PyObject *args)
{
    double *dashes, offset = 0;
    int ndash, i;
    PyObject *py_dashes;

    if (!PyArg_ParseTuple (args, "O|d:Context.set_dash", &py_dashes, &offset))
	return NULL;

    py_dashes = PySequence_Fast (py_dashes,
				 "first argument must be a sequence");
    if (!py_dashes)
	return NULL;

    ndash = PySequence_Fast_GET_SIZE(py_dashes);
    dashes = malloc (ndash * sizeof(double));
    for (i = 0; i < ndash; i++) {
	PyObject *item = PySequence_Fast_GET_ITEM(py_dashes, i);

	dashes[i] = PyFloat_AsDouble(item);
	if (PyErr_Occurred()) {
	    free (dashes);
	    Py_DECREF(py_dashes);
	    return NULL;
	}
    }
    Py_DECREF(py_dashes);

    cairo_set_dash (o->ctx, dashes, ndash, offset);
    free (dashes);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Exemplo n.º 29
0
void WayRenderer::stroke(cairo_t* cr, AssetCache& cache)
{
	if (s->width <= 0.0)
		return;

	addWayPath(cr);

	cairo_save(cr);

	setLineCap(cr,  s->linecap);
	setLineJoin(cr, s->linejoin);
	cairo_set_source_rgba(cr, COLOR2RGBA(s->color));
	const string& image = s->image.str();
	cairo_pattern_t* pattern = NULL;
	if (!image.empty()) {
		pattern = cairo_pattern_create_for_surface(cache.getImage(image));
		cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
		cairo_set_source(cr, pattern);
	}

	if (s->dashes.size() > 0)
		cairo_set_dash(cr, s->dashes.data(), s->dashes.size(), 0.0);
	cairo_set_line_width(cr, s->width);

	cairo_stroke(cr);

	if (pattern != NULL)
		cairo_pattern_destroy(pattern);

	cairo_restore(cr);
}
Exemplo n.º 30
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    double total;
    size_t i, j, k;

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_set_line_width (cr, 2);

    total = 0.0;
    for (k = 0; k < ARRAY_SIZE(dashes); ++k) {
	total += dashes[k];
	for (i = 0; i < ARRAY_SIZE(frac_offset); ++i) {
	    for (j = 0; j < ARRAY_SIZE(int_offset); ++j) {
		cairo_set_dash (cr, dashes, k + 1, frac_offset[i] + total * int_offset[j]);
		cairo_move_to (cr, (STROKE_LENGTH + PAD) * k + PAD, PAD * (i + j + ARRAY_SIZE(frac_offset) * j + 1));
		cairo_line_to (cr, (STROKE_LENGTH + PAD) * (k + 1), PAD * (i + j + ARRAY_SIZE(frac_offset) * j + 1));
		cairo_stroke (cr);
	    }
	}
    }

    return CAIRO_TEST_SUCCESS;
}