• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ cairo_set_operator函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中cairo_set_operator函数的典型用法代码示例。如果您正苦于以下问题:C++ cairo_set_operator函数的具体用法?C++ cairo_set_operator怎么用?C++ cairo_set_operator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了cairo_set_operator函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: VisualizeXML

void VisualizeXML(NewsItem_p pNewsListHead,
                  cairo_t         *pCairoHandle)
{
  double dLinkWidth, dLinkHeight;
  double dWidth, dHeight;
  double dTitleWidth, dTitleHeight;
  // TODO

  cairo_set_operator(pCairoHandle, CAIRO_OPERATOR_OVER);

  // Query item link width
  cairo_select_font_face(pCairoHandle, "Helv",
                         1, 0.2);
  cairo_set_font_size(pCairoHandle,
                      0.03);
  cairo_set_source_rgba(pCairoHandle,
                        0.6, 0.6, 0.9,
                        0.8);

  QueryMultilineTextExtents(pCairoHandle,
                            pNewsListHead->pchItemLink,
                            &dLinkWidth, &dLinkHeight);


  // Show the multiline text, centered!
  cairo_select_font_face(pCairoHandle, "Helv",
                         0, 0);
  cairo_set_font_size(pCairoHandle,
                      0.05);
  cairo_set_source_rgba(pCairoHandle,
                        1, 1, 1,
                        1);

  QueryMultilineTextExtents(pCairoHandle,
                            pNewsListHead->pchItemDescription,
                            &dWidth, &dHeight);
  if (dWidth<dLinkWidth)
    dWidth = dLinkWidth;
  ShowMultilineText(pCairoHandle,
                    pNewsListHead->pchItemDescription,
                    (1*dXAspect-dWidth)/2, (1*dYAspect-dHeight)/2 );

  cairo_stroke (pCairoHandle);

  // Show the item title above it!
  cairo_select_font_face(pCairoHandle, "Helv",
                         1, 1);
  cairo_set_font_size(pCairoHandle,
                      0.055);
  cairo_set_source_rgba(pCairoHandle,
                        1, 1, 0.2,
                        0.9);
  QueryMultilineTextExtents(pCairoHandle,
                            pNewsListHead->pchItemTitle,
                            &dTitleWidth, &dTitleHeight);
  ShowMultilineText(pCairoHandle,
                    pNewsListHead->pchItemTitle,
                    (1*dXAspect-dTitleWidth)/2, (1*dYAspect-dHeight)/2 - 0.02 - dTitleHeight);

  cairo_stroke (pCairoHandle);

  // Show the item link under it!
  cairo_select_font_face(pCairoHandle, "Helv",
                         1, 0.2);
  cairo_set_font_size(pCairoHandle,
                      0.03);
  cairo_set_source_rgba(pCairoHandle,
                        0.6, 0.6, 0.9,
                        0.8);

  QueryMultilineTextExtents(pCairoHandle,
                            pNewsListHead->pchItemLink,
                            &dLinkWidth, &dLinkHeight);

  ShowMultilineText(pCairoHandle,
                    pNewsListHead->pchItemLink,
                    (1*dXAspect-dWidth)/2, (1*dYAspect-dHeight)/2 + 0.02 + dHeight);

  cairo_stroke (pCairoHandle);

}
开发者ID:OS2World,项目名称:UTIL-WPS-Doodle-Screen-Saver,代码行数:81,代码来源:ModuleSpec.c


示例2: DrawInputBar


//.........这里部分代码省略.........

    /* round to ROUND_SIZE in order to decrease resize */
    newWidth = (newWidth / ROUND_SIZE) * ROUND_SIZE + ROUND_SIZE;

    if (vertical) { /* vertical */
        newWidth = (newWidth < INPUT_BAR_VMIN_WIDTH) ? INPUT_BAR_VMIN_WIDTH : newWidth;
    } else {
        newWidth = (newWidth < INPUT_BAR_HMIN_WIDTH) ? INPUT_BAR_HMIN_WIDTH : newWidth;
    }

    *iwidth = newWidth;
    *iheight = newHeight;

    EnlargeCairoSurface(&inputWindow->cs_input_back, newWidth, newHeight);
    if (EnlargeCairoSurface(&inputWindow->cs_input_bar, newWidth, newHeight)) {
        LoadInputMessage(&classicui->skin, classicui->inputWindow, classicui->font);
    }

    if (oldHeight != newHeight || oldWidth != newWidth) {
        c = cairo_create(inputWindow->cs_input_back);
        DrawResizableBackground(c, inputimg->image, newHeight, newWidth,
                                sc->skinInputBar.marginLeft,
                                sc->skinInputBar.marginTop,
                                sc->skinInputBar.marginRight,
                                sc->skinInputBar.marginBottom,
                                sc->skinInputBar.fillV,
                                sc->skinInputBar.fillH
                               );
        cairo_destroy(c);
    }

    c = cairo_create(inputWindow->cs_input_bar);
    cairo_set_source_surface(c, inputWindow->cs_input_back, 0, 0);
    cairo_save(c);
    cairo_rectangle(c, 0, 0, newWidth, newHeight);
    cairo_set_operator(c, CAIRO_OPERATOR_SOURCE);
    cairo_clip(c);
    cairo_paint(c);
    cairo_restore(c);

    cairo_set_operator(c, CAIRO_OPERATOR_OVER);


    if (FcitxInputStateGetShowCursor(input)) {
        //画向前向后箭头
        if (prev && next) {
            cairo_set_source_surface(inputWindow->c_back, prev->image,
                                     newWidth - sc->skinInputBar.iBackArrowX ,
                                     sc->skinInputBar.iBackArrowY);
            if (FcitxCandidateWordHasPrev(FcitxInputStateGetCandidateList(input)))
                cairo_paint(inputWindow->c_back);
            else
                cairo_paint_with_alpha(inputWindow->c_back, 0.5);

            //画向前箭头
            cairo_set_source_surface(inputWindow->c_back, next->image,
                                     newWidth - sc->skinInputBar.iForwardArrowX ,
                                     sc->skinInputBar.iForwardArrowY);
            if (FcitxCandidateWordHasNext(FcitxInputStateGetCandidateList(input)))
                cairo_paint(inputWindow->c_back);
            else
                cairo_paint_with_alpha(inputWindow->c_back, 0.5);
        }
    }

    for (i = 0; i < FcitxMessagesGetMessageCount(msgup) ; i++) {
        OutputStringWithContext(inputWindow->c_font[FcitxMessagesGetMessageType(msgup, i)], dpi, strUp[i], posUpX[i], posUpY[i]);
        if (strUp[i] != FcitxMessagesGetMessageString(msgup, i))
            free(strUp[i]);
    }

    for (i = 0; i < FcitxMessagesGetMessageCount(msgdown) ; i++) {
        OutputStringWithContext(inputWindow->c_font[FcitxMessagesGetMessageType(msgdown, i)], dpi, strDown[i], posDownX[i], posDownY[i]);
        if (strDown[i] != FcitxMessagesGetMessageString(msgdown, i))
            free(strDown[i]);
    }

    int cursorY1, cursorY2;
    if (sc->skinFont.respectDPI) {
        cursorY1 = sc->skinInputBar.marginTop + sc->skinInputBar.iInputPos;
        cursorY2 = sc->skinInputBar.marginTop + sc->skinInputBar.iInputPos + fontHeight;
    }
    else {
        cursorY1 = sc->skinInputBar.marginTop + sc->skinInputBar.iInputPos - fontHeight;
        cursorY2 = sc->skinInputBar.marginTop + sc->skinInputBar.iInputPos;
    }

    //画光标
    if (FcitxInputStateGetShowCursor(input)) {
        cairo_move_to(inputWindow->c_cursor, cursor_pos, cursorY1);
        cairo_line_to(inputWindow->c_cursor, cursor_pos, cursorY2);
        cairo_stroke(inputWindow->c_cursor);
    }

    ResetFontContext();

    cairo_destroy(c);
    FcitxMessagesSetMessageChanged(msgup, false);
    FcitxMessagesSetMessageChanged(msgdown, false);
}
开发者ID:adaptee,项目名称:fcitx,代码行数:101,代码来源:skin.c


示例3: render_to_png

static svg_cairo_status_t
render_to_png (FILE *svg_file, FILE *png_file, double scale, int width, int height)
{
    unsigned int svg_width, svg_height;

    svg_cairo_status_t status;
    cairo_t *cr;
    svg_cairo_t *svgc;
    cairo_surface_t *surface;
    double dx = 0, dy = 0;

    status = svg_cairo_create (&svgc);
    if (status) {
	fprintf (stderr, "Failed to create svg_cairo_t. Exiting.\n");
	exit(1);
    }

    status = svg_cairo_parse_file (svgc, svg_file);
    if (status)
	return status;

    svg_cairo_get_size (svgc, &svg_width, &svg_height);

    if (width < 0 && height < 0) {
	width = (svg_width * scale + 0.5);
	height = (svg_height * scale + 0.5);
    } else if (width < 0) {
	scale = (double) height / (double) svg_height;
	width = (svg_width * scale + 0.5);
    } else if (height < 0) {
	scale = (double) width / (double) svg_width;
	height = (svg_height * scale + 0.5);
    } else {
	scale = MIN ((double) width / (double) svg_width, (double) height / (double) svg_height);
	/* Center the resulting image */
	dx = (width - (int) (svg_width * scale + 0.5)) / 2;
	dy = (height - (int) (svg_height * scale + 0.5)) / 2;
    }

    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
    cr = cairo_create (surface);
    
    cairo_save (cr);
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_paint (cr);
    cairo_restore (cr);

    cairo_translate (cr, dx, dy);
    cairo_scale (cr, scale, scale);

    /* XXX: This probably doesn't need to be here (eventually) */
    cairo_set_source_rgb (cr, 1, 1, 1);

    status = svg_cairo_render (svgc, cr);

    status = write_surface_to_png_file (surface, png_file);
    cairo_surface_destroy (surface);
    cairo_destroy (cr);
    
    if (status)
	return status;

    svg_cairo_destroy (svgc);

    return status;
}
开发者ID:Agentx86,项目名称:sea,代码行数:66,代码来源:svg2png.c


示例4: ppg_visualizer_task_notify_state

/**
 * ppg_visualizer_task_notify_state:
 * @visualizer: (in): A #PpgVisualizer.
 * @pspec: (in): A #GParamSpec.
 * @task: (in): A #PpgTask.
 *
 * Handle the "notify::state" signal from @task. Update the visualizer
 * pattern if necessary.
 *
 * Returns: None.
 * Side effects: None.
 */
