/* This draw_inset implementation only differes in the shades values from the
 * default one. */
static void
clearlooks_glossy_draw_inset (cairo_t          *cr, 
                              const CairoColor *bg_color,
                              double x, double y, double width, double height,
                              double radius, uint8 corners)
{
	CairoColor shadow;
	CairoColor highlight;
	double line_width;
	double min = MIN (width, height);

	line_width = cairo_get_line_width (cr);

	/* not really sure of shading ratios... we will think */
	ge_shade_color (bg_color, 0.93, &shadow);
	ge_shade_color (bg_color, 1.07, &highlight);

	/* highlight */
	cairo_save (cr);

	cairo_move_to (cr, x, y + height);
	cairo_line_to (cr, x + min / 2.0, y + height - min / 2.0);
	cairo_line_to (cr, x + width - min / 2.0, y + min / 2.0);
	cairo_line_to (cr, x + width, y);
	cairo_line_to (cr, x, y);
	cairo_close_path (cr);
	
	cairo_clip (cr);

	ge_cairo_rounded_rectangle (cr, x + line_width / 2.0, y + line_width / 2.0,
	                            width - line_width, height - line_width,
	                            radius, corners);

	ge_cairo_set_color (cr, &shadow);
	cairo_stroke (cr);
	
	cairo_restore (cr);

	/* shadow */
	cairo_save (cr);

	cairo_move_to (cr, x, y + height);
	cairo_line_to (cr, x + min / 2.0, y + height - min / 2.0);
	cairo_line_to (cr, x + width - min / 2.0, y + min / 2.0);
	cairo_line_to (cr, x + width, y);
	cairo_line_to (cr, x + width, y + height);
	cairo_close_path (cr);
	
	cairo_clip (cr);

	ge_cairo_rounded_rectangle (cr, x + line_width / 2.0, y + line_width / 2.0,
	                            width - line_width, height - line_width,
	                            radius, corners);

	ge_cairo_set_color (cr, &highlight);
	cairo_stroke (cr);

	cairo_restore (cr);
}
Exemple #2
0
static int cairo_get_line_width_l( lua_State* L )
{
  lua_cairo_t* lc = lua_cairo_check( L, 1 );

  lua_pushnumber( L, cairo_get_line_width( lc->cairo ) );

  return( 1 );
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_text_extents_t extents;
    cairo_scaled_font_t *scaled_font;
    cairo_status_t status;
    const char text[] = "i-W";
    double line_width, x, y;

    line_width = cairo_get_line_width (cr);

    /* 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);

    status = create_scaled_font (cr, &scaled_font);
    if (status) {
        return cairo_test_status_from_status (cairo_test_get_context (cr),
                                              status);
    }

    cairo_set_scaled_font (cr, scaled_font);
    cairo_scaled_font_destroy (scaled_font);

    cairo_set_line_width (cr, 1.0);
    cairo_set_source_rgb (cr, 0, 0, 0); /* black */
    cairo_text_extents (cr, text, &extents);
    x = width  - (extents.width  + extents.x_bearing) - 5;
    y = height - (extents.height + extents.y_bearing) - 5;
    cairo_move_to (cr, x, y);
    cairo_show_text (cr, text);
    cairo_rectangle (cr,
                     x + extents.x_bearing - line_width / 2,
                     y + extents.y_bearing - line_width / 2,
                     extents.width  + line_width,
                     extents.height + line_width);
    cairo_stroke (cr);

    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
    cairo_text_extents (cr, text, &extents);
    x = -extents.x_bearing + 5;
    y = -extents.y_bearing + 5;
    cairo_move_to (cr, x, y);
    cairo_text_path (cr, text);
    cairo_fill (cr);
    cairo_rectangle (cr,
                     x + extents.x_bearing - line_width / 2,
                     y + extents.y_bearing - line_width / 2,
                     extents.width  + line_width,
                     extents.height + line_width);
    cairo_stroke (cr);

    return CAIRO_TEST_SUCCESS;
}
void
ge_cairo_inner_rectangle (cairo_t *cr,
                          double x, double y,
                          double width, double height)
{
	double line_width = cairo_get_line_width (cr);

	cairo_rectangle (cr, x + line_width / 2.0,
	                     y + line_width / 2.0,
	                     width - line_width,
	                     height - line_width);
}
void
ge_cairo_inner_rounded_rectangle (cairo_t *cr,
                                  double x, double y,
                                  double width, double height,
                                  double radius, CairoCorners corners)
{
	double line_width = cairo_get_line_width (cr);

	ge_cairo_rounded_rectangle (cr,
                                    x + line_width / 2.0,
                                    y + line_width / 2.0,
                                    width - line_width,
                                    height - line_width,
                                    radius, corners);
}
Exemple #6
0
void copyContextProperties(cairo_t* srcCr, cairo_t* dstCr)
{
    cairo_set_antialias(dstCr, cairo_get_antialias(srcCr));

    size_t dashCount = cairo_get_dash_count(srcCr);
    Vector<double> dashes(dashCount);

    double offset;
    cairo_get_dash(srcCr, dashes.data(), &offset);
    cairo_set_dash(dstCr, dashes.data(), dashCount, offset);
    cairo_set_line_cap(dstCr, cairo_get_line_cap(srcCr));
    cairo_set_line_join(dstCr, cairo_get_line_join(srcCr));
    cairo_set_line_width(dstCr, cairo_get_line_width(srcCr));
    cairo_set_miter_limit(dstCr, cairo_get_miter_limit(srcCr));
    cairo_set_fill_rule(dstCr, cairo_get_fill_rule(srcCr));
}
void drawn_progress_bar(cairo_surface_t *surface, font_info *font, int x, int y, float curr, float max, byte color, int len)
{
	cairo_t *cr;
	int temp;
	cairo_rectangle_t r;
	float percent;
	measurements size;
	
	 size.w = font->w;
	size.h = font->h;
	
	if (surface != NULL)
	{
	cr = cairo_create(surface);
	
	if (max > 0)
		percent = curr / max;
	else
		percent = 0;
	
	init_cairo_rect(&r, (size.w * x)+ 1, (size.h) * y + 1,  (size.w * len) - 1, size.h - 2);
	cairo_clear(surface, r, TERM_DARK);
	
	temp = cairo_get_line_width(cr);
	set_foreground_color(cr, color);
	
	if (percent > 0)
	{
		cairo_set_line_width(cr, size.h);
		cairo_move_to(cr, r.x, r.y + (r.height * 0.5));
		cairo_line_to(cr, (size.w * ((len * percent) + x)), r.y + (r.height * 0.5));
		cairo_stroke(cr);
	}
	if (max > 0)
	{
		cairo_set_line_width(cr, 1);
		
		set_foreground_color(cr, TERM_SLATE);
		c_rect(cr, r);
		cairo_stroke(cr);
		
		cairo_set_line_width(cr, temp);
	}
		cairo_destroy(cr);
	}
}
Exemple #8
0
static int
settings_get (cairo_t *cr, settings_t *settings)
{
    int count;

    settings->op = cairo_get_operator (cr);
    settings->tolerance = cairo_get_tolerance (cr);
    settings->fill_rule = cairo_get_fill_rule (cr);
    settings->line_width = cairo_get_line_width (cr);
    settings->line_cap = cairo_get_line_cap (cr);
    settings->line_join = cairo_get_line_join (cr);
    settings->miter_limit = cairo_get_miter_limit (cr);
    cairo_get_matrix (cr, &settings->matrix);

    count = cairo_get_dash_count (cr);
    if (count != 5)
	return -1;

    cairo_get_dash (cr, settings->dash, &settings->dash_offset);

    return 0;
}
Exemple #9
0
void
cairodraw_dblock(cairo_t * cr, pcdblock b, int levels)
{
  double    sx, sy, ex, ey;
  uint      rsize, csize;
  double    scalex, scaley, scale;

  /* Save Cairo state */
  cairo_save(cr);

  /* Obtain size of block */
  rsize = b->rc->size;
  csize = b->cc->size;

  /* Obtain size of current Cairo bounding box */
  cairo_clip_extents(cr, &sx, &sy, &ex, &ey);

  /* Compute scaling factor */
  scalex = (ex - sx) / rsize;
  scaley = (ey - sy) / csize;
  scale = (scalex < scaley ? scalex : scaley);

  /* Center block in bounding box */
  cairo_translate(cr,
		  0.5 * (ex - sx - scale * rsize),
		  0.5 * (ey - sy - scale * csize));

  /* Scale coordinates */
  cairo_scale(cr, scale, scale);
  cairo_set_line_width(cr, cairo_get_line_width(cr) / scale);

  /* Start drawing */
  cairodraw_subblock(cr, b, levels);

  /* Restore Cairo state */
  cairo_restore(cr);
}
Exemple #10
0
void
draw_curve2d(pccurve2d gr, cairo_t * cr, real scale)
{
  uint      i, edges;
  real     *p, bmin[2], bmax[2];
  real      s, tx, ty, tol;

  edges = gr->edges;

  tol = 0.05;

  compute_boundingbox_curve2d(gr, bmin, bmax);

  if ((bmax[0] - bmin[0]) >= (bmax[1] - bmin[1])) {
    s = (1.0 - tol) / (bmax[0] - bmin[0]);
  }
  else {
    s = (1.0 - tol) / (bmax[1] - bmin[1]);
  }

  tx = -1.5 * bmin[0] + 0.5 * (bmax[0] + bmin[0]);
  ty = -1.5 * bmin[1] + 0.5 * (bmax[1] + bmin[1]);

  cairo_scale(cr, s, s);
  cairo_translate(cr, tx / s, ty / s);

  cairo_set_line_width(cr, cairo_get_line_width(cr) / scale);

  for (i = 0; i < edges; ++i) {
    p = gr->x[gr->e[i][0]];
    cairo_move_to(cr, p[0], p[1]);
    p = gr->x[gr->e[i][1]];
    cairo_line_to(cr, p[0], p[1]);
  }

  cairo_stroke(cr);
}
Exemple #11
0
void
draw_cairo_tri2d(pctri2d t2, const char *filename, bool mark_refedges,
		 int mark_triangle)
{
#ifdef USE_CAIRO
  cairo_surface_t *surface;
  cairo_t  *cr;
  const     real(*x)[2] = (const real(*)[2]) t2->x;
  const     uint(*e)[2] = (const uint(*)[2]) t2->e;
  const     uint(*t)[3] = (const uint(*)[3]) t2->t;
  uint      vertices = t2->vertices;
  uint      edges = t2->edges;
  uint      triangles = t2->triangles;
  double    xmin, xmax, ymin, ymax;
  double    hmin, hk, x0, y0, dx, dy, nx, ny;
  uint      k;

  xmin = xmax = x[0][0];
  ymin = ymax = x[0][1];
  for (k = 1; k < vertices; k++) {
    if (x[k][0] < xmin)
      xmin = x[k][0];
    else if (x[k][0] > xmax)
      xmax = x[k][0];
    if (x[k][1] < ymin)
      ymin = x[k][1];
    else if (x[k][1] > ymax)
      ymax = x[k][1];
  }

  surface = cairo_pdf_surface_create(filename, 100.0 * (xmax - xmin),
				     100.0 * (ymax - ymin));
  cr = cairo_create(surface);
  cairo_surface_destroy(surface);
  cairo_translate(cr, -100.0 * xmin, -100.0 * ymin);
  cairo_scale(cr, 95.0, 95.0);
  cairo_set_line_width(cr, cairo_get_line_width(cr) / 95.0);
  cairo_scale(cr, 1.0, -1.0);

  cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
  if (mark_triangle >= 0) {
    k = mark_triangle;
    cairo_move_to(cr, x[e[t[k][0]][0]][0], x[e[t[k][0]][0]][1]);
    cairo_line_to(cr, x[e[t[k][0]][1]][0], x[e[t[k][0]][1]][1]);
    if (e[t[k][1]][0] == e[t[k][0]][0] || e[t[k][1]][0] == e[t[k][0]][1])
      cairo_line_to(cr, x[e[t[k][1]][1]][0], x[e[t[k][1]][1]][1]);
    else
      cairo_line_to(cr, x[e[t[k][1]][0]][0], x[e[t[k][1]][0]][1]);
    cairo_close_path(cr);
    cairo_fill(cr);
  }

  if (mark_refedges) {
    hmin =
      REAL_SQRT(REAL_SQR(x[e[0][0]][0] - x[e[0][1]][0]) +
		REAL_SQR(x[e[0][0]][1] - x[e[0][1]][1]));
    for (k = 1; k < edges; k++) {
      hk =
	REAL_SQRT(REAL_SQR(x[e[k][0]][0] - x[e[k][1]][0]) +
		  REAL_SQR(x[e[k][0]][1] - x[e[k][1]][1]));
      if (hk < hmin)
	hmin = hk;
    }

    hk = xmax - xmin;
    if (ymax - ymin < hk)
      hk = ymax - ymin;
    if (hmin > 0.05 * hk)
      hmin = 0.05 * hk;

    cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
    for (k = 0; k < triangles; k++) {
      cairo_move_to(cr, x[e[t[k][0]][0]][0], x[e[t[k][0]][0]][1]);
      cairo_line_to(cr, x[e[t[k][0]][1]][0], x[e[t[k][0]][1]][1]);

      nx = x[e[t[k][0]][1]][1] - x[e[t[k][0]][0]][1];
      ny = x[e[t[k][0]][0]][0] - x[e[t[k][0]][1]][0];
      hk = REAL_SQRT(REAL_SQR(nx) + REAL_SQR(ny));
      nx /= hk;
      ny /= hk;

      if (e[t[k][1]][0] == e[t[k][2]][0] || e[t[k][1]][0] == e[t[k][2]][1]) {
	x0 = x[e[t[k][1]][0]][0];
	y0 = x[e[t[k][1]][0]][1];
      }
      else {
	assert(e[t[k][1]][1] == e[t[k][2]][0]
	       || e[t[k][1]][1] == e[t[k][2]][1]);
	x0 = x[e[t[k][1]][1]][0];
	y0 = x[e[t[k][1]][1]][1];
      }

      dx = x0 - x[e[t[k][0]][1]][0];
      dy = y0 - x[e[t[k][0]][1]][1];
      hk = REAL_ABS(dx * nx + dy * ny);
      dx /= hk;
      dy /= hk;
      cairo_line_to(cr, x[e[t[k][0]][1]][0] + hmin * 0.2 * dx,
		    x[e[t[k][0]][1]][1] + hmin * 0.2 * dy);

      dx = x0 - x[e[t[k][0]][0]][0];
      dy = y0 - x[e[t[k][0]][0]][1];
      hk = REAL_ABS(dx * nx + dy * ny);
      dx /= hk;
      dy /= hk;
      cairo_line_to(cr, x[e[t[k][0]][0]][0] + hmin * 0.2 * dx,
		    x[e[t[k][0]][0]][1] + hmin * 0.2 * dy);

      cairo_close_path(cr);
      cairo_fill(cr);
    }
  }

  cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
  for (k = 0; k < edges; k++) {
    cairo_move_to(cr, x[e[k][0]][0], x[e[k][0]][1]);
    cairo_line_to(cr, x[e[k][1]][0], x[e[k][1]][1]);
    cairo_stroke(cr);
  }

  cairo_destroy(cr);
#else
  fprintf(stderr, "CAIRO not supported.\n");
#endif
}
Exemple #12
0
static int
cr_get_line_width (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    lua_pushnumber(L, cairo_get_line_width(*obj));
    return 1;
}
Exemple #13
0
	double lime_cairo_get_line_width (value handle) {
		
		return cairo_get_line_width ((cairo_t*)val_data (handle));
		
	}
