<｜begin▁of▁sentence｜>### Instruction:
As a software developer tasked with designing a graphics application, you've been asked to implement a feature that allows users to input text onto a canvas using Cairo graphics library. The challenge is to devise a method to calculate the layout for the text starting from a specific point on the canvas, while adhering to width constraints. Additionally, users should have the option to enable text wrapping if the text exceeds the specified width. How would you go about integrating this functionality into your application using Cairo's API?
### Response:
from igraph.drawing.text import CairoTextDrawer
import cairo

# Create a cairo surface and context
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 600, 50)
context = cairo.Context(surface)

text_drawer = CairoTextDrawer(context, halign='left')
layout = text_drawer.get_text_layout("This is a sample text", x=50, y=20, width=200, wrap=True)

# Print the calculated text layouts
for x, y, line in layout:
    print(f'Text at ({x}, {y}): {line}')

# Save the surface to a file
surface.write_to_png('text_layout.png')
<|EOT|>
