Commits

Matthew Turk committed 5e400d3

A bit more progress in making things available. The hello_world script now
works -- missed a 'path'. Added white and black background slides.

Comments (0)

Files changed (4)

examples/hello_world.py

 import os
 
-from vanhoek.api import Slide, Presentation
+from vanhoek.api import \
+    Slide, WhiteSlide, Presentation
 import vanhoek.primitives.api as primitives
 import vanhoek.backends.api as backends
 
 presentation = Presentation()
 
-s1 = Slide([
-    primitives.TextObject("Hi!", (0, 100)),
-    primitives.TextObject("Hello", (300, 300))
+s1 = WhiteSlide([
+    primitives.TextObject("Hello", (0, 100)),
+    primitives.TextObject("world", (300, 300), (0.0, 1.0, 0.0, 1.0)),
+    primitives.TextObject("!", (600, 500), (1.0, 0.0, 0.0, 1.0))
 ])
 
 presentation.append(s1)
 
-if not os.isdir("output"): os.mkdir("output")
+if not os.path.isdir("output"): os.mkdir("output")
 output = backends.PNGWriter("output/slide_%04i.png")
 presentation.display(output)
-from .slide import Slide
+from .slide import Slide, WhiteSlide
 from .presentation import Presentation

vanhoek/primitives/text.py

 import cairo
+try:
+    from ._freetype_fonts import create_cairo_font_face_for_file
+except ImportError:
+    print "FreeType not available."
 
 class TextObject(object):
-    def __init__(self, text, position):
+    def __init__(self, text, position, color = (0.0,0.0,0.0,1.0)):
         self.text = text
         self.position = position
+        self.color = color
 
     def render(self, context):
+        context.set_source_rgba(*self.color)
         context.move_to(self.position[0], self.position[1])
         context.select_font_face("Sans")
+        context.set_font_size(80)
         context.show_text(self.text)
         for primitive in self.primitives:
             primitive.render(context)
 
-    
+class WhiteSlide(Slide):
+    def setup_slide(self, context):
+        context.set_source_rgba(1.0, 1.0, 1.0, 1.0)
+        context.paint()
+
+class BlackSlide(Slide):
+    def setup_slide(self, context):
+        context.set_source_rgba(0.0, 0.0, 0.0, 1.0)
+        context.paint()