Exemple #14
0
void CairoDevice::PushPenWidth( float width)
{
	fPenWidthStack.push( cairo_get_line_width(fNativeDevice) );
	SelectPenWidth( width );	
}
Exemple #15
0
static cairo_status_t
twin_scaled_font_render_glyph (cairo_scaled_font_t  *scaled_font,
			       unsigned long         glyph,
			       cairo_t              *cr,
			       cairo_text_extents_t *metrics)
{
    double x1, y1, x2, y2, x3, y3;
    const int8_t *b = _cairo_twin_outlines +
		      _cairo_twin_charmap[glyph >= ARRAY_LENGTH (_cairo_twin_charmap) ? 0 : glyph];
    const int8_t *g = twin_glyph_draw(b);

    struct {
      cairo_bool_t snap;
      int snap_x;
      int snap_y;
      int n_snap_x;
      int n_snap_y;
    } info = {FALSE};

    cairo_set_line_width (cr, 0.06);
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);

    for (;;) {
	switch (*g++) {
	case 'M':
	    cairo_close_path (cr);
	    /* fall through */
	case 'm':
	    x1 = FX(*g++);
	    y1 = FY(*g++);
	    if (info.snap)
	    {
		x1 = SNAPX (x1);
		y1 = SNAPY (y1);
	    }
	    cairo_move_to (cr, x1, y1);
	    continue;
	case 'L':
	    cairo_close_path (cr);
	    /* fall through */
	case 'l':
	    x1 = FX(*g++);
	    y1 = FY(*g++);
	    if (info.snap)
	    {
		x1 = SNAPX (x1);
		y1 = SNAPY (y1);
	    }
	    cairo_line_to (cr, x1, y1);
	    continue;
	case 'C':
	    cairo_close_path (cr);
	    /* fall through */
	case 'c':
	    x1 = FX(*g++);
	    y1 = FY(*g++);
	    x2 = FX(*g++);
	    y2 = FY(*g++);
	    x3 = FX(*g++);
	    y3 = FY(*g++);
	    if (info.snap)
	    {
		x1 = SNAPX (x1);
		y1 = SNAPY (y1);
		x2 = SNAPX (x2);
		y2 = SNAPY (y2);
		x3 = SNAPX (x3);
		y3 = SNAPY (y3);
	    }
	    cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
	    continue;
	case 'E':
	    cairo_close_path (cr);
	    /* fall through */
	case 'e':
	    cairo_stroke (cr);
	    break;
	case 'X':
	    /* filler */
	    continue;
	}
	break;
    }

    metrics->x_advance = FX(twin_glyph_right(b)) + cairo_get_line_width (cr);
    metrics->x_advance +=  cairo_get_line_width (cr)/* XXX 2*x.margin */;
    if (info.snap)
	metrics->x_advance = SNAPI (SNAPX (metrics->x_advance));


    return CAIRO_STATUS_SUCCESS;
}
Exemple #16
0
	double lime_cairo_get_line_width (double handle) {
		
		return cairo_get_line_width ((cairo_t*)(intptr_t)handle);
		
	}
