Skip to content

Commit d6235c1

Browse files
committed
1、排查页脚异常问题:
  丢失了mc:AlternateContent标签,引起文档页码信息丢失,页脚下划线丢失;   优化重构了文档图片读取算法;   增加了读取AlternateContent标签的样式功能;   重新设计了AlternateContent标签关联各种子标签的架构设计;   增加了AlternateContent标签关子的子元素关联类:Line和Shape   调整了AlternateContent标签 关联主容器算法;   增加了AltLine写回功能;   增加了AltShage写回功能;   增加了AlternateContent写回功能; 2、从页码丢失重新分析instrText标签的信息:   重构了读取instrText标签的文本功能;   增加了读取文本隐藏信息功能;   优化了读取文本算法;   修改优化了instrText前台写入文本算法功能;   调整了instrText标签 关联主容器算法; 3、调整了表格的单元格校式读取功能:   增加了单元元格边框样式读取功能;   解决了黄金版合同读取尾部表格显示异常问题;   增加了单元格关联系统样式StyleID功能;   增加了表头背景填充功能;   增加了表格tblOverlap标签读取功能;   增加了word2007下上述四个新增功能的写回功能(4项); 4、修复了页眉的边框丢失问题:   增加样式读取功能;   增加样式写回功能;
1 parent 372da20 commit d6235c1

16 files changed

+1070
-76
lines changed

src/PhpWord/ComplexType/AltLine.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
4+
namespace PhpOffice\PhpWord\ComplexType;
5+
6+
7+
use PhpOffice\PhpWord\Shared\Text;
8+
9+
final class AltLine extends AltShape
10+
{
11+
}

src/PhpWord/ComplexType/AltShape.php

+325
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
<?php
2+
3+
4+
namespace PhpOffice\PhpWord\ComplexType;
5+
6+
7+
use PhpOffice\PhpWord\Shared\Text;
8+
9+
class AltShape
10+
{
11+
/**
12+
* Shape Id
13+
*
14+
* @var string
15+
*/
16+
private $id;
17+
18+
/**
19+
* Shape spid
20+
*
21+
* @var string
22+
*/
23+
private $spid;
24+
25+
/**
26+
* Shape spt
27+
*
28+
* @var string
29+
*/
30+
private $spt;
31+
32+
/**
33+
* Shape type
34+
*
35+
* @var string
36+
*/
37+
private $type;
38+
39+
/**
40+
* Shape style
41+
*
42+
* @var string
43+
*/
44+
private $style;
45+
46+
/**
47+
* Shape filled
48+
*
49+
* @var string
50+
*/
51+
private $filled;
52+
53+
/**
54+
* Shape stroked
55+
*
56+
* @var string
57+
*/
58+
private $stroked;
59+
60+
/**
61+
* Shape coordsize
62+
*
63+
* @var string
64+
*/
65+
private $coordsize;
66+
67+
/**
68+
* Shape gfxdata
69+
*
70+
* @var string
71+
*/
72+
private $gfxdata;
73+
74+
75+
public function __construct($id)
76+
{
77+
$this->setId($id);
78+
}
79+
80+
/**
81+
* Set shape Id
82+
*
83+
* @return string
84+
* @author <[email protected]>
85+
* @since 2023/8/15 3:24 下午
86+
*/
87+
public function setId($value = null) {
88+
$this->id = $value;
89+
}
90+
91+
/**
92+
* Get shape Id
93+
*
94+
* @return string
95+
* @author <[email protected]>
96+
* @since 2023/8/15 3:24 下午
97+
*/
98+
public function getId() {
99+
return $this->id;
100+
}
101+
102+
/**
103+
* Set shape spid
104+
*
105+
* @return string
106+
* @author <[email protected]>
107+
* @since 2023/8/15 3:24 下午
108+
*/
109+
public function setSpid($value = null) {
110+
$this->spid = $value;
111+
}
112+
113+
/**
114+
* Set shape spid
115+
*
116+
* @return string
117+
* @author <[email protected]>
118+
* @since 2023/8/15 3:24 下午
119+
*/
120+
public function getSpid() {
121+
return $this->spid;
122+
}
123+
124+
/**
125+
* Set shape spt
126+
*
127+
* @return string
128+
* @author <[email protected]>
129+
* @since 2023/8/15 3:24 下午
130+
*/
131+
public function setSpt($value = null) {
132+
$this->spt = $value;
133+
}
134+
135+
/**
136+
* Set shape spt
137+
*
138+
* @return string
139+
* @author <[email protected]>
140+
* @since 2023/8/15 3:24 下午
141+
*/
142+
public function getSpt() {
143+
return $this->spt;
144+
}
145+
146+
/**
147+
* Set shape type
148+
*
149+
* @return string
150+
* @author <[email protected]>
151+
* @since 2023/8/15 3:24 下午
152+
*/
153+
public function setType($value = null) {
154+
$this->type = $value;
155+
}
156+
157+
/**
158+
* Set shape type
159+
*
160+
* @return string
161+
* @author <[email protected]>
162+
* @since 2023/8/15 3:24 下午
163+
*/
164+
public function getType() {
165+
return $this->type;
166+
}
167+
168+
/**
169+
* Set shape style
170+
*
171+
* @return string
172+
* @author <[email protected]>
173+
* @since 2023/8/15 3:24 下午
174+
*/
175+
public function setStyle($value = null) {
176+
$this->style = $value;
177+
}
178+
179+
/**
180+
* Set shape style
181+
*
182+
* @return string
183+
* @author <[email protected]>
184+
* @since 2023/8/15 3:24 下午
185+
*/
186+
public function getStyle() {
187+
return $this->style;
188+
}
189+
190+
/**
191+
* Set shape filled
192+
*
193+
* @return string
194+
* @author <[email protected]>
195+
* @since 2023/8/15 3:24 下午
196+
*/
197+
public function setFilled($value = null) {
198+
$this->filled = $value;
199+
}
200+
201+
/**
202+
* Set shape filled
203+
*
204+
* @return string
205+
* @author <[email protected]>
206+
* @since 2023/8/15 3:24 下午
207+
*/
208+
public function getFilled() {
209+
return $this->filled;
210+
}
211+
212+
/**
213+
* Set shape stroked
214+
*
215+
* @return string
216+
* @author <[email protected]>
217+
* @since 2023/8/15 3:24 下午
218+
*/
219+
public function setStroked($value = null) {
220+
$this->stroked = $value;
221+
}
222+
223+
/**
224+
* Set shape filled
225+
*
226+
* @return string
227+
* @author <[email protected]>
228+
* @since 2023/8/15 3:24 下午
229+
*/
230+
public function getStroked() {
231+
return $this->stroked;
232+
}
233+
234+
/**
235+
* Set shape coordsize
236+
*
237+
* @return string
238+
* @author <[email protected]>
239+
* @since 2023/8/15 3:24 下午
240+
*/
241+
public function setCoordsize($value = null) {
242+
$this->coordsize = $value;
243+
}
244+
245+
/**
246+
* Set shape coordsize
247+
*
248+
* @return string
249+
* @author <[email protected]>
250+
* @since 2023/8/15 3:24 下午
251+
*/
252+
public function getCoordsize() {
253+
return $this->coordsize;
254+
}
255+
256+
/**
257+
* Set shape coordsize
258+
*
259+
* @return string
260+
* @author <[email protected]>
261+
* @since 2023/8/15 3:24 下午
262+
*/
263+
public function setGfxdata($value = null) {
264+
$this->gfxdata = $value;
265+
}
266+
267+
/**
268+
* Set shape coordsize
269+
*
270+
* @return string
271+
* @author <[email protected]>
272+
* @since 2023/8/15 3:24 下午
273+
*/
274+
public function getGfxdata() {
275+
return $this->gfxdata;
276+
}
277+
278+
/**
279+
* Set style value template method.
280+
*
281+
* Some child classes have their own specific overrides.
282+
* Backward compability check for versions < 0.10.0 which use underscore
283+
* prefix for their private properties.
284+
* Check if the set method is exists. Throws an exception?
285+
*
286+
* @param string $key
287+
* @param array|int|string $value
288+
*
289+
* @return self
290+
*/
291+
public function setAttrValue($key, $value)
292+
{
293+
if (isset($this->aliases[$key])) {
294+
$key = $this->aliases[$key];
295+
}
296+
297+
if ($key === 'align') {
298+
$key = 'alignment';
299+
}
300+
301+
$method = 'set' . Text::removeUnderscorePrefix($key);
302+
if (method_exists($this, $method)) {
303+
$this->$method($value);
304+
}
305+
306+
return $this;
307+
}
308+
309+
310+
/**
311+
* Set style by using associative array.
312+
*
313+
* @param array $values
314+
*
315+
* @return self
316+
*/
317+
public function setAttrByArray($values = [])
318+
{
319+
foreach ($values as $key => $value) {
320+
$this->setAttrValue($key, $value);
321+
}
322+
323+
return $this;
324+
}
325+
}