static void
ppg_visualizer_task_notify_state (PpgVisualizer *visualizer,
                                  GParamSpec    *pspec,
                                  PpgTask       *task)
{
	PpgVisualizerPrivate *priv;
	cairo_surface_t *surface;
	PpgTaskState state;
	cairo_t *cr;
	gdouble begin_time;
	gdouble height;
	gdouble total_width;
	gdouble span;
	gdouble width;
	gdouble x;
	gdouble y;

	g_return_if_fail(PPG_IS_VISUALIZER(visualizer));
	g_return_if_fail(PPG_IS_TASK(task));
	g_return_if_fail(visualizer->priv->surface);

	priv = visualizer->priv;

	/*
	 * We don't own the reference, so safe to just drop our pointer. Using
	 * GObjects weak pointers here would be a lot of maintenance pain.
	 */
	if (priv->task == task) {
		priv->task = NULL;
	}

	g_object_get(task,
	             "state", &state,
	             "surface", &surface,
	             NULL);

	if (state == PPG_TASK_SUCCESS) {
		g_object_get(task,
		             "begin-time", &begin_time,
		             "height", &height,
		             "width", &width,
		             "x", &x,
		             "y", &y,
		             NULL);

		span = priv->end_time - priv->begin_time;
		g_object_get(visualizer, "width", &total_width, NULL);
		x = (begin_time - priv->begin_time) / span * total_width;

		/*
		 * Only draw what we can do on integer aligned offsets.
		 *
		 * TODO: We need to make sure we render extra area to prevent
		 *       a striping effect.
		 */
		width -= ceil(x) - x;
		x = ceil(x);

		cr = cairo_create(priv->surface);
		cairo_set_source_surface(cr, surface, x, y);
		if (cairo_status(cr) != 0) {
			cairo_destroy(cr);
			GOTO(failure);
		}

		/*
		 * Clip the range of the draw.
		 */
		cairo_rectangle(cr, x, y, width, height);
		cairo_clip_preserve(cr);

		/*
		 * Clear the draw area.
		 */
		cairo_save(cr);
		cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
		cairo_fill_preserve(cr);
		cairo_restore(cr);

		/*
		 * Fill in the rendered image.
		 */
		cairo_fill(cr);
		cairo_destroy(cr);

		goo_canvas_item_request_update(GOO_CANVAS_ITEM(visualizer));
	}

//.........这里部分代码省略.........
开发者ID:chergert,项目名称:perfkit,代码行数:101,代码来源:ppg-visualizer.c


示例5: switch

void cairo_context::set_operator(composite_mode_e comp_op)
{
    switch (comp_op)
    {
    case clear:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_CLEAR);
        break;
    case src:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_SOURCE);
        break;
    case dst:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_DEST);
        break;
    case src_over:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_OVER);
        break;
    case dst_over:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_DEST_OVER);
        break;
    case src_in:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_IN);
        break;
    case dst_in:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_DEST_IN);
        break;
    case src_out:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_OUT);
        break;
    case dst_out:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_DEST_OUT);
        break;
    case src_atop:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_ATOP);
        break;
    case dst_atop:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_DEST_ATOP);
        break;
    case _xor:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_XOR);
        break;
    case plus:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_ADD);
        break;
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 10, 0)
    case multiply:
        cairo_set_operator(cairo_.get(), CAIRO_OPERATOR_MULTIPLY);
        break;
    case screen:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_SCREEN);
        break;
    case overlay:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_OVERLAY);
        break;
    case darken:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_DARKEN);
        break;
    case lighten:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_LIGHTEN);
        break;
    case color_dodge:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_COLOR_DODGE);
        break;
    case color_burn:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_COLOR_BURN);
        break;
    case hard_light:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_HARD_LIGHT);
        break;
    case soft_light:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_SOFT_LIGHT);
        break;
    case difference:
        cairo_set_operator(cairo_.get(),CAIRO_OPERATOR_DIFFERENCE);
        break;
    case exclusion:
        cairo_set_operator(cairo_.get(), CAIRO_OPERATOR_EXCLUSION);
        break;
#else
#warning building against cairo older that 1.10.0, some compositing options are disabled
    case multiply:
    case screen:
    case overlay:
    case darken:
    case lighten:
    case color_dodge:
    case color_burn:
    case hard_light:
    case soft_light:
    case difference:
    case exclusion:
        break;
#endif
    case contrast:
    case minus:
    case invert:
    case invert_rgb:
    case grain_merge:
    case grain_extract:
    case hue:
    case saturation:
//.........这里部分代码省略.........
开发者ID:zuiwanting,项目名称:mapnik,代码行数:101,代码来源:cairo_context.cpp


示例6: draw_flower

