コード例 #1
0
def draw2(ctx, pixel_width, pixel_height, frame_no, frame_count):

    width = 32
    setup(ctx, pixel_width, pixel_height, width=width, startx=-width/2, starty=-width/2, background=Color(1))

    a = 14
    b = 6
    d = 4
    angle = 1

    Origin = (0, 0)
    A = (-a, 0)
    B = ((a-b)*math.cos(angle), (a-b)*math.sin(angle))
    x = (a - b) * math.cos(angle) + d * math.cos((a - b) / b * angle)
    y = (a - b) * math.sin(angle) - d * math.sin((a - b) / b * angle)
    D = (x, y)

    Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(Color('skyblue'), line_width=0.1)
    Polygon(ctx).of_points(create_spiro(a, b, d, 0.01, angle)).open().stroke(Color('red'), line_width=0.1)

    Circle(ctx).of_center_radius(Origin, a).stroke(Color('darkgreen'), line_width=0.1)
    Circle(ctx).of_center_radius(Origin, 0.3).fill(Color('darkgreen'))
    Line(ctx).of_start_end(Origin, A).stroke(Color('darkgreen'), line_width=0.1)
    Text(ctx).of('a', (A[0]/2, A[1])).size(1.5).offset(0, -0.5).fill(Color('darkgreen'))
    Circle(ctx).of_center_radius(B, b).stroke(Color('blue'), line_width=0.1)
    Circle(ctx).of_center_radius(B, 0.3).fill(Color('blue'))
    Text(ctx).of('b', (B[0], B[1]+b/2)).size(1.5).offset(0.5, 0).fill(Color('blue'))
    Line(ctx).of_start_end(B, (B[0], B[1]+b)).stroke(Color('blue'), line_width=0.1)
    Circle(ctx).of_center_radius(D, 0.3).fill(Color('black'))
    Line(ctx).of_start_end(B, D).stroke(Color('black'), line_width=0.1)
    Text(ctx).of('d', ((B[0]+D[0])/2, (B[1]+D[1])/2)).size(1.5).offset(0.5, 0.5).fill(Color('black'))
コード例 #2
0
ファイル: markers.py プロジェクト: martinmcbride/generativepy
def draw3(ctx, pixel_width, pixel_height, frame_no, frame_count):
    setup(ctx, pixel_width, pixel_height, width=10, background=Color(0.8))

    a = (1, 2)
    b = (7, 2)
    c = (3, 8)
    d = (9, 8)
    e = (5, 2)
    f = (5, 8)

    Polygon(ctx).of_points([a, b, d, c]).stroke(Color('blue'), line_width=.05)

    ParallelMarker(ctx).of_start_end(
        a,
        b).with_length(.5).with_count(2).with_gap(0.15).stroke(Color('blue'),
                                                               line_width=.05)
    ParallelMarker(ctx).of_start_end(
        c,
        d).with_length(.5).with_count(2).with_gap(0.15).stroke(Color('blue'),
                                                               line_width=.05)
    ParallelMarker(ctx).of_start_end(a,
                                     c).with_length(.5).stroke(Color('blue'),
                                                               line_width=.05)
    ParallelMarker(ctx).of_start_end(b,
                                     d).with_length(.5).stroke(Color('blue'),
                                                               line_width=.05)

    Text(ctx).of('a', a).size(1).offset_towards(d, -0.5).fill(Color('red'))
    Text(ctx).of('b', b).size(1).offset_towards(c, -0.5).fill(Color('red'))
    Text(ctx).of('c', c).size(1).offset_towards(b, -0.9).fill(Color('red'))
    Text(ctx).of('d', d).size(1).offset_towards(a, -0.5).fill(Color('red'))
