📄 pango-utils.c
字号:
if (keys_error) { g_warning ("error getting keys in group '%s' of config file '%s'\n", filename, group); g_error_free(keys_error); } } g_strfreev(groups); g_key_file_free(key_file);}static voidread_config (void){ if (!config_hash) { char *filename; const char *home; const char *envvar; config_hash = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); filename = g_build_filename (pango_get_sysconf_subdirectory (), "pangorc", NULL); read_config_file (filename, FALSE); g_free (filename); home = g_get_home_dir (); if (home && *home) { filename = g_build_filename (home, ".pangorc", NULL); read_config_file (filename, FALSE); g_free (filename); } envvar = g_getenv ("PANGO_RC_FILE"); if (envvar) read_config_file (envvar, TRUE); }}/** * pango_config_key_get: * @key: Key to look up, in the form "SECTION/KEY". * * Looks up a key in the Pango config database * (pseudo-win.ini style, read from $sysconfdir/pango/pangorc, * ~/.pangorc, and getenv (PANGO_RC_FILE).) * * Return value: the value, if found, otherwise %NULL. The value is a * newly-allocated string and must be freed with g_free(). **/char *pango_config_key_get (const char *key){ g_return_val_if_fail (key != NULL, NULL); read_config (); return g_strdup (g_hash_table_lookup (config_hash, key));}#ifdef G_OS_WIN32/* DllMain function needed to tuck away the DLL name */G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)#endif/** * pango_get_sysconf_subdirectory: * * On Unix, returns the name of the "pango" subdirectory of SYSCONFDIR * (which is set at compile time). On Win32, returns a subdirectory of * the Pango installation directory (which is deduced at run time from * the DLL's location, or stored in the Registry). * * Return value: the Pango sysconf directory. The returned string should * not be freed. */G_CONST_RETURN char *pango_get_sysconf_subdirectory (void){#ifdef G_OS_WIN32 static gchar *result = NULL; if (result == NULL) result = g_win32_get_package_installation_subdirectory (PACKAGE " " VERSION, dll_name, "etc\\pango"); return result;#else return SYSCONFDIR "/pango";#endif}/** * pango_get_lib_subdirectory: * * On Unix, returns the name of the "pango" subdirectory of LIBDIR * (which is set at compile time). On Win32, returns the Pango * installation directory (which is deduced at run time from the DLL's * location, or stored in the Registry). The returned string should * not be freed. * * Return value: the Pango lib directory. The returned string should * not be freed. */G_CONST_RETURN char *pango_get_lib_subdirectory (void){#ifdef G_OS_WIN32 static gchar *result = NULL; if (result == NULL) result = g_win32_get_package_installation_subdirectory (PACKAGE " " VERSION, dll_name, "lib\\pango"); return result;#else return LIBDIR "/pango";#endif}/** * pango_parse_enum: * @type: enum type to parse, eg. %PANGO_TYPE_ELLIPSIZE_MODE. * @str: string to parse. May be %NULL. * @value: integer to store the result in, or %NULL. * @warn: if %TRUE, issue a g_warning() on bad input. * @possible_values: place to store list of possible values on failure, or %NULL. * * Parses an enum type and stored the result in @value. * * If @str does not match the nick name of any of the possible values for the * enum, %FALSE is returned, a warning is issued if @warn is %TRUE, and a * string representing the list of possible values is stored in * @possible_values. The list is slash-separated, eg. * "none/start/middle/end". If failed and @possible_values is not %NULL, * returned string should be freed using g_free(). * * Return value: %TRUE if @str was successfully parsed. * * Since: 1.16 **/gbooleanpango_parse_enum (GType type, const char *str, int *value, gboolean warn, char **possible_values){ GEnumClass *class = NULL; gboolean ret = TRUE; GEnumValue *v = NULL; class = g_type_class_ref (type); if (G_LIKELY (str)) v = g_enum_get_value_by_nick (class, str); if (v) { if (G_LIKELY (value)) *value = v->value; } else { ret = FALSE; if (warn || possible_values) { int i; GString *s = g_string_new (NULL); for (i = 0, v = g_enum_get_value (class, i); v; i++ , v = g_enum_get_value (class, i)) { if (i) g_string_append_c (s, '/'); g_string_append (s, v->value_nick); } if (warn) g_warning ("%s must be one of %s", G_ENUM_CLASS_TYPE_NAME(class), s->str); if (possible_values) *possible_values = s->str; g_string_free (s, possible_values ? FALSE : TRUE); } } g_type_class_unref (class); return ret;}/** * pango_parse_style: * @str: a string to parse. * @style: a #PangoStyle to store the result in. * @warn: if %TRUE, issue a g_warning() on bad input. * * Parses a font style. The allowed values are "normal", * "italic" and "oblique", case variations being * ignored. * * Return value: %TRUE if @str was successfully parsed. **/gbooleanpango_parse_style (const char *str, PangoStyle *style, gboolean warn){ if (*str == '\0') return FALSE; switch (str[0]) { case 'n': case 'N': if (g_ascii_strcasecmp (str, "normal") == 0) { *style = PANGO_STYLE_NORMAL; return TRUE; } break; case 'i': case 'I': if (g_ascii_strcasecmp (str, "italic") == 0) { *style = PANGO_STYLE_ITALIC; return TRUE; } break; case 'o': case 'O': if (g_ascii_strcasecmp (str, "oblique") == 0) { *style = PANGO_STYLE_OBLIQUE; return TRUE; } break; } if (warn) g_warning ("style must be normal, italic, or oblique"); return FALSE;}/** * pango_parse_variant: * @str: a string to parse. * @variant: a #PangoVariant to store the result in. * @warn: if %TRUE, issue a g_warning() on bad input. * * Parses a font variant. The allowed values are "normal" * and "smallcaps" or "small_caps", case variations being * ignored. * * Return value: %TRUE if @str was successfully parsed. **/gbooleanpango_parse_variant (const char *str, PangoVariant *variant, gboolean warn){ if (*str == '\0') return FALSE; switch (str[0]) { case 'n': case 'N': if (g_ascii_strcasecmp (str, "normal") == 0) { *variant = PANGO_VARIANT_NORMAL; return TRUE; } break; case 's': case 'S': if (g_ascii_strcasecmp (str, "small_caps") == 0 || g_ascii_strcasecmp (str, "smallcaps") == 0) { *variant = PANGO_VARIANT_SMALL_CAPS; return TRUE; } break; } if (warn) g_warning ("variant must be normal or small_caps"); return FALSE;}/** * pango_parse_weight: * @str: a string to parse. * @weight: a #PangoWeight to store the result in. * @warn: if %TRUE, issue a g_warning() on bad input. * * Parses a font weight. The allowed values are "heavy", * "ultrabold", "bold", "normal", "light", "ultraleight" * and integers. Case variations are ignored. * * Return value: %TRUE if @str was successfully parsed. **/gbooleanpango_parse_weight (const char *str, PangoWeight *weight, gboolean warn){ if (*str == '\0') return FALSE; switch (str[0]) { case 'b': case 'B': if (g_ascii_strcasecmp (str, "bold") == 0) { *weight = PANGO_WEIGHT_BOLD; return TRUE; } break; case 'h': case 'H': if (g_ascii_strcasecmp (str, "heavy") == 0) { *weight = PANGO_WEIGHT_HEAVY; return TRUE; } break; case 'l': case 'L': if (g_ascii_strcasecmp (str, "light") == 0) { *weight = PANGO_WEIGHT_LIGHT; return TRUE; } break; case 'n': case 'N': if (g_ascii_strcasecmp (str, "normal") == 0) { *weight = PANGO_WEIGHT_NORMAL; return TRUE; } break; case 'u': case 'U': if (g_ascii_strcasecmp (str, "ultralight") == 0) { *weight = PANGO_WEIGHT_ULTRALIGHT; return TRUE; } else if (g_ascii_strcasecmp (str, "ultrabold") == 0) { *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 *end; *weight = strtol (str, &end, 10); if (*end != '\0') { if (warn) g_warning ("failed parsing numerical weight '%s'", str); return FALSE; } return TRUE; } } if (warn) g_warning ("weight must be ultralight, light, normal, bold, ultrabold, heavy, or an integer"); return FALSE;}/** * pango_parse_stretch: * @str: a string to parse. * @stretch: a #PangoStretch to store the result in. * @warn: if %TRUE, issue a g_warning() on bad input. * * Parses a font stretch. The allowed values are * "ultra_condensed", "extra_condensed", "condensed", * "semi_condensed", "normal", "semi_expanded", "expanded", * "extra_expanded" and "ultra_expanded". Case variations are * ignored and the '_' characters may be omitted. * * Return value: %TRUE if @str was successfully parsed. **/gbooleanpango_parse_stretch (const char *str, PangoStretch *stretch, gboolean warn){ if (*str == '\0') return FALSE; switch (str[0]) { case 'c': case 'C': if (g_ascii_strcasecmp (str, "condensed") == 0) { *stretch = PANGO_STRETCH_CONDENSED; return TRUE; } break; case 'e': case 'E': if (g_ascii_strcasecmp (str, "extra_condensed") == 0 || g_ascii_strcasecmp (str, "extracondensed") == 0) { *stretch = PANGO_STRETCH_EXTRA_CONDENSED; return TRUE; } if (g_ascii_strcasecmp (str, "extra_expanded") == 0 || g_ascii_strcasecmp (str, "extraexpanded") == 0) { *stretch = PANGO_STRETCH_EXTRA_EXPANDED; return TRUE; } if (g_ascii_strcasecmp (str, "expanded") == 0) { *stretch = PANGO_STRETCH_EXPANDED; return TRUE; } break; case 'n': case 'N': if (g_ascii_strcasecmp (str, "normal") == 0) { *stretch = PANGO_STRETCH_NORMAL; return TRUE; } break; case 's': case 'S': if (g_ascii_strcasecmp (str, "semi_condensed") == 0 || g_ascii_strcasecmp (str, "semicondensed") == 0) { *stretch = PANGO_STRETCH_SEMI_CONDENSED; return TRUE; } if (g_ascii_strcasecmp (str, "semi_expanded") == 0 || g_ascii_strcasecmp (str, "semiexpanded") == 0) { *stretch = PANGO_STRETCH_SEMI_EXPANDED; return TRUE; } break; case 'u': case 'U': if (g_ascii_strcasecmp (str, "ultra_condensed") == 0 || g_ascii_strcasecmp (str, "ultracondensed") == 0) { *stretch = PANGO_STRETCH_ULTRA_CONDENSED; return TRUE; } if (g_ascii_strcasecmp (str, "ultra_expanded") == 0 || g_ascii_strcasecmp (str, "ultraexpanded") == 0) { *stretch = PANGO_STRETCH_ULTRA_EXPANDED; return TRUE; } break; } if (warn) g_warning ("stretch must be ultra_condensed, extra_condensed, condensed, semi_condensed, normal, semi_expanded, expanded, extra_expanded, or ultra_expanded"); return FALSE;}/** * pango_log2vis_get_embedding_levels: * @text: the text to itemize. * @length: the number of bytes (not characters) to process, or -1 * if @text is nul-terminated and the length should be calculated. * @pbase_dir: input base direction, and output resolved direction. * * This will return the bidirectional embedding levels of the input paragraph * as defined by the Unicode Bidirectional Algorithm available at: * * http://www.unicode.org/reports/tr9/ * * If the input base direction is a weak direction, the direction of the * characters in the text will determine the final resolved direction. * * Return value: a newly allocated array of embedding levels, one item per * character (not byte), that should be freed using g_free. * * Since: 1.4 */guint8 *pango_log2vis_get_embedding_levels (const gchar *text, int length, PangoDirection *pbase_dir){ FriBidiCharType fribidi_base_dir; guint8 *embedding_levels_list; switch (*pbase_dir) { case PANGO_DIRECTION_LTR: case PANGO_DIRECTION_TTB_RTL: fribidi_base_dir = FRIBIDI_TYPE_L; break; case PANGO_DIRECTION_RTL: case PANGO_DIRECTION_TTB_LTR: fribidi_base_dir = FRIBIDI_TYPE_R; break; case PANGO_DIRECTION_WEAK_RTL: fribidi_base_dir = FRIBIDI_TYPE_WR; break; /* case PANGO_DIRECTION_WEAK_LTR: case PANGO_DIRECTION_NEUTRAL: */ default: fribidi_base_dir = FRIBIDI_TYPE_WL; break; }#ifdef FRIBIDI_HAVE_UTF8 { if (length < 0) length = strlen (text); embedding_levels_list = fribidi_log2vis_get_embedding_levels_new_utf8 (text, length, &fribidi_base_dir); }#else { gunichar *text_ucs4; int n_chars; text_ucs4 = g_utf8_to_ucs4_fast (text, length, &n_chars); embedding_levels_list = g_new (guint8, n_chars); fribidi_log2vis_get_embedding_levels ((FriBidiChar*)text_ucs4, n_chars, &fribidi_base_dir, (FriBidiLevel*)embedding_levels_list); g_free (text_ucs4); }#endif *pbase_dir = (fribidi_base_dir == FRIBIDI_TYPE_L) ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL; return embedding_levels_list;}/** * pango_unichar_direction: * @ch: a Unicode character * * Determines the direction of a character; either * %PANGO_DIRECTION_LTR, %PANGO_DIRECTION_RTL, or * %PANGO_DIRECTION_NEUTRAL. * * Return value: the direction of the character, as used in the * Unicode bidirectional algorithm. */PangoDirectionpango_unichar_direction (gunichar ch){ FriBidiCharType fribidi_ch_type = fribidi_get_type (ch); if (!FRIBIDI_IS_LETTER (fribidi_ch_type)) return PANGO_DIRECTION_NEUTRAL; else if (FRIBIDI_IS_RTL (fribidi_ch_type)) return PANGO_DIRECTION_RTL; else return PANGO_DIRECTION_LTR;}/** * pango_get_mirror_char: * @ch: a Unicode character
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -