Re: Using TT_NAME_ID_SAMPLE_TEXT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11 March 2014 21:47, Behdad Esfahbod <behdad@xxxxxxxxxx> wrote:
>> Okay, that looks awesome. Can I get that data from pango (e.g.
>> pango_script_get_sample_char) or should I encode it into my program?
> Commit to Pango please!

Okay, I've attached two different versions of incomplete patches for
comments. I'd like to know how to encode the sample chars; all those
'if's makes for an unhappy compiler. switch/case might be slightly
faster, or v2 just defines a static data table the size of all the
entries in PangoScript (and add a private PANGO_SCRIPT_LAST) and does
a direct lookup, although if the PANGO_SCRIPT_ defines ever get out of
sync it'll be tricky to debug. Using the table looks sane to me, but
it's just a pain to order all those enums :)

I've also chosen char * to return the sample char in, I figured this
was more flexible than using gunichar and probably easier for the
consumer to digest and use. Both patches are known incomplete and
broken. Feedback please :)

Richard.
From 1fefc390cd8d53c4a1fbaeb103b0f979db77a6fe Mon Sep 17 00:00:00 2001
From: Richard Hughes <richard@xxxxxxxxxxx>
Date: Wed, 12 Mar 2014 09:02:27 +0000
Subject: [PATCH] Add pango_script_get_sample_char()

This allows us to get a short sample string for each PangoScript.
---
 pango/pango-script.c | 34 ++++++++++++++++++++++++++++++++++
 pango/pango-script.h |  1 +
 2 files changed, 35 insertions(+)

diff --git a/pango/pango-script.c b/pango/pango-script.c
index 95dd3e9..80efab6 100644
--- a/pango/pango-script.c
+++ b/pango/pango-script.c
@@ -91,6 +91,40 @@ pango_script_for_unichar (gunichar ch)
   return g_unichar_get_script (ch);
 }
 
+/**
+ * pango_script_get_sample_char:
+ * @script: a #PangoScript
+ *
+ * Get a short character string that is representative of the particular script.
+ *
+ * If Pango does not have a sample string for @script, "@" is returned.
+ * This can be detected by
+ * comparing the returned pointer value to that returned for script
+ * %PANGO_SCRIPT_INVALID_CODE.
+ *
+ * That is, compare to:
+ * <informalexample><programlisting>
+ * pango_script_get_sample_char (PANGO_SCRIPT_INVALID_CODE)
+ * </programlisting></informalexample>
+ *
+ * Return value: the sample string. This value is owned by Pango
+ *   and should not be freed.
+ **/
+const char *
+pango_script_get_sample_char (PangoScript script)
+{
+  if (script == PANGO_SCRIPT_COMMON)
+    return "@";
+  if (script == PANGO_SCRIPT_ARABIC)
+    return "ب";
+  if (script == PANGO_SCRIPT_ARMENIAN)
+    return "Ա";
+  if (script == PANGO_SCRIPT_BENGALI)
+    return "ক";
+  /* FIXME: other entries */
+  return "@";
+}
+
 /**********************************************************************/
 
 PangoScriptIter *
diff --git a/pango/pango-script.h b/pango/pango-script.h
index e370e3e..6822425 100644
--- a/pango/pango-script.h
+++ b/pango/pango-script.h
@@ -250,6 +250,7 @@ void             pango_script_iter_get_range (PangoScriptIter     *iter,
                                               PangoScript         *script);
 gboolean         pango_script_iter_next      (PangoScriptIter     *iter);
 void             pango_script_iter_free      (PangoScriptIter     *iter);
+const char      *pango_script_get_sample_char (PangoScript         script) G_GNUC_CONST;
 
 #include <pango/pango-language.h>
 
-- 
1.8.5.3

From 751715f516cd3320366ca1ea46fe3c3e91f57371 Mon Sep 17 00:00:00 2001
From: Richard Hughes <richard@xxxxxxxxxxx>
Date: Wed, 12 Mar 2014 09:02:27 +0000
Subject: [PATCH] Add pango_script_get_sample_char() using a table of data

This allows us to get a short sample string for each PangoScript.
---
 pango/pango-script.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++
 pango/pango-script.h |   6 ++-
 2 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/pango/pango-script.c b/pango/pango-script.c
index 95dd3e9..9b03347 100644
--- a/pango/pango-script.c
+++ b/pango/pango-script.c
@@ -91,6 +91,124 @@ pango_script_for_unichar (gunichar ch)
   return g_unichar_get_script (ch);
 }
 
