Beispiel #1
0
static void _expose_info_bar(dt_lib_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, int32_t pointery)
{
  dt_lib_camera_t *lib=(dt_lib_camera_t *)self->data;

  // Draw infobar background at top
  cairo_set_source_rgb (cr, .0,.0,.0);
  cairo_rectangle(cr, 0, 0, width, BAR_HEIGHT);
  cairo_fill (cr);

  cairo_set_source_rgb (cr,.8,.8,.8);

  // Draw left aligned value camera model value
  cairo_text_extents_t te;
  char model[4096]= {0};
  sprintf(model+strlen(model),"%s", lib->data.camera_model );
  cairo_text_extents (cr, model, &te);
  cairo_move_to (cr,5, 1+BAR_HEIGHT - te.height / 2 );
  cairo_show_text(cr, model);

  // Draw right aligned battary value
  const char *battery_value=dt_camctl_camera_get_property(darktable.camctl,NULL,"batterylevel");
  char battery[4096]= {0};
  sprintf(battery,"%s: %s", _("battery"), battery_value?battery_value:_("n/a"));
  cairo_text_extents (cr, battery, &te);
  cairo_move_to(cr,width-te.width-5, 1+BAR_HEIGHT - te.height / 2 );
  cairo_show_text(cr, battery);

  // Let's cook up the middle part of infobar
  gchar center[1024]= {0};
  for(int i=0; i<g_list_length(lib->gui.properties); i++)
  {
    dt_lib_camera_property_t *prop=(dt_lib_camera_property_t *)g_list_nth_data(lib->gui.properties,i);
    if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prop->osd)) == TRUE )
    {
      g_strlcat(center,"      ",1024);
      g_strlcat(center,prop->name,1024);
      g_strlcat(center,": ",1024);
      g_strlcat(center,gtk_combo_box_get_active_text(prop->values),1024);
    }
  }
  g_strlcat(center,"      ",1024);

  // Now lets put it in center view...
  cairo_text_extents (cr, center, &te);
  cairo_move_to(cr,(width/2)-(te.width/2), 1+BAR_HEIGHT - te.height / 2 );
  cairo_show_text(cr, center);


}
/*
    To test, copy the the following files to the disk image:
        vcopy /dev/sdb ../../es-trunk/cmd/fonts.conf
        vcopy /dev/sdb ../../es-trunk/cmd/fonts.dtd
        vcopy /dev/sdb ../../es-trunk/cmd/40-generic.conf conf.d/
        vcopy /dev/sdb /usr/share/fonts/liberation/LiberationMono-Regular.ttf fonts/
        vcopy /dev/sdb /usr/share/fonts/liberation/LiberationSans-Regular.ttf fonts/
        vcopy /dev/sdb /usr/share/fonts/liberation/LiberationSerif-Regular.ttf fonts/

 */