static gboolean
draw_flower (ClutterCanvas *canvas,
             cairo_t       *cr,
             gint           width,
             gint           height,
             gpointer       user_data)
{
    /* No science here, just a hack from toying */
    gint i, j;

    double colors[] = {
        0.71, 0.81, 0.83,
        1.0,  0.78, 0.57,
        0.64, 0.30, 0.35,
        0.73, 0.40, 0.39,
        0.91, 0.56, 0.64,
        0.70, 0.47, 0.45,
        0.92, 0.75, 0.60,
        0.82, 0.86, 0.85,
        0.51, 0.56, 0.67,
        1.0, 0.79, 0.58,

    };

    gint size;
    gint petal_size;
    gint n_groups;    /* Num groups of petals 1-3 */
    gint n_petals;    /* num of petals 4 - 8  */
    gint pm1, pm2;

    gint idx, last_idx = -1;

    petal_size = GPOINTER_TO_INT (user_data);
    size = petal_size * 8;

    n_groups = rand() % 3 + 1;

    cairo_set_tolerance (cr, 0.1);

    /* Clear */
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_paint(cr);
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

    cairo_translate(cr, size/2, size/2);

    for (i=0; i<n_groups; i++)
    {
        n_petals = rand() % 5 + 4;
        cairo_save (cr);

        cairo_rotate (cr, rand() % 6);

        do {
            idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
        } while (idx == last_idx);

        cairo_set_source_rgba (cr, colors[idx], colors[idx+1],
                               colors[idx+2], 0.5);

        last_idx = idx;

        /* some bezier randomness */
        pm1 = rand() % 20;
        pm2 = rand() % 4;

        for (j=1; j<n_petals+1; j++)
        {
            cairo_save (cr);
            cairo_rotate (cr, ((2*M_PI)/n_petals)*j);

            /* Petals are made up beziers */
            cairo_new_path (cr);
            cairo_move_to (cr, 0, 0);
            cairo_rel_curve_to (cr,
                                petal_size, petal_size,
                                (pm2+2)*petal_size, petal_size,
                                (2*petal_size) + pm1, 0);
            cairo_rel_curve_to (cr,
                                0 + (pm2*petal_size), -petal_size,
                                -petal_size, -petal_size,
                                -((2*petal_size) + pm1), 0);
            cairo_close_path (cr);
            cairo_fill (cr);
            cairo_restore (cr);
        }

        petal_size -= rand() % (size/8);

        cairo_restore (cr);
    }

    /* Finally draw flower center */
    do {
        idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
    } while (idx == last_idx);

    if (petal_size < 0)
        petal_size = rand() % 10;

//.........这里部分代码省略.........
开发者ID:jigpu,项目名称:clutter,代码行数:101,代码来源:test-cairo-flowers.c


示例7: gen_faceplate

static void gen_faceplate (BITui* ui, const int ww, const int hh) {
	assert(!ui->m0_faceplate);
	ui->m0_faceplate = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, ww, hh);
	cairo_t* cr = cairo_create (ui->m0_faceplate);

	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr);
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

	const int spc = (int) floorf ((ww - 28) / 28.) & ~1;
	const int rad = ceilf (spc * .75);
	const int mid = rint (spc * .75 * .5);
	const int x0r = rint (ww * .5 + 12 * spc);
	const int xpr = rint (ww * .5 - 13 * spc);

	const int spc_s = (int) floorf (ww / 45.) & ~1;
	const int rad_s = ceilf (spc_s * .75);
	const int x0r_s  = ww * .5 + 20 * spc_s;

	const int y0   = hh - 60 - rad_s - spc;
	const int y0_s = hh - 20 - rad_s;

	const int y0_g = 10;
	const int y1_g = y0 - 4;
	const int yh_g = y1_g - y0_g;

	// grid & annotations -- TODO statically allocate surface
	const float x0_g = xpr - 2;
	const float x1_b = x0r + rad + 2;
	const float x1_g = x1_b + mid + 2;
	const float yc_g = rintf (y0_g + .5 * yh_g);
	const float y6_g = rintf (y0_g +  yh_g * 2. / 3.);
	const float y3_g = rintf (y0_g +  yh_g / 3.);

	cairo_rectangle (cr, x1_b, y0_g, mid, y3_g);
	cairo_set_source_rgba (cr, .8, .5, .1, 1.0);
	cairo_fill (cr);
	cairo_rectangle (cr, x1_b, y3_g, mid, y6_g - y3_g);
	cairo_set_source_rgba (cr, .1, .9, .1, 1.0);
	cairo_fill (cr);
	cairo_rectangle (cr, x1_b, y6_g, mid, y1_g - y6_g);
	cairo_set_source_rgba (cr, .1, .6, .9, 1.0);
	cairo_fill (cr);

	cairo_set_line_width (cr, 2);
	cairo_move_to (cr, x1_b, y0_g);
	cairo_line_to (cr, x1_b + mid, y0_g);
	cairo_set_source_rgba (cr, .9, .0, .0, 1.0);
	cairo_stroke (cr);
	cairo_move_to (cr, x1_b, y0_g + yh_g);
	cairo_line_to (cr, x1_b + mid, y0_g + yh_g);
	cairo_set_source_rgba (cr, .0, .0, .9, 1.0);
	cairo_stroke (cr);

	CairoSetSouerceRGBA(c_g80);
	cairo_set_line_width (cr, 1);

	cairo_save (cr);
	double dash = 1;
	cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
	cairo_set_dash (cr, &dash, 1, 0);

	cairo_move_to (cr, x0_g, y0_g - .5);
	cairo_line_to (cr, x1_b, y0_g - .5);
	cairo_stroke (cr);

	cairo_move_to (cr, x0_g, .5 + yc_g);
	cairo_line_to (cr, x0_g + spc + 4, .5 + yc_g);
	cairo_stroke (cr);

	cairo_move_to (cr, x0_g, .5 + y6_g);
	cairo_line_to (cr, x1_b, .5 + y6_g);
	cairo_stroke (cr);

	cairo_move_to (cr, x0_g, .5 + y3_g);
	cairo_line_to (cr, x1_b, .5 + y3_g);
	cairo_stroke (cr);

	cairo_move_to (cr, x0_g, y1_g + .5);
	cairo_line_to (cr, x1_b, y1_g + .5);
	cairo_stroke (cr);

	cairo_restore (cr);

	cairo_move_to (cr, 1.5 + rintf (x0r_s - 33 * spc_s), y0_s - 1.5);
	cairo_line_to (cr, 1.5 + rintf (x0r_s - 33 * spc_s), y0_s + rad_s + 3.5);
	cairo_line_to (cr, .5 + rintf (x0r_s - 35.5 * spc_s), y0_s + rad_s + 3.5);
	cairo_stroke (cr);


	write_text_full (cr, ">1.0",
				FONT(FONT_M), x0r_s - 33.0 * spc_s, hh - 2, 0, 4, c_wht);
	write_text_full (cr, "<markup>2<small><sup>-32</sup></small></markup>",
				FONT(FONT_M), x0r_s + 0.5 * spc_s, hh - 2, 0, 5, c_wht);
	write_text_full (cr, "<markup>2<small><sup>-24</sup></small></markup>",
				FONT(FONT_M), x0r_s - 8.0 * spc_s, hh - 2, 0, 5, c_wht);
	write_text_full (cr, "<markup>2<small><sup>-16</sup></small></markup>",
				FONT(FONT_M), x0r_s - 16.5 * spc_s, hh - 2, 0, 5, c_wht);
	write_text_full (cr, "<markup>2<small><sup>-8</sup></small></markup>",
				FONT(FONT_M), x0r_s - 25.0 * spc_s, hh - 2, 0, 5, c_wht);
//.........这里部分代码省略.........
开发者ID:EQ4,项目名称:meters.lv2,代码行数:101,代码来源:bitmeter.c


示例8: draw

