code: def getTJstr(text, glyphs, simple, ordering):
      
      if text.startswith("[<") and text.endswith(">]"): # already done
          return text
  
      if not bool(text):
          return "[<>]"
  
      if simple:
          if glyphs is None:             # simple and not Symbol / ZapfDingbats
              otxt = "".join([hex(ord(c))[2:].rjust(2, "0") if ord(c)<256 else "b7" for c in text])
          else:                          # Symbol or ZapfDingbats
              otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(2, "0") if ord(c)<256 else "b7" for c in text])
          return "[<" + otxt + ">]"
  
      if ordering < 0:                   # not a CJK font: use the glyphs
          otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(4, "0") for c in text])
      else:                              # CJK: use char codes, no glyphs
          otxt = "".join([hex(ord(c))[2:].rjust(4, "0") for c in text])
  
      return "[<" + otxt + ">]"
docs: Return a PDF string enclosed in [] brackets, suitable for the PDF TJ
      operator.
  
      Notes:
          The input string is converted to either 2 or 4 hex digits per character.
      Args:
          simple: no glyphs: 2-chars, use char codes as the glyph
                  glyphs: 2-chars, use glyphs instead of char codes (Symbol,
                  ZapfDingbats)
          not simple: ordering < 0: 4-chars, use glyphs not char codes
                      ordering >=0: a CJK font! 4 chars, use char codes as glyphs