MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / TextFrame

Class TextFrame

utils/src/presentation.py:108–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106
107
108class TextFrame:
109 def __init__(self, shape: BaseShape, level: int):
110 if not shape.has_text_frame:
111 self.is_textframe = False
112 return
113 self.paragraphs = [
114 Paragraph(paragraph, idx)
115 for idx, paragraph in enumerate(shape.text_frame.paragraphs)
116 ]
117 para_offset = 0
118 for para in self.paragraphs:
119 if para.idx == -1:
120 para_offset += 1
121 else:
122 para.idx = para.idx - para_offset
123 if len(self.paragraphs) == 0:
124 self.is_textframe = False
125 return
126 self.level = level
127 self.text = shape.text
128 self.is_textframe = True
129 self.font = merge_dict(
130 object_to_dict(shape.text_frame.font),
131 [para.font for para in self.paragraphs if para.idx != -1],
132 )
133
134 def to_html(self, style_args: StyleArg):
135 """
136 Convert the text frame to HTML.
137
138 Args:
139 style_args (StyleArg): The style arguments for HTML conversion.
140
141 Returns:
142 str: The HTML representation of the text frame.
143 """
144 if not self.is_textframe:
145 return ""
146 repr_list = [
147 para.to_html(style_args) for para in self.paragraphs if para.idx != -1
148 ]
149 return "\n".join([INDENT * self.level + repr for repr in repr_list])
150
151 def __repr__(self):
152 if not self.is_textframe:
153 return "TextFrame: null"
154 return f"TextFrame: {self.paragraphs}"
155
156 def __len__(self):
157 if not self.is_textframe:
158 return 0
159 return len(self.text)
160
161 def to_pptc(self, father_idx: int) -> str:
162 """
163 Convert the text frame to PPTC format.
164
165 Args:

Callers 1

from_shapeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected