code: def draw_text(
      canvas,
      layout,
      arrangement: str = "lr",
      font_size: Optional[int] = None,
      font_path: Optional[str] = None,
      text_color: Optional[str] = None,
      text_background_color: Optional[str] = None,
      text_background_alpha: Optional[float] = None,
      vertical_text: bool = False,
      with_box_on_text: bool = False,
      text_box_width: Optional[int] = None,
      text_box_color: Optional[str] = None,
      text_box_alpha: Optional[float] = None,
      with_layout: bool = False,
      **kwargs,
  ):
      """Draw the (detected) text in the `layout` according to
      their coordinates next to the input `canvas` (image) for better comparison.
  
      Args:
          canvas (:obj:`~np.ndarray` or :obj:`~PIL.Image.Image`):
              The canvas to draw the layout boxes.
          layout (:obj:`Layout` or :obj:`list`):
              The layout of the canvas to show.
          arrangement (`{'lr', 'ud'}`, optional):
              The arrangement of the drawn text canvas and the original
              image canvas:
              * `lr` - left and right
              * `ud` - up and down
              Defaults to 'lr'.
          font_size (:obj:`str`, optional):
              Set to change the size of the font used for
              drawing `block.text`.
              Defaults to None, when the size is set to
              :const:`DEFAULT_FONT_SIZE`.
          font_path (:obj:`str`, optional):
              Set to change the font used for drawing `block.text`.
              Defaults to None, when the :const:`DEFAULT_FONT_OBJECT` is used.
          text_color ([type], optional):
              Set to change the text color used for drawing `block.text`.
              Defaults to None, when the color is set to
              :const:`DEFAULT_TEXT_COLOR`.
          text_background_color ([type], optional):
              Set to change the text region background used for drawing
              `block.text`.
              Defaults to None, when the color is set to
              :const:`DEFAULT_TEXT_BACKGROUND`.
          text_background_alpha (:obj:`float`, optional):
              A float range from 0 to 1. Set to change the alpha of the
              background of the canvas.
              Defaults to 1 - the text box will be solid.
          vertical_text (bool, optional):
              Whether the text in a block should be drawn vertically.
              Defaults to False.
          with_box_on_text (bool, optional):
              Whether to draw the layout box boundary of a text region
              on the text canvas.
              Defaults to False.
          text_box_width (:obj:`int`, optional):
              Set to change the width of the drawn layout box boundary.
              Defaults to None, when the boundary is automatically
              calculated as the the :const:`DEFAULT_BOX_WIDTH_RATIO`
              * the maximum of (height, width) of the canvas.
          text_box_alpha (:obj:`float`, optional):
              A float range from 0 to 1. Set to change the alpha of the
              drawn text box.
              Defaults to 0 - the text box will be fully transparent.
          text_box_color (:obj:`int`, optional):
              Set to change the color of the drawn layout box boundary.
              Defaults to None, when the color is set to
              :const:`DEFAULT_OUTLINE_COLOR`.
          with_layout (bool, optional):
              Whether to draw the layout boxes on the input (image) canvas.
              Defaults to False.
              When set to true, you can pass in the arguments in
              :obj:`draw_box` to change the style of the drawn layout boxes.
  
      Returns:
          :obj:`PIL.Image.Image`:
              A Image object containing the drawn text from `layout`.
      """
  
      if text_background_alpha is None:
          text_background_alpha = 1
      if text_box_alpha is None:
          text_box_alpha = 0
  
      assert 0 <= text_background_alpha <= 1, ValueError(
          f"The text_background_color value {text_background_alpha} is not within range [0,1]."
      )
      assert 0 <= text_box_alpha <= 1, ValueError(
          f"The text_box_alpha value {text_box_alpha} is not within range [0,1]."
      )
  
      if with_box_on_text:
          if text_box_width is None:
              text_box_width = _calculate_default_box_width(canvas)
  
      if with_layout:
          canvas = draw_box(canvas, layout, **kwargs)
  
      font_obj = _create_font_object(font_size, font_path)
      text_box_color = text_box_color or DEFAULT_OUTLINE_COLOR
      text_color = text_color or DEFAULT_TEXT_COLOR
      text_background_color = (
          text_background_color or DEFAULT_TEXT_BACKGROUND
      )
  
      canvas = _create_new_canvas(
          canvas,
          arrangement,
          _get_color_rgb(text_background_color, text_background_alpha),
      )
      draw = ImageDraw.Draw(canvas, "RGBA")
  
      for idx, ele in enumerate(layout):
          if with_box_on_text:
              modified_box = ele.pad(
                  right=text_box_width, bottom=text_box_width
              )
  
              _draw_box_outline_on_handler(
                  draw, modified_box, text_box_color, text_box_width
              )
              _draw_transparent_box_on_handler(
                  draw, modified_box, text_box_color, text_box_alpha
              )
  
          if not hasattr(ele, "text") or ele.text == "":
              continue
  
          (start_x, start_y) = ele.coordinates[:2]
          if not vertical_text:
              draw.text(
                  (start_x, start_y),
                  ele.text,
                  font=font_obj,
                  fill=text_color,
              )
          else:
              text_segment = _draw_vertical_text(
                  ele.text,
                  font_obj,
                  text_color,
                  _get_color_rgb(
                      text_background_color, text_background_alpha
                  ),
              )
  
              if with_box_on_text:
                  # Avoid cover the box regions
                  canvas.paste(
                      text_segment,
                      (
                          start_x + text_box_width,
                          start_y + text_box_width,
                      ),
                  )
              else:
                  canvas.paste(text_segment, (start_x, start_y))
  
      return canvas
  
imports: from typing import List, Optional, Union, Dict, Any, Tuple, Dict
  import functools
  import os
  import sys
  from itertools import cycle
  import numpy
  from PIL import Image, ImageFont, ImageDraw, ImageColor
  import layoutparser
  from .elements import Layout, Interval, Rectangle, TextBlock, Quadrilateral
  from .elements.utils import cvt_coordinates_to_points
label_desc: Use image node_id 12 for calling a global function with example usage: draw_text(canvas, layout, arrangement, font_size, font_path, text_color, text_background_color, text_background_alpha, vertical_text, with_box_on_text, text_box_width, text_box_color, text_box_alpha, with_layout) and returns: canvas