File: fontyfilter.py

package info (click to toggle)
fontypython 0.4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,152 kB
  • ctags: 559
  • sloc: python: 3,619; makefile: 10
file content (45 lines) | stat: -rw-r--r-- 1,301 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import fpsys # Global objects
import re

"""
June 2009
Created this file with the intention of more complex searching using the 
FontTools module. This has not come to fruition, but I will keep this
module just in-case.
"""
def doFilter( filter_string ):
	##filter_string is a unicode object

	## STEP 1 : get the current view object (pog or folder)
	filteredList = fpsys.state.viewobject
	
	## if filter is not empty	
	if filter_string is not "":
		## Okay, we have some kind of filter.
		## This idea was suggested by user Chris Mohler.

		filteredList = []
		
		## We allow regex in the string. Is this wise?
		test = re.compile(filter_string, re.IGNORECASE)

		## Go through each font item and match 
		## the regex against certain fields.
		## EXTEND THIS TO PANOSE AND other fontTools criteria.
		for fi in fpsys.state.viewobject:
			## July 2016
			## =========
			## There was a None slipping in via fi.style!
			## Fixed this up-stream in fontcontrol.py
			##  print fi.name, fi.family, fi.style

			## Make sure we don't try fetch info from a bad font.
			if not fi.badfont:
				if test.search( fi.name + fi.family[0] + fi.style[0] ):
					filteredList.append( fi )
			else:
				if test.search( fi.name ):
					filteredList.append( fi )

	## We return the filtered-list
	return filteredList