MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / text_length

Method text_length

src/__init__.py:8399–8416  ·  view source on GitHub ↗

Return length of unicode 'text' under a fontsize.

(self, text, fontsize=11, language=None, script=0, wmode=0, small_caps=0)

Source from the content-addressed store, hash-verified

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."""

Callers 4

test_font1Function · 0.95
test_font2Function · 0.95
textlenMethod · 0.80
textlenFunction · 0.80

Calls

no outgoing calls

Tested by 2

test_font1Function · 0.76
test_font2Function · 0.76