Skip to content

Commit 78eb8c5

Browse files
committed
Code refactoring for renderers
Fix formatting issues, rearrange imports
1 parent 04d0155 commit 78eb8c5

File tree

12 files changed

+57
-55
lines changed

12 files changed

+57
-55
lines changed

src/main/java/com/itextpdf/html2pdf/attach/impl/DefaultTagWorkerMapping.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,11 @@ TagProcessorMapping<ITagWorkerCreator> getDefaultTagWorkerMapping() {
268268
public interface ITagWorkerCreator {
269269
/**
270270
* Creates an {@link ITagWorker} instance.
271-
* @param elementNode tag worker element node.
272-
* @param processorContext processor context.
273-
* @return {@link ITagWorker} instance.
271+
*
272+
* @param elementNode tag worker element node
273+
* @param processorContext processor context
274+
*
275+
* @return {@link ITagWorker} instance
274276
*/
275277
ITagWorker create(IElementNode elementNode, ProcessorContext processorContext);
276278
}

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/HtmlDocumentRenderer.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.html2pdf.attach.ProcessorContext;
2626
import com.itextpdf.html2pdf.attach.impl.layout.HtmlBodyStylesApplierHandler.LowestAndHighest;
2727
import com.itextpdf.html2pdf.attach.impl.layout.HtmlBodyStylesApplierHandler.PageStylesProperties;
28-
import com.itextpdf.kernel.pdf.event.AbstractPdfDocumentEventHandler;
29-
import com.itextpdf.kernel.pdf.event.AbstractPdfDocumentEvent;
30-
import com.itextpdf.kernel.pdf.event.PdfDocumentEvent;
3128
import com.itextpdf.kernel.geom.PageSize;
3229
import com.itextpdf.kernel.geom.Rectangle;
3330
import com.itextpdf.kernel.pdf.PdfDocument;
3431
import com.itextpdf.kernel.pdf.PdfPage;
32+
import com.itextpdf.kernel.pdf.event.AbstractPdfDocumentEvent;
33+
import com.itextpdf.kernel.pdf.event.AbstractPdfDocumentEventHandler;
34+
import com.itextpdf.kernel.pdf.event.PdfDocumentEvent;
3535
import com.itextpdf.layout.Document;
3636
import com.itextpdf.layout.IPropertyContainer;
3737
import com.itextpdf.layout.element.AreaBreak;
@@ -64,6 +64,10 @@ public class HtmlDocumentRenderer extends DocumentRenderer {
6464
*/
6565
private static final boolean TRIM_LAST_BLANK_PAGE = true;
6666

67+
private final HtmlBodyStylesApplierHandler htmlBodyHandler;
68+
69+
private final Map<Integer, PageStylesProperties> pageStylesPropertiesMap = new HashMap<>();
70+
6771
/** The page context processor for the first page. */
6872
private PageContextProcessor firstPageProc;
6973

@@ -82,12 +86,9 @@ public class HtmlDocumentRenderer extends DocumentRenderer {
8286
private boolean evenPagesAreLeft = true;
8387

8488
private PageMarginBoxesDrawingHandler marginBoxesHandler;
85-
private HtmlBodyStylesApplierHandler htmlBodyHandler;
86-
87-
private Map<Integer, PageStylesProperties> pageStylesPropertiesMap = new HashMap<>();
8889

8990
/**
90-
* The waiting element, an child element is kept waiting for the
91+
* The waiting element, a child element is kept waiting for the
9192
* next element to process the "keep with previous" property.
9293
*/
9394
private IRenderer waitingElement;
@@ -107,7 +108,7 @@ public class HtmlDocumentRenderer extends DocumentRenderer {
107108
/**
108109
* Instantiates a new {@link HtmlDocumentRenderer} instance.
109110
*
110-
* @param document an iText {@link Document} instance
111+
* @param document an iText {@link Document} instance
111112
* @param immediateFlush the immediate flush indicator
112113
*/
113114
public HtmlDocumentRenderer(Document document, boolean immediateFlush) {
@@ -119,9 +120,9 @@ public HtmlDocumentRenderer(Document document, boolean immediateFlush) {
119120
/**
120121
* Processes the page rules.
121122
*
122-
* @param rootNode the root node
123+
* @param rootNode the root node
123124
* @param cssResolver the CSS resolver
124-
* @param context the processor context
125+
* @param context the processor context
125126
*/
126127
public void processPageRules(INode rootNode, ICssResolver cssResolver, ProcessorContext context) {
127128
PageContextProperties firstPageProps = PageContextProperties.resolve(rootNode, cssResolver, context.getCssContext(),
@@ -217,15 +218,15 @@ public IRenderer getNextRenderer() {
217218
}
218219

219220
@Override
220-
public void flush(){
221+
public void flush() {
221222
processWaitingElement();
222223
super.flush();
223224
}
224225

225226
/**
226227
* Layouts waiting element.
227228
*/
228-
public void processWaitingElement(){
229+
public void processWaitingElement() {
229230
if (waitingElement != null) {
230231
IRenderer r = this.waitingElement;
231232
waitingElement = null;
@@ -327,7 +328,7 @@ protected PageSize addNewPage(PageSize customPageSize) {
327328
nextProcessor.processNewPage(addedPage);
328329

329330
float[] margins = nextProcessor.computeLayoutMargins();
330-
BodyHtmlStylesContainer[] styles = new BodyHtmlStylesContainer[] {
331+
BodyHtmlStylesContainer[] styles = new BodyHtmlStylesContainer[]{
331332
((IPropertyContainer) document).<BodyHtmlStylesContainer>getProperty(Html2PdfProperty.HTML_STYLING),
332333
((IPropertyContainer) document).<BodyHtmlStylesContainer>getProperty(Html2PdfProperty.BODY_STYLING)};
333334
pageStylesPropertiesMap.put(pageNumber, new PageStylesProperties(styles));
@@ -358,6 +359,7 @@ void trimLastPageIfNecessary() {
358359

359360
/**
360361
* Returns the number of pages that will be trimmed on {@link #close()}
362+
*
361363
* @return 0 if no pages will be trimmed, or positive number of trimmed pages in case any are trimmed
362364
*/
363365
int simulateTrimLastPage() {
@@ -389,6 +391,7 @@ int simulateTrimLastPage() {
389391
* Gets a page processor for the page.
390392
*
391393
* @param pageNum the number of the page for which the {@link PageContextProcessor} shall be obtained
394+
*
392395
* @return a page processor
393396
*/
394397
PageContextProcessor getPageProcessor(int pageNum) {

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/PageCountRenderer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.html2pdf.attach.impl.layout;
2424

25+
import com.itextpdf.commons.utils.MessageFormatUtil;
2526
import com.itextpdf.html2pdf.css.resolve.func.counter.CounterDigitsGlyphStyle;
2627
import com.itextpdf.html2pdf.html.HtmlUtils;
27-
import com.itextpdf.io.logs.IoLogMessageConstant;
2828
import com.itextpdf.io.font.otf.GlyphLine;
29-
import com.itextpdf.commons.utils.MessageFormatUtil;
29+
import com.itextpdf.io.logs.IoLogMessageConstant;
3030
import com.itextpdf.kernel.font.PdfFont;
3131
import com.itextpdf.layout.Document;
3232
import com.itextpdf.layout.layout.LayoutContext;
@@ -36,11 +36,11 @@ This file is part of the iText (R) project.
3636
import com.itextpdf.layout.renderer.DocumentRenderer;
3737
import com.itextpdf.layout.renderer.IRenderer;
3838
import com.itextpdf.layout.renderer.TextRenderer;
39+
import org.slf4j.Logger;
40+
import org.slf4j.LoggerFactory;
3941

4042
import java.util.ArrayList;
4143
import java.util.List;
42-
import org.slf4j.Logger;
43-
import org.slf4j.LoggerFactory;
4444

4545
/**
4646
* {@link TextRenderer} implementation for the page count.
@@ -61,15 +61,15 @@ class PageCountRenderer extends TextRenderer {
6161

6262
protected PageCountRenderer(TextRenderer other) {
6363
super(other);
64-
this.digitsGlyphStyle = ((PageCountRenderer)other).digitsGlyphStyle;
64+
this.digitsGlyphStyle = ((PageCountRenderer) other).digitsGlyphStyle;
6565
}
6666

6767
/* (non-Javadoc)
6868
* @see com.itextpdf.layout.renderer.TextRenderer#layout(com.itextpdf.layout.layout.LayoutContext)
6969
*/
7070
@Override
7171
public LayoutResult layout(LayoutContext layoutContext) {
72-
PageCountType pageCountType = (PageCountType)this.<PageCountType>getProperty(Html2PdfProperty.PAGE_COUNT_TYPE);
72+
PageCountType pageCountType = (PageCountType) this.<PageCountType>getProperty(Html2PdfProperty.PAGE_COUNT_TYPE);
7373
String previousText = getText().toString();
7474
// If typography is enabled and the page counter element has a non-default direction,
7575
// iText processes its content (see LineRenderer#updateBidiLevels) before layouting it.

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/PageTargetCountRenderer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.html2pdf.attach.impl.layout;
2424

25+
import com.itextpdf.commons.utils.MessageFormatUtil;
2526
import com.itextpdf.html2pdf.css.resolve.func.counter.CounterDigitsGlyphStyle;
2627
import com.itextpdf.html2pdf.html.HtmlUtils;
27-
import com.itextpdf.io.logs.IoLogMessageConstant;
28-
import com.itextpdf.io.font.otf.GlyphLine;
2928
import com.itextpdf.html2pdf.logs.Html2PdfLogMessageConstant;
30-
import com.itextpdf.commons.utils.MessageFormatUtil;
29+
import com.itextpdf.io.font.otf.GlyphLine;
30+
import com.itextpdf.io.logs.IoLogMessageConstant;
3131
import com.itextpdf.kernel.font.PdfFont;
3232
import com.itextpdf.layout.layout.LayoutContext;
3333
import com.itextpdf.layout.layout.LayoutResult;
@@ -67,8 +67,8 @@ class PageTargetCountRenderer extends TextRenderer {
6767

6868
protected PageTargetCountRenderer(TextRenderer other) {
6969
super(other);
70-
this.digitsGlyphStyle = ((PageTargetCountRenderer)other).digitsGlyphStyle;
71-
this.target = ((PageTargetCountRenderer)other).target;
70+
this.digitsGlyphStyle = ((PageTargetCountRenderer) other).digitsGlyphStyle;
71+
this.target = ((PageTargetCountRenderer) other).target;
7272
}
7373

7474
/**

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/RunningElement.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ This file is part of the iText (R) project.
3737
* from the normal flow. This element is designed to register where particular running element would have been placed.
3838
*/
3939
public class RunningElement extends Div {
40-
private RunningElementContainer runningElementContainer;
40+
private final RunningElementContainer runningElementContainer;
4141

4242
/**
4343
* Creates a new instance of {@link RunningElement}.
44+
*
4445
* @param runningElementContainer a container for the actual running element removed from the normal flow.
4546
*/
4647
public RunningElement(RunningElementContainer runningElementContainer) {
@@ -57,7 +58,7 @@ protected IRenderer makeNewRenderer() {
5758
* It's an empty div so it's not expected to be ever split between areas.
5859
*/
5960
static class RunningElementRenderer extends DivRenderer {
60-
private RunningElementContainer runningElementContainer;
61+
private final RunningElementContainer runningElementContainer;
6162
private boolean isFirstOnRootArea;
6263

6364
public RunningElementRenderer(Div modelElement, RunningElementContainer runningElementContainer) {

src/main/java/com/itextpdf/html2pdf/attach/impl/tags/PTagWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public boolean processTagChild(ITagWorker childTagWorker, ProcessorContext conte
134134
} else if (isBlockWithDisplay(childTagWorker, element, CssConstants.INLINE_BLOCK, false)) {
135135
inlineHelper.add((IBlockElement) element);
136136
return true;
137-
} else if (isBlockWithDisplay(childTagWorker, element,CssConstants.BLOCK, false)) {
137+
} else if (isBlockWithDisplay(childTagWorker, element, CssConstants.BLOCK, false)) {
138138
IPropertyContainer propertyContainer = childTagWorker.getElementResult();
139139
processBlockElement((IBlockElement) propertyContainer);
140140
return true;

src/main/java/com/itextpdf/html2pdf/css/apply/impl/DefaultTagCssApplierMapping.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class DefaultTagCssApplierMapping {
4343

4444
/** The default mapping. */
4545
private static TagProcessorMapping<ICssApplierCreator> mapping;
46+
4647
static {
4748
mapping = new TagProcessorMapping<>();
4849

@@ -205,7 +206,8 @@ TagProcessorMapping<ICssApplierCreator> getDefaultCssApplierMapping() {
205206
public interface ICssApplierCreator {
206207
/**
207208
* Creates an {@link ICssApplier} instance.
208-
* @return {@link ICssApplier} instance.
209+
*
210+
* @return {@link ICssApplier} instance
209211
*/
210212
ICssApplier create();
211213
}

src/main/java/com/itextpdf/html2pdf/css/resolve/DefaultCssResolver.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ This file is part of the iText (R) project.
5858
import com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver;
5959
import com.itextpdf.styledxmlparser.util.CssVariableUtil;
6060
import com.itextpdf.styledxmlparser.util.StyleUtil;
61+
import org.slf4j.Logger;
62+
import org.slf4j.LoggerFactory;
6163

6264
import java.io.InputStream;
6365
import java.util.ArrayList;
@@ -69,9 +71,6 @@ This file is part of the iText (R) project.
6971
import java.util.Map.Entry;
7072
import java.util.Set;
7173

72-
import org.slf4j.Logger;
73-
import org.slf4j.LoggerFactory;
74-
7574
/**
7675
* Default implementation of the {@link ICssResolver} interface.
7776
*/
@@ -102,9 +101,9 @@ public class DefaultCssResolver implements ICssResolver {
102101
/**
103102
* Creates a new {@link DefaultCssResolver} instance.
104103
*
105-
* @param treeRoot the root node
104+
* @param treeRoot the root node
106105
* @param mediaDeviceDescription the media device description
107-
* @param resourceResolver the resource resolver
106+
* @param resourceResolver the resource resolver
108107
*/
109108
public DefaultCssResolver(INode treeRoot, MediaDeviceDescription mediaDeviceDescription, ResourceResolver resourceResolver) {
110109
this.deviceDescription = mediaDeviceDescription;
@@ -116,7 +115,7 @@ public DefaultCssResolver(INode treeRoot, MediaDeviceDescription mediaDeviceDesc
116115
* Creates a new {@link DefaultCssResolver} instance.
117116
*
118117
* @param treeRoot the root node
119-
* @param context the processor context
118+
* @param context the processor context
120119
*/
121120
public DefaultCssResolver(INode treeRoot, ProcessorContext context) {
122121
this.deviceDescription = context.getDeviceDescription();
@@ -191,7 +190,7 @@ private Map<String, String> resolveStyles(INode element, CssContext context) {
191190
for (Map.Entry<String, String> entry : parentStyles.entrySet()) {
192191
elementStyles = StyleUtil
193192
.mergeParentStyleDeclaration(elementStyles, entry.getKey(), entry.getValue(), parentStyles.get(
194-
CommonCssConstants.FONT_SIZE), INHERITANCE_RULES);
193+
CommonCssConstants.FONT_SIZE), INHERITANCE_RULES);
195194

196195
// If the parent has display: flex, the flex item is blockified
197196
// no matter what display value is set for it (except 'none' and 'grid' values).
@@ -271,9 +270,9 @@ private Map<String, String> resolveElementsStyles(INode element) {
271270
/**
272271
* Resolves a content property.
273272
*
274-
* @param styles the styles map
273+
* @param styles the styles map
275274
* @param contentContainer the content container
276-
* @param context the CSS context
275+
* @param context the CSS context
277276
*/
278277
private void resolveContentProperty(Map<String, String> styles, INode contentContainer, CssContext context) {
279278
if (contentContainer instanceof CssPseudoElementNode || contentContainer instanceof PageMarginBoxContextNode) {
@@ -293,9 +292,9 @@ private void resolveContentProperty(Map<String, String> styles, INode contentCon
293292
/**
294293
* Collects CSS declarationss.
295294
*
296-
* @param rootNode the root node
295+
* @param rootNode the root node
297296
* @param resourceResolver the resource resolver
298-
* @param cssContext the CSS context
297+
* @param cssContext the CSS context
299298
*/
300299
private void collectCssDeclarations(INode rootNode, ResourceResolver resourceResolver, CssContext cssContext) {
301300
cssStyleSheet = new CssStyleSheet();
@@ -308,7 +307,7 @@ private void collectCssDeclarations(INode rootNode, ResourceResolver resourceRes
308307
if (TagConstants.STYLE.equals(element.name())) {
309308
if (!element.childNodes().isEmpty() && element.childNodes().get(0) instanceof IDataNode) {
310309
String styleData = ((IDataNode) element.childNodes().get(0)).getWholeData();
311-
CssStyleSheet styleSheet = CssStyleSheetParser.parse(styleData, resourceResolver.getBaseUri());
310+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(styleData, resourceResolver.getBaseUri());
312311
styleSheet = wrapStyleSheetInMediaQueryIfNecessary(element, styleSheet);
313312
cssStyleSheet.appendCssStyleSheet(styleSheet);
314313
}
@@ -375,7 +374,8 @@ private static void enablePagesCounterIfMentioned(CssStyleSheet styleSheet, CssC
375374
* Wraps a {@link CssMediaRule} into the style sheet if the head child element has a media attribute.
376375
*
377376
* @param headChildElement the head child element
378-
* @param styleSheet the style sheet
377+
* @param styleSheet the style sheet
378+
*
379379
* @return the css style sheet
380380
*/
381381
private CssStyleSheet wrapStyleSheetInMediaQueryIfNecessary(IElementNode headChildElement, CssStyleSheet styleSheet) {

src/test/java/com/itextpdf/html2pdf/css/flex/FlexContainerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ This file is part of the iText (R) project.
2828
import com.itextpdf.layout.logs.LayoutLogMessageConstant;
2929
import com.itextpdf.test.annotations.LogMessage;
3030
import com.itextpdf.test.annotations.LogMessages;
31-
32-
import java.io.IOException;
3331
import org.junit.jupiter.api.BeforeAll;
3432
import org.junit.jupiter.api.Tag;
3533
import org.junit.jupiter.api.Test;
3634

35+
import java.io.IOException;
36+
3737
@Tag("IntegrationTest")
3838
public class FlexContainerTest extends ExtendedHtmlConversionITextTest {
3939

@@ -552,7 +552,7 @@ public void flexTagAlignSelfTest() throws IOException, InterruptedException {
552552

553553
@Test
554554
@LogMessages(messages = {@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET),
555-
@LogMessage(messageTemplate = IoLogMessageConstant.CLIP_ELEMENT)})
555+
@LogMessage(messageTemplate = IoLogMessageConstant.CLIP_ELEMENT)})
556556
public void pAlignSelfTest() throws IOException, InterruptedException {
557557
convertToPdfAndCompare("pAlignSelf", SOURCE_FOLDER, DESTINATION_FOLDER, true);
558558
}

src/test/java/com/itextpdf/html2pdf/css/flex/FlexGapTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,11 @@ public void gapNestedFlexContainerColumnTest() throws IOException, InterruptedEx
165165
}
166166

167167
@Test
168-
// TODO DEVSIX-9473 Fix issues on page split
169168
public void gapAlignContentTest() throws IOException, InterruptedException {
170169
convertToPdfAndCompare("gapAlignContent", SOURCE_FOLDER, DESTINATION_FOLDER);
171170
}
172171

173172
@Test
174-
// TODO DEVSIX-9473 Fix issues on page split
175173
public void gapAlignContentRowRevDirTest() throws IOException, InterruptedException {
176174
convertToPdfAndCompare("gapAlignContentRowRevDir", SOURCE_FOLDER, DESTINATION_FOLDER);
177175
}
@@ -189,7 +187,6 @@ public void gapAlignContentColumnRevDirTest() throws IOException, InterruptedExc
189187
}
190188

191189
@Test
192-
// TODO DEVSIX-9473 Fix issues on page split
193190
public void gapAlignContentWrapRevTest() throws IOException, InterruptedException {
194191
convertToPdfAndCompare("gapAlignContentWrapRev", SOURCE_FOLDER, DESTINATION_FOLDER);
195192
}
@@ -347,7 +344,6 @@ public void colGapRemTest() throws IOException, InterruptedException {
347344
}
348345

349346
@Test
350-
// TODO DEVSIX-9473 Fix issues on page split
351347
public void colGapAlignContentTest() throws IOException, InterruptedException {
352348
convertToPdfAndCompare("colGapAlignContent", SOURCE_FOLDER, DESTINATION_FOLDER);
353349
}
@@ -459,7 +455,6 @@ public void rowGapWrapTest() throws IOException, InterruptedException {
459455
}
460456

461457
@Test
462-
// TODO DEVSIX-9473 Fix issues on page split
463458
public void rowGapAlignContentTest() throws IOException, InterruptedException {
464459
convertToPdfAndCompare("rowGapAlignContent", SOURCE_FOLDER, DESTINATION_FOLDER);
465460
}

0 commit comments

Comments
 (0)