Esempio n. 1
0
int render_keyvalue(cairo_t *cairo, int x, int y, char *k, char *v , int d) {
	uint32_t render_x;
	cairo_text_extents_t k_extents;
	cairo_text_extents_t v_extents;

	//we must set the fonts to measure extents
	cairo_set_font_face(cairo, conf->keyfont);
	cairo_set_font_size(cairo, conf->keyfontsize);
	cairo_text_extents(cairo, k, &k_extents);
	cairo_set_font_face(cairo, conf->valfont);
	cairo_set_font_size(cairo, conf->valfontsize);
	cairo_text_extents(cairo, v, &v_extents);

	//render key
	set_cairo_source_colour(cairo, conf->keycol);
	cairo_set_font_face(cairo, conf->keyfont);
	cairo_set_font_size(cairo, conf->keyfontsize);
	render_x = x;
	if(d == RIGHT)
		render_x = x - (k_extents.width + v_extents.width + conf->kvpadding);
	cairo_move_to(cairo, render_x, y);
	cairo_show_text(cairo, k);

	//render value
	set_cairo_source_colour(cairo, conf->valcol);
	cairo_set_font_face(cairo, conf->valfont);
	cairo_set_font_size(cairo, conf->valfontsize);
	render_x = x + k_extents.width + conf->kvpadding;
	if(d == RIGHT)
		render_x = x - v_extents.width;
	cairo_move_to(cairo, render_x, y);
	cairo_show_text(cairo, v);

	return k_extents.width + conf->kvpadding + v_extents.width;
}
Esempio n. 2
0
void CairoRenderer::SetFontFace(InputStream *pStream)
{
	FT_Face face;
	static cairo_user_data_key_t key;

	if (m_cairo_face)
	{
		cairo_set_font_face(m_pCairo, NULL);
		cairo_font_face_destroy(m_cairo_face);
		m_cairo_face = NULL;
	}

	if (pStream)
	{
		face = FreeType::OpenFace(pStream);  // face will be destroyed by FT_Done_Face
		if (face)
		{
			m_cairo_face = cairo_ft_font_face_create_for_ft_face(face, 0);
			cairo_font_face_set_user_data(m_cairo_face, &key, face, (cairo_destroy_func_t)FT_Done_Face);
		}
	}
	else
		m_cairo_face = cairo_toy_font_face_create("unifont", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);

	if (m_cairo_face)
		cairo_set_font_face(m_pCairo, m_cairo_face);
}
Esempio n. 3
0
static PyObject *
pycairo_set_font_face (PycairoContext *o, PyObject *obj) {
  if (PyObject_TypeCheck(obj, &PycairoFontFace_Type))
    cairo_set_font_face (o->ctx, ((PycairoFontFace *)obj)->font_face);
  else if (obj == Py_None)
    cairo_set_font_face (o->ctx, NULL);
  else {
    PyErr_SetString(PyExc_TypeError,
		    "Context.set_font_face() argument must be "
		    "cairo.FontFace or None");
    return NULL;
  }
  RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
  Py_RETURN_NONE;
}
Esempio n. 4
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;
}
Esempio n. 5
0
static VALUE
cr_set_font_face (VALUE self, VALUE face)
{
  cairo_set_font_face (_SELF, NIL_P (face) ? NULL : RVAL2CRFONTFACE (face));
  cr_check_status (_SELF);
  return self;
}
Esempio n. 6
0
void label_t::paint() {

	clearSurface();

	auto cr = graphics.getContext();
	auto bounds = getBounds();

	cairo_set_source_rgb(cr, 0, 0, 0);

	int textLeft;
	int textBot = (bounds.height / 2 - lastExtents.height / 2) + lastExtents.height;

	if (alignment == g_text_alignment::CENTER) {
		textLeft = bounds.width / 2 - lastExtents.width / 2;
	} else if (alignment == g_text_alignment::RIGHT) {
		textLeft = bounds.width - lastExtents.width;
	} else {
		textLeft = 0;
	}

	cairo_move_to(cr, textLeft, textBot);
	cairo_set_font_face(cr, font->getFace());
	cairo_set_font_size(cr, fontSize);
	cairo_show_text(cr, text.c_str());
}
Esempio n. 7
0
static void
draw (GtkWidget *drawing_area,
      cairo_t *cr,
      FT_Face face)
{
    cairo_font_extents_t font_extents;
    gint *sizes = NULL, n_sizes, alpha_size, pos_y, i;
    const gchar *text;
    cairo_font_face_t *font;

    text = get_sample_string (face);
    sizes = build_sizes_table (face, &n_sizes, &alpha_size);

    font = cairo_ft_font_face_create_for_ft_face (face, 0);
    cairo_set_font_face (cr, font);
    cairo_font_extents (cr, &font_extents);
    cairo_font_face_destroy (font);

    /* draw text */
    pos_y = MAX (font_extents.height, 32) + 4;
    cairo_set_font_size (cr, alpha_size);
    draw_string (cr, lowercase_text, &pos_y);
    draw_string (cr, uppercase_text, &pos_y);
    draw_string (cr, punctuation_text, &pos_y);

    pos_y += 8;
    for (i = 0; i < n_sizes; i++) {
	cairo_set_font_size (cr, sizes[i]);
	draw_string (cr, text, &pos_y);
    }

    g_free (sizes);
}
Esempio n. 8
0
int toolwin_win_create(ToolWin *tw) {
	tw->win = XCreateSimpleWindow(dpy, root, 20, 20, tw->w, tw->h, 0, 0, 0);
	tw->buf = XCreatePixmap(dpy, root, tw->w, tw->h, DefaultDepth(dpy,scr));
	cairo_surface_t *t = cairo_xlib_surface_create(dpy, tw->buf,
			DefaultVisual(dpy,scr), tw->w, tw->h);
	tw->ctx = cairo_create(t);
	cairo_surface_destroy(t);
	cairo_set_font_face(tw->ctx,conf.font);
	cairo_set_font_size(tw->ctx,conf.font_size);
	XSelectInput(dpy, tw->win, EVENT_MASK);
	XSetTransientForHint(dpy, tw->win, win);
	XSetWMProtocols(dpy, tw->win, &WM_DELETE_WINDOW, 1);
	XSizeHints *hints = XAllocSizeHints();
	hints->min_width = hints->max_width = tw->w;
	hints->min_height = hints->max_height = tw->h;
	hints->flags = PMinSize | PMaxSize;
	XSetWMNormalHints(dpy, tw->win, hints);
	XFree(hints);
	XStoreName(dpy, tw->win, tw->name);
	if (tw->backing) tw->backing(tw);
	else toolwin_backing(tw);
	XSetWindowBackgroundPixmap(dpy, tw->win, tw->buf);
	XFlush(dpy);
	return 0;
}
Esempio n. 9
0
void ilG_gui_textlayout_getExtents(ilG_gui_textlayout *self, unsigned *rx, unsigned *ry, int *bx, int *by, int *ax, int *ay)
{
    if (!self->have_size) {
        self->have_size = 1;
        cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
        cairo_t *cr = cairo_create(surface);

        il_return_on_fail(self->cairo_glyphs);
        cairo_set_font_face(cr, self->cairo_ft_face);
        cairo_set_font_size(cr, self->pt);
        cairo_glyph_extents(cr, self->cairo_glyphs, self->glyph_count, &self->extents);
        cairo_surface_destroy(surface);
        cairo_destroy(cr);
    }
    if (rx) {
        *rx = self->extents.width;
    }
    if (ry) {
        *ry = self->extents.height + 1; // TODO: ????
    }
    if (bx) {
        *bx = self->extents.x_bearing;
    }
    if (by) {
        *by = self->extents.y_bearing;
    }
    if (ax) {
        *ax = self->extents.x_advance;
    }
    if (ay) {
        *ay = self->extents.y_advance;
    }
}
Esempio n. 10
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;
}
Esempio n. 11
0
int renderTruetypeSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol,
                              symbolStyleObj *s)
{
  int unicode;
  cairo_glyph_t glyph;
  cairo_text_extents_t extents;

  cairo_matrix_t trans;
  double ox,oy;
  cairoCacheData *cache = MS_IMAGE_RENDERER_CACHE(img);
  cairo_renderer *r = CAIRO_RENDERER(img);
  faceCacheObj *face = getFontFace(cache,symbol->full_font_path);

  if(!face) return MS_FAILURE;

  cairo_save(r->cr);
  cairo_set_font_face(r->cr,face->face);
  cairo_set_font_size(r->cr,s->scale*96/72.0);


  msUTF8ToUniChar(symbol->character, &unicode);

  if (face->ftface->charmap &&
    face->ftface->charmap->encoding == FT_ENCODING_MS_SYMBOL)
    unicode |= 0xf000;

  glyph.index = FT_Get_Char_Index(face->ftface, unicode);
  glyph.x=0;
  glyph.y=0;
  cairo_glyph_extents(r->cr,&glyph,1,&extents);
  ox=extents.x_bearing+extents.width/2.;
  oy=extents.y_bearing+extents.height/2.;



  cairo_matrix_init_rotate(&trans,-s->rotation);

  cairo_matrix_transform_point(&trans,&ox,&oy);
  /* cairo_translate(cr,-extents.width/2,-extents.height/2); */

  cairo_translate(r->cr,x-ox,y-oy);
  cairo_rotate(r->cr, -s->rotation);

  cairo_glyph_path(r->cr,&glyph,1);

  if (s->outlinewidth) {
    msCairoSetSourceColor(r->cr, s->outlinecolor);
    cairo_set_line_width(r->cr, s->outlinewidth + 1);
    cairo_stroke_preserve(r->cr);
  }
  if(s->color) {
    msCairoSetSourceColor(r->cr, s->color);
    cairo_fill_preserve(r->cr);
  }
  cairo_new_path(r->cr);
  cairo_restore(r->cr);
  return MS_SUCCESS;
}
Esempio n. 12
0
static int cairo_set_font_face_l( lua_State* L )
{
  lua_cairo_t* lc = lua_cairo_check( L, 1 );
  lua_cairo_font_face_t* lcff = lua_cairo_font_face_check( L, 2 );

  cairo_set_font_face( lc->cairo, lcff->crface );

  return( 0 );
}
Esempio n. 13
0
static int info_split_printf(ToolWin *tw, char *bold, char *fmt, ...) {
	char str[MAX_STRING];
	va_list arg;
	va_start(arg, fmt);
	vsprintf(str, fmt, arg);
	va_end(arg);
	cairo_set_font_face(tw->ctx, conf.bfont);
	cairo_text_extents(tw->ctx,bold,&ext);
	cairo_rel_move_to(tw->ctx, MARGIN, conf.font_size);
	cairo_show_text(tw->ctx,bold);
	cairo_rel_move_to(tw->ctx, -1.0 * ext.x_advance - MARGIN, 0);
	cairo_set_font_face(tw->ctx, conf.font);
	cairo_text_extents(tw->ctx,str,&ext);
	cairo_rel_move_to(tw->ctx, tw->w - ext.x_advance - MARGIN, 0);
	cairo_show_text(tw->ctx,str);
	cairo_rel_move_to(tw->ctx, MARGIN - tw->w, conf.font_size / 3.0);
	return 0;
}
Esempio n. 14
0
static int
cr_set_font_face (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    cairo_font_face_t *face = 0;
    if (!lua_isnoneornil(L, 2))
        face = *(cairo_font_face_t **) luaL_checkudata(L, 2, OOCAIRO_MT_NAME_FONTFACE);
    cairo_set_font_face(*obj, face);
    return 0;
}
Esempio n. 15
0
void Aw::Label::getMetrics(cairo_t *cr, Size& min_size, bool& expandh, bool& expandv)
{
    // We over-ride the
    switch (m_font_type)
    {
        case font_type::normal:
            cairo_set_font_face(cr, theApp->m_font.m_norm_face);
            break;
        case font_type::bold:
            cairo_set_font_face(cr, theApp->m_font.m_bold_face);
            break;
        case font_type::mono:
            cairo_set_font_face(cr, theApp->m_font.m_mono_face);
            break;
    }

    cairo_text_extents_t te;
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_set_font_size(cr, m_font_size);
    cairo_text_extents (cr, m_text.c_str(), &te);

//    anvil_syslog(0, "TEXT: %s %d %d %d %d %d %d\n",
//            m_text.c_str(),
//            (int)te.width,
//            (int)te.height,
//            (int)te.x_advance,
//            (int)te.y_advance,
//            (int)te.x_bearing,
//            (int)te.y_bearing
//            );

    min_size = getMinSize();
    if (te.width + 10 > min_size.m_width)
    {
        min_size.m_width = te.width + 10;
    }
    if (te.height + 10 > min_size.m_height)
    {
        min_size.m_height = te.height + 10;
    }

    expandh = expandH();
    expandv = expandV();
}
Esempio n. 16
0
void Context::setFont( const cinder::Font &font )
{
#if defined( CINDER_COCOA )
	cairo_font_face_t *cairoFont = cairo_quartz_font_face_create_for_cgfont( font.getCgFontRef() );
#elif defined( CINDER_MSW )
	cairo_font_face_t *cairoFont = cairo_win32_font_face_create_for_logfontw( &font.getLogfont() );
#endif
	cairo_set_font_face( mCairo, cairoFont );
	cairo_font_face_destroy( cairoFont );
}
Esempio n. 17
0
void Aw::Label::Draw(cairo_t *cr)
{
    //anvil_syslog(0, "AwLabel::Draw %s %d %d\n", m_text.c_str(), size.m_width, size.m_height);
    switch (m_font_type)
    {
        case font_type::normal:
            cairo_set_font_face(cr, theApp->m_font.m_norm_face);
            break;
        case font_type::bold:
            cairo_set_font_face(cr, theApp->m_font.m_bold_face);
            break;
        case font_type::mono:
            cairo_set_font_face(cr, theApp->m_font.m_mono_face);
            break;
    }

    cairo_text_extents_t te;
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_set_font_size(cr, m_font_size);
    cairo_text_extents (cr, m_text.c_str(), &te);

    double x, y;
    switch (m_just)
    {
        case just::left:
            x = te.x_bearing + k_text_gap;
            y = m_draw_size.m_height/2 - (te.height/2 + te.y_bearing);
            break;
        case just::centre:
            x = m_draw_size.m_width/2  - (te.width/2  + te.x_bearing);
            y = m_draw_size.m_height/2 - (te.height/2 + te.y_bearing);
            break;
        case just::right:
            x = m_draw_size.m_width - te.width - te.x_bearing;
            y = m_draw_size.m_height/2 - (te.height/2 + te.y_bearing);
            break;
    }
    cairo_move_to(cr, x, y);
    cairo_show_text(cr, m_text.c_str());

    drawChild(cr);
}
    void SelectFont() {
        if (mFontSelected)
            return;

        cairo_t *cr = mContext->GetCairo();

        cairo_set_font_face(cr, mShaper->GetFont()->CairoFontFace());
        cairo_set_font_size(cr, mShaper->GetFont()->GetAdjustedSize());
        cairo_scaled_font_t *scaledFont = mShaper->GetFont()->CairoScaledFont();
        cairo_win32_scaled_font_select_font(scaledFont, mDC);

        mFontSelected = true;
    }
