prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Pygame text provider does not render text opacity properly
  Text renders as if opacity is set to 100% regardless of what's set in a Label's color attribute.
  
  SDL2 works just fine.
  
  Tested with master pulled today on Linux.
  
  Pygame text provider does not render text opacity properly
  Text renders as if opacity is set to 100% regardless of what's set in a Label's color attribute.
  
  SDL2 works just fine.
  
  Tested with master pulled today on Linux.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `kivy/core/text/text_pygame.py`
  Content:
  ```
  1 '''
  2 Text Pygame: Draw text with pygame
  3 '''
  4 
  5 __all__ = ('LabelPygame', )
  6 
  7 from kivy.compat import PY2
  8 from kivy.core.text import LabelBase
  9 from kivy.core.image import ImageData
  10 
  11 try:
  12     import pygame
  13 except:
  14     raise
  15 
  16 pygame_cache = {}
  17 pygame_font_handles = {}
  18 pygame_cache_order = []
  19 
  20 # init pygame font
  21 try:
  22     pygame.ftfont.init()
  23 except:
  24     pygame.font.init()
  25 
  26 
  27 class LabelPygame(LabelBase):
  28 
  29     def _get_font_id(self):
  30         if PY2:
  31             try:
  32                 return '|'.join([unicode(self.options[x]) for x in
  33                                  ('font_size', 'font_name_r',
  34                                   'bold', 'italic')])
  35             except UnicodeDecodeError:
  36                 pass
  37         return '|'.join([str(self.options[x]) for x in
  38                          ('font_size', 'font_name_r', 'bold', 'italic')])
  39 
  40     def _get_font(self):
  41         fontid = self._get_font_id()
  42         if fontid not in pygame_cache:
  43             # try first the file if it's a filename
  44             font_handle = fontobject = None
  45             fontname = self.options['font_name_r']
  46             ext = fontname.rsplit('.', 1)
  47             if len(ext) == 2:
  48                 # try to open the font if it has an extension
  49                 font_handle = open(fontname, 'rb')
  50                 fontobject = pygame.font.Font(font_handle,
  51                                               int(self.options['font_size']))
  52 
  53             # fallback to search a system font
  54             if fontobject is None:
  55                 # try to search the font
  56                 font = pygame.font.match_font(
  57                     self.options['font_name_r'].replace(' ', ''),
  58                     bold=self.options['bold'],
  59                     italic=self.options['italic'])
  60 
  61                 # fontobject
  62                 fontobject = pygame.font.Font(font,
  63                                               int(self.options['font_size']))
  64             pygame_cache[fontid] = fontobject
  65             pygame_font_handles[fontid] = font_handle
  66             pygame_cache_order.append(fontid)
  67 
  68         # to prevent too much file open, limit the number of opened fonts to 64
  69         while len(pygame_cache_order) > 64:
  70             popid = pygame_cache_order.pop(0)
  71             del pygame_cache[popid]
  72             font_handle = pygame_font_handles.pop(popid)
  73             if font_handle is not None:
  74                 font_handle.close()
  75 
  76         return pygame_cache[fontid]
  77 
  78     def get_ascent(self):
  79         return self._get_font().get_ascent()
  80 
  81     def get_descent(self):
  82         return self._get_font().get_descent()
  83 
  84     def get_extents(self, text):
  85         return self._get_font().size(text)
  86 
  87     def get_cached_extents(self):
  88         return self._get_font().size
  89 
  90     def _render_begin(self):
  91         self._pygame_surface = pygame.Surface(self._size, pygame.SRCALPHA, 32)
  92         self._pygame_surface.fill((0, 0, 0, 0))
  93 
  94     def _render_text(self, text, x, y):
  95         font = self._get_font()
  96         color = [c * 255 for c in self.options['color']]
  97         color[0], color[2] = color[2], color[0]
  98         try:
  99             text = font.render(text, True, color)
  100             self._pygame_surface.blit(text, (x, y), None,
  101                                       pygame.BLEND_RGBA_ADD)
  102         except pygame.error:
  103             pass
  104 
  105     def _render_end(self):
  106         w, h = self._size
  107         data = ImageData(w, h,
  108                          'rgba', self._pygame_surface.get_buffer().raw)
  109 
  110         del self._pygame_surface
  111 
  112         return data
  113
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/kivy/core/text/text_pygame.py b/kivy/core/text/text_pygame.py
  --- a/kivy/core/text/text_pygame.py
  +++ b/kivy/core/text/text_pygame.py
  @@ -97,6 +97,7 @@
           color[0], color[2] = color[2], color[0]
           try:
               text = font.render(text, True, color)
  +            text.set_colorkey(color)
               self._pygame_surface.blit(text, (x, y), None,
                                         pygame.BLEND_RGBA_ADD)
           except pygame.error:
  
verification_info: {"golden_diff": "diff --git a/kivy/core/text/text_pygame.py b/kivy/core/text/text_pygame.py\n--- a/kivy/core/text/text_pygame.py\n+++ b/kivy/core/text/text_pygame.py\n@@ -97,6 +97,7 @@\n         color[0], color[2] = color[2], color[0]\n         try:\n             text = font.render(text, True, color)\n+            text.set_colorkey(color)\n             self._pygame_surface.blit(text, (x, y), None,\n                                       pygame.BLEND_RGBA_ADD)\n         except pygame.error:\n", "issue": "Pygame text provider does not render text opacity properly\nText renders as if opacity is set to 100% regardless of what's set in a Label's color attribute.\n\nSDL2 works just fine.\n\nTested with master pulled today on Linux.\n\nPygame text provider does not render text opacity properly\nText renders as if opacity is set to 100% regardless of what's set in a Label's color attribute.\n\nSDL2 works just fine.\n\nTested with master pulled today on Linux.\n\n", "before_files": [{"content": "'''\nText Pygame: Draw text with pygame\n'''\n\n__all__ = ('LabelPygame', )\n\nfrom kivy.compat import PY2\nfrom kivy.core.text import LabelBase\nfrom kivy.core.image import ImageData\n\ntry:\n    import pygame\nexcept:\n    raise\n\npygame_cache = {}\npygame_font_handles = {}\npygame_cache_order = []\n\n# init pygame font\ntry:\n    pygame.ftfont.init()\nexcept:\n    pygame.font.init()\n\n\nclass LabelPygame(LabelBase):\n\n    def _get_font_id(self):\n        if PY2:\n            try:\n                return '|'.join([unicode(self.options[x]) for x in\n                                 ('font_size', 'font_name_r',\n                                  'bold', 'italic')])\n            except UnicodeDecodeError:\n                pass\n        return '|'.join([str(self.options[x]) for x in\n                         ('font_size', 'font_name_r', 'bold', 'italic')])\n\n    def _get_font(self):\n        fontid = self._get_font_id()\n        if fontid not in pygame_cache:\n            # try first the file if it's a filename\n            font_handle = fontobject = None\n            fontname = self.options['font_name_r']\n            ext = fontname.rsplit('.', 1)\n            if len(ext) == 2:\n                # try to open the font if it has an extension\n                font_handle = open(fontname, 'rb')\n                fontobject = pygame.font.Font(font_handle,\n                                              int(self.options['font_size']))\n\n            # fallback to search a system font\n            if fontobject is None:\n                # try to search the font\n                font = pygame.font.match_font(\n                    self.options['font_name_r'].replace(' ', ''),\n                    bold=self.options['bold'],\n                    italic=self.options['italic'])\n\n                # fontobject\n                fontobject = pygame.font.Font(font,\n                                              int(self.options['font_size']))\n            pygame_cache[fontid] = fontobject\n            pygame_font_handles[fontid] = font_handle\n            pygame_cache_order.append(fontid)\n\n        # to prevent too much file open, limit the number of opened fonts to 64\n        while len(pygame_cache_order) > 64:\n            popid = pygame_cache_order.pop(0)\n            del pygame_cache[popid]\n            font_handle = pygame_font_handles.pop(popid)\n            if font_handle is not None:\n                font_handle.close()\n\n        return pygame_cache[fontid]\n\n    def get_ascent(self):\n        return self._get_font().get_ascent()\n\n    def get_descent(self):\n        return self._get_font().get_descent()\n\n    def get_extents(self, text):\n        return self._get_font().size(text)\n\n    def get_cached_extents(self):\n        return self._get_font().size\n\n    def _render_begin(self):\n        self._pygame_surface = pygame.Surface(self._size, pygame.SRCALPHA, 32)\n        self._pygame_surface.fill((0, 0, 0, 0))\n\n    def _render_text(self, text, x, y):\n        font = self._get_font()\n        color = [c * 255 for c in self.options['color']]\n        color[0], color[2] = color[2], color[0]\n        try:\n            text = font.render(text, True, color)\n            self._pygame_surface.blit(text, (x, y), None,\n                                      pygame.BLEND_RGBA_ADD)\n        except pygame.error:\n            pass\n\n    def _render_end(self):\n        w, h = self._size\n        data = ImageData(w, h,\n                         'rgba', self._pygame_surface.get_buffer().raw)\n\n        del self._pygame_surface\n\n        return data\n", "path": "kivy/core/text/text_pygame.py"}], "after_files": [{"content": "'''\nText Pygame: Draw text with pygame\n'''\n\n__all__ = ('LabelPygame', )\n\nfrom kivy.compat import PY2\nfrom kivy.core.text import LabelBase\nfrom kivy.core.image import ImageData\n\ntry:\n    import pygame\nexcept:\n    raise\n\npygame_cache = {}\npygame_font_handles = {}\npygame_cache_order = []\n\n# init pygame font\ntry:\n    pygame.ftfont.init()\nexcept:\n    pygame.font.init()\n\n\nclass LabelPygame(LabelBase):\n\n    def _get_font_id(self):\n        if PY2:\n            try:\n                return '|'.join([unicode(self.options[x]) for x in\n                                 ('font_size', 'font_name_r',\n                                  'bold', 'italic')])\n            except UnicodeDecodeError:\n                pass\n        return '|'.join([str(self.options[x]) for x in\n                         ('font_size', 'font_name_r', 'bold', 'italic')])\n\n    def _get_font(self):\n        fontid = self._get_font_id()\n        if fontid not in pygame_cache:\n            # try first the file if it's a filename\n            font_handle = fontobject = None\n            fontname = self.options['font_name_r']\n            ext = fontname.rsplit('.', 1)\n            if len(ext) == 2:\n                # try to open the font if it has an extension\n                font_handle = open(fontname, 'rb')\n                fontobject = pygame.font.Font(font_handle,\n                                              int(self.options['font_size']))\n\n            # fallback to search a system font\n            if fontobject is None:\n                # try to search the font\n                font = pygame.font.match_font(\n                    self.options['font_name_r'].replace(' ', ''),\n                    bold=self.options['bold'],\n                    italic=self.options['italic'])\n\n                # fontobject\n                fontobject = pygame.font.Font(font,\n                                              int(self.options['font_size']))\n            pygame_cache[fontid] = fontobject\n            pygame_font_handles[fontid] = font_handle\n            pygame_cache_order.append(fontid)\n\n        # to prevent too much file open, limit the number of opened fonts to 64\n        while len(pygame_cache_order) > 64:\n            popid = pygame_cache_order.pop(0)\n            del pygame_cache[popid]\n            font_handle = pygame_font_handles.pop(popid)\n            if font_handle is not None:\n                font_handle.close()\n\n        return pygame_cache[fontid]\n\n    def get_ascent(self):\n        return self._get_font().get_ascent()\n\n    def get_descent(self):\n        return self._get_font().get_descent()\n\n    def get_extents(self, text):\n        return self._get_font().size(text)\n\n    def get_cached_extents(self):\n        return self._get_font().size\n\n    def _render_begin(self):\n        self._pygame_surface = pygame.Surface(self._size, pygame.SRCALPHA, 32)\n        self._pygame_surface.fill((0, 0, 0, 0))\n\n    def _render_text(self, text, x, y):\n        font = self._get_font()\n        color = [c * 255 for c in self.options['color']]\n        color[0], color[2] = color[2], color[0]\n        try:\n            text = font.render(text, True, color)\n            text.set_colorkey(color)\n            self._pygame_surface.blit(text, (x, y), None,\n                                      pygame.BLEND_RGBA_ADD)\n        except pygame.error:\n            pass\n\n    def _render_end(self):\n        w, h = self._size\n        data = ImageData(w, h,\n                         'rgba', self._pygame_surface.get_buffer().raw)\n\n        del self._pygame_surface\n\n        return data\n", "path": "kivy/core/text/text_pygame.py"}]}