/** * Describes the physical output characteristics like page size, margins, and imaginable area. * * @return */ public PageFormat getPageFormat() { if ( pageDefinition == null ) { return new PageFormat(); } final PageFormat pageFormat = pageDefinition.getPageFormat(); final Paper orgPaper = pageFormat.getPaper(); final PageFormatFactory pff = PageFormatFactory.getInstance(); final double virtualPaperWidth = orgPaper.getImageableWidth() + pff.getLeftBorder( orgPaper ) + pff.getRightBorder( orgPaper ); final double virtualPaperHeight = orgPaper.getImageableHeight() + pff.getTopBorder( orgPaper ) + pff.getBottomBorder( orgPaper ); final Paper p = pff.createPaper( virtualPaperWidth, virtualPaperHeight ); pff.setBorders( p, pff.getTopBorder( orgPaper ), pff.getLeftBorder( orgPaper ), pff.getBottomBorder( orgPaper ), pff.getRightBorder( orgPaper ) ); return pff.createPageFormat( p, pageFormat.getOrientation() ); }
/** * Returns a single instance of the factory. * * @return an instance of a PageFormatFactory. */ public static synchronized PageFormatFactory getInstance() { if ( singleton == null ) { singleton = new PageFormatFactory(); } return singleton; }
/** * Defines the imageable area of the given paper by adjusting the border around the imagable area. The bordersizes are * given in inches. * * @param paper * the paper that should be modified * @param top * the bordersize of the top-border * @param left * the border in points in the left * @param bottom * the border in points in the bottom * @param right * the border in points in the right */ public void setBordersInch( final Paper paper, final double top, final double left, final double bottom, final double right ) { setBorders( paper, convertInchToPoints( top ), convertInchToPoints( left ), convertInchToPoints( bottom ), convertInchToPoints( right ) ); }
public static PageFormat create( final PageSize papersize, final int orientation, final Insets margins ) { final PageFormatFactory instance = PageFormatFactory.getInstance(); final PageFormat pageFormat = instance.createPageFormat( instance.createPaper( papersize ), orientation ); instance.setPageMargins( pageFormat, margins ); return pageFormat; }
/** * Defines the imageable area of the given paper by adjusting the border around the imagable area. The bordersizes are * given in millimeters. * * @param paper * the paper that should be modified * @param top * the bordersize of the top-border * @param left * the border in points in the left * @param bottom * the border in points in the bottom * @param right * the border in points in the right */ public void setBordersMm( final Paper paper, final double top, final double left, final double bottom, final double right ) { setBorders( paper, convertMmToPoints( top ), convertMmToPoints( left ), convertMmToPoints( bottom ), convertMmToPoints( right ) ); }
final Paper p = PageFormatFactory.getInstance().createPaper( pageformatName ); if ( p == null ) { PageDefinitionReadHandler.logger.warn( "Paper size '" + pageformatName + "' is not regognized." ); return defaultPageFormat; return PageFormatFactory.getInstance().createPageFormat( p, orientationVal ); ParserUtil.parseInt( atts.getValue( getUri(), "height" ), "Specified attribute 'height' is not valid", getLocator() ); final Paper p = PageFormatFactory.getInstance().createPaper( pageformatData ); if ( p == null ) { PageDefinitionReadHandler.logger.warn( "Unable to create the requested Paper size with width " return defaultPageFormat; return PageFormatFactory.getInstance().createPageFormat( p, orientationVal );
private void copyPageFormatToFields( final PageFormat pageFormat ) { final Paper paper = pageFormat.getPaper(); final PageFormatFactory pageFormatFactory = PageFormatFactory.getInstance(); final String formatName = pageFormatFactory.getPageFormatName( paper.getWidth(), paper.getHeight() ); pageFormatBox.setSelectedItem( formatName ); pageWidthField.setText( String.valueOf( paper.getWidth() ) ); pageHeightField.setText( String.valueOf( paper.getHeight() ) ); userDefinedPageSizeBox.setSelected( formatName == null ); preDefinedPageSizeBox.setSelected( formatName != null ); final boolean portraitMode = pageFormat.getOrientation() == PageFormat.PORTRAIT; portraitModeBox.setSelected( portraitMode ); landscapeModeBox.setSelected( portraitMode == false ); if ( portraitMode ) { marginLeftField.setText( String.valueOf( pageFormatFactory.getLeftBorder( paper ) ) ); marginTopField.setText( String.valueOf( pageFormatFactory.getTopBorder( paper ) ) ); marginRightField.setText( String.valueOf( pageFormatFactory.getRightBorder( paper ) ) ); marginBottomField.setText( String.valueOf( pageFormatFactory.getBottomBorder( paper ) ) ); } else { marginTopField.setText( String.valueOf( pageFormatFactory.getLeftBorder( paper ) ) ); marginLeftField.setText( String.valueOf( pageFormatFactory.getBottomBorder( paper ) ) ); marginBottomField.setText( String.valueOf( pageFormatFactory.getRightBorder( paper ) ) ); marginRightField.setText( String.valueOf( pageFormatFactory.getTopBorder( paper ) ) ); } }
private SimplePageDefinition createPageDefinition() { final float pageWidth = ParserUtil.parseFloat( pageWidthField.getText(), 0 ); final float pageHeight = ParserUtil.parseFloat( pageHeightField.getText(), 0 ); final int spanHorizontal = ParserUtil.parseInt( spanHorizontalField.getText(), 0 ); final int spanVertical = ParserUtil.parseInt( spanVerticalField.getText(), 0 ); final float marginTop = ParserUtil.parseFloat( marginTopField.getText(), 0 ); final float marginLeft = ParserUtil.parseFloat( marginLeftField.getText(), 0 ); final float marginBottom = ParserUtil.parseFloat( marginBottomField.getText(), 0 ); final float marginRight = ParserUtil.parseFloat( marginRightField.getText(), 0 ); final Paper p = PageFormatFactory.getInstance().createPaper( pageWidth, pageHeight ); final PageFormat pf; if ( portraitModeBox.isSelected() ) { PageFormatFactory.getInstance().setBorders( p, marginTop, marginLeft, marginBottom, marginRight ); pf = PageFormatFactory.getInstance().createPageFormat( p, PageFormat.PORTRAIT ); } else { // noinspection SuspiciousNameCombination PageFormatFactory.getInstance().setBorders( p, marginRight, marginTop, marginLeft, marginBottom ); pf = PageFormatFactory.getInstance().createPageFormat( p, PageFormat.LANDSCAPE ); } return new SimplePageDefinition( pf, spanHorizontal, spanVertical ); } }
final PageFormatFactory fact = PageFormatFactory.getInstance(); final int borderLeft = (int) ( fact.getLeftBorder( paper ) / charWidthPoints ); final int borderRight = (int) ( fact.getRightBorder( paper ) / charWidthPoints ); sendDefineHorizontalBorders( borderLeft, borderRight ); final int borderTop = (int) ( fact.getTopBorder( paper ) / lineHeightPoints );
switch ( format.getOrientation() ) { case PageFormat.PORTRAIT: PageFormatFactory.getInstance().setBorders( p, defTopMargin, defLeftMargin, defBottomMargin, defRightMargin ); break; case PageFormat.REVERSE_LANDSCAPE: PageFormatFactory.getInstance().setBorders( p, defLeftMargin, defBottomMargin, defRightMargin, defTopMargin ); break; case PageFormat.LANDSCAPE: PageFormatFactory.getInstance().setBorders( p, defRightMargin, defTopMargin, defLeftMargin, defBottomMargin ); break; default:
/** * Invoked when an action occurs. */ public void actionPerformed( final ActionEvent e ) { final String selectedItem = (String) pageFormatBox.getSelectedItem(); if ( selectedItem == null ) { return; } final Paper paper = PageFormatFactory.getInstance().createPaper( selectedItem ); if ( paper == null ) { return; } pageWidthField.setText( String.valueOf( paper.getWidth() ) ); pageHeightField.setText( String.valueOf( paper.getHeight() ) ); } }
/** * Resets the printer and starts a new page. Prints the top border lines (if necessary). * * @throws java.io.IOException * if there was an IOError while writing the command */ public void startPage( final Paper paper, final String encoding ) throws IOException { this.defaultEncoding = encoding; if ( firstPage ) { final EncodingUtilities encodingUtilities = getEncodingUtilities( encoding ); out.write( encodingUtilities.getEncodingHeader() ); firstPage = false; } final PageFormatFactory fact = PageFormatFactory.getInstance(); final float charWidthPoints = 72.0f / getCharactersPerInch(); borderLeft = (int) ( fact.getLeftBorder( paper ) / charWidthPoints ); final float lineHeightPoints = 72.0f / getLinesPerInch(); final int borderTop = (int) ( fact.getTopBorder( paper ) / lineHeightPoints ); for ( int i = 0; i < borderTop; i++ ) { startLine(); endLine( false ); } }
final int h = (int) paper.getHeight(); final String pageDefinition = PageFormatFactory.getInstance().getPageFormatName( w, h ); if ( pageDefinition != null ) { retval.setAttribute( BundleNamespaces.STYLE, "pageformat", pageDefinition );
/** * Creates a paper by using the paper size in points found in the int-array. The array must have a length of 2 and the * first value of this array has to contain the width and the second the height parameter. The created Paper has no * ImagableArea defined. * * @param papersize * the definition of the papersize in a 2-element int-array * @return the created paper */ public Paper createPaper( final int[] papersize ) { if ( papersize.length != 2 ) { throw new IllegalArgumentException( "Paper must have a width and a height" ); } return createPaper( (double) papersize[0], (double) papersize[1] ); }
pageFormatBox = new JComboBox( new DefaultComboBoxModel( PageFormatFactory.getInstance().getPageFormats() ) ); pageHeightField = new JTextField(); pageHeightField.setColumns( 5 );
public String[] getPageFormats() { try { final ArrayList a = new ArrayList(); final Field[] fields = PageSize.class.getFields(); for ( int i = 0; i < fields.length; i++ ) { final Field f = fields[i]; if ( Modifier.isPublic( f.getModifiers() ) && Modifier.isStatic( f.getModifiers() ) ) { final Object o = f.get( PageFormatFactory.getInstance() ); if ( o instanceof PageSize ) { a.add( f.getName() ); } } } return (String[]) a.toArray( new String[a.size()] ); } catch ( Exception e ) { PageFormatFactory.logger.warn( "Unable to lookup the page name", e ); } return PageFormatFactory.EMPTY_PAGEFORMATS; }
/** * Creates a 1x1 page defintion. The physical page size is equal to the logical page size. */ public SimplePageDefinition( final PageSize papersize, final int orientation, final Insets margins ) { this( PageFormatFactory.create( papersize, orientation, margins ), 1, 1 ); }
final Paper p = PageFormatFactory.getInstance().createPaper( pageformatName ); if ( p == null ) { PageReadHandler.logger.warn( "Unable to create the requested Paper. " + pageformatName ); return format; return PageFormatFactory.getInstance().createPageFormat( p, orientationVal ); pageformatData[1] = ParserUtil.parseInt( atts.getValue( getUri(), PageReadHandler.HEIGHT_ATT ), "No Height set", getLocator() ); final Paper p = PageFormatFactory.getInstance().createPaper( pageformatData ); if ( p == null ) { PageReadHandler.logger.warn( "Unable to create the requested Paper. Paper={" + pageformatData[0] + ", " return format; return PageFormatFactory.getInstance().createPageFormat( p, orientationVal );
sendDefinePageLengthInLines( lines ); final PageFormatFactory fact = PageFormatFactory.getInstance(); final int borderLeft = (int) ( fact.getLeftBorder( paper ) / charWidthPoints ); final int borderRight = (int) ( fact.getRightBorder( paper ) / charWidthPoints ); final int borderTop = (int) ( fact.getTopBorder( paper ) / lineHeightPoints ); sendDefineHorizontalBorders( borderLeft, borderRight );
switch ( format.getOrientation() ) { case PageFormat.PORTRAIT: PageFormatFactory.getInstance().setBorders( p, defTopMargin, defLeftMargin, defBottomMargin, defRightMargin ); break; case PageFormat.LANDSCAPE: PageFormatFactory.getInstance().setBorders( p, defRightMargin, defTopMargin, defLeftMargin, defBottomMargin ); break; case PageFormat.REVERSE_LANDSCAPE: PageFormatFactory.getInstance().setBorders( p, defLeftMargin, defBottomMargin, defRightMargin, defTopMargin ); break; default: