Skip to content

Commit

Permalink
GFOpPathPaint and GFOpTextShow refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Nov 17, 2023
1 parent e3b102d commit a761271
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public abstract class GFOpFillAndStroke extends GFOpPathPaint {

protected GFOpFillAndStroke(List<COSBase> arguments, final GraphicState state,
final PDResourcesHandler resourcesHandler, final String opType) {
super(arguments, state, resourcesHandler, opType);
super(arguments, state.isProcessColorOperators(), opType);
this.fillCS = getColorSpace(state, resourcesHandler, state.getFillColorSpace(),
state.isOverprintingFlagNonStroke());
this.strokeCS = getColorSpace(state, resourcesHandler, state.getStrokeColorSpace(),
state.isOverprintingFlagStroke());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
public abstract class GFOpFillPaint extends GFOpPathPaint {

protected GFOpFillPaint(List<COSBase> arguments, final GraphicState state,
final PDResourcesHandler resources, final String opType) {
super(arguments, state, resources, opType);
final PDResourcesHandler resourcesHandler, final String opType) {
super(arguments, state.isProcessColorOperators(), opType);
this.fillCS = getColorSpace(state, resourcesHandler, state.getFillColorSpace(),
state.isOverprintingFlagNonStroke());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,84 +43,47 @@ public abstract class GFOpPathPaint extends GFOperator implements OpPathPaint {
/** Name of link to the fill color space */
public static final String FILL_CS = "fillCS";

private final PDColorSpace rawFillColorSpace;
private final PDColorSpace rawStrokeColorSpace;
protected org.verapdf.model.pdlayer.PDColorSpace fillCS;
protected org.verapdf.model.pdlayer.PDColorSpace strokeCS;

private final int opm;
private final boolean overprintingFlagStroke;
private final boolean overprintingFlagNonStroke;
private final boolean isProcessColorOperators;

private final PDResourcesHandler resourcesHandler;
private final GraphicState inheritedGraphicState;

private List<org.verapdf.model.pdlayer.PDColorSpace> fillCS = null;
private List<org.verapdf.model.pdlayer.PDColorSpace> strokeCS = null;

protected GFOpPathPaint(List<COSBase> arguments, final GraphicState state,
final PDResourcesHandler resourcesHandler, final String operatorType) {
this(arguments, state.getFillColorSpace(), state.getStrokeColorSpace(),
state.getOpm(), state.isOverprintingFlagStroke(), state.isOverprintingFlagNonStroke(),
resourcesHandler, state, operatorType);
}

protected GFOpPathPaint(List<COSBase> arguments,
final PDColorSpace rawFillColorSpace, final PDColorSpace rawStrokeColorSpace,
int opm, boolean overprintingFlagStroke, boolean overprintingFlagNonStroke,
final PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState,
final String operatorType) {
protected GFOpPathPaint(List<COSBase> arguments, boolean isProcessColorOperators, final String operatorType) {
super(arguments, operatorType);
this.rawFillColorSpace = rawFillColorSpace;
this.rawStrokeColorSpace = rawStrokeColorSpace;
this.opm = opm;
this.overprintingFlagStroke = overprintingFlagStroke;
this.overprintingFlagNonStroke = overprintingFlagNonStroke;
this.resourcesHandler = resourcesHandler;
this.inheritedGraphicState = inheritedGraphicState;
this.isProcessColorOperators = isProcessColorOperators;
}

protected List<org.verapdf.model.pdlayer.PDColorSpace> getFillCS() {
if (!this.inheritedGraphicState.isProcessColorOperators()) {
return Collections.emptyList();
}
if (this.fillCS == null) {
this.fillCS = getColorSpace(this.rawFillColorSpace, this.overprintingFlagNonStroke);
if (this.fillCS != null && isProcessColorOperators) {
List<org.verapdf.model.pdlayer.PDColorSpace> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(fillCS);
return Collections.unmodifiableList(list);
}
return this.fillCS;
return Collections.emptyList();
}

protected List<org.verapdf.model.pdlayer.PDColorSpace> getStrokeCS() {
if (!this.inheritedGraphicState.isProcessColorOperators()) {
return Collections.emptyList();
}
if (this.strokeCS == null) {
this.strokeCS = getColorSpace(this.rawStrokeColorSpace, this.overprintingFlagStroke);
if (this.strokeCS != null && isProcessColorOperators) {
List<org.verapdf.model.pdlayer.PDColorSpace> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(strokeCS);
return Collections.unmodifiableList(list);
}
return this.strokeCS;
return Collections.emptyList();
}

public org.verapdf.model.pdlayer.PDColorSpace getVeraFillCS() {
if (this.fillCS == null) {
this.fillCS = getColorSpace(this.rawFillColorSpace, this.overprintingFlagNonStroke);
}
return this.fillCS.isEmpty() ? null : this.fillCS.get(0);
return this.fillCS;
}

public org.verapdf.model.pdlayer.PDColorSpace getVeraStrokeCS() {
if (this.strokeCS == null) {
this.strokeCS = getColorSpace(this.rawStrokeColorSpace, this.overprintingFlagStroke);
}
return this.strokeCS.isEmpty() ? null : this.strokeCS.get(0);
return this.strokeCS;
}

private List<org.verapdf.model.pdlayer.PDColorSpace> getColorSpace(PDColorSpace rawColorSpace, boolean op) {
org.verapdf.model.pdlayer.PDColorSpace veraColorSpace =
ColorSpaceFactory.getColorSpace(rawColorSpace, this.resourcesHandler, this.opm, op, inheritedGraphicState);
if (veraColorSpace != null) {
List<org.verapdf.model.pdlayer.PDColorSpace> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(veraColorSpace);
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
protected org.verapdf.model.pdlayer.PDColorSpace getColorSpace(GraphicState inheritedGraphicState,
PDResourcesHandler resourcesHandler,
PDColorSpace rawColorSpace, boolean op) {
return ColorSpaceFactory.getColorSpace(rawColorSpace, resourcesHandler, inheritedGraphicState.getOpm(), op,
inheritedGraphicState);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
public abstract class GFOpStrokePaint extends GFOpPathPaint {

protected GFOpStrokePaint(List<COSBase> arguments, final GraphicState state,
final PDResourcesHandler resources, final String operatorType) {
super(arguments, state, resources, operatorType);
final PDResourcesHandler resourcesHandler, final String operatorType) {
super(arguments, state.isProcessColorOperators(), operatorType);
this.strokeCS = getColorSpace(state, resourcesHandler, state.getStrokeColorSpace(),
state.isOverprintingFlagStroke());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
/**
* @author Timur Kamalov
*/
public class GFOp_B_fill_stroke extends GFOpFillAndStroke
implements Op_B_fill_stroke {
public class GFOp_B_fill_stroke extends GFOpFillAndStroke implements Op_B_fill_stroke {

/** Type name for {@code GFOp_B_fill_stroke} */
public static final String OP_B_FILL_STROKE_TYPE = "Op_B_fill_stroke";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class GFOp_n extends GFOpPathPaint implements Op_n {
public static final String OP_N_TYPE = "Op_n";

public GFOp_n(List<COSBase> arguments) {
super(arguments, null, null, 0, false, false, null, null, OP_N_TYPE);
super(arguments, false, OP_N_TYPE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.verapdf.model.operator.Glyph;
import org.verapdf.model.operator.OpTextShow;
import org.verapdf.model.pdlayer.PDFont;
import org.verapdf.pd.colors.PDColorSpace;
import org.verapdf.pd.font.FontProgram;
import org.verapdf.pd.font.cff.CFFFontProgram;
import org.verapdf.pd.structure.StructureElementAccessObject;
Expand Down Expand Up @@ -70,43 +69,34 @@ public abstract class GFOpTextShow extends GFOperator implements OpTextShow {
*/
public static final String STROKE_COLOR_SPACE = "strokeCS";

private final PDColorSpace rawFillColorSpace;
private final PDColorSpace rawStrokeColorSpace;

private final org.verapdf.pd.font.PDFont font;
private final Double scaleFactor;

private final RenderingMode renderingMode;

private final int opm;
private final boolean overprintingFlagStroke;
private final boolean overprintingFlagNonStroke;
private final GraphicState inheritedGraphicState;

private final PDResourcesHandler resourcesHandler;
private final GFOpMarkedContent markedContent;
private final StructureElementAccessObject structureElementAccessObject;

private List<PDFont> fonts = null;
private List<org.verapdf.model.pdlayer.PDColorSpace> fillCS = null;
private List<org.verapdf.model.pdlayer.PDColorSpace> strokeCS = null;
private final org.verapdf.model.pdlayer.PDColorSpace fillCS;
private final org.verapdf.model.pdlayer.PDColorSpace strokeCS;

protected GFOpTextShow(List<COSBase> arguments, GraphicState state, PDResourcesHandler resourcesHandler,
GFOpMarkedContent markedContent, StructureElementAccessObject structureElementAccessObject,
final String opType) {
super(arguments, opType);
this.rawFillColorSpace = state.getFillColorSpace();
this.rawStrokeColorSpace = state.getStrokeColorSpace();
this.font = state.getFont();
this.scaleFactor = state.getScaleFactor();
this.renderingMode = state.getRenderingMode();
this.opm = state.getOpm();
this.overprintingFlagStroke = state.isOverprintingFlagStroke();
this.overprintingFlagNonStroke = state.isOverprintingFlagNonStroke();
this.resourcesHandler = resourcesHandler;
this.markedContent = markedContent;
this.inheritedGraphicState = state;
this.structureElementAccessObject = structureElementAccessObject;
this.fillCS = parseFillColorSpace();
this.strokeCS = parseStrokeColorSpace();
}

@Override
Expand Down Expand Up @@ -173,42 +163,33 @@ private List<Glyph> getUsedGlyphs() {
}

private List<org.verapdf.model.pdlayer.PDColorSpace> getFillColorSpace() {
if (!inheritedGraphicState.isProcessColorOperators()) {
return Collections.emptyList();
}
if (this.fillCS == null) {
this.fillCS = parseFillColorSpace();
if (inheritedGraphicState.isProcessColorOperators() && this.fillCS != null) {
List<org.verapdf.model.pdlayer.PDColorSpace> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(fillCS);
return Collections.unmodifiableList(list);
}
return this.fillCS;
return Collections.emptyList();
}

private List<org.verapdf.model.pdlayer.PDColorSpace> getStrokeColorSpace() {
if (!inheritedGraphicState.isProcessColorOperators()) {
return Collections.emptyList();
}
if (this.strokeCS == null) {
this.strokeCS = parseStrokeColorSpace();
if (inheritedGraphicState.isProcessColorOperators() && this.strokeCS != null) {
List<org.verapdf.model.pdlayer.PDColorSpace> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(strokeCS);
return Collections.unmodifiableList(list);
}
return this.strokeCS;
return Collections.emptyList();
}

public org.verapdf.model.pdlayer.PDColorSpace getVeraModelFillColorSpace() {
if (this.fillCS == null) {
this.fillCS = parseFillColorSpace();
}
return this.fillCS.isEmpty() ? null : this.fillCS.get(0);
return this.fillCS;
}

public org.verapdf.model.pdlayer.PDColorSpace getVeraModelStrokeColorSpace() {
if (this.strokeCS == null) {
this.strokeCS = parseStrokeColorSpace();
}
return this.strokeCS.isEmpty() ? null : this.strokeCS.get(0);
return this.strokeCS;
}

private List<PDFont> parseFont() {
PDFont font = FontFactory.parseFont(this.font, renderingMode,
this.resourcesHandler, this.inheritedGraphicState);
PDFont font = FontFactory.parseFont(this.font, renderingMode, this.resourcesHandler, this.inheritedGraphicState);
if (font != null) {
List<PDFont> result = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
result.add(font);
Expand All @@ -217,30 +198,26 @@ private List<PDFont> parseFont() {
return Collections.emptyList();
}

private List<org.verapdf.model.pdlayer.PDColorSpace> parseFillColorSpace() {
if (this.renderingMode.isFill()) {
return this.getColorSpace(this.rawFillColorSpace, this.overprintingFlagNonStroke);
private org.verapdf.model.pdlayer.PDColorSpace parseFillColorSpace() {
if (inheritedGraphicState.getRenderingMode().isFill()) {
return this.getColorSpace(inheritedGraphicState.getFillColorSpace(),
inheritedGraphicState.isOverprintingFlagNonStroke());
}
return Collections.emptyList();
return null;
}

private List<org.verapdf.model.pdlayer.PDColorSpace> parseStrokeColorSpace() {
if (this.renderingMode.isStroke()) {
return this.getColorSpace(this.rawStrokeColorSpace, this.overprintingFlagStroke);
private org.verapdf.model.pdlayer.PDColorSpace parseStrokeColorSpace() {
if (inheritedGraphicState.getRenderingMode().isStroke()) {
return this.getColorSpace(inheritedGraphicState.getStrokeColorSpace(),
inheritedGraphicState.isOverprintingFlagStroke());
}
return Collections.emptyList();
return null;
}

private List<org.verapdf.model.pdlayer.PDColorSpace> getColorSpace(org.verapdf.pd.colors.PDColorSpace rawColorSpace,
private org.verapdf.model.pdlayer.PDColorSpace getColorSpace(org.verapdf.pd.colors.PDColorSpace rawColorSpace,
boolean op) {
org.verapdf.model.pdlayer.PDColorSpace veraColorSpace = ColorSpaceFactory.getColorSpace(rawColorSpace,
this.resourcesHandler, this.opm, op, inheritedGraphicState);
if (veraColorSpace != null) {
List<org.verapdf.model.pdlayer.PDColorSpace> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(veraColorSpace);
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
return ColorSpaceFactory.getColorSpace(rawColorSpace, this.resourcesHandler, inheritedGraphicState.getOpm(), op,
inheritedGraphicState);
}

/**
Expand Down

0 comments on commit a761271

Please sign in to comment.