static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *gradient, *image;

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

    cairo_translate (cr, PAD, PAD);

    /* clip to the unit size */
    cairo_rectangle (cr, 0, 0,
                     UNIT_SIZE, UNIT_SIZE);
    cairo_clip (cr);

    cairo_rectangle (cr, 0, 0,
                     UNIT_SIZE, UNIT_SIZE);
    cairo_set_source_rgba (cr, 0, 0, 0, 1);
    cairo_set_line_width (cr, 2);
    cairo_stroke (cr);

    /* start a group */
    cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR);

    /* draw a gradient background */
    cairo_save (cr);
    cairo_translate (cr, INNER_PAD, INNER_PAD);
    cairo_new_path (cr);
    cairo_rectangle (cr, 0, 0,
                     UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
    gradient = cairo_pattern_create_linear (UNIT_SIZE - (INNER_PAD*2), 0,
                                            UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
    cairo_pattern_add_color_stop_rgba (gradient, 0.0, 0.3, 0.3, 0.3, 1.0);
    cairo_pattern_add_color_stop_rgba (gradient, 1.0, 1.0, 1.0, 1.0, 1.0);
    cairo_set_source (cr, gradient);
    cairo_pattern_destroy (gradient);
    cairo_fill (cr);
    cairo_restore (cr);

    /* draw diamond */
    cairo_move_to (cr, UNIT_SIZE / 2, 0);
    cairo_line_to (cr, UNIT_SIZE    , UNIT_SIZE / 2);
    cairo_line_to (cr, UNIT_SIZE / 2, UNIT_SIZE);
    cairo_line_to (cr, 0            , UNIT_SIZE / 2);
    cairo_close_path (cr);
    cairo_set_source_rgba (cr, 0, 0, 1, 1);
    cairo_fill (cr);

    /* draw circle */
    cairo_arc (cr,
               UNIT_SIZE / 2, UNIT_SIZE / 2,
               UNIT_SIZE / 3.5,
               0, M_PI * 2);
    cairo_set_source_rgba (cr, 1, 0, 0, 1);
    cairo_fill (cr);

    /* and put the image on top */
    cairo_translate (cr, UNIT_SIZE/2 - 8, UNIT_SIZE/2 - 8);
    image = argb32_source ();
    cairo_set_source (cr, image);
    cairo_pattern_destroy (image);
    cairo_paint (cr);

    cairo_pop_group_to_source (cr);
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;
}
开发者ID:ghub,项目名称:NVprSDK,代码行数:69,代码来源:push-group-color.c


示例9: createImageCairo

imageObj* createImageCairo(int width, int height, outputFormatObj *format,colorObj* bg) {
    imageObj *image = NULL;
    cairo_renderer *r=NULL;
    if (format->imagemode != MS_IMAGEMODE_RGB && format->imagemode!= MS_IMAGEMODE_RGBA) {
        msSetError(MS_MISCERR,
                   "Cairo driver only supports RGB or RGBA pixel models.","msImageCreateCairo()");
        return image;
    }
    if (width > 0 && height > 0) {
        image = (imageObj *) calloc(1, sizeof(imageObj));
        r = (cairo_renderer*)calloc(1,sizeof(cairo_renderer));
        if(!strcasecmp(format->driver,"cairo/pdf")) {
            r->outputStream = (bufferObj*)malloc(sizeof(bufferObj));
            msBufferInit(r->outputStream);
            r->surface = cairo_pdf_surface_create_for_stream(
                    _stream_write_fn,
                    r->outputStream,
                    width,height);
        } else if(!strcasecmp(format->driver,"cairo/svg")) {
            r->outputStream = (bufferObj*)malloc(sizeof(bufferObj));
            msBufferInit(r->outputStream);
            r->surface = cairo_svg_surface_create_for_stream(
                    _stream_write_fn,
                    r->outputStream,
                    width,height);
        } else if(!strcasecmp(format->driver,"cairo/winGDI") && format->device) {
#if CAIRO_HAS_WIN32_SURFACE
            r->outputStream = NULL;
            r->surface = cairo_win32_surface_create(format->device);
#else
            msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.",
             "msImageCreateCairo()");
#endif
        } else if(!strcasecmp(format->driver,"cairo/winGDIPrint") && format->device) {
#if CAIRO_HAS_WIN32_SURFACE
            r->outputStream = NULL;
            r->surface = cairo_win32_printing_surface_create(format->device);
#else
            msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.",
             "msImageCreateCairo()");
#endif
        } else {
            r->outputStream = NULL;
            r->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
        }
        r->cr = cairo_create(r->surface);
        if(format->transparent || !bg || !MS_VALID_COLOR(*bg)) {
           r->use_alpha = 1;
           cairo_set_source_rgba (r->cr, 0,0,0,0);
        } else {
           r->use_alpha = 0;
           msCairoSetSourceColor(r->cr,bg);
        }
        cairo_save (r->cr);
        cairo_set_operator (r->cr, CAIRO_OPERATOR_SOURCE);
        cairo_paint (r->cr);
        cairo_restore (r->cr);

        cairo_set_line_cap (r->cr,CAIRO_LINE_CAP_ROUND);
        cairo_set_line_join(r->cr,CAIRO_LINE_JOIN_ROUND);
        image->img.plugin = (void*)r;
    } else {
       msSetError(MS_RENDERERERR, "Cannot create cairo image of size %dx%d.",
                  "msImageCreateCairo()", width, height);
    }
    return image;
}
开发者ID:msilex,项目名称:mapserver,代码行数:67,代码来源:mapcairo.c


示例10: cairo_image_surface_create

