Last active
May 18, 2021 21:16
-
-
Save ebraminio/670882634571c3b74f477dcad892ea2c to your computer and use it in GitHub Desktop.
make sure `pkg-config pangocairo --cflags --libs` prints something, otherwise some -dev packages should be installed given your distribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #cgo pkg-config: pangocairo | |
// #include <pango/pangocairo.h> | |
// void draw(const char *font, const char *text, const char *output) { | |
// int width, height; | |
// PangoFontDescription *font_description = pango_font_description_from_string(font); | |
// { | |
// cairo_surface_t *cairo_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); | |
// cairo_t *cr = cairo_create(cairo_surface); | |
// PangoLayout *pango_layout = pango_cairo_create_layout(cr); | |
// pango_layout_set_font_description(pango_layout, font_description); | |
// pango_layout_set_text(pango_layout, text, -1); | |
// pango_layout_set_auto_dir(pango_layout, 1); | |
// pango_layout_get_pixel_size(pango_layout, &width, &height); | |
// cairo_destroy(cr); | |
// cairo_surface_destroy(cairo_surface); | |
// } | |
// { | |
// cairo_surface_t *cairo_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); | |
// cairo_t *cr = cairo_create(cairo_surface); | |
// PangoLayout *pango_layout = pango_cairo_create_layout(cr); | |
// pango_layout_set_font_description(pango_layout, font_description); | |
// pango_layout_set_text(pango_layout, text, -1); | |
// pango_layout_set_auto_dir(pango_layout, 1); | |
// cairo_set_source_rgba(cr, 0, 0, 0, 0); | |
// cairo_rectangle(cr, 0, 0, width, height); | |
// cairo_fill(cr); | |
// cairo_set_source_rgb(cr, 1, 1, 1); | |
// pango_cairo_show_layout(cr, pango_layout); | |
// cairo_surface_write_to_png(cairo_surface, output); | |
// cairo_surface_destroy(cairo_surface); | |
// cairo_destroy(cr); | |
// } | |
// pango_font_description_free(font_description); | |
// } | |
import "C" | |
import "unsafe" | |
func main() { | |
font := C.CString("Noto Naskh Arabic 600") | |
defer C.free(unsafe.Pointer(font)) | |
text := C.CString("سلام") | |
defer C.free(unsafe.Pointer(text)) | |
output := C.CString("out.png") | |
defer C.free(unsafe.Pointer(output)) | |
C.draw(font, text, output) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment