prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Bug when running Vispy offline for the first time
  There appears to be a bug when you run Vispy offline and you don't have the freetype thing already downloaded. Not completely sure about the exact conditions responsible for the crash, require some testing...
  
  
  </issue>
  <code>
  [start of vispy/util/fonts/_freetype.py]
  1 # -*- coding: utf-8 -*-
  2 # -----------------------------------------------------------------------------
  3 # Copyright (c) 2014, Vispy Development Team. All Rights Reserved.
  4 # Distributed under the (new) BSD License. See LICENSE.txt for more info.
  5 # -----------------------------------------------------------------------------
  6 
  7 # Use freetype to get glyph bitmaps
  8 
  9 import sys
  10 import numpy as np
  11 
  12 from ...ext.freetype import (FT_LOAD_RENDER, FT_LOAD_NO_HINTING,
  13                              FT_LOAD_NO_AUTOHINT, Face)
  14 
  15 
  16 # Convert face to filename
  17 from ._vispy_fonts import _vispy_fonts, _get_vispy_font_filename
  18 if sys.platform.startswith('linux'):
  19     from ...ext.fontconfig import find_font
  20 elif sys.platform.startswith('win'):
  21     from ._win32 import find_font  # noqa, analysis:ignore
  22 else:
  23     raise NotImplementedError
  24 
  25 _font_dict = {}
  26 
  27 
  28 def _load_font(face, bold, italic):
  29     key = '%s-%s-%s' % (face, bold, italic)
  30     if key in _font_dict:
  31         return _font_dict[key]
  32     if face in _vispy_fonts:
  33         fname = _get_vispy_font_filename(face, bold, italic)
  34     else:
  35         fname = find_font(face, bold, italic)
  36     font = Face(fname)
  37     _font_dict[key] = font
  38     return font
  39 
  40 
  41 def _load_glyph(f, char, glyphs_dict):
  42     """Load glyph from font into dict"""
  43     flags = FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT
  44     face = _load_font(f['face'], f['bold'], f['italic'])
  45     face.set_char_size(f['size'] * 64)
  46     # get the character of interest
  47     face.load_char(char, flags)
  48     bitmap = face.glyph.bitmap
  49     width = face.glyph.bitmap.width
  50     height = face.glyph.bitmap.rows
  51     bitmap = np.array(bitmap.buffer)
  52     w0 = bitmap.size // height if bitmap.size > 0 else 0
  53     bitmap.shape = (height, w0)
  54     bitmap = bitmap[:, :width].astype(np.ubyte)
  55 
  56     left = face.glyph.bitmap_left
  57     top = face.glyph.bitmap_top
  58     advance = face.glyph.advance.x / 64.
  59     glyph = dict(char=char, offset=(left, top), bitmap=bitmap,
  60                  advance=advance, kerning={})
  61     glyphs_dict[char] = glyph
  62     # Generate kerning
  63     for other_char, other_glyph in glyphs_dict.items():
  64         kerning = face.get_kerning(other_char, char)
  65         glyph['kerning'][other_char] = kerning.x / 64.
  66         kerning = face.get_kerning(char, other_char)
  67         other_glyph['kerning'][char] = kerning.x / 64.
  68
  [end of vispy/util/fonts/_freetype.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/vispy/util/fonts/_freetype.py b/vispy/util/fonts/_freetype.py
  --- a/vispy/util/fonts/_freetype.py
  +++ b/vispy/util/fonts/_freetype.py
  @@ -9,9 +9,6 @@
   import sys
   import numpy as np
   
  -from ...ext.freetype import (FT_LOAD_RENDER, FT_LOAD_NO_HINTING,
  -                             FT_LOAD_NO_AUTOHINT, Face)
  -
   
   # Convert face to filename
   from ._vispy_fonts import _vispy_fonts, _get_vispy_font_filename
  @@ -25,7 +22,11 @@
   _font_dict = {}
   
   
  +# Nest freetype imports in case someone doesn't have freetype on their system
  +# and isn't using fonts (Windows)
  +
   def _load_font(face, bold, italic):
  +    from ...ext.freetype import Face
       key = '%s-%s-%s' % (face, bold, italic)
       if key in _font_dict:
           return _font_dict[key]
  @@ -40,6 +41,8 @@
   
   def _load_glyph(f, char, glyphs_dict):
       """Load glyph from font into dict"""
  +    from ...ext.freetype import (FT_LOAD_RENDER, FT_LOAD_NO_HINTING,
  +                                 FT_LOAD_NO_AUTOHINT)
       flags = FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT
       face = _load_font(f['face'], f['bold'], f['italic'])
       face.set_char_size(f['size'] * 64)
  
verification_info: {"golden_diff": "diff --git a/vispy/util/fonts/_freetype.py b/vispy/util/fonts/_freetype.py\n--- a/vispy/util/fonts/_freetype.py\n+++ b/vispy/util/fonts/_freetype.py\n@@ -9,9 +9,6 @@\n import sys\n import numpy as np\n \n-from ...ext.freetype import (FT_LOAD_RENDER, FT_LOAD_NO_HINTING,\n-                             FT_LOAD_NO_AUTOHINT, Face)\n-\n \n # Convert face to filename\n from ._vispy_fonts import _vispy_fonts, _get_vispy_font_filename\n@@ -25,7 +22,11 @@\n _font_dict = {}\n \n \n+# Nest freetype imports in case someone doesn't have freetype on their system\n+# and isn't using fonts (Windows)\n+\n def _load_font(face, bold, italic):\n+    from ...ext.freetype import Face\n     key = '%s-%s-%s' % (face, bold, italic)\n     if key in _font_dict:\n         return _font_dict[key]\n@@ -40,6 +41,8 @@\n \n def _load_glyph(f, char, glyphs_dict):\n     \"\"\"Load glyph from font into dict\"\"\"\n+    from ...ext.freetype import (FT_LOAD_RENDER, FT_LOAD_NO_HINTING,\n+                                 FT_LOAD_NO_AUTOHINT)\n     flags = FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT\n     face = _load_font(f['face'], f['bold'], f['italic'])\n     face.set_char_size(f['size'] * 64)\n", "issue": "Bug when running Vispy offline for the first time\nThere appears to be a bug when you run Vispy offline and you don't have the freetype thing already downloaded. Not completely sure about the exact conditions responsible for the crash, require some testing...\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# -----------------------------------------------------------------------------\n# Copyright (c) 2014, Vispy Development Team. All Rights Reserved.\n# Distributed under the (new) BSD License. See LICENSE.txt for more info.\n# -----------------------------------------------------------------------------\n\n# Use freetype to get glyph bitmaps\n\nimport sys\nimport numpy as np\n\nfrom ...ext.freetype import (FT_LOAD_RENDER, FT_LOAD_NO_HINTING,\n                             FT_LOAD_NO_AUTOHINT, Face)\n\n\n# Convert face to filename\nfrom ._vispy_fonts import _vispy_fonts, _get_vispy_font_filename\nif sys.platform.startswith('linux'):\n    from ...ext.fontconfig import find_font\nelif sys.platform.startswith('win'):\n    from ._win32 import find_font  # noqa, analysis:ignore\nelse:\n    raise NotImplementedError\n\n_font_dict = {}\n\n\ndef _load_font(face, bold, italic):\n    key = '%s-%s-%s' % (face, bold, italic)\n    if key in _font_dict:\n        return _font_dict[key]\n    if face in _vispy_fonts:\n        fname = _get_vispy_font_filename(face, bold, italic)\n    else:\n        fname = find_font(face, bold, italic)\n    font = Face(fname)\n    _font_dict[key] = font\n    return font\n\n\ndef _load_glyph(f, char, glyphs_dict):\n    \"\"\"Load glyph from font into dict\"\"\"\n    flags = FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT\n    face = _load_font(f['face'], f['bold'], f['italic'])\n    face.set_char_size(f['size'] * 64)\n    # get the character of interest\n    face.load_char(char, flags)\n    bitmap = face.glyph.bitmap\n    width = face.glyph.bitmap.width\n    height = face.glyph.bitmap.rows\n    bitmap = np.array(bitmap.buffer)\n    w0 = bitmap.size // height if bitmap.size > 0 else 0\n    bitmap.shape = (height, w0)\n    bitmap = bitmap[:, :width].astype(np.ubyte)\n\n    left = face.glyph.bitmap_left\n    top = face.glyph.bitmap_top\n    advance = face.glyph.advance.x / 64.\n    glyph = dict(char=char, offset=(left, top), bitmap=bitmap,\n                 advance=advance, kerning={})\n    glyphs_dict[char] = glyph\n    # Generate kerning\n    for other_char, other_glyph in glyphs_dict.items():\n        kerning = face.get_kerning(other_char, char)\n        glyph['kerning'][other_char] = kerning.x / 64.\n        kerning = face.get_kerning(char, other_char)\n        other_glyph['kerning'][char] = kerning.x / 64.\n", "path": "vispy/util/fonts/_freetype.py"}]}