       0        0        0        0        0        0        0        0        0        0        0        0        0        0        0        0        0
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Â484_‘I|¥‰ÓMdœv ©ƒ†ü+=ÂÁ ä    ‹      ­”]oÛ †ïû+»‹�óÑNk1SGZ´4‰ROÛ4í‚bh°€4í~ýpœªÞ”tŸWû=/ïÃ“él˜}ž�Ð»ìj‚æÞNÆC„; ûC€4K›ƒ(îŒ¦aé}u°Ýn£m?2¶€lÒ¯Ë8oUî#î9¦'¤~GO‘‚ñðDÄ+_
:Ö\Ü#³B`6Þ).°qœdV€6\Ü8(gNF^ZãC�¦4˜ÁÞ�,¨éþ�a¨ÛEbË�o=´”x‰îX©
�`o*L‰ZÈÙ<Á r£,K¦o£B­0b¥Oð—ñpö5èÀËºš†¤«¿&Ó‹Yr‰é”­Ãzì°æªÑL˜óhm¸Z)Á�Š¯ñµúvÜ0m4©p¹U•WF?I! ¶QsSºŠÖÓ@ m[ÕHø¯vƒå?lÆür1šféxÑl	¯-žÒ=ÓLça¦=J•¹7öaŸº±x©—®ºxœ¢}&«
é1E¨ƒ*ÿ Ä‹{ßÉ>eT}Ô¢‡éã¨�ó§`½¸wÖ‰_uâêõÏ»]„ŽtÏÞÿ+ÁFßj³ÕmˆÐéƒUè+Do4¦íÙÿ€9}?ÓŽß<}°¿—v×œ@ó/ù¾¹…ò®    B   ˆl–Ü4ý(Ð;ÝÀ¹q–”Å£�þDàŸY¸É$£”l¶óÀþÅƒ}×Ä_ŠI|¥�+Wé3ž¯ÄÃ &)    """
Text drawers.

"""

from math import cos, radians, sin

from .bounding_box import (
    EMPTY_BOUNDING_BOX, extend_bounding_box, is_valid_bounding_box)
from .helpers import distance, normalize, point_angle, size, zip_letters
from .surface import cairo
from .url import parse_url


def path_length(path):
    """Get the length of ``path``."""
    total_length = 0
    for item in path:
        if item[0] == cairo.PATH_MOVE_TO:
            old_point = item[1]
        elif item[0] == cairo.PATH_LINE_TO:
            new_point = item[1]
            length = distance(
                old_point[0], old_point[1], new_point[0], new_point[1])
            total_length += length
            old_point = new_point
    return total_length


def point_following_path(path, width):
    """Get the point at ``width`` distance on ``path``."""
    total_length = 0
    for item in path:
        if item[0] == cairo.PATH_MOVE_TO:
            old_point = item[1]
        elif item[0] == cairo.PATH_LINE_TO:
            new_point = item[1]
            length = distance(
                old_point[0], old_point[1], new_point[0], new_point[1])
            total_length += length
            if total_length < width:
                old_point = new_point
            else:
                length -= total_length - width
                angle = point_angle(
                    old_point[0], old_point[1], new_point[0], new_point[1])
                x = cos(angle) * length + old_point[0]
                y = sin(angle) * length + old_point[1]
                return x, y


def text(surface, node, draw_as_text=False):
    """Draw a text ``node``."""
    font_family = (
        (node.get('font-family') or 'sans-serif').split(',')[0].strip('"\' '))
    font_style = getattr(
        cairo, ('font_slant_{}'.format(node.get('font-style')).upper()),
        cairo.FONT_SLANT_NORMAL)
    node_font_weight = node.get('font-weight')
    if (node_font_weight and node_font_weight.isdigit()
            and int(node_font_weight) >= 550):
        node_font_weight = 'bold'
    font_weight = getattr(
        cairo, ('font_weight_{}'.format(node_font_weight).upper()),
        cairo.FONT_WEIGHT_NORMAL)
    surface.context.select_font_face(font_family, font_style, font_weight)
    surface.context.set_font_size(surface.font_size)
    ascent, descent, _, max_x_advance, max_y_advance = (
        surface.context.font_extents())

    text_path_href = parse_url(node.get_href() or node.parent.get_href() or '')
    if text_path_href.fragment:
        text_path = surface.paths.get(text_path_href.fragment)
    else:
        text_path = None
    letter_spacing = size(surface, node.get('letter-spacing'))
    x_bearing, y_bearing, width, height = (
        surface.context.text_extents(node.text)[:4])

    x, y, dx, dy, rotate = [], [], [], [], [0]
    if 'x' in node:
        x = [size(surface, i, 'x')
             for i in normalize(node['x']).strip().split(' ')]
    if 'y' in node:
        y = [size(surface, i, 'y')
             for i in normalize(node['y']).strip().split(' ')]
    if 'dx' in node:
        dx = [size(surface, i, 'x')
              for i in normalize(node['dx']).strip().split(' ')]
    if 'dy' in node:
        dy = [size(surface, i, 'y')
              for i in normalize(node['dy']).strip().split(' ')]
    if