Пример #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
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
 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(''), '')