sketch-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

None


From: matthias entenmann
Subject: None
Date: Mon, 09 Dec 2002 17:45:14 +0000


What is still missing to make sketch a _real_ drawing program is the
implementaion of a multiline text object. Over a year ago, Mark Rose
posted a solution which is (at least in my eyes) great. However, it is
still not included in sketch (what I don't really understand).

The "textbox"-object was surly ment to be work in progress, but already
useful. What is missing is the extension to the sk fileformat to save and
load textbox objects. It doesn't look like there is any remaining
activity, and I don't want to wait. So here is my fileformat extension:

I. New commands for the sk-fileformat

TC(TRAFO, WIDTH [, HORIZ_ALIGN, VERT_ALIGN])
      Begins a text compound

t(TXT)
      A piece of text. Typeset in a uniform style. Can contain
      '\n'.
TC_()
      Ends text compound.

Fc(SCRIPT)
      The script value.

Between TC(..) and TC_(..) can be text pieces t(..) and also property
changes. In future versions it might be possible, to put any Sketch object
in a text compound.


II. Installation

Get the 0.6.14 source and untar it. Get Marks textbox
patch textbox-S.2.0.tgz from
http://sketch.sourceforge.net/files/src/patches/0.6/
and apply it as described in the README.

Save the code part of this mail in patch.diff  and apply the
patch in the same way:
% cd sketch-0.6.14/
% patch -p1 -l < ../patch.diff

Then go on with the usual installation of sketch as described in sketch's
INSTALL file. Usually this is:
% cd sketch-0.6.14
% ./setup.py configure
% ./setup.py build
% ./sketch.py

Matthias

diff -trNa -U 4 -x*afm -x.* -x*pyc -xconfig.c -x*o -xMake* -xSetup -xsedscript* -x*~ -x*arrow* -x *linedlg* sketch-0.6.14_textbox/Plugins/Filters/skloader.py sketch-0.6.14_patched/Plugins/Filters/skloader.py --- sketch-0.6.14_textbox/Plugins/Filters/skloader.py Mon Dec 9 18:14:54 2002 +++ sketch-0.6.14_patched/Plugins/Filters/skloader.py Mon Dec 9 18:15:51 2002
@@ -36,9 +36,9 @@
from Sketch import CreateRGBColor, SolidPattern, HatchingPattern,EmptyPattern,\
     LinearGradient, ConicalGradient, RadialGradient, ImageTilePattern, \
     Style, MultiGradient, Trafo, Translation, Point, \
     GridLayer, GuideLayer, GuideLine, Arrow, CreatePath, StandardColors, \
-     GetFont
+     GetFont, TextBox, Character, Break

from Sketch.load import GenericLoader

from Sketch.Graphics import pagelayout, plugobj, blendgroup, text, image, eps,\
@@ -55,8 +55,10 @@
base_style.line_arrow1 = None
base_style.line_arrow2 = None
base_style.font = None
base_style.font_size = 12.0
+base_style.script = 0.0
+

# sanity check: does base_style have all properties?
for key in dir(properties.factory_defaults):
    if not hasattr(base_style, key):
@@ -67,10 +69,9 @@
papersizes = [#    'A0', 'A1', 'A2',
    'A3', 'A4', 'A5', 'A6', 'A7',
    'letter', 'legal', 'executive',
    ]
-
-
+
class SKLoader(GenericLoader):

    format_name = format_name

@@ -286,8 +287,12 @@
    functions.append('Fs')
    def Fs(self, size):
        self.style.font_size = size

+    functions.append('Fc')
+    def Fc(self, script):
+        self.style.script = script
+
    functions.append('guide')
    def guide(self, pos, horizontal):
        if horizontal:
            p = Point(0, pos)
@@ -362,8 +367,36 @@
            else:
                filename = os.path.join(os.getcwd(), filename)
self.append_object(eps.EpsImage(filename = filename, trafo = trafo))

+    def create_textbox(self, trafo, width, halign = text.ALIGN_LEFT,
+                       valign = text.ALIGN_BASE):
+        if len(trafo) == 2:
+            trafo = Translation(trafo)
+        else:
+            trafo = apply(Trafo, trafo)
+        obj = TextBox(trafo = trafo, halign = halign, valign = valign, \
+                      width = width)
+        return obj
+
+    functions.append('TC')
+    def TC(self, *args, **kw):
+        self.begin_composite(self.create_textbox, args, kw)
+
+    functions.append('TC_')
+    def TC_(self):
+        self.end_composite()
+
+    functions.append('t')
+    def t(self, txt):
+        props = self.get_prop_stack()
+        for c in txt:
+            if c == '\n':
+                obj = Break()
+            else:
+                obj = Character(c, properties=props.Duplicate())
+            self.append_object(obj)
+
    functions.append('B')
    def B(self, *args, **kw):
        self.begin_composite(blendgroup.BlendGroup, args, kw)

diff -trNa -U 4 -x*afm -x.* -x*pyc -xconfig.c -x*o -xMake* -xSetup -xsedscript* -x*~ -x*arrow* -x *linedlg* sketch-0.6.14_textbox/Plugins/Filters/sksaver.py sketch-0.6.14_patched/Plugins/Filters/sksaver.py --- sketch-0.6.14_textbox/Plugins/Filters/sksaver.py Mon Dec 9 18:14:54 2002 +++ sketch-0.6.14_patched/Plugins/Filters/sksaver.py Mon Dec 9 18:15:51 2002
@@ -114,8 +114,11 @@
#
# Fs(SIZE)
#
#       `font size'
+# Fc(SCRIPT)
+#
+#       'font script'
#
# dstyle(NAME)
#
#       Define new dynamic style named NAME with the current properties
@@ -169,8 +172,16 @@
#       Text on a path. The path is the only object between the pt and
#       PT_ functions.
#
#
+# TC(TRAFO, WIDTH [, HORIZ_ALIGN, VERT_ALIGN])
+# t(TXT)
+# TC_()
+#       TextCompound. Between TC and TC_ can be text elements and
+#       properties. In later versions, it might be possible, to
+#       put any Sketch object in a text compound.
+#
+#
# b()
#       start a bezier obj
# bs(X, Y, CONT)                        append a line segment
# bc(X1, Y1, X2, Y2, X3, Y3, CONT)      append a bezier segment
@@ -258,8 +269,9 @@
base_style.line_arrow1 = None
base_style.line_arrow2 = None
base_style.font = None
base_style.font_size = 12.0
+base_style.script = 0.0

papersizes = {
#    'A0': (0.841 * m_to_pt, 1.189 * m_to_pt),
#    'A1': (0.594 * m_to_pt, 0.841 * m_to_pt),
@@ -437,8 +449,10 @@
        if hasattr(style, 'font'):
            write('Fn(%s)\n' % `style.font.PostScriptName()`)
        if hasattr(style, 'font_size'):
            write('Fs(%g)\n' % style.font_size)
+        if hasattr(style, 'script'):
+            write('Fc(%g)\n' % style.script)

    def DynamicStyle(self, style):
        self.write_style(style)
        self.file.write('dstyle(%s)\n' % `style.Name()`)
@@ -607,9 +621,29 @@

    def EndPluginCompound(self):
        self.file.write('PC_()\n')

-
+    def BeginCompoundText(self, width, trafo, halign, valign):
+        if width is None:
+            width = -1
+
+        write = self.file.write
+        write('TC(')
+        if trafo.matrix() != IdentityMatrix:
+            write('(%g,%g,%g,%g,%g,%g)' % trafo.coeff())
+        else:
+            write('(%g,%g)' % (trafo.v1, trafo.v2))
+        write(',%d' % width)
+        if halign or valign:
+            write(',%d,%d' % (halign, valign))
+        write(')\n')
+
+    def EndCompoundText(self):
+        self.file.write('TC_()\n')
+
+    def TextPiece(self, text, align=None):
+        self.file.write('t(%s)\n' % (`text`,))
+
def save(document, file, filename, options = {}):
    saver = SKSaver(file, filename, options)
    document.SaveToFile(saver)

diff -trNa -U 4 -x*afm -x.* -x*pyc -xconfig.c -x*o -xMake* -xSetup -xsedscript* -x*~ -x*arrow* -x *linedlg* sketch-0.6.14_textbox/Sketch/Base/load.py sketch-0.6.14_patched/Sketch/Base/load.py
--- sketch-0.6.14_textbox/Sketch/Base/load.py   Mon Dec  9 18:14:52 2002
+++ sketch-0.6.14_patched/Sketch/Base/load.py   Mon Dec  9 18:15:51 2002
@@ -98,13 +98,15 @@
            args, kw = self.composite_args
            if not kw:
                kw = {}
            composite = apply(self.composite_class, args, kw)
+
            if self.composite_items or composite.can_be_empty:
                append = composite.load_AppendObject
                for item in self.composite_items:
                    if self.check_object(item):
                        append(item)
+
                composite.load_Done()
                self.__pop()
                self.append_object(composite)
            else:
diff -trNa -U 4 -x*afm -x.* -x*pyc -xconfig.c -x*o -xMake* -xSetup -xsedscript* -x*~ -x*arrow* -x *linedlg* sketch-0.6.14_textbox/Sketch/Graphics/textbox.py sketch-0.6.14_patched/Sketch/Graphics/textbox.py --- sketch-0.6.14_textbox/Sketch/Graphics/textbox.py Mon Dec 9 18:14:53 2002 +++ sketch-0.6.14_patched/Sketch/Graphics/textbox.py Mon Dec 9 18:21:25 2002
@@ -46,9 +46,9 @@
from Sketch import main

import handle
import selinfo
-from base import Primitive, RectangularPrimitive, Creator, Editor
+from base import Primitive, RectangularPrimitive, Creator, Editor, Protocols
from group import Group
from bezier import PolyBezier, CombineBeziers
from blend import Blend, MismatchError, BlendTrafo
from properties import PropertyStack, FactoryTextStyle, DefaultTextProperties
@@ -102,9 +102,9 @@
#
# Base class for items in the TextBox.text array.
# Characters, Linebreaks, Tabs, etc derive from this.

-class TextElement:
+class TextElement(Protocols):

    is_break = 0

    def Duplicate(self):
@@ -243,8 +243,16 @@
            if isinstance(self.text[caret],Break):
                return self.text[caret]
        raise "internal error: text[0] should be a Break!"

+    def load_AppendObject(self, obj):
+        self.text.append(obj)
+
+    def load_Done(self):
+        self.typeset()
+        self.update_properties()
+        self._changed()
+
    def SetText(self, start, end, text, caret = None, state = None):
        if self.editor is not None:
            old_state = self.editor.get_state()
        else:
@@ -1302,22 +1310,28 @@

    def FullTrafo(self):
        return self.trafo(self.atrafo)

-    # FIXME
-    # .sk format needs to be extended to support textbox
-    # fully.  for now, just save the blocks as a group of
-    # simpletext objects with the appropriate styles
    def SaveToFile(self, file):
-        trafo = map(self.trafo(self.atrafo),self.block_trafo)
-        file.BeginGroup()
-        for n in range(len(self.blocks)):
-                block = self.blocks[n]
-                text = block[2]
-                style = block[5]
-                style.SaveToFile(file)
-                file.SimpleText(text,trafo[n],0,0)
-        file.EndGroup()
+        file.BeginCompoundText(self.width, self.trafo, self.halign, \
+                               self.valign)
+        text = self.text
+        blocks = self.blocks[:]+ [(None, len(text))]
+        i = 1
+        props = text[0].properties
+        for block in blocks:
+            file.Properties(props)
+            props, next = block[-2:]
+            txt = ''
+            for item in text[i:next]:
+                if item.is_break:
+                    txt = txt +'\n'
+                else:
+                    txt = txt + item.char
+            i = next
+            file.TextPiece(txt)
+        file.EndCompoundText()
+        return

    def Blend(self, other, p, q):
        raise MismatchError

diff -trNa -U 4 -x*afm -x.* -x*pyc -xconfig.c -x*o -xMake* -xSetup -xsedscript* -x*~ -x*arrow* -x *linedlg* sketch-0.6.14_textbox/Sketch/__init__.py sketch-0.6.14_patched/Sketch/__init__.py
--- sketch-0.6.14_textbox/Sketch/__init__.py    Mon Dec  9 18:14:54 2002
+++ sketch-0.6.14_patched/Sketch/__init__.py    Mon Dec  9 18:15:51 2002
@@ -66,8 +66,9 @@


from _sketch import CreatePath, RectanglePath, RoundedRectanglePath, \
     approx_arc, CreateFontMetric, SKCache, TransformRectangle
+SKCache = dict

from _sketch import ContAngle, ContSmooth, ContSymmetrical, \
     SelNone, SelNodes, SelSegmentFirst, SelSegmentLast, Bezier, Line

@@ -167,9 +168,9 @@


from Graphics.text import SimpleText, SimpleTextCreator, PathText

-from Graphics.textbox import TextBox, TextBoxCreator
+from Graphics.textbox import TextBox, TextBoxCreator, Character, Break


def init_lib():
    import plugins







_________________________________________________________________
Messenger  -  Wer in Echtzeit kommunizieren will, lädt den MSN Messenger. Cool, kostenlos und mit 3D Emoticons: http://messenger.msn.de




reply via email to

[Prev in Thread] Current Thread [Next in Thread]