Beispiel #1
0
 def __init__(self, path, size):
     self.database = QFontDatabase()
     try:
         self.font_id = Font.font_ids[path]
     except Exception:
         if isinstance(path, str):
             self.font_id = self.database.addApplicationFont(path)
         else:
             self.font_id = self.database.addApplicationFontFromData(
                 path.read()
             )
         Font.font_ids[path] = self.font_id
     self.families = self.database.applicationFontFamilies(self.font_id)
     print(self.families)
     self.size = size
     if len(self.families) > 0:
         styles = self.database.styles(self.families[0])
         print(styles)
         self.font = self.database.font(self.families[0], "Bold", size)
         if self.size <= 0:
             print("WARNING: font size is", self.size)
             traceback.print_stack()
         self.font.setPixelSize(self.size)
     else:
         self.font = None
def app_main():
    print("prefs")
    qapplication = init_qt()

    print("FIXME: Saira - read from proper data location")
    with open(
        os.path.expanduser(
            "~/openretro/git/fsemu/data/SairaCondensed-Medium.ttf"
        ),
        "rb",
    ) as f:
        QFontDatabase.addApplicationFontFromData(f.read())
    with open(
        os.path.expanduser(
            "~/openretro/git/fsemu/data/SairaCondensed-Medium.ttf"
        ),
        "rb",
    ) as f:
        QFontDatabase.addApplicationFontFromData(f.read())
    with open(
        os.path.expanduser(
            "~/openretro/git/fsemu/data/SairaCondensed-SemiBold.ttf"
        ),
        "rb",
    ) as f:
        QFontDatabase.addApplicationFontFromData(f.read())
    with open(
        os.path.expanduser(
            "~/openretro/git/fsemu/data/SairaCondensed-Bold.ttf"
        ),
        "rb",
    ) as f:
        QFontDatabase.addApplicationFontFromData(f.read())

    initialize_qt_style(qapplication)

    from launcher.launcherapp import LauncherApp

    launcherapp = LauncherApp()

    # from launcher.ui.launcherwindow import LauncherWindow
    # launcherwindow = LauncherWindow()
    # launcherwindow.show()

    # window = PrefsWindow(app)
    # window.show()

    app = Application()
    from system.wsopen import wsopen

    wsopen("SYS:Prefs/WHDLoad")

    qapplication.exec_()
Beispiel #3
0
    def __init__(self, name):
        self._app = Application(name)

        stream = Font.stream("NotoSans-Regular.ttf")
        # noinspection PyArgumentList
        QFontDatabase.addApplicationFontFromData(stream.read())

        stream = Font.stream("Roboto-Regular.ttf")
        # noinspection PyArgumentList
        QFontDatabase.addApplicationFontFromData(stream.read())

        stream = Font.stream("RobotoMono-Regular.ttf")
        # noinspection PyArgumentList
        QFontDatabase.addApplicationFontFromData(stream.read())

        font = Font("Roboto", 14)
        font.qfont().setPointSizeF(10.5)
        font.qfont().setHintingPreference(QFont.PreferNoHinting)
        self._app.qapplication.setFont(font.qfont())
    def __init__(self, name):
        self._app = Application(name)

        stream = Font.stream("NotoSans-Regular.ttf")
        # noinspection PyArgumentList
        QFontDatabase.addApplicationFontFromData(stream.read())

        stream = Font.stream("Roboto-Regular.ttf")
        # noinspection PyArgumentList
        QFontDatabase.addApplicationFontFromData(stream.read())

        stream = Font.stream("RobotoMono-Regular.ttf")
        # noinspection PyArgumentList
        QFontDatabase.addApplicationFontFromData(stream.read())

        font = Font("Roboto", 14)
        font.qfont().setPointSizeF(10.5)
        font.qfont().setHintingPreference(QFont.PreferNoHinting)
        self._app.qapplication.setFont(font.qfont())
Beispiel #5
0
class Font(object):
    title_font = None
    subtitle_font = None
    small_font = None
    main_path_font = None
    list_subtitle_font = None
    header_font = None

    font_ids = {}

    def __init__(self, path, size):
        self.database = QFontDatabase()
        try:
            self.font_id = Font.font_ids[path]
        except Exception:
            if isinstance(path, str):
                self.font_id = self.database.addApplicationFont(path)
            else:
                self.font_id = self.database.addApplicationFontFromData(
                    path.read()
                )
            Font.font_ids[path] = self.font_id
        self.families = self.database.applicationFontFamilies(self.font_id)
        print(self.families)
        self.size = size
        if len(self.families) > 0:
            styles = self.database.styles(self.families[0])
            print(styles)
            self.font = self.database.font(self.families[0], "Bold", size)
            if self.size <= 0:
                print("WARNING: font size is", self.size)
                traceback.print_stack()
            self.font.setPixelSize(self.size)
        else:
            self.font = None

    def set_size(self, size):
        if self.font is not None:
            self.size = size
            if self.size <= 0:
                print("WARNING: font size is", self.size)
                traceback.print_stack()
            self.font.setPixelSize(self.size)

    def render(self, text, _, color):
        if self.font is None:
            return "", (0, 0)

        fm = QFontMetrics(self.font)
        rect = fm.boundingRect(text)
        im = QImage(
            rect.x() + rect.width(),
            rect.height(),
            QImage.Format_ARGB32_Premultiplied,
        )
        im.fill(QColor(0, 0, 0, 0))
        painter = QPainter()
        painter.begin(im)
        painter.setPen(QPen(QColor(*color)))
        painter.setFont(self.font)
        painter.drawText(QPoint(0 - rect.x(), 0 - rect.y()), text)
        painter.end()

        bits = im.bits()
        try:
            pixels = bits.tobytes()
        except AttributeError:
            bits.setsize(im.byteCount())
            pixels = bytes(bits)
        return pixels, (rect.x() + rect.width(), rect.height())

    def rendered_size(self, text):
        if self.font is None:
            return 0, 0

        fm = QFontMetrics(self.font)
        rect = fm.boundingRect(text)
        return rect.width(), rect.height()
Beispiel #6
0
def add_font(filename):
    QFontDatabase.addApplicationFontFromData(
        ApplicationData.stream(filename).read()
    )