static VALUE
cr_get_line_width (VALUE self)
{
  return rb_float_new (cairo_get_line_width (_SELF));
}
Exemple #18
0
gfxFloat gfxContext::CurrentLineWidth() const
{
    return cairo_get_line_width(mCairo);
}
static PyObject *
pycairo_get_line_width (PycairoContext *o)
{
    return PyFloat_FromDouble(cairo_get_line_width (o->ctx));
}
Exemple #20
0
double Context::getLineWidth() const
{
	return cairo_get_line_width( mCairo );
}
Exemple #21
0
static GpStatus
DrawString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int length, GDIPCONST GpFont *font, 
	GDIPCONST RectF *rc_org, GDIPCONST GpStringFormat *fmt, GpBrush *brush, 
	WCHAR *CleanString, GpStringDetailStruct* StringDetails, GpDrawTextData *data)
{
	float CursorX = 0.0;		/* Current X position of drawing cursor */
	float CursorY = 0.0;		/* Current Y position of drawing cursor */
	int StringLen = length;
	BOOL SetClipping = FALSE;
	unsigned long	i, j;
	int AlignHorz = data->align_horz;
	int AlignVert = data->align_vert;
	int LineHeight = data->line_height;
	int MaxY = data->max_y;
	cairo_font_extents_t FontExtent;
	RectF rect, *rc = &rect;

	cairo_font_extents (graphics->ct, &FontExtent);

	if (OPTIMIZE_CONVERSION (graphics)) {
		rc->X = rc_org->X;
		rc->Y = rc_org->Y;
		rc->Width = rc_org->Width;
		rc->Height = rc_org->Height;
	} else {
		rc->X = gdip_unitx_convgr (graphics, rc_org->X);
		rc->Y = gdip_unity_convgr (graphics, rc_org->Y);
		rc->Width = gdip_unitx_convgr (graphics, rc_org->Width);
		rc->Height = gdip_unity_convgr (graphics, rc_org->Height);
	}

	/* Set our clipping rectangle */
	if ((rc->Width!=0) && (rc->Height!=0) && ((fmt->formatFlags & StringFormatFlagsNoClip)==0)) {
#ifdef DRAWSTRING_DEBUG
		printf("Setting clipping rectangle (%f, %f %fx%f)\n", rc->X, rc->Y, rc->Width, rc->Height);
#endif		
		/* We do not call cairo_reset_clip because we want to take previous clipping into account */
		gdip_cairo_rectangle (graphics, rc->X, rc->Y, rc->Width, rc->Height, TRUE);
		cairo_clip (graphics->ct);
		SetClipping = TRUE;
	}

	/* Setup cairo */

	if (brush) {
		gdip_brush_setup (graphics, (GpBrush *)brush);
	} else {
		cairo_set_source_rgb (graphics->ct, 0., 0., 0.);
	}

	for (i=0; i<StringLen; i++) {
		if (StringDetails[i].Flags & STRING_DETAIL_LINESTART) {
			BYTE *String;
			int length = StringDetails[i].LineLen;
			int current_line_length = min (length + i, StringLen);

			/* To support the LineLimit flag */
			if ((StringDetails[i].Flags & STRING_DETAIL_HIDDEN)!=0){
#ifdef DRAWSTRING_DEBUG
				printf("Hidding partially visible line\n");
#endif
				i=StringLen;
				continue;
			}

			if (length > StringLen - i)
				length = StringLen - i;
			String = (BYTE*) ucs2_to_utf8 ((const gunichar2 *)(CleanString+i), length);
#ifdef DRAWSTRING_DEBUG
			printf("Displaying line >%s< (%d chars)\n", String, length);
#endif

			if ((fmt->formatFlags & StringFormatFlagsDirectionVertical)==0) {
				CursorX = rc->X + StringDetails[i].PosX;
				CursorY = rc->Y + StringDetails[i].PosY + LineHeight;

				gdip_cairo_move_to (graphics, CursorX, CursorY, FALSE, TRUE);
				cairo_show_text (graphics->ct, (const char *) String);
			} else {
				CursorY = rc->Y + StringDetails[i].PosX;
				CursorX = rc->X + StringDetails[i].PosY;

				/* Rotate text for vertical drawing */
				cairo_save (graphics->ct);
				gdip_cairo_move_to (graphics, CursorX, CursorY, FALSE, TRUE);
				cairo_rotate (graphics->ct, PI/2);
				cairo_show_text (graphics->ct, (const char *) String);
				cairo_restore (graphics->ct);
			}

#ifdef DRAWSTRING_DEBUG
			printf("Drawing %d chars at %d x %d (width=%f pixels)\n", StringDetails[i].LineLen, (int)CursorX, (int)CursorY, StringDetails[i+StringDetails[i].LineLen-1].PosX);
#endif
			GdipFree (String);

			if (font->style & (FontStyleUnderline | FontStyleStrikeout)) {
				double line_width = cairo_get_line_width (graphics->ct);

				/* Calculate the width of the line */
				cairo_set_line_width (graphics->ct, 1.0);
				j=StringDetails[i+StringDetails[i].LineLen-1].PosX+StringDetails[i+StringDetails[i].LineLen-1].Width;

				if (font->style & FontStyleStrikeout) {
					if ((fmt->formatFlags & StringFormatFlagsDirectionVertical)==0) {
						gdip_cairo_move_to (graphics, (int)(CursorX), (int)(CursorY-FontExtent.descent), FALSE, TRUE);
						gdip_cairo_line_to (graphics, (int)(CursorX+j), (int)(CursorY-FontExtent.descent), FALSE, TRUE);
					} else {
						gdip_cairo_move_to (graphics, (int)(CursorX+FontExtent.descent), (int)(CursorY), FALSE, TRUE);
						gdip_cairo_line_to (graphics, (int)(CursorX+FontExtent.descent), (int)(CursorY+j), FALSE, TRUE);
					}
				}

				if (font->style & FontStyleUnderline) {
					if ((fmt->formatFlags & StringFormatFlagsDirectionVertical)==0) {
						gdip_cairo_move_to (graphics, (int)(CursorX), (int)(CursorY+FontExtent.descent-2), FALSE, TRUE);
						gdip_cairo_line_to (graphics, (int)(CursorX+j), (int)(CursorY+FontExtent.descent-2), FALSE, TRUE);
					} else {
						gdip_cairo_move_to (graphics, (int)(CursorX+FontExtent.descent-2), (int)(CursorY), FALSE, TRUE);
						gdip_cairo_line_to (graphics, (int)(CursorX+FontExtent.descent-2), (int)(CursorY+j), FALSE, TRUE);
					}
				}

				cairo_stroke (graphics->ct);
				cairo_set_line_width (graphics->ct, line_width);
			}

			i+=StringDetails[i].LineLen-1;
		}
	}

	/* Handle Hotkey prefix */
	if (fmt->hotkeyPrefix==HotkeyPrefixShow && data->has_hotkeys) {
		GpStringDetailStruct *CurrentDetail = StringDetails;
		for (i=0; i<StringLen; i++) {
			if (CurrentDetail->Flags & STRING_DETAIL_HOTKEY) {
				if ((fmt->formatFlags & StringFormatFlagsDirectionVertical)==0) {
					CursorX = rc->X + StringDetails[i].PosX;
					CursorY = rc->Y + StringDetails[i].PosY + LineHeight;
				} else {
					CursorY = rc->Y + StringDetails[i].PosX;
					CursorX = rc->X + StringDetails[i].PosY;
				}

				if ((fmt->formatFlags & StringFormatFlagsDirectionVertical)==0) {
					cairo_set_line_width(graphics->ct, 1);
					gdip_cairo_move_to (graphics, (int)(CursorX), (int)(CursorY+FontExtent.descent), FALSE, TRUE);
					gdip_cairo_line_to (graphics, (int)(CursorX+CurrentDetail->Width), (int)(CursorY+FontExtent.descent), FALSE, TRUE);
					cairo_stroke (graphics->ct);
				} else {
					gdip_cairo_move_to (graphics, (int)(CursorX-FontExtent.descent), (int)(CursorY), FALSE, TRUE);
					gdip_cairo_line_to (graphics, (int)(CursorX-FontExtent.descent), (int)(CursorY+CurrentDetail->Width), FALSE, TRUE);
				}
			}
			CurrentDetail++;
		}
	}

	/* Restore the graphics clipping region */
	if (SetClipping)
		cairo_SetGraphicsClip (graphics);

	return Ok;
}
inf_text_gtk_viewport_scrollbar_expose_event_cb(GtkWidget* scrollbar,
                                                GdkEventExpose* event,
                                                gpointer user_data)
