예제 #1
0
def display_text(
    string,
    bgcolor=bgcolor,
    dfont=pygame.font.Font(myexpefont,
                           round(2 / 3 * myexpefontsize))):  # Display text
    font = dfont  # Font name and size

    if textdirection == 'RTL':
        text = font.render(
            pyfribidi.log2vis(string), 1,
            fgcolor)  # Set text to display, antialiasing and color
        if DEBUG:
            print(string, pyfribidi.log2vis(string))
    else:
        text = font.render(
            string, 1, fgcolor)  # Set text to display, antialiasing and color
        if DEBUG:
            print(string)

    textpos = text.get_rect()  # Get coordinates of the surface
    # needed for text display
    textsize = text.get_size()
    textpos.centerx = background.get_rect().centerx  # set text
    # x-position
    # centered
    textpos.centery = background.get_rect().centery  # set text
    # y-position
    # centered
    background.fill(bgcolor)  # Blank the background surface
    window.blit(background, (0, 0))  # Blit it
    window.blit(text, textpos)  # Blits the text to the coordinates
    pygame.display.flip()  # Flip the display
    return (textsize, textpos)
예제 #2
0
 def format(self, item):
     if item.price_include_lawyer == None:
         return '---'
     elif item.price_include_lawyer == False:
         return log2vis(gettext('no'))
     elif item.price_include_lawyer == True:
         return log2vis(gettext('yes'))
예제 #3
0
 def testCp1255NaturalRTL(self):
     """ other encodings: cp1255 """
     charset = 'cp1255'
     self.assertEqual(
         pyfribidi.log2vis(u"שלום - hello".encode(charset),
                           encoding=charset),
         u"hello - םולש".encode(charset))
예제 #4
0
 def testUTF16NaturalRTL(self):
     """ other encodings: utf-16 """
     charset = 'utf-16'
     self.assertEqual(
         pyfribidi.log2vis(u"שלום - hello".encode(charset),
                           encoding=charset),
         u"hello - םולש".encode(charset))
예제 #5
0
 def testIso8859_8NaturalRTL(self):
     """ other encodings: iso8859-8 """
     charset = 'iso8859-8'
     self.assertEqual(
         pyfribidi.log2vis(u"שלום - hello".encode(charset),
                           encoding=charset),
         u"hello - םולש".encode(charset))
예제 #6
0
def biditext_cb(data, modifier, modifier_data, line):
    # We assume a tab separates the nick from the text
    text = line.split('\t', 1)
    if len(text) > 1:
        text[1] = log2vis(text[1], ON)
        return '\t'.join(text)

    return line
예제 #7
0
def biditext_cb(data, modifier, modifier_data, line):
    # We assume a tab separates the nick from the text
    text = line.split('\t', 1)
    if len(text) > 1:
        text[1] = log2vis(text[1], ON)
        return '\t'.join(text)

    return line
예제 #8
0
 def format(self, item):
     clients = item.clients
     str2 = ''
     parts = clients.strip().split('\r\n')
     parts.reverse()
     for s in parts:
         str2 += log2vis(s)
     return Paragraph(str2, styleRow10)
예제 #9
0
 def format(self, item):
     '''
     item is of type EmployeeSalary
     '''
     val = ''
     sales = item.sales
     for project, sales in sales:
         val += log2vis("%s - %s" % (project, len(sales))) + '<br/>'
     return val
예제 #10
0
 def format(self, item):
     '''
     item is of type EmployeeSalary
     '''
     val = ''
     sales = item.sales
     for project, sales in sales:
         val += log2vis("%s - %s" % (project, len(sales))) + '<br/>'
     return val
예제 #11
0
    def testBigString(self):
        """ unicode: big string

        It does not make sense to order such big strings, this just
        checks that there are no size limits in pyfribidi.
        """
        # About 2MB string for default python build (ucs2)
        big = (u'א' * 1024) * 1024
        self.assertEqual(pyfribidi.log2vis(big), big)
