summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2000-07-16 19:59:19 +0000
committerTor Lillqvist <tml@src.gnome.org>2000-07-16 19:59:19 +0000
commitca5b24d14066ce35f5b92d117beee0e3605b2f4b (patch)
treedff2e3baad7fe6d7b31d0f9a13b5b84801aa12f5 /pango
parent33c98d1b53adc6708fc20ff2db11a71f93c23a13 (diff)
downloadpango-ca5b24d14066ce35f5b92d117beee0e3605b2f4b.tar.gz
pango/pango-utils.h pango/pango-utils.c pango/pangox-fontmap.c Move the
2000-07-16 Tor Lillqvist <tml@iki.fi> * pango/pango-utils.h * pango/pango-utils.c * pango/pangox-fontmap.c * pango/pangowin32-fontmap.c: Move the get_{style,variant, weight,stretch} functions to pango-utils.c, and rename them to pango_parse_*. Would otherwise be duplicated in pangox and angowin32. * pango/pango.def: Export them. * pango/pango-font.h: Add PANGO_WEIGHT_ULTRALIGHT, PANGO_WEIGHT_LIGHT, PANGO_WEIGHT_EXTRABOLD and PANGO_WEIGHT_HEAVY values to PangoWeight. * pango/pango-utils.c: Recognize the new weight strings. * pango/pangowin32.c (pango_win32_list_subfonts): Don't g_free the subfont_list from the subfonts_by_subrange hash table... * pango/pangowin32-fontmap.c (pango_win32_font_map_read_alias_file): Also set the other properties in the LOGFONT, not only the face name. (pango_win32_insert_font): Insert a pointer to a freshly allocated LOGFONT in the hash table, not the one passed in as a parameter, which could be (and in fact, *is*) a pointer to an auto variable. Quantize the description weight values to exact PANGO_WEIGHT_* values. (pango_win32_get_unknown_glyph): Use subfont 1. * examples/viewer-win32.c: (split_paragraphs): Don't include the newline. (draw): Correct 1st parameter to gdk_win32_hdc_{get,release}.
Diffstat (limited to 'pango')
-rw-r--r--pango/pango-font.h6
-rw-r--r--pango/pango-utils.c231
-rw-r--r--pango/pango-utils.h15
-rw-r--r--pango/pangowin32-fontmap.c397
-rw-r--r--pango/pangowin32-private.h6
-rw-r--r--pango/pangowin32.c16
-rw-r--r--pango/pangox-fontmap.c204
7 files changed, 344 insertions, 531 deletions
diff --git a/pango/pango-font.h b/pango/pango-font.h
index a299a887..3819b815 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -54,8 +54,12 @@ typedef enum {
} PangoVariant;
typedef enum {
+ PANGO_WEIGHT_ULTRALIGHT = 200,
+ PANGO_WEIGHT_LIGHT = 300,
PANGO_WEIGHT_NORMAL = 400,
- PANGO_WEIGHT_BOLD = 700
+ PANGO_WEIGHT_BOLD = 700,
+ PANGO_WEIGHT_ULTRABOLD = 800,
+ PANGO_WEIGHT_HEAVY = 900
} PangoWeight;
typedef enum {
diff --git a/pango/pango-utils.c b/pango/pango-utils.c
index c267a692..f54bd340 100644
--- a/pango/pango-utils.c
+++ b/pango/pango-utils.c
@@ -25,6 +25,7 @@
#include <config.h>
+#include "pango-font.h"
#include "pango-utils.h"
#ifndef HAVE_FLOCKFILE
@@ -651,3 +652,233 @@ pango_get_lib_subdirectory (void)
return LIBDIR "/pango";
#endif
}
+
+gboolean
+pango_parse_style (GString *str,
+ PangoFontDescription *desc)
+{
+ if (str->len == 0)
+ return FALSE;
+
+ switch (str->str[0])
+ {
+ case 'n':
+ case 'N':
+ if (strncasecmp (str->str, "normal", str->len) == 0)
+ {
+ desc->style = PANGO_STYLE_NORMAL;
+ return TRUE;
+ }
+ break;
+ case 'i':
+ if (strncasecmp (str->str, "italic", str->len) == 0)
+ {
+ desc->style = PANGO_STYLE_ITALIC;
+ return TRUE;
+ }
+ break;
+ case 'o':
+ if (strncasecmp (str->str, "oblique", str->len) == 0)
+ {
+ desc->style = PANGO_STYLE_OBLIQUE;
+ return TRUE;
+ }
+ break;
+ }
+ g_warning ("Style must be normal, italic, or oblique");
+
+ return FALSE;
+}
+
+gboolean
+pango_parse_variant (GString *str,
+ PangoFontDescription *desc)
+{
+ if (str->len == 0)
+ return FALSE;
+
+ switch (str->str[0])
+ {
+ case 'n':
+ case 'N':
+ if (strncasecmp (str->str, "normal", str->len) == 0)
+ {
+ desc->variant = PANGO_VARIANT_NORMAL;
+ return TRUE;
+ }
+ break;
+ case 's':
+ case 'S':
+ if (strncasecmp (str->str, "small_caps", str->len) == 0)
+ {
+ desc->variant = PANGO_VARIANT_SMALL_CAPS;
+ return TRUE;
+ }
+ break;
+ }
+
+ g_warning ("Variant must be normal, or small_caps");
+ return FALSE;
+}
+
+gboolean
+pango_parse_weight (GString *str,
+ PangoFontDescription *desc)
+{
+ if (str->len == 0)
+ return FALSE;
+
+ switch (str->str[0])
+ {
+ case 'b':
+ case 'B':
+ if (strncasecmp (str->str, "bold", str->len) == 0)
+ {
+ desc->weight = PANGO_WEIGHT_BOLD;
+ return TRUE;
+ }
+ break;
+ case 'h':
+ case 'H':
+ if (strncasecmp (str->str, "heavy", str->len) == 0)
+ {
+ desc->weight = PANGO_WEIGHT_HEAVY;
+ return TRUE;
+ }
+ break;
+ case 'l':
+ case 'L':
+ if (strncasecmp (str->str, "light", str->len) == 0)
+ {
+ desc->weight = PANGO_WEIGHT_LIGHT;
+ return TRUE;
+ }
+ break;
+ case 'n':
+ case 'N':
+ if (strncasecmp (str->str, "normal", str->len) == 0)
+ {
+ desc->weight = PANGO_WEIGHT_NORMAL;
+ return TRUE;
+ }
+ break;
+ case 'u':
+ case 'U':
+ if (strncasecmp (str->str, "ultralight", str->len) == 0)
+ {
+ desc->weight = PANGO_WEIGHT_ULTRALIGHT;
+ return TRUE;
+ }
+ else if (strncasecmp (str->str, "ultrabold", str->len) == 0)
+ {
+ desc->weight = PANGO_WEIGHT_ULTRABOLD;
+ return TRUE;
+ }
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ {
+ char *numstr, *end;
+
+ numstr = g_strndup (str->str, str->len);
+
+ desc->weight = strtol (numstr, &end, 0);
+ if (*end != '\0')
+ {
+ g_warning ("Cannot parse numerical weight '%s'", numstr);
+ g_free (numstr);
+ return FALSE;
+ }
+
+ g_free (numstr);
+ return TRUE;
+ }
+ }
+
+ g_warning ("Weight must be ultralight, light, normal, bold, ultrabold, heavy, or an integer");
+ return FALSE;
+}
+
+gboolean
+pango_parse_stretch (GString *str,
+ PangoFontDescription *desc)
+{
+ if (str->len == 0)
+ return FALSE;
+
+ switch (str->str[0])
+ {
+ case 'c':
+ case 'C':
+ if (strncasecmp (str->str, "condensed", str->len) == 0)
+ {
+ desc->stretch = PANGO_STRETCH_CONDENSED;
+ return TRUE;
+ }
+ break;
+ case 'e':
+ case 'E':
+ if (strncasecmp (str->str, "extra_condensed", str->len) == 0)
+ {
+ desc->stretch = PANGO_STRETCH_EXTRA_CONDENSED;
+ return TRUE;
+ }
+ if (strncasecmp (str->str, "extra_expanded", str->len) == 0)
+ {
+ desc->stretch = PANGO_STRETCH_EXTRA_EXPANDED;
+ return TRUE;
+ }
+ if (strncasecmp (str->str, "expanded", str->len) == 0)
+ {
+ desc->stretch = PANGO_STRETCH_EXPANDED;
+ return TRUE;
+ }
+ break;
+ case 'n':
+ case 'N':
+ if (strncasecmp (str->str, "normal", str->len) == 0)
+ {
+ desc->stretch = PANGO_STRETCH_NORMAL;
+ return TRUE;
+ }
+ break;
+ case 's':
+ case 'S':
+ if (strncasecmp (str->str, "semi_condensed", str->len) == 0)
+ {
+ desc->stretch = PANGO_STRETCH_SEMI_CONDENSED;
+ return TRUE;
+ }
+ if (strncasecmp (str->str, "semi_expanded", str->len) == 0)
+ {
+ desc->stretch = PANGO_STRETCH_SEMI_EXPANDED;
+ return TRUE;
+ }
+ break;
+ case 'u':
+ case 'U':
+ if (strncasecmp (str->str, "ultra_condensed", str->len) == 0)
+ {
+ desc->stretch = PANGO_STRETCH_ULTRA_CONDENSED;
+ return TRUE;
+ }
+ if (strncasecmp (str->str, "ultra_expanded", str->len) == 0)
+ {
+ desc->variant = PANGO_STRETCH_ULTRA_EXPANDED;
+ return TRUE;
+ }
+ break;
+ }
+
+ g_warning ("Stretch must be ultra_condensed, extra_condensed, condensed, semi_condensed, normal, semi_expanded, expanded, extra_expanded, or ultra_expanded");
+ return FALSE;
+}
+
diff --git a/pango/pango-utils.h b/pango/pango-utils.h
index 1c8dfcaa..941ad515 100644
--- a/pango/pango-utils.h
+++ b/pango/pango-utils.h
@@ -38,6 +38,20 @@ gboolean pango_scan_int (const char **pos,
char * pango_config_key_get (const char *key);
+/* Functions for parsing textual representations
+ * of PangoFontDescription fields. They return TRUE if the input string
+ * contains a valid value, which then has been assigned to the corresponding
+ * field in the PangoFontDescription.
+ */
+gboolean pango_parse_style (GString *str,
+ PangoFontDescription *desc);
+gboolean pango_parse_variant (GString *str,
+ PangoFontDescription *desc);
+gboolean pango_parse_weight (GString *str,
+ PangoFontDescription *desc);
+gboolean pango_parse_stretch (GString *str,
+ PangoFontDescription *desc);
+
/* On Unix, return the name of the "pango" subdirectory of SYSCONFDIR
* (which is set at compile time). On Win32, return the Pango
* installation directory (which is set at installation time, and
@@ -51,3 +65,4 @@ char * pango_get_sysconf_subdirectory (void);
* g_free'd either.
*/
char * pango_get_lib_subdirectory (void);
+
diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c
index 67d4129d..a7b6cde4 100644
--- a/pango/pangowin32-fontmap.c
+++ b/pango/pangowin32-fontmap.c
@@ -204,9 +204,9 @@ static PangoWin32FontMap *fontmap = NULL;
static int CALLBACK
pango_win32_inner_enum_proc (LOGFONT *lfp,
- TEXTMETRIC *metrics,
- DWORD fontType,
- LPARAM lParam)
+ TEXTMETRIC *metrics,
+ DWORD fontType,
+ LPARAM lParam)
{
pango_win32_insert_font (fontmap, lfp);
@@ -235,7 +235,6 @@ PangoFontMap *
pango_win32_font_map_for_display (void)
{
LOGFONT logfont;
- int screen;
/* Make sure that the type system is initialized */
g_type_init();
@@ -498,300 +497,6 @@ pango_win32_font_map_load_font (PangoFontMap *fontmap,
return result;
}
-/* Similar to GNU libc's getline, but buffer is g_malloc'd */
-static size_t
-pango_getline (char **lineptr, size_t *n, FILE *stream)
-{
-#define EXPAND_CHUNK 16
-
- int n_read = 0;
- int result = -1;
-
- g_return_val_if_fail (lineptr != NULL, -1);
- g_return_val_if_fail (n != NULL, -1);
- g_return_val_if_fail (*lineptr != NULL || *n == 0, -1);
-
-#ifdef HAVE_FLOCKFILE
- flockfile (stream);
-#endif
-
- while (1)
- {
- int c;
-
-#ifdef HAVE_FLOCKFILE
- c = getc_unlocked (stream);
-#else
- c = getc (stream);
-#endif
-
- if (c == EOF)
- {
- if (n_read > 0)
- {
- result = n_read;
- (*lineptr)[n_read] = '\0';
- }
- break;
- }
-
- if (n_read + 2 >= *n)
- {
- *n += EXPAND_CHUNK;
- *lineptr = g_realloc (*lineptr, *n);
- }
-
- (*lineptr)[n_read] = c;
- n_read++;
-
- if (c == '\n' || c == '\r')
- {
- result = n_read;
- (*lineptr)[n_read] = '\0';
- break;
- }
- }
-
-#ifdef HAVE_FLOCKFILE
- funlockfile (stream);
-#endif
-
- return n_read - 1;
-}
-
-static int
-find_tok (char **start, char **tok)
-{
- char *p = *start;
-
- while (*p && (*p == ' ' || *p == '\t'))
- p++;
-
- if (*p == 0 || *p == '\n' || *p == '\r')
- return -1;
-
- if (*p == '"')
- {
- p++;
- *tok = p;
-
- while (*p && *p != '"')
- p++;
-
- if (*p != '"')
- return -1;
-
- *start = p + 1;
- return p - *tok;
- }
- else
- {
- *tok = p;
-
- while (*p && *p != ' ' && *p != '\t' && *p != '\r' && *p != '\n')
- p++;
-
- *start = p;
- return p - *tok;
- }
-}
-
-static gboolean
-get_style (GString *str, PangoFontDescription *desc)
-{
- if (str->len == 0)
- return FALSE;
-
- switch (str->str[0])
- {
- case 'n':
- case 'N':
- if (strncasecmp (str->str, "normal", str->len) == 0)
- {
- desc->style = PANGO_STYLE_NORMAL;
- return TRUE;
- }
- break;
- case 'i':
- if (strncasecmp (str->str, "italic", str->len) == 0)
- {
- desc->style = PANGO_STYLE_ITALIC;
- return TRUE;
- }
- break;
- case 'o':
- if (strncasecmp (str->str, "oblique", str->len) == 0)
- {
- desc->style = PANGO_STYLE_OBLIQUE;
- return TRUE;
- }
- break;
- }
- g_warning ("Style must be normal, italic, or oblique");
-
- return FALSE;
-}
-
-static gboolean
-get_variant (GString *str, PangoFontDescription *desc)
-{
- if (str->len == 0)
- return FALSE;
-
- switch (str->str[0])
- {
- case 'n':
- case 'N':
- if (strncasecmp (str->str, "normal", str->len) == 0)
- {
- desc->variant = PANGO_VARIANT_NORMAL;
- return TRUE;
- }
- break;
- case 's':
- case 'S':
- if (strncasecmp (str->str, "small_caps", str->len) == 0)
- {
- desc->variant = PANGO_VARIANT_SMALL_CAPS;
- return TRUE;
- }
- break;
- }
-
- g_warning ("Variant must be normal, or small_caps");
- return FALSE;
-}
-
-static gboolean
-get_weight (GString *str, PangoFontDescription *desc)
-{
- if (str->len == 0)
- return FALSE;
-
- switch (str->str[0])
- {
- case 'n':
- case 'N':
- if (strncasecmp (str->str, "normal", str->len) == 0)
- {
- desc->weight = PANGO_WEIGHT_NORMAL;
- return TRUE;
- }
- break;
- case 'b':
- case 'B':
- if (strncasecmp (str->str, "bold", str->len) == 0)
- {
- desc->weight = PANGO_WEIGHT_BOLD;
- return TRUE;
- }
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- char *numstr, *end;
-
- numstr = g_strndup (str->str, str->len);
-
- desc->weight = strtol (numstr, &end, 0);
- if (*end != '\0')
- {
- g_warning ("Cannot parse numerical weight '%s'", numstr);
- g_free (numstr);
- return FALSE;
- }
-
- g_free (numstr);
- return TRUE;
- }
- }
-
- g_warning ("Weight must be normal, bold, or an integer");
- return FALSE;
-}
-
-static gboolean
-get_stretch (GString *str, PangoFontDescription *desc)
-{
- if (str->len == 0)
- return FALSE;
-
- switch (str->str[0])
- {
- case 'c':
- case 'C':
- if (strncasecmp (str->str, "condensed", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_CONDENSED;
- return TRUE;
- }
- break;
- case 'e':
- case 'E':
- if (strncasecmp (str->str, "extra_condensed", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_EXTRA_CONDENSED;
- return TRUE;
- }
- if (strncasecmp (str->str, "extra_expanded", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_EXTRA_EXPANDED;
- return TRUE;
- }
- if (strncasecmp (str->str, "expanded", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_EXPANDED;
- return TRUE;
- }
- break;
- case 'n':
- case 'N':
- if (strncasecmp (str->str, "normal", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_NORMAL;
- return TRUE;
- }
- break;
- case 's':
- case 'S':
- if (strncasecmp (str->str, "semi_condensed", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_SEMI_CONDENSED;
- return TRUE;
- }
- if (strncasecmp (str->str, "semi_expanded", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_SEMI_EXPANDED;
- return TRUE;
- }
- break;
- case 'u':
- case 'U':
- if (strncasecmp (str->str, "ultra_condensed", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_ULTRA_CONDENSED;
- return TRUE;
- }
- if (strncasecmp (str->str, "ultra_expanded", str->len) == 0)
- {
- desc->variant = PANGO_STRETCH_ULTRA_EXPANDED;
- return TRUE;
- }
- break;
- }
-
- g_warning ("Stretch must be ultra_condensed, extra_condensed, condensed, semi_condensed, normal, semi_expanded, expanded, extra_expanded, or ultra_expanded");
- return FALSE;
-}
-
static gboolean
pango_win32_guess_subranges (UINT charset,
FONTSIGNATURE *fsp)
@@ -1286,25 +991,25 @@ pango_win32_font_map_read_alias_file (PangoWin32FontMap *win32fontmap,
if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_style (tmp_buf, &font_entry->description))
+ if (!pango_parse_style (tmp_buf, &font_entry->description))
goto error;
if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_variant (tmp_buf, &font_entry->description))
+ if (!pango_parse_variant (tmp_buf, &font_entry->description))
goto error;
if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_weight (tmp_buf, &font_entry->description))
+ if (!pango_parse_weight (tmp_buf, &font_entry->description))
goto error;
if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_stretch (tmp_buf, &font_entry->description))
+ if (!pango_parse_stretch (tmp_buf, &font_entry->description))
goto error;
if (!pango_scan_string (&p, tmp_buf))
@@ -1326,6 +1031,37 @@ pango_win32_font_map_read_alias_file (PangoWin32FontMap *win32fontmap,
for (i=0; i<nfaces; i++)
{
strcpy (font_entry->lfp[i].lfFaceName, faces[i]);
+
+ /* Set LOGFONT properties based on the PangoFontDescription */
+ if (font_entry->description.style == PANGO_STYLE_OBLIQUE ||
+ font_entry->description.style == PANGO_STYLE_ITALIC)
+ font_entry->lfp[i].lfItalic = TRUE;
+
+ /* Quantize weight */
+ if (font_entry->description.weight <=
+ (PANGO_WEIGHT_ULTRALIGHT + PANGO_WEIGHT_LIGHT) / 2)
+ font_entry->lfp[i].lfWeight = FW_ULTRALIGHT;
+ else if (font_entry->description.weight <=
+ (PANGO_WEIGHT_LIGHT + PANGO_WEIGHT_NORMAL) / 2)
+ font_entry->lfp[i].lfWeight = FW_LIGHT;
+ else if (font_entry->description.weight <=
+ (PANGO_WEIGHT_NORMAL + PANGO_WEIGHT_BOLD) / 2)
+ font_entry->lfp[i].lfWeight = FW_NORMAL;
+ else if (font_entry->description.weight <=
+ (PANGO_WEIGHT_BOLD + PANGO_WEIGHT_ULTRABOLD) / 2)
+ font_entry->lfp[i].lfWeight = FW_BOLD;
+ else if (font_entry->description.weight <=
+ (PANGO_WEIGHT_ULTRABOLD + PANGO_WEIGHT_HEAVY) / 2)
+ font_entry->lfp[i].lfWeight = FW_ULTRABOLD;
+ else
+ font_entry->lfp[i].lfWeight = FW_HEAVY;
+
+ /* Stretch ? */
+
+ /* Charset is ignored anyway when used with the widechar
+ * API?
+ */
+ font_entry->lfp[i].lfCharSet = DEFAULT_CHARSET;
}
g_strfreev (faces);
@@ -1418,33 +1154,33 @@ pango_win32_insert_font (PangoWin32FontMap *win32fontmap,
PangoWin32SizeInfo *size_info;
int i;
+ PING(("lfp.face=%s,wt=%d,ht=%d",lfp->lfFaceName,lfp->lfWeight,lfp->lfHeight));
description.size = 0;
/* First insert the LOGFONT into the list of LOGFONTs for the typeface name
*/
+ lfp2 = g_new (LOGFONT, 1);
+ *lfp2 = *lfp;
+ g_strdown (lfp2->lfFaceName);
size_info = g_hash_table_lookup (win32fontmap->size_infos, lfp);
if (!size_info)
{
+ PING(("SizeInfo not found"));
size_info = g_new (PangoWin32SizeInfo, 1);
- pango_win32_setup_signature (win32fontmap, lfp, &size_info->signature);
+ pango_win32_setup_signature (win32fontmap, lfp2,
+ &size_info->signature);
size_info->logfonts = NULL;
- g_hash_table_insert (win32fontmap->size_infos, lfp, size_info);
+ g_hash_table_insert (win32fontmap->size_infos, lfp2, size_info);
}
- lfp2 = g_new (LOGFONT, 1);
- *lfp2 = *lfp;
size_info->logfonts = g_slist_prepend (size_info->logfonts, lfp2);
/* Convert the LOGFONT into a PangoFontDescription */
- description.family_name = g_strdup (lfp->lfFaceName);
- g_strdown (description.family_name);
+ description.family_name = g_strdup (lfp2->lfFaceName);
- if (!description.family_name[0])
- return;
-
- if (!lfp->lfItalic)
+ if (!lfp2->lfItalic)
description.style = PANGO_STYLE_NORMAL;
else
description.style = PANGO_STYLE_ITALIC;
@@ -1452,12 +1188,23 @@ pango_win32_insert_font (PangoWin32FontMap *win32fontmap,
description.variant = PANGO_VARIANT_NORMAL;
/* The PangoWeight values PANGO_WEIGHT_* map exactly do Windows FW_* values.
- * Is this on purpose?
+ * Is this on purpose? Quantize the weight to exact PANGO_WEIGHT_*
+ * values. Is this a good idea?
*/
- if (lfp->lfWeight == FW_DONTCARE)
+ if (lfp2->lfWeight == FW_DONTCARE)
+ description.weight = PANGO_WEIGHT_NORMAL;
+ else if (lfp2->lfWeight <= (FW_ULTRALIGHT + FW_LIGHT) / 2)
+ description.weight = PANGO_WEIGHT_ULTRALIGHT;
+ else if (lfp2->lfWeight <= (FW_LIGHT + FW_NORMAL) / 2)
+ description.weight = PANGO_WEIGHT_LIGHT;
+ else if (lfp2->lfWeight <= (FW_NORMAL + FW_BOLD) / 2)
description.weight = PANGO_WEIGHT_NORMAL;
+ else if (lfp2->lfWeight <= (FW_BOLD + FW_ULTRABOLD) / 2)
+ description.weight = PANGO_WEIGHT_BOLD;
+ else if (lfp2->lfWeight <= (FW_ULTRABOLD + FW_HEAVY) / 2)
+ description.weight = PANGO_WEIGHT_ULTRABOLD;
else
- description.weight = lfp->lfWeight;
+ description.weight = PANGO_WEIGHT_HEAVY;
/* XXX No idea how to figure out the stretch */
description.stretch = PANGO_STRETCH_NORMAL;
@@ -1512,21 +1259,25 @@ pango_win32_logfont_has_subrange (PangoFontMap *fontmap,
PangoWin32FontMap *win32fontmap;
PangoWin32SizeInfo *size_info;
+ PING(("lfp.face=%s,wt=%d,ht=%d,subr:%d",lfp->lfFaceName,lfp->lfWeight,lfp->lfHeight,subrange));
win32fontmap = PANGO_WIN32_FONT_MAP (fontmap);
size_info = g_hash_table_lookup (win32fontmap->size_infos, lfp);
if (!size_info)
- return FALSE;
+ {
+ PING(("SizeInfo not found"));
+ return FALSE;
+ }
- return size_info->signature.fsUsb[subrange/32] & (1 << subrange % 32);
+ return ((size_info->signature.fsUsb[subrange/32] & (1 << subrange % 32)) != 0);
}
/* Given a LOGFONT and size, make a matching LOGFONT corresponding to
* an installed font.
*/
LOGFONT *
-pango_win32_make_matching_logfont (PangoFontMap *fontmap,
- LOGFONT *lfp,
- int size)
+pango_win32_make_matching_logfont (PangoFontMap *fontmap,
+ LOGFONT *lfp,
+ int size)
{
PangoWin32FontMap *win32fontmap;
GSList *tmp_list;
@@ -1535,12 +1286,16 @@ pango_win32_make_matching_logfont (PangoFontMap *fontmap,
LOGFONT *result = NULL;
gint match_distance = 0;
+ PING(("lfp.face=%s,wt=%d,ht=%d,size:%d",lfp->lfFaceName,lfp->lfWeight,lfp->lfHeight,size));
win32fontmap = PANGO_WIN32_FONT_MAP (fontmap);
size_info = g_hash_table_lookup (win32fontmap->size_infos, lfp);
if (!size_info)
- return NULL;
+ {
+ PING(("SizeInfo not found"));
+ return NULL;
+ }
tmp_list = size_info->logfonts;
while (tmp_list)
diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h
index 9d748798..78d459a3 100644
--- a/pango/pangowin32-private.h
+++ b/pango/pangowin32-private.h
@@ -22,6 +22,12 @@
#ifndef __PANGOWIN32_PRIVATE_H__
#define __PANGOWIN32_PRIVATE_H__
+/* Just for debugging, will be removed */
+#define PING(printlist) \
+(g_print ("%s:%d ", __PRETTY_FUNCTION__, __LINE__), \
+ g_print printlist, \
+ g_print ("\n"))
+
#include "pango-modules.h"
#include "pangowin32.h"
diff --git a/pango/pangowin32.c b/pango/pangowin32.c
index 38937184..2147fef2 100644
--- a/pango/pangowin32.c
+++ b/pango/pangowin32.c
@@ -260,7 +260,7 @@ pango_win32_font_new (PangoFontMap *fontmap,
result->fontmap = fontmap;
g_object_ref (G_OBJECT (fontmap));
- result -> n_fonts = n_fonts;
+ result->n_fonts = n_fonts;
result->fonts = g_new (LOGFONT, n_fonts);
memcpy (result->fonts, lfp, sizeof (LOGFONT) * n_fonts);
result->size = size;
@@ -320,7 +320,7 @@ pango_win32_render (HDC hdc,
g_return_if_fail (glyphs != NULL);
- for (i=0; i<glyphs->num_glyphs; i++)
+ for (i = 0; i <glyphs->num_glyphs; i++)
{
if (glyphs->glyphs[i].glyph)
{
@@ -874,7 +874,7 @@ pango_win32_list_subfonts (PangoFont *font,
PangoWin32Subfont *subfont_list;
PangoFontMap *fontmap;
int i, j;
- int n_subfonts = 0;
+ int n_subfonts;
g_return_val_if_fail (font != NULL, 0);
@@ -906,6 +906,7 @@ pango_win32_list_subfonts (PangoFont *font,
g_hash_table_insert (win32font->subfonts_by_subrange, (gpointer) subrange, subfont_list);
}
+ n_subfonts = 0;
for (i = 0; i < win32font->n_fonts; i++)
if (subfont_list[i])
n_subfonts++;
@@ -913,16 +914,13 @@ pango_win32_list_subfonts (PangoFont *font,
*subfont_ids = g_new (PangoWin32Subfont, n_subfonts);
n_subfonts = 0;
-
- for (i=0; i<win32font->n_fonts; i++)
+ for (i = 0; i < win32font->n_fonts; i++)
if (subfont_list[i])
{
(*subfont_ids)[n_subfonts] = subfont_list[i];
n_subfonts++;
}
- g_free (subfont_list);
-
return n_subfonts;
}
@@ -1096,7 +1094,7 @@ pango_win32_font_finalize (GObject *object)
PangoWin32FontCache *cache = pango_win32_font_map_get_font_cache (win32font->fontmap);
int i;
- for (i=0; i<win32font->n_subfonts; i++)
+ for (i = 0; i < win32font->n_subfonts; i++)
{
PangoWin32SubfontInfo *info = win32font->subfonts[i];
@@ -1219,7 +1217,7 @@ pango_win32_find_glyph (PangoFont *font,
PangoGlyph
pango_win32_get_unknown_glyph (PangoFont *font)
{
- return PANGO_WIN32_MAKE_GLYPH (0, 0); /* XXX */
+ return PANGO_WIN32_MAKE_GLYPH (1, 0); /* XXX */
}
/**
diff --git a/pango/pangox-fontmap.c b/pango/pangox-fontmap.c
index 6b0c90bb..007e3ad1 100644
--- a/pango/pangox-fontmap.c
+++ b/pango/pangox-fontmap.c
@@ -547,202 +547,6 @@ pango_x_font_map_load_font (PangoFontMap *fontmap,
return result;
}
-static gboolean
-get_style (GString *str, PangoFontDescription *desc)
-{
- if (str->len == 0)
- return FALSE;
-
- switch (str->str[0])
- {
- case 'n':
- case 'N':
- if (strncasecmp (str->str, "normal", str->len) == 0)
- {
- desc->style = PANGO_STYLE_NORMAL;
- return TRUE;
- }
- break;
- case 'i':
- if (strncasecmp (str->str, "italic", str->len) == 0)
- {
- desc->style = PANGO_STYLE_ITALIC;
- return TRUE;
- }
- break;
- case 'o':
- if (strncasecmp (str->str, "oblique", str->len) == 0)
- {
- desc->style = PANGO_STYLE_OBLIQUE;
- return TRUE;
- }
- break;
- }
- g_warning ("Style must be normal, italic, or oblique");
-
- return FALSE;
-}
-
-static gboolean
-get_variant (GString *str, PangoFontDescription *desc)
-{
- if (str->len == 0)
- return FALSE;
-
- switch (str->str[0])
- {
- case 'n':
- case 'N':
- if (strncasecmp (str->str, "normal", str->len) == 0)
- {
- desc->variant = PANGO_VARIANT_NORMAL;
- return TRUE;
- }
- break;
- case 's':
- case 'S':
- if (strncasecmp (str->str, "small_caps", str->len) == 0)
- {
- desc->variant = PANGO_VARIANT_SMALL_CAPS;
- return TRUE;
- }
- break;
- }
-
- g_warning ("Variant must be normal, or small_caps");
- return FALSE;
-}
-
-static gboolean
-get_weight (GString *str, PangoFontDescription *desc)
-{
- if (str->len == 0)
- return FALSE;
-
- switch (str->str[0])
- {
- case 'n':
- case 'N':
- if (strncasecmp (str->str, "normal", str->len) == 0)
- {
- desc->weight = PANGO_WEIGHT_NORMAL;
- return TRUE;
- }
- break;
- case 'b':
- case 'B':
- if (strncasecmp (str->str, "bold", str->len) == 0)
- {
- desc->weight = PANGO_WEIGHT_BOLD;
- return TRUE;
- }
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- char *numstr, *end;
-
- numstr = g_strndup (str->str, str->len);
-
- desc->weight = strtol (numstr, &end, 0);
- if (*end != '\0')
- {
- g_warning ("Cannot parse numerical weight '%s'", numstr);
- g_free (numstr);
- return FALSE;
- }
-
- g_free (numstr);
- return TRUE;
- }
- }
-
- g_warning ("Weight must be normal, bold, or an integer");
- return FALSE;
-}
-
-static gboolean
-get_stretch (GString *str, PangoFontDescription *desc)
-{
- if (str->len == 0)
- return FALSE;
-
- switch (str->str[0])
- {
- case 'c':
- case 'C':
- if (strncasecmp (str->str, "condensed", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_CONDENSED;
- return TRUE;
- }
- break;
- case 'e':
- case 'E':
- if (strncasecmp (str->str, "extra_condensed", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_EXTRA_CONDENSED;
- return TRUE;
- }
- if (strncasecmp (str->str, "extra_expanded", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_EXTRA_EXPANDED;
- return TRUE;
- }
- if (strncasecmp (str->str, "expanded", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_EXPANDED;
- return TRUE;
- }
- break;
- case 'n':
- case 'N':
- if (strncasecmp (str->str, "normal", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_NORMAL;
- return TRUE;
- }
- break;
- case 's':
- case 'S':
- if (strncasecmp (str->str, "semi_condensed", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_SEMI_CONDENSED;
- return TRUE;
- }
- if (strncasecmp (str->str, "semi_expanded", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_SEMI_EXPANDED;
- return TRUE;
- }
- break;
- case 'u':
- case 'U':
- if (strncasecmp (str->str, "ultra_condensed", str->len) == 0)
- {
- desc->stretch = PANGO_STRETCH_ULTRA_CONDENSED;
- return TRUE;
- }
- if (strncasecmp (str->str, "ultra_expanded", str->len) == 0)
- {
- desc->variant = PANGO_STRETCH_ULTRA_EXPANDED;
- return TRUE;
- }
- break;
- }
-
- g_warning ("Stretch must be ultra_condensed, extra_condensed, condensed, semi_condensed, normal, semi_expanded, expanded, extra_expanded, or ultra_expanded");
- return FALSE;
-}
-
static void
pango_x_font_map_read_alias_file (PangoXFontMap *xfontmap,
const char *filename)
@@ -781,25 +585,25 @@ pango_x_font_map_read_alias_file (PangoXFontMap *xfontmap,
if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_style (tmp_buf, &font_entry->description))
+ if (!pango_parse_style (tmp_buf, &font_entry->description))
goto error;
if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_variant (tmp_buf, &font_entry->description))
+ if (!pango_parse_variant (tmp_buf, &font_entry->description))
goto error;
if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_weight (tmp_buf, &font_entry->description))
+ if (!pango_parse_weight (tmp_buf, &font_entry->description))
goto error;
if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_stretch (tmp_buf, &font_entry->description))
+ if (!pango_parse_stretch (tmp_buf, &font_entry->description))
goto error;
if (!pango_scan_string (&p, tmp_buf))