我希望能够识别特定类别的所有字体(sans,sans-serif),这在Google的web字体查看器中是可能的,但似乎不能通过API工作。
https://developers.google.com/webfonts/docs/developer_api#Details
发布于 2012-11-16 18:06:01
Short answer:从this gist获取
scala :这里有一个很小的scala程序可以做到这一点。你需要从http://code.google.com/p/googlefontdirectory中签出googlefontdirectory项目才能使用它,并在下面的程序中更改basePath
:
import com.google.gson.GsonBuilder
import org.apache.commons.io.IOUtils
import java.io.FileInputStream
import collection.mutable
import collection.JavaConverters._
object Webfonts {
private val basePath = new java.io.File("/path/to/googlefontdirectory")
def main(args: Array[String]) {
val fontDetailsList = mutable.ListBuffer.empty[FontDetails]
val categoryMap = mutable.Map.empty[String, java.util.List[String]]
val gson = new GsonBuilder().setPrettyPrinting().create()
for (font <- FontsList.fonts ) {
fontDetailsList += gson.fromJson(IOUtils.toString(new FileInputStream(new java.io.File(basePath, font))), classOf[FontDetails])
}
fontDetailsList.filter(_.subsets.contains("latin")).foreach((font) => {
val a = categoryMap.getOrElseUpdate(font.category, new java.util.ArrayList[String]())
a.add(font.name)
})
val json = gson.toJson(categoryMap.asJava)
println(json)
}
case class FontDetails(name: String, license: String, category: String, size: Int, subsets: Array[String]) {
override def toString = category + " : " + name
}
}
object FontsList {
val fonts = Array(
"./apache/aclonica/METADATA.json",
"./apache/calligraffitti/METADATA.json",
"./apache/cherrycreamsoda/METADATA.json",
"./ufl/ubuntucondensed/METADATA.json",
"./ufl/ubuntumono/METADATA.json"
)
}
您可以在https://gist.github.com/4085914上获得完整的FontsList
发布于 2012-08-30 04:30:55
我不认为API支持这一点。如果检查从API返回的JSON文件,它不会显示此信息。Google Web Font小组也提出了类似的问题,但没有答案。
https://groups.google.com/forum/?fromgroups=#!topic/googlefontdirectory-discuss/U2cROKUjRqM
https://stackoverflow.com/questions/11807467
复制相似问题