static PyObject * toy_font_face_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *obj; PyObject *pyUTF8 = NULL; const char *utf8family = NULL; cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL; cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL; if (!PyArg_ParseTuple(args, "O!|ii:ToyFontFace.__new__", &PyBaseString_Type, &obj, &slant, &weight)) return NULL; /* accept str and unicode family, auto convert to utf8 as required */ if (PyString_Check(obj)) { /* A plain ASCII string is also a valid UTF-8 string */ utf8family = PyString_AS_STRING(obj); } else if (PyUnicode_Check(obj)) { pyUTF8 = PyUnicode_AsUTF8String(obj); if (pyUTF8 != NULL) { utf8family = PyString_AS_STRING(pyUTF8); } } else { PyErr_SetString(PyExc_TypeError, "ToyFontFace.__new__: family must be str or unicode"); } if (utf8family == NULL) return NULL; PyObject *o = PycairoFontFace_FromFontFace ( cairo_toy_font_face_create (utf8family, slant, weight)); Py_XDECREF(pyUTF8); return o; }
static cairo_status_t _user_font_face_create (cairo_font_face_t **out) { cairo_font_face_t *user_font_face; cairo_font_face_t *fallback_font_face; cairo_status_t status; user_font_face = cairo_user_font_face_create (); cairo_user_font_face_set_init_func (user_font_face, test_scaled_font_init); cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph); cairo_user_font_face_set_text_to_glyphs_func (user_font_face, test_scaled_font_text_to_glyphs); /* This also happens to be default font face on cairo_t, so does * not make much sense here. For demonstration only. */ fallback_font_face = cairo_toy_font_face_create ("", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); status = cairo_font_face_set_user_data (user_font_face, &fallback_font_key, fallback_font_face, (cairo_destroy_func_t) cairo_font_face_destroy); if (status) { cairo_font_face_destroy (fallback_font_face); cairo_font_face_destroy (user_font_face); return status; } *out = user_font_face; return CAIRO_STATUS_SUCCESS; }
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); }
static cairo_font_face_t * get_user_font_face (void) { if (!user_font_face) { cairo_font_face_t *fallback_font_face; user_font_face = cairo_user_font_face_create (); cairo_user_font_face_set_init_func (user_font_face, test_scaled_font_init); cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph); cairo_user_font_face_set_text_to_glyphs_func (user_font_face, test_scaled_font_text_to_glyphs); /* This also happens to be default font face on cairo_t, so does * not make much sense here. For demonstration only. */ fallback_font_face = cairo_toy_font_face_create ("", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_font_face_set_user_data (user_font_face, &fallback_font_key, fallback_font_face, (cairo_destroy_func_t) cairo_font_face_destroy); } return user_font_face; }
static int new_ToyFontFace (lua_State *L) { const char *family; cairo_font_slant_t slant; cairo_font_weight_t weight; cairo_font_face_t *ff; lua_remove(L, 1); // remove cairo.ToyFontFace family = luaL_checkstring(L, 1); slant = (cairo_font_slant_t) luaL_checkinteger(L, 2); weight = (cairo_font_weight_t) luaL_checkinteger(L, 3); ff = cairo_toy_font_face_create (family, slant, weight); return new_FontFace(L, LUACAIRO ".ToyFontFace.mt", ff, CAIRO_FONT_TYPE_TOY, 1); }
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); }
static VALUE cr_toy_font_face_initialize (int argc, VALUE *argv, VALUE self) { cairo_font_face_t *face; VALUE rb_family, rb_slant, rb_weight; const char *family; cairo_font_slant_t slant; cairo_font_weight_t weight; rb_scan_args (argc, argv, "03", &rb_family, &rb_slant, &rb_weight); if (NIL_P (rb_family)) { family = ""; } else if (rb_cairo__is_kind_of (rb_family, rb_cString)) { family = RSTRING_PTR (rb_family); } else if (rb_cairo__is_kind_of (rb_family, rb_cSymbol)) { family = rb_id2name (SYM2ID (rb_family)); } else { rb_raise (rb_eArgError, "family name should be nil, String or Symbol: %s", rb_cairo__inspect (rb_family)); } if (NIL_P (rb_slant)) slant = CAIRO_FONT_SLANT_NORMAL; else slant = RVAL2CRFONTSLANT (rb_slant); if (NIL_P (rb_weight)) weight = CAIRO_FONT_WEIGHT_NORMAL; else weight = RVAL2CRFONTWEIGHT (rb_weight); face = cairo_toy_font_face_create (family, slant, weight); cr_font_face_check_status (face); DATA_PTR (self) = face; return Qnil; }
void parse_config_font(const char *confkey, char *value) { char face[64]; char weight[8]; int size; int success = sscanf(value, " %64[^:] : %8[^:] : %2u", face, weight, &size); cairo_font_weight_t weight_t = CAIRO_FONT_WEIGHT_NORMAL; if(strcmp(weight, "bold") == 0) weight_t = CAIRO_FONT_WEIGHT_BOLD; if(success == 3) { //build the font cairo_font_face_t *font = cairo_toy_font_face_create(face, CAIRO_FONT_SLANT_NORMAL, weight_t); //TODO replace this mess with enums and config array if(strcmp(confkey, "keyfont") == 0) { conf->keyfont = font; conf->keyfontsize = (double)size; } else if(strcmp(confkey, "valfont") == 0) { conf->valfont = font; conf->valfontsize = (double)size; } else if(strcmp(confkey, "datefont") == 0) { conf->datefont = font; conf->datefontsize = (double)size; } else if(strcmp(confkey, "timefont") == 0) { conf->timefont = font; conf->timefontsize = (double)size; } else if(strcmp(confkey, "wsfont") == 0) { conf->wsfont = font; conf->wsfontsize = (double)size; } } else fprintf(stderr, "%sbad formatting of config font: '%s'\n", BAD_MSG, value); }
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); }