#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
# (c) GPL
# This example is not complete
# 1. the alpha-image segfault.
# 2. the memoryoperations are nyi
IMAGEPATH = "../c/"
import pslib as ps
LEFT_BORDER = 50
EXAMPLE_BOX_HEIGHT = 190
EXAMPLE_BOX_WIDTH = 150
EXAMPLE_BOX_TITLE_HEIGHT = 40
def begin_example_box(p, llx, lly, title, font):
ps.PS_save(p)
ps.PS_translate(p, llx, lly)
ps.PS_setcolor(p, "stroke", "gray", 0.5, 0.0, 0.0, 0.0)
ps.PS_rect(p, 0, EXAMPLE_BOX_HEIGHT-EXAMPLE_BOX_TITLE_HEIGHT,
EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_TITLE_HEIGHT)
ps.PS_fill(p)
ps.PS_setcolor(p, "stroke", "gray", 1.0, 0.0, 0.0, 0.0)
ps.PS_setfont(p, font, 12.0)
ps.PS_show_xy(p, title, 10, EXAMPLE_BOX_HEIGHT-EXAMPLE_BOX_TITLE_HEIGHT+5)
ps.PS_setlinewidth(p, 1.0)
ps.PS_setcolor(p, "stroke", "gray", 0.0, 0.0, 0.0, 0.0)
ps.PS_setcolor(p, "stroke", "gray", 0.0, 0.0, 0.0, 0.0)
ps.PS_rect(p, 0, 0, EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_HEIGHT)
ps.PS_stroke(p)
ps.PS_moveto(p, 0, EXAMPLE_BOX_HEIGHT-EXAMPLE_BOX_TITLE_HEIGHT)
ps.PS_lineto(p, EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_HEIGHT-EXAMPLE_BOX_TITLE_HEIGHT)
ps.PS_stroke(p)
def end_example_box(p):
ps.PS_restore(p)
p1=ps.PS_new()
ps.PS_set_info(p1, "Creator", "Python");
ps.PS_set_info(p1, "Author", "Uwe Steinmann & Stefan Schroeder");
ps.PS_set_info(p1, "Title", "Drawing Examples");
ps.PS_open_file(p1, 'image.ps')
print "Creating image.ps ... ",
ps.PS_begin_page(p1, 596, 842)
ps.PS_set_parameter(p1, "transition", "wipe")
ps.PS_set_value(p1, "duration", 0.5)
psfont = ps.PS_findfont(p1, "Helvetica", "", 0)
ps.PS_setfont(p1, psfont, 8.0);
x = 0
y = 675
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Indexed image without alpha channel", psfont)
x+=1
psimage = ps.PS_open_image_file(p1, "png", IMAGEPATH + "indexed.png", "", 0)
ps.PS_place_image(p1, psimage, 10, 30, 1.0)
ps.PS_close_image(p1, psimage)
end_example_box(p1)
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "RGB image without alpha channel", psfont)
x+=1
psimage = ps.PS_open_image_file(p1, "png", IMAGEPATH + "rgb.png", "", 0)
ps.PS_place_image(p1, psimage, 10, 30, 1.0)
ps.PS_close_image(p1, psimage)
end_example_box(p1)
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Indexed image with alpha channel", psfont)
x+=1
#psimage = ps.PS_open_image_file(p1, "png", IMAGEPATH + "indexed-alpha.png", "", 0)
#ps.PS_place_image(p1, psimage, 10, 30, 1.0)
#ps.PS_close_image(p1, psimage)
end_example_box(p1)
x = 0
y = 405
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "RGB image with alpha channel", psfont)
x+=1
#psimage = ps.PS_open_image_file(p1, "png", IMAGEPATH + "rgb-alpha.png", "", 0)
#ps.PS_place_image(p1, psimage, 10, 30, 1.0)
#ps.PS_close_image(p1, psimage)
end_example_box(p1)
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Jpeg gray scale image", psfont)
x+=1
psimage = ps.PS_open_image_file(p1, "jpeg", IMAGEPATH + "gnu-head.jpg", "", 0)
ps.PS_place_image(p1, psimage, 10, 10, 0.45)
ps.PS_close_image(p1, psimage)
end_example_box(p1)
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Exiftest", psfont)
x+=1
psimage = ps.PS_open_image_file(p1, "jpeg", IMAGEPATH + "exiftest.jpg", "", 0)
ps.PS_place_image(p1, psimage, 30, 10, 0.30)
ps.PS_close_image(p1, psimage)
end_example_box(p1)
x = 0
y = 185
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Images created in memory", psfont)
x+=1
# RGB */
#psimage = ps.PS_open_image(p1, "memory", "memory", imagedata, 12, 2, 2, 3, 8, "")
#ps.PS_place_image(p1, psimage, 20, 20, 20.0)
#ps.close_image(p1, psimage)
# Gray */
#memset(imagedata, 0, 16)
#imagedata[0] = 192
#imagedata[1] = 128
#imagedata[2] = 64
#imagedata[3] = 0
##imagedata = "aaaaaaaaaaaaaaaa"
##psimage = ps.PS_open_image(p1, "memory", "memory", imagedata, 4, 2, 2, 1, 8, "")
##ps.PS_place_image(p1, psimage, 90, 20, 20.0)
# CMYK */
#memset(imagedata, 0, 16)
#imagedata[0] = 255
#imagedata[5] = 255
#imagedata[10] = 255
#imagedata[15] = 255
#imagedata = "aaaaaaaaaaaaaaaa"
#psimage = ps.PS_open_image(p1, "memory", "memory", imagedata, 16, 2, 2, 4, 8, "")
#ps.PS_place_image(p1, psimage, 20, 90, 20.0)
#ps.PS_setfont(p1, psfont, 8.0)
#ps.PS_show_xy(p1, "CMYK", 20, 80)
#ps.PS_show_xy(p1, "RGB", 20, 10)
#ps.PS_show_xy(p1, "Gray", 90, 10)
end_example_box(p1)
# TRAILER
ps.PS_end_page(p1)
ps.PS_close(p1)
ps.PS_delete(p1)
print "Finished."