Package megameklab.printing
Class InventoryWriter
java.lang.Object
megameklab.printing.InventoryWriter
Formats text for the record sheet's "Weapons and Equipment Inventory" section. For most units, an instance is created
for the sheet using
InventoryWriter(PrintEntity, SVGRectElement), then the text is added to the SVG document
using writeEquipment(). This adds the appropriate header, for the unit, equipment table, and
quirks/features/ammo at the bottom of the space. Large craft can have multiple sections and should invoke the
appropriate section writers, using each return value for the vertical placement of the next section. Multipage record
sheets can instantiate using InventoryWriter(PrintEntity) to process the equipment and find the size of each
section, then call setRegion(SVGRectElement) for each page before calling the section writers.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatThe amount of space between lines, as a factor of the font height determined byFontMetrics -
Constructor Summary
ConstructorsConstructorDescriptionInventoryWriter(PrintEntity sheet) Creates a new instance, determines column positions, and parses equipment.InventoryWriter(PrintEntity sheet, org.w3c.dom.svg.SVGRectElement svgRect) -
Method Summary
Modifier and TypeMethodDescriptionintintextraCapitalBayLines(float fontSize) Calculates the number of additional lines required to print the capital scale weapon bay block due to wrapping long names to another line.intextraStandardBayLines(float fontSize) Calculates the number of additional lines required to print the standard scale weapon bay block due to wrapping long names to another line.intfooterLines(float fontSize) doubleprintAR10Block(float fontSize, double lineHeight, double currY) Adds a static table showing the details of the types of AR10 missiles.doubleprintBayInfo(float fontSize, double lineHeight, double currY) Convenience method for printing information related to cargo and transport bays.doubleprintGravityDecks(megamek.common.units.Jumpship ship, float fontSize, double lineHeight, double currY) Prints the gravity deck blockdoubleprintReverseSideMessage(double lineHeight, double currY) Add single line of text explaining where to find the standard scale bays for ships that cannot fit both capital and standard on the obverse.float[]If the lines do not fit in the available space, we will need to reduce the font size and possible the amount of space between lines.float[]Rescales text to allow space for a fixed number of lines using the entire region.voidsetRegion(org.w3c.dom.svg.SVGRectElement svgRect) Recalculates column positions for a new pageintdoubleintdoublewriteCapitalBays(float fontSize, double lineHeight, double currY) Adds the text for the capital scale weapon bays.voidvoidwriteFooterBlock(float fontSize, float lineHeight) Displays ammo, fuel, features, and quirks as free-flowing text at the bottom of the inventory boxdoublewriteStandardBays(float fontSize, double lineHeight, double currY) Adds the text for the standard scale weapon bays.
-
Field Details
-
MIN_LINE_SPACING
public static final float MIN_LINE_SPACINGThe amount of space between lines, as a factor of the font height determined byFontMetrics- See Also:
-
-
Constructor Details
-
InventoryWriter
Creates a new instance, determines column positions, and parses equipment.- Parameters:
sheet- The record sheet layout instance
-
InventoryWriter
-
-
Method Details
-
setRegion
public void setRegion(org.w3c.dom.svg.SVGRectElement svgRect) Recalculates column positions for a new page- Parameters:
svgRect- The bounding rectangle of the print region
-
startingY
public double startingY() -
capitalBayLines
public int capitalBayLines() -
extraCapitalBayLines
public int extraCapitalBayLines(float fontSize) Calculates the number of additional lines required to print the capital scale weapon bay block due to wrapping long names to another line.- Parameters:
fontSize- The font size used to print- Returns:
- The number of extra lines required by the table
-
extraStandardBayLines
public int extraStandardBayLines(float fontSize) Calculates the number of additional lines required to print the standard scale weapon bay block due to wrapping long names to another line.- Parameters:
fontSize- The font size used to print- Returns:
- The number of extra lines required by the table
-
transportBayLines
public int transportBayLines()- Returns:
- The size of the transport bay block, not including header
-
standardBayLines
public int standardBayLines() -
writeEquipment
public void writeEquipment() -
writeStandardBays
public double writeStandardBays(float fontSize, double lineHeight, double currY) Adds the text for the standard scale weapon bays.- Parameters:
fontSize- The size of font to size for the table textlineHeight- The amount to increase the y coordinate for each linecurrY- The starting y coordinate- Returns:
- The y coordinate of the bottom of the table
-
writeCapitalBays
public double writeCapitalBays(float fontSize, double lineHeight, double currY) Adds the text for the capital scale weapon bays.- Parameters:
fontSize- The size of font to size for the table textlineHeight- The amount to increase the y coordinate for each linecurrY- The starting y coordinate- Returns:
- The y coordinate of the bottom of the table
-
scaleText
Rescales text to allow space for a fixed number of lines using the entire region. Used for large craft, which have a number of possible block types and may need a second page.- Parameters:
calcLines- A supplier for the number of lines. Since reducing the font size may allow for fewer lines, the supplier gives an opportunity to recalculate after each resizing.- Returns:
- A tuple of the new font height and line height, in that order
-
scaleText
If the lines do not fit in the available space, we will need to reduce the font size and possible the amount of space between lines. We first try to reduce the line spacing factor until a certain threshold, and if it fails we start an alternate cycle of attempts between font size and line spacing reduction.- Parameters:
height- The height of the region the text needs to fit incalcLines- A supplier for the number of lines. Since reducing the font size may allow for fewer lines, the supplier gives an opportunity to recalculate after each resizing.- Returns:
- A tuple of the new font height and line height, in that order
-
printAR10Block
public double printAR10Block(float fontSize, double lineHeight, double currY) Adds a static table showing the details of the types of AR10 missiles.- Parameters:
fontSize- The font size to use for the table rowslineHeight- The height of each table rowcurrY- The y coordinate of the top of the table- Returns:
- The y coordinate of the bottom of the table
-
printGravityDecks
public double printGravityDecks(megamek.common.units.Jumpship ship, float fontSize, double lineHeight, double currY) Prints the gravity deck block- Parameters:
ship- The jumpship, warship, or space stationfontSize- The font size to use for the table rowslineHeight- The height of each table rowcurrY- The y coordinate of the top of the table- Returns:
- The y coordinate of the bottom of the table
-
printBayInfo
public double printBayInfo(float fontSize, double lineHeight, double currY) Convenience method for printing information related to cargo and transport bays.- Parameters:
fontSize- The font size to use for the table rowslineHeight- The height of each table rowcurrY- The y coordinate of the top of the table- Returns:
- The y coordinate of the bottom of the table
-
printReverseSideMessage
public double printReverseSideMessage(double lineHeight, double currY) Add single line of text explaining where to find the standard scale bays for ships that cannot fit both capital and standard on the obverse.- Parameters:
lineHeight- The height of each table rowcurrY- The y coordinate of the top of the table- Returns:
- The y coordinate of the bottom of the table
-