Changeset 340


Ignore:
Timestamp:
09/29/11 19:38:33 (20 months ago)
Author:
tal
Message:

Support image.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ufo3k/Lib/ufoLib/glifLib.py

    r339 r340  
    490490        if width is not None: 
    491491                if not isinstance(width, (int, float)): 
    492                         raise GlifLibError, "width attribute must be int or float" 
     492                        raise GlifLibError("width attribute must be int or float") 
    493493        height = getattr(glyphObject, "height", None) 
    494494        if height is not None: 
    495495                if not isinstance(height, (int, float)): 
    496                         raise GlifLibError, "height attribute must be int or float" 
     496                        raise GlifLibError("height attribute must be int or float") 
    497497        if width is not None and height is not None: 
    498498                writer.simpletag("advance", width=str(width), height=str(height)) 
     
    511511                for code in unicodes: 
    512512                        if not isinstance(code, int): 
    513                                 raise GlifLibError, "unicode values must be int" 
     513                                raise GlifLibError("unicode values must be int") 
    514514                        hexCode = hex(code)[2:].upper() 
    515515                        if len(hexCode) < 4: 
     
    521521        if note is not None: 
    522522                if not isinstance(note, (str, unicode)): 
    523                         raise GlifLibError, "note attribute must be str or unicode" 
    524                 note = note.encode('utf-8') 
     523                        raise GlifLibError("note attribute must be str or unicode") 
     524                note = note.encode("utf-8") 
    525525                writer.begintag("note") 
    526526                writer.newline() 
     
    530530                writer.endtag("note") 
    531531                writer.newline() 
     532 
     533        image = getattr(glyphObject, "image", None) 
     534        if image is not None: 
     535                if not imageValidator(image): 
     536                        raise GlifLibError("image attribute must be a dict or dict-like object with the proper structure.") 
     537                attrs = [ 
     538                        ("filename", image["filename"]) 
     539                ] 
     540                for attr, default in _transformationInfo.items(): 
     541                        value = image.get(attr) 
     542                        attrs.append((attr, str(value))) 
     543                color = image.get("color") 
     544                if color is not None: 
     545                        attrs.append(("color", color)) 
     546                self.writer.simpletag("image", attrs) 
     547                self.writer.newline() 
    532548 
    533549        if drawPointsFunc is not None: 
Note: See TracChangeset for help on using the changeset viewer.