bool
TextAsset::load()
{
    // Set up a temporary Cairo surface/context for text measurement
    cairo_surface_t* probeSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);

    if (cairo_surface_status(probeSurface) != CAIRO_STATUS_SUCCESS) {
        fprintf(stderr, "Could not create Cairo surface\n");
        _error = true;
        return false;
    }

    cairo_t* probeContext = cairo_create(probeSurface);
    if (cairo_status(probeContext) != CAIRO_STATUS_SUCCESS) {
        fprintf(stderr, "Could not create Cairo context\n");
        _error = true;
        return false;
    }

    // Text rectangle drawn within border
    const int idealWidth = _maxSize.width - _marginLeft - _marginRight;

    const Size textRegion(idealWidth, _maxSize.height - _marginTop - _marginBottom);
    const float fontSize = primaryFontSize(probeContext, textRegion);

    const std::string fontDesc = _fontName + " " + boost::lexical_cast<std::string>(fontSize);
    PangoFontDescription* fontDescription = pango_font_description_from_string(fontDesc.c_str());

    const std::string req_desc_str(pango_font_description_to_string(fontDescription));
    PangoFontMap* fontMap = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
    PangoContext* pango_context = pango_font_map_create_context(fontMap);

    // TODO: Does this need to be freed or does the context take it with it?
    PangoFont* pangoFont = pango_font_map_load_font(fontMap, pango_context, fontDescription);
    PangoFontDescription* reverseDescription = pango_font_describe(pangoFont);
    const std::string match_desc_str(pango_font_description_to_string(reverseDescription));
    pango_font_description_free(reverseDescription);
    g_object_unref(pango_context);

    if (req_desc_str.find(match_desc_str) == std::string::npos) {
        fprintf(stderr, "Warning: Unable to correctly match font \"%s\", using "
                "\"%s\" instead.\n", req_desc_str.c_str(), match_desc_str.c_str());
    }

    float shadowXOffset = 0;
    float shadowYOffset = 0;
    if (_dropShadow) {
        shadowXOffset = _dropShadowOffset.x() * CLIENT_TO_SERVER_SCALE * fontSize;
        shadowYOffset = _dropShadowOffset.y() * CLIENT_TO_SERVER_SCALE * fontSize;
    }

    Rect tight;
    const Size textSize = computeSizeOfText(probeContext, _textContent, idealWidth, fontDescription, &tight);
    const Size imageSize = imageSizeForTextSize(tight.size, shadowXOffset, shadowYOffset);

    // Tear down scratch contexts
    cairo_destroy(probeContext);
    cairo_surface_destroy(probeSurface);

    const int width = imageSize.width;
    const int height = imageSize.height;

    // Configure the actual Cairo drawing surface/context now that we know the final resolution
    cairo_surface_t* cairoSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
    if (cairo_surface_status(cairoSurface) != CAIRO_STATUS_SUCCESS) {
        fprintf(stderr, "Could not create Cairo surface\n");
        _error = true;
        return false;
    }

    cairo_t* cairoContext = cairo_create(cairoSurface);

    // Flip the context like in the iOS version.
    // This fixes flipped filters associated with text assets.
    cairo_translate(cairoContext, 0.0, height);
    cairo_scale(cairoContext, 1.0, -1.0);

    if (cairo_status(cairoContext) != CAIRO_STATUS_SUCCESS) {
        fprintf(stderr, "Could not create Cairo context\n");
        _error = true;
        return false;
    }

    // Fill the box with the background color
    cairo_save(cairoContext);
    cairo_set_operator(cairoContext, CAIRO_OPERATOR_SOURCE);

    const mf::Color& bgColor(_style->getBackgroundColor());
    cairo_set_source_rgba(cairoContext, bgColor.red, bgColor.green, bgColor.blue, bgColor.alpha);

    if (_shape == 0) {
        if (_cornerWidth > 0 && _cornerHeight > 0) {
            // TODO: Support independent corner width and height
            drawRoundedRect(cairoContext, 0, 0, imageSize.width, imageSize.height, _cornerWidth);
        } else {
            cairo_paint(cairoContext);
            if (_strokeThickness > 0.0f) {
                drawStrokedRect(cairoContext, 0, 0, imageSize.width, imageSize.height, _strokeThickness);
            }
        }
//.........这里部分代码省略.........
开发者ID:CaringLabs,项目名称:MediaFramework,代码行数:101,代码来源:TextAsset.cpp


示例11: platformContext

void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int /* offset */, const Color& color)
{
    if (paintingDisabled())
        return;

    unsigned rectCount = rects.size();

    cairo_t* cr = platformContext()->cr();
    cairo_save(cr);
    cairo_push_group(cr);
    cairo_new_path(cr);

#if PLATFORM(GTK)
#ifdef GTK_API_VERSION_2
    GdkRegion* reg = gdk_region_new();
#else
    cairo_region_t* reg = cairo_region_create();
#endif

    for (unsigned i = 0; i < rectCount; i++) {
#ifdef GTK_API_VERSION_2
        GdkRectangle rect = rects[i];
        gdk_region_union_with_rect(reg, &rect);
#else
        cairo_rectangle_int_t rect = rects[i];
        cairo_region_union_rectangle(reg, &rect);
#endif
    }
    gdk_cairo_region(cr, reg);
#ifdef GTK_API_VERSION_2
    gdk_region_destroy(reg);
#else
    cairo_region_destroy(reg);
#endif
#else
    int radius = (width - 1) / 2;
    Path path;
    for (unsigned i = 0; i < rectCount; ++i) {
        if (i > 0)
            path.clear();
        path.addRoundedRect(rects[i], FloatSize(radius, radius));
        appendWebCorePathToCairoContext(cr, path);
    }
#endif
    Color ringColor = color;
    adjustFocusRingColor(ringColor);
    adjustFocusRingLineWidth(width);
    setSourceRGBAFromColor(cr, ringColor);
    cairo_set_line_width(cr, width);
    setPlatformStrokeStyle(focusRingStrokeStyle());

    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
    cairo_stroke_preserve(cr);

    cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
    cairo_fill(cr);

    cairo_pop_group_to_source(cr);
    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
    cairo_paint(cr);
    cairo_restore(cr);
}
开发者ID:sysrqb,项目名称:chromium-src,代码行数:63,代码来源:GraphicsContextCairo.cpp


示例12: ReadPANGOImage