+/**
+ * pango_script_get_sample_char:
+ * @script: a #PangoScript
+ *
+ * Get a short character string that is representative of the particular script.
+ *
+ * If Pango does not have a sample string for @script, "@" is returned.
+ * This can be detected by
+ * comparing the returned pointer value to that returned for script
+ * %PANGO_SCRIPT_INVALID_CODE.
+ *
+ * That is, compare to:
+ * <informalexample><programlisting>
+ * pango_script_get_sample_char (PANGO_SCRIPT_INVALID_CODE)
+ * </programlisting></informalexample>
+ *
+ * Return value: the sample string. This value is owned by Pango
+ *   and should not be freed.
+ **/
+const char *
+pango_script_get_sample_char (PangoScript script)
+{
+  /* FIXME: these need sorting into PangoScript order */
+  const char *sample_chars[PANGO_SCRIPT_LAST] = {
+	"@",	/* PANGO_SCRIPT_COMMON */
+	"ب",	/* PANGO_SCRIPT_ARABIC */
+	"Ա",	/* PANGO_SCRIPT_ARMENIAN */
+	"ক",	/* PANGO_SCRIPT_BENGALI */
+	"ㄅ",	/* PANGO_SCRIPT_BOPOMOFO */
+	"Ꮔ",	/* PANGO_SCRIPT_CHEROKEE */
+	"Ϣ",	/* PANGO_SCRIPT_COPTIC */
+	"Я",	/* PANGO_SCRIPT_CYRILLIC */
+	"𐐔",	/* PANGO_SCRIPT_DESERET */
+	"क",	/* PANGO_SCRIPT_DEVANAGARI */
+	"አ",	/* PANGO_SCRIPT_ETHIOPIC */
+	"დ",	/* PANGO_SCRIPT_GEORGIAN */
+	"𐌰",	/* PANGO_SCRIPT_GOTHIC */
+	"Ω",	/* PANGO_SCRIPT_GREEK */
+	"ક",	/* PANGO_SCRIPT_GUJARATI */
+	"ਕ",	/* PANGO_SCRIPT_GURMUKHI */
+	"字",	/* PANGO_SCRIPT_HAN */
+	"가",	/* PANGO_SCRIPT_HANGUL */
+	"א",	/* PANGO_SCRIPT_HEBREW */
+	"か",	/* PANGO_SCRIPT_HIRAGANA */
+	"ಕ",	/* PANGO_SCRIPT_KANNADA */
+	"カ",	/* PANGO_SCRIPT_KATAKANA */
+	"ក",	/* PANGO_SCRIPT_KHMER */
+	"ລ",	/* PANGO_SCRIPT_LAO */
+	"L",	/* PANGO_SCRIPT_LATIN */
+	"ക",	/* PANGO_SCRIPT_MALAYALAM */
+	"ᠦ",	/* PANGO_SCRIPT_MONGOLIAN */
+	"က",	/* PANGO_SCRIPT_MYANMAR */
+	"ᚏ",	/* PANGO_SCRIPT_OGHAM */
+	"𐌀",	/* PANGO_SCRIPT_OLD_ITALIC */
+	"କ",	/* PANGO_SCRIPT_ORIYA */
+	"ᚠ",	/* PANGO_SCRIPT_RUNIC */
+	"අ",	/* PANGO_SCRIPT_SINHALA */
+	"ܐ",	/* PANGO_SCRIPT_SYRIAC */
+	"க",	/* PANGO_SCRIPT_TAMIL */
+	"క",	/* PANGO_SCRIPT_TELUGU */
+	"ތ",	/* PANGO_SCRIPT_THAANA */
+	"ท",	/* PANGO_SCRIPT_THAI */
+	"ཀ",	/* PANGO_SCRIPT_TIBETAN */
+	"ᓀ",	/* PANGO_SCRIPT_CANADIAN_ABORIGINAL */
+	"ꊈ",	/* PANGO_SCRIPT_YI */
+	"ᜃ",	/* PANGO_SCRIPT_TAGALOG */
+	"ᜣ",	/* PANGO_SCRIPT_HANUNOO */
+	"ᝃ",	/* PANGO_SCRIPT_BUHID */
+	"ᝣ",	/* PANGO_SCRIPT_TAGBANWA */
+	"𐠀",	/* PANGO_SCRIPT_CYPRIOT */
+	"ᤀ",	/* PANGO_SCRIPT_LIMBU */
+	"𐀀",	/* PANGO_SCRIPT_LINEAR_B */
+	"𐒀",	/* PANGO_SCRIPT_OSMANYA */
+	"𐑐",	/* PANGO_SCRIPT_SHAVIAN */
+	"ᥐ",	/* PANGO_SCRIPT_TAI_LE */
+	"𐎀",	/* PANGO_SCRIPT_UGARITIC */
+	"ᨀ",	/* PANGO_SCRIPT_BUGINESE */
+	"Ⰰ",	/* PANGO_SCRIPT_GLAGOLITIC */
+	"𐨀",	/* PANGO_SCRIPT_KHAROSHTHI */
+	"ꠀ",	/* PANGO_SCRIPT_SYLOTI_NAGRI */
+	"ᦀ",	/* PANGO_SCRIPT_NEW_TAI_LUE */
+	"ⴰ",	/* PANGO_SCRIPT_TIFINAGH */
+	"𐎠",	/* PANGO_SCRIPT_OLD_PERSIAN */
+	"ᬅ",	/* PANGO_SCRIPT_BALINESE */
+	"ꨀ",	/* PANGO_SCRIPT_CHAM */
+	"𓅓",	/* PANGO_SCRIPT_EGYPTIAN_HIEROGLYPHS */
+	"ꦄ",	/* PANGO_SCRIPT_JAVANESE */
+	"ꤊ",	/* PANGO_SCRIPT_KAYAH_LI */
+	"ᰀ",	/* PANGO_SCRIPT_LEPCHA */
+	"ߊ",	/* PANGO_SCRIPT_NKO */
+	"𐰀",	/* PANGO_SCRIPT_OLD_TURKIC */
+	"ꡀ",	/* PANGO_SCRIPT_PHAGS_PA */
+	"𐤀",	/* PANGO_SCRIPT_PHOENICIAN */
+	"ꕉ",	/* PANGO_SCRIPT_VAI */
+	"𒀀",	/* PANGO_SCRIPT_CUNEIFORM */
+	"𐊠",	/* PANGO_SCRIPT_CARIAN */
+	"ᨠ",	/* PANGO_SCRIPT_TAI_THAM */
+	"𐊀",	/* PANGO_SCRIPT_LYCIAN */
+	"𐤠",	/* PANGO_SCRIPT_LYDIAN */
+	"ᱚ",	/* PANGO_SCRIPT_OL_CHIKI */
+	"ꤰ",	/* PANGO_SCRIPT_REJANG */
+	"ꢂ",	/* PANGO_SCRIPT_SAURASHTRA */
+	"ᮃ",	/* PANGO_SCRIPT_SUNDANESE */
+	"ꯀ",	/* PANGO_SCRIPT_MEETEI_MAYEK */
+	"𐡀",	/* PANGO_SCRIPT_IMPERIAL_ARAMAIC */
+	"𐬀",	/* PANGO_SCRIPT_AVESTAN */
+	"𑂃",	/* PANGO_SCRIPT_KAITHI */
+	"𐭠",	/* PANGO_SCRIPT_INSCRIPTIONAL_PAHLAVI */
+	"𐭀",	/* PANGO_SCRIPT_INSCRIPTIONAL_PARTHIAN */
+	"ࠀ",	/* PANGO_SCRIPT_SAMARITAN */
+	"ꪀ",	/* PANGO_SCRIPT_TAI_VIET */
+	"ꚠ",	/* PANGO_SCRIPT_BAMUM */
+	"ꓐ",	/* PANGO_SCRIPT_LISU */
+	"𐩠",	/* PANGO_SCRIPT_OLD_SOUTH_ARABIAN */
+	NULL };
+  return sample_chars[script];
+}
+
 /**********************************************************************/
 
 PangoScriptIter *