예제 #12
0
    def testBigString(self):
        """ utf8: big string

        It does not make sense to order such big strings, this just
        checks that there are no size limits in pyfribidi.
        """
        # About 2MB string
        big = ('א' * 1024) * 1024
        self.assertEqual(pyfribidi.log2vis(big), big)
예제 #13
0
    def testBigString(self):
        """ unicode: big string

        It does not make sense to order such big strings, this just
        checks that there are no size limits in pyfribidi.
        """
        # About 2MB string for default python build (ucs2)
        big = (u'א' * 1024) * 1024
        self.assertEqual(pyfribidi.log2vis(big), big)
예제 #14
0
    def testBigString(self):
        """ utf8: big string

        It does not make sense to order such big strings, this just
        checks that there are no size limits in pyfribidi.
        """
        # About 2MB string
        big = ('א' * 1024) * 1024
        self.assertEqual(pyfribidi.log2vis(big), big)
예제 #15
0
def display_text(string, direction):
    pygame.font.init()
    font = pygame.font.Font(myexpefont, myexpefontsize)  # Font name and size
    #text = font.render(string, 1, (250, 250, 250)) # Set text to display, antialiasing and color
    if direction == 'RTL':
        text = font.render(
            pyfribidi.log2vis(string), 1,
            fgcolor)  # Set text to display, antialiasing and color
        print string, pyfribidi.log2vis(string)
    else:
        text = font.render(
            string, 1, fgcolor)  # Set text to display, antialiasing and color
        print string
    textpos = text.get_rect()  # Get surface size information
    textpos.centerx = background.get_rect().centerx  # set x position
    textpos.centery = background.get_rect().centery  # set y position
    screen.fill(bgcolor)
    screen.blit(text, textpos)
    pygame.display.flip()
예제 #16
0
 def _formatText(self, text):
     "Generates PDF text output operator(s)"
     text = pyfribidi.log2vis(text, RTL)
     if self._dynamicFont:
         results = []
         font = pdfmetrics.getFont(self._fontname)
         for subset, chunk in font.splitString(text, self._canvas._doc):
             if subset != self._curSubset:
                 pdffontname = font.getSubsetInternalName(subset, self._canvas._doc)
                 results.append("%s %s Tf %s TL" % (pdffontname, fp_str(self._fontsize), fp_str(self._leading)))
                 self._curSubset = subset
             chunk = self._canvas._escape(chunk)
             results.append("(%s) Tj" % chunk)
         return string.join(results, ' ')
     else:
         text = self._canvas._escape(text)
         return "(%s) Tj" % text
예제 #17
0
def on_button_clicked(obj):
    inText = clip.wait_for_text()
    outText = pyfribidi.log2vis(inText, pyfribidi.ON)
    clip.set_text(outText)
예제 #18
0
 def testNaturalLTR(self):
     """ unicode: reorder LTR line by natural order """
     self.assertEqual(pyfribidi.log2vis(u"hello - שלום", ON),
                      u"hello - םולש")
예제 #19
0
def biditext_cb(data, modifier, modifier_data, line):
    return log2vis(line, LTR)
예제 #20
0
 def testEmpty(self):
     """ utf8: empty string """
     self.assertEqual(pyfribidi.log2vis(''), '')
예제 #21
0
 def test_glibc_free_invalid_next_size(self):
     # *** glibc detected *** /home/ralf/py27/bin/python2: free(): invalid next size (fast): 0x00000000011cff00 ***
     pyfribidi.log2vis(
         '\xf0\x90\x8e\xa2\xf0\x90\x8e\xaf\xf0\x90\x8e\xb4\xf0\x90\x8e\xa1\xf0\x90\x8f\x83'
     )
예제 #22
0
 def test_glibc_free_invalid_next_size(self):
     # *** glibc detected *** /home/ralf/py27/bin/python2: free(): invalid next size (fast): 0x00000000011cff00 ***
     pyfribidi.log2vis('\xf0\x90\x8e\xa2\xf0\x90\x8e\xaf\xf0\x90\x8e\xb4\xf0\x90\x8e\xa1\xf0\x90\x8f\x83')
예제 #23
0
 def testReorderNonSpacingMarks(self):
     """unicode: reorder non spacing marks"""
     self.assertEqual(pyfribidi.log2vis(u"חַיְפַא", RTL),
                      u"אפַיְחַ"
                      )
예제 #24
0
 def testNoReorderNonSpacingMarks(self):
     """unicode: reorder non spacing marks"""
     self.assertEqual(pyfribidi.log2vis(u"חַיְפַא", RTL, reordernsm=False),
                      u"אַפְיַח")
예제 #25
0
 def testReorderNonSpacingMarks(self):
     """unicode: reorder non spacing marks"""
     self.assertEqual(pyfribidi.log2vis(u"חַיְפַא", RTL), u"אפַיְחַ")
예제 #26
0
 def testNaturalLTR(self):
     """ unicode: reorder LTR line by natural order """
     self.assertEqual(pyfribidi.log2vis(u"hello - שלום", ON),
                      u"hello - םולש")
예제 #27
0
 def testNaturalRTL(self):
     """ unicode: reorder RTL line by natural order """
     self.assertEqual(pyfribidi.log2vis(u"שלום - hello", ON),
                      u"hello - םולש")
예제 #28
0
 def testAsLTR(self):
     """ unicode: reorder line as LTR """
     self.assertEqual(pyfribidi.log2vis(u"hello - שלום", LTR),
                      u"hello - םולש")
예제 #29
0
 def testAsRTL(self):
     """ unicode: reorder line as RTL """
     self.assertEqual(pyfribidi.log2vis(u"hello - שלום", RTL),
                      u"םולש - hello")
예제 #30
0
 def testDefaultDirection(self):
     """ unicode: use RTL default """
     self.assertEqual(pyfribidi.log2vis(u"hello - שלום"),
                      pyfribidi.log2vis(u"hello - שלום", RTL))
예제 #31
0
def prep_arabic(string):
    '''Prepares strings with arabic in them for being printed to the terminal
    '''
    return pyfribidi.log2vis(string)
예제 #32
0
 def testIso8859_8NaturalRTL(self):
     """ other encodings: iso8859-8 """
     charset = 'iso8859-8'
     self.assertEqual(pyfribidi.log2vis(u"שלום - hello".encode(charset),
                                        encoding=charset),
                      u"hello - םולש".encode(charset))
예제 #33
0
    text = text.encode('%(encoding)s')
""" % locals()

    if encoding in ['unicode', 'utf-8']:
        # utf-8 is the default encoding for strings
        code = "pyfribidi.log2vis(text)"
    else:
        # other encodings require encoding parameter
        code = "pyfribidi.log2vis(text, encoding='%s')" % encoding

    timer = timeit.Timer(code, setup)
    seconds = timer.timeit(number=tests)
    microseconds = 1000000 * seconds / tests
    print("%12s: %.8f seconds (%.2f usec/pass)" %
          (encoding, seconds, microseconds))


# warm up caches
for i in xrange(100000):
    pyfribidi.log2vis(u'Some text to warm up the caches')

lines = 50  # typical screen of text
print('\ntime to reorder %s lines:\n' % lines)
for encoding in hebrew_encodings:
    timeEncoding(encoding, lines)

lines = 100000
print('\ntime to reorder %s lines:\n' % lines)
for encoding in hebrew_encodings:
    timeEncoding(encoding, lines)
예제 #34
0
 def testUTF16NaturalRTL(self):
     """ other encodings: utf-16 """
     charset = 'utf-16'
     self.assertEqual(pyfribidi.log2vis(u"שלום - hello".encode(charset),
                                        encoding=charset),
                      u"hello - םולש".encode(charset))
예제 #35
0
 def testNoReorderNonSpacingMarks(self):
     """unicode: reorder non spacing marks"""
     self.assertEqual(pyfribidi.log2vis(u"חַיְפַא", RTL, reordernsm=False),
                      u"אַפְיַח"
                      )
예제 #36
0
        # utf-8 is the default encoding for strings
        code = "pyfribidi.log2vis(text)"
    else:
        # other encodings require encoding parameter
        code = "pyfribidi.log2vis(text, encoding='%s')" % encoding

    timer = timeit.Timer(code, setup)
    seconds = timer.timeit(number=tests)
    microseconds = 1000000 * seconds / tests
    print "%12s: %.8f seconds (%.2f usec/pass)" % (encoding, seconds,
                                                   microseconds)

    
# warm up caches
for i in xrange(100000):
    pyfribidi.log2vis(u'Some text to warm up the caches')

lines = 50 # typical screen of text
print
print 'time to rerorder %s lines:' % lines
print
for encoding in hebrew_encodings:
    timeEncoding(encoding, lines)

lines = 100000 
print
print 'time to rerorder %s lines:' % lines
print
for encoding in hebrew_encodings:
    timeEncoding(encoding, lines)
예제 #37
0
def biditext_cb(data, modifier, modifier_data, line):
    return log2vis(line, LTR)
예제 #38
0
 def testAsRTL(self):
     """ unicode: reorder line as RTL """
     self.assertEqual(pyfribidi.log2vis(u"hello - שלום", RTL),
                      u"םולש - hello")
예제 #39
0
def simple_render(text):
    result = log2vis(text)
    return result
예제 #40
0
 def testEmpty(self):
     """ unicode: empty string """
     self.assertEqual(pyfribidi.log2vis(u''), u'')
예제 #41
0
 def testCp1255NaturalRTL(self):
     """ other encodings: cp1255 """
     charset = 'cp1255'
     self.assertEqual(pyfribidi.log2vis(u"שלום - hello".encode(charset),
                                        encoding=charset),
                      u"hello - םולש".encode(charset))
예제 #42
0
def get_extents(font_name ,text, font_size):
    result = log2vis(text)
    result = shape(font_name, text, font_size)
    x_advance = sum([char['x_advance'] for char in result])
    y_advance = 0
    return x_advance, y_advance
예제 #43
0
 def testEmpty(self):
     """ unicode: empty string """
     self.assertEqual(pyfribidi.log2vis(u''), u'')
예제 #44
0
def _getFragWords(frags, use_bidi=False):
   ''' given a Parafrag list return a list of fragwords
       [[size, (f00,w00), ..., (f0n,w0n)],....,[size, (fm0,wm0), ..., (f0n,wmn)]]
       each pair f,w represents a style and some string
       each sublist represents a word
   '''
   R = [] # the collection of frag information
   W = [] # a frag per word
   n = 0  # width of the frag
   hangingStrip = False

   for f in frags:
       text = f.text

       if use_bidi and pyfribidi:
           text = pyfribidi.log2vis(text)

            # PDF renderers commonly mishandle uFEFF, but it's safe to delete it, so do that now.
           if u'\ufeff' in text:
               text = u''.join([c for c in text if c != u'\ufeff'])

       else:
           is_indic = False
           for c in text:
               if 2304 <= ord(c) <= 3071 or 3398 <= ord(c) <= 3415 or 4096 <= ord(c) <= 4191:
                   is_indic = True
                   break

           if is_indic:
               dependent_vowels = (u'\u0a3f',  u'\u0bc6', u'\u0bc7', u'\u0bc8', u'\u09bf', u'\u09c7',
                    u'\u09c8', u'\u0d46', u'\u0d47', u'\u0d48', u'\u093f', u'\u0b47', u'\u0abf', u'\u1031',
                    u'\u0dd9', u'\u0ddb')

               text = [c for c in text]
               k = 1
               for c in text[1:]:
                   if c in dependent_vowels:
                       text[k-1], text[k] = text[k], text[k-1]
                   k += 1

               text = u''.join(text)


       #del f.text # we can't do this until we sort out splitting
                   # of paragraphs
       if text!='':
           if hangingStrip:
               hangingStrip = False
               text = text.lstrip()
           #if type(text) is str:
           #    text = text.decode('utf8')
           S = split(text)
           if S==[]: S = ['']

           # not sure what's going on here yet
           if W!=[] and text[0] in whitespace:
               W.insert(0,n)
               R.append(W)
               W = []
               n = 0

           # loop through all but the last word
           for w in S[:-1]:
               W.append((f,w))
               n += stringWidth(w, f.fontName, f.fontSize)
               W.insert(0,n)
               R.append(W)
               W = []
               n = 0

           # handle the last word
           # WTF IS ALL OF THIS.

           # set the word to the last word, because we skipped it in the for loop above
           w = S[-1]
           W.append((f,w))
           n += stringWidth(w, f.fontName, f.fontSize)
           # if the last character in the text is whitespace
           # then go ahead and add the wordfrag structure
           # otherwise it will be caught by the last if W != []
           # and the exact same thing will happen.. WTF
           # ^ but only if this is the last frag
           # otherwise this frag gets included in with something else
           # W is not always length = 2 when it is appended
           if text and text[-1] in whitespace:
               W.insert(0,n)
               R.append(W)
               W = []
               n = 0
       #elif hasattr(f,'cbDefn'):
       #    w = getattr(f.cbDefn,'width',0)
       #    if w:
       #        if W!=[]:
       #            W.insert(0,n)
       #            R.append(W)
       #            W = []
       #            n = 0
       #        R.append([w,(f,'')])
       #    else:
       #        W.append((f,''))
       elif hasattr(f, 'lineBreak'):
           #pass the frag through.  The line breaker will scan for it.
           if W!=[]:
               W.insert(0,n)
               R.append(W)
               W = []
               n = 0
           R.append([0,(f,'')])
           hangingStrip = True

   if W!=[]:
       W.insert(0,n)
       R.append(W)

   return R
예제 #45
0
 def testDefaultDirection(self):
     """ unicode: use RTL default """
     self.assertEqual(pyfribidi.log2vis(u"hello - שלום"),
                      pyfribidi.log2vis(u"hello - שלום", RTL))
예제 #46
0
 def test_log2vis(self):
     result = pyfribidi.log2vis(self.text)
     self.assertEqual(self.result, result)
예제 #47
0
 def testAsLTR(self):
     """ unicode: reorder line as LTR """
     self.assertEqual(pyfribidi.log2vis(u"hello - שלום", LTR),
                      u"hello - םולש")
예제 #48
0
 def format(self, item):
     return log2vis(item.project.initiator)
예제 #49
0
 def testNaturalRTL(self):
     """ unicode: reorder RTL line by natural order """
     self.assertEqual(pyfribidi.log2vis(u"שלום - hello", ON),
                      u"hello - םולש")
예제 #50
0
파일: cmus.py 프로젝트: kenanpelit/vim-cmus
def visualizeIfUnicode(s):
    return pyfribidi.log2vis(s, base_direction=pyfribidi.ON
            ).decode('utf-8')
예제 #51
0
 def format(self, item):
     return log2vis(item.project.name_and_city)
예제 #52
0
파일: twigi.py 프로젝트: thedod/twigi
 def bidi(s,enabled=DEFAULT_BIDI):
     if not enabled: return s
     return log2vis(s,base_direction=LTR)
예제 #53
0
def on_button_clicked(obj):
	inText = clip.wait_for_text()
	outText = pyfribidi.log2vis (inText, pyfribidi.ON)
	clip.set_text(outText)
예제 #54
0
 def testEmpty(self):
     """ utf8: empty string """
     self.assertEqual(pyfribidi.log2vis(''), '')