fix the dpi stuff with pango by reading the right ascent and descent stuff
This commit is contained in:
parent
69a4abe1d0
commit
8f9aae0cc2
5 changed files with 35 additions and 17 deletions
|
@ -21,6 +21,7 @@
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "mask.h"
|
#include "mask.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
#include "geom.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
|
|
||||||
#include <X11/Xft/Xft.h>
|
#include <X11/Xft/Xft.h>
|
||||||
|
@ -42,6 +43,9 @@ FcObjectType objs[] = {
|
||||||
{ OB_SHADOW_ALPHA, FcTypeInteger }
|
{ OB_SHADOW_ALPHA, FcTypeInteger }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PangoFontMap *pfm;
|
||||||
|
PangoContext *context;
|
||||||
|
|
||||||
static gboolean started = FALSE;
|
static gboolean started = FALSE;
|
||||||
|
|
||||||
static void font_startup(void)
|
static void font_startup(void)
|
||||||
|
@ -53,6 +57,9 @@ static void font_startup(void)
|
||||||
|
|
||||||
#ifdef USE_PANGO
|
#ifdef USE_PANGO
|
||||||
g_type_init();
|
g_type_init();
|
||||||
|
/* these will never be freed, but we will need them until we shut down anyway */
|
||||||
|
pfm = pango_xft_get_font_map(RrDisplay(NULL), RrScreen(NULL));
|
||||||
|
context = pango_xft_get_context(RrDisplay(NULL), RrScreen(NULL));
|
||||||
#endif /* USE_PANGO */
|
#endif /* USE_PANGO */
|
||||||
/* Here we are teaching xft about the shadow, shadowoffset & shadowtint */
|
/* Here we are teaching xft about the shadow, shadowoffset & shadowtint */
|
||||||
FcNameRegisterObjectTypes(objs, (sizeof(objs) / sizeof(objs[0])));
|
FcNameRegisterObjectTypes(objs, (sizeof(objs) / sizeof(objs[0])));
|
||||||
|
@ -119,6 +126,9 @@ static RrFont *openfont(const RrInstance *inst, gchar *fontstring)
|
||||||
/* TODO: is PANGO_SCALE correct ?? */
|
/* TODO: is PANGO_SCALE correct ?? */
|
||||||
pango_font_description_set_size(out->pango_font_description, tmp_int*PANGO_SCALE);
|
pango_font_description_set_size(out->pango_font_description, tmp_int*PANGO_SCALE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PangoFontset *pfs = pango_font_map_load_fontset(pfm, context, out->pango_font_description, NULL);
|
||||||
|
out->pango_font_metrics = pango_fontset_get_metrics(pfs);
|
||||||
#endif /* USE_PANGO */
|
#endif /* USE_PANGO */
|
||||||
|
|
||||||
if (FcPatternGetBool(match, OB_SHADOW, 0, &out->shadow) != FcResultMatch)
|
if (FcPatternGetBool(match, OB_SHADOW, 0, &out->shadow) != FcResultMatch)
|
||||||
|
@ -177,16 +187,18 @@ void RrFontClose(RrFont *f)
|
||||||
XftFontClose(RrDisplay(f->inst), f->xftfont);
|
XftFontClose(RrDisplay(f->inst), f->xftfont);
|
||||||
g_free(f);
|
g_free(f);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_PANGO
|
||||||
|
pango_font_metrics_unref(f->pango_font_metrics);
|
||||||
|
pango_font_description_free(f->pango_font_description);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void font_measure_full(const RrFont *f, const gchar *str,
|
static void font_measure_full(const RrFont *f, const gchar *str,
|
||||||
gint *x, gint *y)
|
gint *x, gint *y)
|
||||||
{
|
{
|
||||||
#ifdef USE_PANGO
|
#ifdef USE_PANGO
|
||||||
PangoContext *context;
|
|
||||||
PangoLayout *pl;
|
PangoLayout *pl;
|
||||||
PangoRectangle rect;
|
PangoRectangle rect;
|
||||||
context = pango_xft_get_context (RrDisplay(f->inst), RrScreen(f->inst));
|
|
||||||
pl = pango_layout_new (context);
|
pl = pango_layout_new (context);
|
||||||
pango_layout_set_text(pl, str, -1);
|
pango_layout_set_text(pl, str, -1);
|
||||||
pango_layout_set_font_description(pl, f->pango_font_description);
|
pango_layout_set_font_description(pl, f->pango_font_description);
|
||||||
|
@ -195,7 +207,6 @@ static void font_measure_full(const RrFont *f, const gchar *str,
|
||||||
*x = rect.width + (f->shadow ? ABS(f->offset) : 0);
|
*x = rect.width + (f->shadow ? ABS(f->offset) : 0);
|
||||||
*y = rect.height + (f->shadow ? ABS(f->offset) : 0);
|
*y = rect.height + (f->shadow ? ABS(f->offset) : 0);
|
||||||
g_object_unref(pl);
|
g_object_unref(pl);
|
||||||
g_object_unref(context);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
XGlyphInfo info;
|
XGlyphInfo info;
|
||||||
|
@ -208,17 +219,25 @@ static void font_measure_full(const RrFont *f, const gchar *str,
|
||||||
#endif /* USE_PANGO */
|
#endif /* USE_PANGO */
|
||||||
}
|
}
|
||||||
|
|
||||||
gint RrFontMeasureString(const RrFont *f, const gchar *str)
|
RrSize *RrFontMeasureString(const RrFont *f, const gchar *str)
|
||||||
{
|
{
|
||||||
gint x, y;
|
RrSize *size;
|
||||||
font_measure_full (f, str, &x, &y);
|
size = g_new(RrSize, 1);
|
||||||
return x + 4;
|
font_measure_full (f, str, &size->width, &size->height);
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint RrFontHeight(const RrFont *f)
|
gint RrFontHeight(const RrFont *f)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_PANGO
|
||||||
|
int ascent, descent;
|
||||||
|
ascent = pango_font_metrics_get_ascent(f->pango_font_metrics);
|
||||||
|
descent = pango_font_metrics_get_descent(f->pango_font_metrics);
|
||||||
|
return (ascent + descent) / PANGO_SCALE;
|
||||||
|
#else
|
||||||
return f->xftfont->ascent + f->xftfont->descent +
|
return f->xftfont->ascent + f->xftfont->descent +
|
||||||
(f->shadow ? f->offset : 0);
|
(f->shadow ? f->offset : 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
gint RrFontMaxCharWidth(const RrFont *f)
|
gint RrFontMaxCharWidth(const RrFont *f)
|
||||||
|
@ -237,10 +256,8 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
|
||||||
gboolean shortened = FALSE;
|
gboolean shortened = FALSE;
|
||||||
#else
|
#else
|
||||||
PangoLayout *pl;
|
PangoLayout *pl;
|
||||||
PangoContext *context;
|
|
||||||
PangoRectangle rect;
|
PangoRectangle rect;
|
||||||
|
|
||||||
context = pango_xft_get_context (RrDisplay(t->font->inst), RrScreen(t->font->inst));
|
|
||||||
pl = pango_layout_new (context);
|
pl = pango_layout_new (context);
|
||||||
#endif /* USE_PANGO */
|
#endif /* USE_PANGO */
|
||||||
|
|
||||||
|
@ -338,7 +355,6 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
|
||||||
#else /* USE_PANGO */
|
#else /* USE_PANGO */
|
||||||
pango_xft_render_layout(d, &c, pl, x * PANGO_SCALE, y * PANGO_SCALE);
|
pango_xft_render_layout(d, &c, pl, x * PANGO_SCALE, y * PANGO_SCALE);
|
||||||
g_object_unref(pl);
|
g_object_unref(pl);
|
||||||
g_object_unref(context);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_string_free(text, TRUE);
|
g_string_free(text, TRUE);
|
||||||
|
|
|
@ -29,6 +29,7 @@ struct _RrFont {
|
||||||
const RrInstance *inst;
|
const RrInstance *inst;
|
||||||
#ifdef USE_PANGO
|
#ifdef USE_PANGO
|
||||||
PangoFontDescription *pango_font_description;
|
PangoFontDescription *pango_font_description;
|
||||||
|
PangoFontMetrics *pango_font_metrics;
|
||||||
#endif /* USE_PANGO */
|
#endif /* USE_PANGO */
|
||||||
XftFont *xftfont;
|
XftFont *xftfont;
|
||||||
gint elipses_length;
|
gint elipses_length;
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
See the COPYING file for a copy of the GNU General Public License.
|
See the COPYING file for a copy of the GNU General Public License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __geom_h
|
#ifndef __render_geom_h
|
||||||
#define __geom_h
|
#define __render_geom_h
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int width;
|
int width;
|
||||||
|
|
|
@ -311,7 +311,7 @@ void RrMargins (RrAppearance *a, gint *l, gint *t, gint *r, gint *b)
|
||||||
void RrMinsize(RrAppearance *a, gint *w, gint *h)
|
void RrMinsize(RrAppearance *a, gint *w, gint *h)
|
||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
gint m;
|
RrSize *m;
|
||||||
gint l, t, r, b;
|
gint l, t, r, b;
|
||||||
*w = *h = 0;
|
*w = *h = 0;
|
||||||
|
|
||||||
|
@ -326,9 +326,9 @@ void RrMinsize(RrAppearance *a, gint *w, gint *h)
|
||||||
case RR_TEXTURE_TEXT:
|
case RR_TEXTURE_TEXT:
|
||||||
m = RrFontMeasureString(a->texture[i].data.text.font,
|
m = RrFontMeasureString(a->texture[i].data.text.font,
|
||||||
a->texture[i].data.text.string);
|
a->texture[i].data.text.string);
|
||||||
*w = MAX(*w, m);
|
*w = MAX(*w, m->width + 4);
|
||||||
m = RrFontHeight(a->texture[i].data.text.font);
|
m->height = RrFontHeight(a->texture[i].data.text.font);
|
||||||
*h += MAX(*h, m);
|
*h += MAX(*h, m->height);
|
||||||
break;
|
break;
|
||||||
case RR_TEXTURE_RGBA:
|
case RR_TEXTURE_RGBA:
|
||||||
*w += MAX(*w, a->texture[i].data.rgba.width);
|
*w += MAX(*w, a->texture[i].data.rgba.width);
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#ifndef __render_h
|
#ifndef __render_h
|
||||||
#define __render_h
|
#define __render_h
|
||||||
|
|
||||||
|
#include "geom.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
#include <X11/Xlib.h> /* some platforms dont include this as needed for Xft */
|
#include <X11/Xlib.h> /* some platforms dont include this as needed for Xft */
|
||||||
|
@ -202,7 +203,7 @@ RrAppearance *RrAppearanceNew (const RrInstance *inst, gint numtex);
|
||||||
RrAppearance *RrAppearanceCopy (RrAppearance *a);
|
RrAppearance *RrAppearanceCopy (RrAppearance *a);
|
||||||
void RrAppearanceFree (RrAppearance *a);
|
void RrAppearanceFree (RrAppearance *a);
|
||||||
|
|
||||||
gint RrFontMeasureString (const RrFont *f, const gchar *str);
|
RrSize *RrFontMeasureString (const RrFont *f, const gchar *str);
|
||||||
gint RrFontHeight (const RrFont *f);
|
gint RrFontHeight (const RrFont *f);
|
||||||
gint RrFontMaxCharWidth (const RrFont *f);
|
gint RrFontMaxCharWidth (const RrFont *f);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue