예제 #1
0
파일: layout.py 프로젝트: imclab/4up
def setup_doc(name):
    '''
    '''
    doc = PDFSurface(name, sheet_width*ptpin, sheet_height*ptpin)
    ctx = Context(doc)
    ctx.scale(ptpin, ptpin)
    
    set_font_face_from_file(ctx, 'DejaVuSerifCondensed.ttf')
    
    return doc, ctx
예제 #2
0
    def __init__(self, filename, width, height):
        """
        """
        self.filename = filename
        self.size = width, height

        handle, dummy_file = mkstemp(prefix='cairoutils-', suffix='.pdf')
        close(handle)

        surface = PDFSurface(dummy_file, width, height)
        self.context = Context(surface)

        self.commands = []
        self.garbage = [dummy_file]
        self.page = []

        self.point = Point(0, 0)
        self.stack = [(1, 0, 0, 0, -1, height)]
        self.affine = Affine(*self.stack[0])
예제 #3
0
def draw_pdf(filename):

    surface = PDFSurface(filename, 320, 240)
    c = cairo.Context(surface)

    c.set_source_rgb(1, 1, 1)
    c.paint()

    c.arc(150, 150, 50, 0, 2 * math.pi)
    c.set_source_rgba(1, 0, 0, 1)
    c.fill()

    surface.show_page()

    c.set_source_rgb(1, 1, 1)
    c.paint()

    c.arc(100, 100, 50, 0, 2 * math.pi)
    c.set_source_rgba(1, 0, 1, 1)
    c.fill()

    surface.show_page()
예제 #4
0
        raise OSError('broken moodbar file: ' + path)

    for rgb in grouper(vector, n=3):
        rgb_values.append(tuple(c / 0xff for c in rgb))

    return list(rgb_values)


if __name__ == '__main__':
    import sys
    if len(sys.argv) < 2:
        print('usage: {} [some_mood_file] [-i some_audio_file]'.format(
            sys.argv[0]))
        sys.exit(-1)

    if '-i' in sys.argv:
        from subprocess import call
        moodbar_file = '/tmp/mood.file'
        call(['moodbar', sys.argv[2], '-o', moodbar_file])
        print('Writing out to', moodbar_file)
    else:
        moodbar_file = sys.argv[1]

    # Read the rgb vector:
    rgb_values = read_moodbar_values(moodbar_file)

    w, h = 1000, 125
    surface = PDFSurface('/tmp/mood.out', w, h)
    draw_moodbar(Context(surface), rgb_values, w, h)
    surface.finish()
예제 #5
0
from cairo import PDFSurface, Context
from math import atan, ceil, cos, pi, sin
from IPython import embed

height = 160
width = 260
canvas_padding = 15

dot_radius = 0.5

surface = PDFSurface('dot_pattern_1.pdf', width + 2 * canvas_padding,
                     height + 2 * canvas_padding)
ctx = Context(surface)

ctx.rectangle(0, 0, width + 2 * canvas_padding, height + 2 * canvas_padding)
ctx.set_source_rgb(1, 1, 1)
ctx.fill()

num_full_arc_rings = 8
max_num_filler_arc_rings = 9
dot_padding = 1
ring_padding = 1

pattern_radius = num_full_arc_rings * (2 * dot_radius + ring_padding)

max_arc_radius = (num_full_arc_rings - 1) * (dot_radius * 2 + ring_padding)


def draw_dot(x, y):

    ctx.arc(x, y, dot_radius, 0, 2 * pi)
예제 #6
0
    if len(vector) is 0:
        raise OSError('broken moodbar file: ' + path)

    for rgb in grouper(vector, n=3):
        rgb_values.append(tuple(c / 0xff for c in rgb))

    return list(rgb_values)


if __name__ == '__main__':
    import sys
    if len(sys.argv) < 2:
        print('usage: {} [some_mood_file] [-i some_audio_file]'.format(sys.argv[0]))
        sys.exit(-1)

    if '-i' in sys.argv:
        from subprocess import call
        moodbar_file = '/tmp/mood.file'
        call(['moodbar', sys.argv[2], '-o', moodbar_file])
        print('Writing out to', moodbar_file)
    else:
        moodbar_file = sys.argv[1]

    # Read the rgb vector:
    rgb_values = read_moodbar_values(moodbar_file)

    w, h = 1000, 125
    surface = PDFSurface('/tmp/mood.out', w, h)
    draw_moodbar(Context(surface), rgb_values, w, h)
    surface.finish()
예제 #7
0
def main(marker, paper, format, bbox, emergency, place, recipient, sender, text, sender_is_recipient, map_href):
    """
    """
    mark = Location(*marker)
    
    handle, filename = mkstemp(prefix='safetymap-', suffix='.pdf')
    close(handle)

    if paper == 'a4':
        surf = PDFSurface(filename, 210*ptpmm, 297*ptpmm)
    
    elif paper == 'letter':
        surf = PDFSurface(filename, 8.5*ptpin, 11*ptpin)
    
    ctx = Context(surf)
    
    ctx.scale(ptpmm, ptpmm)

    set_font_face_from_file(ctx, 'assets/HelveticaNeue.ttc')
    
    if paper == 'a4':
        draw_a4_master(ctx, format, map_href)
        ctx.translate(19, 24)
    
    elif paper == 'letter':
        draw_letter_master(ctx, format, map_href)
        ctx.translate(21, 18)

    ctx.set_line_width(.25 * mmppt)
    ctx.set_source_rgb(*md_gray)
    ctx.set_dash([3 * mmppt])

    reps = {'4up': 4, '2up-fridge': 2, 'poster': 0}
    
    if reps[format]:
        card_img, mark_point = get_map_image(bbox, 84, 39, mark)
        
    for i in range(reps[format]):
    
        # dashed outlines
        ctx.move_to(0, 61)
        ctx.line_to(0, 0)
        ctx.line_to(173, 0)
        ctx.line_to(173, 61)
        #ctx.move_to(86, 0)
        #ctx.line_to(86, 61)
        ctx.stroke()
    
        # two card sides and contents
        draw_card_left(ctx, recipient, sender, text, sender_is_recipient)
        ctx.translate(86.5, 0)

        draw_card_right(ctx, card_img, mark_point, emergency, place)
        ctx.translate(-86.5, 61)

    if format == '4up':
        # bottom dashed outline
        ctx.move_to(0, 0)
        ctx.line_to(172, 0)
        ctx.stroke()

    elif format == '2up-fridge':
        # prepare to draw sideways
        ctx.translate(0, 122.5)
        ctx.rotate(-pi/2)

        ctx.rectangle(0, 0, 122.5, 173)
        ctx.stroke()

        poster_img, mark_point = get_map_image(bbox, 109, 77, mark)
        draw_small_poster(ctx, poster_img, mark_point, emergency, place, recipient, sender, text, sender_is_recipient)

    elif format == 'poster':
        ctx.rectangle(0, 0, 173, 245)
        ctx.stroke()

        poster_img, mark_point = get_map_image(bbox, 153, 108, mark)
        draw_large_poster(ctx, poster_img, mark_point, emergency, place, recipient, sender, text, sender_is_recipient)

    surf.finish()
    chmod(filename, 0644)
    return filename