//.........这里部分代码省略.........
  else
    {
      image->columns-=2*page.x;
      pango_layout_set_width(layout,(int) ((PANGO_SCALE*image->columns*
        (image->resolution.x == 0.0 ? 90.0 : image->resolution.x)+45.0)/90.0+
        0.5));
    }
  if (image->rows == 0)
    {
      pango_layout_get_extents(layout,NULL,&extent);
      image->rows=(extent.y+extent.height+PANGO_SCALE/2)/PANGO_SCALE+2*page.y;
    }
  else
    {
      image->rows-=2*page.y;
      pango_layout_set_height(layout,(int) ((PANGO_SCALE*image->rows*
        (image->resolution.y == 0.0 ? 90.0 : image->resolution.y)+45.0)/90.0+
        0.5));
    }
  /*
    Render markup.
  */
  stride=(size_t) cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
    image->columns);
  pixels=(unsigned char *) AcquireQuantumMemory(image->rows,stride*
    sizeof(*pixels));
  if (pixels == (unsigned char *) NULL)
    {
      draw_info=DestroyDrawInfo(draw_info);
      caption=DestroyString(caption);
      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
    }
  surface=cairo_image_surface_create_for_data(pixels,CAIRO_FORMAT_ARGB32,
    image->columns,image->rows,stride);
  cairo_image=cairo_create(surface);
  cairo_set_operator(cairo_image,CAIRO_OPERATOR_CLEAR);
  cairo_paint(cairo_image);
  cairo_set_operator(cairo_image,CAIRO_OPERATOR_OVER);
  cairo_translate(cairo_image,page.x,page.y);
  pango_cairo_show_layout(cairo_image,layout);
  cairo_destroy(cairo_image);
  cairo_surface_destroy(surface);
  g_object_unref(layout);
  g_object_unref(fontmap);
  /*
    Convert surface to image.
  */
  (void) SetImageBackgroundColor(image,exception);
  p=pixels;
  GetPixelInfo(image,&fill_color);
  for (y=0; y < (ssize_t) image->rows; y++)
  {
    register Quantum
      *q;

    register ssize_t
      x;

    q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
    if (q == (Quantum *) NULL)
      break;
    for (x=0; x < (ssize_t) image->columns; x++)
    {
      double
        gamma;

      fill_color.blue=(double) ScaleCharToQuantum(*p++);
      fill_color.green=(double) ScaleCharToQuantum(*p++);
      fill_color.red=(double) ScaleCharToQuantum(*p++);
      fill_color.alpha=(double) ScaleCharToQuantum(*p++);
      /*
        Disassociate alpha.
      */
      gamma=1.0-QuantumScale*fill_color.alpha;
      gamma=PerceptibleReciprocal(gamma);
      fill_color.blue*=gamma;
      fill_color.green*=gamma;
      fill_color.red*=gamma;
      CompositePixelOver(image,&fill_color,fill_color.alpha,q,(double)
        GetPixelAlpha(image,q),q);
      q+=GetPixelChannels(image);
    }
    if (SyncAuthenticPixels(image,exception) == MagickFalse)
      break;
    if (image->previous == (Image *) NULL)
      {
        status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
        image->rows);
        if (status == MagickFalse)
          break;
      }
  }
  /*
    Relinquish resources.
  */
  pixels=(unsigned char *) RelinquishMagickMemory(pixels);
  draw_info=DestroyDrawInfo(draw_info);
  caption=DestroyString(caption);
  return(GetFirstImageInList(image));
}
开发者ID:epu,项目名称:ImageMagick,代码行数:101,代码来源:pango.c


示例13: render_hex

void render_hex (cairo_t *cr, int x, int y, int w) {

	cairo_pattern_t *pat;
	static float hexrot = 0;
	int r1;
	float scale;
		
	cairo_save(cr);
	cairo_set_line_width(cr, 1);
	cairo_set_source_rgb(cr, ORANGE);

	scale = 2.5;
	r1 = ((w)/2 * sqrt(3));

	cairo_translate (cr, x, y);
	cairo_rotate (cr, hexrot * (M_PI/180.0));
	cairo_translate (cr, -(w/2), -r1);

	cairo_move_to (cr, 0, 0);
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	hexrot += 1.5;
	cairo_fill (cr);
	
	cairo_restore(cr);
	cairo_save(cr);
		
	cairo_set_line_width(cr, 1.5);
	cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
	cairo_set_source_rgb(cr, GREY);


	cairo_translate (cr, x, y);
	cairo_rotate (cr, hexrot * (M_PI/180.0));
	cairo_translate (cr, -((w * scale)/2), -r1 * scale);
	cairo_scale(cr, scale, scale);

	cairo_move_to (cr, 0, 0);
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	cairo_rotate (cr, 60 * (M_PI/180.0));
	cairo_rel_line_to (cr, w, 0);
	
	cairo_rotate (cr, 60 * (M_PI/180.0));

	cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
	pat = cairo_pattern_create_radial (w/2, r1, 3, w/2, r1, r1*scale);
	cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 1, 1);
	cairo_pattern_add_color_stop_rgba (pat, 0.4, 0, 0, 0, 0);
	cairo_set_source (cr, pat);
	
	cairo_fill (cr);
	cairo_pattern_destroy (pat);
	cairo_restore(cr);

}
开发者ID:dsheeler,项目名称:krad_radio,代码行数:72,代码来源:kr_udp_recvrw.c


示例14: draw_line

static void
draw_line(struct clickdot *clickdot, cairo_t *cr,
	  struct rectangle *allocation)
{
	cairo_t *bcr;
	cairo_surface_t *tmp_buffer = NULL;

	if (clickdot->reset) {
		tmp_buffer = clickdot->buffer;
		clickdot->buffer = NULL;
		clickdot->line.x = -1;
		clickdot->line.y = -1;
		clickdot->line.old_x = -1;
		clickdot->line.old_y = -1;
		clickdot->reset = 0;
	}