diff --git a/pango/pango-script.h b/pango/pango-script.h
index e370e3e..099d514 100644
--- a/pango/pango-script.h
+++ b/pango/pango-script.h
@@ -237,7 +237,10 @@ typedef enum {                         /* ISO 15924 code */
       PANGO_SCRIPT_MIAO,               /* Plrd */
       PANGO_SCRIPT_SHARADA,            /* Shrd */
       PANGO_SCRIPT_SORA_SOMPENG,       /* Sora */
-      PANGO_SCRIPT_TAKRI               /* Takr */
+      PANGO_SCRIPT_TAKRI,              /* Takr */
+
+      /*< private >*/
+      PANGO_SCRIPT_LAST
 } PangoScript;
 
 PangoScript pango_script_for_unichar         (gunichar             ch) G_GNUC_CONST;
@@ -250,6 +253,7 @@ void             pango_script_iter_get_range (PangoScriptIter     *iter,
                                               PangoScript         *script);
 gboolean         pango_script_iter_next      (PangoScriptIter     *iter);
 void             pango_script_iter_free      (PangoScriptIter     *iter);
+const char      *pango_script_get_sample_char (PangoScript         script) G_GNUC_CONST;
 
 #include <pango/pango-language.h>
 
-- 
1.8.5.3

_______________________________________________
fonts mailing list
fonts@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/fonts
http://fonts.fedoraproject.org/

[Index of Archives]     [Fedora Users]     [Font Configuration]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite Forum]     [KDE Users]

  Powered by Linux