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

Method _validate

src/__init__.py:9112–9181  ·  view source on GitHub ↗

Validate the class entries.

(self)

Source from the content-addressed store, hash-verified

9110 return
9111
9112 def _validate(self):
9113 """Validate the class entries.
9114 """
9115 if (self.rect.is_infinite
9116 or self.rect.is_empty
9117 ):
9118 raise ValueError("bad rect")
9119
9120 if not self.field_name:
9121 raise ValueError("field name missing")
9122
9123 if self.field_label == "Unnamed":
9124 self.field_label = None
9125 CheckColor(self.border_color)
9126 CheckColor(self.fill_color)
9127 if not self.text_color:
9128 self.text_color = (0, 0, 0)
9129 CheckColor(self.text_color)
9130
9131 if not self.border_width:
9132 self.border_width = 0
9133
9134 if not self.text_fontsize:
9135 self.text_fontsize = 0
9136
9137 self.border_style = self.border_style.upper()[0:1]
9138
9139 # standardize content of JavaScript entries
9140 btn_type = self.field_type in (
9141 mupdf.PDF_WIDGET_TYPE_BUTTON,
9142 mupdf.PDF_WIDGET_TYPE_CHECKBOX,
9143 mupdf.PDF_WIDGET_TYPE_RADIOBUTTON,
9144 )
9145 if not self.script:
9146 self.script = None
9147 elif type(self.script) is not str:
9148 raise ValueError("script content must be a string")
9149
9150 # buttons cannot have the following script actions
9151 if btn_type or not self.script_calc:
9152 self.script_calc = None
9153 elif type(self.script_calc) is not str:
9154 raise ValueError("script_calc content must be a string")
9155
9156 if btn_type or not self.script_change:
9157 self.script_change = None
9158 elif type(self.script_change) is not str:
9159 raise ValueError("script_change content must be a string")
9160
9161 if btn_type or not self.script_format:
9162 self.script_format = None
9163 elif type(self.script_format) is not str:
9164 raise ValueError("script_format content must be a string")
9165
9166 if btn_type or not self.script_stroke:
9167 self.script_stroke = None
9168 elif type(self.script_stroke) is not str:
9169 raise ValueError("script_stroke content must be a string")

Callers 2

updateMethod · 0.95
add_widgetMethod · 0.80

Calls 2

_checkerMethod · 0.95
CheckColorFunction · 0.85

Tested by

no test coverage detected