id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
242,800 | pymupdf/PyMuPDF | fitz/fitz.py | Rect.includePoint | def includePoint(self, p):
"""Extend rectangle to include point p."""
if not len(p) == 2:
raise ValueError("bad sequ. length")
self.x0, self.y0, self.x1, self.y1 = TOOLS._include_point_in_rect(self, p)
return self | python | def includePoint(self, p):
if not len(p) == 2:
raise ValueError("bad sequ. length")
self.x0, self.y0, self.x1, self.y1 = TOOLS._include_point_in_rect(self, p)
return self | [
"def",
"includePoint",
"(",
"self",
",",
"p",
")",
":",
"if",
"not",
"len",
"(",
"p",
")",
"==",
"2",
":",
"raise",
"ValueError",
"(",
"\"bad sequ. length\"",
")",
"self",
".",
"x0",
",",
"self",
".",
"y0",
",",
"self",
".",
"x1",
",",
"self",
".... | Extend rectangle to include point p. | [
"Extend",
"rectangle",
"to",
"include",
"point",
"p",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L624-L629 |
242,801 | pymupdf/PyMuPDF | fitz/fitz.py | Rect.includeRect | def includeRect(self, r):
"""Extend rectangle to include rectangle r."""
if not len(r) == 4:
raise ValueError("bad sequ. length")
self.x0, self.y0, self.x1, self.y1 = TOOLS._union_rect(self, r)
return self | python | def includeRect(self, r):
if not len(r) == 4:
raise ValueError("bad sequ. length")
self.x0, self.y0, self.x1, self.y1 = TOOLS._union_rect(self, r)
return self | [
"def",
"includeRect",
"(",
"self",
",",
"r",
")",
":",
"if",
"not",
"len",
"(",
"r",
")",
"==",
"4",
":",
"raise",
"ValueError",
"(",
"\"bad sequ. length\"",
")",
"self",
".",
"x0",
",",
"self",
".",
"y0",
",",
"self",
".",
"x1",
",",
"self",
"."... | Extend rectangle to include rectangle r. | [
"Extend",
"rectangle",
"to",
"include",
"rectangle",
"r",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L631-L636 |
242,802 | pymupdf/PyMuPDF | fitz/fitz.py | Rect.intersect | def intersect(self, r):
"""Restrict self to common area with rectangle r."""
if not len(r) == 4:
raise ValueError("bad sequ. length")
self.x0, self.y0, self.x1, self.y1 = TOOLS._intersect_rect(self, r)
return self | python | def intersect(self, r):
if not len(r) == 4:
raise ValueError("bad sequ. length")
self.x0, self.y0, self.x1, self.y1 = TOOLS._intersect_rect(self, r)
return self | [
"def",
"intersect",
"(",
"self",
",",
"r",
")",
":",
"if",
"not",
"len",
"(",
"r",
")",
"==",
"4",
":",
"raise",
"ValueError",
"(",
"\"bad sequ. length\"",
")",
"self",
".",
"x0",
",",
"self",
".",
"y0",
",",
"self",
".",
"x1",
",",
"self",
".",
... | Restrict self to common area with rectangle r. | [
"Restrict",
"self",
"to",
"common",
"area",
"with",
"rectangle",
"r",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L638-L643 |
242,803 | pymupdf/PyMuPDF | fitz/fitz.py | Rect.transform | def transform(self, m):
"""Replace rectangle with its transformation by matrix m."""
if not len(m) == 6:
raise ValueError("bad sequ. length")
self.x0, self.y0, self.x1, self.y1 = TOOLS._transform_rect(self, m)
return self | python | def transform(self, m):
if not len(m) == 6:
raise ValueError("bad sequ. length")
self.x0, self.y0, self.x1, self.y1 = TOOLS._transform_rect(self, m)
return self | [
"def",
"transform",
"(",
"self",
",",
"m",
")",
":",
"if",
"not",
"len",
"(",
"m",
")",
"==",
"6",
":",
"raise",
"ValueError",
"(",
"\"bad sequ. length\"",
")",
"self",
".",
"x0",
",",
"self",
".",
"y0",
",",
"self",
".",
"x1",
",",
"self",
".",
... | Replace rectangle with its transformation by matrix m. | [
"Replace",
"rectangle",
"with",
"its",
"transformation",
"by",
"matrix",
"m",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L645-L650 |
242,804 | pymupdf/PyMuPDF | fitz/fitz.py | Rect.intersects | def intersects(self, x):
"""Check if intersection with rectangle x is not empty."""
r1 = Rect(x)
if self.isEmpty or self.isInfinite or r1.isEmpty:
return False
r = Rect(self)
if r.intersect(r1).isEmpty:
return False
return True | python | def intersects(self, x):
r1 = Rect(x)
if self.isEmpty or self.isInfinite or r1.isEmpty:
return False
r = Rect(self)
if r.intersect(r1).isEmpty:
return False
return True | [
"def",
"intersects",
"(",
"self",
",",
"x",
")",
":",
"r1",
"=",
"Rect",
"(",
"x",
")",
"if",
"self",
".",
"isEmpty",
"or",
"self",
".",
"isInfinite",
"or",
"r1",
".",
"isEmpty",
":",
"return",
"False",
"r",
"=",
"Rect",
"(",
"self",
")",
"if",
... | Check if intersection with rectangle x is not empty. | [
"Check",
"if",
"intersection",
"with",
"rectangle",
"x",
"is",
"not",
"empty",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L766-L774 |
242,805 | pymupdf/PyMuPDF | fitz/fitz.py | Quad.isRectangular | def isRectangular(self):
"""Check if quad is rectangular.
"""
# if any two of the 4 corners are equal return false
upper = (self.ur - self.ul).unit
if not bool(upper):
return False
right = (self.lr - self.ur).unit
if not bool(right):
return False
left = (self.ll - self.ul).unit
if not bool(left):
return False
lower = (self.lr - self.ll).unit
if not bool(lower):
return False
eps = 1e-5
# we now have 4 sides of length 1. If 3 of them have 90 deg angles,
# then it is a rectangle -- we check via scalar product == 0
return abs(sum(map(lambda x,y: x*y, upper, right))) <= eps and \
abs(sum(map(lambda x,y: x*y, upper, left))) <= eps and \
abs(sum(map(lambda x,y: x*y, left, lower))) <= eps | python | def isRectangular(self):
# if any two of the 4 corners are equal return false
upper = (self.ur - self.ul).unit
if not bool(upper):
return False
right = (self.lr - self.ur).unit
if not bool(right):
return False
left = (self.ll - self.ul).unit
if not bool(left):
return False
lower = (self.lr - self.ll).unit
if not bool(lower):
return False
eps = 1e-5
# we now have 4 sides of length 1. If 3 of them have 90 deg angles,
# then it is a rectangle -- we check via scalar product == 0
return abs(sum(map(lambda x,y: x*y, upper, right))) <= eps and \
abs(sum(map(lambda x,y: x*y, upper, left))) <= eps and \
abs(sum(map(lambda x,y: x*y, left, lower))) <= eps | [
"def",
"isRectangular",
"(",
"self",
")",
":",
"# if any two of the 4 corners are equal return false",
"upper",
"=",
"(",
"self",
".",
"ur",
"-",
"self",
".",
"ul",
")",
".",
"unit",
"if",
"not",
"bool",
"(",
"upper",
")",
":",
"return",
"False",
"right",
... | Check if quad is rectangular. | [
"Check",
"if",
"quad",
"is",
"rectangular",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L879-L900 |
242,806 | pymupdf/PyMuPDF | fitz/fitz.py | Quad.transform | def transform(self, m):
"""Replace quad by its transformation with matrix m."""
if len(m) != 6:
raise ValueError("bad sequ. length")
self.ul *= m
self.ur *= m
self.ll *= m
self.lr *= m
return self | python | def transform(self, m):
if len(m) != 6:
raise ValueError("bad sequ. length")
self.ul *= m
self.ur *= m
self.ll *= m
self.lr *= m
return self | [
"def",
"transform",
"(",
"self",
",",
"m",
")",
":",
"if",
"len",
"(",
"m",
")",
"!=",
"6",
":",
"raise",
"ValueError",
"(",
"\"bad sequ. length\"",
")",
"self",
".",
"ul",
"*=",
"m",
"self",
".",
"ur",
"*=",
"m",
"self",
".",
"ll",
"*=",
"m",
... | Replace quad by its transformation with matrix m. | [
"Replace",
"quad",
"by",
"its",
"transformation",
"with",
"matrix",
"m",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L968-L976 |
242,807 | pymupdf/PyMuPDF | fitz/fitz.py | Widget._validate | def _validate(self):
"""Validate the class entries.
"""
checker = (self._check0, self._check1, self._check2, self._check3,
self._check4, self._check5)
if not 0 <= self.field_type <= 5:
raise NotImplementedError("unsupported widget type")
if type(self.rect) is not Rect:
raise ValueError("invalid rect")
if self.rect.isInfinite or self.rect.isEmpty:
raise ValueError("rect must be finite and not empty")
if not self.field_name:
raise ValueError("field name missing")
if self.border_color:
if not len(self.border_color) in range(1,5) or \
type(self.border_color) not in (list, tuple):
raise ValueError("border_color must be 1 - 4 floats")
if self.fill_color:
if not len(self.fill_color) in range(1,5) or \
type(self.fill_color) not in (list, tuple):
raise ValueError("fill_color must be 1 - 4 floats")
if not self.text_color:
self.text_color = (0, 0, 0)
if not len(self.text_color) in range(1,5) or \
type(self.text_color) not in (list, tuple):
raise ValueError("text_color must be 1 - 4 floats")
if not self.border_width:
self.border_width = 0
if not self.text_fontsize:
self.text_fontsize = 0
checker[self.field_type]() | python | def _validate(self):
checker = (self._check0, self._check1, self._check2, self._check3,
self._check4, self._check5)
if not 0 <= self.field_type <= 5:
raise NotImplementedError("unsupported widget type")
if type(self.rect) is not Rect:
raise ValueError("invalid rect")
if self.rect.isInfinite or self.rect.isEmpty:
raise ValueError("rect must be finite and not empty")
if not self.field_name:
raise ValueError("field name missing")
if self.border_color:
if not len(self.border_color) in range(1,5) or \
type(self.border_color) not in (list, tuple):
raise ValueError("border_color must be 1 - 4 floats")
if self.fill_color:
if not len(self.fill_color) in range(1,5) or \
type(self.fill_color) not in (list, tuple):
raise ValueError("fill_color must be 1 - 4 floats")
if not self.text_color:
self.text_color = (0, 0, 0)
if not len(self.text_color) in range(1,5) or \
type(self.text_color) not in (list, tuple):
raise ValueError("text_color must be 1 - 4 floats")
if not self.border_width:
self.border_width = 0
if not self.text_fontsize:
self.text_fontsize = 0
checker[self.field_type]() | [
"def",
"_validate",
"(",
"self",
")",
":",
"checker",
"=",
"(",
"self",
".",
"_check0",
",",
"self",
".",
"_check1",
",",
"self",
".",
"_check2",
",",
"self",
".",
"_check3",
",",
"self",
".",
"_check4",
",",
"self",
".",
"_check5",
")",
"if",
"not... | Validate the class entries. | [
"Validate",
"the",
"class",
"entries",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1047-L1083 |
242,808 | pymupdf/PyMuPDF | fitz/fitz.py | Widget._adjust_font | def _adjust_font(self):
"""Ensure the font name is from our list and correctly spelled.
"""
fnames = [k for k in Widget_fontdict.keys()]
fl = list(map(str.lower, fnames))
if (not self.text_font) or self.text_font.lower() not in fl:
self.text_font = "helv"
i = fl.index(self.text_font.lower())
self.text_font = fnames[i]
return | python | def _adjust_font(self):
fnames = [k for k in Widget_fontdict.keys()]
fl = list(map(str.lower, fnames))
if (not self.text_font) or self.text_font.lower() not in fl:
self.text_font = "helv"
i = fl.index(self.text_font.lower())
self.text_font = fnames[i]
return | [
"def",
"_adjust_font",
"(",
"self",
")",
":",
"fnames",
"=",
"[",
"k",
"for",
"k",
"in",
"Widget_fontdict",
".",
"keys",
"(",
")",
"]",
"fl",
"=",
"list",
"(",
"map",
"(",
"str",
".",
"lower",
",",
"fnames",
")",
")",
"if",
"(",
"not",
"self",
... | Ensure the font name is from our list and correctly spelled. | [
"Ensure",
"the",
"font",
"name",
"is",
"from",
"our",
"list",
"and",
"correctly",
"spelled",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1085-L1094 |
242,809 | pymupdf/PyMuPDF | fitz/fitz.py | Document.embeddedFileCount | def embeddedFileCount(self):
"""Return number of embedded files."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileCount(self) | python | def embeddedFileCount(self):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileCount(self) | [
"def",
"embeddedFileCount",
"(",
"self",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_embeddedFileCount",
"(",
"... | Return number of embedded files. | [
"Return",
"number",
"of",
"embedded",
"files",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1906-L1911 |
242,810 | pymupdf/PyMuPDF | fitz/fitz.py | Document.embeddedFileDel | def embeddedFileDel(self, name):
"""Delete embedded file by name."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileDel(self, name) | python | def embeddedFileDel(self, name):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileDel(self, name) | [
"def",
"embeddedFileDel",
"(",
"self",
",",
"name",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_embeddedFileDel... | Delete embedded file by name. | [
"Delete",
"embedded",
"file",
"by",
"name",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1914-L1919 |
242,811 | pymupdf/PyMuPDF | fitz/fitz.py | Document.embeddedFileInfo | def embeddedFileInfo(self, id):
"""Retrieve embedded file information given its entry number or name."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileInfo(self, id) | python | def embeddedFileInfo(self, id):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileInfo(self, id) | [
"def",
"embeddedFileInfo",
"(",
"self",
",",
"id",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_embeddedFileInfo... | Retrieve embedded file information given its entry number or name. | [
"Retrieve",
"embedded",
"file",
"information",
"given",
"its",
"entry",
"number",
"or",
"name",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1922-L1927 |
242,812 | pymupdf/PyMuPDF | fitz/fitz.py | Document.embeddedFileUpd | def embeddedFileUpd(self, id, buffer=None, filename=None, ufilename=None, desc=None):
"""Change an embedded file given its entry number or name."""
return _fitz.Document_embeddedFileUpd(self, id, buffer, filename, ufilename, desc) | python | def embeddedFileUpd(self, id, buffer=None, filename=None, ufilename=None, desc=None):
return _fitz.Document_embeddedFileUpd(self, id, buffer, filename, ufilename, desc) | [
"def",
"embeddedFileUpd",
"(",
"self",
",",
"id",
",",
"buffer",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"ufilename",
"=",
"None",
",",
"desc",
"=",
"None",
")",
":",
"return",
"_fitz",
".",
"Document_embeddedFileUpd",
"(",
"self",
",",
"id",
"... | Change an embedded file given its entry number or name. | [
"Change",
"an",
"embedded",
"file",
"given",
"its",
"entry",
"number",
"or",
"name",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1930-L1932 |
242,813 | pymupdf/PyMuPDF | fitz/fitz.py | Document.embeddedFileGet | def embeddedFileGet(self, id):
"""Retrieve embedded file content by name or by number."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileGet(self, id) | python | def embeddedFileGet(self, id):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileGet(self, id) | [
"def",
"embeddedFileGet",
"(",
"self",
",",
"id",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_embeddedFileGet",... | Retrieve embedded file content by name or by number. | [
"Retrieve",
"embedded",
"file",
"content",
"by",
"name",
"or",
"by",
"number",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1940-L1945 |
242,814 | pymupdf/PyMuPDF | fitz/fitz.py | Document.embeddedFileAdd | def embeddedFileAdd(self, buffer, name, filename=None, ufilename=None, desc=None):
"""Embed a new file."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileAdd(self, buffer, name, filename, ufilename, desc) | python | def embeddedFileAdd(self, buffer, name, filename=None, ufilename=None, desc=None):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileAdd(self, buffer, name, filename, ufilename, desc) | [
"def",
"embeddedFileAdd",
"(",
"self",
",",
"buffer",
",",
"name",
",",
"filename",
"=",
"None",
",",
"ufilename",
"=",
"None",
",",
"desc",
"=",
"None",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueErr... | Embed a new file. | [
"Embed",
"a",
"new",
"file",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1948-L1955 |
242,815 | pymupdf/PyMuPDF | fitz/fitz.py | Document.convertToPDF | def convertToPDF(self, from_page=0, to_page=-1, rotate=0):
"""Convert document to PDF selecting page range and optional rotation. Output bytes object."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_convertToPDF(self, from_page, to_page, rotate) | python | def convertToPDF(self, from_page=0, to_page=-1, rotate=0):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_convertToPDF(self, from_page, to_page, rotate) | [
"def",
"convertToPDF",
"(",
"self",
",",
"from_page",
"=",
"0",
",",
"to_page",
"=",
"-",
"1",
",",
"rotate",
"=",
"0",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for c... | Convert document to PDF selecting page range and optional rotation. Output bytes object. | [
"Convert",
"document",
"to",
"PDF",
"selecting",
"page",
"range",
"and",
"optional",
"rotation",
".",
"Output",
"bytes",
"object",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1958-L1963 |
242,816 | pymupdf/PyMuPDF | fitz/fitz.py | Document.layout | def layout(self, rect=None, width=0, height=0, fontsize=11):
"""Re-layout a reflowable document."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document_layout(self, rect, width, height, fontsize)
self._reset_page_refs()
self.initData()
return val | python | def layout(self, rect=None, width=0, height=0, fontsize=11):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document_layout(self, rect, width, height, fontsize)
self._reset_page_refs()
self.initData()
return val | [
"def",
"layout",
"(",
"self",
",",
"rect",
"=",
"None",
",",
"width",
"=",
"0",
",",
"height",
"=",
"0",
",",
"fontsize",
"=",
"11",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"oper... | Re-layout a reflowable document. | [
"Re",
"-",
"layout",
"a",
"reflowable",
"document",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L1997-L2007 |
242,817 | pymupdf/PyMuPDF | fitz/fitz.py | Document.makeBookmark | def makeBookmark(self, pno=0):
"""Make page bookmark in a reflowable document."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_makeBookmark(self, pno) | python | def makeBookmark(self, pno=0):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_makeBookmark(self, pno) | [
"def",
"makeBookmark",
"(",
"self",
",",
"pno",
"=",
"0",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_makeB... | Make page bookmark in a reflowable document. | [
"Make",
"page",
"bookmark",
"in",
"a",
"reflowable",
"document",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2010-L2015 |
242,818 | pymupdf/PyMuPDF | fitz/fitz.py | Document.findBookmark | def findBookmark(self, bookmark):
"""Find page number after layouting a document."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_findBookmark(self, bookmark) | python | def findBookmark(self, bookmark):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_findBookmark(self, bookmark) | [
"def",
"findBookmark",
"(",
"self",
",",
"bookmark",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_findBookmark",... | Find page number after layouting a document. | [
"Find",
"page",
"number",
"after",
"layouting",
"a",
"document",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2018-L2023 |
242,819 | pymupdf/PyMuPDF | fitz/fitz.py | Document._deleteObject | def _deleteObject(self, xref):
"""Delete an object given its xref."""
if self.isClosed:
raise ValueError("operation illegal for closed doc")
return _fitz.Document__deleteObject(self, xref) | python | def _deleteObject(self, xref):
if self.isClosed:
raise ValueError("operation illegal for closed doc")
return _fitz.Document__deleteObject(self, xref) | [
"def",
"_deleteObject",
"(",
"self",
",",
"xref",
")",
":",
"if",
"self",
".",
"isClosed",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed doc\"",
")",
"return",
"_fitz",
".",
"Document__deleteObject",
"(",
"self",
",",
"xref",
")"
] | Delete an object given its xref. | [
"Delete",
"an",
"object",
"given",
"its",
"xref",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2035-L2040 |
242,820 | pymupdf/PyMuPDF | fitz/fitz.py | Document.authenticate | def authenticate(self, password):
"""Decrypt document with a password."""
if self.isClosed:
raise ValueError("operation illegal for closed doc")
val = _fitz.Document_authenticate(self, password)
if val: # the doc is decrypted successfully and we init the outline
self.isEncrypted = 0
self.initData()
self.thisown = True
return val | python | def authenticate(self, password):
if self.isClosed:
raise ValueError("operation illegal for closed doc")
val = _fitz.Document_authenticate(self, password)
if val: # the doc is decrypted successfully and we init the outline
self.isEncrypted = 0
self.initData()
self.thisown = True
return val | [
"def",
"authenticate",
"(",
"self",
",",
"password",
")",
":",
"if",
"self",
".",
"isClosed",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed doc\"",
")",
"val",
"=",
"_fitz",
".",
"Document_authenticate",
"(",
"self",
",",
"password",
")",
"i... | Decrypt document with a password. | [
"Decrypt",
"document",
"with",
"a",
"password",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2105-L2118 |
242,821 | pymupdf/PyMuPDF | fitz/fitz.py | Document.write | def write(self, garbage=0, clean=0, deflate=0, ascii=0, expand=0, linear=0, pretty=0, decrypt=1):
"""Write document to a bytes object."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.pageCount < 1:
raise ValueError("cannot write with zero pages")
return _fitz.Document_write(self, garbage, clean, deflate, ascii, expand, linear, pretty, decrypt) | python | def write(self, garbage=0, clean=0, deflate=0, ascii=0, expand=0, linear=0, pretty=0, decrypt=1):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.pageCount < 1:
raise ValueError("cannot write with zero pages")
return _fitz.Document_write(self, garbage, clean, deflate, ascii, expand, linear, pretty, decrypt) | [
"def",
"write",
"(",
"self",
",",
"garbage",
"=",
"0",
",",
"clean",
"=",
"0",
",",
"deflate",
"=",
"0",
",",
"ascii",
"=",
"0",
",",
"expand",
"=",
"0",
",",
"linear",
"=",
"0",
",",
"pretty",
"=",
"0",
",",
"decrypt",
"=",
"1",
")",
":",
... | Write document to a bytes object. | [
"Write",
"document",
"to",
"a",
"bytes",
"object",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2144-L2153 |
242,822 | pymupdf/PyMuPDF | fitz/fitz.py | Document.select | def select(self, pyliste):
"""Build sub-pdf with page numbers in 'list'."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document_select(self, pyliste)
self._reset_page_refs()
self.initData()
return val | python | def select(self, pyliste):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document_select(self, pyliste)
self._reset_page_refs()
self.initData()
return val | [
"def",
"select",
"(",
"self",
",",
"pyliste",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"val",
"=",
"_fitz",
".",
"Document_select",
"(",
... | Build sub-pdf with page numbers in 'list'. | [
"Build",
"sub",
"-",
"pdf",
"with",
"page",
"numbers",
"in",
"list",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2186-L2196 |
242,823 | pymupdf/PyMuPDF | fitz/fitz.py | Document._getCharWidths | def _getCharWidths(self, xref, bfname, ext, ordering, limit, idx=0):
"""Return list of glyphs and glyph widths of a font."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document__getCharWidths(self, xref, bfname, ext, ordering, limit, idx) | python | def _getCharWidths(self, xref, bfname, ext, ordering, limit, idx=0):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document__getCharWidths(self, xref, bfname, ext, ordering, limit, idx) | [
"def",
"_getCharWidths",
"(",
"self",
",",
"xref",
",",
"bfname",
",",
"ext",
",",
"ordering",
",",
"limit",
",",
"idx",
"=",
"0",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation ... | Return list of glyphs and glyph widths of a font. | [
"Return",
"list",
"of",
"glyphs",
"and",
"glyph",
"widths",
"of",
"a",
"font",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2208-L2213 |
242,824 | pymupdf/PyMuPDF | fitz/fitz.py | Document._getPageInfo | def _getPageInfo(self, pno, what):
"""Show fonts or images used on a page."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document__getPageInfo(self, pno, what)
x = []
for v in val:
if v not in x:
x.append(v)
val = x
return val | python | def _getPageInfo(self, pno, what):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
val = _fitz.Document__getPageInfo(self, pno, what)
x = []
for v in val:
if v not in x:
x.append(v)
val = x
return val | [
"def",
"_getPageInfo",
"(",
"self",
",",
"pno",
",",
"what",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"val",
"=",
"_fitz",
".",
"Documen... | Show fonts or images used on a page. | [
"Show",
"fonts",
"or",
"images",
"used",
"on",
"a",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2224-L2237 |
242,825 | pymupdf/PyMuPDF | fitz/fitz.py | Document.extractImage | def extractImage(self, xref=0):
"""Extract image which 'xref' is pointing to."""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_extractImage(self, xref) | python | def extractImage(self, xref=0):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_extractImage(self, xref) | [
"def",
"extractImage",
"(",
"self",
",",
"xref",
"=",
"0",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"return",
"_fitz",
".",
"Document_extr... | Extract image which 'xref' is pointing to. | [
"Extract",
"image",
"which",
"xref",
"is",
"pointing",
"to",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2248-L2253 |
242,826 | pymupdf/PyMuPDF | fitz/fitz.py | Document.getPageFontList | def getPageFontList(self, pno):
"""Retrieve a list of fonts used on a page.
"""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.isPDF:
return self._getPageInfo(pno, 1)
return [] | python | def getPageFontList(self, pno):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.isPDF:
return self._getPageInfo(pno, 1)
return [] | [
"def",
"getPageFontList",
"(",
"self",
",",
"pno",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"if",
"self",
".",
"isPDF",
":",
"return",
"... | Retrieve a list of fonts used on a page. | [
"Retrieve",
"a",
"list",
"of",
"fonts",
"used",
"on",
"a",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2391-L2398 |
242,827 | pymupdf/PyMuPDF | fitz/fitz.py | Document.getPageImageList | def getPageImageList(self, pno):
"""Retrieve a list of images used on a page.
"""
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.isPDF:
return self._getPageInfo(pno, 2)
return [] | python | def getPageImageList(self, pno):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
if self.isPDF:
return self._getPageInfo(pno, 2)
return [] | [
"def",
"getPageImageList",
"(",
"self",
",",
"pno",
")",
":",
"if",
"self",
".",
"isClosed",
"or",
"self",
".",
"isEncrypted",
":",
"raise",
"ValueError",
"(",
"\"operation illegal for closed / encrypted doc\"",
")",
"if",
"self",
".",
"isPDF",
":",
"return",
... | Retrieve a list of images used on a page. | [
"Retrieve",
"a",
"list",
"of",
"images",
"used",
"on",
"a",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2400-L2407 |
242,828 | pymupdf/PyMuPDF | fitz/fitz.py | Document.copyPage | def copyPage(self, pno, to=-1):
"""Copy a page to before some other page of the document. Specify 'to = -1' to copy after last page.
"""
pl = list(range(len(self)))
if pno < 0 or pno > pl[-1]:
raise ValueError("'from' page number out of range")
if to < -1 or to > pl[-1]:
raise ValueError("'to' page number out of range")
if to == -1:
pl.append(pno)
else:
pl.insert(to, pno)
return self.select(pl) | python | def copyPage(self, pno, to=-1):
pl = list(range(len(self)))
if pno < 0 or pno > pl[-1]:
raise ValueError("'from' page number out of range")
if to < -1 or to > pl[-1]:
raise ValueError("'to' page number out of range")
if to == -1:
pl.append(pno)
else:
pl.insert(to, pno)
return self.select(pl) | [
"def",
"copyPage",
"(",
"self",
",",
"pno",
",",
"to",
"=",
"-",
"1",
")",
":",
"pl",
"=",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
")",
")",
")",
"if",
"pno",
"<",
"0",
"or",
"pno",
">",
"pl",
"[",
"-",
"1",
"]",
":",
"raise",
"Val... | Copy a page to before some other page of the document. Specify 'to = -1' to copy after last page. | [
"Copy",
"a",
"page",
"to",
"before",
"some",
"other",
"page",
"of",
"the",
"document",
".",
"Specify",
"to",
"=",
"-",
"1",
"to",
"copy",
"after",
"last",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2409-L2421 |
242,829 | pymupdf/PyMuPDF | fitz/fitz.py | Document.movePage | def movePage(self, pno, to = -1):
"""Move a page to before some other page of the document. Specify 'to = -1' to move after last page.
"""
pl = list(range(len(self)))
if pno < 0 or pno > pl[-1]:
raise ValueError("'from' page number out of range")
if to < -1 or to > pl[-1]:
raise ValueError("'to' page number out of range")
pl.remove(pno)
if to == -1:
pl.append(pno)
else:
pl.insert(to-1, pno)
return self.select(pl) | python | def movePage(self, pno, to = -1):
pl = list(range(len(self)))
if pno < 0 or pno > pl[-1]:
raise ValueError("'from' page number out of range")
if to < -1 or to > pl[-1]:
raise ValueError("'to' page number out of range")
pl.remove(pno)
if to == -1:
pl.append(pno)
else:
pl.insert(to-1, pno)
return self.select(pl) | [
"def",
"movePage",
"(",
"self",
",",
"pno",
",",
"to",
"=",
"-",
"1",
")",
":",
"pl",
"=",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
")",
")",
")",
"if",
"pno",
"<",
"0",
"or",
"pno",
">",
"pl",
"[",
"-",
"1",
"]",
":",
"raise",
"Val... | Move a page to before some other page of the document. Specify 'to = -1' to move after last page. | [
"Move",
"a",
"page",
"to",
"before",
"some",
"other",
"page",
"of",
"the",
"document",
".",
"Specify",
"to",
"=",
"-",
"1",
"to",
"move",
"after",
"last",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2423-L2436 |
242,830 | pymupdf/PyMuPDF | fitz/fitz.py | Document.deletePage | def deletePage(self, pno = -1):
"""Delete a page from the document. First page is '0', last page is '-1'.
"""
pl = list(range(len(self)))
if pno < -1 or pno > pl[-1]:
raise ValueError("page number out of range")
if pno >= 0:
pl.remove(pno)
else:
pl.remove(pl[-1])
return self.select(pl) | python | def deletePage(self, pno = -1):
pl = list(range(len(self)))
if pno < -1 or pno > pl[-1]:
raise ValueError("page number out of range")
if pno >= 0:
pl.remove(pno)
else:
pl.remove(pl[-1])
return self.select(pl) | [
"def",
"deletePage",
"(",
"self",
",",
"pno",
"=",
"-",
"1",
")",
":",
"pl",
"=",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
")",
")",
")",
"if",
"pno",
"<",
"-",
"1",
"or",
"pno",
">",
"pl",
"[",
"-",
"1",
"]",
":",
"raise",
"ValueErro... | Delete a page from the document. First page is '0', last page is '-1'. | [
"Delete",
"a",
"page",
"from",
"the",
"document",
".",
"First",
"page",
"is",
"0",
"last",
"page",
"is",
"-",
"1",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2438-L2448 |
242,831 | pymupdf/PyMuPDF | fitz/fitz.py | Document.deletePageRange | def deletePageRange(self, from_page = -1, to_page = -1):
"""Delete pages from the document. First page is '0', last page is '-1'.
"""
pl = list(range(len(self)))
f = from_page
t = to_page
if f == -1:
f = pl[-1]
if t == -1:
t = pl[-1]
if not 0 <= f <= t <= pl[-1]:
raise ValueError("page number(s) out of range")
for i in range(f, t+1):
pl.remove(i)
return self.select(pl) | python | def deletePageRange(self, from_page = -1, to_page = -1):
pl = list(range(len(self)))
f = from_page
t = to_page
if f == -1:
f = pl[-1]
if t == -1:
t = pl[-1]
if not 0 <= f <= t <= pl[-1]:
raise ValueError("page number(s) out of range")
for i in range(f, t+1):
pl.remove(i)
return self.select(pl) | [
"def",
"deletePageRange",
"(",
"self",
",",
"from_page",
"=",
"-",
"1",
",",
"to_page",
"=",
"-",
"1",
")",
":",
"pl",
"=",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
")",
")",
")",
"f",
"=",
"from_page",
"t",
"=",
"to_page",
"if",
"f",
"==... | Delete pages from the document. First page is '0', last page is '-1'. | [
"Delete",
"pages",
"from",
"the",
"document",
".",
"First",
"page",
"is",
"0",
"last",
"page",
"is",
"-",
"1",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2450-L2464 |
242,832 | pymupdf/PyMuPDF | fitz/fitz.py | Document._forget_page | def _forget_page(self, page):
"""Remove a page from document page dict."""
pid = id(page)
if pid in self._page_refs:
self._page_refs[pid] = None | python | def _forget_page(self, page):
pid = id(page)
if pid in self._page_refs:
self._page_refs[pid] = None | [
"def",
"_forget_page",
"(",
"self",
",",
"page",
")",
":",
"pid",
"=",
"id",
"(",
"page",
")",
"if",
"pid",
"in",
"self",
".",
"_page_refs",
":",
"self",
".",
"_page_refs",
"[",
"pid",
"]",
"=",
"None"
] | Remove a page from document page dict. | [
"Remove",
"a",
"page",
"from",
"document",
"page",
"dict",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2488-L2492 |
242,833 | pymupdf/PyMuPDF | fitz/fitz.py | Document._reset_page_refs | def _reset_page_refs(self):
"""Invalidate all pages in document dictionary."""
if self.isClosed:
return
for page in self._page_refs.values():
if page:
page._erase()
page = None
self._page_refs.clear() | python | def _reset_page_refs(self):
if self.isClosed:
return
for page in self._page_refs.values():
if page:
page._erase()
page = None
self._page_refs.clear() | [
"def",
"_reset_page_refs",
"(",
"self",
")",
":",
"if",
"self",
".",
"isClosed",
":",
"return",
"for",
"page",
"in",
"self",
".",
"_page_refs",
".",
"values",
"(",
")",
":",
"if",
"page",
":",
"page",
".",
"_erase",
"(",
")",
"page",
"=",
"None",
"... | Invalidate all pages in document dictionary. | [
"Invalidate",
"all",
"pages",
"in",
"document",
"dictionary",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2494-L2502 |
242,834 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addLineAnnot | def addLineAnnot(self, p1, p2):
"""Add 'Line' annot for points p1 and p2."""
CheckParent(self)
val = _fitz.Page_addLineAnnot(self, p1, p2)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addLineAnnot(self, p1, p2):
CheckParent(self)
val = _fitz.Page_addLineAnnot(self, p1, p2)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addLineAnnot",
"(",
"self",
",",
"p1",
",",
"p2",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addLineAnnot",
"(",
"self",
",",
"p1",
",",
"p2",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=... | Add 'Line' annot for points p1 and p2. | [
"Add",
"Line",
"annot",
"for",
"points",
"p1",
"and",
"p2",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2563-L2574 |
242,835 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addTextAnnot | def addTextAnnot(self, point, text):
"""Add a 'sticky note' at position 'point'."""
CheckParent(self)
val = _fitz.Page_addTextAnnot(self, point, text)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addTextAnnot(self, point, text):
CheckParent(self)
val = _fitz.Page_addTextAnnot(self, point, text)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addTextAnnot",
"(",
"self",
",",
"point",
",",
"text",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addTextAnnot",
"(",
"self",
",",
"point",
",",
"text",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"this... | Add a 'sticky note' at position 'point'. | [
"Add",
"a",
"sticky",
"note",
"at",
"position",
"point",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2577-L2588 |
242,836 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addInkAnnot | def addInkAnnot(self, list):
"""Add a 'handwriting' as a list of list of point-likes. Each sublist forms an independent stroke."""
CheckParent(self)
val = _fitz.Page_addInkAnnot(self, list)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addInkAnnot(self, list):
CheckParent(self)
val = _fitz.Page_addInkAnnot(self, list)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addInkAnnot",
"(",
"self",
",",
"list",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addInkAnnot",
"(",
"self",
",",
"list",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".",... | Add a 'handwriting' as a list of list of point-likes. Each sublist forms an independent stroke. | [
"Add",
"a",
"handwriting",
"as",
"a",
"list",
"of",
"list",
"of",
"point",
"-",
"likes",
".",
"Each",
"sublist",
"forms",
"an",
"independent",
"stroke",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2591-L2602 |
242,837 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addStampAnnot | def addStampAnnot(self, rect, stamp=0):
"""Add a 'rubber stamp' in a rectangle."""
CheckParent(self)
val = _fitz.Page_addStampAnnot(self, rect, stamp)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addStampAnnot(self, rect, stamp=0):
CheckParent(self)
val = _fitz.Page_addStampAnnot(self, rect, stamp)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addStampAnnot",
"(",
"self",
",",
"rect",
",",
"stamp",
"=",
"0",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addStampAnnot",
"(",
"self",
",",
"rect",
",",
"stamp",
")",
"if",
"not",
"val",
":",
"return",
"val"... | Add a 'rubber stamp' in a rectangle. | [
"Add",
"a",
"rubber",
"stamp",
"in",
"a",
"rectangle",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2605-L2616 |
242,838 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addFileAnnot | def addFileAnnot(self, point, buffer, filename, ufilename=None, desc=None):
"""Add a 'FileAttachment' annotation at location 'point'."""
CheckParent(self)
val = _fitz.Page_addFileAnnot(self, point, buffer, filename, ufilename, desc)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addFileAnnot(self, point, buffer, filename, ufilename=None, desc=None):
CheckParent(self)
val = _fitz.Page_addFileAnnot(self, point, buffer, filename, ufilename, desc)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addFileAnnot",
"(",
"self",
",",
"point",
",",
"buffer",
",",
"filename",
",",
"ufilename",
"=",
"None",
",",
"desc",
"=",
"None",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addFileAnnot",
"(",
"self",
",",
"poin... | Add a 'FileAttachment' annotation at location 'point'. | [
"Add",
"a",
"FileAttachment",
"annotation",
"at",
"location",
"point",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2619-L2630 |
242,839 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addStrikeoutAnnot | def addStrikeoutAnnot(self, rect):
"""Strike out content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addStrikeoutAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addStrikeoutAnnot(self, rect):
CheckParent(self)
val = _fitz.Page_addStrikeoutAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addStrikeoutAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addStrikeoutAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"... | Strike out content in a rectangle or quadrilateral. | [
"Strike",
"out",
"content",
"in",
"a",
"rectangle",
"or",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2633-L2644 |
242,840 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addUnderlineAnnot | def addUnderlineAnnot(self, rect):
"""Underline content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addUnderlineAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addUnderlineAnnot(self, rect):
CheckParent(self)
val = _fitz.Page_addUnderlineAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addUnderlineAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addUnderlineAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"... | Underline content in a rectangle or quadrilateral. | [
"Underline",
"content",
"in",
"a",
"rectangle",
"or",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2647-L2658 |
242,841 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addSquigglyAnnot | def addSquigglyAnnot(self, rect):
"""Wavy underline content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addSquigglyAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addSquigglyAnnot(self, rect):
CheckParent(self)
val = _fitz.Page_addSquigglyAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addSquigglyAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addSquigglyAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"va... | Wavy underline content in a rectangle or quadrilateral. | [
"Wavy",
"underline",
"content",
"in",
"a",
"rectangle",
"or",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2661-L2672 |
242,842 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addHighlightAnnot | def addHighlightAnnot(self, rect):
"""Highlight content in a rectangle or quadrilateral."""
CheckParent(self)
val = _fitz.Page_addHighlightAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addHighlightAnnot(self, rect):
CheckParent(self)
val = _fitz.Page_addHighlightAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addHighlightAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addHighlightAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"... | Highlight content in a rectangle or quadrilateral. | [
"Highlight",
"content",
"in",
"a",
"rectangle",
"or",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2675-L2686 |
242,843 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addRectAnnot | def addRectAnnot(self, rect):
"""Add a 'Rectangle' annotation."""
CheckParent(self)
val = _fitz.Page_addRectAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addRectAnnot(self, rect):
CheckParent(self)
val = _fitz.Page_addRectAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addRectAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addRectAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
".... | Add a 'Rectangle' annotation. | [
"Add",
"a",
"Rectangle",
"annotation",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2689-L2700 |
242,844 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addCircleAnnot | def addCircleAnnot(self, rect):
"""Add a 'Circle' annotation."""
CheckParent(self)
val = _fitz.Page_addCircleAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addCircleAnnot(self, rect):
CheckParent(self)
val = _fitz.Page_addCircleAnnot(self, rect)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addCircleAnnot",
"(",
"self",
",",
"rect",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addCircleAnnot",
"(",
"self",
",",
"rect",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"val",
... | Add a 'Circle' annotation. | [
"Add",
"a",
"Circle",
"annotation",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2703-L2714 |
242,845 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addPolylineAnnot | def addPolylineAnnot(self, points):
"""Add a 'Polyline' annotation for a sequence of points."""
CheckParent(self)
val = _fitz.Page_addPolylineAnnot(self, points)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addPolylineAnnot(self, points):
CheckParent(self)
val = _fitz.Page_addPolylineAnnot(self, points)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addPolylineAnnot",
"(",
"self",
",",
"points",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addPolylineAnnot",
"(",
"self",
",",
"points",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
... | Add a 'Polyline' annotation for a sequence of points. | [
"Add",
"a",
"Polyline",
"annotation",
"for",
"a",
"sequence",
"of",
"points",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2717-L2728 |
242,846 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addPolygonAnnot | def addPolygonAnnot(self, points):
"""Add a 'Polygon' annotation for a sequence of points."""
CheckParent(self)
val = _fitz.Page_addPolygonAnnot(self, points)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addPolygonAnnot(self, points):
CheckParent(self)
val = _fitz.Page_addPolygonAnnot(self, points)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addPolygonAnnot",
"(",
"self",
",",
"points",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_addPolygonAnnot",
"(",
"self",
",",
"points",
")",
"if",
"not",
"val",
":",
"return",
"val",
".",
"thisown",
"=",
"True",
"... | Add a 'Polygon' annotation for a sequence of points. | [
"Add",
"a",
"Polygon",
"annotation",
"for",
"a",
"sequence",
"of",
"points",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2731-L2742 |
242,847 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addFreetextAnnot | def addFreetextAnnot(self, rect, text, fontsize=12, fontname=None, color=None, rotate=0):
"""Add a 'FreeText' annotation in rectangle 'rect'."""
CheckParent(self)
val = _fitz.Page_addFreetextAnnot(self, rect, text, fontsize, fontname, color, rotate)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | python | def addFreetextAnnot(self, rect, text, fontsize=12, fontname=None, color=None, rotate=0):
CheckParent(self)
val = _fitz.Page_addFreetextAnnot(self, rect, text, fontsize, fontname, color, rotate)
if not val: return
val.thisown = True
val.parent = weakref.proxy(self)
self._annot_refs[id(val)] = val
return val | [
"def",
"addFreetextAnnot",
"(",
"self",
",",
"rect",
",",
"text",
",",
"fontsize",
"=",
"12",
",",
"fontname",
"=",
"None",
",",
"color",
"=",
"None",
",",
"rotate",
"=",
"0",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Pa... | Add a 'FreeText' annotation in rectangle 'rect'. | [
"Add",
"a",
"FreeText",
"annotation",
"in",
"rectangle",
"rect",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2745-L2756 |
242,848 | pymupdf/PyMuPDF | fitz/fitz.py | Page.addWidget | def addWidget(self, widget):
"""Add a form field.
"""
CheckParent(self)
doc = self.parent
if not doc.isPDF:
raise ValueError("not a PDF")
widget._validate()
# Check if PDF already has our fonts.
# If none insert all of them in a new object and store the xref.
# Else only add any missing fonts.
# To determine the situation, /DR object is checked.
xref = 0
ff = doc.FormFonts # /DR object: existing fonts
if not widget.text_font: # ensure default
widget.text_font = "Helv"
if not widget.text_font in ff: # if no existent font ...
if not doc.isFormPDF or not ff: # a fresh /AcroForm PDF!
xref = doc._getNewXref() # insert all our fonts
doc._updateObject(xref, Widget_fontobjects)
else: # add any missing fonts
for k in Widget_fontdict.keys():
if not k in ff: # add our font if missing
doc._addFormFont(k, Widget_fontdict[k])
widget._adjust_font() # ensure correct font spelling
widget._dr_xref = xref # non-zero causes /DR creation
# now create the /DA string
if len(widget.text_color) == 3:
fmt = "{:g} {:g} {:g} rg /{f:s} {s:g} Tf " + widget._text_da
elif len(widget.text_color) == 1:
fmt = "{:g} g /{f:s} {s:g} Tf " + widget._text_da
elif len(widget.text_color) == 4:
fmt = "{:g} {:g} {:g} {:g} k /{f:s} {s:g} Tf " + widget._text_da
widget._text_da = fmt.format(*widget.text_color, f=widget.text_font,
s=widget.text_fontsize)
# create the widget at last
annot = self._addWidget(widget)
if annot:
annot.thisown = True
annot.parent = weakref.proxy(self) # owning page object
self._annot_refs[id(annot)] = annot
return annot | python | def addWidget(self, widget):
CheckParent(self)
doc = self.parent
if not doc.isPDF:
raise ValueError("not a PDF")
widget._validate()
# Check if PDF already has our fonts.
# If none insert all of them in a new object and store the xref.
# Else only add any missing fonts.
# To determine the situation, /DR object is checked.
xref = 0
ff = doc.FormFonts # /DR object: existing fonts
if not widget.text_font: # ensure default
widget.text_font = "Helv"
if not widget.text_font in ff: # if no existent font ...
if not doc.isFormPDF or not ff: # a fresh /AcroForm PDF!
xref = doc._getNewXref() # insert all our fonts
doc._updateObject(xref, Widget_fontobjects)
else: # add any missing fonts
for k in Widget_fontdict.keys():
if not k in ff: # add our font if missing
doc._addFormFont(k, Widget_fontdict[k])
widget._adjust_font() # ensure correct font spelling
widget._dr_xref = xref # non-zero causes /DR creation
# now create the /DA string
if len(widget.text_color) == 3:
fmt = "{:g} {:g} {:g} rg /{f:s} {s:g} Tf " + widget._text_da
elif len(widget.text_color) == 1:
fmt = "{:g} g /{f:s} {s:g} Tf " + widget._text_da
elif len(widget.text_color) == 4:
fmt = "{:g} {:g} {:g} {:g} k /{f:s} {s:g} Tf " + widget._text_da
widget._text_da = fmt.format(*widget.text_color, f=widget.text_font,
s=widget.text_fontsize)
# create the widget at last
annot = self._addWidget(widget)
if annot:
annot.thisown = True
annot.parent = weakref.proxy(self) # owning page object
self._annot_refs[id(annot)] = annot
return annot | [
"def",
"addWidget",
"(",
"self",
",",
"widget",
")",
":",
"CheckParent",
"(",
"self",
")",
"doc",
"=",
"self",
".",
"parent",
"if",
"not",
"doc",
".",
"isPDF",
":",
"raise",
"ValueError",
"(",
"\"not a PDF\"",
")",
"widget",
".",
"_validate",
"(",
")",... | Add a form field. | [
"Add",
"a",
"form",
"field",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2762-L2805 |
242,849 | pymupdf/PyMuPDF | fitz/fitz.py | Page.firstAnnot | def firstAnnot(self):
"""Points to first annotation on page"""
CheckParent(self)
val = _fitz.Page_firstAnnot(self)
if val:
val.thisown = True
val.parent = weakref.proxy(self) # owning page object
self._annot_refs[id(val)] = val
return val | python | def firstAnnot(self):
CheckParent(self)
val = _fitz.Page_firstAnnot(self)
if val:
val.thisown = True
val.parent = weakref.proxy(self) # owning page object
self._annot_refs[id(val)] = val
return val | [
"def",
"firstAnnot",
"(",
"self",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_firstAnnot",
"(",
"self",
")",
"if",
"val",
":",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=",
"weakref",
".",
"proxy",
"(",... | Points to first annotation on page | [
"Points",
"to",
"first",
"annotation",
"on",
"page"
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2848-L2858 |
242,850 | pymupdf/PyMuPDF | fitz/fitz.py | Page.deleteLink | def deleteLink(self, linkdict):
"""Delete link if PDF"""
CheckParent(self)
val = _fitz.Page_deleteLink(self, linkdict)
if linkdict["xref"] == 0: return
linkid = linkdict["id"]
try:
linkobj = self._annot_refs[linkid]
linkobj._erase()
except:
pass
return val | python | def deleteLink(self, linkdict):
CheckParent(self)
val = _fitz.Page_deleteLink(self, linkdict)
if linkdict["xref"] == 0: return
linkid = linkdict["id"]
try:
linkobj = self._annot_refs[linkid]
linkobj._erase()
except:
pass
return val | [
"def",
"deleteLink",
"(",
"self",
",",
"linkdict",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_deleteLink",
"(",
"self",
",",
"linkdict",
")",
"if",
"linkdict",
"[",
"\"xref\"",
"]",
"==",
"0",
":",
"return",
"linkid",
"=... | Delete link if PDF | [
"Delete",
"link",
"if",
"PDF"
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2861-L2875 |
242,851 | pymupdf/PyMuPDF | fitz/fitz.py | Page.deleteAnnot | def deleteAnnot(self, fannot):
"""Delete annot if PDF and return next one"""
CheckParent(self)
val = _fitz.Page_deleteAnnot(self, fannot)
if val:
val.thisown = True
val.parent = weakref.proxy(self) # owning page object
val.parent._annot_refs[id(val)] = val
fannot._erase()
return val | python | def deleteAnnot(self, fannot):
CheckParent(self)
val = _fitz.Page_deleteAnnot(self, fannot)
if val:
val.thisown = True
val.parent = weakref.proxy(self) # owning page object
val.parent._annot_refs[id(val)] = val
fannot._erase()
return val | [
"def",
"deleteAnnot",
"(",
"self",
",",
"fannot",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Page_deleteAnnot",
"(",
"self",
",",
"fannot",
")",
"if",
"val",
":",
"val",
".",
"thisown",
"=",
"True",
"val",
".",
"parent",
"=... | Delete annot if PDF and return next one | [
"Delete",
"annot",
"if",
"PDF",
"and",
"return",
"next",
"one"
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L2878-L2890 |
242,852 | pymupdf/PyMuPDF | fitz/fitz.py | Page._forget_annot | def _forget_annot(self, annot):
"""Remove an annot from reference dictionary."""
aid = id(annot)
if aid in self._annot_refs:
self._annot_refs[aid] = None | python | def _forget_annot(self, annot):
aid = id(annot)
if aid in self._annot_refs:
self._annot_refs[aid] = None | [
"def",
"_forget_annot",
"(",
"self",
",",
"annot",
")",
":",
"aid",
"=",
"id",
"(",
"annot",
")",
"if",
"aid",
"in",
"self",
".",
"_annot_refs",
":",
"self",
".",
"_annot_refs",
"[",
"aid",
"]",
"=",
"None"
] | Remove an annot from reference dictionary. | [
"Remove",
"an",
"annot",
"from",
"reference",
"dictionary",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L3072-L3076 |
242,853 | pymupdf/PyMuPDF | fitz/fitz.py | Annot.rect | def rect(self):
"""Rectangle containing the annot"""
CheckParent(self)
val = _fitz.Annot_rect(self)
val = Rect(val)
return val | python | def rect(self):
CheckParent(self)
val = _fitz.Annot_rect(self)
val = Rect(val)
return val | [
"def",
"rect",
"(",
"self",
")",
":",
"CheckParent",
"(",
"self",
")",
"val",
"=",
"_fitz",
".",
"Annot_rect",
"(",
"self",
")",
"val",
"=",
"Rect",
"(",
"val",
")",
"return",
"val"
] | Rectangle containing the annot | [
"Rectangle",
"containing",
"the",
"annot"
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L3586-L3593 |
242,854 | pymupdf/PyMuPDF | fitz/fitz.py | Annot.fileUpd | def fileUpd(self, buffer=None, filename=None, ufilename=None, desc=None):
"""Update annotation attached file."""
CheckParent(self)
return _fitz.Annot_fileUpd(self, buffer, filename, ufilename, desc) | python | def fileUpd(self, buffer=None, filename=None, ufilename=None, desc=None):
CheckParent(self)
return _fitz.Annot_fileUpd(self, buffer, filename, ufilename, desc) | [
"def",
"fileUpd",
"(",
"self",
",",
"buffer",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"ufilename",
"=",
"None",
",",
"desc",
"=",
"None",
")",
":",
"CheckParent",
"(",
"self",
")",
"return",
"_fitz",
".",
"Annot_fileUpd",
"(",
"self",
",",
"b... | Update annotation attached file. | [
"Update",
"annotation",
"attached",
"file",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L3888-L3894 |
242,855 | pymupdf/PyMuPDF | fitz/fitz.py | Link.dest | def dest(self):
"""Create link destination details."""
if hasattr(self, "parent") and self.parent is None:
raise ValueError("orphaned object: parent is None")
if self.parent.parent.isClosed or self.parent.parent.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
doc = self.parent.parent
if self.isExternal or self.uri.startswith("#"):
uri = None
else:
uri = doc.resolveLink(self.uri)
return linkDest(self, uri) | python | def dest(self):
if hasattr(self, "parent") and self.parent is None:
raise ValueError("orphaned object: parent is None")
if self.parent.parent.isClosed or self.parent.parent.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
doc = self.parent.parent
if self.isExternal or self.uri.startswith("#"):
uri = None
else:
uri = doc.resolveLink(self.uri)
return linkDest(self, uri) | [
"def",
"dest",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"\"parent\"",
")",
"and",
"self",
".",
"parent",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"orphaned object: parent is None\"",
")",
"if",
"self",
".",
"parent",
".",
"parent",... | Create link destination details. | [
"Create",
"link",
"destination",
"details",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L4130-L4143 |
242,856 | pymupdf/PyMuPDF | fitz/fitz.py | Tools.measure_string | def measure_string(self, text, fontname, fontsize, encoding=0):
"""Measure length of a string for a Base14 font."""
return _fitz.Tools_measure_string(self, text, fontname, fontsize, encoding) | python | def measure_string(self, text, fontname, fontsize, encoding=0):
return _fitz.Tools_measure_string(self, text, fontname, fontsize, encoding) | [
"def",
"measure_string",
"(",
"self",
",",
"text",
",",
"fontname",
",",
"fontsize",
",",
"encoding",
"=",
"0",
")",
":",
"return",
"_fitz",
".",
"Tools_measure_string",
"(",
"self",
",",
"text",
",",
"fontname",
",",
"fontsize",
",",
"encoding",
")"
] | Measure length of a string for a Base14 font. | [
"Measure",
"length",
"of",
"a",
"string",
"for",
"a",
"Base14",
"font",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L4492-L4494 |
242,857 | pymupdf/PyMuPDF | fitz/fitz.py | Tools._le_annot_parms | def _le_annot_parms(self, annot, p1, p2):
"""Get common parameters for making line end symbols.
"""
w = annot.border["width"] # line width
sc = annot.colors["stroke"] # stroke color
if not sc: sc = (0,0,0)
scol = " ".join(map(str, sc)) + " RG\n"
fc = annot.colors["fill"] # fill color
if not fc: fc = (0,0,0)
fcol = " ".join(map(str, fc)) + " rg\n"
nr = annot.rect
np1 = p1 # point coord relative to annot rect
np2 = p2 # point coord relative to annot rect
m = self._hor_matrix(np1, np2) # matrix makes the line horizontal
im = ~m # inverted matrix
L = np1 * m # converted start (left) point
R = np2 * m # converted end (right) point
if 0 <= annot.opacity < 1:
opacity = "/Alp0 gs\n"
else:
opacity = ""
return m, im, L, R, w, scol, fcol, opacity | python | def _le_annot_parms(self, annot, p1, p2):
w = annot.border["width"] # line width
sc = annot.colors["stroke"] # stroke color
if not sc: sc = (0,0,0)
scol = " ".join(map(str, sc)) + " RG\n"
fc = annot.colors["fill"] # fill color
if not fc: fc = (0,0,0)
fcol = " ".join(map(str, fc)) + " rg\n"
nr = annot.rect
np1 = p1 # point coord relative to annot rect
np2 = p2 # point coord relative to annot rect
m = self._hor_matrix(np1, np2) # matrix makes the line horizontal
im = ~m # inverted matrix
L = np1 * m # converted start (left) point
R = np2 * m # converted end (right) point
if 0 <= annot.opacity < 1:
opacity = "/Alp0 gs\n"
else:
opacity = ""
return m, im, L, R, w, scol, fcol, opacity | [
"def",
"_le_annot_parms",
"(",
"self",
",",
"annot",
",",
"p1",
",",
"p2",
")",
":",
"w",
"=",
"annot",
".",
"border",
"[",
"\"width\"",
"]",
"# line width",
"sc",
"=",
"annot",
".",
"colors",
"[",
"\"stroke\"",
"]",
"# stroke color",
"if",
"not",
"sc"... | Get common parameters for making line end symbols. | [
"Get",
"common",
"parameters",
"for",
"making",
"line",
"end",
"symbols",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/fitz.py#L4504-L4525 |
242,858 | pymupdf/PyMuPDF | demo/caustic.py | pbis | def pbis(a):
"""End point of a reflected sun ray, given an angle a."""
return(math.cos(3*a - math.pi), (math.sin(3*a - math.pi))) | python | def pbis(a):
return(math.cos(3*a - math.pi), (math.sin(3*a - math.pi))) | [
"def",
"pbis",
"(",
"a",
")",
":",
"return",
"(",
"math",
".",
"cos",
"(",
"3",
"*",
"a",
"-",
"math",
".",
"pi",
")",
",",
"(",
"math",
".",
"sin",
"(",
"3",
"*",
"a",
"-",
"math",
".",
"pi",
")",
")",
")"
] | End point of a reflected sun ray, given an angle a. | [
"End",
"point",
"of",
"a",
"reflected",
"sun",
"ray",
"given",
"an",
"angle",
"a",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/demo/caustic.py#L33-L35 |
242,859 | pymupdf/PyMuPDF | demo/new-annots.py | print_descr | def print_descr(rect, annot):
"""Print a short description to the right of an annot rect."""
annot.parent.insertText(rect.br + (10, 0),
"'%s' annotation" % annot.type[1], color = red) | python | def print_descr(rect, annot):
annot.parent.insertText(rect.br + (10, 0),
"'%s' annotation" % annot.type[1], color = red) | [
"def",
"print_descr",
"(",
"rect",
",",
"annot",
")",
":",
"annot",
".",
"parent",
".",
"insertText",
"(",
"rect",
".",
"br",
"+",
"(",
"10",
",",
"0",
")",
",",
"\"'%s' annotation\"",
"%",
"annot",
".",
"type",
"[",
"1",
"]",
",",
"color",
"=",
... | Print a short description to the right of an annot rect. | [
"Print",
"a",
"short",
"description",
"to",
"the",
"right",
"of",
"an",
"annot",
"rect",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/demo/new-annots.py#L41-L44 |
242,860 | pymupdf/PyMuPDF | demo/extract-img2.py | recoverpix | def recoverpix(doc, item):
"""Return pixmap for item, which is a list of 2 xref numbers. Second xref
is that of an smask if > 0.
Return None for any error.
"""
x = item[0] # xref of PDF image
s = item[1] # xref of its /SMask
try:
pix1 = fitz.Pixmap(doc, x) # make pixmap from image
except:
print("xref %i " % x + doc._getGCTXerrmsg())
return None # skip if error
if s == 0: # has no /SMask
return pix1 # no special handling
try:
pix2 = fitz.Pixmap(doc, s) # create pixmap of /SMask entry
except:
print("cannot create mask %i for image xref %i" % (s,x))
return pix1 # return w/ failed transparency
# check that we are safe
if not (pix1.irect == pix2.irect and \
pix1.alpha == pix2.alpha == 0 and \
pix2.n == 1):
print("unexpected /SMask situation: pix1", pix1, "pix2", pix2)
return pix1
pix = fitz.Pixmap(pix1) # copy of pix1, alpha channel added
pix.setAlpha(pix2.samples) # treat pix2.samples as alpha values
pix1 = pix2 = None # free temp pixmaps
return pix | python | def recoverpix(doc, item):
x = item[0] # xref of PDF image
s = item[1] # xref of its /SMask
try:
pix1 = fitz.Pixmap(doc, x) # make pixmap from image
except:
print("xref %i " % x + doc._getGCTXerrmsg())
return None # skip if error
if s == 0: # has no /SMask
return pix1 # no special handling
try:
pix2 = fitz.Pixmap(doc, s) # create pixmap of /SMask entry
except:
print("cannot create mask %i for image xref %i" % (s,x))
return pix1 # return w/ failed transparency
# check that we are safe
if not (pix1.irect == pix2.irect and \
pix1.alpha == pix2.alpha == 0 and \
pix2.n == 1):
print("unexpected /SMask situation: pix1", pix1, "pix2", pix2)
return pix1
pix = fitz.Pixmap(pix1) # copy of pix1, alpha channel added
pix.setAlpha(pix2.samples) # treat pix2.samples as alpha values
pix1 = pix2 = None # free temp pixmaps
return pix | [
"def",
"recoverpix",
"(",
"doc",
",",
"item",
")",
":",
"x",
"=",
"item",
"[",
"0",
"]",
"# xref of PDF image",
"s",
"=",
"item",
"[",
"1",
"]",
"# xref of its /SMask",
"try",
":",
"pix1",
"=",
"fitz",
".",
"Pixmap",
"(",
"doc",
",",
"x",
")",
"# m... | Return pixmap for item, which is a list of 2 xref numbers. Second xref
is that of an smask if > 0.
Return None for any error. | [
"Return",
"pixmap",
"for",
"item",
"which",
"is",
"a",
"list",
"of",
"2",
"xref",
"numbers",
".",
"Second",
"xref",
"is",
"that",
"of",
"an",
"smask",
"if",
">",
"0",
".",
"Return",
"None",
"for",
"any",
"error",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/demo/extract-img2.py#L39-L71 |
242,861 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.on_update_page_links | def on_update_page_links(self, evt):
""" Perform PDF update of changed links."""
if not self.update_links: # skip if unsupported links
evt.Skip()
return
pg = self.doc[getint(self.TextToPage.Value) -1]
for i in range(len(self.page_links)):
l = self.page_links[i]
if l.get("update", False): # "update" must be True
if l["xref"] == 0: # no xref => new link
pg.insertLink(l)
elif l["kind"] < 1 or l["kind"] > len(self.linkTypeStrings):
pg.deleteLink(l) # delete invalid link
else:
pg.updateLink(l) # else link update
l["update"] = False # reset update indicator
self.page_links[i] = l # update list of page links
self.btn_Update.Disable() # disable update button
self.t_Update.Label = "" # and its message
self.btn_Save.Enable()
self.t_Save.Label = "There are changes. Press to save them to file."
evt.Skip()
return | python | def on_update_page_links(self, evt):
if not self.update_links: # skip if unsupported links
evt.Skip()
return
pg = self.doc[getint(self.TextToPage.Value) -1]
for i in range(len(self.page_links)):
l = self.page_links[i]
if l.get("update", False): # "update" must be True
if l["xref"] == 0: # no xref => new link
pg.insertLink(l)
elif l["kind"] < 1 or l["kind"] > len(self.linkTypeStrings):
pg.deleteLink(l) # delete invalid link
else:
pg.updateLink(l) # else link update
l["update"] = False # reset update indicator
self.page_links[i] = l # update list of page links
self.btn_Update.Disable() # disable update button
self.t_Update.Label = "" # and its message
self.btn_Save.Enable()
self.t_Save.Label = "There are changes. Press to save them to file."
evt.Skip()
return | [
"def",
"on_update_page_links",
"(",
"self",
",",
"evt",
")",
":",
"if",
"not",
"self",
".",
"update_links",
":",
"# skip if unsupported links",
"evt",
".",
"Skip",
"(",
")",
"return",
"pg",
"=",
"self",
".",
"doc",
"[",
"getint",
"(",
"self",
".",
"TextT... | Perform PDF update of changed links. | [
"Perform",
"PDF",
"update",
"of",
"changed",
"links",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L464-L486 |
242,862 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.Rect_to_wxRect | def Rect_to_wxRect(self, fr):
""" Return a zoomed wx.Rect for given fitz.Rect."""
r = (fr * self.zoom).irect # zoomed IRect
return wx.Rect(r.x0, r.y0, r.width, r.height) | python | def Rect_to_wxRect(self, fr):
r = (fr * self.zoom).irect # zoomed IRect
return wx.Rect(r.x0, r.y0, r.width, r.height) | [
"def",
"Rect_to_wxRect",
"(",
"self",
",",
"fr",
")",
":",
"r",
"=",
"(",
"fr",
"*",
"self",
".",
"zoom",
")",
".",
"irect",
"# zoomed IRect",
"return",
"wx",
".",
"Rect",
"(",
"r",
".",
"x0",
",",
"r",
".",
"y0",
",",
"r",
".",
"width",
",",
... | Return a zoomed wx.Rect for given fitz.Rect. | [
"Return",
"a",
"zoomed",
"wx",
".",
"Rect",
"for",
"given",
"fitz",
".",
"Rect",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L903-L906 |
242,863 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.wxRect_to_Rect | def wxRect_to_Rect(self, wr):
""" Return a shrunk fitz.Rect for given wx.Rect."""
r = fitz.Rect(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height)
return r * self.shrink | python | def wxRect_to_Rect(self, wr):
r = fitz.Rect(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height)
return r * self.shrink | [
"def",
"wxRect_to_Rect",
"(",
"self",
",",
"wr",
")",
":",
"r",
"=",
"fitz",
".",
"Rect",
"(",
"wr",
".",
"x",
",",
"wr",
".",
"y",
",",
"wr",
".",
"x",
"+",
"wr",
".",
"width",
",",
"wr",
".",
"y",
"+",
"wr",
".",
"height",
")",
"return",
... | Return a shrunk fitz.Rect for given wx.Rect. | [
"Return",
"a",
"shrunk",
"fitz",
".",
"Rect",
"for",
"given",
"wx",
".",
"Rect",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L908-L911 |
242,864 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.is_in_free_area | def is_in_free_area(self, nr, ok = -1):
""" Determine if rect covers a free area inside the bitmap."""
for i, r in enumerate(self.link_rects):
if r.Intersects(nr) and i != ok:
return False
bmrect = wx.Rect(0,0,dlg.bitmap.Size[0],dlg.bitmap.Size[1])
return bmrect.Contains(nr) | python | def is_in_free_area(self, nr, ok = -1):
for i, r in enumerate(self.link_rects):
if r.Intersects(nr) and i != ok:
return False
bmrect = wx.Rect(0,0,dlg.bitmap.Size[0],dlg.bitmap.Size[1])
return bmrect.Contains(nr) | [
"def",
"is_in_free_area",
"(",
"self",
",",
"nr",
",",
"ok",
"=",
"-",
"1",
")",
":",
"for",
"i",
",",
"r",
"in",
"enumerate",
"(",
"self",
".",
"link_rects",
")",
":",
"if",
"r",
".",
"Intersects",
"(",
"nr",
")",
"and",
"i",
"!=",
"ok",
":",
... | Determine if rect covers a free area inside the bitmap. | [
"Determine",
"if",
"rect",
"covers",
"a",
"free",
"area",
"inside",
"the",
"bitmap",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L913-L919 |
242,865 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.get_linkrect_idx | def get_linkrect_idx(self, pos):
""" Determine if cursor is inside one of the link hot spots."""
for i, r in enumerate(self.link_rects):
if r.Contains(pos):
return i
return -1 | python | def get_linkrect_idx(self, pos):
for i, r in enumerate(self.link_rects):
if r.Contains(pos):
return i
return -1 | [
"def",
"get_linkrect_idx",
"(",
"self",
",",
"pos",
")",
":",
"for",
"i",
",",
"r",
"in",
"enumerate",
"(",
"self",
".",
"link_rects",
")",
":",
"if",
"r",
".",
"Contains",
"(",
"pos",
")",
":",
"return",
"i",
"return",
"-",
"1"
] | Determine if cursor is inside one of the link hot spots. | [
"Determine",
"if",
"cursor",
"is",
"inside",
"one",
"of",
"the",
"link",
"hot",
"spots",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L921-L926 |
242,866 | pymupdf/PyMuPDF | examples/PDFLinkMaint.py | PDFdisplay.get_bottomrect_idx | def get_bottomrect_idx(self, pos):
""" Determine if cursor is on bottom right corner of a hot spot."""
for i, r in enumerate(self.link_bottom_rects):
if r.Contains(pos):
return i
return -1 | python | def get_bottomrect_idx(self, pos):
for i, r in enumerate(self.link_bottom_rects):
if r.Contains(pos):
return i
return -1 | [
"def",
"get_bottomrect_idx",
"(",
"self",
",",
"pos",
")",
":",
"for",
"i",
",",
"r",
"in",
"enumerate",
"(",
"self",
".",
"link_bottom_rects",
")",
":",
"if",
"r",
".",
"Contains",
"(",
"pos",
")",
":",
"return",
"i",
"return",
"-",
"1"
] | Determine if cursor is on bottom right corner of a hot spot. | [
"Determine",
"if",
"cursor",
"is",
"on",
"bottom",
"right",
"corner",
"of",
"a",
"hot",
"spot",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/examples/PDFLinkMaint.py#L928-L933 |
242,867 | pymupdf/PyMuPDF | fitz/utils.py | getTextWords | def getTextWords(page):
"""Return the text words as a list with the bbox for each word.
"""
CheckParent(page)
dl = page.getDisplayList()
tp = dl.getTextPage()
l = tp._extractTextWords_AsList()
del dl
del tp
return l | python | def getTextWords(page):
CheckParent(page)
dl = page.getDisplayList()
tp = dl.getTextPage()
l = tp._extractTextWords_AsList()
del dl
del tp
return l | [
"def",
"getTextWords",
"(",
"page",
")",
":",
"CheckParent",
"(",
"page",
")",
"dl",
"=",
"page",
".",
"getDisplayList",
"(",
")",
"tp",
"=",
"dl",
".",
"getTextPage",
"(",
")",
"l",
"=",
"tp",
".",
"_extractTextWords_AsList",
"(",
")",
"del",
"dl",
... | Return the text words as a list with the bbox for each word. | [
"Return",
"the",
"text",
"words",
"as",
"a",
"list",
"with",
"the",
"bbox",
"for",
"each",
"word",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L349-L358 |
242,868 | pymupdf/PyMuPDF | fitz/utils.py | getText | def getText(page, output = "text"):
""" Extract a document page's text.
Args:
output: (str) text, html, dict, json, rawdict, xhtml or xml.
Returns:
the output of TextPage methods extractText, extractHTML, extractDICT, extractJSON, extractRAWDICT, extractXHTML or etractXML respectively. Default and misspelling choice is "text".
"""
CheckParent(page)
dl = page.getDisplayList()
# available output types
formats = ("text", "html", "json", "xml", "xhtml", "dict", "rawdict")
# choose which of them also include images in the TextPage
images = (0, 1, 1, 0, 1, 1, 1) # controls image inclusion in text page
try:
f = formats.index(output.lower())
except:
f = 0
flags = TEXT_PRESERVE_LIGATURES | TEXT_PRESERVE_WHITESPACE
if images[f] :
flags |= TEXT_PRESERVE_IMAGES
tp = dl.getTextPage(flags) # TextPage with / without images
t = tp._extractText(f)
del dl
del tp
return t | python | def getText(page, output = "text"):
CheckParent(page)
dl = page.getDisplayList()
# available output types
formats = ("text", "html", "json", "xml", "xhtml", "dict", "rawdict")
# choose which of them also include images in the TextPage
images = (0, 1, 1, 0, 1, 1, 1) # controls image inclusion in text page
try:
f = formats.index(output.lower())
except:
f = 0
flags = TEXT_PRESERVE_LIGATURES | TEXT_PRESERVE_WHITESPACE
if images[f] :
flags |= TEXT_PRESERVE_IMAGES
tp = dl.getTextPage(flags) # TextPage with / without images
t = tp._extractText(f)
del dl
del tp
return t | [
"def",
"getText",
"(",
"page",
",",
"output",
"=",
"\"text\"",
")",
":",
"CheckParent",
"(",
"page",
")",
"dl",
"=",
"page",
".",
"getDisplayList",
"(",
")",
"# available output types",
"formats",
"=",
"(",
"\"text\"",
",",
"\"html\"",
",",
"\"json\"",
","... | Extract a document page's text.
Args:
output: (str) text, html, dict, json, rawdict, xhtml or xml.
Returns:
the output of TextPage methods extractText, extractHTML, extractDICT, extractJSON, extractRAWDICT, extractXHTML or etractXML respectively. Default and misspelling choice is "text". | [
"Extract",
"a",
"document",
"page",
"s",
"text",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L360-L386 |
242,869 | pymupdf/PyMuPDF | fitz/utils.py | getPagePixmap | def getPagePixmap(doc, pno, matrix = None, colorspace = csRGB,
clip = None, alpha = True):
"""Create pixmap of document page by page number.
Notes:
Convenience function calling page.getPixmap.
Args:
pno: (int) page number
matrix: Matrix for transformation (default: Identity).
colorspace: (str/Colorspace) rgb, rgb, gray - case ignored, default csRGB.
clip: (irect-like) restrict rendering to this area.
alpha: (bool) include alpha channel
"""
return doc[pno].getPixmap(matrix = matrix, colorspace = colorspace,
clip = clip, alpha = alpha) | python | def getPagePixmap(doc, pno, matrix = None, colorspace = csRGB,
clip = None, alpha = True):
return doc[pno].getPixmap(matrix = matrix, colorspace = colorspace,
clip = clip, alpha = alpha) | [
"def",
"getPagePixmap",
"(",
"doc",
",",
"pno",
",",
"matrix",
"=",
"None",
",",
"colorspace",
"=",
"csRGB",
",",
"clip",
"=",
"None",
",",
"alpha",
"=",
"True",
")",
":",
"return",
"doc",
"[",
"pno",
"]",
".",
"getPixmap",
"(",
"matrix",
"=",
"mat... | Create pixmap of document page by page number.
Notes:
Convenience function calling page.getPixmap.
Args:
pno: (int) page number
matrix: Matrix for transformation (default: Identity).
colorspace: (str/Colorspace) rgb, rgb, gray - case ignored, default csRGB.
clip: (irect-like) restrict rendering to this area.
alpha: (bool) include alpha channel | [
"Create",
"pixmap",
"of",
"document",
"page",
"by",
"page",
"number",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L438-L452 |
242,870 | pymupdf/PyMuPDF | fitz/utils.py | getToC | def getToC(doc, simple = True):
"""Create a table of contents.
Args:
simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation.
"""
def recurse(olItem, liste, lvl):
'''Recursively follow the outline item chain and record item information in a list.'''
while olItem:
if olItem.title:
title = olItem.title
else:
title = " "
if not olItem.isExternal:
if olItem.uri:
page = olItem.page + 1
else:
page = -1
else:
page = -1
if not simple:
link = getLinkDict(olItem)
liste.append([lvl, title, page, link])
else:
liste.append([lvl, title, page])
if olItem.down:
liste = recurse(olItem.down, liste, lvl+1)
olItem = olItem.next
return liste
# check if document is open and not encrypted
if doc.isClosed:
raise ValueError("illegal operation on closed document")
olItem = doc.outline
if not olItem: return []
lvl = 1
liste = []
return recurse(olItem, liste, lvl) | python | def getToC(doc, simple = True):
def recurse(olItem, liste, lvl):
'''Recursively follow the outline item chain and record item information in a list.'''
while olItem:
if olItem.title:
title = olItem.title
else:
title = " "
if not olItem.isExternal:
if olItem.uri:
page = olItem.page + 1
else:
page = -1
else:
page = -1
if not simple:
link = getLinkDict(olItem)
liste.append([lvl, title, page, link])
else:
liste.append([lvl, title, page])
if olItem.down:
liste = recurse(olItem.down, liste, lvl+1)
olItem = olItem.next
return liste
# check if document is open and not encrypted
if doc.isClosed:
raise ValueError("illegal operation on closed document")
olItem = doc.outline
if not olItem: return []
lvl = 1
liste = []
return recurse(olItem, liste, lvl) | [
"def",
"getToC",
"(",
"doc",
",",
"simple",
"=",
"True",
")",
":",
"def",
"recurse",
"(",
"olItem",
",",
"liste",
",",
"lvl",
")",
":",
"'''Recursively follow the outline item chain and record item information in a list.'''",
"while",
"olItem",
":",
"if",
"olItem",
... | Create a table of contents.
Args:
simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation. | [
"Create",
"a",
"table",
"of",
"contents",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L528-L571 |
242,871 | pymupdf/PyMuPDF | fitz/utils.py | updateLink | def updateLink(page, lnk):
""" Update a link on the current page. """
CheckParent(page)
annot = getLinkText(page, lnk)
if annot == "":
raise ValueError("link kind not supported")
page.parent._updateObject(lnk["xref"], annot, page = page)
return | python | def updateLink(page, lnk):
CheckParent(page)
annot = getLinkText(page, lnk)
if annot == "":
raise ValueError("link kind not supported")
page.parent._updateObject(lnk["xref"], annot, page = page)
return | [
"def",
"updateLink",
"(",
"page",
",",
"lnk",
")",
":",
"CheckParent",
"(",
"page",
")",
"annot",
"=",
"getLinkText",
"(",
"page",
",",
"lnk",
")",
"if",
"annot",
"==",
"\"\"",
":",
"raise",
"ValueError",
"(",
"\"link kind not supported\"",
")",
"page",
... | Update a link on the current page. | [
"Update",
"a",
"link",
"on",
"the",
"current",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L990-L998 |
242,872 | pymupdf/PyMuPDF | fitz/utils.py | insertLink | def insertLink(page, lnk, mark = True):
""" Insert a new link for the current page. """
CheckParent(page)
annot = getLinkText(page, lnk)
if annot == "":
raise ValueError("link kind not supported")
page._addAnnot_FromString([annot])
return | python | def insertLink(page, lnk, mark = True):
CheckParent(page)
annot = getLinkText(page, lnk)
if annot == "":
raise ValueError("link kind not supported")
page._addAnnot_FromString([annot])
return | [
"def",
"insertLink",
"(",
"page",
",",
"lnk",
",",
"mark",
"=",
"True",
")",
":",
"CheckParent",
"(",
"page",
")",
"annot",
"=",
"getLinkText",
"(",
"page",
",",
"lnk",
")",
"if",
"annot",
"==",
"\"\"",
":",
"raise",
"ValueError",
"(",
"\"link kind not... | Insert a new link for the current page. | [
"Insert",
"a",
"new",
"link",
"for",
"the",
"current",
"page",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1000-L1008 |
242,873 | pymupdf/PyMuPDF | fitz/utils.py | newPage | def newPage(doc, pno=-1, width=595, height=842):
"""Create and return a new page object.
"""
doc._newPage(pno, width=width, height=height)
return doc[pno] | python | def newPage(doc, pno=-1, width=595, height=842):
doc._newPage(pno, width=width, height=height)
return doc[pno] | [
"def",
"newPage",
"(",
"doc",
",",
"pno",
"=",
"-",
"1",
",",
"width",
"=",
"595",
",",
"height",
"=",
"842",
")",
":",
"doc",
".",
"_newPage",
"(",
"pno",
",",
"width",
"=",
"width",
",",
"height",
"=",
"height",
")",
"return",
"doc",
"[",
"pn... | Create and return a new page object. | [
"Create",
"and",
"return",
"a",
"new",
"page",
"object",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1094-L1098 |
242,874 | pymupdf/PyMuPDF | fitz/utils.py | insertPage | def insertPage(
doc,
pno,
text=None,
fontsize=11,
width=595,
height=842,
fontname="helv",
fontfile=None,
color=None,
):
""" Create a new PDF page and insert some text.
Notes:
Function combining Document.newPage() and Page.insertText().
For parameter details see these methods.
"""
page = doc.newPage(pno=pno, width=width, height=height)
if not bool(text):
return 0
rc = page.insertText(
(50, 72),
text,
fontsize=fontsize,
fontname=fontname,
fontfile=fontfile,
color=color,
)
return rc | python | def insertPage(
doc,
pno,
text=None,
fontsize=11,
width=595,
height=842,
fontname="helv",
fontfile=None,
color=None,
):
page = doc.newPage(pno=pno, width=width, height=height)
if not bool(text):
return 0
rc = page.insertText(
(50, 72),
text,
fontsize=fontsize,
fontname=fontname,
fontfile=fontfile,
color=color,
)
return rc | [
"def",
"insertPage",
"(",
"doc",
",",
"pno",
",",
"text",
"=",
"None",
",",
"fontsize",
"=",
"11",
",",
"width",
"=",
"595",
",",
"height",
"=",
"842",
",",
"fontname",
"=",
"\"helv\"",
",",
"fontfile",
"=",
"None",
",",
"color",
"=",
"None",
",",
... | Create a new PDF page and insert some text.
Notes:
Function combining Document.newPage() and Page.insertText().
For parameter details see these methods. | [
"Create",
"a",
"new",
"PDF",
"page",
"and",
"insert",
"some",
"text",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1100-L1128 |
242,875 | pymupdf/PyMuPDF | fitz/utils.py | drawSquiggle | def drawSquiggle(page, p1, p2, breadth = 2, color=None, dashes=None,
width=1, roundCap=False, overlay=True, morph=None):
"""Draw a squiggly line from point p1 to point p2.
"""
img = page.newShape()
p = img.drawSquiggle(Point(p1), Point(p2), breadth = breadth)
img.finish(color=color, dashes=dashes, width=width, closePath=False,
roundCap=roundCap, morph=morph)
img.commit(overlay)
return p | python | def drawSquiggle(page, p1, p2, breadth = 2, color=None, dashes=None,
width=1, roundCap=False, overlay=True, morph=None):
img = page.newShape()
p = img.drawSquiggle(Point(p1), Point(p2), breadth = breadth)
img.finish(color=color, dashes=dashes, width=width, closePath=False,
roundCap=roundCap, morph=morph)
img.commit(overlay)
return p | [
"def",
"drawSquiggle",
"(",
"page",
",",
"p1",
",",
"p2",
",",
"breadth",
"=",
"2",
",",
"color",
"=",
"None",
",",
"dashes",
"=",
"None",
",",
"width",
"=",
"1",
",",
"roundCap",
"=",
"False",
",",
"overlay",
"=",
"True",
",",
"morph",
"=",
"Non... | Draw a squiggly line from point p1 to point p2. | [
"Draw",
"a",
"squiggly",
"line",
"from",
"point",
"p1",
"to",
"point",
"p2",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1141-L1151 |
242,876 | pymupdf/PyMuPDF | fitz/utils.py | drawQuad | def drawQuad(page, quad, color=None, fill=None, dashes=None,
width=1, roundCap=False, morph=None, overlay=True):
"""Draw a quadrilateral.
"""
img = page.newShape()
Q = img.drawQuad(Quad(quad))
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph)
img.commit(overlay)
return Q | python | def drawQuad(page, quad, color=None, fill=None, dashes=None,
width=1, roundCap=False, morph=None, overlay=True):
img = page.newShape()
Q = img.drawQuad(Quad(quad))
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph)
img.commit(overlay)
return Q | [
"def",
"drawQuad",
"(",
"page",
",",
"quad",
",",
"color",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"dashes",
"=",
"None",
",",
"width",
"=",
"1",
",",
"roundCap",
"=",
"False",
",",
"morph",
"=",
"None",
",",
"overlay",
"=",
"True",
")",
":",... | Draw a quadrilateral. | [
"Draw",
"a",
"quadrilateral",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1177-L1187 |
242,877 | pymupdf/PyMuPDF | fitz/utils.py | drawPolyline | def drawPolyline(page, points, color=None, fill=None, dashes=None,
width=1, morph=None, roundCap=False, overlay=True,
closePath=False):
"""Draw multiple connected line segments.
"""
img = page.newShape()
Q = img.drawPolyline(points)
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph, closePath=closePath)
img.commit(overlay)
return Q | python | def drawPolyline(page, points, color=None, fill=None, dashes=None,
width=1, morph=None, roundCap=False, overlay=True,
closePath=False):
img = page.newShape()
Q = img.drawPolyline(points)
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph, closePath=closePath)
img.commit(overlay)
return Q | [
"def",
"drawPolyline",
"(",
"page",
",",
"points",
",",
"color",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"dashes",
"=",
"None",
",",
"width",
"=",
"1",
",",
"morph",
"=",
"None",
",",
"roundCap",
"=",
"False",
",",
"overlay",
"=",
"True",
",",
... | Draw multiple connected line segments. | [
"Draw",
"multiple",
"connected",
"line",
"segments",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1189-L1200 |
242,878 | pymupdf/PyMuPDF | fitz/utils.py | drawBezier | def drawBezier(page, p1, p2, p3, p4, color=None, fill=None,
dashes=None, width=1, morph=None,
closePath=False, roundCap=False, overlay=True):
"""Draw a general cubic Bezier curve from p1 to p4 using control points p2 and p3.
"""
img = page.newShape()
Q = img.drawBezier(Point(p1), Point(p2), Point(p3), Point(p4))
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph, closePath=closePath)
img.commit(overlay)
return Q | python | def drawBezier(page, p1, p2, p3, p4, color=None, fill=None,
dashes=None, width=1, morph=None,
closePath=False, roundCap=False, overlay=True):
img = page.newShape()
Q = img.drawBezier(Point(p1), Point(p2), Point(p3), Point(p4))
img.finish(color=color, fill=fill, dashes=dashes, width=width,
roundCap=roundCap, morph=morph, closePath=closePath)
img.commit(overlay)
return Q | [
"def",
"drawBezier",
"(",
"page",
",",
"p1",
",",
"p2",
",",
"p3",
",",
"p4",
",",
"color",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"dashes",
"=",
"None",
",",
"width",
"=",
"1",
",",
"morph",
"=",
"None",
",",
"closePath",
"=",
"False",
",... | Draw a general cubic Bezier curve from p1 to p4 using control points p2 and p3. | [
"Draw",
"a",
"general",
"cubic",
"Bezier",
"curve",
"from",
"p1",
"to",
"p4",
"using",
"control",
"points",
"p2",
"and",
"p3",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1240-L1251 |
242,879 | pymupdf/PyMuPDF | fitz/utils.py | getColor | def getColor(name):
"""Retrieve RGB color in PDF format by name.
Returns:
a triple of floats in range 0 to 1. In case of name-not-found, "white" is returned.
"""
try:
c = getColorInfoList()[getColorList().index(name.upper())]
return (c[1] / 255., c[2] / 255., c[3] / 255.)
except:
return (1, 1, 1) | python | def getColor(name):
try:
c = getColorInfoList()[getColorList().index(name.upper())]
return (c[1] / 255., c[2] / 255., c[3] / 255.)
except:
return (1, 1, 1) | [
"def",
"getColor",
"(",
"name",
")",
":",
"try",
":",
"c",
"=",
"getColorInfoList",
"(",
")",
"[",
"getColorList",
"(",
")",
".",
"index",
"(",
"name",
".",
"upper",
"(",
")",
")",
"]",
"return",
"(",
"c",
"[",
"1",
"]",
"/",
"255.",
",",
"c",
... | Retrieve RGB color in PDF format by name.
Returns:
a triple of floats in range 0 to 1. In case of name-not-found, "white" is returned. | [
"Retrieve",
"RGB",
"color",
"in",
"PDF",
"format",
"by",
"name",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1848-L1858 |
242,880 | pymupdf/PyMuPDF | fitz/utils.py | getColorHSV | def getColorHSV(name):
"""Retrieve the hue, saturation, value triple of a color name.
Returns:
a triple (degree, percent, percent). If not found (-1, -1, -1) is returned.
"""
try:
x = getColorInfoList()[getColorList().index(name.upper())]
except:
return (-1, -1, -1)
r = x[1] / 255.
g = x[2] / 255.
b = x[3] / 255.
cmax = max(r, g, b)
V = round(cmax * 100, 1)
cmin = min(r, g, b)
delta = cmax - cmin
if delta == 0:
hue = 0
elif cmax == r:
hue = 60. * (((g - b)/delta) % 6)
elif cmax == g:
hue = 60. * (((b - r)/delta) + 2)
else:
hue = 60. * (((r - g)/delta) + 4)
H = int(round(hue))
if cmax == 0:
sat = 0
else:
sat = delta / cmax
S = int(round(sat * 100))
return (H, S, V) | python | def getColorHSV(name):
try:
x = getColorInfoList()[getColorList().index(name.upper())]
except:
return (-1, -1, -1)
r = x[1] / 255.
g = x[2] / 255.
b = x[3] / 255.
cmax = max(r, g, b)
V = round(cmax * 100, 1)
cmin = min(r, g, b)
delta = cmax - cmin
if delta == 0:
hue = 0
elif cmax == r:
hue = 60. * (((g - b)/delta) % 6)
elif cmax == g:
hue = 60. * (((b - r)/delta) + 2)
else:
hue = 60. * (((r - g)/delta) + 4)
H = int(round(hue))
if cmax == 0:
sat = 0
else:
sat = delta / cmax
S = int(round(sat * 100))
return (H, S, V) | [
"def",
"getColorHSV",
"(",
"name",
")",
":",
"try",
":",
"x",
"=",
"getColorInfoList",
"(",
")",
"[",
"getColorList",
"(",
")",
".",
"index",
"(",
"name",
".",
"upper",
"(",
")",
")",
"]",
"except",
":",
"return",
"(",
"-",
"1",
",",
"-",
"1",
... | Retrieve the hue, saturation, value triple of a color name.
Returns:
a triple (degree, percent, percent). If not found (-1, -1, -1) is returned. | [
"Retrieve",
"the",
"hue",
"saturation",
"value",
"triple",
"of",
"a",
"color",
"name",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1860-L1895 |
242,881 | pymupdf/PyMuPDF | fitz/utils.py | Shape.horizontal_angle | def horizontal_angle(C, P):
"""Return the angle to the horizontal for the connection from C to P.
This uses the arcus sine function and resolves its inherent ambiguity by
looking up in which quadrant vector S = P - C is located.
"""
S = Point(P - C).unit # unit vector 'C' -> 'P'
alfa = math.asin(abs(S.y)) # absolute angle from horizontal
if S.x < 0: # make arcsin result unique
if S.y <= 0: # bottom-left
alfa = -(math.pi - alfa)
else: # top-left
alfa = math.pi - alfa
else:
if S.y >= 0: # top-right
pass
else: # bottom-right
alfa = - alfa
return alfa | python | def horizontal_angle(C, P):
S = Point(P - C).unit # unit vector 'C' -> 'P'
alfa = math.asin(abs(S.y)) # absolute angle from horizontal
if S.x < 0: # make arcsin result unique
if S.y <= 0: # bottom-left
alfa = -(math.pi - alfa)
else: # top-left
alfa = math.pi - alfa
else:
if S.y >= 0: # top-right
pass
else: # bottom-right
alfa = - alfa
return alfa | [
"def",
"horizontal_angle",
"(",
"C",
",",
"P",
")",
":",
"S",
"=",
"Point",
"(",
"P",
"-",
"C",
")",
".",
"unit",
"# unit vector 'C' -> 'P'",
"alfa",
"=",
"math",
".",
"asin",
"(",
"abs",
"(",
"S",
".",
"y",
")",
")",
"# absolute angle from horizontal"... | Return the angle to the horizontal for the connection from C to P.
This uses the arcus sine function and resolves its inherent ambiguity by
looking up in which quadrant vector S = P - C is located. | [
"Return",
"the",
"angle",
"to",
"the",
"horizontal",
"for",
"the",
"connection",
"from",
"C",
"to",
"P",
".",
"This",
"uses",
"the",
"arcus",
"sine",
"function",
"and",
"resolves",
"its",
"inherent",
"ambiguity",
"by",
"looking",
"up",
"in",
"which",
"quad... | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L1986-L2003 |
242,882 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawLine | def drawLine(self, p1, p2):
"""Draw a line between two points.
"""
p1 = Point(p1)
p2 = Point(p2)
if not (self.lastPoint == p1):
self.draw_cont += "%g %g m\n" % JM_TUPLE(p1 * self.ipctm)
self.lastPoint = p1
self.updateRect(p1)
self.draw_cont += "%g %g l\n" % JM_TUPLE(p2 * self.ipctm)
self.updateRect(p2)
self.lastPoint = p2
return self.lastPoint | python | def drawLine(self, p1, p2):
p1 = Point(p1)
p2 = Point(p2)
if not (self.lastPoint == p1):
self.draw_cont += "%g %g m\n" % JM_TUPLE(p1 * self.ipctm)
self.lastPoint = p1
self.updateRect(p1)
self.draw_cont += "%g %g l\n" % JM_TUPLE(p2 * self.ipctm)
self.updateRect(p2)
self.lastPoint = p2
return self.lastPoint | [
"def",
"drawLine",
"(",
"self",
",",
"p1",
",",
"p2",
")",
":",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"if",
"not",
"(",
"self",
".",
"lastPoint",
"==",
"p1",
")",
":",
"self",
".",
"draw_cont",
"+=",
"\"%g %g m... | Draw a line between two points. | [
"Draw",
"a",
"line",
"between",
"two",
"points",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2042-L2055 |
242,883 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawPolyline | def drawPolyline(self, points):
"""Draw several connected line segments.
"""
for i, p in enumerate(points):
if i == 0:
if not (self.lastPoint == Point(p)):
self.draw_cont += "%g %g m\n" % JM_TUPLE(Point(p) * self.ipctm)
self.lastPoint = Point(p)
else:
self.draw_cont += "%g %g l\n" % JM_TUPLE(Point(p) * self.ipctm)
self.updateRect(p)
self.lastPoint = Point(points[-1])
return self.lastPoint | python | def drawPolyline(self, points):
for i, p in enumerate(points):
if i == 0:
if not (self.lastPoint == Point(p)):
self.draw_cont += "%g %g m\n" % JM_TUPLE(Point(p) * self.ipctm)
self.lastPoint = Point(p)
else:
self.draw_cont += "%g %g l\n" % JM_TUPLE(Point(p) * self.ipctm)
self.updateRect(p)
self.lastPoint = Point(points[-1])
return self.lastPoint | [
"def",
"drawPolyline",
"(",
"self",
",",
"points",
")",
":",
"for",
"i",
",",
"p",
"in",
"enumerate",
"(",
"points",
")",
":",
"if",
"i",
"==",
"0",
":",
"if",
"not",
"(",
"self",
".",
"lastPoint",
"==",
"Point",
"(",
"p",
")",
")",
":",
"self"... | Draw several connected line segments. | [
"Draw",
"several",
"connected",
"line",
"segments",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2057-L2070 |
242,884 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawBezier | def drawBezier(self, p1, p2, p3, p4):
"""Draw a standard cubic Bezier curve.
"""
p1 = Point(p1)
p2 = Point(p2)
p3 = Point(p3)
p4 = Point(p4)
if not (self.lastPoint == p1):
self.draw_cont += "%g %g m\n" % JM_TUPLE(p1 * self.ipctm)
self.draw_cont += "%g %g %g %g %g %g c\n" % JM_TUPLE(list(p2 * self.ipctm) + \
list(p3 * self.ipctm) + \
list(p4 * self.ipctm))
self.updateRect(p1)
self.updateRect(p2)
self.updateRect(p3)
self.updateRect(p4)
self.lastPoint = p4
return self.lastPoint | python | def drawBezier(self, p1, p2, p3, p4):
p1 = Point(p1)
p2 = Point(p2)
p3 = Point(p3)
p4 = Point(p4)
if not (self.lastPoint == p1):
self.draw_cont += "%g %g m\n" % JM_TUPLE(p1 * self.ipctm)
self.draw_cont += "%g %g %g %g %g %g c\n" % JM_TUPLE(list(p2 * self.ipctm) + \
list(p3 * self.ipctm) + \
list(p4 * self.ipctm))
self.updateRect(p1)
self.updateRect(p2)
self.updateRect(p3)
self.updateRect(p4)
self.lastPoint = p4
return self.lastPoint | [
"def",
"drawBezier",
"(",
"self",
",",
"p1",
",",
"p2",
",",
"p3",
",",
"p4",
")",
":",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"p3",
"=",
"Point",
"(",
"p3",
")",
"p4",
"=",
"Point",
"(",
"p4",
")",
"if",
... | Draw a standard cubic Bezier curve. | [
"Draw",
"a",
"standard",
"cubic",
"Bezier",
"curve",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2072-L2089 |
242,885 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawOval | def drawOval(self, tetra):
"""Draw an ellipse inside a tetrapod.
"""
if len(tetra) != 4:
raise ValueError("invalid arg length")
if hasattr(tetra[0], "__float__"):
q = Rect(tetra).quad
else:
q = Quad(tetra)
mt = q.ul + (q.ur - q.ul) * 0.5
mr = q.ur + (q.lr - q.ur) * 0.5
mb = q.ll + (q.lr - q.ll) * 0.5
ml = q.ul + (q.ll - q.ul) * 0.5
if not (self.lastPoint == ml):
self.draw_cont += "%g %g m\n" % JM_TUPLE(ml * self.ipctm)
self.lastPoint = ml
self.drawCurve(ml, q.ll, mb)
self.drawCurve(mb, q.lr, mr)
self.drawCurve(mr, q.ur, mt)
self.drawCurve(mt, q.ul, ml)
self.updateRect(q.rect)
self.lastPoint = ml
return self.lastPoint | python | def drawOval(self, tetra):
if len(tetra) != 4:
raise ValueError("invalid arg length")
if hasattr(tetra[0], "__float__"):
q = Rect(tetra).quad
else:
q = Quad(tetra)
mt = q.ul + (q.ur - q.ul) * 0.5
mr = q.ur + (q.lr - q.ur) * 0.5
mb = q.ll + (q.lr - q.ll) * 0.5
ml = q.ul + (q.ll - q.ul) * 0.5
if not (self.lastPoint == ml):
self.draw_cont += "%g %g m\n" % JM_TUPLE(ml * self.ipctm)
self.lastPoint = ml
self.drawCurve(ml, q.ll, mb)
self.drawCurve(mb, q.lr, mr)
self.drawCurve(mr, q.ur, mt)
self.drawCurve(mt, q.ul, ml)
self.updateRect(q.rect)
self.lastPoint = ml
return self.lastPoint | [
"def",
"drawOval",
"(",
"self",
",",
"tetra",
")",
":",
"if",
"len",
"(",
"tetra",
")",
"!=",
"4",
":",
"raise",
"ValueError",
"(",
"\"invalid arg length\"",
")",
"if",
"hasattr",
"(",
"tetra",
"[",
"0",
"]",
",",
"\"__float__\"",
")",
":",
"q",
"=",... | Draw an ellipse inside a tetrapod. | [
"Draw",
"an",
"ellipse",
"inside",
"a",
"tetrapod",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2091-L2114 |
242,886 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawCurve | def drawCurve(self, p1, p2, p3):
"""Draw a curve between points using one control point.
"""
kappa = 0.55228474983
p1 = Point(p1)
p2 = Point(p2)
p3 = Point(p3)
k1 = p1 + (p2 - p1) * kappa
k2 = p3 + (p2 - p3) * kappa
return self.drawBezier(p1, k1, k2, p3) | python | def drawCurve(self, p1, p2, p3):
kappa = 0.55228474983
p1 = Point(p1)
p2 = Point(p2)
p3 = Point(p3)
k1 = p1 + (p2 - p1) * kappa
k2 = p3 + (p2 - p3) * kappa
return self.drawBezier(p1, k1, k2, p3) | [
"def",
"drawCurve",
"(",
"self",
",",
"p1",
",",
"p2",
",",
"p3",
")",
":",
"kappa",
"=",
"0.55228474983",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"p3",
"=",
"Point",
"(",
"p3",
")",
"k1",
"=",
"p1",
"+",
"(",
... | Draw a curve between points using one control point. | [
"Draw",
"a",
"curve",
"between",
"points",
"using",
"one",
"control",
"point",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2125-L2134 |
242,887 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawQuad | def drawQuad(self, quad):
"""Draw a Quad.
"""
q = Quad(quad)
return self.drawPolyline([q.ul, q.ll, q.lr, q.ur, q.ul]) | python | def drawQuad(self, quad):
q = Quad(quad)
return self.drawPolyline([q.ul, q.ll, q.lr, q.ur, q.ul]) | [
"def",
"drawQuad",
"(",
"self",
",",
"quad",
")",
":",
"q",
"=",
"Quad",
"(",
"quad",
")",
"return",
"self",
".",
"drawPolyline",
"(",
"[",
"q",
".",
"ul",
",",
"q",
".",
"ll",
",",
"q",
".",
"lr",
",",
"q",
".",
"ur",
",",
"q",
".",
"ul",
... | Draw a Quad. | [
"Draw",
"a",
"Quad",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2215-L2219 |
242,888 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawZigzag | def drawZigzag(self, p1, p2, breadth = 2):
"""Draw a zig-zagged line from p1 to p2.
"""
p1 = Point(p1)
p2 = Point(p2)
S = p2 - p1 # vector start - end
rad = abs(S) # distance of points
cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases
if cnt < 4:
raise ValueError("points too close")
mb = rad / cnt # revised breadth
matrix = TOOLS._hor_matrix(p1, p2) # normalize line to x-axis
i_mat = ~matrix # get original position
points = [] # stores edges
for i in range (1, cnt):
if i % 4 == 1: # point "above" connection
p = Point(i, -1) * mb
elif i % 4 == 3: # point "below" connection
p = Point(i, 1) * mb
else: # ignore others
continue
points.append(p * i_mat)
self.drawPolyline([p1] + points + [p2]) # add start and end points
return p2 | python | def drawZigzag(self, p1, p2, breadth = 2):
p1 = Point(p1)
p2 = Point(p2)
S = p2 - p1 # vector start - end
rad = abs(S) # distance of points
cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases
if cnt < 4:
raise ValueError("points too close")
mb = rad / cnt # revised breadth
matrix = TOOLS._hor_matrix(p1, p2) # normalize line to x-axis
i_mat = ~matrix # get original position
points = [] # stores edges
for i in range (1, cnt):
if i % 4 == 1: # point "above" connection
p = Point(i, -1) * mb
elif i % 4 == 3: # point "below" connection
p = Point(i, 1) * mb
else: # ignore others
continue
points.append(p * i_mat)
self.drawPolyline([p1] + points + [p2]) # add start and end points
return p2 | [
"def",
"drawZigzag",
"(",
"self",
",",
"p1",
",",
"p2",
",",
"breadth",
"=",
"2",
")",
":",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"S",
"=",
"p2",
"-",
"p1",
"# vector start - end",
"rad",
"=",
"abs",
"(",
"S",
... | Draw a zig-zagged line from p1 to p2. | [
"Draw",
"a",
"zig",
"-",
"zagged",
"line",
"from",
"p1",
"to",
"p2",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2221-L2244 |
242,889 | pymupdf/PyMuPDF | fitz/utils.py | Shape.drawSquiggle | def drawSquiggle(self, p1, p2, breadth = 2):
"""Draw a squiggly line from p1 to p2.
"""
p1 = Point(p1)
p2 = Point(p2)
S = p2 - p1 # vector start - end
rad = abs(S) # distance of points
cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases
if cnt < 4:
raise ValueError("points too close")
mb = rad / cnt # revised breadth
matrix = TOOLS._hor_matrix(p1, p2) # normalize line to x-axis
i_mat = ~matrix # get original position
k = 2.4142135623765633 # y of drawCurve helper point
points = [] # stores edges
for i in range (1, cnt):
if i % 4 == 1: # point "above" connection
p = Point(i, -k) * mb
elif i % 4 == 3: # point "below" connection
p = Point(i, k) * mb
else: # else on connection line
p = Point(i, 0) * mb
points.append(p * i_mat)
points = [p1] + points + [p2]
cnt = len(points)
i = 0
while i + 2 < cnt:
self.drawCurve(points[i], points[i+1], points[i+2])
i += 2
return p2 | python | def drawSquiggle(self, p1, p2, breadth = 2):
p1 = Point(p1)
p2 = Point(p2)
S = p2 - p1 # vector start - end
rad = abs(S) # distance of points
cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases
if cnt < 4:
raise ValueError("points too close")
mb = rad / cnt # revised breadth
matrix = TOOLS._hor_matrix(p1, p2) # normalize line to x-axis
i_mat = ~matrix # get original position
k = 2.4142135623765633 # y of drawCurve helper point
points = [] # stores edges
for i in range (1, cnt):
if i % 4 == 1: # point "above" connection
p = Point(i, -k) * mb
elif i % 4 == 3: # point "below" connection
p = Point(i, k) * mb
else: # else on connection line
p = Point(i, 0) * mb
points.append(p * i_mat)
points = [p1] + points + [p2]
cnt = len(points)
i = 0
while i + 2 < cnt:
self.drawCurve(points[i], points[i+1], points[i+2])
i += 2
return p2 | [
"def",
"drawSquiggle",
"(",
"self",
",",
"p1",
",",
"p2",
",",
"breadth",
"=",
"2",
")",
":",
"p1",
"=",
"Point",
"(",
"p1",
")",
"p2",
"=",
"Point",
"(",
"p2",
")",
"S",
"=",
"p2",
"-",
"p1",
"# vector start - end",
"rad",
"=",
"abs",
"(",
"S"... | Draw a squiggly line from p1 to p2. | [
"Draw",
"a",
"squiggly",
"line",
"from",
"p1",
"to",
"p2",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2246-L2277 |
242,890 | pymupdf/PyMuPDF | fitz/utils.py | Shape.finish | def finish(
self,
width=1,
color=None,
fill=None,
roundCap=False,
dashes=None,
even_odd=False,
morph=None,
closePath=True
):
"""Finish the current drawing segment.
Notes:
Apply stroke and fill colors, dashes, line style and width, or
morphing. Also determines whether any open path should be closed
by a connecting line to its start point.
"""
if self.draw_cont == "": # treat empty contents as no-op
return
color_str = ColorCode(color, "c") # ensure proper color string
fill_str = ColorCode(fill, "f") # ensure proper fill string
if width != 1:
self.draw_cont += "%g w\n" % width
if roundCap:
self.draw_cont += "%i J %i j\n" % (roundCap, roundCap)
if dashes is not None and len(dashes) > 0:
self.draw_cont += "%s d\n" % dashes
if closePath:
self.draw_cont += "h\n"
self.lastPoint = None
if color is not None:
self.draw_cont += color_str
if fill is not None:
self.draw_cont += fill_str
if not even_odd:
self.draw_cont += "B\n"
else:
self.draw_cont += "B*\n"
else:
self.draw_cont += "S\n"
if CheckMorph(morph):
m1 = Matrix(1, 0, 0, 1, morph[0].x + self.x,
self.height - morph[0].y - self.y)
mat = ~m1 * morph[1] * m1
self.draw_cont = "%g %g %g %g %g %g cm\n" % JM_TUPLE(mat) + self.draw_cont
self.totalcont += "\nq\n" + self.draw_cont + "Q\n"
self.draw_cont = ""
self.lastPoint = None
return | python | def finish(
self,
width=1,
color=None,
fill=None,
roundCap=False,
dashes=None,
even_odd=False,
morph=None,
closePath=True
):
if self.draw_cont == "": # treat empty contents as no-op
return
color_str = ColorCode(color, "c") # ensure proper color string
fill_str = ColorCode(fill, "f") # ensure proper fill string
if width != 1:
self.draw_cont += "%g w\n" % width
if roundCap:
self.draw_cont += "%i J %i j\n" % (roundCap, roundCap)
if dashes is not None and len(dashes) > 0:
self.draw_cont += "%s d\n" % dashes
if closePath:
self.draw_cont += "h\n"
self.lastPoint = None
if color is not None:
self.draw_cont += color_str
if fill is not None:
self.draw_cont += fill_str
if not even_odd:
self.draw_cont += "B\n"
else:
self.draw_cont += "B*\n"
else:
self.draw_cont += "S\n"
if CheckMorph(morph):
m1 = Matrix(1, 0, 0, 1, morph[0].x + self.x,
self.height - morph[0].y - self.y)
mat = ~m1 * morph[1] * m1
self.draw_cont = "%g %g %g %g %g %g cm\n" % JM_TUPLE(mat) + self.draw_cont
self.totalcont += "\nq\n" + self.draw_cont + "Q\n"
self.draw_cont = ""
self.lastPoint = None
return | [
"def",
"finish",
"(",
"self",
",",
"width",
"=",
"1",
",",
"color",
"=",
"None",
",",
"fill",
"=",
"None",
",",
"roundCap",
"=",
"False",
",",
"dashes",
"=",
"None",
",",
"even_odd",
"=",
"False",
",",
"morph",
"=",
"None",
",",
"closePath",
"=",
... | Finish the current drawing segment.
Notes:
Apply stroke and fill colors, dashes, line style and width, or
morphing. Also determines whether any open path should be closed
by a connecting line to its start point. | [
"Finish",
"the",
"current",
"drawing",
"segment",
"."
] | 917f2d83482510e26ba0ff01fd2392c26f3a8e90 | https://github.com/pymupdf/PyMuPDF/blob/917f2d83482510e26ba0ff01fd2392c26f3a8e90/fitz/utils.py#L2709-L2767 |
242,891 | stitchfix/pyxley | pyxley/charts/mg/mg.py | OptionHelper.set_float | def set_float(self, option, value):
"""Set a float option.
Args:
option (str): name of option.
value (float): value of the option.
Raises:
TypeError: Value must be a float.
"""
if not isinstance(value, float):
raise TypeError("Value must be a float")
self.options[option] = value | python | def set_float(self, option, value):
if not isinstance(value, float):
raise TypeError("Value must be a float")
self.options[option] = value | [
"def",
"set_float",
"(",
"self",
",",
"option",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"float",
")",
":",
"raise",
"TypeError",
"(",
"\"Value must be a float\"",
")",
"self",
".",
"options",
"[",
"option",
"]",
"=",
"value"... | Set a float option.
Args:
option (str): name of option.
value (float): value of the option.
Raises:
TypeError: Value must be a float. | [
"Set",
"a",
"float",
"option",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/mg.py#L29-L41 |
242,892 | stitchfix/pyxley | pyxley/charts/mg/mg.py | OptionHelper.set_integer | def set_integer(self, option, value):
"""Set an integer option.
Args:
option (str): name of option.
value (int): value of the option.
Raises:
ValueError: Value must be an integer.
"""
try:
int_value = int(value)
except ValueError as err:
print(err.args)
self.options[option] = value | python | def set_integer(self, option, value):
try:
int_value = int(value)
except ValueError as err:
print(err.args)
self.options[option] = value | [
"def",
"set_integer",
"(",
"self",
",",
"option",
",",
"value",
")",
":",
"try",
":",
"int_value",
"=",
"int",
"(",
"value",
")",
"except",
"ValueError",
"as",
"err",
":",
"print",
"(",
"err",
".",
"args",
")",
"self",
".",
"options",
"[",
"option",
... | Set an integer option.
Args:
option (str): name of option.
value (int): value of the option.
Raises:
ValueError: Value must be an integer. | [
"Set",
"an",
"integer",
"option",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/mg.py#L43-L58 |
242,893 | stitchfix/pyxley | pyxley/charts/mg/mg.py | OptionHelper.set_boolean | def set_boolean(self, option, value):
"""Set a boolean option.
Args:
option (str): name of option.
value (bool): value of the option.
Raises:
TypeError: Value must be a boolean.
"""
if not isinstance(value, bool):
raise TypeError("%s must be a boolean" % option)
self.options[option] = str(value).lower() | python | def set_boolean(self, option, value):
if not isinstance(value, bool):
raise TypeError("%s must be a boolean" % option)
self.options[option] = str(value).lower() | [
"def",
"set_boolean",
"(",
"self",
",",
"option",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"raise",
"TypeError",
"(",
"\"%s must be a boolean\"",
"%",
"option",
")",
"self",
".",
"options",
"[",
"option",
"]... | Set a boolean option.
Args:
option (str): name of option.
value (bool): value of the option.
Raises:
TypeError: Value must be a boolean. | [
"Set",
"a",
"boolean",
"option",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/mg.py#L60-L73 |
242,894 | stitchfix/pyxley | pyxley/charts/mg/mg.py | OptionHelper.set_string | def set_string(self, option, value):
"""Set a string option.
Args:
option (str): name of option.
value (str): value of the option.
Raises:
TypeError: Value must be a string.
"""
if not isinstance(value, str):
raise TypeError("%s must be a string" % option)
self.options[option] = value | python | def set_string(self, option, value):
if not isinstance(value, str):
raise TypeError("%s must be a string" % option)
self.options[option] = value | [
"def",
"set_string",
"(",
"self",
",",
"option",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"\"%s must be a string\"",
"%",
"option",
")",
"self",
".",
"options",
"[",
"option",
"]",
... | Set a string option.
Args:
option (str): name of option.
value (str): value of the option.
Raises:
TypeError: Value must be a string. | [
"Set",
"a",
"string",
"option",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/mg.py#L75-L88 |
242,895 | stitchfix/pyxley | pyxley/charts/mg/graphic.py | Graphic.custom_line_color_map | def custom_line_color_map(self, values):
"""Set the custom line color map.
Args:
values (list): list of colors.
Raises:
TypeError: Custom line color map must be a list.
"""
if not isinstance(values, list):
raise TypeError("custom_line_color_map must be a list")
self.options["custom_line_color_map"] = values | python | def custom_line_color_map(self, values):
if not isinstance(values, list):
raise TypeError("custom_line_color_map must be a list")
self.options["custom_line_color_map"] = values | [
"def",
"custom_line_color_map",
"(",
"self",
",",
"values",
")",
":",
"if",
"not",
"isinstance",
"(",
"values",
",",
"list",
")",
":",
"raise",
"TypeError",
"(",
"\"custom_line_color_map must be a list\"",
")",
"self",
".",
"options",
"[",
"\"custom_line_color_map... | Set the custom line color map.
Args:
values (list): list of colors.
Raises:
TypeError: Custom line color map must be a list. | [
"Set",
"the",
"custom",
"line",
"color",
"map",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/graphic.py#L89-L101 |
242,896 | stitchfix/pyxley | pyxley/charts/mg/graphic.py | Graphic.legend | def legend(self, values):
"""Set the legend labels.
Args:
values (list): list of labels.
Raises:
ValueError: legend must be a list of labels.
"""
if not isinstance(values, list):
raise TypeError("legend must be a list of labels")
self.options["legend"] = values | python | def legend(self, values):
if not isinstance(values, list):
raise TypeError("legend must be a list of labels")
self.options["legend"] = values | [
"def",
"legend",
"(",
"self",
",",
"values",
")",
":",
"if",
"not",
"isinstance",
"(",
"values",
",",
"list",
")",
":",
"raise",
"TypeError",
"(",
"\"legend must be a list of labels\"",
")",
"self",
".",
"options",
"[",
"\"legend\"",
"]",
"=",
"values"
] | Set the legend labels.
Args:
values (list): list of labels.
Raises:
ValueError: legend must be a list of labels. | [
"Set",
"the",
"legend",
"labels",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/graphic.py#L164-L176 |
242,897 | stitchfix/pyxley | pyxley/charts/mg/graphic.py | Graphic.markers | def markers(self, values):
"""Set the markers.
Args:
values (list): list of marker objects.
Raises:
ValueError: Markers must be a list of objects.
"""
if not isinstance(values, list):
raise TypeError("Markers must be a list of objects")
self.options["markers"] = values | python | def markers(self, values):
if not isinstance(values, list):
raise TypeError("Markers must be a list of objects")
self.options["markers"] = values | [
"def",
"markers",
"(",
"self",
",",
"values",
")",
":",
"if",
"not",
"isinstance",
"(",
"values",
",",
"list",
")",
":",
"raise",
"TypeError",
"(",
"\"Markers must be a list of objects\"",
")",
"self",
".",
"options",
"[",
"\"markers\"",
"]",
"=",
"values"
] | Set the markers.
Args:
values (list): list of marker objects.
Raises:
ValueError: Markers must be a list of objects. | [
"Set",
"the",
"markers",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/graphic.py#L194-L206 |
242,898 | stitchfix/pyxley | pyxley/charts/mg/graphic.py | Graphic.get | def get(self):
"""Get graphics options."""
return {k:v for k,v in list(self.options.items()) if k in self._allowed_graphics} | python | def get(self):
return {k:v for k,v in list(self.options.items()) if k in self._allowed_graphics} | [
"def",
"get",
"(",
"self",
")",
":",
"return",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"list",
"(",
"self",
".",
"options",
".",
"items",
"(",
")",
")",
"if",
"k",
"in",
"self",
".",
"_allowed_graphics",
"}"
] | Get graphics options. | [
"Get",
"graphics",
"options",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/mg/graphic.py#L260-L262 |
242,899 | stitchfix/pyxley | pyxley/charts/charts.py | Chart.apply_filters | def apply_filters(df, filters):
"""Basic filtering for a dataframe."""
idx = pd.Series([True]*df.shape[0])
for k, v in list(filters.items()):
if k not in df.columns:
continue
idx &= (df[k] == v)
return df.loc[idx] | python | def apply_filters(df, filters):
idx = pd.Series([True]*df.shape[0])
for k, v in list(filters.items()):
if k not in df.columns:
continue
idx &= (df[k] == v)
return df.loc[idx] | [
"def",
"apply_filters",
"(",
"df",
",",
"filters",
")",
":",
"idx",
"=",
"pd",
".",
"Series",
"(",
"[",
"True",
"]",
"*",
"df",
".",
"shape",
"[",
"0",
"]",
")",
"for",
"k",
",",
"v",
"in",
"list",
"(",
"filters",
".",
"items",
"(",
")",
")",... | Basic filtering for a dataframe. | [
"Basic",
"filtering",
"for",
"a",
"dataframe",
"."
] | 2dab00022d977d986169cd8a629b3a2f91be893f | https://github.com/stitchfix/pyxley/blob/2dab00022d977d986169cd8a629b3a2f91be893f/pyxley/charts/charts.py#L10-L18 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.