コード例 #3
0
def show_bezier_labels(ctx, a, b, c, d):
    grey = Color(0.2)
    thickness = 2
    show_bezier_points(ctx, a, b, c, d)
    Text(ctx).of('a', a).size(20).align_center().align_middle().offset_towards(b, -20).fill(grey)
    Text(ctx).of('b', b).size(20).align_center().align_middle().offset_towards(a, -20).fill(grey)
    Text(ctx).of('c', c).size(20).align_center().align_middle().offset_towards(d, -20).fill(grey)
    Text(ctx).of('d', d).size(20).align_center().align_middle().offset_towards(c, -20).fill(grey)
コード例 #4
0
        def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
            setup(ctx, pixel_width, pixel_height, background=Color(1))

            Circle(ctx).of_center_radius((200, 200), 10).fill(Color('red'))
            Circle(ctx).of_center_radius((100, 150), 10).fill(Color('blue'))
            Text(ctx).of('A', (200, 200)).font('Arial').size(40).fill(Color(0))
            Text(ctx).of('B', (200, 200)).font('Arial').offset(100, 20).size(40).fill(Color(0))
            Text(ctx).of('C', (200, 200)).font('Arial').offset_angle(1, 150).size(40).fill(Color(0))
            Text(ctx).of('D', (200, 200)).font('Arial').offset_towards((100, 150), 50).size(40).fill(Color(0))
コード例 #5
0
def draw(ctx, width, height, frame_no, frame_count):
    setup(ctx, width, height, width=800, background=Color(0.8))

    image1, size1 = rasterise_formula("cosh-formula",
                                      r"\cosh{x} = \frac{e^{x}+e^{-x}}{2}",
                                      Color("dodgerblue"))
    image2, size2 = rasterise_formula("quadratic",
                                      r"x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}",
                                      Color("crimson"),
                                      dpi=400)
    Image(ctx).of_file_position(image1, (50, 50)).paint()
    Text(ctx).of("Size1 = " + str(size1), (50, 500)).size(20).fill(Color(0))
    Image(ctx).of_file_position(image2, (50, 300)).paint()
    Text(ctx).of("Size2 = " + str(size2), (250, 500)).size(20).fill(Color(0))
コード例 #6
0
def draw(ctx, width, height, frame_no, frame_count):
    setup(ctx, width, height, width=5, background=Color(0.8))

    # Get a polygon path object
    path1 = Polygon(ctx).of_points([(0, 0), (1, 1), (0.5, 2), (0.5, 1)])\
	                    .path()

    # Get a text path object
    path2 = Text(ctx).of("Path text", (0, 0)).font("Times").size(0.2)\
	                 .align_left().align_top().path()

    # Apply the polygon in various places
    with Transform(ctx).translate(0.5, 1):
        Path(ctx).of(path1).stroke(Color('darkgreen'), 0.1)

    with Transform(ctx).translate(1, 2.5):
        Path(ctx).of(path1).fill(Color('blue'))

    with Transform(ctx).translate(2.5, 0.5).scale(2, 2):
        Path(ctx).of(path1).fill(Color('orange')).stroke(Color('black'), 0.05)

    # Apply the text in various places
    with Transform(ctx).translate(0, 0):
        Path(ctx).of(path2).fill(Color('black'))

    with Transform(ctx).translate(2, 3):
        Path(ctx).of(path2).stroke(Color('red'), 0.01)

    with Transform(ctx).translate(2, 4).scale(2, 2):
        Path(ctx).of(path2).fill(Color('yellow')).stroke(Color('black'), 0.01)
コード例 #7
0
 def draw(ctx, width, height, frame_no, frame_count):
     setup(ctx, width, height, background=Color(0.8))
     image, size = rasterise_formula(
         "formula-test-temp", r"\cosh{x} = \frac{e^{x}+e^{-x}}{2}",
         Color("dodgerblue"))
     Image(ctx).of_file_position(image, (50, 50)).paint()
     Text(ctx).of("Size = " + str(size),
                  (50, 300)).size(20).fill(Color(0))
コード例 #8
0
def draw4(ctx, pixel_width, pixel_height, frame_no, frame_count):

    setup(ctx, pixel_width, pixel_height, background=Color(0.8))

    blue = Color('blue')
    grey = Color(0.2)
    thickness = 2

    a0 = (50, 200)
    b0 = (100, 200)
    c0 = (100, 50)
    d0 = (200, 50)
    a1 = (200, 50)
    b1 = (300, 50)
    c1 = (350, 220)
    d1 = (450, 200)
    points = [a0, (*b0, *c0, *d0), (*b1, *c1, *d1)]
    Polygon(ctx).of_points(points).open().stroke(blue, thickness)

    show_bezier_points(ctx, (50, 200), (100, 200), (100, 50), (200, 50))
    show_bezier_points(ctx, (200, 50), (300, 50), (350, 220), (450, 200))

    Text(ctx).of('a0', a0).size(20).align_center().align_middle().offset_towards(b0, -20).fill(grey)
    Text(ctx).of('b0', b0).size(20).align_center().align_middle().offset_towards(a0, -20).fill(grey)
    Text(ctx).of('c0', c0).size(20).align_center().align_middle().offset_towards(d0, -20).fill(grey)
    Text(ctx).of('d0/a1', d0).size(20).align_center().align_middle().offset(0, -20).fill(grey)
    Text(ctx).of('b1', b1).size(20).align_center().align_middle().offset_towards(a1, -20).fill(grey)
    Text(ctx).of('c1', c1).size(20).align_center().align_middle().offset_towards(d1, -20).fill(grey)
    Text(ctx).of('d1', d1).size(20).align_center().align_middle().offset_towards(c1, -20).fill(grey)
コード例 #9
0
 def draw(ctx, width, height, frame_no, frame_count):
     setup(ctx, width, height, background=Color(0.8))
     image, size = rasterise_formula(
         "formula-test-temp",
         r"x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}",
         Color("crimson"),
         dpi=400)
     Image(ctx).of_file_position(image, (50, 50)).paint()
     Text(ctx).of("Size = " + str(size),
                  (50, 300)).size(20).fill(Color(0))
コード例 #10
0
 def test_text_extent(self):
     surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 100, 200)
     ctx = cairo.Context(surface)
     x_bearing, y_bearing, width, height, x_advance, y_advance = Text(ctx).of('abc', (0, 0)).get_metrics()
     self.assertAlmostEqual(x_bearing, 0)
     self.assertAlmostEqual(y_bearing, -7)
     self.assertAlmostEqual(width, 17)
     self.assertAlmostEqual(height, 7)
     self.assertAlmostEqual(x_advance, 17)
     self.assertAlmostEqual(y_advance, 0)
コード例 #11
0
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):

    setup(ctx, pixel_width, pixel_height, background=Color(0.8))

    blue = Color('blue')
    red = Color('red')
    green = Color('green')
    thickness = 4

    Text(ctx).of('F', (40, 100)).size(100).fill(blue)
    Line(ctx).of_start_end((100, 20), (100, 110)).stroke(green, thickness)

    with Transform(ctx).scale(-1, 1, (100, 0)):
        Text(ctx).of('F', (40, 100)).size(100).fill(red)

    Text(ctx).of('W', (240, 100)).size(100).fill(blue)
    Line(ctx).of_start_end((240, 70), (340, 70)).stroke(green, thickness)

    with Transform(ctx).scale(1, -1, (0, 60)):
        Text(ctx).of('W', (240, 100)).size(100).fill(red.with_a(0.6))
コード例 #12
0
ファイル: markers.py プロジェクト: martinmcbride/generativepy
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
    setup(ctx, pixel_width, pixel_height, width=10, background=Color(0.8))

    a = (1, 2)
    b = (7, 2)
    c = (3, 8)
    d = (9, 8)
    e = (5, 2)
    f = (5, 8)

    Polygon(ctx).of_points([a, b, d, c]).stroke(Color('blue'), line_width=.05)
    Line(ctx).of_start_end(e, f).stroke(Color('blue'), line_width=.05)

    AngleMarker(ctx).of_points(
        b, a,
        c).with_radius(.5).with_count(2).with_gap(0.15).stroke(Color('blue'),
                                                               line_width=.05)
    AngleMarker(ctx).of_points(a, b, d).with_radius(.5).stroke(Color('blue'),
                                                               line_width=.05)
    AngleMarker(ctx).of_points(
        c, d,
        b).with_radius(.5).with_count(2).with_gap(0.15).stroke(Color('blue'),
                                                               line_width=.05)
    AngleMarker(ctx).of_points(a, c, d).with_radius(.5).stroke(Color('blue'),
                                                               line_width=.05)
    AngleMarker(ctx).of_points(
        e, f, d).with_radius(.5).as_right_angle().stroke(Color('blue'),
                                                         line_width=.05)

    Text(ctx).of('a', a).size(1).offset_towards(d, -0.5).fill(Color('red'))
    Text(ctx).of('b', b).size(1).offset_towards(c, -0.9).fill(Color('red'))
    Text(ctx).of('c', c).size(1).offset_towards(b, -0.9).fill(Color('red'))
    Text(ctx).of('d', d).size(1).offset_towards(a, -0.5).fill(Color('red'))
    Text(ctx).of('e', e).size(1).offset_towards(f, -0.3).fill(Color('red'))
    Text(ctx).of('f', f).size(1).offset_towards(e, -0.9).fill(Color('red'))
コード例 #13
0
        def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
            setup(ctx,
                  pixel_width,
                  pixel_height,
                  width=5,
                  background=Color(0.8))

            # Get a polygon path object
            path1 = Polygon(ctx).of_points([(0, 0), (1, 1), (0.5, 2),
                                            (0.5, 1)]).path()

            # Get a text path object
            path2 = Text(ctx).of("Path text", (0, 0)).font(
                "Times", weight=FONT_WEIGHT_BOLD).size(
                    0.2).align_left().align_top().path()

            # Apply the polygon in various places
            ctx.save()
            ctx.translate(0.5, 1)
            Path(ctx).of(path1).stroke(Color('darkgreen'), 0.1)
            ctx.restore()

            ctx.save()
            ctx.translate(1, 2.5)
            Path(ctx).of(path1).fill(Color('blue'))
            ctx.restore()

            ctx.save()
            ctx.translate(2.5, 0.5)
            ctx.scale(2, 2)
            Path(ctx).of(path1).fill(Color('orange')).stroke(
                Color('black'), 0.05)
            ctx.restore()

            # Apply the text in various places
            ctx.save()
            ctx.translate(0, 0)
            Path(ctx).of(path2).fill(Color('black'))
            ctx.restore()

            ctx.save()
            ctx.translate(2, 3)
            Path(ctx).of(path2).stroke(Color('red'), 0.01)
            ctx.restore()

            ctx.save()
            ctx.translate(2, 4)
            ctx.scale(2, 2)
            Path(ctx).of(path2).fill(Color('yellow')).stroke(
                Color('black'), 0.01)
            ctx.restore()
コード例 #14
0
def draw(ctx, width, height, frame_no, frame_count):
    setup(ctx, width, height, background=Color(0.8))

    # Create a circular clip region and draw some squares in it
    with Transform(ctx):
        Circle(ctx).of_center_radius((190, 190), 100).clip()
        Square(ctx).of_corner_size((100, 100), 80).fill(Color('red'))
        Square(ctx).of_corner_size((100, 200), 80).fill(Color('green'))
        Square(ctx).of_corner_size((200, 100), 80).fill(Color('blue'))
        Square(ctx).of_corner_size((200, 200), 80).fill(Color('black'))

    with Transform(ctx):
        Text(ctx).of("ABC", (150, 350)).font("Times").size(150).align_left().align_top().clip()
        circles = [(200, 380, 'orange'), (200, 450, 'cyan'), (300, 380, 'green'),
                   (300, 450, 'purple'), (400, 380, 'yellow'), (400, 450, 'blue')]
        for x, y, color in circles:
            Circle(ctx).of_center_radius((x, y), 70).fill(Color(color))
