Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1068: Handling null source image document creation issues #1070

Merged
merged 3 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions megameklab/src/megameklab/printing/PrintAero.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ public PrintAero(Aero aero, int startPage, RecordSheetOptions options) {
this.aero = aero;
}

/**
* Creates an SVG object for the record sheet using the global printing options
*
* @param aero The aerospace unit to print
* @param startPage The print job page number for this sheet
*/
public PrintAero(Aero aero, int startPage) {
this(aero, startPage, new RecordSheetOptions());
}

@Override
protected String getSVGFileName(int pageNumber) {
if (aero instanceof SmallCraft) {
Expand Down Expand Up @@ -332,4 +322,4 @@ protected void addReferenceCharts(PageFormat pageFormat) {
height * 0.5 - 3.0));
}
}
}
}
11 changes: 0 additions & 11 deletions megameklab/src/megameklab/printing/PrintBattleArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ public PrintBattleArmor(BattleArmor battleArmor, int squadIndex, int startPage,
this.squadIndex = squadIndex;
}

/**
* Creates an SVG object for the record sheet using the global printing options
*
* @param battleArmor The BattleArmor to print
* @param squadIndex The index of this unit on the page
* @param startPage The print job page number for this sheet
*/
public PrintBattleArmor(BattleArmor battleArmor, int squadIndex, int startPage) {
this(battleArmor, startPage, squadIndex, new RecordSheetOptions());
}

@Override
protected String getSVGFileName(int pageNumber) {
return "battle_armor_squad.svg";
Expand Down
43 changes: 26 additions & 17 deletions megameklab/src/megameklab/printing/PrintCompositeTankSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public List<String> getBookmarkNames() {
}

@Override
Document loadTemplate(int pageIndex, PageFormat pageFormat) {
protected @Nullable Document loadTemplate(int pageIndex, PageFormat pageFormat) {
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
Document doc = domImpl.createDocument(svgNS, SVGConstants.SVG_SVG_TAG, null);
Element svgRoot = doc.getDocumentElement();
Expand All @@ -94,31 +94,40 @@ protected void processImage(int startPage, PageFormat pageFormat) {
double ratio = includeReferenceCharts() ? TABLE_RATIO : 1.0;
RecordSheetOptions subOptions = new RecordSheetOptions(options);
subOptions.setReferenceCharts(false);
Element g;

// First Sheet
PrintRecordSheet sheet = new PrintTank(tank1, getFirstPage(), subOptions);
sheet.createDocument(startPage, pageFormat, false);
Element g = getSVGDocument().createElementNS(svgNS, SVGConstants.SVG_G_TAG);
g.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE,
String.format("%s(%f 0 0 %f %f %f)", SVGConstants.SVG_MATRIX_VALUE,
ratio, ratio, pageFormat.getImageableX(), pageFormat.getImageableY()));
sheet.hideElement(FOOTER);
g.appendChild(getSVGDocument().importNode(sheet.getSVGDocument().getDocumentElement(), true));
getSVGDocument().getDocumentElement().appendChild(g);
if (sheet.createDocument(startPage, pageFormat, false)) {
g = getSVGDocument().createElementNS(svgNS, SVGConstants.SVG_G_TAG);
g.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE,
String.format("%s(%f 0 0 %f %f %f)", SVGConstants.SVG_MATRIX_VALUE, ratio,
ratio, pageFormat.getImageableX(), pageFormat.getImageableY()));
sheet.hideElement(FOOTER);
g.appendChild(getSVGDocument().importNode(sheet.getSVGDocument().getDocumentElement(), true));
getSVGDocument().getDocumentElement().appendChild(g);
}

// Second Sheet
if (tank2 != null) {
sheet = new PrintTank(tank2, getFirstPage(), subOptions);
} else if (tank1 instanceof VTOL) {
sheet = new VTOLTables(options);
} else {
sheet = new TankTables(options);
}
sheet.createDocument(startPage, pageFormat, false);
g = getSVGDocument().createElementNS(svgNS, SVGConstants.SVG_G_TAG);
g.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE,
String.format("%s(%f 0 0 %f %f %f)", SVGConstants.SVG_MATRIX_VALUE,
ratio, ratio, pageFormat.getImageableX(),
pageFormat.getImageableY() + pageFormat.getImageableHeight() * 0.5 * ratio));
g.appendChild(getSVGDocument().importNode(sheet.getSVGDocument().getDocumentElement(), true));
getSVGDocument().getDocumentElement().appendChild(g);

if (sheet.createDocument(startPage, pageFormat, false)) {
g = getSVGDocument().createElementNS(svgNS, SVGConstants.SVG_G_TAG);
g.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE,
String.format("%s(%f 0 0 %f %f %f)", SVGConstants.SVG_MATRIX_VALUE, ratio,
ratio, pageFormat.getImageableX(),
pageFormat.getImageableY() + pageFormat.getImageableHeight() * 0.5 * ratio));
g.appendChild(getSVGDocument().importNode(sheet.getSVGDocument().getDocumentElement(), true));
getSVGDocument().getDocumentElement().appendChild(g);
}

// Reference Charts
if (includeReferenceCharts()) {
addReferenceCharts(pageFormat);
}
Expand Down
31 changes: 14 additions & 17 deletions megameklab/src/megameklab/printing/PrintEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* MegaMekLab - Copyright (C) 2017 - The MegaMek Team
* MegaMekLab - Copyright (c) 2017-2022 - The MegaMek Team. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
Expand All @@ -13,16 +13,12 @@
*/
package megameklab.printing;

import java.awt.geom.Rectangle2D;
import java.awt.print.PageFormat;
import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;

import megamek.client.generator.RandomNameGenerator;
import megamek.common.*;
import megameklab.printing.reference.ReferenceTable;
import megamek.common.options.IOption;
import megamek.common.options.IOptionGroup;
import megamek.common.options.PilotOptions;
import megamek.common.options.Quirks;
import megameklab.util.CConfig;
import org.apache.batik.anim.dom.SVGGraphicsElement;
import org.apache.batik.anim.dom.SVGLocatableSupport;
Expand All @@ -32,16 +28,17 @@
import org.w3c.dom.svg.SVGRectElement;
import org.w3c.dom.svg.SVGTextContentElement;

import megamek.common.options.IOption;
import megamek.common.options.IOptionGroup;
import megamek.common.options.PilotOptions;
import megamek.common.options.Quirks;
import java.awt.geom.Rectangle2D;
import java.awt.print.PageFormat;
import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;

/**
* Base class for printing Entity record sheets
*
* @author Neoancient
*
*/
public abstract class PrintEntity extends PrintRecordSheet {

Expand Down Expand Up @@ -252,7 +249,7 @@ protected void writeTextFields() {
if (null != element) {
double offset = nameOffset;
String prev = element.getAttribute(SVGConstants.SVG_X_ATTRIBUTE);
if (null != prev) {
if (!prev.isBlank()) {
offset += Double.parseDouble(prev);
} else {
offset += ((SVGTextContentElement) element).getStartPositionOfChar(0).getX();
Expand Down Expand Up @@ -282,7 +279,7 @@ protected void writeTextFields() {
if (rect instanceof SVGRectElement) {
Rectangle2D bbox = getRectBBox((SVGRectElement) rect);
Element canvas = (Element) rect.getParentNode();
String spaText = "Abilities: " + spaList.toString();
String spaText = "Abilities: " + spaList;
float fontSize = FONT_SIZE_MEDIUM;
if (getTextLength(spaText, fontSize) > bbox.getWidth()) {
fontSize = (float) bbox.getHeight() / 2.4f;
Expand Down Expand Up @@ -508,7 +505,7 @@ void drawHeatSinkPips(SVGRectElement svgRect, int hsCount) {
// First check whether we can shrink them less than what is required for a new column
if (cols * (int) (rows * nextCol) > hsCount) {
rows = (int) Math.ceil((double) hsCount / cols);
size = (double) viewHeight / rows;
size = viewHeight / rows;
} else {
cols++;
size *= viewWidth / (cols * size);
Expand Down
13 changes: 1 addition & 12 deletions megameklab/src/megameklab/printing/PrintInfantry.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*/

package megameklab.printing;

import megamek.common.*;
Expand Down Expand Up @@ -48,16 +47,6 @@ public PrintInfantry(Infantry infantry, int startPage, RecordSheetOptions option
this.infantry = infantry;
}

/**
* Creates an SVG object for the record sheet using the global printing options
*
* @param infantry The infantry to print
* @param startPage The print job page number for this sheet
*/
public PrintInfantry(Infantry infantry, int startPage) {
this(infantry, startPage, new RecordSheetOptions());
}

@Override
protected String getSVGFileName(int pageNumber) {
return "conventional_infantry_platoon.svg";
Expand Down Expand Up @@ -368,7 +357,7 @@ protected void drawArmor() {
sj.add("ECM");
}
if (sj.length() > 0) {
setTextField(ARMOR_KIT, "Sneak(" + sj.toString() + ")");
setTextField(ARMOR_KIT, "Sneak(" + sj + ")");
}
}
setTextField(ARMOR_DIVISOR, infantry.calcDamageDivisor()
Expand Down
10 changes: 0 additions & 10 deletions megameklab/src/megameklab/printing/PrintMech.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ public PrintMech(Mech mech, int startPage, RecordSheetOptions options) {
this.mech = mech;
}

/**
* Creates an SVG object for the record sheet using the global printing options
*
* @param mech The mech to print
* @param startPage The print job page number for this sheet
*/
public PrintMech(Mech mech, int startPage) {
this(mech, startPage, new RecordSheetOptions());
}

@Override
protected String getSVGFileName(int pageNumber) {
String base;
Expand Down
11 changes: 0 additions & 11 deletions megameklab/src/megameklab/printing/PrintProtomech.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ public PrintProtomech(Protomech proto, int startPage, int unitIndex, RecordSheet
this.unitIndex = unitIndex;
}

/**
* Creates an SVG object for the record sheet using the global printing options
*
* @param proto The protomech to print
* @param startPage The print job page number for this sheet
* @param unitIndex The index of this unit on the page
*/
public PrintProtomech(Protomech proto, int startPage, int unitIndex) {
this(proto, startPage, unitIndex, new RecordSheetOptions());
}

@Override
protected String getSVGFileName(int pageNumber) {
if (proto.isQuad()) {
Expand Down
Loading