Add FC_FONT_HAS_HINT property to see if font has hinting or not.

This may helps to enable autohint only when font doesn't have any hinting
diff --git a/conf.d/09-autohint-if-no-hinting.conf b/conf.d/09-autohint-if-no-hinting.conf
new file mode 100644
index 0000000..afcef3f
--- /dev/null
+++ b/conf.d/09-autohint-if-no-hinting.conf
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
+<fontconfig>
+  <its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
+    <its:translateRule translate="no" selector="/fontconfig/*[not(self::description)]"/>
+  </its:rules>
+
+  <description>Enable autohinter if font doesn't have any hinting</description>
+  <!--  Use the Autohinter --> 
+  <match target="font">
+    <test name="fonthashint"><bool>false</bool></test>
+    <!--
+      This configuration is available on the major desktop environments.
+      We shouldn't overwrite it with "assign" unconditionally.
+      Most clients may picks up the first value only. so using "append"
+      may simply works to avoid it.
+    -->
+    <edit name="autohint" mode="append"><bool>true</bool></edit>
+  </match>
+</fontconfig>
diff --git a/conf.d/Makefile.am b/conf.d/Makefile.am
index 3bb92dd..710318c 100644
--- a/conf.d/Makefile.am
+++ b/conf.d/Makefile.am
@@ -57,6 +57,7 @@
 templatedir = $(TEMPLATEDIR)
 template_DATA =				\
 	05-reset-dirs-sample.conf	\
+	09-autohint-if-no-hinting.conf	\
 	10-autohint.conf		\
 	10-hinting-full.conf		\
 	10-hinting-medium.conf		\
diff --git a/doc/fontconfig-devel.sgml b/doc/fontconfig-devel.sgml
index ee4a432..c4d7537 100644
--- a/doc/fontconfig-devel.sgml
+++ b/doc/fontconfig-devel.sgml
@@ -211,6 +211,7 @@
     color          FC_COLOR               Bool    Whether any glyphs have color
     fontvariations FC_FONT_VARIATIONS     String  comma-separated string of axes in variable font
     variable       FC_VARIABLE            Bool    Whether font is Variable Font
+    fonthashint    FC_FONT_HAS_HINT       Bool    Whether font has hinting
     </programlisting>
   </sect2>
 </sect1>
diff --git a/doc/fontconfig-user.sgml b/doc/fontconfig-user.sgml
index cfe173f..59431dd 100644
--- a/doc/fontconfig-user.sgml
+++ b/doc/fontconfig-user.sgml
@@ -140,6 +140,7 @@
                           familylang, stylelang, and fullnamelang
   prgname         String  String  Name of the running program
   postscriptname  String  Font family name in PostScript
+  fonthashint     Bool    Whether the font has hinting
     </programlisting>
   </refsect2>
   <refsect2>
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index 14a23be..9586616 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -126,6 +126,7 @@
 #define FC_PRGNAME	    "prgname"		/* String */
 #define FC_HASH		    "hash"		/* String (deprecated) */
 #define FC_POSTSCRIPT_NAME  "postscriptname"	/* String */
+#define FC_FONT_HAS_HINT    "fonthashint"	/* Bool - true if font has hinting */
 
 #define FC_CACHE_SUFFIX		    ".cache-" FC_CACHE_VERSION
 #define FC_DIR_CACHE_FILE	    "fonts.cache-" FC_CACHE_VERSION
diff --git a/src/fcfreetype.c b/src/fcfreetype.c
index 28fa8ac..77c174e 100644
--- a/src/fcfreetype.c
+++ b/src/fcfreetype.c
@@ -543,6 +543,9 @@
 static FcChar8 *
 FcFontCapabilities(FT_Face face);
 
+static FcBool
+FcFontHasHint (FT_Face face);
+
 static int
 FcFreeTypeSpacing (FT_Face face);
 
@@ -1829,6 +1832,9 @@
 	free (complex_);
     }
 
+    if (!FcPatternAddBool (pat, FC_FONT_HAS_HINT, FcFontHasHint (face)))
+	goto bail1;
+
     if (!variable_size && os2 && os2->version >= 0x0005 && os2->version != 0xffff)
     {
 	double lower_size, upper_size;
@@ -2552,6 +2558,7 @@
 #define TTAG_GPOS  FT_MAKE_TAG( 'G', 'P', 'O', 'S' )
 #define TTAG_GSUB  FT_MAKE_TAG( 'G', 'S', 'U', 'B' )
 #define TTAG_SILF  FT_MAKE_TAG( 'S', 'i', 'l', 'f')
+#define TTAG_prep  FT_MAKE_TAG( 'p', 'r', 'e', 'p' )
 
 #define OTLAYOUT_HEAD	    "otlayout:"
 #define OTLAYOUT_HEAD_LEN   9
@@ -2736,6 +2743,20 @@
     return complex_;
 }
 
+static FcBool
+FcFontHasHint (FT_Face face)
+{
+    FT_ULong *prep = NULL;
+    FT_UShort prep_count = 0;
+
+    prep_count = GetScriptTags (face, TTAG_prep, &prep);
+
+    free (prep);
+
+    return prep_count > 0;
+}
+
+
 #define __fcfreetype__
 #include "fcaliastail.h"
 #include "fcftaliastail.h"
diff --git a/src/fcobjs.h b/src/fcobjs.h
index e3926cc..7bb97d0 100644
--- a/src/fcobjs.h
+++ b/src/fcobjs.h
@@ -72,4 +72,5 @@
 FC_OBJECT (SYMBOL,		FcTypeBool,	FcCompareBool)
 FC_OBJECT (FONT_VARIATIONS,	FcTypeString,	NULL)
 FC_OBJECT (VARIABLE,		FcTypeBool,	FcCompareBool)
+FC_OBJECT (FONT_HAS_HINT,	FcTypeBool,	NULL)
 /* ^-------------- Add new objects here. */