Created
April 4, 2016 15:03
-
-
Save chearon/c4d0eeba9e81277b81f8f98a3f80c234 to your computer and use it in GitHub Desktop.
Print the family name, weight, style, and width of a specification string given to Pango
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 <pango/pango.h> | |
#include <glib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
char* | |
get_arg_string(int argc, char** argv) | |
{ | |
size_t total_len = 0; | |
char* s = NULL; | |
if (argc > 1) { | |
for (int i = 1; i < argc; ++i) total_len += strlen(*(argv+i)); | |
s = (char*) malloc(total_len + (argc-2) + 1); | |
char* ptr = s; | |
for (int i = 1; i < argc; ++i) { | |
unsigned len = strlen(*(argv+i)); | |
// Add the space | |
if (i > 1) { | |
*ptr = ' '; | |
ptr += 1; | |
} | |
memcpy(ptr, *(argv+i), len); | |
ptr += len; | |
} | |
*ptr = '\0'; | |
} | |
return s; | |
} | |
char* | |
stringify_desc(PangoFontDescription* desc) { | |
static char s[2048]; | |
g_snprintf(s, 2048, "%s %i %i %i", | |
pango_font_description_get_family(desc), | |
pango_font_description_get_weight(desc), | |
pango_font_description_get_stretch(desc), | |
pango_font_description_get_style(desc)); | |
return s; | |
} | |
int | |
main (int argc, char** argv) | |
{ | |
char* s = get_arg_string(argc, argv); | |
PangoFontDescription* desc = pango_font_description_from_string(s); | |
free(s); | |
printf("%s\n", stringify_desc(desc)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment