diff options
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | ChangeLog.pre-1-10 | 19 | ||||
-rw-r--r-- | ChangeLog.pre-1-8 | 19 | ||||
-rw-r--r-- | pango/fonts.c | 86 | ||||
-rw-r--r-- | pango/pango-attributes.c | 97 | ||||
-rw-r--r-- | pango/pango-attributes.h | 9 | ||||
-rw-r--r-- | pango/pango-font.h | 3 | ||||
-rw-r--r-- | pango/pangofc-fontmap.c | 5 | ||||
-rw-r--r-- | pango/pangoft2.c | 4 | ||||
-rw-r--r-- | pango/pangowin32-fontmap.c | 3 | ||||
-rw-r--r-- | pango/pangoxft-font.c | 17 |
11 files changed, 245 insertions, 36 deletions
@@ -1,3 +1,22 @@ +Wed Dec 15 22:09:42 2004 Owen Taylor <otaylor@redhat.com> + + Add pixel sizes for fonts (#119081, patch from Chris Lahey) + + * pango/fonts.c pango/pango-font.h: + Add pango_font_description_set_absolute_size(), + pango_font_description_get_size_is_absolute() + + * pango/pango-attributes.[ch]: Add pango_attr_size_new_absolute(), + change PANGO_ATTR_SIZE from PangoAttrInt to PangoAttrSize + (preserves compat because first component is identical) + + * pango/pangowin32-fontmap.c (pango_win32_font_map_load_font): + For absolute sizes, convert pixels to points, before + calling pango_win32_font_new(). + + * pango/pangofc-fontmap.c pango/pangoft2.c pango/pangoxft-font.c: + Handle absolute sizes. + Wed Dec 15 18:50:18 2004 Owen Taylor <otaylor@redhat.com> * modules/indic/indic-fc.c modules/indic/indic-ot.h: diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index 1aaa4269..2f519d6c 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,3 +1,22 @@ +Wed Dec 15 22:09:42 2004 Owen Taylor <otaylor@redhat.com> + + Add pixel sizes for fonts (#119081, patch from Chris Lahey) + + * pango/fonts.c pango/pango-font.h: + Add pango_font_description_set_absolute_size(), + pango_font_description_get_size_is_absolute() + + * pango/pango-attributes.[ch]: Add pango_attr_size_new_absolute(), + change PANGO_ATTR_SIZE from PangoAttrInt to PangoAttrSize + (preserves compat because first component is identical) + + * pango/pangowin32-fontmap.c (pango_win32_font_map_load_font): + For absolute sizes, convert pixels to points, before + calling pango_win32_font_new(). + + * pango/pangofc-fontmap.c pango/pangoft2.c pango/pangoxft-font.c: + Handle absolute sizes. + Wed Dec 15 18:50:18 2004 Owen Taylor <otaylor@redhat.com> * modules/indic/indic-fc.c modules/indic/indic-ot.h: diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8 index 1aaa4269..2f519d6c 100644 --- a/ChangeLog.pre-1-8 +++ b/ChangeLog.pre-1-8 @@ -1,3 +1,22 @@ +Wed Dec 15 22:09:42 2004 Owen Taylor <otaylor@redhat.com> + + Add pixel sizes for fonts (#119081, patch from Chris Lahey) + + * pango/fonts.c pango/pango-font.h: + Add pango_font_description_set_absolute_size(), + pango_font_description_get_size_is_absolute() + + * pango/pango-attributes.[ch]: Add pango_attr_size_new_absolute(), + change PANGO_ATTR_SIZE from PangoAttrInt to PangoAttrSize + (preserves compat because first component is identical) + + * pango/pangowin32-fontmap.c (pango_win32_font_map_load_font): + For absolute sizes, convert pixels to points, before + calling pango_win32_font_new(). + + * pango/pangofc-fontmap.c pango/pangoft2.c pango/pangoxft-font.c: + Handle absolute sizes. + Wed Dec 15 18:50:18 2004 Owen Taylor <otaylor@redhat.com> * modules/indic/indic-fc.c modules/indic/indic-ot.h: diff --git a/pango/fonts.c b/pango/fonts.c index f39d65a1..ccd13ed7 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -39,7 +39,8 @@ struct _PangoFontDescription guint16 mask; guint static_family : 1; - + guint size_is_absolute : 1; + int size; }; @@ -76,6 +77,7 @@ pango_font_description_new (void) desc->weight = PANGO_WEIGHT_NORMAL; desc->stretch = PANGO_STRETCH_NORMAL; desc->size = 0; + desc->size_is_absolute = FALSE; return desc; } @@ -331,10 +333,16 @@ pango_font_description_get_stretch (const PangoFontDescription *desc) /** * pango_font_description_set_size: * @desc: a #PangoFontDescription - * @size: the size for the font description in pango units. - * There are #PANGO_SCALE Pango units in one device unit (device unit is a point, for font sizes). - * - * Sets the size field of a font description. + * @size: the size of the font in points, scaled by PANGO_SCALE. (That is, + * a @size value of 10 * PANGO_SCALE is a 10 point font. The conversion + * factor between points and device units depends on system configuration + * and the output device. For screen display, a logical DPI of 96 is + * common, in which case a 10 point font corresponds to a 10 * (96 / 72) = 13.3 + * pixel font. Use pango_font_description_set_absolute_size() if you need + * a particular size in device units. + * + * Sets the size field of a font description in fractional points. This is mutually + * exclusive with pango_font_description_set_absolute_size(). **/ void pango_font_description_set_size (PangoFontDescription *desc, @@ -343,6 +351,7 @@ pango_font_description_set_size (PangoFontDescription *desc, g_return_if_fail (desc != NULL); desc->size = size; + desc->size_is_absolute = FALSE; desc->mask |= PANGO_FONT_MASK_SIZE; } @@ -353,9 +362,9 @@ pango_font_description_set_size (PangoFontDescription *desc, * Gets the size field of a font description. * See pango_font_description_get_size(). * - * Return value: the size field for the font description in pango - * units. (There are #PANGO_SCALE pango units in one device unit — - * for fonts, font points are the device unit.) Returns 0 if the stretch field has not + * Return value: the size field for the font description in points or device units. + * You must call pango_font_description_get_size_is_absolute() + * to find out which is the case. Returns 0 if the size field has not * previously been set. pango_font_description_get_set_fields() to * find out if the field was explicitely set or not. **/ @@ -368,6 +377,50 @@ pango_font_description_get_size (const PangoFontDescription *desc) } /** + * pango_font_description_set_absolute_size: + * @desc: a #PangoFontDescription + * @size: the new size, in pango units. There are #PANGO_SCALE Pango units in one + * device unit. For an output backend where a device unit is a pixel, a @size + * value of 10 * PANGO_SCALE gives a 10 pixel font. + * + * Sets the size field of a font description, in device units. This is mutually + * exclusive with pango_font_description_set_size(). + * + * Since: 1.8 + **/ +void +pango_font_description_set_absolute_size (PangoFontDescription *desc, + double size) +{ + g_return_if_fail (desc != NULL); + + desc->size = size; + desc->size_is_absolute = TRUE; + desc->mask |= PANGO_FONT_MASK_SIZE; +} + +/** + * pango_font_description_get_size_is_absolute: + * @desc: a #PangoFontDescription + * + * Determines whether the size of the font is in points or device units. + * See pango_font_description_set_size() and pango_font_description_set_absolute_size(). + * + * Return value: whether the the size for the font description is in + * points or device units. Use pango_font_description_get_set_fields() to + * find out if the size field of the font description was explicitely set or not. + * + * Since: 1.8 + **/ +gboolean +pango_font_description_get_size_is_absolute (const PangoFontDescription *desc) +{ + g_return_val_if_fail (desc != NULL, FALSE); + + return desc->size_is_absolute; +} + +/** * pango_font_description_get_set_fields: * @desc: a #PangoFontDescription * @@ -443,7 +496,10 @@ pango_font_description_merge (PangoFontDescription *desc, if (new_mask & PANGO_FONT_MASK_STRETCH) desc->stretch = desc_to_merge->stretch; if (new_mask & PANGO_FONT_MASK_SIZE) - desc->size = desc_to_merge->size; + { + desc->size = desc_to_merge->size; + desc->size_is_absolute = desc_to_merge->size_is_absolute; + } desc->mask |= new_mask; } @@ -486,7 +542,10 @@ pango_font_description_merge_static (PangoFontDescription *desc, if (new_mask & PANGO_FONT_MASK_STRETCH) desc->stretch = desc_to_merge->stretch; if (new_mask & PANGO_FONT_MASK_SIZE) - desc->size = desc_to_merge->size; + { + desc->size = desc_to_merge->size; + desc->size_is_absolute = desc_to_merge->size_is_absolute; + } desc->mask |= new_mask; } @@ -614,6 +673,7 @@ pango_font_description_equal (const PangoFontDescription *desc1, desc1->weight == desc2->weight && desc1->stretch == desc2->stretch && desc1->size == desc2->size && + desc1->size_is_absolute == desc2->size_is_absolute && (desc1->family_name == desc2->family_name || (desc1->family_name && desc2->family_name && g_ascii_strcasecmp (desc1->family_name, desc2->family_name) == 0))); } @@ -655,7 +715,10 @@ pango_font_description_hash (const PangoFontDescription *desc) if (desc->mask & PANGO_FONT_MASK_FAMILY) hash = case_insensitive_hash (desc->family_name); if (desc->mask & PANGO_FONT_MASK_SIZE) - hash ^= desc->size; + { + hash ^= desc->size; + hash ^= desc->size_is_absolute ? 0xc33ca55a : 0; + } if (desc->mask & PANGO_FONT_MASK_STYLE) hash ^= desc->style << 16; if (desc->mask & PANGO_FONT_MASK_VARIANT) @@ -839,6 +902,7 @@ pango_font_description_from_string (const char *str) desc->stretch = PANGO_STRETCH_NORMAL; desc->size = 0; + desc->size_is_absolute = FALSE; len = strlen (str); last = str + len; diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index f4b9b5e2..ca085c3c 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -40,16 +40,18 @@ struct _PangoAttrIterator int end_index; }; -static PangoAttribute *pango_attr_color_new (const PangoAttrClass *klass, - guint16 red, - guint16 green, - guint16 blue); -static PangoAttribute *pango_attr_string_new (const PangoAttrClass *klass, - const char *str); -static PangoAttribute *pango_attr_int_new (const PangoAttrClass *klass, - int value); -static PangoAttribute *pango_attr_float_new (const PangoAttrClass *klass, - double value); +static PangoAttribute *pango_attr_color_new (const PangoAttrClass *klass, + guint16 red, + guint16 green, + guint16 blue); +static PangoAttribute *pango_attr_string_new (const PangoAttrClass *klass, + const char *str); +static PangoAttribute *pango_attr_int_new (const PangoAttrClass *klass, + int value); +static PangoAttribute *pango_attr_float_new (const PangoAttrClass *klass, + double value); +static PangoAttribute *pango_attr_size_new_internal (int size, + gboolean absolute); /** @@ -396,25 +398,79 @@ pango_attr_float_new (const PangoAttrClass *klass, return (PangoAttribute *)result; } +static PangoAttribute * +pango_attr_size_copy (const PangoAttribute *attr) +{ + const PangoAttrSize *size_attr = (PangoAttrSize *)attr; + + return pango_attr_size_new_internal (size_attr->size, size_attr->absolute); +} + +static void +pango_attr_size_destroy (PangoAttribute *attr) +{ + g_free (attr); +} + +static gboolean +pango_attr_size_equal (const PangoAttribute *attr1, + const PangoAttribute *attr2) +{ + const PangoAttrSize *size_attr1 = (const PangoAttrSize *)attr1; + const PangoAttrSize *size_attr2 = (const PangoAttrSize *)attr2; + + return (size_attr1->size == size_attr2->size && + size_attr1->absolute == size_attr2->absolute); +} + +static PangoAttribute * +pango_attr_size_new_internal (int size, + gboolean absolute) +{ + PangoAttrSize *result; + static const PangoAttrClass klass = { + PANGO_ATTR_SIZE, + pango_attr_size_copy, + pango_attr_size_destroy, + pango_attr_size_equal + }; + + result = g_new (PangoAttrSize, 1); + result->attr.klass = &klass; + result->size = size; + result->absolute = absolute; + + return (PangoAttribute *)result; +} + /** * pango_attr_size_new: * @size: the font size, in #PANGO_SCALE<!-- -->ths of a point. * - * Create a new font-size attribute. + * Create a new font-size attribute in fractional points. * * Return value: the new #PangoAttribute. **/ PangoAttribute * pango_attr_size_new (int size) { - static const PangoAttrClass klass = { - PANGO_ATTR_SIZE, - pango_attr_int_copy, - pango_attr_int_destroy, - pango_attr_int_equal - }; + return pango_attr_size_new_internal (size, FALSE); +} - return pango_attr_int_new (&klass, size); +/** + * pango_attr_size_absolute_new: + * @size: the font size, in #PANGO_SCALE<!-- -->ths of a device units. + * + * Create a new font-size attribute in device units. + * + * Return value: the new #PangoAttribute. + * + * Since: 1.8 + **/ +PangoAttribute * +pango_attr_size_new_absolute (int size) +{ + return pango_attr_size_new_internal (size, TRUE); } /** @@ -1620,7 +1676,10 @@ pango_attr_iterator_get_font (PangoAttrIterator *iterator, if (!(mask & PANGO_FONT_MASK_SIZE)) { mask |= PANGO_FONT_MASK_SIZE; - pango_font_description_set_size (desc, ((PangoAttrInt *)attr)->value); + if (((PangoAttrSize *)attr)->absolute) + pango_font_description_set_size (desc, ((PangoAttrSize *)attr)->size); + else + pango_font_description_set_absolute_size (desc, ((PangoAttrSize *)attr)->size); } break; case PANGO_ATTR_SCALE: diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index 69b63187..a1877058 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -54,6 +54,7 @@ typedef struct _PangoAttrClass PangoAttrClass; typedef struct _PangoAttrString PangoAttrString; typedef struct _PangoAttrLanguage PangoAttrLanguage; typedef struct _PangoAttrInt PangoAttrInt; +typedef struct _PangoAttrSize PangoAttrSize; typedef struct _PangoAttrFloat PangoAttrFloat; typedef struct _PangoAttrColor PangoAttrColor; typedef struct _PangoAttrFontDesc PangoAttrFontDesc; @@ -146,6 +147,13 @@ struct _PangoAttrColor PangoColor color; }; +struct _PangoAttrSize +{ + PangoAttribute attr; + int size; + guint absolute : 1; +}; + struct _PangoAttrShape { PangoAttribute attr; @@ -179,6 +187,7 @@ PangoAttribute *pango_attr_background_new (guint16 red, guint16 green, guint16 blue); PangoAttribute *pango_attr_size_new (int size); +PangoAttribute *pango_attr_size_new_absolute (int size); PangoAttribute *pango_attr_style_new (PangoStyle style); PangoAttribute *pango_attr_weight_new (PangoWeight weight); PangoAttribute *pango_attr_variant_new (PangoVariant variant); diff --git a/pango/pango-font.h b/pango/pango-font.h index 53254301..5098350a 100644 --- a/pango/pango-font.h +++ b/pango/pango-font.h @@ -128,6 +128,9 @@ PangoStretch pango_font_description_get_stretch (const PangoFontDe void pango_font_description_set_size (PangoFontDescription *desc, gint size); gint pango_font_description_get_size (const PangoFontDescription *desc); +void pango_font_description_set_absolute_size (PangoFontDescription *desc, + double size); +gboolean pango_font_description_get_size_is_absolute (const PangoFontDescription *desc); PangoFontMask pango_font_description_get_set_fields (const PangoFontDescription *desc); void pango_font_description_unset_fields (PangoFontDescription *desc, diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index 0f7b67bb..a7e9f375 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -598,6 +598,7 @@ pango_fc_make_pattern (const PangoFontDescription *description) int slant; int weight; double size; + gboolean size_is_absolute; char **families; int i; #ifdef FC_WIDTH @@ -611,6 +612,7 @@ pango_fc_make_pattern (const PangoFontDescription *description) #endif size = (double) pango_font_description_get_size (description) / PANGO_SCALE; + size_is_absolute = pango_font_description_get_size_is_absolute (description); pattern = FcPatternBuild (NULL, FC_WEIGHT, FcTypeInteger, weight, @@ -618,7 +620,7 @@ pango_fc_make_pattern (const PangoFontDescription *description) #ifdef FC_WIDTH FC_WIDTH, FcTypeInteger, width, #endif - FC_SIZE, FcTypeDouble, size, + (size_is_absolute ? FC_PIXEL_SIZE : FC_SIZE), FcTypeDouble, size, NULL); families = g_strsplit (pango_font_description_get_family (description), ",", -1); @@ -1255,6 +1257,7 @@ pango_fc_convert_width_to_pango (int fc_stretch) * @pattern: a #FcPattern * @include_size: if %TRUE, the pattern will include the size from * the @pattern; otherwise the resulting pattern will be unsized. + * (only %FC_SIZE is examined, not %FC_PIXEL_SIZE) * * Creates a #PangoFontDescription that matches the specified * Fontconfig pattern as closely as possible. Many possible Fontconfig diff --git a/pango/pangoft2.c b/pango/pangoft2.c index 268b01dc..d0c35358 100644 --- a/pango/pangoft2.c +++ b/pango/pangoft2.c @@ -100,8 +100,8 @@ load_fallback_face (PangoFT2Font *ft2font, int id; sans = FcPatternBuild (NULL, - FC_FAMILY, FcTypeString, "sans", - FC_SIZE, FcTypeDouble, (double)pango_font_description_get_size (fcfont->description)/PANGO_SCALE, + FC_FAMILY, FcTypeString, "sans", + FC_PIXEL_SIZE, FcTypeDouble, (double)ft2font->size / PANGO_SCALE, NULL); matched = FcFontMatch (NULL, sans, &result); diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c index 66053356..92bf7f64 100644 --- a/pango/pangowin32-fontmap.c +++ b/pango/pangowin32-fontmap.c @@ -449,6 +449,9 @@ pango_win32_font_map_load_font (PangoFontMap *fontmap, GSList *tmp_list = best_match->cached_fonts; gint size = pango_font_description_get_size (description); + if (pango_font_description_get_size_is_absolute (description)) + size = (int) 0.5 + (size * win32fontmap->resolution) / PANGO_SCALE; + PING(("got best match:%s size=%d",best_match->logfont.lfFaceName,size)); while (tmp_list) diff --git a/pango/pangoxft-font.c b/pango/pangoxft-font.c index 0080ba81..632ec433 100644 --- a/pango/pangoxft-font.c +++ b/pango/pangoxft-font.c @@ -128,13 +128,19 @@ _pango_xft_font_get_mini_font (PangoXftFont *xfont) int width = 0, height = 0; XGlyphInfo extents; XftFont *mini_xft; + int new_size; _pango_xft_font_map_get_info (fcfont->fontmap, &display, NULL); pango_font_description_set_family_static (desc, "monospace"); - pango_font_description_set_size (desc, - 0.5 * pango_font_description_get_size (fcfont->description)); + + new_size = pango_font_description_get_size (fcfont->description) / 2; + if (pango_font_description_get_size_is_absolute (fcfont->description)) + pango_font_description_set_absolute_size (desc, new_size); + else + pango_font_description_set_size (desc, new_size); + xfont->mini_font = pango_font_map_load_font (fcfont->fontmap, NULL, desc); pango_font_description_free (desc); @@ -340,12 +346,17 @@ load_fallback_font (PangoXftFont *xfont) Display *display; int screen; XftFont *xft_font; + gboolean size_is_absolute; + double size; _pango_xft_font_map_get_info (fcfont->fontmap, &display, &screen); + + size_is_absolute = pango_font_description_get_size_is_absolute (fcfont->description); + size = (double)pango_font_description_get_size (fcfont->description) / PANGO_SCALE; xft_font = XftFontOpen (display, screen, FC_FAMILY, FcTypeString, "sans", - FC_SIZE, FcTypeDouble, (double)pango_font_description_get_size (fcfont->description)/PANGO_SCALE, + size_is_absolute ? FC_PIXEL_SIZE : FC_SIZE, FcTypeDouble, size, NULL); if (!xft_font) |