def test_plain_text_decoding_special_chars(): assert plain_mtext("%%C") == "Ø" # alt-0216 assert plain_mtext("%%D") == "°" # alt-0176 assert plain_mtext("%%P") == "±" # alt-0177 # formatting codes of TEXT are not supported in MTEXT # and unknown codes are rendered as they are: s = "%%a%%u_%%U_%%k_%%K_%%o_%%O_%%z" assert plain_mtext(s) == s
def test_plain_text_removes_formatting(): raw_text = r"\A1;Das ist eine MText\PZeile mit {\LFormat}ierung\Pänder " \ r"die Farbe\P\pi-7.5,l7.5,t7.5;1.^INummerierung\P2.^INummeri" \ r"erung\P\pi0,l0,tz;\P{\H0.7x;\S1/2500;} ein Bruch" expected = "Das ist eine MText\nZeile mit Formatierung\nänder die Farbe\n" \ "1.^INummerierung\n2.^INummerierung\n\n1/2500 ein Bruch" assert plain_mtext(raw_text) == expected assert plain_mtext('\\:') == '\\:', \ "invalid escape code is printed verbatim"
def test_plain_mtext2_removes_formatting(): raw_text = ( r"\A1;Das ist eine MText\PZeile mit {\LFormat}ierung\Pänder " r"die Farbe\P\pi-7.5,l7.5,t7.5;1.^INummerierung\P2.^INummeri" r"erung\P\pi0,l0,tz;\P{\H0.7x;\S1/2500;} ein Bruch" ) expected = ( "Das ist eine MText\nZeile mit Formatierung\nänder die Farbe\n" "1. Nummerierung\n2. Nummerierung\n\n1/2500 ein Bruch" ) assert plain_mtext(raw_text, tabsize=1) == expected assert ( plain_mtext("\\:\\;") == "\\:\\;" ), "invalid escape code is printed verbatim"
def plain_text(self, split=False) -> Union[List[str], str]: """ Returns text content without formatting codes. Args: split: returns list of strings splitted at line breaks if ``True`` else returns a single string. """ return plain_mtext(self.text, split=split)
def plain_text(self, split=False) -> Union[List[str], str]: """ Returns the text content without inline formatting codes. Args: split: split content text at line breaks if ``True`` and returns a list of strings without line endings """ return plain_mtext(self.text, split=split)
def split_content(): content = plain_mtext(self.text, split=True) if self.has_columns: if content and content[-1] == "": content.pop() for c in self._columns.linked_columns: content.extend(c.plain_text(split=True)) if content and content[-1] == "": content.pop() return content
def plain_text(self, split=False, fast=True) -> Union[List[str], str]: """Returns the text content without inline formatting codes. The "fast" mode is accurate if the DXF content was created by reliable (and newer) CAD applications like AutoCAD or BricsCAD. The "accurate" mode is for some rare cases where the content was created by older CAD applications or unreliable DXF libraries and CAD applications. Args: split: split content text at line breaks if ``True`` and returns a list of strings without line endings fast: uses the "fast" mode to extract the plain MTEXT content if ``True`` or the "accurate" mode if set to ``False`` .. versionadded:: 0.16.6 `fast` argument """ if fast: return fast_plain_mtext(self.text, split=split) else: return plain_mtext(self.text, split=split)
def plain_mtext(self, fast=True) -> str: """Returns the embedded MTEXT content without formatting codes. Returns an empty string if no embedded MTEXT entity exist. The "fast" mode is accurate if the DXF content was created by reliable (and newer) CAD applications like AutoCAD or BricsCAD. The "accurate" mode is for some rare cases where the content was created by older CAD applications or unreliable DXF libraries and CAD applications. The "accurate" mode is **much** slower than the "fast" mode. Args: fast: uses the "fast" mode to extract the plain MTEXT content if ``True`` or the "accurate" mode if set to ``False`` """ if self._embedded_mtext: text = self._embedded_mtext.text if fast: return fast_plain_mtext(text, split=False) # type: ignore else: return plain_mtext(text, split=False) # type: ignore return ""
def merged_content(): content = [plain_mtext(self.text, split=False)] if self.has_columns: for c in self._columns.linked_columns: content.append(c.plain_text(split=False)) return "".join(content)
def test_plain_text_convert_special_chars(): assert plain_mtext("%%d") == "°" assert plain_mtext("%%u") == "" assert plain_mtext("%%U") == ""
def test_remove_commands_without_terminating_semicolon(): # single letter commands do not need a trailing semicolon: assert plain_mtext(r"\C1Text") == "Text" assert fast_plain_mtext(r"\C1Text") == r"\C1Text" # not the expected result
def long_plain_mtext(count: int): for _ in range(count): plain_mtext(LONG)
def short_plain_mtext(count: int): for _ in range(count): plain_mtext(SHORT)