コード例 #1
0
ファイル: __init__.py プロジェクト: 7o9/stdm-plugin
	def __init__(self, file=None, res_name_or_index=None,
			sfntVersion="\000\001\000\000", checkChecksums=0,
			verbose=0, recalcBBoxes=1, allowVID=0, ignoreDecompileErrors=False,
			fontNumber=-1):
		
		"""The constructor can be called with a few different arguments.
		When reading a font from disk, 'file' should be either a pathname
		pointing to a file, or a readable file object. 
		
		It we're running on a Macintosh, 'res_name_or_index' maybe an sfnt 
		resource name or an sfnt resource index number or zero. The latter 
		case will cause TTLib to autodetect whether the file is a flat file 
		or a suitcase. (If it's a suitcase, only the first 'sfnt' resource
		will be read!)
		
		The 'checkChecksums' argument is used to specify how sfnt
		checksums are treated upon reading a file from disk:
			0: don't check (default)
			1: check, print warnings if a wrong checksum is found
			2: check, raise an exception if a wrong checksum is found.
		
		The TTFont constructor can also be called without a 'file' 
		argument: this is the way to create a new empty font. 
		In this case you can optionally supply the 'sfntVersion' argument.
		
		If the recalcBBoxes argument is false, a number of things will *not*
		be recalculated upon save/compile:
			1) glyph bounding boxes
			2) maxp font bounding box
			3) hhea min/max values
		(1) is needed for certain kinds of CJK fonts (ask Werner Lemberg ;-).
		Additionally, upon importing an TTX file, this option cause glyphs
		to be compiled right away. This should reduce memory consumption 
		greatly, and therefore should have some impact on the time needed 
		to parse/compile large fonts.

		If the allowVID argument is set to true, then virtual GID's are
		supported. Asking for a glyph ID with a glyph name or GID that is not in
		the font will return a virtual GID.   This is valid for GSUB and cmap
		tables. For SING glyphlets, the cmap table is used to specify Unicode
		values for virtual GI's used in GSUB/GPOS rules. If the gid Nis requested
		and does not exist in the font, or the glyphname has the form glyphN
		and does not exist in the font, then N is used as the virtual GID.
		Else, the first virtual GID is assigned as 0x1000 -1; for subsequent new
		virtual GIDs, the next is one less than the previous.

		If ignoreDecompileErrors is set to True, exceptions raised in
		individual tables during decompilation will be ignored, falling
		back to the DefaultTable implementation, which simply keeps the
		binary data.
		"""
		
		import sfnt
		self.verbose = verbose
		self.recalcBBoxes = recalcBBoxes
		self.tables = {}
		self.reader = None

		# Permit the user to reference glyphs that are not int the font.
		self.last_vid = 0xFFFE # Can't make it be 0xFFFF, as the world is full unsigned short integer counters that get incremented after the last seen GID value.
		self.reverseVIDDict = {}
		self.VIDDict = {}
		self.allowVID = allowVID
		self.ignoreDecompileErrors = ignoreDecompileErrors

		if not file:
			self.sfntVersion = sfntVersion
			return
		if not hasattr(file, "read"):
			# assume file is a string
			if haveMacSupport and res_name_or_index is not None:
				# on the mac, we deal with sfnt resources as well as flat files
				import macUtils
				if res_name_or_index == 0:
					if macUtils.getSFNTResIndices(file):
						# get the first available sfnt font.
						file = macUtils.SFNTResourceReader(file, 1)
					else:
						file = open(file, "rb")
				else:
					file = macUtils.SFNTResourceReader(file, res_name_or_index)
			else:
				file = open(file, "rb")
		else:
			pass # assume "file" is a readable file object
		self.reader = sfnt.SFNTReader(file, checkChecksums, fontNumber=fontNumber)
		self.sfntVersion = self.reader.sfntVersion
コード例 #2
0
    def __init__(self,
                 file=None,
                 res_name_or_index=None,
                 sfntVersion="\000\001\000\000",
                 checkChecksums=0,
                 verbose=0,
                 recalcBBoxes=1,
                 allowVID=0,
                 ignoreDecompileErrors=False,
                 fontNumber=-1):
        """The constructor can be called with a few different arguments.
		When reading a font from disk, 'file' should be either a pathname
		pointing to a file, or a readable file object. 
		
		It we're running on a Macintosh, 'res_name_or_index' maybe an sfnt 
		resource name or an sfnt resource index number or zero. The latter 
		case will cause TTLib to autodetect whether the file is a flat file 
		or a suitcase. (If it's a suitcase, only the first 'sfnt' resource
		will be read!)
		
		The 'checkChecksums' argument is used to specify how sfnt
		checksums are treated upon reading a file from disk:
			0: don't check (default)
			1: check, print warnings if a wrong checksum is found
			2: check, raise an exception if a wrong checksum is found.
		
		The TTFont constructor can also be called without a 'file' 
		argument: this is the way to create a new empty font. 
		In this case you can optionally supply the 'sfntVersion' argument.
		
		If the recalcBBoxes argument is false, a number of things will *not*
		be recalculated upon save/compile:
			1) glyph bounding boxes
			2) maxp font bounding box
			3) hhea min/max values
		(1) is needed for certain kinds of CJK fonts (ask Werner Lemberg ;-).
		Additionally, upon importing an TTX file, this option cause glyphs
		to be compiled right away. This should reduce memory consumption 
		greatly, and therefore should have some impact on the time needed 
		to parse/compile large fonts.

		If the allowVID argument is set to true, then virtual GID's are
		supported. Asking for a glyph ID with a glyph name or GID that is not in
		the font will return a virtual GID.   This is valid for GSUB and cmap
		tables. For SING glyphlets, the cmap table is used to specify Unicode
		values for virtual GI's used in GSUB/GPOS rules. If the gid Nis requested
		and does not exist in the font, or the glyphname has the form glyphN
		and does not exist in the font, then N is used as the virtual GID.
		Else, the first virtual GID is assigned as 0x1000 -1; for subsequent new
		virtual GIDs, the next is one less than the previous.

		If ignoreDecompileErrors is set to True, exceptions raised in
		individual tables during decompilation will be ignored, falling
		back to the DefaultTable implementation, which simply keeps the
		binary data.
		"""

        import sfnt
        self.verbose = verbose
        self.recalcBBoxes = recalcBBoxes
        self.tables = {}
        self.reader = None

        # Permit the user to reference glyphs that are not int the font.
        self.last_vid = 0xFFFE  # Can't make it be 0xFFFF, as the world is full unsigned short integer counters that get incremented after the last seen GID value.
        self.reverseVIDDict = {}
        self.VIDDict = {}
        self.allowVID = allowVID
        self.ignoreDecompileErrors = ignoreDecompileErrors

        if not file:
            self.sfntVersion = sfntVersion
            return
        if not hasattr(file, "read"):
            # assume file is a string
            if haveMacSupport and res_name_or_index is not None:
                # on the mac, we deal with sfnt resources as well as flat files
                import macUtils
                if res_name_or_index == 0:
                    if macUtils.getSFNTResIndices(file):
                        # get the first available sfnt font.
                        file = macUtils.SFNTResourceReader(file, 1)
                    else:
                        file = open(file, "rb")
                else:
                    file = macUtils.SFNTResourceReader(file, res_name_or_index)
            else:
                file = open(file, "rb")
        else:
            pass  # assume "file" is a readable file object
        self.reader = sfnt.SFNTReader(file,
                                      checkChecksums,
                                      fontNumber=fontNumber)
        self.sfntVersion = self.reader.sfntVersion
コード例 #3
0
ファイル: __init__.py プロジェクト: GaZ3ll3/enable
        def __init__(self, file=None, res_name_or_index=None,
                        sfntVersion="\000\001\000\000", checkChecksums=0,
                        verbose=0, recalcBBoxes=1):

                """The constructor can be called with a few different arguments.
                When reading a font from disk, 'file' should be either a pathname
                pointing to a file, or a readable file object.

                It we're running on a Macintosh, 'res_name_or_index' maybe an sfnt
                resource name or an sfnt resource index number or zero. The latter
                case will cause TTLib to autodetect whether the file is a flat file
                or a suitcase. (If it's a suitcase, only the first 'sfnt' resource
                will be read!)

                The 'checkChecksums' argument is used to specify how sfnt
                checksums are treated upon reading a file from disk:

                - 0: don't check (default)
                - 1: check, print warnings if a wrong checksum is found
                - 2: check, raise an exception if a wrong checksum is found.

                The TTFont constructor can also be called without a 'file'
                argument: this is the way to create a new empty font.
                In this case you can optionally supply the 'sfntVersion' argument.

                If the recalcBBoxes argument is false, a number of things will *not*
                be recalculated upon save/compile:

                        1. glyph bounding boxes
                        2. maxp font bounding box
                        3. hhea min/max values

                (1) is needed for certain kinds of CJK fonts (ask Werner Lemberg ;-).
                Additionally, upon importing an TTX file, this option cause glyphs
                to be compiled right away. This should reduce memory consumption
                greatly, and therefore should have some impact on the time needed
                to parse/compile large fonts.
                """

                import sfnt
                self.verbose = verbose
                self.recalcBBoxes = recalcBBoxes
                self.tables = {}
                self.reader = None
                if not file:
                        self.sfntVersion = sfntVersion
                        return
                if isinstance(file, basestring):
                        if os.name == "mac" and res_name_or_index is not None:
                                # on the mac, we deal with sfnt resources as well as flat files
                                import macUtils
                                if res_name_or_index == 0:
                                        if macUtils.getSFNTResIndices(file):
                                                # get the first available sfnt font.
                                                file = macUtils.SFNTResourceReader(file, 1)
                                        else:
                                                file = open(file, "rb")
                                else:
                                        file = macUtils.SFNTResourceReader(file, res_name_or_index)
                        else:
                                file = open(file, "rb")
                else:
                        pass # assume "file" is a readable file object
                self.reader = sfnt.SFNTReader(file, checkChecksums)
                self.sfntVersion = self.reader.sfntVersion
コード例 #4
0
ファイル: __init__.py プロジェクト: enthought/etsproxy
    def __init__(self,
                 file=None,
                 res_name_or_index=None,
                 sfntVersion="\000\001\000\000",
                 checkChecksums=0,
                 verbose=0,
                 recalcBBoxes=1):
        """The constructor can be called with a few different arguments.
                When reading a font from disk, 'file' should be either a pathname
                pointing to a file, or a readable file object.

                It we're running on a Macintosh, 'res_name_or_index' maybe an sfnt
                resource name or an sfnt resource index number or zero. The latter
                case will cause TTLib to autodetect whether the file is a flat file
                or a suitcase. (If it's a suitcase, only the first 'sfnt' resource
                will be read!)

                The 'checkChecksums' argument is used to specify how sfnt
                checksums are treated upon reading a file from disk:

                - 0: don't check (default)
                - 1: check, print warnings if a wrong checksum is found
                - 2: check, raise an exception if a wrong checksum is found.

                The TTFont constructor can also be called without a 'file'
                argument: this is the way to create a new empty font.
                In this case you can optionally supply the 'sfntVersion' argument.

                If the recalcBBoxes argument is false, a number of things will *not*
                be recalculated upon save/compile:

                        1. glyph bounding boxes
                        2. maxp font bounding box
                        3. hhea min/max values

                (1) is needed for certain kinds of CJK fonts (ask Werner Lemberg ;-).
                Additionally, upon importing an TTX file, this option cause glyphs
                to be compiled right away. This should reduce memory consumption
                greatly, and therefore should have some impact on the time needed
                to parse/compile large fonts.
                """

        import sfnt
        self.verbose = verbose
        self.recalcBBoxes = recalcBBoxes
        self.tables = {}
        self.reader = None
        if not file:
            self.sfntVersion = sfntVersion
            return
        if isinstance(file, basestring):
            if os.name == "mac" and res_name_or_index is not None:
                # on the mac, we deal with sfnt resources as well as flat files
                import macUtils
                if res_name_or_index == 0:
                    if macUtils.getSFNTResIndices(file):
                        # get the first available sfnt font.
                        file = macUtils.SFNTResourceReader(file, 1)
                    else:
                        file = open(file, "rb")
                else:
                    file = macUtils.SFNTResourceReader(file, res_name_or_index)
            else:
                file = open(file, "rb")
        else:
            pass  # assume "file" is a readable file object
        self.reader = sfnt.SFNTReader(file, checkChecksums)
        self.sfntVersion = self.reader.sfntVersion