Esempio n. 19
0
static gboolean
pango_cairo_win32_font_install (PangoCairoFont *font,
				cairo_t        *cr)
{
  PangoCairoWin32Font *cwfont = PANGO_CAIRO_WIN32_FONT (font);

  cairo_set_font_face (cr,
		       pango_cairo_win32_font_get_font_face (font));
  cairo_set_font_matrix (cr, &cwfont->font_matrix);
  cairo_set_font_options (cr, cwfont->options);

  return TRUE;
}
Esempio n. 20
0
static void
realize_callback (GtkWidget *drawing_area,
		  FT_Face face)
{
    gint i, pixmap_width, pixmap_height;
    const gchar *text;
    cairo_text_extents_t extents;
    cairo_font_face_t *font;
    gint *sizes = NULL, n_sizes, alpha_size;
    cairo_t *cr;

    cr = gdk_cairo_create (gtk_widget_get_window (drawing_area));

    text = get_sample_string (face);
    sizes = build_sizes_table (face, &n_sizes, &alpha_size);

    /* calculate size of pixmap to use (with 4 pixels padding) ... */
    pixmap_width = 8;
    pixmap_height = 8;

    font = cairo_ft_font_face_create_for_ft_face (face, 0);
    cairo_set_font_face (cr, font);
    cairo_set_font_size (cr, alpha_size);
    cairo_font_face_destroy (font);

    cairo_text_extents (cr, lowercase_text, &extents);
    pixmap_height += extents.height + 4;
    pixmap_width = MAX (pixmap_width, 8 + extents.width);

    cairo_text_extents (cr, uppercase_text, &extents);
    pixmap_height += extents.height + 4;
    pixmap_width = MAX (pixmap_width, 8 + extents.width);

    cairo_text_extents (cr, punctuation_text, &extents);
    pixmap_height += extents.height + 4;
    pixmap_width = MAX (pixmap_width, 8 + extents.width);

    pixmap_height += 8;

    for (i = 0; i < n_sizes; i++) {
	cairo_set_font_size (cr, sizes[i]);
	cairo_text_extents (cr, text, &extents);
	pixmap_height += extents.height + 4;
	pixmap_width = MAX (pixmap_width, 8 + extents.width);
    }

    gtk_widget_set_size_request (drawing_area, pixmap_width, pixmap_height);

    cairo_destroy (cr);
    g_free (sizes);
}
Esempio n. 21
0
	void renderLabels(cairo_t* cr, std::vector<std::pair<string, FloatPoint> >& toPlace) {
		cairo_save(cr);
		cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5);
		cairo_font_face_t* font = cairo_toy_font_face_create(DEFAULT_FONT, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
		cairo_set_font_face(cr, font);
		cairo_set_font_size(cr, 120.0);
		cairo_set_line_width(cr, 2.0);

		cairo_text_extents_t textSize;
		std::list<shared_ptr<Label> > labels;
		int i = 0;
		std::vector<shared_ptr<Style>> styles;
		for (auto& pair : toPlace)
		{
			string& text = pair.first;
			cairo_text_extents(cr, text.c_str(), &textSize);
			shared_ptr<Style> s = boost::make_shared<Style>();
			s->text = text;
			styles.push_back(s);
			FloatPoint center = pair.second + FloatPoint(textSize.width/2.0, textSize.height/2.0);
			FloatRect owner = FloatRect(center.x, center.y, center.x, center.y);
			FloatPoint origin = pair.second - FloatPoint(textSize.x_bearing, textSize.y_bearing);
			shared_ptr<Label> l = boost::make_shared<Label>(FloatRect(pair.second, textSize.width, textSize.height), owner, s->text, s.get(), origin);

			cairo_rectangle(cr, l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
			cairo_stroke(cr);

			labels.push_back(l);
		}

		std::vector<shared_ptr<Label> > placed;
		placeLabels(labels, placed);

		for (auto& l: placed)
		{
			cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
			cairo_move_to(cr, l->box.minX, l->box.maxY);
			cairo_show_text(cr, l->style->text.str().c_str());
			cairo_fill(cr);

			cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.5);
			cairo_rectangle(cr, l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
			cairo_fill(cr);
		}

		cairo_restore(cr);
	}
Esempio n. 22
0
void TermBox::Draw(cairo_t *cr)
{
    m_cols = (m_draw_size.m_width - 10) / 6;
    m_rows = (m_draw_size.m_height - 10) / 13;

    m_screen->set_size(m_cols, m_rows);

    //anvil_syslog(0, "TermBox::Draw() r=%d c=%d\n", m_rows, m_cols);

    cairo_set_font_face(cr, theApp->m_font.m_mono_face);
    cairo_text_extents_t te;
    cairo_set_font_size(cr, 10);

//    int ncols = m_draw_size.m_width / 6;
//    int nrows = m_draw_size.m_height / 13;
    //anvil_syslog(0, "TermBox::Draw r=%d c=%d\n", nrows, m_cols);

    int xpos = 0;
    int ypos = 0;
    m_screen->prepare();
    for (int r=0; r<m_rows; ++r)
    {
        for (int c=0; c<m_cols; ++c)
        {
            NormalScreen::term_cell cell = m_screen->GetChar(c, r);
            // Draw background
            cairo_set_source_rgb(cr, cell.back, cell.back, cell.back);
            cairo_rectangle(cr, xpos + 4.5, ypos + 7, 7, 13);
            cairo_fill(cr);
            // Draw char
            cairo_set_source_rgb(cr, cell.fore, cell.fore, cell.fore);
            cairo_move_to(cr, xpos + 5, ypos + 18);

            mbstate_t state;
            char buf[10];
            int len = wcrtomb(buf, cell.ch, &state);
            buf[len] = 0;
            cairo_show_text(cr, buf);
            xpos += 6;
        }
        ypos += 13;
        xpos = 0;
    }

    drawChild(cr);

}
Esempio n. 23
0
ilA_img *ilG_gui_textlayout_render(ilG_gui_textlayout *self, float col[4], enum ilG_gui_textoptions opts)
{
    (void)opts;
    unsigned w = 0, h = 0;
    unsigned x = 0, y = 0;
    int bx = 0, by = 0;
    int scale = 64;
    unsigned i;

    self->cairo_ft_face = cairo_ft_font_face_create_for_ft_face(self->ft_face, 0);
    self->hb_ft_face = hb_ft_face_create(self->ft_face, NULL);

    x *= scale;
    y *= scale;
    self->cairo_glyphs = calloc(self->glyph_count, sizeof(cairo_glyph_t));
    for (i = 0; i < self->glyph_count; i++) {
        self->cairo_glyphs[i].index = self->glyph_info[i].codepoint;
        self->cairo_glyphs[i].x = (x + self->glyph_pos[i].x_offset)/scale;
        self->cairo_glyphs[i].y = (y + self->glyph_pos[i].y_offset)/scale;
        x += self->glyph_pos[i].x_advance;
        y += self->glyph_pos[i].y_advance;
    }

    ilG_gui_textlayout_getExtents(self, &w, &h, &bx, &by, NULL, NULL);
    self->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
    self->cr = cairo_create(self->surface);

    cairo_translate(self->cr, -bx, 1-by);
    cairo_set_source_rgba(self->cr, col[0], col[1], col[2], col[3]);
    cairo_set_font_face(self->cr, self->cairo_ft_face);
    cairo_set_font_size(self->cr, self->pt);
    cairo_show_glyphs(self->cr, self->cairo_glyphs, self->glyph_count);
    cairo_surface_flush(self->surface);

    ilA_img *preswizzle = ilA_img_fromdata(cairo_image_surface_get_data(self->surface), w, h, 8, ILA_IMG_RGBA);
    /*   R G B A | 0x
     * B 0 0 1 0 | 2
     * G 0 1 0 0 | 4
     * R 1 0 0 0 | 8
     * A 0 0 0 1 | 1
    */
    ilA_img *img = ilA_img_bgra_to_rgba(preswizzle);//ilA_img_swizzle(preswizzle, 0x2481);
    ilA_img_free(preswizzle);
    return img;
}
Esempio n. 24
0
static cairo_status_t
test_scaled_font_init (cairo_scaled_font_t  *scaled_font,
		       cairo_t              *cr,
		       cairo_font_extents_t *extents)
{
    cairo_set_font_face (cr,
			 cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
							&fallback_font_key));

    cairo_scaled_font_set_user_data (scaled_font,
				     &fallback_font_key,
				     cairo_scaled_font_reference (cairo_get_scaled_font (cr)),
				     (cairo_destroy_func_t) cairo_scaled_font_destroy);

    cairo_font_extents (cr, extents);

    return CAIRO_STATUS_SUCCESS;
}
Esempio n. 25
0
static void Rcairo_setup_font(CairoGDDesc* xd, R_GE_gcontext *gc) {
	cairo_t *cc = xd->cb->cc;

#ifdef CAIRO_HAS_FT_FONT
	int i = gc->fontface - 1;

	if (i < 0 || i >= 5) i = 0;

	if (Rcairo_fonts[i].updated || (xd->fontface != gc->fontface)){
		cairo_set_font_face(cc,Rcairo_fonts[i].face);
		set_cf_antialias(cc);
		Rcairo_fonts[i].updated = 0;
#ifdef JGD_DEBUG
		  Rprintf("  font face changed to \"%d\" %fpt\n", gc->fontface, gc->cex*gc->ps + 0.5);
#endif
	} 

	xd->fontface = gc->fontface;

#else
  char *Cfontface="Helvetica";
  int slant = CAIRO_FONT_SLANT_NORMAL;
  int wght  = CAIRO_FONT_WEIGHT_NORMAL;
#ifdef WIN32
  if (gc->fontface==5) Cfontface="Times";
#else
  if (gc->fontface==5) Cfontface="Symbol";
#endif
  if (gc->fontfamily[0]) Cfontface=gc->fontfamily;
  if (gc->fontface==3 || gc->fontface==4) slant=CAIRO_FONT_SLANT_ITALIC;
  if (gc->fontface==2 || gc->fontface==4) wght=CAIRO_FONT_WEIGHT_BOLD;
  
  cairo_select_font_face (cc, Cfontface, slant, wght);
  set_cf_antialias(cc);
#ifdef JGD_DEBUG
  Rprintf("  font \"%s\" %fpt (slant:%d, weight:%d)\n", Cfontface, gc->cex*gc->ps + 0.5, slant, wght);
#endif
#endif

  /* Add 0.5 per devX11.c in R src. We want to match it's png output as close
   * as possible. */
  cairo_set_font_size (cc, gc->cex * gc->ps * xd->fontscale + 0.5);
}
Esempio n. 26
0
void draw_axis(cairo_surface_t *cs,int mark){
  int i;
  cairo_t *c = cairo_create(cs);
  cairo_text_extents_t extents;
  cairo_font_face_t *ff;
  double SW = 105;

  cairo_set_source_rgba(c,AXIS_COLOR);
  cairo_set_line_width(c,AXIS_LINE_WIDTH);
  cairo_move_to(c,0,CR);
  cairo_line_to(c,W,CR);
  cairo_move_to(c,W-SW/2,CR-SW/3);
  cairo_line_to(c,W,CR);
  cairo_line_to(c,W-SW/2,CR+SW/3);
  cairo_stroke(c);

  cairo_set_line_width(c,AXIS_LINE_WIDTH*.75);

  if(mark){
    for(i=1;i*SPACING<W;i++){
      double x = i*SPACING-8;
      cairo_move_to(c,x,CR-AXIS_LINE_WIDTH*2);
      cairo_line_to(c,x,CR+AXIS_LINE_WIDTH*2);
    }
    cairo_stroke(c);
  }

  ff = cairo_toy_font_face_create ("Adobe Garamond",
                                   CAIRO_FONT_SLANT_ITALIC,
                                   CAIRO_FONT_WEIGHT_NORMAL);
  if(!ff){
    fprintf(stderr,"Unable to create axis font");
    exit(1);
  }
  cairo_set_font_face(c,ff);
  cairo_set_font_size(c, AXIS_FONT_SIZE);
  cairo_text_extents(c, "time", &extents);
  cairo_move_to(c, W-extents.width-SW*.6, CR + AXIS_FONT_SIZE);
  cairo_show_text(c, "time");

  cairo_font_face_destroy(ff);
  cairo_destroy(c);
}
Esempio n. 27
0
int renderGlyphs2Cairo(imageObj *img, textPathObj *tp, colorObj *c, colorObj *oc, int ow) {
  cairo_renderer *r = CAIRO_RENDERER(img);
  cairoCacheData *cache = MS_IMAGE_RENDERER_CACHE(img);
  cairoFaceCache *cairo_face = NULL;
  FT_Face prevface = NULL;
  int g;

  cairo_set_font_size(r->cr,MS_NINT(tp->glyph_size * 96.0/72.0));
  for(g=0;g<tp->numglyphs;g++) {
    glyphObj *gl = &tp->glyphs[g];
    cairo_glyph_t glyph;
    /* load the glyph's face into cairo, if not already present */
    if(gl->face->face != prevface) {
      cairo_face = getCairoFontFace(cache,gl->face->face);
      cairo_set_font_face(r->cr, cairo_face->face);
      cairo_set_font_options(r->cr,cairo_face->options);
      prevface = gl->face->face;
      cairo_set_font_size(r->cr,MS_NINT(tp->glyph_size * 96.0/72.0));
    }
    cairo_save(r->cr);
    cairo_translate(r->cr,gl->pnt.x,gl->pnt.y);
    if(gl->rot != 0.0)
      cairo_rotate(r->cr, -gl->rot);
    glyph.x = glyph.y = 0;
    glyph.index = gl->glyph->key.codepoint;
    cairo_glyph_path(r->cr,&glyph,1);
    cairo_restore(r->cr);
  }
  if (oc) {
    cairo_save(r->cr);
    msCairoSetSourceColor(r->cr, oc);
    cairo_set_line_width(r->cr, ow + 1);
    cairo_stroke_preserve(r->cr);
    cairo_restore(r->cr);
  }
  if(c) {
    msCairoSetSourceColor(r->cr, c);
    cairo_fill(r->cr);
  }
  cairo_new_path(r->cr);
  return MS_SUCCESS;
}
Esempio n. 28
0
static cairo_status_t
test_scaled_font_render_glyph (cairo_scaled_font_t  *scaled_font,
			       unsigned long         glyph,
			       cairo_t              *cr,
			       cairo_text_extents_t *extents)
{
    cairo_glyph_t cairo_glyph;

    cairo_glyph.index = glyph;
    cairo_glyph.x = 0;
    cairo_glyph.y = 0;

    cairo_set_font_face (cr,
			 cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
							&fallback_font_key));

    cairo_show_glyphs (cr, &cairo_glyph, 1);
    cairo_glyph_extents (cr, &cairo_glyph, 1, extents);

    return CAIRO_STATUS_SUCCESS;
}
Esempio n. 29
0
void Label_t::paint()
{
	clearSurface();

	cr = graphics.getContext();
	bounds = getBounds();

	cairo_set_source_rgba(cr, ARGB_TO_CAIRO_PARAMS(shapeColor));

	int textLeft;
	int textBot = (bounds.height / 2 - lastExtents.height / 2) + lastExtents.height;

	if (alignment == TextAlignment::CENTER) textLeft = bounds.width / 2 - lastExtents.width / 2;
	else if (alignment == TextAlignment::RIGHT) textLeft = bounds.width - lastExtents.width;
	else textLeft = 0;

	cairo_move_to(cr, textLeft, textBot);
	cairo_set_font_face(cr, font->getFace());
	cairo_set_font_size(cr, fontSize);
	cairo_show_text(cr, text.c_str());
}
Esempio n. 30
0
void Label_t::update()
{
	Rectangle thisBounds(0, 0, getBounds().width, getBounds().height);

	// Check if the component was ever layouted, otherwise set to a high value
	if (!thisBounds.width && !thisBounds.height)
	{
		thisBounds.width = 9999;
		thisBounds.height = 9999;
	}

	// get text bounds
	cr = graphics.getContext();
	cairo_set_font_face(cr, font->getFace());
	cairo_set_font_size(cr, fontSize);
	cairo_text_extents(cr, this->text.c_str(), &lastExtents);
	Dimension newPreferred(lastExtents.width + 3, lastExtents.height + 3);

	// Set new preferred size
	if (getPreferredSize() != newPreferred) setPreferredSize(newPreferred);
	markFor(COMPONENT_REQUIREMENT_PAINT);
}