コード例 #15
0
        def draw(ctx, width, height, frame_no, frame_count):
            setup(ctx, width, height, width=5, background=Color(0.8))

            # Create a circular clip region and draw some squares in it
            ctx.save()
            Circle(ctx).of_center_radius((1.9, 1.9), 1).clip()
            Square(ctx).of_corner_size((1, 1), .8).fill(Color('red'))
            Square(ctx).of_corner_size((1, 2), .8).fill(Color('green'))
            Square(ctx).of_corner_size((2, 1), .8).fill(Color('blue'))
            Square(ctx).of_corner_size((2, 2), .8).fill(Color('black'))
            ctx.restore()

            ctx.save()
            Text(ctx).of("ABC", (1.5, 3.5)).font("Times", weight=FONT_WEIGHT_BOLD).size(1.5).align_left().align_top().clip()
            circles = [(2, 3.8, 'orange'), (2, 4.5, 'cyan'), (3, 3.8, 'green'),
                       (3, 4.5, 'purple'), (4, 3.8, 'yellow'), (4, 4.5, 'blue')]
            for x, y, color in circles:
                Circle(ctx).of_center_radius((x, y), 0.7).fill(Color(color))
            ctx.restore()
コード例 #16
0
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
    setup(ctx, pixel_width, pixel_height, background=Color(1))

    Text(ctx).of("Filled Times",
                 (100, 100)).font("Times").size(40).fill(Color('blue'))
    Text(ctx).of("Filled Arial",
                 (100, 150)).font("Arial").size(40).fill(Color('red'))
    Text(ctx).of("Small",
                 (100, 180)).font("Arial").size(20).fill(Color('darkgreen'))
    Text(ctx).of("Large",
                 (100, 240)).font("Arial").size(60).fill(Color('magenta'))
    Text(ctx).of("Stroke",
                 (100, 310)).font("Arial").size(60).stroke(Color('black'), 4)
    Text(ctx).of("Fill Stroke", (100, 380)).font("Arial").size(60)\
                                           .fill(Color('blue')).stroke(Color('red'), 2)
    Text(ctx).of("Dashed",
                 (100, 450)).font("Arial").size(60).stroke(Color('black'),
                                                           3,
                                                           dash=[4])
コード例 #17
0
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
    setup(ctx, pixel_width, pixel_width, background=Color(0.8))

    x, y = 50, 100
    text = Text(ctx).of("Text size",
                        (x, y)).font("Times").size(100).fill(Color('blue'))
    width, height = text.get_size()
    Text(ctx).of('{} by {}'.format(width, height), (x+400, y))\
        .font("Times").size(40).fill(Color('black'))

    x, y = 50, 200
    text = Text(ctx).of("xyz",
                        (x, y)).font("Times").size(100).fill(Color('blue'))
    width, height = text.get_size()
    Text(ctx).of('{} by {}'.format(width, height), (x+400, y))\
        .font("Times").size(40).fill(Color('black'))

    x, y = 50, 300
    text = Text(ctx).of("Text extents",
                        (x, y)).font("Times").size(100).fill(Color('blue'))
    x_bearing, y_bearing, width, height, x_advance, y_advance = text.get_metrics(
    )
    Rectangle(ctx).of_corner_size((x + x_bearing, y + y_bearing), width,
                                  height).stroke(Color('red'))

    x, y = 50, 400
    text = Text(ctx).of("xyz",
                        (x, y)).font("Times").size(100).fill(Color('blue'))
    x_bearing, y_bearing, width, height, x_advance, y_advance = text.get_metrics(
    )
    Rectangle(ctx).of_corner_size((x + x_bearing, y + y_bearing), width,
                                  height).stroke(Color('red'))

    x, y = 300, 400
    text = Text(ctx).of("'''",
                        (x, y)).font("Times").size(100).fill(Color('blue'))
    x_bearing, y_bearing, width, height, x_advance, y_advance = text.get_metrics(
    )
    Rectangle(ctx).of_corner_size((x + x_bearing, y + y_bearing), width,
                                  height).stroke(Color('red'))