src/PhpWord/Element/AbstractContainer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ abstract class AbstractContainer extends AbstractElement
8585
public function __call($function, $args)
8686
{
8787
$elements = [
88-
'Text', 'TextRun', 'Bookmark', 'Link', 'PreserveText', 'TextBreak',
88+
'Text', 'TextRun', 'Bookmark', 'Link', 'PreserveText', 'TextBreak', 'AlternateContent',
8989
'ListItem', 'ListItemRun', 'Table', 'Image', 'Drawing', 'Object', 'OLEObject',
9090
'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field',
9191
'Line', 'Shape', 'Title', 'TOC', 'PageBreak',
@@ -328,15 +328,15 @@ private function checkValidity($method)
328328
'FormField' => $generalContainers,
329329
'SDT' => $generalContainers,
330330
'TrackChange' => $generalContainers,
331-
'TextRun' => ['Section', 'Header', 'Footer', 'Cell', 'TextBox', 'TrackChange', 'ListItemRun'],
331+
'TextRun' => ['Section', 'Header', 'Footer', 'Cell', 'TextBox', 'TrackChange', 'ListItemRun', 'AlternateContent'],
332332
'ListItem' => ['Section', 'Header', 'Footer', 'Cell', 'TextBox'],
333333
'ListItemRun' => ['Section', 'Header', 'Footer', 'Cell', 'TextBox'],
334334
'Table' => ['Section', 'Header', 'Footer', 'Cell', 'TextBox'],
335335
'CheckBox' => ['Section', 'Header', 'Footer', 'Cell', 'TextRun'],
336336
'TextBox' => ['Section', 'Header', 'Footer', 'Cell'],
337337
'Footnote' => ['Section', 'TextRun', 'Cell', 'ListItemRun'],
338338
'Endnote' => ['Section', 'TextRun', 'Cell'],
339-
'PreserveText' => ['Section', 'Header', 'Footer', 'Cell'],
339+
'PreserveText' => ['Section', 'Header', 'Footer', 'Cell', 'AlternateContent', 'TextRun'],
340340
'Title' => ['Section', 'Cell'],
341341
'TOC' => ['Section'],
342342
'PageBreak' => ['Section'],
@@ -346,7 +346,7 @@ private function checkValidity($method)
346346
// Special condition, e.g. preservetext can only exists in cell when
347347
// the cell is located in header or footer
348348
$validSubcontainers = [
349-
'PreserveText' => [['Cell'], ['Header', 'Footer', 'Section']],
349+
'PreserveText' => [['Cell', 'AlternateContent', 'TextRun'], ['Header', 'Footer', 'Section']],
350350
'Footnote' => [['Cell', 'TextRun'], ['Section']],
351351
'Endnote' => [['Cell', 'TextRun'], ['Section']],
352352
];

0 commit comments

Comments
 (0)