From 91d8773a88938aaa0a78de9bc6f768baf7021bc8 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Tue, 30 Mar 2010 10:28:51 +0300 Subject: Remove the .vcproj files before rewriting them In case they are write protected for some reason. Might help Behdad's problem with make dist. --- pango/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pango/Makefile.am b/pango/Makefile.am index ce3d0b77..37510fa0 100644 --- a/pango/Makefile.am +++ b/pango/Makefile.am @@ -645,6 +645,7 @@ dist-hook: \ # pangowin32.vcproj is not automatically built, it is not being changed ../build/win32/vs9/pango.vcproj: $(top_srcdir)/build/win32/vs9/pango.vcprojin mini-fribidi/libmini-fribidi.sourcefiles + -rm $@ for F in $(libpango_1_0_la_SOURCES); do \ case $$F in \ *.c) echo ' ' \ @@ -654,6 +655,7 @@ dist-hook: \ $(CPP) -P - <$(top_srcdir)/build/win32/vs9/pango.vcprojin >$@ ../build/win32/vs9/pangoft2.vcproj: $(top_srcdir)/build/win32/vs9/pangoft2.vcprojin opentype/libharfbuzz.sourcefiles + -rm $@ for F in $(libpangoft2_1_0_la_SOURCES); do \ case $$F in \ *.c) echo ' ' \ @@ -665,6 +667,7 @@ dist-hook: \ ../build/win32/vs9/pangocairo.vcproj: $(top_srcdir)/build/win32/vs9/pangocairo.vcprojin # Backend-specific sources for the libpangocairo DLL are explicitly # listed in the vcprojin file + -rm $@ for F in $(pangocairo_core_sources); do \ case $$F in \ *.c) echo ' ' \ -- cgit v1.2.1 From 1a36b77ee5030c099eff8a6ac7f0081a4a46d69d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 1 Apr 2010 03:33:22 -0400 Subject: Bug 582698 - Support CSS-style margin specification --- pango-view/viewer-render.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/pango-view/viewer-render.c b/pango-view/viewer-render.c index e672dcd4..8e3cc7f8 100644 --- a/pango-view/viewer-render.c +++ b/pango-view/viewer-render.c @@ -38,7 +38,10 @@ gboolean opt_pixels = FALSE; const char *opt_font = ""; gboolean opt_header = FALSE; const char *opt_output = NULL; -int opt_margin = 10; +int opt_margin_t = 10; +int opt_margin_r = 10; +int opt_margin_b = 10; +int opt_margin_l = 10; int opt_markup = FALSE; gboolean opt_rtl = FALSE; double opt_rotate = 0; @@ -248,8 +251,8 @@ do_output (PangoContext *context, PangoMatrix *orig_matrix; gboolean supports_matrix; int rotated_width, rotated_height; - int x = opt_margin; - int y = opt_margin; + int x = opt_margin_l; + int y = opt_margin_t; int width, height; width = 0; @@ -331,8 +334,8 @@ do_output (PangoContext *context, width = MAX (width, rect.width); height += rect.height; - width += 2 * opt_margin; - height += 2 * opt_margin; + width += opt_margin_l + opt_margin_r; + height += opt_margin_t + opt_margin_b; if (width_out) *width_out = width; @@ -543,6 +546,30 @@ parse_background (const char *name, name, arg, data, error); } +static gboolean +parse_margin (const char *name G_GNUC_UNUSED, + const char *arg, + gpointer data G_GNUC_UNUSED, + GError **error) +{ + switch (sscanf (arg, "%d %d %d %d", &opt_margin_t, &opt_margin_r, &opt_margin_b, &opt_margin_l)) + { + case 0: + { + g_set_error(error, + G_OPTION_ERROR, + G_OPTION_ERROR_BAD_VALUE, + "Argument for --margin must be one to four space-separated numbers"); + return FALSE; + } + case 1: opt_margin_r = opt_margin_t; + case 2: opt_margin_b = opt_margin_t; + case 3: opt_margin_l = opt_margin_r; + } + return TRUE; +} + + static gchar * backends_to_string (void) { @@ -680,8 +707,8 @@ parse_options (int argc, char *argv[]) "Align paragraph lines to be justified", NULL}, {"language", 0, 0, G_OPTION_ARG_STRING, &opt_language, "Language to use for font selection", "en_US/etc"}, - {"margin", 0, 0, G_OPTION_ARG_INT, &opt_margin, - "Set the margin on the output in pixels", "pixels"}, + {"margin", 0, 0, G_OPTION_ARG_CALLBACK, &parse_margin, + "Set the margin on the output in pixels", "CSS-style numbers in pixels"}, {"markup", 0, 0, G_OPTION_ARG_NONE, &opt_markup, "Interpret text as Pango markup", NULL}, {"output", 'o', 0, G_OPTION_ARG_STRING, &opt_output, -- cgit v1.2.1 From 52ab3d508ad900cc435aa6529cd4a333db43af78 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 19 Apr 2010 02:27:56 -0400 Subject: [HB] Fix debug build --- pango/opentype/hb-open-type-private.hh | 2 +- pango/opentype/hb-ot-layout-gsubgpos-private.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 06324ee3..77c5dfe4 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -124,7 +124,7 @@ struct Null \ HB_STMT_START { \ if (sanitize_depth < HB_DEBUG_SANITIZE) \ fprintf (stderr, "SANITIZE(%p) %-*d-> %s\n", \ - (CONST_CHARP (this) == NullPool) ? 0 : this, \ + (CONST_CHARP (this) == CONST_CHARP (&NullPool)) ? 0 : this, \ sanitize_depth, sanitize_depth, \ __PRETTY_FUNCTION__); \ } HB_STMT_END diff --git a/pango/opentype/hb-ot-layout-gsubgpos-private.hh b/pango/opentype/hb-ot-layout-gsubgpos-private.hh index 0e15cf60..13e74759 100644 --- a/pango/opentype/hb-ot-layout-gsubgpos-private.hh +++ b/pango/opentype/hb-ot-layout-gsubgpos-private.hh @@ -43,7 +43,7 @@ HB_STMT_START { \ if (apply_depth < HB_DEBUG_APPLY) \ fprintf (stderr, "APPLY(%p) %-*d-> %s\n", \ - (CONST_CHARP (this) == NullPool) ? 0 : this, \ + (CONST_CHARP (this) == CONST_CHARP (&NullPool)) ? 0 : this, \ apply_depth, apply_depth, \ __PRETTY_FUNCTION__); \ } HB_STMT_END -- cgit v1.2.1 From 5383831f1c73eaed7696fddad3e2fb823858a8ff Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 19 Apr 2010 02:29:04 -0400 Subject: [HB] Fix warnings --- pango/opentype/hb-open-type-private.hh | 2 +- pango/opentype/hb-ot-layout-gdef-private.hh | 4 ++-- pango/opentype/hb-ot-layout-gpos-private.hh | 4 ++-- pango/opentype/hb-ot-layout-gsubgpos-private.hh | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 77c5dfe4..98d46bd9 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -117,7 +117,7 @@ struct Null \ #endif #if HB_DEBUG_SANITIZE -#define TRACE_SANITIZE_ARG_DEF , unsigned int sanitize_depth +#define TRACE_SANITIZE_ARG_DEF , unsigned int sanitize_depth HB_GNUC_UNUSED #define TRACE_SANITIZE_ARG , sanitize_depth + 1 #define TRACE_SANITIZE_ARG_INIT , 1 #define TRACE_SANITIZE() \ diff --git a/pango/opentype/hb-ot-layout-gdef-private.hh b/pango/opentype/hb-ot-layout-gdef-private.hh index 69f90fec..f6480542 100644 --- a/pango/opentype/hb-ot-layout-gdef-private.hh +++ b/pango/opentype/hb-ot-layout-gdef-private.hh @@ -87,7 +87,7 @@ struct CaretValueFormat1 friend struct CaretValue; private: - inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const + inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_GNUC_UNUSED) const { /* TODO vertical */ return context->font->x_scale * coordinate / 0x10000; @@ -129,7 +129,7 @@ struct CaretValueFormat3 { friend struct CaretValue; - inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const + inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_GNUC_UNUSED) const { /* TODO vertical */ return context->font->x_scale * coordinate / 0x10000 + diff --git a/pango/opentype/hb-ot-layout-gpos-private.hh b/pango/opentype/hb-ot-layout-gpos-private.hh index be7b5a5c..e4ec9fcf 100644 --- a/pango/opentype/hb-ot-layout-gpos-private.hh +++ b/pango/opentype/hb-ot-layout-gpos-private.hh @@ -149,7 +149,7 @@ struct AnchorFormat1 friend struct Anchor; private: - inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id, + inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_GNUC_UNUSED, hb_position_t *x, hb_position_t *y) const { *x = _hb_16dot16_mul_trunc (context->font->x_scale, xCoordinate); @@ -199,7 +199,7 @@ struct AnchorFormat3 friend struct Anchor; private: - inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id, + inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_GNUC_UNUSED, hb_position_t *x, hb_position_t *y) const { *x = _hb_16dot16_mul_trunc (context->font->x_scale, xCoordinate); diff --git a/pango/opentype/hb-ot-layout-gsubgpos-private.hh b/pango/opentype/hb-ot-layout-gsubgpos-private.hh index 13e74759..0bb96a41 100644 --- a/pango/opentype/hb-ot-layout-gsubgpos-private.hh +++ b/pango/opentype/hb-ot-layout-gsubgpos-private.hh @@ -36,7 +36,7 @@ #endif #if HB_DEBUG_APPLY -#define TRACE_APPLY_ARG_DEF , unsigned int apply_depth +#define TRACE_APPLY_ARG_DEF , unsigned int apply_depth HB_GNUC_UNUSED #define TRACE_APPLY_ARG , apply_depth + 1 #define TRACE_APPLY_ARG_INIT , 1 #define TRACE_APPLY() \ @@ -59,7 +59,7 @@ hb_buffer_t *buffer, \ unsigned int context_length HB_GNUC_UNUSED, \ unsigned int nesting_level_left HB_GNUC_UNUSED, \ - unsigned int lookup_flag, \ + unsigned int lookup_flag HB_GNUC_UNUSED, \ unsigned int property HB_GNUC_UNUSED /* propety of first glyph */ \ TRACE_APPLY_ARG_DEF #define APPLY_ARG \ @@ -90,7 +90,7 @@ struct ContextFuncs }; -static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, char *data) +static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, char *data HB_GNUC_UNUSED) { return glyph_id == value; } -- cgit v1.2.1 From 0d0cbf451613c301ae358cc4dbe54fb63ae5fc9e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 19 Apr 2010 02:34:10 -0400 Subject: [HB] Round instead of trunc --- pango/opentype/hb-ot-layout-gpos-private.hh | 20 ++++++++++---------- pango/opentype/hb-private.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pango/opentype/hb-ot-layout-gpos-private.hh b/pango/opentype/hb-ot-layout-gpos-private.hh index e4ec9fcf..dcbbf0f5 100644 --- a/pango/opentype/hb-ot-layout-gpos-private.hh +++ b/pango/opentype/hb-ot-layout-gpos-private.hh @@ -104,13 +104,13 @@ struct ValueRecord { y_scale = context->font->y_scale; /* design units -> fractional pixel */ if (format & xPlacement) - glyph_pos->x_pos += _hb_16dot16_mul_trunc (x_scale, *(SHORT*)values++); + glyph_pos->x_pos += _hb_16dot16_mul_round (x_scale, *(SHORT*)values++); if (format & yPlacement) - glyph_pos->y_pos += _hb_16dot16_mul_trunc (y_scale, *(SHORT*)values++); + glyph_pos->y_pos += _hb_16dot16_mul_round (y_scale, *(SHORT*)values++); if (format & xAdvance) - glyph_pos->x_advance += _hb_16dot16_mul_trunc (x_scale, *(SHORT*)values++); + glyph_pos->x_advance += _hb_16dot16_mul_round (x_scale, *(SHORT*)values++); if (format & yAdvance) - glyph_pos->y_advance += _hb_16dot16_mul_trunc (y_scale, *(SHORT*)values++); + glyph_pos->y_advance += _hb_16dot16_mul_round (y_scale, *(SHORT*)values++); x_ppem = context->font->x_ppem; y_ppem = context->font->y_ppem; @@ -152,8 +152,8 @@ struct AnchorFormat1 inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_GNUC_UNUSED, hb_position_t *x, hb_position_t *y) const { - *x = _hb_16dot16_mul_trunc (context->font->x_scale, xCoordinate); - *y = _hb_16dot16_mul_trunc (context->font->y_scale, yCoordinate); + *x = _hb_16dot16_mul_round (context->font->x_scale, xCoordinate); + *y = _hb_16dot16_mul_round (context->font->y_scale, yCoordinate); } inline bool sanitize (SANITIZE_ARG_DEF) { @@ -177,8 +177,8 @@ struct AnchorFormat2 hb_position_t *x, hb_position_t *y) const { /* TODO Contour */ - *x = _hb_16dot16_mul_trunc (context->font->x_scale, xCoordinate); - *y = _hb_16dot16_mul_trunc (context->font->y_scale, yCoordinate); + *x = _hb_16dot16_mul_round (context->font->x_scale, xCoordinate); + *y = _hb_16dot16_mul_round (context->font->y_scale, yCoordinate); } inline bool sanitize (SANITIZE_ARG_DEF) { @@ -202,8 +202,8 @@ struct AnchorFormat3 inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_GNUC_UNUSED, hb_position_t *x, hb_position_t *y) const { - *x = _hb_16dot16_mul_trunc (context->font->x_scale, xCoordinate); - *y = _hb_16dot16_mul_trunc (context->font->y_scale, yCoordinate); + *x = _hb_16dot16_mul_round (context->font->x_scale, xCoordinate); + *y = _hb_16dot16_mul_round (context->font->y_scale, yCoordinate); /* pixel -> fractional pixel */ if (context->font->x_ppem) diff --git a/pango/opentype/hb-private.h b/pango/opentype/hb-private.h index b17b24a0..92e514f7 100644 --- a/pango/opentype/hb-private.h +++ b/pango/opentype/hb-private.h @@ -207,7 +207,7 @@ _hb_popcount32 (uint32_t mask) /* Multiplies a 16dot16 value by another value, then truncates the result */ -#define _hb_16dot16_mul_trunc(A,B) ((int64_t) (A) * (B) / 0x10000) +#define _hb_16dot16_mul_round(A,B) (((int64_t) (A) * (B) + 0x8000) / 0x10000) #include "hb-object-private.h" -- cgit v1.2.1 From 1c90dc64539551c8e0b86415a4949b8eb21b5b1c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 29 Mar 2010 00:04:12 -0400 Subject: GNOME Bug 613015 - [HB] Does not sanitize Device tables referenced from ValueRecords --- pango/opentype/hb-ot-layout-gpos-private.hh | 147 ++++++++++++++++++++++------ 1 file changed, 116 insertions(+), 31 deletions(-) diff --git a/pango/opentype/hb-ot-layout-gpos-private.hh b/pango/opentype/hb-ot-layout-gpos-private.hh index dcbbf0f5..1624e83e 100644 --- a/pango/opentype/hb-ot-layout-gpos-private.hh +++ b/pango/opentype/hb-ot-layout-gpos-private.hh @@ -51,30 +51,13 @@ struct ValueFormat : USHORT xAdvDevice = 0x0040, /* Includes horizontal Device table for advance */ yAdvDevice = 0x0080, /* Includes vertical Device table for advance */ ignored = 0x0F00, /* Was used in TrueType Open for MM fonts */ - reserved = 0xF000 /* For future use */ - }; - - inline unsigned int get_len () const - { return _hb_popcount32 ((unsigned int) *this); } - inline unsigned int get_size () const - { return get_len () * Value::get_size (); } - - void apply_value (hb_ot_layout_context_t *context, - const char *base, - const Value *values, - hb_internal_glyph_position_t *glyph_pos) const - { - unsigned int x_ppem, y_ppem; - hb_16dot16_t x_scale, y_scale; - unsigned int format = *this; + reserved = 0xF000, /* For future use */ - if (!format) - return; + devices = 0x00F0, /* Mask for having any Device table */ + }; - /* All fields are options. Only those available advance the value - * pointer. */ +/* All fields are options. Only those available advance the value pointer. */ #if 0 -struct ValueRecord { SHORT xPlacement; /* Horizontal adjustment for * placement--in design units */ SHORT yPlacement; /* Vertical adjustment for @@ -97,9 +80,24 @@ struct ValueRecord { Offset yAdvDevice; /* Offset to Device table for vertical * advance--measured from beginning of * PosTable (may be NULL) */ -}; #endif + inline unsigned int get_len () const + { return _hb_popcount32 ((unsigned int) *this); } + inline unsigned int get_size () const + { return get_len () * Value::get_size (); } + + void apply_value (hb_ot_layout_context_t *context, + const char *base, + const Value *values, + hb_internal_glyph_position_t *glyph_pos) const + { + unsigned int x_ppem, y_ppem; + hb_16dot16_t x_scale, y_scale; + unsigned int format = *this; + + if (!format) return; + x_scale = context->font->x_scale; y_scale = context->font->y_scale; /* design units -> fractional pixel */ @@ -140,6 +138,68 @@ struct ValueRecord { values++; } } + + private: + inline bool sanitize_value_devices (SANITIZE_ARG_DEF, void *base, const Value *values) { + unsigned int format = *this; + + if (format & xPlacement) values++; + if (format & yPlacement) values++; + if (format & xAdvance) values++; + if (format & yAdvance) values++; + + if ((format & xPlaDevice) && !SANITIZE_BASE (*(OffsetTo*)values++, base)) return false; + if ((format & yPlaDevice) && !SANITIZE_BASE (*(OffsetTo*)values++, base)) return false; + if ((format & xAdvDevice) && !SANITIZE_BASE (*(OffsetTo*)values++, base)) return false; + if ((format & yAdvDevice) && !SANITIZE_BASE (*(OffsetTo*)values++, base)) return false; + + return true; + } + + public: + + inline bool has_device () { + unsigned int format = *this; + return (format & devices) != 0; + } + + inline bool sanitize_value (SANITIZE_ARG_DEF, void *base, const Value *values) { + TRACE_SANITIZE (); + + return SANITIZE_MEM (values, get_size ()) && + (!has_device () || sanitize_value_devices (SANITIZE_ARG, base, values)); + } + + inline bool sanitize_values (SANITIZE_ARG_DEF, void *base, const Value *values, unsigned int count) { + TRACE_SANITIZE (); + unsigned int len = get_len (); + + if (!SANITIZE_ARRAY (values, get_size (), count)) return false; + + if (!has_device ()) return true; + + for (unsigned int i = 0; i < count; i++) { + if (!sanitize_value_devices (SANITIZE_ARG, base, values)) + return false; + values += len; + } + + return true; + } + + inline bool sanitize_values_stride_unsafe (SANITIZE_ARG_DEF, void *base, const Value *values, unsigned int count, unsigned int stride) { + TRACE_SANITIZE (); + + if (!has_device ()) return true; + + for (unsigned int i = 0; i < count; i++) { + if (!sanitize_value_devices (SANITIZE_ARG, base, values)) + return false; + values += stride; + } + + return true; + } }; ASSERT_SIZE (ValueFormat, 2); @@ -377,7 +437,7 @@ struct SinglePosFormat1 inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); return SANITIZE_SELF () && SANITIZE_THIS (coverage) && - SANITIZE_MEM (values, valueFormat.get_size ()); + valueFormat.sanitize_value (SANITIZE_ARG, CHARP(this), values); } private: @@ -419,7 +479,7 @@ struct SinglePosFormat2 inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); return SANITIZE_SELF () && SANITIZE_THIS (coverage) && - SANITIZE_MEM (values, valueFormat.get_size () * valueCount); + valueFormat.sanitize_values (SANITIZE_ARG, CHARP(this), values, valueCount); } private: @@ -486,6 +546,7 @@ struct PairSet { friend struct PairPosFormat1; + /* Note: Doesn't sanitize the Device entries in the ValueRecord */ inline bool sanitize (SANITIZE_ARG_DEF, unsigned int format_len) { TRACE_SANITIZE (); if (!SANITIZE_SELF ()) return false; @@ -525,12 +586,11 @@ struct PairPosFormat1 j++; } - const PairSet &pair_set = this+pairSet[index]; - unsigned int len1 = valueFormat1.get_len (); unsigned int len2 = valueFormat2.get_len (); unsigned int record_size = USHORT::get_size () * (1 + len1 + len2); + const PairSet &pair_set = this+pairSet[index]; unsigned int count = pair_set.len; const PairValueRecord *record = pair_set.array; for (unsigned int i = 0; i < count; i++) @@ -552,9 +612,29 @@ struct PairPosFormat1 inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - return SANITIZE_SELF () && SANITIZE_THIS (coverage) && - pairSet.sanitize (SANITIZE_ARG, CONST_CHARP(this), - valueFormat1.get_len () + valueFormat2.get_len ()); + + unsigned int len1 = valueFormat1.get_len (); + unsigned int len2 = valueFormat2.get_len (); + + if (!(SANITIZE_SELF () && SANITIZE_THIS (coverage) && + pairSet.sanitize (SANITIZE_ARG, CONST_CHARP(this), len1 + len2))) return false; + + if (!(valueFormat1.has_device () || valueFormat2.has_device ())) return true; + + unsigned int stride = 1 + len1 + len2; + unsigned int count1 = pairSet.len; + for (unsigned int i = 0; i < count1; i++) + { + const PairSet &pair_set = this+pairSet[i]; + + unsigned int count2 = pair_set.len; + const PairValueRecord *record = pair_set.array; + if (!(valueFormat1.sanitize_values_stride_unsafe (SANITIZE_ARG, CHARP(this), &record->values[0], count2, stride) && + valueFormat2.sanitize_values_stride_unsafe (SANITIZE_ARG, CHARP(this), &record->values[len1], count2, stride))) + return false; + } + + return true; } private: @@ -623,9 +703,14 @@ struct PairPosFormat2 if (!(SANITIZE_SELF () && SANITIZE_THIS (coverage) && SANITIZE_THIS2 (classDef1, classDef2))) return false; + unsigned int len1 = valueFormat1.get_len (); + unsigned int len2 = valueFormat2.get_len (); + unsigned int stride = len1 + len2; unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size (); - unsigned int len = class1Count * class2Count; - return SANITIZE_ARRAY (values, record_size, len); + unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count; + return SANITIZE_ARRAY (values, record_size, count) && + valueFormat1.sanitize_values_stride_unsafe (SANITIZE_ARG, CHARP(this), &values[0], count, stride) && + valueFormat2.sanitize_values_stride_unsafe (SANITIZE_ARG, CHARP(this), &values[len1], count, stride); } private: -- cgit v1.2.1 From fc23518fc6fb391a0e7dc872c6a2e89a09cad018 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 20 Apr 2010 15:25:27 -0400 Subject: [HB] Remove ASSERT_SIZE_DATA --- pango/opentype/hb-open-type-private.hh | 4 ---- pango/opentype/hb-ot-layout-common-private.hh | 9 ++++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 98d46bd9..e146a2d3 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -84,10 +84,6 @@ struct Null \ #define Null(Type) (Null::get()) -#define ASSERT_SIZE_DATA(Type, size, data) \ - ASSERT_SIZE (Type, size); \ - DEFINE_NULL_DATA (Type, size, data) - /* get_for_data() is a static class method returning a reference to an * instance of Type located at the input data location. It's just a * fancy, NULL-safe, cast! */ diff --git a/pango/opentype/hb-ot-layout-common-private.hh b/pango/opentype/hb-ot-layout-common-private.hh index aff14689..0c0a768e 100644 --- a/pango/opentype/hb-ot-layout-common-private.hh +++ b/pango/opentype/hb-ot-layout-common-private.hh @@ -171,7 +171,8 @@ struct LangSys * = 0xFFFF */ IndexArray featureIndex; /* Array of indices into the FeatureList */ }; -ASSERT_SIZE_DATA (LangSys, 6, "\0\0\xFF\xFF"); +ASSERT_SIZE (LangSys, 6); +DEFINE_NULL_DATA (LangSys, 6, "\0\0\xFF\xFF"); struct Script @@ -372,7 +373,8 @@ struct CoverageRangeRecord USHORT startCoverageIndex; /* Coverage Index of first GlyphID in * range */ }; -ASSERT_SIZE_DATA (CoverageRangeRecord, 6, "\000\001"); +ASSERT_SIZE (CoverageRangeRecord, 6); +DEFINE_NULL_DATA (CoverageRangeRecord, 6, "\000\001"); struct CoverageFormat2 { @@ -491,7 +493,8 @@ struct ClassRangeRecord GlyphID end; /* Last GlyphID in the range */ USHORT classValue; /* Applied to all glyphs in the range */ }; -ASSERT_SIZE_DATA (ClassRangeRecord, 6, "\000\001"); +ASSERT_SIZE (ClassRangeRecord, 6); +DEFINE_NULL_DATA (ClassRangeRecord, 6, "\000\001"); struct ClassDefFormat2 { -- cgit v1.2.1 From 851f873072b26b32c514c459ba2ca141dd1b79e0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 20 Apr 2010 15:51:53 -0400 Subject: [HB] Add couple consts to operators --- pango/opentype/hb-open-type-private.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index e146a2d3..ea6ba5b4 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007,2008,2009 Red Hat, Inc. + * Copyright (C) 2007,2008,2009,2010 Red Hat, Inc. * * This is part of HarfBuzz, an OpenType Layout engine library. * @@ -346,7 +346,7 @@ struct Sanitizer { \ inline NAME& set (TYPE i) { (TYPE&) v = BIG_ENDIAN (i); return *this; } \ inline operator TYPE(void) const { return BIG_ENDIAN ((TYPE&) v); } \ - inline bool operator== (NAME o) const { return (TYPE&) v == (TYPE&) o.v; } \ + inline bool operator== (const NAME &o) const { return (TYPE&) v == (TYPE&) o.v; } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ TRACE_SANITIZE (); \ return SANITIZE_SELF (); \ @@ -361,7 +361,7 @@ struct Sanitizer static inline unsigned int get_size () { return BYTES; } \ inline NAME& set (TYPE i) { BIG_ENDIAN##_put_unaligned(v, i); return *this; } \ inline operator TYPE(void) const { return BIG_ENDIAN##_get_unaligned (v); } \ - inline bool operator== (NAME o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ + inline bool operator== (const NAME &o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ TRACE_SANITIZE (); \ return SANITIZE_SELF (); \ -- cgit v1.2.1 From 5453f4b097811e31e8205d3729bee1fc97d2e541 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 20 Apr 2010 15:52:47 -0400 Subject: [HB] Fix Class operator return type --- pango/opentype/hb-ot-layout-common-private.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pango/opentype/hb-ot-layout-common-private.hh b/pango/opentype/hb-ot-layout-common-private.hh index 0c0a768e..e3171e36 100644 --- a/pango/opentype/hb-ot-layout-common-private.hh +++ b/pango/opentype/hb-ot-layout-common-private.hh @@ -528,7 +528,7 @@ ASSERT_SIZE (ClassDefFormat2, 4); struct ClassDef { - inline unsigned int operator() (hb_codepoint_t glyph_id) const { return get_class (glyph_id); } + inline hb_ot_layout_class_t operator() (hb_codepoint_t glyph_id) const { return get_class (glyph_id); } inline hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const { -- cgit v1.2.1 From b11755c2f68d0dfe1dac7a7bce29defa25255bc9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 20 Apr 2010 23:50:45 -0400 Subject: [HB] Cosmetic --- pango/opentype/hb-open-type-private.hh | 8 ++++---- pango/opentype/hb-ot-layout-common-private.hh | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index ea6ba5b4..590b0d98 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -346,7 +346,7 @@ struct Sanitizer { \ inline NAME& set (TYPE i) { (TYPE&) v = BIG_ENDIAN (i); return *this; } \ inline operator TYPE(void) const { return BIG_ENDIAN ((TYPE&) v); } \ - inline bool operator== (const NAME &o) const { return (TYPE&) v == (TYPE&) o.v; } \ + inline bool operator == (const NAME &o) const { return (TYPE&) v == (TYPE&) o.v; } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ TRACE_SANITIZE (); \ return SANITIZE_SELF (); \ @@ -361,7 +361,7 @@ struct Sanitizer static inline unsigned int get_size () { return BYTES; } \ inline NAME& set (TYPE i) { BIG_ENDIAN##_put_unaligned(v, i); return *this; } \ inline operator TYPE(void) const { return BIG_ENDIAN##_get_unaligned (v); } \ - inline bool operator== (const NAME &o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ + inline bool operator == (const NAME &o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ TRACE_SANITIZE (); \ return SANITIZE_SELF (); \ @@ -386,7 +386,7 @@ struct Tag : ULONG inline Tag (const Tag &o) { *(ULONG*)this = (ULONG&) o; } inline Tag (uint32_t i) { (*(ULONG*)this).set (i); } inline Tag (const char *c) { *(ULONG*)this = *(ULONG*)c; } - inline bool operator== (const char *c) const { return *(ULONG*)this == *(ULONG*)c; } + inline bool operator == (const char *c) const { return *(ULONG*)this == *(ULONG*)c; } /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */ inline operator const char* (void) const { return CONST_CHARP(this); } inline operator char* (void) { return CHARP(this); } @@ -459,7 +459,7 @@ ASSERT_SIZE (FixedVersion, 4); template struct GenericOffsetTo : OffsetType { - inline const Type& operator() (const void *base) const + inline const Type& operator () (const void *base) const { unsigned int offset = *this; if (HB_UNLIKELY (!offset)) return Null(Type); diff --git a/pango/opentype/hb-ot-layout-common-private.hh b/pango/opentype/hb-ot-layout-common-private.hh index e3171e36..2cb59d64 100644 --- a/pango/opentype/hb-ot-layout-common-private.hh +++ b/pango/opentype/hb-ot-layout-common-private.hh @@ -410,7 +410,7 @@ ASSERT_SIZE (CoverageFormat2, 4); struct Coverage { - inline unsigned int operator() (hb_codepoint_t glyph_id) const { return get_coverage (glyph_id); } + inline unsigned int operator () (hb_codepoint_t glyph_id) const { return get_coverage (glyph_id); } inline unsigned int get_coverage (hb_codepoint_t glyph_id) const { @@ -528,7 +528,7 @@ ASSERT_SIZE (ClassDefFormat2, 4); struct ClassDef { - inline hb_ot_layout_class_t operator() (hb_codepoint_t glyph_id) const { return get_class (glyph_id); } + inline hb_ot_layout_class_t operator () (hb_codepoint_t glyph_id) const { return get_class (glyph_id); } inline hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const { @@ -564,7 +564,7 @@ struct ClassDef struct Device { - inline int operator() (unsigned int ppem_size) const { return get_delta (ppem_size); } + inline int operator () (unsigned int ppem_size) const { return get_delta (ppem_size); } inline int get_delta (unsigned int ppem_size) const { -- cgit v1.2.1 From 39620ce42fa212d4e76f49ac257d2b2cf6da20fa Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Apr 2010 00:14:12 -0400 Subject: [HB] Simplify Tag struct --- pango/opentype/hb-open-file-private.hh | 3 ++- pango/opentype/hb-open-type-private.hh | 6 +----- pango/opentype/hb-ot-layout-common-private.hh | 3 ++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pango/opentype/hb-open-file-private.hh b/pango/opentype/hb-open-file-private.hh index 0947747d..080975b7 100644 --- a/pango/opentype/hb-open-file-private.hh +++ b/pango/opentype/hb-open-file-private.hh @@ -84,7 +84,8 @@ typedef struct OffsetTable } inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const { - const Tag t = tag; + Tag t; + t.set (tag); // TODO bsearch unsigned int count = numTables; for (unsigned int i = 0; i < count; i++) diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 590b0d98..4dbff0dc 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -359,7 +359,7 @@ struct Sanitizer struct NAME \ { \ static inline unsigned int get_size () { return BYTES; } \ - inline NAME& set (TYPE i) { BIG_ENDIAN##_put_unaligned(v, i); return *this; } \ + inline void set (TYPE i) { BIG_ENDIAN##_put_unaligned(v, i); } \ inline operator TYPE(void) const { return BIG_ENDIAN##_get_unaligned (v); } \ inline bool operator == (const NAME &o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ @@ -383,10 +383,6 @@ DEFINE_INT_TYPE (LONG, , 32); /* 32-bit signed integer. */ * system, feature, or baseline */ struct Tag : ULONG { - inline Tag (const Tag &o) { *(ULONG*)this = (ULONG&) o; } - inline Tag (uint32_t i) { (*(ULONG*)this).set (i); } - inline Tag (const char *c) { *(ULONG*)this = *(ULONG*)c; } - inline bool operator == (const char *c) const { return *(ULONG*)this == *(ULONG*)c; } /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */ inline operator const char* (void) const { return CONST_CHARP(this); } inline operator char* (void) { return CHARP(this); } diff --git a/pango/opentype/hb-ot-layout-common-private.hh b/pango/opentype/hb-ot-layout-common-private.hh index 2cb59d64..1f6cf4a2 100644 --- a/pango/opentype/hb-ot-layout-common-private.hh +++ b/pango/opentype/hb-ot-layout-common-private.hh @@ -84,7 +84,8 @@ struct RecordArrayOf : ArrayOf > { } inline bool find_index (hb_tag_t tag, unsigned int *index) const { - const Tag t = tag; + Tag t; + t.set (tag); // TODO bsearch const Record *a = this->const_array(); unsigned int count = this->len; -- cgit v1.2.1 From 9091e0f4d59b4f6dec4b0992f86ddcc141c0b919 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Apr 2010 00:32:47 -0400 Subject: [HB] Use a function template instead of struct template for Null --- pango/opentype/hb-open-type-private.hh | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 4dbff0dc..832d2ad1 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -61,27 +61,25 @@ /* Null objects */ /* Global nul-content Null pool. Enlarge as necessary. */ -static const void *NullPool[32 / sizeof (void *)]; +static const void *_NullPool[32 / sizeof (void *)]; /* Generic template for nul-content sizeof-sized Null objects. */ template -struct Null -{ - ASSERT_STATIC (sizeof (Type) <= sizeof (NullPool)); - static inline const Type &get () { return CONST_CAST (Type, *NullPool, 0); } -}; +static inline const Type& Null () { + ASSERT_STATIC (sizeof (Type) <= sizeof (_NullPool)); + return CONST_CAST (Type, *_NullPool, 0); +} /* Specializaiton for arbitrary-content arbitrary-sized Null objects. */ #define DEFINE_NULL_DATA(Type, size, data) \ -static const char _Null##Type[size] = data; \ +static const char _Null##Type[size + 1] = data; \ template <> \ -struct Null \ -{ \ - static inline const Type &get () { return CONST_CAST (Type, *_Null##Type, 0); } \ +inline const Type& Null () { \ + return CONST_CAST (Type, *_Null##Type, 0); \ } /* Accessor macro. */ -#define Null(Type) (Null::get()) +#define Null(Type) Null() /* get_for_data() is a static class method returning a reference to an @@ -397,9 +395,7 @@ struct Tag : ULONG } }; ASSERT_SIZE (Tag, 4); -#define _NULL_TAG_INIT {' ', ' ', ' ', ' '} -DEFINE_NULL_DATA (Tag, 4, _NULL_TAG_INIT); -#undef _NULL_TAG_INIT +DEFINE_NULL_DATA (Tag, 4, " "); /* Glyph index number, same as uint16 (length = 16 bits) */ typedef USHORT GlyphID; -- cgit v1.2.1 From 4eca6bc0c98b573cc28005413e40790af8b10930 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Apr 2010 00:40:50 -0400 Subject: [HB] Remove stale TODO item --- pango/opentype/hb-open-type-private.hh | 1 - 1 file changed, 1 deletion(-) diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 832d2ad1..994f6d8d 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -247,7 +247,6 @@ _hb_sanitize_edit (SANITIZE_ARG_DEF, #define SANITIZE_OBJ(X) SANITIZE_MEM(&(X), sizeof (X)) #define SANITIZE_GET_SIZE() SANITIZE_SELF() && SANITIZE_MEM (this, this->get_size ()) -/* TODO Optimize this if L is fixed (gcc magic) */ #define SANITIZE_MEM(B,L) HB_LIKELY (_hb_sanitize_check (SANITIZE_ARG, CONST_CHARP(B), (L))) #define SANITIZE_ARRAY(A,S,L) HB_LIKELY (_hb_sanitize_array (SANITIZE_ARG, CONST_CHARP(A), S, L)) -- cgit v1.2.1 From 140cfe4b4a40f95a379c1b78881b1edf12f72145 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Apr 2010 00:49:40 -0400 Subject: [HB] Improve comments --- pango/opentype/hb-open-type-private.hh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 994f6d8d..9e99175a 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -510,11 +510,14 @@ struct GenericArrayOf inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); if (!SANITIZE_GET_SIZE()) return false; - /* Note: - * for non-recursive types, this is not much needed. - * But we keep the code to make sure the objects pointed to - * do have a simple sanitize(). */ + /* Note: for structs that do not reference other structs, + * we do not need to call their sanitize() as we already did + * a bound check on the aggregate array size, hence the return. + */ return true; + /* We do keep this code though to make sure the structs pointed + * to do have a simple sanitize(), ie. they do not reference + * other structs. */ unsigned int count = len; for (unsigned int i = 0; i < count; i++) if (!SANITIZE (array()[i])) @@ -613,11 +616,14 @@ struct HeadlessArrayOf inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); if (!SANITIZE_GET_SIZE()) return false; - /* Note: - * for non-recursive types, this is not much needed. - * But we keep the code to make sure the objects pointed to - * do have a simple sanitize(). */ + /* Note: for structs that do not reference other structs, + * we do not need to call their sanitize() as we already did + * a bound check on the aggregate array size, hence the return. + */ return true; + /* We do keep this code though to make sure the structs pointed + * to do have a simple sanitize(), ie. they do not reference + * other structs. */ unsigned int count = len ? len - 1 : 0; Type *a = array(); for (unsigned int i = 0; i < count; i++) -- cgit v1.2.1 From fd31122c5a153c3a21ae015cdd1c72aef79671d0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Apr 2010 02:04:22 -0400 Subject: [HB] Minor --- pango/opentype/hb-ot-layout-gpos-private.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pango/opentype/hb-ot-layout-gpos-private.hh b/pango/opentype/hb-ot-layout-gpos-private.hh index 1624e83e..44d15688 100644 --- a/pango/opentype/hb-ot-layout-gpos-private.hh +++ b/pango/opentype/hb-ot-layout-gpos-private.hh @@ -53,7 +53,7 @@ struct ValueFormat : USHORT ignored = 0x0F00, /* Was used in TrueType Open for MM fonts */ reserved = 0xF000, /* For future use */ - devices = 0x00F0, /* Mask for having any Device table */ + devices = 0x00F0 /* Mask for having any Device table */ }; /* All fields are options. Only those available advance the value pointer. */ -- cgit v1.2.1 From 34e05035af0ce854df1cc2f77c0b11dbc1a3cb36 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 4 May 2010 11:55:27 -0400 Subject: [cairo] Refactor common code in create_metrics_for_context() --- pango/pangocairo-atsuifont.c | 31 ++++++--------------------- pango/pangocairo-fcfont.c | 8 +++---- pango/pangocairo-font.c | 48 ++++++++++++++++++++++++++++++++++++++++- pango/pangocairo-private.h | 4 ++-- pango/pangocairo-win32font.c | 31 ++++++--------------------- pango/pangofc-font.c | 51 +++----------------------------------------- pango/pangofc-private.h | 4 ++-- 7 files changed, 70 insertions(+), 107 deletions(-) diff --git a/pango/pangocairo-atsuifont.c b/pango/pangocairo-atsuifont.c index 3abaffff..1c1ba550 100644 --- a/pango/pangocairo-atsuifont.c +++ b/pango/pangocairo-atsuifont.c @@ -46,15 +46,15 @@ struct _PangoCairoATSUIFontClass -static cairo_font_face_t *pango_cairo_atsui_font_create_font_face (PangoCairoFont *font); -static PangoFontMetrics *pango_cairo_atsui_font_create_metrics_for_context (PangoCairoFont *font, - PangoContext *context); +static cairo_font_face_t *pango_cairo_atsui_font_create_font_face (PangoCairoFont *font); +static PangoFontMetrics *pango_cairo_atsui_font_create_base_metrics_for_context (PangoCairoFont *font, + PangoContext *context); static void cairo_font_iface_init (PangoCairoFontIface *iface) { iface->create_font_face = pango_cairo_atsui_font_create_font_face; - iface->create_metrics_for_context = pango_cairo_atsui_font_create_metrics_for_context; + iface->create_base_metrics_for_context = pango_cairo_atsui_font_create_base_metrics_for_context; iface->cf_priv_offset = G_STRUCT_OFFSET (PangoCairoATSUIFont, cf_priv); } @@ -113,19 +113,14 @@ max_glyph_width (PangoLayout *layout) } static PangoFontMetrics * -pango_cairo_atsui_font_create_metrics_for_context (PangoCairoFont *font, - PangoContext *context) +pango_cairo_atsui_font_create_base_metrics_for_context (PangoCairoFont *font, + PangoContext *context) { PangoCairoATSUIFont *cafont = (PangoCairoATSUIFont *) font; PangoATSUIFont *afont = (PangoATSUIFont *) font; ATSFontRef ats_font; ATSFontMetrics ats_metrics; PangoFontMetrics *metrics; - PangoFontDescription *font_desc; - PangoLayout *layout; - PangoRectangle extents; - PangoLanguage *language = pango_context_get_language (context); - const char *sample_str = pango_language_get_sample_string (language); metrics = pango_font_metrics_new (); @@ -141,20 +136,6 @@ pango_cairo_atsui_font_create_metrics_for_context (PangoCairoFont *font, metrics->strikethrough_position = metrics->ascent / 3; metrics->strikethrough_thickness = ats_metrics.underlineThickness * cafont->size * PANGO_SCALE; - layout = pango_layout_new (context); - font_desc = pango_font_describe_with_absolute_size ((PangoFont *) font); - pango_layout_set_font_description (layout, font_desc); - pango_layout_set_text (layout, sample_str, -1); - pango_layout_get_extents (layout, NULL, &extents); - - metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str); - - pango_layout_set_text (layout, "0123456789", -1); - metrics->approximate_digit_width = max_glyph_width (layout); - - pango_font_description_free (font_desc); - g_object_unref (layout); - return metrics; } diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c index 8401ed8d..1393ce8e 100644 --- a/pango/pangocairo-fcfont.c +++ b/pango/pangocairo-fcfont.c @@ -64,19 +64,19 @@ pango_cairo_fc_font_create_font_face (PangoCairoFont *cfont) } static PangoFontMetrics * -pango_cairo_fc_font_create_metrics_for_context (PangoCairoFont *cfont, - PangoContext *context) +pango_cairo_fc_font_create_base_metrics_for_context (PangoCairoFont *cfont, + PangoContext *context) { PangoFcFont *fcfont = (PangoFcFont *) (cfont); - return pango_fc_font_create_metrics_for_context (fcfont, context); + return pango_fc_font_create_base_metrics_for_context (fcfont, context); } static void cairo_font_iface_init (PangoCairoFontIface *iface) { iface->create_font_face = pango_cairo_fc_font_create_font_face; - iface->create_metrics_for_context = pango_cairo_fc_font_create_metrics_for_context; + iface->create_base_metrics_for_context = pango_cairo_fc_font_create_base_metrics_for_context; iface->cf_priv_offset = G_STRUCT_OFFSET (PangoCairoFcFont, cf_priv); } diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index 35da71ce..ace2a575 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -206,6 +206,30 @@ _pango_cairo_font_install (PangoFont *font, } +static int +max_glyph_width (PangoLayout *layout) +{ + int max_width = 0; + GSList *l, *r; + + for (l = pango_layout_get_lines_readonly (layout); l; l = l->next) + { + PangoLayoutLine *line = l->data; + + for (r = line->runs; r; r = r->next) + { + PangoGlyphString *glyphs = ((PangoGlyphItem *)r->data)->glyphs; + int i; + + for (i = 0; i < glyphs->num_glyphs; i++) + if (glyphs->glyphs[i].geometry.width > max_width) + max_width = glyphs->glyphs[i].geometry.width; + } + } + + return max_width; +} + typedef struct _PangoCairoFontMetricsInfo { const char *sample_str; @@ -239,6 +263,10 @@ _pango_cairo_font_get_metrics (PangoFont *font, PangoFontMap *fontmap; PangoContext *context; cairo_font_options_t *font_options; + PangoLayout *layout; + PangoRectangle extents; + PangoFontDescription *desc; + int height, shift; /* XXX this is racy. need a ref'ing getter... */ @@ -260,7 +288,25 @@ _pango_cairo_font_get_metrics (PangoFont *font, pango_cairo_context_set_font_options (context, font_options); cairo_font_options_destroy (font_options); - info->metrics = (* PANGO_CAIRO_FONT_GET_IFACE (font)->create_metrics_for_context) (cfont, context); + info->metrics = (* PANGO_CAIRO_FONT_GET_IFACE (font)->create_base_metrics_for_context) (cfont, context); + + /* Update approximate_*_width now */ + + layout = pango_layout_new (context); + desc = pango_font_describe_with_absolute_size (font); + pango_layout_set_font_description (layout, desc); + pango_font_description_free (desc); + + pango_layout_set_text (layout, sample_str, -1); + pango_layout_get_extents (layout, NULL, &extents); + + info->metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str); + + pango_layout_set_text (layout, "0123456789", -1); + info->metrics->approximate_digit_width = max_glyph_width (layout); + + g_object_unref (layout); + /* We may actually reuse ascent/descent we got from cairo here. that's * in cf_priv->font_extents. diff --git a/pango/pangocairo-private.h b/pango/pangocairo-private.h index 3a4a9d0e..4e64f25d 100644 --- a/pango/pangocairo-private.h +++ b/pango/pangocairo-private.h @@ -95,8 +95,8 @@ struct _PangoCairoFontIface GTypeInterface g_iface; cairo_font_face_t *(*create_font_face) (PangoCairoFont *cfont); - PangoFontMetrics *(*create_metrics_for_context) (PangoCairoFont *cfont, - PangoContext *context); + PangoFontMetrics *(*create_base_metrics_for_context) (PangoCairoFont *cfont, + PangoContext *context); gssize cf_priv_offset; }; diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c index 3493d582..59f7c0f6 100644 --- a/pango/pangocairo-win32font.c +++ b/pango/pangocairo-win32font.c @@ -54,16 +54,16 @@ struct _PangoCairoWin32FontClass GType pango_cairo_win32_font_get_type (void); -static cairo_font_face_t *pango_cairo_win32_font_create_font_face (PangoCairoFont *font); -static PangoFontMetrics *pango_cairo_win32_font_create_metrics_for_context (PangoCairoFont *font, - PangoContext *context); +static cairo_font_face_t *pango_cairo_win32_font_create_font_face (PangoCairoFont *font); +static PangoFontMetrics *pango_cairo_win32_font_create_base_metrics_for_context (PangoCairoFont *font, + PangoContext *context); static void cairo_font_iface_init (PangoCairoFontIface *iface) { iface->create_font_face = pango_cairo_win32_font_create_font_face; - iface->create_metrics_for_context = pango_cairo_win32_font_create_metrics_for_context; + iface->create_base_metrics_for_context = pango_cairo_win32_font_create_base_metrics_for_context; iface->cf_priv_offset = G_STRUCT_OFFSET (PangoCairoWin32Font, cf_priv); } @@ -104,15 +104,10 @@ max_glyph_width (PangoLayout *layout) } static PangoFontMetrics * -pango_cairo_win32_font_create_metrics_for_context (PangoCairoFont *font, - PangoContext *context) +pango_cairo_win32_font_create_base_metrics_for_context (PangoCairoFont *font, + PangoContext *context) { PangoFontMetrics *metrics; - PangoFontDescription *font_desc; - PangoLayout *layout; - PangoRectangle extents; - PangoLanguage *language = pango_context_get_language (context); - const char *sample_str = pango_language_get_sample_string (language); cairo_scaled_font_t *scaled_font; cairo_font_extents_t font_extents; double height; @@ -144,20 +139,6 @@ pango_cairo_win32_font_create_metrics_for_context (PangoCairoFont *font, if (metrics->underline_position == 0) metrics->underline_position = - metrics->underline_thickness; - layout = pango_layout_new (context); - font_desc = pango_font_describe_with_absolute_size ((PangoFont *) font); - pango_layout_set_font_description (layout, font_desc); - pango_layout_set_text (layout, sample_str, -1); - pango_layout_get_extents (layout, NULL, &extents); - - metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str); - - pango_layout_set_text (layout, "0123456789", -1); - metrics->approximate_digit_width = max_glyph_width (layout); - - pango_font_description_free (font_desc); - g_object_unref (layout); - return metrics; } diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c index ad234beb..7c38ab76 100644 --- a/pango/pangofc-font.c +++ b/pango/pangofc-font.c @@ -479,60 +479,15 @@ get_face_metrics (PangoFcFont *fcfont, PANGO_FC_FONT_UNLOCK_FACE (fcfont); } -static int -max_glyph_width (PangoLayout *layout) -{ - int max_width = 0; - GSList *l, *r; - - for (l = pango_layout_get_lines_readonly (layout); l; l = l->next) - { - PangoLayoutLine *line = l->data; - - for (r = line->runs; r; r = r->next) - { - PangoGlyphString *glyphs = ((PangoGlyphItem *)r->data)->glyphs; - int i; - - for (i = 0; i < glyphs->num_glyphs; i++) - if (glyphs->glyphs[i].geometry.width > max_width) - max_width = glyphs->glyphs[i].geometry.width; - } - } - - return max_width; -} - PangoFontMetrics * -pango_fc_font_create_metrics_for_context (PangoFcFont *fcfont, - PangoContext *context) +pango_fc_font_create_base_metrics_for_context (PangoFcFont *fcfont, + PangoContext *context) { PangoFontMetrics *metrics; - PangoLayout *layout; - PangoRectangle extents; - PangoLanguage *language = pango_context_get_language (context); - const char *sample_str = pango_language_get_sample_string (language); - PangoFontDescription *desc = pango_font_describe_with_absolute_size (PANGO_FONT (fcfont)); - metrics = pango_font_metrics_new (); get_face_metrics (fcfont, metrics); - layout = pango_layout_new (context); - pango_layout_set_font_description (layout, desc); - pango_font_description_free (desc); - - pango_layout_set_text (layout, sample_str, -1); - pango_layout_get_extents (layout, NULL, &extents); - - metrics->approximate_char_width = - extents.width / pango_utf8_strwidth (sample_str); - - pango_layout_set_text (layout, "0123456789", -1); - metrics->approximate_digit_width = max_glyph_width (layout); - - g_object_unref (layout); - return metrics; } @@ -581,7 +536,7 @@ pango_fc_font_get_metrics (PangoFont *font, context = pango_font_map_create_context (fontmap); pango_context_set_language (context, language); - info->metrics = pango_fc_font_create_metrics_for_context (fcfont, context); + info->metrics = pango_fc_font_create_base_metrics_for_context (fcfont, context); g_object_unref (context); g_object_unref (fontmap); diff --git a/pango/pangofc-private.h b/pango/pangofc-private.h index e7c08bff..f200c8c0 100644 --- a/pango/pangofc-private.h +++ b/pango/pangofc-private.h @@ -90,8 +90,8 @@ void pango_fc_font_get_raw_extents (PangoFcFont *font, PangoRectangle *ink_rect, PangoRectangle *logical_rect); -PangoFontMetrics *pango_fc_font_create_metrics_for_context (PangoFcFont *font, - PangoContext *context); +PangoFontMetrics *pango_fc_font_create_base_metrics_for_context (PangoFcFont *font, + PangoContext *context); -- cgit v1.2.1 From 1caf2947f0941e2354dd4f43d56934e1ec706b6e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 4 May 2010 13:40:35 -0400 Subject: [cairo] Scale font metrics to user space Bug 457990 - font metrics are not converted to user space in cairo backend --- pango/pangocairo-font.c | 37 +++++++++++++++++++++++++++++++++++-- pango/pangocairo-private.h | 2 +- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index ace2a575..1f6382b8 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -22,6 +22,7 @@ #include "config.h" #include +#include #include "pangocairo.h" #include "pangocairo-private.h" @@ -266,6 +267,10 @@ _pango_cairo_font_get_metrics (PangoFont *font, PangoLayout *layout; PangoRectangle extents; PangoFontDescription *desc; + cairo_scaled_font_t *scaled_font; + cairo_matrix_t cairo_matrix; + PangoMatrix pango_matrix; + PangoMatrix identity = PANGO_MATRIX_INIT; int height, shift; @@ -281,17 +286,45 @@ _pango_cairo_font_get_metrics (PangoFont *font, info->sample_str = sample_str; + scaled_font = _pango_cairo_font_private_get_scaled_font (cf_priv); + context = pango_font_map_create_context (fontmap); pango_context_set_language (context, language); + font_options = cairo_font_options_create (); - cairo_scaled_font_get_font_options (_pango_cairo_font_private_get_scaled_font (cf_priv), font_options); + cairo_scaled_font_get_font_options (scaled_font, font_options); pango_cairo_context_set_font_options (context, font_options); cairo_font_options_destroy (font_options); info->metrics = (* PANGO_CAIRO_FONT_GET_IFACE (font)->create_base_metrics_for_context) (cfont, context); - /* Update approximate_*_width now */ + /* We now need to adjust the base metrics for ctm */ + cairo_scaled_font_get_ctm (scaled_font, &cairo_matrix); + pango_matrix.xx = cairo_matrix.xx; + pango_matrix.yx = cairo_matrix.yx; + pango_matrix.xy = cairo_matrix.xy; + pango_matrix.yy = cairo_matrix.yy; + pango_matrix.x0 = 0; + pango_matrix.y0 = 0; + if (G_UNLIKELY (0 != memcmp (&identity, &pango_matrix, 4 * sizeof (double)))) + { + double xscale = pango_matrix_get_font_scale_factor (&pango_matrix); + if (xscale) xscale = 1 / xscale; + + info->metrics->ascent *= xscale; + info->metrics->descent *= xscale; + info->metrics->underline_position *= xscale; + info->metrics->underline_thickness *= xscale; + info->metrics->strikethrough_position *= xscale; + info->metrics->strikethrough_thickness *= xscale; + } + + /* Set the matrix on the context so we don't have to adjust the derived + * metrics. */ + pango_context_set_matrix (context, &pango_matrix); + + /* Update approximate_*_width now */ layout = pango_layout_new (context); desc = pango_font_describe_with_absolute_size (font); pango_layout_set_font_description (layout, desc); diff --git a/pango/pangocairo-private.h b/pango/pangocairo-private.h index 4e64f25d..52a8b2f4 100644 --- a/pango/pangocairo-private.h +++ b/pango/pangocairo-private.h @@ -75,7 +75,7 @@ struct _PangoCairoFontPrivateScaledFontData struct _PangoCairoFontPrivate { PangoCairoFont *cfont; - + PangoCairoFontPrivateScaledFontData *data; cairo_scaled_font_t *scaled_font; -- cgit v1.2.1 From 495932623fb3390dd4249e08a3fd8593ebceaef4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 May 2010 20:45:07 -0400 Subject: Fix glyph class building. Oops! Bug 605870 - Incorrect shaping for Syriac --- pango/pango-ot-info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pango/pango-ot-info.c b/pango/pango-ot-info.c index 9c74f917..51aa50de 100644 --- a/pango/pango-ot-info.c +++ b/pango/pango-ot-info.c @@ -211,14 +211,14 @@ get_glyph_class (gunichar charcode, case G_UNICODE_COMBINING_MARK: case G_UNICODE_ENCLOSING_MARK: case G_UNICODE_NON_SPACING_MARK: - *class = 3; /* Mark glyph (non-spacing combining glyph) */ + *class = HB_OT_LAYOUT_GLYPH_CLASS_MARK; /* Mark glyph (non-spacing combining glyph) */ return TRUE; case G_UNICODE_UNASSIGNED: case G_UNICODE_PRIVATE_USE: return FALSE; /* Unknown, don't assign a class; classes get * propagated during GSUB application */ default: - *class = 1; /* Base glyph (single character, spacing glyph) */ + *class = HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH; /* Base glyph (single character, spacing glyph) */ return TRUE; } } -- cgit v1.2.1 From 8be1be82dbea3e81596366d1fa65d9b79d73850c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 26 May 2010 16:21:47 -0400 Subject: Cypriot is RTL --- pango/pango-gravity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pango/pango-gravity.c b/pango/pango-gravity.c index 297199a5..7553a07e 100644 --- a/pango/pango-gravity.c +++ b/pango/pango-gravity.c @@ -182,7 +182,7 @@ const PangoScriptProperties script_properties[] = /* Unicode-4.0 additions */ {LTR, NONE, S, FALSE}, /* Brai */ - {LTR, NONE, S, FALSE}, /* Cprt */ + {RTL, NONE, S, FALSE}, /* Cprt */ {LTR, NONE, S, FALSE}, /* Limb */ {LTR, NONE, S, FALSE}, /* Osma */ {LTR, NONE, S, FALSE}, /* Shaw */ -- cgit v1.2.1 From a30783a14c4dc69adc43922474e79721fec54829 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 3 Jun 2010 11:53:21 -0400 Subject: Fix a test failure See http://build.gnome.org/builders/pango-RHEL5/builds/310/steps/pango%20check/logs/stdio --- pango/pangoft2.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pango/pangoft2.def b/pango/pangoft2.def index 57294318..f2082ccb 100644 --- a/pango/pangoft2.def +++ b/pango/pangoft2.def @@ -2,7 +2,7 @@ EXPORTS pango_fc_decoder_get_charset pango_fc_decoder_get_glyph pango_fc_decoder_get_type - pango_fc_font_create_metrics_for_context + pango_fc_font_create_base_metrics_for_context pango_fc_font_description_from_pattern pango_fc_font_get_glyph pango_fc_font_get_raw_extents -- cgit v1.2.1 From 14763c551fa3c68bfe8ba02389a5f07ab65153b2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 15 Jun 2010 08:38:59 -0400 Subject: Bug 621612 - VPATH build fix --- pango-view/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pango-view/Makefile.am b/pango-view/Makefile.am index 2721f970..dbfd81a0 100644 --- a/pango-view/Makefile.am +++ b/pango-view/Makefile.am @@ -93,7 +93,7 @@ nodist_man_MANS = pango-view.1 # The indirection through pango-view.1.in is to make parallel build work. # See bug 587768. $(srcdir)/pango-view.1.in: ../configure.in $(pango_view_SOURCES) - $(AM_V_GEN) $(top_builddir)/missing --run \ + $(AM_V_GEN) $(top_srcdir)/missing --run \ help2man --no-info --section=1 \ --help-option="--help-all" --output="$@.tmp" \ --name 'Pango text viewer' ./pango-view \ -- cgit v1.2.1 From cf1022c02c89d50a64743b1cf8d989817e4e1fd1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 15 Jun 2010 10:05:16 -0400 Subject: Backport this commit from harfbuzz-ng repo: Fix awful confusion between lookup format and subtable format As reported by John Daggett. --- pango/opentype/hb-ot-layout-gpos-private.hh | 12 ++++++------ pango/opentype/hb-ot-layout-gsub-private.hh | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pango/opentype/hb-ot-layout-gpos-private.hh b/pango/opentype/hb-ot-layout-gpos-private.hh index 44d15688..e68739ed 100644 --- a/pango/opentype/hb-ot-layout-gpos-private.hh +++ b/pango/opentype/hb-ot-layout-gpos-private.hh @@ -1419,10 +1419,10 @@ struct PosLookupSubTable } } - inline bool sanitize (SANITIZE_ARG_DEF) { + inline bool sanitize (SANITIZE_ARG_DEF, unsigned int lookup_type) { TRACE_SANITIZE (); - if (!SANITIZE (u.format)) return false; - switch (u.format) { + if (!SANITIZE (u.sub_format)) return false; + switch (lookup_type) { case Single: return u.single->sanitize (SANITIZE_ARG); case Pair: return u.pair->sanitize (SANITIZE_ARG); case Cursive: return u.cursive->sanitize (SANITIZE_ARG); @@ -1438,7 +1438,7 @@ struct PosLookupSubTable private: union { - USHORT format; + USHORT sub_format; SinglePos single[VAR]; PairPos pair[VAR]; CursivePos cursive[VAR]; @@ -1535,7 +1535,7 @@ struct PosLookup : Lookup TRACE_SANITIZE (); if (!Lookup::sanitize (SANITIZE_ARG)) return false; OffsetArrayOf &list = (OffsetArrayOf &) subTable; - return SANITIZE_THIS (list); + return list.sanitize (SANITIZE_ARG, this, get_type ()); } }; @@ -1591,7 +1591,7 @@ inline bool ExtensionPos::sanitize (SANITIZE_ARG_DEF) return Extension::sanitize (SANITIZE_ARG) && (&(Extension::get_subtable ()) == &Null(LookupSubTable) || get_type () == PosLookupSubTable::Extension || - DECONST_CAST (PosLookupSubTable, get_subtable (), 0).sanitize (SANITIZE_ARG)); + DECONST_CAST (PosLookupSubTable, get_subtable (), 0).sanitize (SANITIZE_ARG, get_type ())); } static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index) diff --git a/pango/opentype/hb-ot-layout-gsub-private.hh b/pango/opentype/hb-ot-layout-gsub-private.hh index d35aaff1..a9f78c24 100644 --- a/pango/opentype/hb-ot-layout-gsub-private.hh +++ b/pango/opentype/hb-ot-layout-gsub-private.hh @@ -702,10 +702,10 @@ struct SubstLookupSubTable } } - inline bool sanitize (SANITIZE_ARG_DEF) { + inline bool sanitize (SANITIZE_ARG_DEF, unsigned int lookup_type) { TRACE_SANITIZE (); - if (!SANITIZE (u.format)) return false; - switch (u.format) { + if (!SANITIZE (u.sub_format)) return false; + switch (lookup_type) { case Single: return u.single->sanitize (SANITIZE_ARG); case Multiple: return u.multiple->sanitize (SANITIZE_ARG); case Alternate: return u.alternate->sanitize (SANITIZE_ARG); @@ -720,7 +720,7 @@ struct SubstLookupSubTable private: union { - USHORT format; + USHORT sub_format; SingleSubst single[VAR]; MultipleSubst multiple[VAR]; AlternateSubst alternate[VAR]; @@ -830,7 +830,7 @@ struct SubstLookup : Lookup TRACE_SANITIZE (); if (!Lookup::sanitize (SANITIZE_ARG)) return false; OffsetArrayOf &list = (OffsetArrayOf &) subTable; - return SANITIZE_THIS (list); + return list.sanitize (SANITIZE_ARG, this, get_type ()); } }; @@ -887,7 +887,7 @@ inline bool ExtensionSubst::sanitize (SANITIZE_ARG_DEF) return Extension::sanitize (SANITIZE_ARG) && (&(Extension::get_subtable ()) == &Null(LookupSubTable) || get_type () == SubstLookupSubTable::Extension || - DECONST_CAST (SubstLookupSubTable, get_subtable (), 0).sanitize (SANITIZE_ARG)); + DECONST_CAST (SubstLookupSubTable, get_subtable (), 0).sanitize (SANITIZE_ARG, get_type ())); } static inline bool substitute_lookup (APPLY_ARG_DEF, unsigned int lookup_index) -- cgit v1.2.1