cairo


can't render text in cairo


I am new to cairo and I have read the tutorials/documentation on its website.
Now I can make lines, rectangles, and basically I can render images but not text.
I am using the following code
cairo_select_font_face (cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAl);
cairo_set_font_size (cr, 14);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_move_to (cr, 50, 50);
cairo_show_text (cr, "Print Something");
Can anyone please point to my mistake?
Same answer as on the cairo mailing list (where it seems to have been lost somewhere):
You aren't doing anything wrong (well, perhaps using the toy text API, but that should still work) and your code works fine for me. Here is the full code that I tested with:
#include <cairo.h>
int main()
{
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200);
cairo_t *cr = cairo_create(surface);
cairo_surface_destroy(surface);
/* Fill everything with white */
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_paint(cr);
/* Draw some text */
cairo_select_font_face (cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 14);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_move_to (cr, 0, 50);
cairo_show_text (cr, "Print Something");
cairo_surface_write_to_png(cairo_get_target(cr), "out.png");
cairo_destroy(cr);
return 0;
}

Related Links

Creating a copy of the cairo_t
Get Cairo output stream content when using PyCairo/CairoSharp/Inkscape
How to clear cairo_region_t
Filling a custom-shaped Clutter Actor with a Cairo-drawn canvas
Why does Cairo.set_source_rgb paint the whole canvas?
Howto sub class a Clutter.Actor (involves Cairo/Clutter.Canvas)
'CAIRO_GOBJECT_TYPE_SURFACE' undeclared
Drawing in a Clutter Texture with Cairo
can't render text in cairo
Why when painting one source to another am i getting the wrong colors
Can I automatically flow two font styles in a Pango Cairo Layout?
Cairo Radial Gradient
How to create gradient between two curves?
Cairo in scrollable drawing area
Can cairo load a PDF?
How to get Pango Cairo to word wrap properly?

Categories

HOME
python
sql-server-2008
xbox-live
cil
blockchain
wsdl
boost-thread
reportportal
memory-leaks
specflow
internet-explorer-11
google-spreadsheet-api
aruco
onsen-ui2
phoenix
ssms-2016
scenebuilder
android-toolbar
session-timeout
jcl
ms-access-2007
movies
multiple-columns
rworldmap
pdfsharp
edge-detection
outsystems
reactivemongo
color-scheme
android-preferences
flex4.5
tripwire
rich-text-editor
rdw
tuleap
goquery
ruby-on-rails-2
scd
cleditor
update-site
tomcat5
multifile-uploader
brython
nssplitview
spring-repositories
console-redirect
amazon-kcl
matcaffe
harp
viper-architecture
cpu-cores
mdm-zinc
adcolony
proxies
coin-flipping
neoload
dvcs
anjuta
uipickerviewcontroller
nsmatrix
installshield-2011
javascriptmvc
dynamic-binding
cgimageref
graph-coloring
android-contextmenu
mvs
cbcentralmanager
mvccontrib
pstree
mpmovieplayer
getstring
flash-cs5.5
emacs23
authenticode
pivotal-crm
delegatecommand
linfu
pci-bus
openvg
soft-keyboard
web-analytics-tools

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App