#endif
{
  InfTextGtkViewport* viewport;
  InfTextGtkViewportPrivate* priv;
  InfTextGtkViewportUser* viewport_user;
  GdkRectangle* rectangle;
  GdkColor* color;
  double h,s,v;
  double r,g,b;
  GSList* item;
  double line_width;

#if GTK_CHECK_VERSION(2, 91, 0)
  GdkRectangle clip_area;
#else
  cairo_t* cr;
#endif

  viewport = INF_TEXT_GTK_VIEWPORT(user_data);
  priv = INF_TEXT_GTK_VIEWPORT_PRIVATE(viewport);

  /* Can this happen? */
#if GTK_CHECK_VERSION(2, 91, 0)
  if(!gtk_cairo_should_draw_window(cr, gtk_widget_get_window(scrollbar)))
#elif GTK_CHECK_VERSION(2,14,0)
  if(event->window != gtk_widget_get_window(scrollbar))
#else
  if(event->window != GTK_WIDGET(scrollbar)->window)
#endif
    return FALSE;

  if(priv->show_user_markers)
  {
    color = &gtk_widget_get_style(scrollbar)->bg[GTK_STATE_NORMAL];
    h = color->red / 65535.0;
    s = color->green / 65535.0;
    v = color->blue / 65535.0;
    rgb_to_hsv(&h, &s, &v);
    s = MIN(MAX(s, 0.5), 0.8);
    v = MAX(v, 0.5);

#if GTK_CHECK_VERSION(2, 91, 0)
    gtk_cairo_transform_to_window(
      cr,
      GTK_WIDGET(scrollbar),
      gtk_widget_get_window(scrollbar)
    );

    gdk_cairo_get_clip_rectangle(cr, &clip_area);
#else
    cr = gdk_cairo_create(event->window);
#endif

    line_width = cairo_get_line_width(cr);
    for(item = priv->users; item != NULL; item = item->next)
    {
      viewport_user = (InfTextGtkViewportUser*)item->data;
      rectangle = &viewport_user->rectangle;

#if GTK_CHECK_VERSION(2, 91, 0)
      if(gdk_rectangle_intersect(&clip_area, rectangle, NULL))
#elif GTK_CHECK_VERSION(2,90,5)
      if(cairo_region_contains_rectangle(event->region, rectangle) !=
         CAIRO_REGION_OVERLAP_OUT)
#else
      if(gdk_region_rect_in(event->region, rectangle) !=
         GDK_OVERLAP_RECTANGLE_OUT)
#endif
      {
        h = inf_text_user_get_hue(viewport_user->user);

        cairo_rectangle(
          cr,
          rectangle->x + line_width/2,
          rectangle->y + line_width/2,
          rectangle->width - line_width,
          rectangle->height - line_width
        );

        r = h; g = s; b = v/2.0;
        hsv_to_rgb(&r, &g, &b);
        cairo_set_source_rgba(cr, r, g, b, 0.6);
        cairo_stroke_preserve(cr);

        r = h; g = s; b = v;
        hsv_to_rgb(&r, &g, &b);
        cairo_set_source_rgba(cr, r, g, b, 0.6);
        cairo_fill(cr);
      }
    }

#if ! GTK_CHECK_VERSION(2, 91, 0)
    cairo_destroy(cr);
#endif
  }

  return FALSE;
}
Exemple #23
0
static gboolean
gtk_clock_draw (GtkWidget *clock, cairo_t *cr)
{
	gint width = gtk_widget_get_allocated_width (clock);
	gint height = gtk_widget_get_allocated_height (clock);
	gdouble cx = width / 2.0;
	gdouble cy = height / 2.0;
	gdouble radius = MIN (width/2, height/2) - 5;
	gint inset;
	gint i;
	GtkClockPrivate *priv = GTK_CLOCK_GET_PRIVATE (clock);
	struct tm *time = &priv->time;
	cairo_pattern_t *pat;

	cairo_arc (cr, cx, cy, radius, 0, 2 * M_PI);
	cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
	cairo_fill_preserve (cr);
	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_stroke (cr);

	for (i = 0; i < 12; i++)
	{
		cairo_save (cr);

		if (i % 3 == 0)
			inset = 0.2 * radius;
		else {
			inset = 0.1 * radius;
			cairo_set_line_width (cr,
				0.5 * cairo_get_line_width (cr));
		}

		cairo_move_to (cr,
				cx + (radius - inset) * cos (i * M_PI / 6),
				cy + (radius - inset) * sin (i * M_PI / 6));
		cairo_line_to (cr,
				cx + radius * cos (i * M_PI / 6),
				cy + radius * sin (i * M_PI / 6));
		cairo_stroke (cr);

		cairo_restore (cr);
	}

	cairo_set_line_width (cr, 2.0 * cairo_get_line_width (cr));
	cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);

	cairo_move_to (cr, cx, cy);
	cairo_line_to (cr, cx + radius / 2 * sin (M_PI / 6 * time->tm_hour +
						M_PI / 360 * time->tm_min),
			cy + radius / 2 * -cos (M_PI / 6 * time->tm_hour +
						M_PI / 360 * time->tm_min));
	cairo_stroke (cr);

	cairo_move_to (cr, cx, cy);
	cairo_line_to (cr, cx + radius * 0.75 * sin (M_PI / 30 * time->tm_min),
			cy + radius * 0.75 * -cos (M_PI / 30 * time->tm_min));
	cairo_stroke (cr);

	cairo_set_line_width (cr, 0.2 * cairo_get_line_width (cr));
	cairo_set_source_rgb (cr, 1, 0, 0);
	cairo_move_to (cr, cx, cy);
	cairo_line_to (cr, cx + radius * 0.75 * sin (M_PI / 30 * time->tm_sec),
			cy + radius * 0.75 * -cos (M_PI / 30 * time->tm_sec));
	cairo_stroke (cr);

	cairo_arc (cr, cx, cy, radius, 0.0, 2.0 * M_PI);

	pat = cairo_pattern_create_radial (cx, cy, radius,
                                   cx,  0, radius);
	cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 0.4);
	cairo_pattern_add_color_stop_rgba (pat, 1, 1, 1, 1, 0.0);
	cairo_set_source (cr, pat);
	cairo_fill (cr);
	cairo_pattern_destroy (pat); 

	return TRUE;
}
Exemple #24
0
EXPORT slate_int_t get_line_width(cairo_t *context)
{
  union float_int_union u;
  u.f = (float)cairo_get_line_width(context);
  return u.i;
}