summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-03-07 02:02:15 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-03-07 02:02:15 +0000
commitdd0b4a5064c6f60adcfd2ea02e2d61fb60254d20 (patch)
tree39a121f4bd40300bcd67521104db86c12bd33165 /pango
parent6278d373c1a564ae4233a2e4b6d428a9f6202728 (diff)
downloadpango-dd0b4a5064c6f60adcfd2ea02e2d61fb60254d20.tar.gz
Convert log_clusters[] use from char offsets to byte offset - should make
Mon Mar 6 20:55:32 2000 Owen Taylor <otaylor@redhat.com> * libpango/mapping.c example/viewer.c: * modules/hangul/hangul.c modules/basic/basic.c modules/tamil/tamil.c: Convert log_clusters[] use from char offsets to byte offset - should make it easier to have all interface deal with stuff in byte offsets. * libpango/mapping.c libpango/pango-glyph.h: Rename x_to_cp and cp_to_x to make them "member functions" of glyph_string. * libpango/pango-types.h: Add a rectangle type for use in storing glyph/glyph-string extents, plus macros for extracting ascent/descent. * libpango/fonts.c libpango/pango-font.h libpango/pangox.c: Virtualize glyph extents function into the font. * libpango/pangox.c modules/*/*.c examples/viewer.c: Convert over to new rationalized unit system - everything in 1000ths of a point or 1000ths of a glyph unit. * libpango/pango-glyph.h libpango/glyphstring.c: Add function to get extents of a glyph string. (We may want to fastpath the width in the future, since getting the width seems to be a very common and time-critical operation)
Diffstat (limited to 'pango')
-rw-r--r--pango/fonts.c29
-rw-r--r--pango/glyphstring.c97
-rw-r--r--pango/mapping.c171
-rw-r--r--pango/pango-attributes.c4
-rw-r--r--pango/pango-font.h22
-rw-r--r--pango/pango-glyph.h44
-rw-r--r--pango/pango-layout.h58
-rw-r--r--pango/pango-types.h23
-rw-r--r--pango/pangox.c208
9 files changed, 385 insertions, 271 deletions
diff --git a/pango/fonts.c b/pango/fonts.c
index c6e4cbd8..9ff5d7d6 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -495,9 +495,36 @@ pango_font_find_shaper (PangoFont *font,
return font->klass->find_shaper (font, lang, ch);
}
-
/**
+ * pango_font_get_glyph_extents:
+ * @font: a #PangoFont
+ * @glyph: the glyph index
+ * @ink_rect: rectangle used to store the extents of the glyph as drawn
+ * or %NULL to indicate that the result is not needed.
+ * @logical_rect: rectangle used to store the logical extents of the glyph
+ * or %NULL to indicate that the result is not needed.
+ *
+ * Get the logical and ink extents of a glyph within a font. The
+ * coordinate system for each rectangle has its origin at the
+ * base line and horizontal origin of the character with increasing
+ * coordinates extending to the right and down. The macros PANGO_ASCENT(),
+ * PANGO_DESCENT(), PANGO_LBEARING(), and PANGO_RBEARING can be used to convert
+ * from the extents rectangle to more traditional font metrics. The units
+ * of the rectangles are in 1000ths of a device unit.
+ **/
+void
+pango_font_get_glyph_extents (PangoFont *font,
+ PangoGlyph glyph,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect)
+{
+ g_return_if_fail (font != NULL);
+
+ font->klass->get_glyph_extents (font, glyph, ink_rect, logical_rect);
+}
+
+/**
* pango_font_map_init:
* @fontmap: a #PangoFontMap
*
diff --git a/pango/glyphstring.c b/pango/glyphstring.c
index a7cc9cea..b29efe09 100644
--- a/pango/glyphstring.c
+++ b/pango/glyphstring.c
@@ -20,7 +20,8 @@
*/
#include <glib.h>
-#include <pango.h>
+#include <pango-glyph.h>
+#include <pango-font.h>
/**
* pango_glyph_string_new:
@@ -83,3 +84,97 @@ pango_glyph_string_free (PangoGlyphString *string)
g_free (string->log_clusters);
g_free (string);
}
+
+/**
+ * pango_glyph_string_extents:
+ * @glyphs: a #PangoGlyphString
+ * @font: a #PangoFont
+ * @ink_rect: rectangle used to store the extents of the glyph string as drawn
+ * or %NULL to indicate that the result is not needed.
+ * @logical_rect: rectangle used to store the logical extents of the glyph string
+ * or %NULL to indicate that the result is not needed.
+ *
+ * Compute the logical and ink extents of a glyph string. See the documentation
+ * for pango_font_get_glyph_extents() for details about the interpretation
+ * of the rectangles.
+ */
+void
+pango_glyph_string_extents (PangoGlyphString *glyphs,
+ PangoFont *font,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect)
+{
+ int x_pos = 0;
+ int i;
+
+ if (glyphs->num_glyphs == 0)
+ {
+ if (ink_rect)
+ {
+ ink_rect->x = 0;
+ ink_rect->y = 0;
+ ink_rect->width = 0;
+ ink_rect->height = 0;
+ }
+
+ if (logical_rect)
+ {
+ logical_rect->x = 0;
+ logical_rect->y = 0;
+ logical_rect->width = 0;
+ logical_rect->height = 0;
+ }
+
+ return;
+ }
+
+ for (i=0; i<glyphs->num_glyphs; i++)
+ {
+ PangoRectangle glyph_ink;
+ PangoRectangle glyph_logical;
+
+ PangoGlyphGeometry *geometry = &glyphs->glyphs[i].geometry;
+
+ if (i == 0)
+ {
+ pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, ink_rect, logical_rect);
+ }
+ else
+ {
+ int new_pos;
+
+ pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph,
+ ink_rect ? &glyph_ink : NULL,
+ logical_rect ? &glyph_logical : NULL);
+
+ if (ink_rect)
+ {
+ new_pos = MIN (ink_rect->x, x_pos + glyph_ink.x + geometry->x_offset);
+ ink_rect->width = MAX (ink_rect->x + ink_rect->width,
+ x_pos + glyph_ink.x + glyph_ink.width + geometry->x_offset) - ink_rect->x;
+ ink_rect->x = new_pos;
+
+ new_pos = MIN (ink_rect->y, glyph_ink.y + geometry->y_offset);
+ ink_rect->height = MAX (ink_rect->y + ink_rect->height,
+ glyph_ink.y + glyph_ink.height + geometry->y_offset) - ink_rect->y;
+ ink_rect->y = new_pos;
+ }
+
+ if (logical_rect)
+ {
+ new_pos = MIN (logical_rect->x, x_pos + glyph_logical.x + geometry->x_offset);
+ logical_rect->width = MAX (logical_rect->x + logical_rect->width,
+ x_pos + glyph_logical.x + glyph_logical.width + geometry->x_offset) - logical_rect->x;
+ logical_rect->x = new_pos;
+
+ new_pos = MIN (logical_rect->y, glyph_logical.y + geometry->y_offset);
+ logical_rect->height = MAX (logical_rect->y + logical_rect->height,
+ glyph_logical.y + glyph_logical.height + geometry->y_offset) - logical_rect->y;
+ logical_rect->y = new_pos;
+ }
+ }
+
+ x_pos += geometry->width;
+ }
+}
+
diff --git a/pango/mapping.c b/pango/mapping.c
index 470b2085..d075b9f8 100644
--- a/pango/mapping.c
+++ b/pango/mapping.c
@@ -32,12 +32,12 @@
#include <unicode.h>
/**
- * pango_cp_to_x:
+ * pango_glyph_string_index_to_x:
+ * @glyphs: the glyphs return from pango_shape()
* @text: the text for the run
* @length: the number of bytes (not characters) in @text.
* @analysis: the analysis information return from pango_itemize()
- * @glyphs: the glyphs return from pango_shape()
- * @char_pos: the character position
+ * @index: the byte index within @text
* @trailing: whether we should compute the result for the beginning
* or end of the character (or cluster - the decision
* for which may be script dependent).
@@ -48,22 +48,27 @@
*/
void
-pango_cp_to_x (gchar *text,
- gint length,
- PangoAnalysis *analysis,
- PangoGlyphString *glyphs,
- gint char_pos,
- gboolean trailing,
- gint *x_pos)
+pango_glyph_string_index_to_x (PangoGlyphString *glyphs,
+ char *text,
+ int length,
+ PangoAnalysis *analysis,
+ int index,
+ gboolean trailing,
+ int *x_pos)
{
- gint i;
- gint start_xpos = 0;
- gint end_xpos = 0;
- gint width = 0;
+ int i;
+ int start_xpos = 0;
+ int end_xpos = 0;
+ int width = 0;
+
+ int start_index = -1;
+ int end_index = -1;
- gint start_char = -1;
- gint end_char = -1;
+ int cluster_chars = 0;
+ int cluster_offset = 0;
+ char *p;
+
g_return_if_fail (glyphs != NULL);
g_return_if_fail (length >= 0);
g_return_if_fail (length == 0 || text != NULL);
@@ -87,16 +92,16 @@ pango_cp_to_x (gchar *text,
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
{
- if (glyphs->log_clusters[i] > char_pos)
+ if (glyphs->log_clusters[i] > index)
{
- end_char = glyphs->log_clusters[i];
+ end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
- if (start_char == -1 || glyphs->log_clusters[i] != start_char)
+ if (glyphs->log_clusters[i] != start_index)
{
- start_char = glyphs->log_clusters[i];
+ start_index = glyphs->log_clusters[i];
start_xpos = width;
}
@@ -107,16 +112,16 @@ pango_cp_to_x (gchar *text,
{
for (i = 0; i < glyphs->num_glyphs; i++)
{
- if (glyphs->log_clusters[i] > char_pos)
+ if (glyphs->log_clusters[i] > index)
{
- end_char = glyphs->log_clusters[i];
+ end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
- if (start_char == -1 || glyphs->log_clusters[i] != start_char)
+ if (glyphs->log_clusters[i] != start_index)
{
- start_char = glyphs->log_clusters[i];
+ start_index = glyphs->log_clusters[i];
start_xpos = width;
}
@@ -124,36 +129,43 @@ pango_cp_to_x (gchar *text,
}
}
- /* We need the character index of one past the end of the
- * string, and so we have to recalculate the entire length
- * of the string...
- */
- if (end_char == -1)
+ if (end_index == -1)
{
- end_char = unicode_strlen (text, length);
+ end_index = length;
end_xpos = (analysis->level % 2) ? 0 : width;
}
+ /* Calculate offset of character within cluster */
+
+ p = text + start_index;
+ while (p < text + end_index)
+ {
+ p = unicode_next_utf8 (p);
+ if (p < text + index)
+ cluster_offset++;
+ cluster_chars++;
+ }
+
/* Now interpolate the result. For South Asian languages
* we actually shouldn't iterpolate
*/
if (trailing)
- char_pos += 1;
+ cluster_offset += 1;
- *x_pos = (((double)(end_char - char_pos)) * start_xpos +
- ((double)(char_pos - start_char)) * end_xpos) /
- (end_char - start_char);
+ *x_pos = (((double)(cluster_chars - cluster_offset)) * start_xpos +
+ ((double)cluster_offset) * end_xpos) /
+ cluster_chars;
}
/**
- * pango_x_to_cp:
+ * pango_glyph_string_x_to_index:
+ * @glyphs: the glyphs return from pango_shape()
* @text: the text for the run
* @length: the number of bytes (not characters) in text.
* @analysis: the analysis information return from pango_itemize()
- * @glyphs: the glyphs return from pango_shape()
- * @x_pos: location to store the returned x character position
- * @char_pos: location to store calculated character position.
+ * @x_pos: the x offset (in thousands of a device unit)
+ * @index: location to store calculated byte index within @text
* @trailing: location to store a integer indicating where
* in the cluster the user clicked. If the script
* allows positioning within the cluster, it is either
@@ -161,25 +173,27 @@ pango_cp_to_x (gchar *text,
* of characters in the cluster. In either case
* 0 represents the trailing edge of the cluster.
*
- * Converts from x position to x character. (X position
- * is measured from the left edge of the run)
+ * Convert from x offset to position.
*/
void
-pango_x_to_cp (gchar *text,
- gint length,
- PangoAnalysis *analysis,
- PangoGlyphString *glyphs,
- gint x_pos,
- gint *char_pos,
- gint *trailing)
+pango_glyph_string_x_to_index (PangoGlyphString *glyphs,
+ char *text,
+ int length,
+ PangoAnalysis *analysis,
+ int x_pos,
+ int *index,
+ int *trailing)
{
- gint i;
- gint start_xpos = 0;
- gint end_xpos = 0;
- gint width = 0;
+ int i;
+ int start_xpos = 0;
+ int end_xpos = 0;
+ int width = 0;
+
+ int start_index = -1;
+ int end_index = -1;
- gint start_char = -1;
- gint end_char = -1;
+ int cluster_chars = 0;
+ char *p;
gboolean found = FALSE;
@@ -194,17 +208,17 @@ pango_x_to_cp (gchar *text,
for (i = glyphs->num_glyphs - 1; i >= 0; i--)
{
- if (start_char == -1 || glyphs->log_clusters[i] != start_char)
+ if (glyphs->log_clusters[i] != start_index)
{
if (found)
{
- end_char = glyphs->log_clusters[i];
+ end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
else
{
- start_char = glyphs->log_clusters[i];
+ start_index = glyphs->log_clusters[i];
start_xpos = width;
}
}
@@ -219,17 +233,17 @@ pango_x_to_cp (gchar *text,
{
for (i = 0; i < glyphs->num_glyphs; i++)
{
- if (start_char == -1 || glyphs->log_clusters[i] != start_char)
+ if (glyphs->log_clusters[i] != start_index)
{
if (found)
{
- end_char = glyphs->log_clusters[i];
+ end_index = glyphs->log_clusters[i];
end_xpos = width;
break;
}
else
{
- start_char = glyphs->log_clusters[i];
+ start_index = glyphs->log_clusters[i];
start_xpos = width;
}
}
@@ -241,31 +255,44 @@ pango_x_to_cp (gchar *text,
}
}
- /* We need the character index of one past the end of the
- * string, and so we have to recalculate the entire length
- * of the string...
- */
- if (end_char == -1)
+ if (end_index == -1)
{
- end_char = unicode_strlen (text, length);
+ end_index = length;
end_xpos = (analysis->level % 2) ? 0 : width;
}
+ /* Calculate number of chars within cluster */
+ p = text + start_index;
+ while (p < text + end_index)
+ {
+ p = unicode_next_utf8 (p);
+ cluster_chars++;
+ }
+
if (start_xpos == end_xpos)
{
- if (char_pos)
- *char_pos = start_char;
+ if (index)
+ *index = start_index;
if (trailing)
trailing = 0;
}
else
{
- double cp = (((double)(end_xpos - x_pos)) * start_char +
- ((double)(x_pos - start_xpos)) * end_char) /
- (end_xpos - start_xpos);
+ double cp = ((double)(x_pos - start_xpos) * cluster_chars) / (end_xpos - start_xpos);
- if (char_pos)
- *char_pos = (int)cp;
+ if (index)
+ {
+ char *p = text + start_index;
+ int i = 0;
+
+ while (i + 1 < cp)
+ {
+ p = unicode_next_utf8 (p);
+ i++;
+ }
+
+ *index = (p - text);
+ }
if (trailing)
*trailing = (cp - (int)cp) > 0.5 ? 1 : 0;
}
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index e75a56f7..4929dc8a 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -513,7 +513,7 @@ pango_attr_list_new (void)
* pango_attr_list_ref:
* @list: a #PangoAttrList
*
- * Increase the reference count on the given attribute list by one.
+ * Increase the reference count of the given attribute list by one.
**/
void
pango_attr_list_ref (PangoAttrList *list)
@@ -527,7 +527,7 @@ pango_attr_list_ref (PangoAttrList *list)
* pango_attr_list_unref:
* @list: a #PangoAttrList
*
- * Decrease the reference count on the given attribute list by one.
+ * Decrease the reference count of the given attribute list by one.
* If the result is zero, free the attribute list and the attributes
* it contains.
**/
diff --git a/pango/pango-font.h b/pango/pango-font.h
index bae83660..1a5d6fd7 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -98,13 +98,17 @@ struct _PangoFont
struct _PangoFontClass
{
- void (*destroy) (PangoFont *font);
- PangoFontDescription *(*describe) (PangoFont *font);
- PangoCoverage * (*get_coverage) (PangoFont *font,
- const char *lang);
- PangoEngineShape * (*find_shaper) (PangoFont *font,
- const char *lang,
- guint32 ch);
+ void (*destroy) (PangoFont *font);
+ PangoFontDescription *(*describe) (PangoFont *font);
+ PangoCoverage * (*get_coverage) (PangoFont *font,
+ const char *lang);
+ PangoEngineShape * (*find_shaper) (PangoFont *font,
+ const char *lang,
+ guint32 ch);
+ void (*get_glyph_extents) (PangoFont *font,
+ PangoGlyph glyph,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect);
};
void pango_font_init (PangoFont *font);
@@ -123,6 +127,10 @@ PangoCoverage * pango_font_get_coverage (PangoFont *font,
PangoEngineShape * pango_font_find_shaper (PangoFont *font,
const char *lang,
guint32 ch);
+void pango_font_get_glyph_extents (PangoFont *font,
+ PangoGlyph glyph,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect);
/*
* Font Map
diff --git a/pango/pango-glyph.h b/pango/pango-glyph.h
index b19cc782..cd9b84f9 100644
--- a/pango/pango-glyph.h
+++ b/pango/pango-glyph.h
@@ -22,6 +22,8 @@
#ifndef __PANGO_GLYPH_H__
#define __PANGO_GLYPH_H__
+#include <pango-types.h>
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -31,12 +33,8 @@ typedef struct _PangoGlyphVisAttr PangoGlyphVisAttr;
typedef struct _PangoGlyphInfo PangoGlyphInfo;
typedef struct _PangoGlyphString PangoGlyphString;
-/* 64'ths of a point - 1/4608 in, 5.51 * 10^-5 in. */
-typedef guint32 PangoGlyphUnit;
-
-/* A index of a glyph into a font. Rendering system dependent
- */
-typedef guint32 PangoGlyph;
+/* 1000ths of a device unit */
+typedef gint32 PangoGlyphUnit;
/* Positioning information about a glyph
*/
@@ -85,21 +83,25 @@ PangoGlyphString *pango_glyph_string_new (void);
void pango_glyph_string_set_size (PangoGlyphString *string,
gint new_len);
void pango_glyph_string_free (PangoGlyphString *string);
-
-void pango_cp_to_x (gchar *text,
- gint length,
- PangoAnalysis *analysis,
- PangoGlyphString *glyphs,
- gint char_pos,
- gboolean trailing,
- gint *x_pos);
-void pango_x_to_cp (gchar *text,
- gint length,
- PangoAnalysis *analysis,
- PangoGlyphString *glyphs,
- gint x_pos,
- gint *char_pos,
- gint *trailing);
+void pango_glyph_string_extents (PangoGlyphString *glyphs,
+ PangoFont *font,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect);
+
+void pango_glyph_string_index_to_x (PangoGlyphString *glyphs,
+ char *text,
+ int length,
+ PangoAnalysis *analysis,
+ int index,
+ gboolean trailing,
+ int *x_pos);
+void pango_glyph_string_x_to_index (PangoGlyphString *glyphs,
+ char *text,
+ int length,
+ PangoAnalysis *analysis,
+ int x_pos,
+ int *index,
+ int *trailing);
void pango_justify (PangoGlyphString *glyphs,
gint new_line_width,
diff --git a/pango/pango-layout.h b/pango/pango-layout.h
index cdbde021..b9c1ea6f 100644
--- a/pango/pango-layout.h
+++ b/pango/pango-layout.h
@@ -26,15 +26,55 @@
extern "C" {
#endif /* __cplusplus */
-typedef struct _PangoLayout PangoLayout;
-
- /*
- pango_layout_new (char *text, int length);
- pango_layout_get_glyph_strings ();
- pango_layout_cp_to_xy ();
- pango_layout_xy_to_cp ();
- pango_layout_justify ();
- */
+typedef struct _PangoLayout PangoLayout;
+typedef struct _PangoLayoutLine PangoLayoutLine;
+typedef struct _PangoLayoutRun PangoLayoutRun;
+
+struct _PangoLayoutLine
+{
+ PangoLayout *layout;
+ gint n_chars; /* length of line in characters */
+ gint length; /* length of line in bytes*/
+ GSList *runs;
+};
+
+struct _PangoLayoutRun
+{
+ PangoItem *item;
+ PangoGlyphString *glyphs;
+};
+
+PangoLayout * pango_layout_new (void);
+void pango_layout_ref (PangoLayout *layout);
+void pango_layout_unref (PangoLayout *layout);
+void pango_layout_set_width (PangoLayout *layout,
+ int width);
+void pango_layout_set_justify (PangoLayout *layout,
+ gboolean justify);
+void pango_layout_set_first_line_width (PangoLayout *layout,
+ int width);
+void pango_layout_set_attributes (PangoLayout *layout,
+ PangoAttrList *attrs);
+void pango_layout_set_text (char *text,
+ int length);
+int pango_layout_get_line_count (PangoLayout *layout);
+PangoLayoutLine *pango_layout_get_line (PangoLayout *layout,
+ int line);
+void pango_layout_cp_to_line_x (PangoLayout *layout,
+ gint char_pos,
+ gboolean trailing,
+ gint *line,
+ gint *x_pos);
+
+void pango_layout_line_ref (PangoLayoutLine *line);
+void pango_layout_line_unref (PangoLayoutLine *line);
+void pango_layout_line_x_to_cp (PangoLayoutLine *line,
+ gint x_pos,
+ gint *char_pos,
+ gint *trailing);
+void pango_layout_line_get_extents (PangoLayoutLine *line,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect);
#ifdef __cplusplus
}
diff --git a/pango/pango-types.h b/pango/pango-types.h
index 33ef0195..9d31603c 100644
--- a/pango/pango-types.h
+++ b/pango/pango-types.h
@@ -39,6 +39,29 @@ typedef struct _PangoEngineLang PangoEngineLang;
typedef struct _PangoEngineShape PangoEngineShape;
typedef struct _PangoFont PangoFont;
+typedef struct _PangoRectangle PangoRectangle;
+
+/* A index of a glyph into a font. Rendering system dependent
+ */
+typedef guint32 PangoGlyph;
+
+/* A rectangle. Used to store logical and physical extents of glyphs,
+ * runs, strings, etc.
+ */
+struct _PangoRectangle
+{
+ int x;
+ int y;
+ int width;
+ int height;
+};
+
+/* Macros to translate from extents rectangles to ascent/descent/lbearing/rbearing
+ */
+#define PANGO_ASCENT(rect) (-(rect).y)
+#define PANGO_DESCENT(rect) ((rect).y + (rect).height)
+#define PANGO_LBEARING(rect) ((rect).x)
+#define PANGO_RBEARING(rect) ((rect).x + (rect).width)
/* Information about a segment of text with a consistent
* shaping/language engine and bidirectional level
diff --git a/pango/pangox.c b/pango/pangox.c
index 203ea5d2..f6a7d142 100644
--- a/pango/pangox.c
+++ b/pango/pangox.c
@@ -174,13 +174,17 @@ static void pango_x_font_map_list_families (PangoFontMap *
int *n_families);
static void pango_x_font_map_read_aliases (PangoXFontMap *xfontmap);
-static void pango_x_font_destroy (PangoFont *font);
-static PangoFontDescription *pango_x_font_describe (PangoFont *font);
-static PangoCoverage * pango_x_font_get_coverage (PangoFont *font,
- const char *lang);
-static PangoEngineShape * pango_x_font_find_shaper (PangoFont *font,
- const char *lang,
- guint32 ch);
+static void pango_x_font_destroy (PangoFont *font);
+static PangoFontDescription *pango_x_font_describe (PangoFont *font);
+static PangoCoverage * pango_x_font_get_coverage (PangoFont *font,
+ const char *lang);
+static PangoEngineShape * pango_x_font_find_shaper (PangoFont *font,
+ const char *lang,
+ guint32 ch);
+static void pango_x_font_get_glyph_extents (PangoFont *font,
+ PangoGlyph glyph,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect);
static PangoXSubfontInfo * pango_x_find_subfont (PangoFont *font,
PangoXSubfont subfont_index);
@@ -214,7 +218,8 @@ PangoFontClass pango_x_font_class = {
pango_x_font_destroy,
pango_x_font_describe,
pango_x_font_get_coverage,
- pango_x_font_find_shaper
+ pango_x_font_find_shaper,
+ pango_x_font_get_glyph_extents
};
PangoFontMapClass pango_x_font_map_class = {
@@ -1300,8 +1305,8 @@ pango_x_load_font_with_size (Display *display,
* @gc: the graphics context
* @font: the font in which to draw the string
* @glyphs: the glyph string to draw
- * @x: the x position of start of string
- * @y: the y position of baseline
+ * @x: the x position of start of string (in pixels)
+ * @y: the y position of baseline (in pixels)
*
* Render a PangoGlyphString onto an X drawable
*/
@@ -1321,6 +1326,7 @@ pango_x_render (Display *display,
Font old_fid = None;
XFontStruct *fs;
int i;
+ int x_off = 0;
g_return_if_fail (display != NULL);
g_return_if_fail (glyphs != NULL);
@@ -1350,172 +1356,58 @@ pango_x_render (Display *display,
}
XDrawString16 (display, d, gc,
- x + glyphs->glyphs[i].geometry.x_offset / 72,
- y + glyphs->glyphs[i].geometry.y_offset / 72,
+ x + (x_off + glyphs->glyphs[i].geometry.x_offset) / 1000,
+ y + glyphs->glyphs[i].geometry.y_offset / 1000,
&c, 1);
}
- x += glyphs->glyphs[i].geometry.width / 72;
+ x_off += glyphs->glyphs[i].geometry.width;
}
}
-/**
- * pango_x_glyph_extents:
- * @font: a #PangoFont
- * @glyph: the glyph to measure
- * @lbearing: left bearing of glyph (result)
- * @rbearing: right bearing of glyph (result)
- * @width: width of glyph (result)
- * @ascent: ascent of glyph (result)
- * @descent: descent of glyph (result)
- * @logical_ascent: The vertical distance from the baseline to the
- * bottom of the line above.
- * @logical_descent: The vertical distance from the baseline to the
- * top of the line below.
- *
- * Compute the measurements of a single glyph in pixels.
- */
-void
-pango_x_glyph_extents (PangoFont *font,
- PangoGlyph glyph,
- int *lbearing,
- int *rbearing,
- int *width,
- int *ascent,
- int *descent,
- int *logical_ascent,
- int *logical_descent)
+static void
+pango_x_font_get_glyph_extents (PangoFont *font,
+ PangoGlyph glyph,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect)
{
XCharStruct *cs;
PangoXSubfontInfo *subfont;
if (pango_x_find_glyph (font, glyph, &subfont, &cs))
{
- if (lbearing)
- *lbearing = cs->lbearing;
- if (rbearing)
- *rbearing = cs->rbearing;
- if (width)
- *width = cs->width;
- if (ascent)
- *ascent = cs->ascent;
- if (descent)
- *descent = cs->descent;
- if (logical_ascent)
- *logical_ascent = subfont->font_struct->ascent;
- if (logical_descent)
- *logical_descent = subfont->font_struct->descent;
+ if (ink_rect)
+ {
+ ink_rect->x = 1000 * cs->lbearing;
+ ink_rect->width = 1000 * (cs->rbearing - cs->lbearing);
+ ink_rect->y = 1000 * -cs->ascent;
+ ink_rect->height = cs->ascent + cs->descent;
+ }
+ if (logical_rect)
+ {
+ logical_rect->x = 0;
+ logical_rect->width = 1000 * cs->width;
+ logical_rect->y = - 1000 * subfont->font_struct->ascent;
+ logical_rect->height = 1000 * (subfont->font_struct->ascent + subfont->font_struct->descent);
+ }
}
else
{
- if (lbearing)
- *lbearing = 0;
- if (rbearing)
- *rbearing = 0;
- if (width)
- *width = 0;
- if (ascent)
- *ascent = 0;
- if (descent)
- *descent = 0;
- if (logical_ascent)
- *logical_ascent = 0;
- if (logical_descent)
- *logical_descent = 0;
- }
-}
-
-/**
- * pango_x_extents:
- * @font: a #PangoFont
- * @glyphs: the glyph string to measure
- * @lbearing: left bearing of string (result)
- * @rbearing: right bearing of string (result)
- * @width: width of string (result)
- * @ascent: ascent of string (result)
- * @descent: descent of string (result)
- * @logical_ascent: The vertical distance from the baseline to the
- * bottom of the line above.
- * @logical_descent: The vertical distance from the baseline to the
- * top of the line below.
- *
- * Compute the measurements of a glyph string in pixels.
- * The number of parameters here is clunky - it might be
- * nicer to use structures as in XmbTextExtents.
- */
-void
-pango_x_extents (PangoFont *font,
- PangoGlyphString *glyphs,
- int *lbearing,
- int *rbearing,
- int *width,
- int *ascent,
- int *descent,
- int *logical_ascent,
- int *logical_descent)
-{
- PangoXSubfontInfo *subfont;
- XCharStruct *cs;
-
- int i;
-
- int t_lbearing = 0;
- int t_rbearing = 0;
- int t_ascent = 0;
- int t_descent = 0;
- int t_logical_ascent = 0;
- int t_logical_descent = 0;
- int t_width = 0;
-
- g_return_if_fail (font != NULL);
- g_return_if_fail (glyphs != NULL);
-
- for (i=0; i<glyphs->num_glyphs; i++)
- {
- PangoGlyphGeometry *geometry = &glyphs->glyphs[i].geometry;
-
- if (pango_x_find_glyph (font, glyphs->glyphs[i].glyph, &subfont, &cs))
+ if (ink_rect)
{
- if (i == 0)
- {
- t_lbearing = cs->lbearing - geometry->x_offset / 72;
- t_rbearing = cs->rbearing + geometry->x_offset / 72;
- t_ascent = cs->ascent + geometry->y_offset / 72;
- t_descent = cs->descent - geometry->y_offset / 72;
-
- t_logical_ascent = subfont->font_struct->ascent + geometry->y_offset / 72;
- t_logical_descent = subfont->font_struct->descent - geometry->y_offset / 72;
- }
- else
- {
- t_lbearing = MAX (t_lbearing,
- cs->lbearing - geometry->x_offset / 72 - t_width);
- t_rbearing = MAX (t_rbearing,
- t_width + cs->rbearing + geometry->x_offset / 72);
- t_ascent = MAX (t_ascent, cs->ascent + geometry->y_offset / 72);
- t_descent = MAX (t_descent, cs->descent - geometry->y_offset / 72);
- t_logical_ascent = MAX (t_logical_ascent, subfont->font_struct->ascent + geometry->y_offset / 72);
- t_logical_descent = MAX (t_logical_descent, subfont->font_struct->descent - geometry->y_offset / 72);
- }
+ ink_rect->x = 0;
+ ink_rect->width = 0;
+ ink_rect->y = 0;
+ ink_rect->height = 0;
+ }
+ if (logical_rect)
+ {
+ logical_rect->x = 0;
+ logical_rect->width = 0;
+ logical_rect->y = 0;
+ logical_rect->height = 0;
}
-
- t_width += geometry->width / 72;
}
-
- if (lbearing)
- *lbearing = t_lbearing;
- if (rbearing)
- *rbearing = t_rbearing;
- if (width)
- *width = t_width;
- if (ascent)
- *ascent = t_ascent;
- if (descent)
- *descent = t_descent;
- if (logical_ascent)
- *logical_ascent = t_logical_ascent;
- if (logical_descent)
- *logical_descent = t_logical_descent;
}
/* Compare the tail of a to b */