Beispiel #1
0
 def get_text_path(self, text: str, font: qg.QFont) -> qg.QPainterPath:
     # None is the default font
     key = font.key() if font is not None else None
     cache = self._text_path_cache[key]  # defaultdict(dict)
     path = cache.get(text, None)
     if path is None:
         if font is None:
             font = self._default_font
         path = qg.QPainterPath()
         path.addText(0, 0, font, text)
         if self._use_cache:
             cache[text] = path
     return path
Beispiel #2
0
 def get_font_measurements(self, font: qg.QFont) -> FontMeasurements:
     # None is the default font.
     key = font.key() if font is not None else None
     measurements = self._font_measurement_cache.get(key)
     if measurements is None:
         upper_x = self.get_text_rect('X', font)
         lower_x = self.get_text_rect('x', font)
         lower_p = self.get_text_rect('p', font)
         baseline = lower_x.bottom()
         measurements = FontMeasurements(
             baseline=baseline,
             cap_height=baseline - upper_x.top(),
             x_height=baseline - lower_x.top(),
             descender_height=lower_p.bottom() - baseline,
         )
         self._font_measurement_cache[key] = measurements
     return measurements