Repository: ManimCommunity/manim

Issue:
`Code` rectangle is extremely large when used with opengl.
## Description of bug / unexpected behavior
<!-- Add a clear and concise description of the problem you encountered. -->
While working on #1735 I noticed that the `Code` mobject looked mostly fine, except for the very large background rectangle around it:
(will need to zoom out)
```py
class CodeFromString(Scene):
    def construct(self):
        code = '''from manim import Scene, Square

        class FadeInSquare(Scene):
            def construct(self):
                s = Square()
                self.play(FadeIn(s))
                self.play(s.animate.scale(2))
                self.wait()
        '''
        rendered_code = Code(code=code, tab_width=4, background="window",
                            language="Python", font="Monospace", scale_factor=0.3)
        self.add(rendered_code)
        
        self.interactive_embed()
```
![image](https://user-images.githubusercontent.com/70682032/127313350-fed8c53c-3519-4436-965e-a77d6d7c194e.png)

This odd behaviour only exists with the opengl renderer.


## Expected behavior
<!-- Add a clear and concise description of what you expected to happen. -->
Running the exact same code in cairo:
![CodeFromString_ManimCE_v0 7 0](https://user-images.githubusercontent.com/70682032/127313502-235a2902-f46c-4a82-b5b9-71dc57132783.png)



## Logs
N/A
<details><summary>Terminal output</summary>
<!-- Add "-v DEBUG" when calling manim to generate more detailed logs -->
N/A
```
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR
```

## System specifications
- OS windows 11
- RAM: 8 GB
- Python version 3.9
<details><summary>System Details</summary>

## Additional comments
<!-- Add further context that you think might be relevant for this issue here. -->
I tried debugging this, and I think i've pinpointed the cause of the issue to be at `gen_line_chars`  for `Paragraph` starting from `gen_colored_lines` in Code.  

from my initial attempts at debugging this:
> i took the sum of the widths of everything in the vgroups for both opengl/cairo and they're both the same, it's just that when i get the vgroup as a whole that the widths are mismatched

relevant lines

https://github.com/ManimCommunity/manim/blob/main/manim/mobject/svg/text_mobject.py#L514-L530



Discussion:
I was looking at this and found that when the line below gets called only the submobjects of `self.chars` get scaled but the parent `self.chars` itself which is an `OpenGLVGroup` object doesn't scale with them so the width doesn't change. In cairo renderer both the submobjects and the parent's width is scaled, so maybe that could be causing it?

https://github.com/ManimCommunity/manim/blob/bc93a2e99afb3f77c18a0c7e56d148aca10683f8/manim/mobject/svg/text_mobject.py#L509


I doubt it's an actual fix but it seems to scale on both cairo and opengl when changing the above line to

```py
            self.chars.scale(TEXT_MOB_SCALE_FACTOR)
```

<img width="643" alt="Screenshot 2021-07-29 at 19 26 35" src="https://user-images.githubusercontent.com/32387857/127546239-89ac263c-6f1a-41fc-bada-a981f892c1b2.png">


Resolving patch:
diff --git a/manim/mobject/svg/text_mobject.py b/manim/mobject/svg/text_mobject.py
--- a/manim/mobject/svg/text_mobject.py
+++ b/manim/mobject/svg/text_mobject.py
@@ -475,7 +475,10 @@ def __init__(
         )
         self.text = text
         if self.disable_ligatures:
-            self.submobjects = [*self.gen_chars()]
+            if config.renderer == "opengl":
+                self.set_submobjects(self.gen_chars())
+            else:
+                self.submobjects = [*self.gen_chars()]
         self.chars = self.get_group_class()(*self.submobjects)
         self.text = text_without_tabs.replace(" ", "").replace("\n", "")
         if config.renderer == "opengl":


Test patch: