Fix hb-view surface size calc for vertical text
For some reason it doesn't quite work with IranianNastaliq, but that looks like a font issue.
This commit is contained in:
parent
6bd9b479b8
commit
69b84a8f6c
|
@ -64,8 +64,9 @@ struct helper_cairo_line_t {
|
||||||
g_free (utf8);
|
g_free (utf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
double get_width (void) {
|
void get_advance (double *x_advance, double *y_advance) {
|
||||||
return glyphs[num_glyphs].x;
|
*x_advance = glyphs[num_glyphs].x;
|
||||||
|
*y_advance = glyphs[num_glyphs].y;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,13 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gprintf.h>
|
#include <glib/gprintf.h>
|
||||||
|
|
||||||
|
#undef MIN
|
||||||
|
template <typename Type> static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; }
|
||||||
|
|
||||||
|
#undef MAX
|
||||||
|
template <typename Type> static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; }
|
||||||
|
|
||||||
|
|
||||||
void fail (hb_bool_t suggest_help, const char *format, ...) G_GNUC_NORETURN;
|
void fail (hb_bool_t suggest_help, const char *format, ...) G_GNUC_NORETURN;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ view_cairo_t::consume_line (hb_buffer_t *buffer,
|
||||||
const char *text,
|
const char *text,
|
||||||
unsigned int text_len)
|
unsigned int text_len)
|
||||||
{
|
{
|
||||||
|
direction = hb_buffer_get_direction (buffer);
|
||||||
helper_cairo_line_t l;
|
helper_cairo_line_t l;
|
||||||
helper_cairo_line_from_buffer (&l, buffer, text, text_len, scale);
|
helper_cairo_line_from_buffer (&l, buffer, text, text_len, scale);
|
||||||
g_array_append_val (lines, l);
|
g_array_append_val (lines, l);
|
||||||
|
@ -63,14 +64,17 @@ view_cairo_t::get_surface_size (cairo_scaled_font_t *scaled_font,
|
||||||
|
|
||||||
cairo_scaled_font_extents (scaled_font, &font_extents);
|
cairo_scaled_font_extents (scaled_font, &font_extents);
|
||||||
|
|
||||||
*h = font_extents.ascent
|
bool vertical = HB_DIRECTION_IS_VERTICAL (direction);
|
||||||
+ font_extents.descent
|
(vertical ? *w : *h) = (int) lines->len * (font_extents.height + line_space) - line_space;
|
||||||
+ ((int) lines->len - 1) * (font_extents.height + line_space);
|
(vertical ? *h : *w) = 0;
|
||||||
*w = 0;
|
|
||||||
for (unsigned int i = 0; i < lines->len; i++) {
|
for (unsigned int i = 0; i < lines->len; i++) {
|
||||||
helper_cairo_line_t &line = g_array_index (lines, helper_cairo_line_t, i);
|
helper_cairo_line_t &line = g_array_index (lines, helper_cairo_line_t, i);
|
||||||
double line_width = line.get_width ();
|
double x_advance, y_advance;
|
||||||
*w = MAX (*w, line_width);
|
line.get_advance (&x_advance, &y_advance);
|
||||||
|
if (vertical)
|
||||||
|
*h = MAX (*h, y_advance);
|
||||||
|
else
|
||||||
|
*w = MAX (*w, x_advance);
|
||||||
}
|
}
|
||||||
|
|
||||||
*w += margin.l + margin.r;
|
*w += margin.l + margin.r;
|
||||||
|
@ -97,17 +101,26 @@ view_cairo_t::draw (cairo_t *cr)
|
||||||
{
|
{
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
|
|
||||||
|
bool vertical = HB_DIRECTION_IS_VERTICAL (direction);
|
||||||
|
int v = vertical ? 1 : 0;
|
||||||
|
int h = vertical ? 0 : 1;
|
||||||
cairo_font_extents_t font_extents;
|
cairo_font_extents_t font_extents;
|
||||||
cairo_font_extents (cr, &font_extents);
|
cairo_font_extents (cr, &font_extents);
|
||||||
cairo_translate (cr, margin.l, margin.t);
|
cairo_translate (cr, margin.l, margin.t);
|
||||||
|
double descent;
|
||||||
|
if (vertical)
|
||||||
|
descent = font_extents.height * .5;
|
||||||
|
else
|
||||||
|
descent = font_extents.height - font_extents.ascent;
|
||||||
|
cairo_translate (cr, v * -descent, h * -descent);
|
||||||
for (unsigned int i = 0; i < lines->len; i++)
|
for (unsigned int i = 0; i < lines->len; i++)
|
||||||
{
|
{
|
||||||
helper_cairo_line_t &l = g_array_index (lines, helper_cairo_line_t, i);
|
helper_cairo_line_t &l = g_array_index (lines, helper_cairo_line_t, i);
|
||||||
|
|
||||||
if (i)
|
if (i)
|
||||||
cairo_translate (cr, 0, line_space);
|
cairo_translate (cr, v * line_space, h * line_space);
|
||||||
|
|
||||||
cairo_translate (cr, 0, font_extents.ascent);
|
cairo_translate (cr, v * font_extents.height, h * font_extents.height);
|
||||||
|
|
||||||
if (annotate) {
|
if (annotate) {
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
|
@ -137,8 +150,6 @@ view_cairo_t::draw (cairo_t *cr)
|
||||||
l.cluster_flags);
|
l.cluster_flags);
|
||||||
else
|
else
|
||||||
cairo_show_glyphs (cr, l.glyphs, l.num_glyphs);
|
cairo_show_glyphs (cr, l.glyphs, l.num_glyphs);
|
||||||
|
|
||||||
cairo_translate (cr, 0, font_extents.height - font_extents.ascent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
|
|
|
@ -52,6 +52,7 @@ struct view_cairo_t : output_options_t, view_options_t {
|
||||||
void get_surface_size (cairo_scaled_font_t *scaled_font, double *w, double *h);
|
void get_surface_size (cairo_scaled_font_t *scaled_font, double *w, double *h);
|
||||||
void draw (cairo_t *cr);
|
void draw (cairo_t *cr);
|
||||||
|
|
||||||
|
hb_direction_t direction; // Remove this, make segment_properties accessible
|
||||||
GArray *lines;
|
GArray *lines;
|
||||||
double scale;
|
double scale;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue