def test_plain_mtext_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.\tNummerierung\n2.\tNummerierung\n\n1/2500 ein Bruch" ) # Includes caret decoding! assert fast_plain_mtext(raw_text) == expected assert ( fast_plain_mtext("\\:") == "\\:" ), "invalid escape code is printed verbatim"
def split_content(): content = fast_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 = [fast_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_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_fast_plain_mtext(count: int): for _ in range(count): fast_plain_mtext(LONG)
def short_fast_plain_mtext(count: int): for _ in range(count): fast_plain_mtext(SHORT)