| 1 | package pro.verron.officestamper.preset.preprocessors.similarrun; | |
| 2 | ||
| 3 | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; | |
| 4 | import org.docx4j.wml.ContentAccessor; | |
| 5 | import pro.verron.officestamper.api.PreProcessor; | |
| 6 | import pro.verron.officestamper.utils.wml.WmlUtils; | |
| 7 | ||
| 8 | import java.util.LinkedHashSet; | |
| 9 | ||
| 10 | /// Merges consecutive runs with the same styling into a single run. | |
| 11 | /// | |
| 12 | /// This preprocessor analyzes the document and identifies adjacent runs that share identical styling properties. It | |
| 13 | /// then merges these runs into a single run to reduce document complexity and improve processing efficiency. | |
| 14 | /// | |
| 15 | /// The merging process preserves all content from the original runs while maintaining the formatting of the first run | |
| 16 | /// in each sequence of similar runs. | |
| 17 | /// | |
| 18 | /// @author Joseph Verron | |
| 19 | public class MergeSameStyleRuns | |
| 20 | implements PreProcessor { | |
| 21 | ||
| 22 | @Override | |
| 23 | public void process(WordprocessingMLPackage document) { | |
| 24 | var visitor = new SimilarRunVisitor(); | |
| 25 |
1
1. process : removed call to pro/verron/officestamper/utils/wml/WmlUtils::visitDocument → TIMED_OUT |
WmlUtils.visitDocument(document, visitor); |
| 26 | for (var similarStyleRuns : visitor.getSimilarStyleRuns()) { | |
| 27 | var firstRun = similarStyleRuns.getFirst(); | |
| 28 | var runContent = firstRun.getContent(); | |
| 29 | var firstRunContent = new LinkedHashSet<>(runContent); | |
| 30 | var firstRunParentContent = ((ContentAccessor) firstRun.getParent()).getContent(); | |
| 31 | for (var r : similarStyleRuns.subList(1, similarStyleRuns.size())) { | |
| 32 | firstRunParentContent.remove(r); | |
| 33 | firstRunContent.addAll(r.getContent()); | |
| 34 | } | |
| 35 |
1
1. process : removed call to java/util/List::clear → KILLED |
runContent.clear(); |
| 36 | runContent.addAll(firstRunContent); | |
| 37 | } | |
| 38 | } | |
| 39 | } | |
Mutations | ||
| 25 |
1.1 |
|
| 35 |
1.1 |