int main(int argc, char* argv[])
{
    init();

    cairo_surface_t *surface;
    cairo_t *cr;

    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 320, 320);
    cr = cairo_create (surface);

    cairo_translate (cr, 10, 10);
    cairo_scale (cr, 100, 100);

    cairo_rectangle (cr, 0.0, 0.0, 3.0, 3.0);
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
    cairo_fill (cr);

    cairo_text_extents_t te;

    cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
    cairo_select_font_face (cr, "Liberation Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, 1.0);
    cairo_text_extents (cr, "Hello", &te);
    cairo_move_to (cr, 1.5 - te.width / 2 - te.x_bearing, 0.5 - te.height / 2 - te.y_bearing);
    cairo_show_text (cr, "Hello");

    cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
    cairo_select_font_face (cr, "Liberation Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, 1.0);
    cairo_text_extents (cr, "Hello", &te);
    cairo_move_to (cr, 1.5 - te.width / 2 - te.x_bearing, 1.5 - te.height / 2 - te.y_bearing);
    cairo_show_text (cr, "Hello");

    cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
    cairo_select_font_face (cr, "Liberation Mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, 1.0);
    cairo_text_extents (cr, "Hello", &te);
    cairo_move_to (cr, 1.5 - te.width / 2 - te.x_bearing, 2.5 - te.height / 2 - te.y_bearing);
    cairo_show_text (cr, "Hello");

    esReport("--- cairo_image_surface_get_data ---\n");
    u8* data = cairo_image_surface_get_data (surface);
    for (int y = 0; y < 320; ++y)
    {
        memmove(framebufferPtr + 4 * WIDTH * y,
                data + 4 * 320 * y,
                4 * 320);
    }
}
Beispiel #3
0
int UrlBar::textWidth(const char* text)
{
    cairo_text_extents_t extents;
    cairo_text_extents(m_cairo, text, &extents);

    return extents.x_advance;
}
Beispiel #4
0
/* ...draw multiline string - hmm; need to put that stuff into display */
static inline void draw_string(cairo_t *cr, const char *fmt, ...)
{
	char                    buffer[4096], *p, *end;
	cairo_text_extents_t    text_extents;
	cairo_font_extents_t    font_extents;
	va_list                 argp;

	cairo_save(cr);
	cairo_select_font_face(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size(cr, 40);
	cairo_font_extents(cr, &font_extents);

	va_start(argp, fmt);
	vsnprintf(buffer, sizeof(buffer), fmt, argp);
	va_end(argp);

    for (p = buffer; *p; p = end + 1)
    {
        /* ...output single line */
		((end = strchr(p, '\n')) != NULL ? *end = 0 : 0);
		cairo_show_text(cr, p);
		cairo_text_extents (cr, p, &text_extents);
		cairo_rel_move_to (cr, -text_extents.x_advance, font_extents.height);
        TRACE(0, _b("print text-line: <%f,%f>"), text_extents.x_advance, font_extents.height);

        /* ...stop when last line processes */
        if (!end)   break;
    }

    /* ...restore drawing context */
	cairo_restore(cr);
}
static void
add_label (struct chart *c,
	   int		 test,
	   const char	*label)
{
    cairo_text_extents_t extents;
    double dx, x;

    cairo_save (c->cr);
    dx = c->width / (double) c->num_tests;
    if (dx / 2 - PAD < 4)
	return;
    cairo_set_font_size (c->cr, dx / 2 - PAD);
    cairo_text_extents (c->cr, label, &extents);

    cairo_set_source_rgb (c->cr, .5, .5, .5);

    x = (test + .5) * dx;
    cairo_save (c->cr);
    cairo_translate (c->cr, x, c->height - PAD / 2);
    cairo_rotate (c->cr, -M_PI/2);
    cairo_move_to (c->cr, 0, -extents.y_bearing/2);
    cairo_show_text (c->cr, label);
    cairo_restore (c->cr);

    cairo_save (c->cr);
    cairo_translate (c->cr, x, PAD / 2);
    cairo_rotate (c->cr, -M_PI/2);
    cairo_move_to (c->cr, -extents.width, -extents.y_bearing/2);
    cairo_show_text (c->cr, label);
    cairo_restore (c->cr);

    cairo_restore (c->cr);
}
Beispiel #6
0
int render_workspace(cairo_t *cairo, int x, int y,
					 struct i3_workspace *ws, int d) {

	//set colour based on visibility
	struct colour *c = conf->inviswscol;
	if(strcmp(ws->visible, "true") == 0) c = conf->viswscol;
	set_cairo_source_colour(cairo, c);

	//set font
	cairo_set_font_face(cairo, conf->wsfont);
	cairo_set_font_size(cairo, conf->wsfontsize);

	cairo_text_extents_t extents;
	cairo_text_extents(cairo, ws->name, &extents);

	int render_x = x;
	if(d == RIGHT) render_x = x - extents.width;

	//draw the text
	cairo_move_to(cairo, render_x, y);
	cairo_show_text(cairo, ws->name);

	//update the padding
	return extents.width + 2;
}
void address_histogram::render_bars(cairo_t *cr, const plot::bounds_t &bounds)
{
    if(top_addrs.size() < 1 || top_addrs.at(0).count == 0) {
        return;
    }

    cairo_matrix_t original_matrix;

    cairo_get_matrix(cr, &original_matrix);
    cairo_translate(cr, bounds.x, bounds.y);

    double offset_unit = bounds.width / top_addrs.size();
    double bar_width = offset_unit / bar_space_factor;
    double space_width = offset_unit - bar_width;
    uint64_t greatest = top_addrs.at(0).count;
    int index = 0;

    for(vector<iptree::addr_elem>::const_iterator it = top_addrs.begin();
            it != top_addrs.end(); it++) {
	double bar_height = (((double) it->count) / ((double) greatest)) * bounds.height;

	if(bar_height > 0) {
            // bar
            double bar_x = index * offset_unit + space_width;
            double bar_y = bounds.height - bar_height;

            cairo_set_source_rgb(cr, bar_color.r, bar_color.g, bar_color.b);
            cairo_rectangle(cr, bar_x, bar_y, bar_width, bar_height);
            cairo_fill(cr);

            // bar label
            std::string label = it->str();

            // IP6 labels are half size since they're (potentially) much longer
            if(it->is4()) {
                cairo_set_font_size(cr, bar_label_font_size);
            }
            else {
                cairo_set_font_size(cr, bar_label_font_size / 2.0);
            }

            cairo_text_extents_t label_extents;
            cairo_text_extents(cr, label.c_str(), &label_extents);

            cairo_move_to(cr, bar_x + bar_width / 2.0, bar_y);

            cairo_matrix_t unrotated_matrix;
            cairo_get_matrix(cr, &unrotated_matrix);
            cairo_rotate(cr, -M_PI / 4.0);

            cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
            cairo_show_text(cr, label.c_str());

            cairo_set_matrix(cr, &unrotated_matrix);
	}
	index++;
    }

    cairo_set_matrix(cr, &original_matrix);
}
Beispiel #8
0
// --------------------------------------------------------------
void CairoFont::GetExtent( const char * s, float * outWidth, float * outHeight, cairo_t * context ) const
{
        bool newcontext = false;
	if (!context) {
        	cairo_surface_t* surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1000, 1000);
                context = cairo_create (surface);
		cairo_surface_destroy (surface);	
		newcontext = true;
		std::cerr << "Your device has no native context.  Probably due to mixing and matching cairo with another device. Creating an ad hoc context and crossing fingers." << std::endl;
	}
	SelectFont (context);

//	cairo_matrix_t matrix;
//	cairo_get_matrix (context, &matrix);

	cairo_text_extents_t extents;
	cairo_text_extents (context, s, &extents);
	*outWidth	= extents.width;
	*outHeight	= extents.height;
//	*outWidth	= extents.width - extents.x_advance;
//	*outHeight	= extents.height - extents.y_advance;
//	*outWidth	= (extents.width - extents.x_advance) * matrix.xx;
//	*outHeight	= (extents.height - extents.y_advance) * matrix.yy;
//std::cout << "CairoFont::GetExtent -" << s << "- w/h " << *outWidth << "/" << *outHeight 
//	<< " - adv x/y " << extents.x_advance << "/" << extents.y_advance << std::endl;
        if (newcontext)
                cairo_destroy(context);
}
Beispiel #9
0
    void WriteText(double x, double y, 
            const std::string &font, double size, double rowPitch, const std::string &text)
            //const char *font, double size, const char *text)
    {
        cairo_text_extents_t extents;

        cairo_save(ctx_);

        cairo_select_font_face(ctx_, font.c_str(), 
                CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);

        cairo_set_font_size(ctx_, size);
        cairo_text_extents(ctx_, text.c_str(), &extents);

        std::istringstream is(text);
        std::string line;

        while(!is.eof())
        {
            y = y - extents.y_bearing + rowPitch;
            cairo_move_to(ctx_, x - extents.x_bearing, y);
            std::getline(is, line);
            cairo_show_text(ctx_, line.c_str());
        }

        cairo_restore(ctx_);
    }
Beispiel #10
0
void PdfView::drawPage(PdfCache * cache, XojPopplerPage * popplerPage, cairo_t * cr, double zoom, double width, double height, bool forPrinting) {
	if (popplerPage) {
		if (cache && !forPrinting) {
			cache->render(cr, popplerPage, zoom);
		} else {
			popplerPage->render(cr, forPrinting);
		}

		if (!forPrinting) {
			cairo_set_operator(cr, CAIRO_OPERATOR_DEST_OVER);
			cairo_set_source_rgb(cr, 1., 1., 1.);
		}
		cairo_paint(cr);
	} else {
		cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
		cairo_set_font_size(cr, 26);

		cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);

		cairo_text_extents_t extents = { 0 };
		const char * strMissing = _("PDF background missing");

		cairo_text_extents(cr, strMissing, &extents);
		cairo_move_to(cr, width / 2 - extents.width / 2, height / 2 - extents.height / 2);
		cairo_show_text(cr, strMissing);
	}
}
Beispiel #11
0
static void
buttonDraw(cairo_t* cr, const Button* but)
{
	// Draw base
	if (but->pressed) {
		cairo_set_source_rgba(cr, 0.4, 0.9, 0.1, 1);
	} else {
		cairo_set_source_rgba(cr, 0.3, 0.5, 0.1, 1);
	}
	roundedBox(cr, but->x, but->y, but->w, but->h);
	cairo_fill_preserve(cr);

	// Draw border
	cairo_set_source_rgba(cr, 0.4, 0.9, 0.1, 1);
	cairo_set_line_width(cr, 4.0);
	cairo_stroke(cr);

	// Draw label
	cairo_text_extents_t extents;
	cairo_set_font_size(cr, 32.0);
	cairo_text_extents(cr, but->label, &extents);
	cairo_move_to(cr,
	              (but->x + but->w / 2) - extents.width / 2,
	              (but->y + but->h / 2) + extents.height / 2);
	cairo_set_source_rgba(cr, 0, 0, 0, 1);
	cairo_show_text(cr, but->label);
}
Beispiel #12
0
static void
draw (cairo_t *cr, struct options *options)
{
    cairo_text_extents_t extents;
    cairo_font_extents_t font_extents;

    cairo_select_font_face (cr,
			    options->family, options->slant, options->weight);
    cairo_set_font_size (cr, options->size);

    cairo_text_extents (cr, options->text, &extents);
    cairo_translate (cr,
		     options->PAD - extents.x_bearing,
		     options->PAD - extents.y_bearing);

    cairo_font_extents (cr, &font_extents);
    cairo_rectangle (cr, 0, -font_extents.ascent,
		      extents.x_advance, font_extents.height);
    cairo_move_to (cr, -options->PAD, 0);
    cairo_line_to (cr, extents.width + options->PAD, 0);
    cairo_set_source_rgba (cr, 1, 0, 0, .7);
    cairo_stroke (cr);

    cairo_rectangle (cr,
		     extents.x_bearing, extents.y_bearing,
		     extents.width, extents.height);
    cairo_set_source_rgba (cr, 0, 1, 0, .7);
    cairo_stroke (cr);

    cairo_move_to (cr, 0, 0);
    cairo_set_source_rgb (cr, 0, 0, 1);
    cairo_show_text (cr, options->text);
    cairo_fill (cr);
}
Beispiel #13
0
// Function to write the percent error on the upper left
void print_pe(frame &anim, double pe, color clr){

    // Drawing black box underneath "Percent Error"
    cairo_set_source_rgb(anim.frame_ctx[anim.curr_frame], 0, 0, 0);
    cairo_rectangle(anim.frame_ctx[anim.curr_frame], 0, 
                    anim.res_y - 20, anim.res_x, 20);
    cairo_fill(anim.frame_ctx[anim.curr_frame]);
    std::string pe_txt, number;
 
    std::stringstream ss;
    ss << std::setw(3) << pe;
    number = ss.str();

    pe_txt = "Percent Error: " + number;
    //std::cout << pe_txt << '\n';

    cairo_set_source_rgb(anim.frame_ctx[anim.curr_frame], clr.r,clr.g,clr.b);

    cairo_text_extents_t textbox;
    cairo_text_extents(anim.frame_ctx[anim.curr_frame], 
                       pe_txt.c_str(), &textbox);
    cairo_move_to(anim.frame_ctx[anim.curr_frame], 20, anim.res_y);
    cairo_show_text(anim.frame_ctx[anim.curr_frame], pe_txt.c_str());

    cairo_stroke(anim.frame_ctx[anim.curr_frame]);

}
Beispiel #14
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    const char *text =
"This needs to be a very long string, wider than the surface, and yet wider."
"Ideally it should overflow the stack buffers, but do you really want to read "
"a message that long. No. So we compromise with around 300 glyphs that is "
"long enough to trigger the conditions as stated in "
"http://lists.cairographics.org/archives/cairo/2008-December/015976.html. "
"Happy now?";
    cairo_text_extents_t extents;

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

    cairo_set_font_size (cr, 16);
    cairo_text_extents (cr, text, &extents);
    cairo_move_to (cr, -extents.width/2, 18);
    cairo_show_text (cr, text);

    /* XXX we should exercise cairo_show_text_glyphs() as well,
     * and CAIRO_TEXT_CLUSTER_BACKWARDS
     */

    return CAIRO_TEST_SUCCESS;
}
Beispiel #15
0
static int ui_text_extents(lua_State *L)
{
	struct context *c = lua_touserdata(L, 1);
	const char *str = lua_tostring(L, 2);	

	cairo_text_extents_t te;
	cairo_text_extents (c->cr, str, &te);

	lua_newtable(L);

	lua_pushnumber(L, te.x_bearing);
	lua_setfield(L, -2, "x_bearing");

	lua_pushnumber(L, te.y_bearing);
	lua_setfield(L, -2, "y_bearing");

	lua_pushnumber(L, te.width);
	lua_setfield(L, -2, "width");

	lua_pushnumber(L, te.height);
	lua_setfield(L, -2, "height");

	lua_pushnumber(L, te.x_advance);
	lua_setfield(L, -2, "x_advance");

	lua_pushnumber(L, te.y_advance);
	lua_setfield(L, -2, "y_advance");	

	return 1;
}
void GraphicsLayerTextureMapper::drawRepaintCounter(GraphicsContext* context)
{
    cairo_t* cr = context->platformContext()->cr();
    cairo_save(cr);

    CString repaintCount = String::format("%i", this->repaintCount()).utf8();
    cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size(cr, 18);

    cairo_text_extents_t repaintTextExtents;
    cairo_text_extents(cr, repaintCount.data(), &repaintTextExtents);

    static const int repaintCountBorderWidth = 10;
    setSourceRGBAFromColor(cr, isShowingDebugBorder() ? m_debugBorderColor : Color(0, 255, 0, 127));
    cairo_rectangle(cr, 0, 0,
        repaintTextExtents.width + (repaintCountBorderWidth * 2),
        repaintTextExtents.height + (repaintCountBorderWidth * 2));
    cairo_fill(cr);

    cairo_set_source_rgb(cr, 1, 1, 1);
    cairo_move_to(cr, repaintCountBorderWidth, repaintTextExtents.height + repaintCountBorderWidth);
    cairo_show_text(cr, repaintCount.data());

    cairo_restore(cr);
}
Beispiel #17
0
void ng_view_render_hints(cairo_surface_t *surf, guint gridsize, guint32 *hints, guint16 *offsets,
                          guint16 count, enum ORIENTATION orientation)
{
    cairo_t *cr = cairo_create(surf);
    guint i, offset = 0, col=0, row=1;
    gchar buf[8];
    cairo_text_extents_t extents;

    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
    cairo_set_font_size(cr, 10);
    for (i = 0; i < count; ++i) {
        while (offset < offsets[i+1]) {
            snprintf(buf, 8, "%d", NG_HINT_NUM(hints[offset]));
            cairo_text_extents(cr, buf, &extents);
            cairo_move_to(cr, (col + 0.5) * gridsize - extents.width * 0.5,
                              (row - 0.5) * gridsize + extents.height * 0.5);
            cairo_show_text(cr, buf);
            if (orientation == ORIENTATION_HORIZONTAL)
                ++col;
            else
                ++row;
            ++offset;
        }
        if (orientation == ORIENTATION_HORIZONTAL) {
            col = 0;
            ++row;
        }
        else {
            row = 1;
            ++col;
        }
    }

    cairo_destroy(cr);
}
Beispiel #18
0
void WayRenderer::shield(cairo_t* cr,
		std::list<shared_ptr<Shield> >& shields,
		AssetCache& cache)
{
	if (s->shield_text.str().size() == 0 || s->font_size <= 0.0)
		return;

	// make sure path is initialized
	addWayPath(cr);
	cairo_new_path(cr);

	cairo_save(cr);

	cairo_set_font_size(cr, s->font_size);

	cairo_select_font_face(cr,
				s->font_family.c_str(),
				s->font_style == Style::STYLE_ITALIC ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
				s->font_weight == Style::WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL
			);

	cairo_text_extents_t textSize;
	cairo_text_extents(cr, s->shield_text.c_str(), &textSize);

	std::list<FloatPoint> positions;
	getShieldPosition(path, positions);

	for (FloatPoint& p : positions)
	{
		addShield(shields, p, &textSize);
	}

	cairo_restore(cr);
}
Beispiel #19
0
static Bool
canvas_configure_event(GtkWidget *widget, GdkEventConfigure *event) {
 GtkAllocation allocation;
 cairo_text_extents_t te;
 //printf("canvas_configure_event\n");

 gtk_widget_get_allocation(widget,&allocation);
 vdevice.sizeX = 1;
 vdevice.sizeY = 1;
 vdevice.minVx = vdevice.minVy = 0;
 vdevice.maxVx = vdevice.sizeSx = allocation.width;
 vdevice.maxVy = vdevice.sizeSy = allocation.height;
 vdevice.depth = 3;
 if (VGUI.cr!=NULL) {
  cairo_destroy (VGUI.cr);
  cairo_surface_destroy (VGUI.surface);
 }
 VGUI.surface= gdk_window_create_similar_surface (gtk_widget_get_window (VGUI.canvas),
  CAIRO_CONTENT_COLOR, vdevice.sizeSx, vdevice.sizeSy);
 VGUI.cr = cairo_create(VGUI.surface);
 cairo_set_antialias(VGUI.cr,VGUI.antialias);
 my_set_font(VGUI.cr);
 cairo_text_extents (VGUI.cr, "A", &te);
 vdevice.hheight = te.height;
 vdevice.hwidth = te.x_advance;
 VGUI.line_width=1;
 //printf("vdevice address=%ld, vdevice.sizeSx=%d, vdevice.sizeSy=%d\n", (long)&vdevice,  vdevice.sizeSx, vdevice.sizeSy);
 Keyboard_Buffer_push('');	// queue a redraw command
 notify_input();
 return TRUE;
}
Beispiel #20
0
// Function to write area found on the lower right
void print_area(frame &anim, double area, color clr){

    // Drawing black box underneath "Area"
    cairo_set_source_rgb(anim.frame_ctx[anim.curr_frame], 0, 0, 0);
    cairo_rectangle(anim.frame_ctx[anim.curr_frame], 0, 0, anim.res_x, 20);
    cairo_fill(anim.frame_ctx[anim.curr_frame]);
    std::string area_txt, number;
 
    std::stringstream ss;
    ss << std::setw(3) << area;
    number = ss.str();

    area_txt = "Ratio: " + number;
    //std::cout << area_txt << '\n';

    cairo_set_source_rgb(anim.frame_ctx[anim.curr_frame], clr.r,clr.g,clr.b);

    cairo_text_extents_t textbox;
    cairo_text_extents(anim.frame_ctx[anim.curr_frame], 
                       area_txt.c_str(), &textbox);
    cairo_move_to(anim.frame_ctx[anim.curr_frame], 20, 20);
    cairo_show_text(anim.frame_ctx[anim.curr_frame], area_txt.c_str());

    cairo_stroke(anim.frame_ctx[anim.curr_frame]);

}
Beispiel #21
0
static void label_tile(struct _openslide_grid *grid,
                       cairo_t *cr,
                       int64_t tile_col, int64_t tile_row) {
  if (!_openslide_debug(OPENSLIDE_DEBUG_TILES)) {
    return;
  }

  struct bounds bounds = {0, 0, 0, 0};
  grid->ops->get_tile_size(grid, tile_col, tile_row, &bounds);

  cairo_save(cr);
  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

  cairo_set_source_rgba(cr, 0.6, 0, 0, 0.3);
  cairo_rectangle(cr, 0, 0, bounds.w, bounds.h);
  cairo_stroke(cr);

  cairo_set_source_rgba(cr, 0.6, 0, 0, 1);
  char *str = g_strdup_printf("%" G_GINT64_FORMAT ", %" G_GINT64_FORMAT,
                              tile_col, tile_row);
  cairo_text_extents_t extents;
  cairo_text_extents(cr, str, &extents);
  cairo_move_to(cr,
                (bounds.w - extents.width) / 2,
                (bounds.h + extents.height) / 2);
  cairo_show_text(cr, str);
  g_free(str);

  cairo_restore(cr);
}
Beispiel #22
0
static gboolean on_badge_draw(ClutterCanvas* canvas, cairo_t* cr,
        gint width, gint height, ClutterActor* badge)
{
    g_debug("%s: %d,%d, ", __func__, width, height);

    cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);
    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
    cairo_paint_with_alpha(cr, 0.0);

    cairo_arc(cr, width/2, height/2, MIN(width, height)/2.0, 0, 2*M_PI);
    cairo_close_path(cr);

    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
    cairo_set_source_rgba(cr, 0.6, 0.2, 0.2, 0.8);
    cairo_fill(cr);

    char title[20];
    snprintf(title, 19, "%d", GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(badge), moses_overview_window_clone_order())));
    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);

    cairo_select_font_face(cr, "fantasy", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size(cr, 28.0);

    cairo_text_extents_t te;
    cairo_text_extents(cr, title, &te);
    cairo_move_to(cr, (width - te.width)/2.0 - te.x_bearing, (height - te.height)/2.0 - te.y_bearing);
    cairo_show_text(cr, title);

    return TRUE;
}
Beispiel #23
0
static void
on_expose_event_draw_text (GtkWidget *widget, SSWorkspace *workspace)
{
#ifdef HAVE_GTK_2_8
  cairo_t *c;
  cairo_text_extents_t extents;
  int x, y;

  c = gdk_cairo_create (widget->window);
  cairo_select_font_face (c, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
  cairo_set_font_size (c, MINI_WORKSPACE_FONT_HEIGHT);

  cairo_text_extents (c, workspace->title, &extents);
  x = (widget->allocation.width  - extents.width)  / 2;
  y = (widget->allocation.height + extents.height) / 2;

  cairo_set_source_rgba (c, 0, 0, 0, 0.25);
  cairo_move_to (c, x-1, y);
  cairo_show_text (c, workspace->title);
  cairo_set_source_rgba (c, 1, 1, 1, 0.25);
  cairo_move_to (c, x, y+1);
  cairo_show_text (c, workspace->title);
  cairo_destroy (c);
#endif
}
static VALUE
cr_text_extents (VALUE self, VALUE utf8)
{
  cairo_text_extents_t extents;
  cairo_text_extents (_SELF, StringValuePtr (utf8), &extents);
  cr_check_status (_SELF);
  return CRTEXTEXTENTS2RVAL (&extents);
}
Beispiel #25
0
static int
cr_text_extents (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    cairo_text_extents_t extents;
    cairo_text_extents(*obj, luaL_checkstring(L, 2), &extents);
    create_lua_text_extents(L, &extents);
    return 1;
}
Beispiel #26
0
CAMLprim value
ml_cairo_text_extents (value v_cr, value v_utf8)
{
  cairo_text_extents_t c_extents;
  cairo_text_extents (cairo_t_val (v_cr), String_val (v_utf8), &c_extents);
  check_cairo_status (v_cr);
  return Val_cairo_text_extents (&c_extents);
}
Beispiel #27
0
static int info_draw(ToolWin *tw) {
	toolwin_backing(tw);
	/* info */
	cairo_set_source_rgba(tw->ctx,0,0,0,1.0);
	cairo_set_font_face(tw->ctx, conf.bfont);
	cairo_move_to(tw->ctx, 0, 8);
	info_printf(tw, A_CENTER, "%.3lf sec, %.2lf KHz",
			spect->fft->time[mx],spect->fft->freq[my]);
	cairo_rel_move_to(tw->ctx,0,12);
	info_split_printf(tw, "Threshold:", "%.2lf", -1.0 * conf.thresh);
	info_split_printf(tw, "Spectrogram Floor:", "%.2lf",
			-1.0 * conf.spect_floor);
	info_split_printf(tw, "Path Length:","%.2lf", spect->pex);
	info_split_printf(tw, "Path Duration:","%.3lf", spect->tex);
	info_split_printf(tw, "Frequency Excursion:","%.3lf", spect->fex);
	cairo_move_to(tw->ctx, 0, 145);
	/* modes */
	info_split_printf(tw, "Modes:","");
	cairo_set_font_face(tw->ctx, conf.bfont);
		/* erase */
	set_color(tw->ctx,RGBA_ERASE1)
	if (mode & MODE_ERASE) set_color(tw->ctx,RGBA_ERASE1)
	else cairo_set_source_rgba(tw->ctx,0.8,0.8,0.8,1.0);
	cairo_rectangle(tw->ctx, 10, 170, tw->w / 2.0 - 15, 20);
	cairo_fill_preserve(tw->ctx);
	cairo_set_source_rgba(tw->ctx,0,0,0,1.0);
	cairo_stroke(tw->ctx);
	cairo_text_extents(tw->ctx,"Erase",&ext);
	cairo_move_to(tw->ctx, tw->w / 4.0 - ext.width / 2.0, 185);
	cairo_set_source_rgba(tw->ctx,0,0,0,1.0);
	cairo_show_text(tw->ctx,"Erase");
		/* crop */
	if (mode & MODE_CROP) set_color(tw->ctx, RGBA_CROP)
	else cairo_set_source_rgba(tw->ctx,0.8,0.8,0.8,1.0);
	cairo_rectangle(tw->ctx, 5 + tw->w / 2.0, 170, tw->w / 2.0 - 15, 20);
	cairo_fill_preserve(tw->ctx);
	cairo_set_source_rgba(tw->ctx,0.0,0.0,0.0,1.0);
	cairo_stroke(tw->ctx);
	cairo_text_extents(tw->ctx,"Crop",&ext);
	cairo_move_to(tw->ctx, tw->w * 0.75 - ext.width / 2.0, 185);
	cairo_set_source_rgba(tw->ctx,0,0,0,1.0);
	cairo_show_text(tw->ctx,"Crop");
	/* draw */
	toolwin_draw(tw);
	return 0;
}
Beispiel #28
0
void displayDiliriumUIMicroKnob(deliriumUI* deliriumUI_window, cairo_t* cr, int widgetNumber)
{
	deliriumUIWidget* deliriumUIWidgets = deliriumUI_window->deliriumUIWidgets;

	int x = deliriumUIWidgets[widgetNumber].x * deliriumUI_window->widgetWidth;
	int y = deliriumUIWidgets[widgetNumber].y * deliriumUI_window->widgetHeight;
	int w = deliriumUIWidgets[widgetNumber].w * deliriumUI_window->widgetWidth;
	int h = deliriumUIWidgets[widgetNumber].h * deliriumUI_window->widgetHeight;

	float value = deliriumUIWidgets[widgetNumber].value; // deliriumUIWidgets[widgetNumber].value;

	cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
	cairo_rectangle(cr, x, y, w, h);
	cairo_clip(cr);

	// Draw label
	cairo_text_extents_t extents;
	cairo_set_font_size(cr, h / 5);
	cairo_text_extents(cr, deliriumUIWidgets[widgetNumber].label, &extents);

	cairo_move_to(cr,
	              (x + w / 2) - extents.width / 2,
	              (y + h) - extents.height / 4);

	if (deliriumUIWidgets[widgetNumber].hover) {
		cairo_set_source_rgba(cr, 1, 1, 1, 1);;
	} else {
		cairo_set_source_rgba(cr, 1, 1, 1, 0.6);;
	}

	cairo_show_text(cr, deliriumUIWidgets[widgetNumber].label);

	y -= (h/8);

	// ------------------------------------------------------------------

	float cos_x =  (w/5) * (cos(((((1-value)*0.75)-0.3)*2) * M_PI));
	float sin_y =  (w/5) * (sin(((((1-value)*0.75)-0.3)*2) * M_PI));

	cairo_pattern_t* pat;

	pat = cairo_pattern_create_radial (x+(w/2) + sin_y, y+(h/2)+cos_x, 0, x+(w/2), y+(h/2) ,(w/2.5));

	cairo_pattern_add_color_stop_rgba (pat, 0,0.4,0.4,0.4,1);
	cairo_pattern_add_color_stop_rgba (pat, 0.5,0.2,0.2,0.2,1);
	cairo_pattern_add_color_stop_rgba (pat, 0.8,0.17,0.17,0.17,1);
	cairo_pattern_add_color_stop_rgba (pat, 1.0,0.0,0.0,0.0,1);

	cairo_set_source(cr, pat);
	cairo_arc(cr, x+(w/2), y+(h/2), (w/2.5), 0.0, 2 * M_PI);
	cairo_fill(cr);
	cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
	cairo_arc(cr, x+(w/2) +cos_x, y+(h/2)+sin_y, (w/16), 0.0, 2 * M_PI);
	cairo_fill(cr);

	cairo_reset_clip(cr);	
	cairo_pattern_destroy (pat);
}
Beispiel #29
0
void WayRenderer::label(cairo_t* cr,
		std::list<shared_ptr<Label> >& labels, AssetCache& cache)
{
	if (s->text.str().size() == 0 || s->font_size <= 0.0)
		return;

	// make sure path is initialized
	addWayPath(cr);
	cairo_new_path(cr);

	cairo_save(cr);

	cairo_set_font_size(cr, s->font_size);

	cairo_select_font_face(cr,
				s->font_family.c_str(),
				s->font_style == Style::STYLE_ITALIC ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
				s->font_weight == Style::WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL
			);

	cairo_text_extents_t textSize;
	cairo_text_extents(cr, s->text.c_str(), &textSize);

	if (s->text_position == Style::POSITION_CENTER)
	{
		// request a centered label
		addLabel(labels, bounds.getCenter() + FloatPoint(0.0, s->text_offset), &textSize);
	}
	else if (s->text_position == Style::POSITION_LINE)
	{
		FloatPoint best;
		double angle = 0;
		bool placed = getTextPosition(path, textSize.width, best, angle);

		if (placed) {
			cairo_translate(cr, best.x, best.y);
			cairo_rotate(cr, angle);
			cairo_translate(cr, 0, s->text_offset);

			cairo_move_to(cr, -textSize.width/2.0 - textSize.x_bearing,
						-textSize.height/2.0 - textSize.y_bearing);

			cairo_text_path(cr, s->text.c_str());

			if (s->text_halo_radius > 0.0)
			{
				cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
				cairo_set_line_width(cr, s->text_halo_radius*2.0);
				cairo_set_source_rgba(cr, COLOR2RGBA(s->text_halo_color));
				cairo_stroke_preserve(cr);
			}
			cairo_set_source_rgba(cr, COLOR2RGBA(s->text_color));
			cairo_fill(cr);
		}
	}

	cairo_restore(cr);
}
Beispiel #30
0
// Den Text zeichnen
static void draw_text (Lcd *lcd, cairo_t *cr)
{
	LcdPrivate *priv;
	GtkWidget *widget;
	cairo_text_extents_t extents;
	cairo_font_options_t *options;
	gdouble x, y;
	gchar *text;

	priv = LCD_GET_PRIVATE (lcd);
	widget = GTK_WIDGET (lcd);
	
	// Text erstellen
	text = construct_text (LCD (lcd));
	
	// Farbe setzen
	cairo_set_source_rgb (cr, 0, 0, 0);

	// Font setzen
	//cairo_select_font_face (cr, "Mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	//cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	//cairo_select_font_face (cr, "Ubuntu-Title", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_select_font_face (cr, "Purisa", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, 24);
	cairo_text_extents (cr, text, &extents);
	
	// Font-Antialiasing ausschalten
	options = cairo_font_options_create ();
	//cairo_get_font_options (cr, options);
	if (!options) {
		g_message ("Font-Antialiasing ausschalten");
		cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_NONE);
		cairo_set_font_options (cr, options);	
	}
	
	// Nur sliden wenn Text grösser als Platz ist
	if (extents.width < widget->allocation.width - FRAME_ABSTAND) {
		// Text horizontal zentrieren
		priv->current_x = (widget->allocation.width / 2) - (extents.width / 2);
	} else if ((priv->current_x + extents.width) <= 0) {
		// falls Text zu Ende -> wieder hinten anfangen
		priv->current_x = widget->allocation.width;
	}
	
	x = priv->current_x;
	y = (widget->allocation.height / 2) + (extents.height / 2) - (extents.height + extents.y_bearing);	
	
	//g_debug ("text position: x=%.1f y=%.1f", x, y);
	
	cairo_move_to (cr, x, y);
	cairo_show_text (cr, text);
	
	// Debug Rechteck zeichnen
	//cairo_set_line_width (cr, 1);
	//cairo_set_source_rgb (cr, 1, 0, 0);
	//cairo_rectangle (cr, x, y-extents.height, extents.width, extents.height);
	//cairo_stroke (cr);
}