	if (clickdot->buffer == NULL) {
		clickdot->buffer =
			cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
						   allocation->width,
						   allocation->height);
		bcr = cairo_create(clickdot->buffer);
		cairo_set_source_rgba(bcr, 0, 0, 0, 0);
		cairo_rectangle(bcr,
				0, 0,
				allocation->width, allocation->height);
		cairo_fill(bcr);
	}
	else
		bcr = cairo_create(clickdot->buffer);

	if (tmp_buffer) {
		cairo_set_source_surface(bcr, tmp_buffer, 0, 0);
		cairo_rectangle(bcr, 0, 0,
				allocation->width, allocation->height);
		cairo_clip(bcr);
		cairo_paint(bcr);

		cairo_surface_destroy(tmp_buffer);
	}

	if (clickdot->line.x != -1 && clickdot->line.y != -1) {
		if (clickdot->line.old_x != -1 &&
		    clickdot->line.old_y != -1) {
			cairo_set_line_width(bcr, 2.0);
			cairo_set_source_rgb(bcr, 1, 1, 1);
			cairo_translate(bcr,
					-allocation->x, -allocation->y);

			cairo_move_to(bcr,
				      clickdot->line.old_x,
				      clickdot->line.old_y);
			cairo_line_to(bcr,
				      clickdot->line.x,
				      clickdot->line.y);

			cairo_stroke(bcr);
		}

		clickdot->line.old_x = clickdot->line.x;
		clickdot->line.old_y = clickdot->line.y;
	}
	cairo_destroy(bcr);

	cairo_set_source_surface(cr, clickdot->buffer,
				 allocation->x, allocation->y);
	cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
	cairo_rectangle(cr,
			allocation->x, allocation->y,
			allocation->width, allocation->height);
	cairo_clip(cr);
	cairo_paint(cr);
}
开发者ID:Tarnyko,项目名称:weston-ivi-shell,代码行数:74,代码来源:clickdot.c


示例15: scale_render

static void scale_render(GpsdViewerOsd *self, OsmGpsMap *map)
{
    GpsdViewerOsdScale *scale = self->priv->scale;

    if(!scale->surface)
        return;

    /* this only needs to be rendered if the zoom or latitude has changed */
    gint zoom;
    gfloat lat;
    g_object_get(G_OBJECT(map), "zoom", &zoom, "latitude", &lat, NULL);
    if(zoom == scale->zoom && lat == scale->lat)
        return;

    scale->zoom = zoom;
    scale->lat = lat;

    float m_per_pix = osm_gps_map_get_scale(map);

    /* first fill with transparency */
    g_assert(scale->surface);
    cairo_t *cr = cairo_create(scale->surface);
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
    // pink for testing:    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
    cairo_paint(cr);
    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

    /* determine the size of the scale width in meters */
    float width = (GPSD_VIEWER_OSD_SCALE_W-GPSD_VIEWER_OSD_SCALE_FONT_SIZE/6) * m_per_pix;

    /* scale this to useful values */
    int exp = logf(width)*M_LOG10E;
    int mant = width/pow(10,exp);
    int width_metric = mant * pow(10,exp);
    char *dist_str = NULL;
    if(width_metric<1000)
        dist_str = g_strdup_printf("%u m", width_metric);
    else
        dist_str = g_strdup_printf("%u km", width_metric/1000);
    width_metric /= m_per_pix;

    /* and now the hard part: scale for useful imperial values :-( */
    /* try to convert to feet, 1ft == 0.3048 m */
    width /= 0.3048;
    float imp_scale = 0.3048;
    char *dist_imp_unit = "ft";

    if(width >= 100) {
        /* 1yd == 3 feet */
        width /= 3.0;
        imp_scale *= 3.0;
        dist_imp_unit = "yd";

        if(width >= 1760.0) {
            /* 1mi == 1760 yd */
            width /= 1760.0;
            imp_scale *= 1760.0;
            dist_imp_unit = "mi";
        }
    }

    /* also convert this to full tens/hundreds */
    exp = logf(width)*M_LOG10E;
    mant = width/pow(10,exp);
    int width_imp = mant * pow(10,exp);
    char *dist_str_imp = g_strdup_printf("%u %s", width_imp, dist_imp_unit);

    /* convert back to pixels */
    width_imp *= imp_scale;
    width_imp /= m_per_pix;

    cairo_select_font_face (cr, "Sans",
                            CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, GPSD_VIEWER_OSD_SCALE_FONT_SIZE);
    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);

    cairo_text_extents_t extents;
    cairo_text_extents (cr, dist_str, &extents);

    cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
    cairo_set_line_width (cr, GPSD_VIEWER_OSD_SCALE_FONT_SIZE/6);
    cairo_move_to (cr, 2*GPSD_VIEWER_OSD_SCALE_FD, GPSD_VIEWER_OSD_SCALE_H2-GPSD_VIEWER_OSD_SCALE_FD);
    cairo_text_path (cr, dist_str);
    cairo_stroke (cr);
    cairo_move_to (cr, 2*GPSD_VIEWER_OSD_SCALE_FD,
                   GPSD_VIEWER_OSD_SCALE_H2+GPSD_VIEWER_OSD_SCALE_FD + extents.height);
    cairo_text_path (cr, dist_str_imp);
    cairo_stroke (cr);

    cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
    cairo_move_to (cr, 2*GPSD_VIEWER_OSD_SCALE_FD, GPSD_VIEWER_OSD_SCALE_H2-GPSD_VIEWER_OSD_SCALE_FD);
    cairo_show_text (cr, dist_str);
    cairo_move_to (cr, 2*GPSD_VIEWER_OSD_SCALE_FD,
                   GPSD_VIEWER_OSD_SCALE_H2+GPSD_VIEWER_OSD_SCALE_FD + extents.height);
    cairo_show_text (cr, dist_str_imp);

    g_free(dist_str);
    g_free(dist_str_imp);
//.........这里部分代码省略.........
开发者ID:Flystix,项目名称:FroboMind,代码行数:101,代码来源:gpsd_viewer_osd.c


示例16: _gtk_pixel_cache_set_position


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ cairo_set_source函数代码示例发布时间:2022-05-30
下一篇:
C++ cairo_set_matrix函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap