Created
December 15, 2017 13:22
-
-
Save yuki-takeichi/f9c1b7bf9154597518fbd9289b527004 to your computer and use it in GitHub Desktop.
Vertical Text Rendering with OpenType Color Emoji
This file contains 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
#include <stdio.h> | |
#include <math.h> | |
#include <pango/pangocairo.h> | |
int main () | |
{ | |
cairo_t *cr; | |
cairo_status_t status; | |
cairo_surface_t *surface; | |
PangoLayout *layout; | |
PangoFontDescription *desc; | |
PangoContext *context; | |
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 800, 300); | |
cr = cairo_create (surface); | |
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); | |
cairo_paint (cr); | |
cairo_translate (cr, 50, 100); | |
layout = pango_cairo_create_layout (cr); | |
pango_layout_set_text (layout, "้บฆ้ (beer) ๐บ๐ป๐บ๐ป๐", -1); | |
desc = pango_font_description_from_string ("Noto Sans CJK JP Regular 40"); | |
pango_layout_set_font_description (layout, desc); | |
pango_font_description_free (desc); | |
context = pango_layout_get_context (layout); | |
pango_context_set_base_gravity (context, PANGO_GRAVITY_EAST); | |
cairo_set_source_rgb (cr, 0, 0, 0); | |
pango_cairo_update_layout (cr, layout); | |
pango_cairo_show_layout (cr, layout); | |
g_object_unref (layout); | |
cairo_destroy (cr); | |
status = cairo_surface_write_to_png (surface, "output.png"); | |
cairo_surface_destroy (surface); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment