Return length of unicode 'text' under a fontsize.
(self, text, fontsize=11, language=None, script=0, wmode=0, small_caps=0)
| 8397 | return ret |
| 8398 | |
| 8399 | def text_length(self, text, fontsize=11, language=None, script=0, wmode=0, small_caps=0): |
| 8400 | """Return length of unicode 'text' under a fontsize.""" |
| 8401 | thisfont = self.this |
| 8402 | lang = mupdf.fz_text_language_from_string(language) |
| 8403 | rc = 0 |
| 8404 | if not isinstance(text, str): |
| 8405 | raise TypeError( MSG_BAD_TEXT) |
| 8406 | for ch in text: |
| 8407 | c = ord(ch) |
| 8408 | if small_caps: |
| 8409 | gid = mupdf.fz_encode_character_sc(thisfont, c) |
| 8410 | if gid >= 0: |
| 8411 | font = thisfont |
| 8412 | else: |
| 8413 | gid, font = mupdf.fz_encode_character_with_fallback(thisfont, c, script, lang) |
| 8414 | rc += mupdf.fz_advance_glyph(font, gid, wmode) |
| 8415 | rc *= fontsize |
| 8416 | return rc |
| 8417 | |
| 8418 | def unicode_to_glyph_name(self, ch): |
| 8419 | """Return the glyph name for a unicode.""" |
no outgoing calls