Beispiel #1
0
    def _width_with_metrics(self, text):
    
        # Return the width of this piece of text when rendered using this
        # font.
        
        fontName = self.font["BaseFont"].name
        at = fontName.find("+")
        if at != -1:
            fontName = fontName[at+1:]

        if "-" in fontName:
            family, style = fontName.split("-")[:2]
        elif " " in fontName:
            family, style = fontName.split(" ")[:2]
        elif "," in fontName:
            family, style = fontName.split(",")[:2]
        else:
            family = fontName
            style = ""
        
        font = QFontDatabase().font(family, style, self.size)
        font.setPointSizeF(self.size)
        fm = QFontMetricsF(font)
        return fm.width(text)
Beispiel #2
0
    def _width_with_metrics(self, text):

        # Return the width of this piece of text when rendered using this
        # font.

        fontName = self.font["BaseFont"].name
        at = fontName.find("+")
        if at != -1:
            fontName = fontName[at + 1:]

        if "-" in fontName:
            family, style = fontName.split("-")[:2]
        elif " " in fontName:
            family, style = fontName.split(" ")[:2]
        elif "," in fontName:
            family, style = fontName.split(",")[:2]
        else:
            family = fontName
            style = ""

        font = QFontDatabase().font(family, style, self.size)
        font.setPointSizeF(self.size)
        fm = QFontMetricsF(font)
        return fm.width(text)