コード例 #18
0
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
    setup(ctx, pixel_width, pixel_width, background=Color(0.8))

    Text(ctx).of(
        "Left",
        (50, 50)).font("Times").size(20).align_left().align_baseline().fill(
            Color('blue'))
    Text(ctx).of(
        "Aligned",
        (50, 70)).font("Times").size(20).align_left().align_baseline().fill(
            Color('red'))
    Text(ctx).of(
        "Text",
        (50, 90)).font("Times").size(20).align_left().align_baseline().fill(
            Color('blue'))

    Text(ctx).of(
        "Centre",
        (250, 50)).font("Times").size(20).align_center().align_baseline().fill(
            Color('blue'))
    Text(ctx).of(
        "Aligned",
        (250, 70)).font("Times").size(20).align_center().align_baseline().fill(
            Color('red'))
    Text(ctx).of(
        "Text",
        (250, 90)).font("Times").size(20).align_center().align_baseline().fill(
            Color('blue'))

    Text(ctx).of(
        "Right",
        (450, 50)).font("Times").size(20).align_right().align_baseline().fill(
            Color('blue'))
    Text(ctx).of(
        "Aligned",
        (450, 70)).font("Times").size(20).align_right().align_baseline().fill(
            Color('red'))
    Text(ctx).of(
        "Text",
        (450, 90)).font("Times").size(20).align_right().align_baseline().fill(
            Color('blue'))

    Circle(ctx).of_center_radius((190, 200), 2).fill(Color(0, 0, 1))
    Text(ctx).of(
        "gTop",
        (200, 200)).font("Times").size(20).align_left().align_top().fill(
            Color('black'))

    Circle(ctx).of_center_radius((190, 250), 2).fill(Color(0, 0, 1))
    Text(ctx).of(
        "gMid",
        (200, 250)).font("Times").size(20).align_left().align_middle().fill(
            Color('black'))

    Circle(ctx).of_center_radius((190, 300), 2).fill(Color(0, 0, 1))
    Text(ctx).of(
        "gBase",
        (200, 300)).font("Times").size(20).align_left().align_baseline().fill(
            Color('black'))

    Circle(ctx).of_center_radius((190, 350), 2).fill(Color(0, 0, 1))
    Text(ctx).of(
        "gBottom",
        (200, 350)).font("Times").size(20).align_left().align_bottom().fill(
            Color('black'))
コード例 #19
0
        def draw(ctx, width, height, frame_no, frame_count):
            setup(ctx, width, height, width=500, background=Color(0.8))

            with Transform(ctx) as transform:
                Text(ctx).of('A', (10, 100)).size(80).fill(Color('blue'))

            Text(ctx).of('B', (110, 100)).size(80).fill(Color('black'))
            with Transform(ctx) as transform:
                transform.scale(0.75, 1.5)
                Text(ctx).of('B', (110, 100)).size(80).fill(Color('blue', 0.5))

            Text(ctx).of('C', (210, 100)).size(80).fill(Color('black'))
            Circle(ctx).of_center_radius((250, 80), 5).fill(Color('red'))
            with Transform(ctx).scale(0.75, 1.5, (250, 80)):
                Text(ctx).of('C', (210, 100)).size(80).fill(Color('blue', 0.5))

            Text(ctx).of('D', (110, 200)).size(80).fill(Color('black'))
            with Transform(ctx) as transform:
                transform.translate(20, 30)
                Text(ctx).of('D', (110, 200)).size(80).fill(Color('blue', 0.5))

            Text(ctx).of('E', (110, 300)).size(80).fill(Color('black'))
            with Transform(ctx) as transform:
                transform.rotate(0.1)
                Text(ctx).of('E', (110, 300)).size(80).fill(Color('blue', 0.5))

            Text(ctx).of('F', (210, 300)).size(80).fill(Color('black'))
            Circle(ctx).of_center_radius((250, 80), 5).fill(Color('red'))
            with Transform(ctx).rotate(0.1, (210, 300)):
                Text(ctx).of('F', (210, 300)).size(80).fill(Color('blue', 0.5))

            Text(ctx).of('G', (210, 400)).size(80).fill(Color('black'))
            Circle(ctx).of_center_radius((250, 80), 5).fill(Color('red'))
            with Transform(ctx).matrix([1, 0.5, 0, 1, 0, 0]):
                Text(ctx).of('G', (210, 400)).size(80).fill(Color('blue', 0.5))
コード例 #20
0
        def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
            setup(ctx,
                  pixel_width,
                  pixel_height,
                  width=5,
                  background=Color(0.8))

            Text(ctx).of("Left", (0.5, 0.5)).font("Times").size(
                0.2).align_left().align_baseline().fill(Color('blue'))
            Text(ctx).of("Aligned", (0.5, 0.7)).font("Times").size(
                0.2).align_left().align_baseline().fill(Color('red'))
            Text(ctx).of("Text", (0.5, 0.9)).font("Times").size(
                0.2).align_left().align_baseline().fill(Color('blue'))

            Text(ctx).of("Centre", (2.5, 0.5)).font("Times", weight=FONT_WEIGHT_BOLD).size(0.2)\
                     .align_center().align_baseline().fill(Color('blue'))
            Text(ctx).of("Aligned", (2.5, 0.7)).font("Times", weight=FONT_WEIGHT_BOLD).size(0.2)\
                     .align_center().align_baseline().fill(Color('red'))
            Text(ctx).of("Text", (2.5, 0.9)).font("Times", weight=FONT_WEIGHT_BOLD).size(0.2)\
                     .align_center().align_baseline().fill(Color('blue'))

            Text(ctx).of("Right", (4.5, 0.5)).font("Times", slant=FONT_SLANT_ITALIC).size(0.2)\
                     .align_right().align_baseline().fill(Color('blue'))
            Text(ctx).of("Aligned", (4.5, 0.7)).font("Times", slant=FONT_SLANT_ITALIC).size(0.2)\
                     .align_right().align_baseline().fill(Color('red'))
            Text(ctx).of("Text", (4.5, 0.9)).font("Times", slant=FONT_SLANT_ITALIC).size(0.2)\
                     .align_right().align_baseline().fill(Color('blue'))

            Circle(ctx).of_center_radius((1.9, 2), 0.02).fill(Color(0, 0, 1))
            Text(ctx).of(
                "gTop",
                (2, 2)).font("Times").size(0.2).align_left().align_top().fill(
                    Color('black'))

            Circle(ctx).of_center_radius((1.9, 2.5), 0.02).fill(Color(0, 0, 1))
            Text(ctx).of("gMid", (
                2,
                2.5)).font("Times").size(0.2).align_left().align_middle().fill(
                    Color('black'))

            Circle(ctx).of_center_radius((1.9, 3), 0.02).fill(Color(0, 0, 1))
            Text(ctx).of("gBase", (
                2,
                3)).font("Times").size(0.2).align_left().align_baseline().fill(
                    Color('black'))

            Circle(ctx).of_center_radius((1.9, 3.5), 0.02).fill(Color(0, 0, 1))
            Text(ctx).of("gBottom", (
                2,
                3.5)).font("Times").size(0.2).align_left().align_bottom().fill(
                    Color('black'))
コード例 #21
0
 def test_text_size(self):
     surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 100, 200)
     ctx = cairo.Context(surface)
     width, height = Text(ctx).of('abc', (0, 0)).get_size()
     self.assertAlmostEqual(width, 17)
     self.assertAlmostEqual(height, 7)