static int margin_l = 10;
static int margin_r = 10;
static int line_space = 0;
+static int face_index = 0;
static double font_size = 18;
static const char *fore = "#000000";
static const char *back = "#ffffff";
static const char *language = NULL;
static hb_feature_t *features = NULL;
static unsigned int num_features;
+static hb_bool_t annotate = FALSE;
static hb_bool_t debug = FALSE;
/* Ugh, global vars. Ugly, but does the job */
static cairo_surface_t *surface = NULL;
static cairo_pattern_t *fore_pattern = NULL;
static cairo_pattern_t *back_pattern = NULL;
-static FT_Library ft_library;
-static FT_Face ft_face;
static cairo_font_face_t *cairo_face;
G_GNUC_NORETURN static void
version (void)
{
- printf ("hb-view (harfbuzz) %s\n", PACKAGE_VERSION);
+ printf ("hb-view (harfbuzz) %s\n", HB_VERSION_STRING);
exit (0);
}
while (1)
{
int option_index = 0, c;
- static struct option long_options[] = {
+ static const struct option long_options[] = {
+ {"annotate", 0, &annotate, TRUE},
{"background", 1, 0, 'B'},
{"debug", 0, &debug, TRUE},
{"direction", 1, 0, 'd'},
{"features", 1, 0, 'f'},
{"font-size", 1, 0, 's'},
+ {"face-index", 1, 0, 'i'},
{"foreground", 1, 0, 'F'},
{"help", 0, 0, 'h'},
{"language", 1, 0, 'L'},
case 'v':
version ();
break;
+ case 'i':
+ face_index = atoi (optarg);
+ break;
case 'l':
line_space = atoi (optarg);
break;
case 'm':
switch (sscanf (optarg, "%d %d %d %d", &margin_t, &margin_r, &margin_b, &margin_l)) {
+ default: break;
case 1: margin_r = margin_t;
case 2: margin_b = margin_t;
case 3: margin_l = margin_r;
static cairo_glyph_t *
_hb_cr_text_glyphs (cairo_t *cr,
- const char *text, int len,
+ const char *utf8, int len,
unsigned int *pnum_glyphs)
{
cairo_scaled_font_t *scaled_font = cairo_get_scaled_font (cr);
hb_glyph_info_t *hb_glyph;
hb_glyph_position_t *hb_position;
unsigned int num_glyphs, i;
- hb_position_t x;
+ hb_position_t x, y;
hb_buffer = hb_buffer_create (0);
hb_buffer_set_language (hb_buffer, hb_language_from_string (language));
if (len < 0)
- len = strlen (text);
- hb_buffer_add_utf8 (hb_buffer, text, len, 0, len);
+ len = strlen (utf8);
+ hb_buffer_add_utf8 (hb_buffer, utf8, len, 0, len);
hb_shape (hb_font, hb_buffer, features, num_features);
hb_position = hb_buffer_get_glyph_positions (hb_buffer, NULL);
cairo_glyphs = cairo_glyph_allocate (num_glyphs);
x = 0;
+ y = 0;
for (i = 0; i < num_glyphs; i++)
{
cairo_glyphs[i].index = hb_glyph->codepoint;
- cairo_glyphs[i].x = (hb_position->x_offset + x) * (1./64);
- cairo_glyphs[i].y = -(hb_position->y_offset) * (1./64);
- x += hb_position->x_advance;
+ cairo_glyphs[i].x = ( hb_position->x_offset + x) * (1./64);
+ cairo_glyphs[i].y = (-hb_position->y_offset + y) * (1./64);
+ x += hb_position->x_advance;
+ y += -hb_position->y_advance;
hb_glyph++;
hb_position++;
fr = fg = fb = 0; fa = 255;
sscanf (fore + (*fore=='#'), "%2x%2x%2x%2x", &fr, &fg, &fb, &fa);
- if (ba == 255 && fa == 255 && br == bg && bg == bb && fr == fg && fg == fb) {
+ if (!annotate && ba == 255 && fa == 255 && br == bg && bg == bb && fr == fg && fg == fb) {
/* grayscale. use A8 surface */
surface = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
cr = cairo_create (surface);
width = MAX (width, extents.x_advance);
cairo_save (cr);
cairo_translate (cr, x, y);
+ if (annotate) {
+ unsigned int i;
+ cairo_save (cr);
+
+ /* Draw actual glyph origins */
+ cairo_set_source_rgba (cr, 1., 0., 0., .5);
+ cairo_set_line_width (cr, 5);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+ for (i = 0; i < num_glyphs; i++) {
+ cairo_move_to (cr, glyphs[i].x, glyphs[i].y);
+ cairo_rel_line_to (cr, 0, 0);
+ }
+ cairo_stroke (cr);
+
+ cairo_restore (cr);
+ }
cairo_show_glyphs (cr, glyphs, num_glyphs);
cairo_restore (cr);
y += ceil (font_extents.height - ceil (font_extents.ascent));
int
main (int argc, char **argv)
{
+ static FT_Library ft_library;
+ static FT_Face ft_face;
cairo_status_t status;
setlocale (LC_ALL, "");
parse_opts (argc, argv);
FT_Init_FreeType (&ft_library);
- if (FT_New_Face (ft_library, font_file, 0, &ft_face)) {
+ if (FT_New_Face (ft_library, font_file, face_index, &ft_face)) {
fprintf (stderr, "Failed to open font file `%s'\n", font_file);
exit (1);
}