Commits

Anonymous committed b79904b

Adding user api to text parsing.

  • Participants
  • Parent commits fd5c151

Comments (0)

Files changed (5)

     >>> layer.visible, layer.opacity, layer.blend_mode
     (True, 255, u'norm')
 
+    >>> layer.text_data.text
+    'Text inside a text box'
+
     >>> layer.as_PIL()
     <PIL.Image.Image image mode=RGBA size=43x62 at ...>
 
 
 .. _libpsd: http://sourceforge.net/projects/libpsd/
 .. _psdparse C library: http://telegraphics.com.au/svn/psdparse/trunk/
-.. _Paint.NET PSD Plugin: http://psdplugin.codeplex.com/
+.. _Paint.NET PSD Plugin: http://psdplugin.codeplex.com/

src/psd_tools/constants.py

     POINT = 3  # 72 points == 1 inch
     PICA = 4   # 6 pica == 1 inch
     COLUMN = 5
+
+class TextProperty(Enum):
+    TXT = 'Txt '
+    ORIENTATION = 'Ornt'
+
+class TextOrientation(Enum):
+    HORIZONTAL = 'Hrzn'

src/psd_tools/decoder/actions.py

         if decode_ostype:
             value = decode_ostype(key, fp)
             if value is not None:
-                items.append((key, value))
+                items.append((key.decode(), value))
 
     return Descriptor(name, classID, items)
 

src/psd_tools/user_api/psd_image.py

 import weakref              # FIXME: there should be weakrefs in this module
 import psd_tools.reader
 import psd_tools.decoder
-from psd_tools.constants import TaggedBlock, SectionDivider, BlendMode
+from psd_tools.constants import TaggedBlock, SectionDivider, BlendMode, TextProperty
 from psd_tools.user_api.layers import group_layers
 from psd_tools.user_api import pymaging_support
 from psd_tools.user_api import pil_support
         return self.y2-self.y1
 
 
-class Text(object):
-	pass
+class TextData(object):
+    def __init__(self, tagged_blocks):
+        text_data = dict(tagged_blocks.text_data.items)
+        self.text = text_data[TextProperty.TXT].value
+
 
 class _RawLayer(object):
     """
         return BBox(info.left, info.top, info.right, info.bottom)
 
     @property
-    def text(self):
-        if self._tagged_blocks.get(TaggedBlock.TYPE_TOOL_OBJECT_SETTING):
-            return Text()
+    def text_data(self):
+        tagged_blocks = self._tagged_blocks.get(TaggedBlock.TYPE_TOOL_OBJECT_SETTING)
+        if tagged_blocks:
+            return TextData(tagged_blocks)
 
     def __repr__(self):
         bbox = self.bbox

tests/test_text.py

     psd = PSDImage(decode_psd(filename))
 
     layer = psd.layers[layer_num]
-    text_data = layer._tagged_blocks['TySh'].text_data
-
-    assert text_data.items[0][1].value == text
+    assert layer.text_data.text == text