Beispiel #1
0
def printKari(strings,
              fontpath,
              fontsize=8,
              rect=(0, 0, 320, 240),
              fg=0xFFFFFF,
              bg=0x000000):

    SDFont = sdfonts_py.SDFonts()
    SDFont.open(fontpath)
    SDFont.setFontSize(fontsize)

    start_x = rect[0]
    start_y = rect[1]
    end_x = rect[0] + rect[2]
    end_y = rect[1] + rect[3]
    x, y = start_x, start_y

    ## Fill backgound
    ##TMP lcd.rect(x=rect[0], y=rect[1], width=rect[2], height=rect[3], color=bg, fillcolor=bg)

    for s in strings:
        b = SDFont.getFontData(s)
        w = SDFont.getWidth()
        h = SDFont.getHeight()
        x += w
        if x > end_x:
            x = start_x
            y += h
            if y > end_y:
                y = start_y
                break  ## Over

        putc(s, x=x, y=y, fg=fg, bg=None, w=w, h=h)
Beispiel #2
0
def test_printTerm():
    SDFont = sdfonts_py.SDFonts()
    SDFont.open('../../fontbin/FONT.BIN')
    SDFont.setFontSize(10)

    utf16s = (u'A\nあ亜イイ/')
    ## utf16s = (u'A', u'あ', u'亜', u'イ', u'イ')

    for utf16 in utf16s:
        print(utf16)
        b = SDFont.getFontData(utf16)
        ## b = SDFont._getFontDataByUTF16(utf16)
        print(b)
        printTerm(b, w=SDFont.getWidth(), h=SDFont.getHeight())

    SDFont.close()
Beispiel #3
0
def btnA_pressed():
    global btnAStr
    SDFont = sdfonts_py.SDFonts()
    SDFont.open('/sd/font/FONT.BIN')
    SDFont.setFontSize(16)

    ## Increment Nihongo
    x = 0
    y = 50
    for j in range(10):
        for i in range(10):
            b = SDFont.getFontData(btnAStr)
            putc(b, x=x, y=y, w=SDFont.getWidth(), h=SDFont.getHeight())
            x += SDFont.getWidth()

            btnAStr = chr(ord(btnAStr) + 1)
            if btnAStr == u'ン':
                btnAStr = u'亜'
            if btnAStr == u'鰐':
                bntAStr = u'あ'
        x = 0
        y += SDFont.getHeight()

    SDFont.close()
Beispiel #4
0
def test_putc():
    SDFont = sdfonts_py.SDFonts()
    SDFont.open('/sd/font/FONT.BIN')

    fontSizes = (8, 10, 12, 14, 16, 20, 24)
    utf16s = (u'0aAあアア亜/')

    y = 50
    for n, fontSize in enumerate(fontSizes):
        SDFont.setFontSize(fontSize)
        ## print("FontSize:%d" % SDFont.getFontSize())

        x = 0

        for utf16 in utf16s:
            print(utf16)
            b = SDFont.getFontData(utf16)
            print(SDFont.getWidth(), SDFont.getHeight(), len(b))
            putc(b, x=x, y=y, w=SDFont.getWidth(), h=SDFont.getHeight())
            x += SDFont.getWidth()

        y += SDFont.getHeight()

    SDFont.close()
Beispiel #5
0
    def _print_core(self,
                    strings,
                    font_path,
                    font_size=8,
                    rect=(0, 0, 320, 240),
                    fg=0xFFFFFF,
                    bg=0x000000,
                    append=False):
        SDFont = sdfonts_py.SDFonts()
        SDFont.open(font_path)
        SDFont.setFontSize(font_size)

        start_x, start_y = rect[0:2]
        end_x = rect[0] + rect[2]
        end_y = rect[1] + rect[3]
        if append:
            if self._last_xy is None:  ##TODO
                self.clear()  ##TODO
            x, y = self._last_xy
        else:
            x, y = start_x, start_y
            ## Fill backgound
            lcd.rect(rect[0],
                     rect[1],
                     rect[2],
                     rect[3],
                     color=bg,
                     fillcolor=bg)
            ## lcd.rect(x=rect[0], y=rect[1],
            ##     width=rect[2], height=rect[3],
            ##     color=bg, fillcolor=bg)
            bg = None

        for s in strings:

            ## NextLine
            if s == "\n":
                x = start_x
                y += font_size
                continue

            b = SDFont.getFontData(s)
            if b is None:
                continue

            w = SDFont.getWidth()
            h = SDFont.getHeight()

            self._putc(b, x=x, y=y, fg=fg, bg=bg, w=w, h=h)

            x += w
            if x > end_x:
                x = start_x
                y += h
                if y > end_y:
                    y = start_y
                    if append:
                        self.clear()  ## go top ##TODO
                    else:
                        break  ## over

        self._last_xy = (x, y)
        SDFont.close()