Repository: matplotlib/matplotlib
File: lib/matplotlib/backends/backend_pdf.py (Python)

Code before:
        """Write some data on the stream."""

        if self.compressobj is None:
            self.file.write(data)
        else:
            compressed = self.compressobj.compress(data)
            self.file.write(compressed)

    def _flush(self):
        """Flush the compression object."""

        if self.compressobj is not None:
            compressed = self.compressobj.flush()
            self.file.write(compressed)
            self.compressobj = None


def _get_pdf_charprocs(font_path, glyph_ids):
    font = get_font(font_path, hinting_factor=1)
    conv = 1000 / font.units_per_EM  # Conversion to PS units (1/1000's).
    procs = {}
    for glyph_id in glyph_ids:
        g = font.load_glyph(glyph_id, LoadFlags.NO_SCALE)
        d1 = [
            round(g.horiAdvance * conv), 0,
            # Round bbox corners *outwards*, so that they indeed bound th glyph.
            math.floor(g.bbox[0] * conv), math.floor(g.bbox[1] * conv),
            math.ceil(g.bbox[2] * conv), math.ceil(g.bbox[3] * conv),
        ]
        v, c = font.get_path()
        v = (v * 64 * conv).round()  # Back to TrueType's internal units (1/64's).
        procs[font.get_glyph_name(glyph_id)] = (
            " ".join(map(str, d1)).encode("ascii") + b" d1\n"
            + _path.convert_to_string(
                Path(v, c), None, None, False, None, 0,
                # no code for quad Beziers triggers auto-conversion to cubics.
                [b"m", b"l", b"", b"c", b"h"], True)
            + b"f")
    return procs


class PdfFile:
    """PDF file object."""

    def __init__(self, filename, metadata=None):
        """
        Parameters
        ----------
        filename : str or path-like or file-like
            Output target; if a string, a file will be opened for writing.


Review comment (suggestion):
```suggestion
            # Round bbox corners *outwards*, so that they indeed bound the glyph.
```

Code after:
        """Write some data on the stream."""

        if self.compressobj is None:
            self.file.write(data)
        else:
            compressed = self.compressobj.compress(data)
            self.file.write(compressed)

    def _flush(self):
        """Flush the compression object."""

        if self.compressobj is not None:
            compressed = self.compressobj.flush()
            self.file.write(compressed)
            self.compressobj = None


def _get_pdf_charprocs(font_path, glyph_ids):
    font = get_font(font_path, hinting_factor=1)
    conv = 1000 / font.units_per_EM  # Conversion to PS units (1/1000's).
    procs = {}
    for glyph_id in glyph_ids:
        g = font.load_glyph(glyph_id, LoadFlags.NO_SCALE)
        d1 = [
            round(g.horiAdvance * conv), 0,
            # Round bbox corners *outwards*, so that they indeed bound the glyph.
            math.floor(g.bbox[0] * conv), math.floor(g.bbox[1] * conv),
            math.ceil(g.bbox[2] * conv), math.ceil(g.bbox[3] * conv),
        ]
        v, c = font.get_path()
        v = (v * 64 * conv).round()  # Back to TrueType's internal units (1/64's).
        procs[font.get_glyph_name(glyph_id)] = (
            " ".join(map(str, d1)).encode("ascii") + b" d1\n"
            + _path.convert_to_string(
                Path(v, c), None, None, False, None, 0,
                # no code for quad Beziers triggers auto-conversion to cubics.
                [b"m", b"l", b"", b"c", b"h"], True)
            + b"f")
    return procs


class PdfFile:
    """PDF file object."""

    def __init__(self, filename, metadata=None):
        """
        Parameters
        ----------
        filename : str or path-like or file-like
            Output target; if a string, a file will be opened for writing.