javax.print.attribute.ResolutionSyntax Java Examples

The following examples show how to use javax.print.attribute.ResolutionSyntax. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestUnsupportedResolution.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void printWorks(String[] args)
{
    PrinterJob job=PrinterJob.getPrinterJob();
    job.setPrintable(this);
    PrintRequestAttributeSet settings=new HashPrintRequestAttributeSet();
    PrinterResolution pr = new PrinterResolution(300, 300, ResolutionSyntax.DPI);
    if (args.length > 0 && (args[0].compareTo("600") == 0)) {
        pr = new PrinterResolution(600, 600, ResolutionSyntax.DPI);
        System.out.println("Adding 600 Dpi attribute");
    } else {
        System.out.println("Adding 300 Dpi attribute");
    }
    PrintService ps = job.getPrintService();
    boolean resolutionSupported = ps.isAttributeValueSupported(pr, null, null);
    System.out.println("Is "+pr+" supported by "+ps+"?    "+resolutionSupported);
    if (resolutionSupported) {
        System.out.println("Resolution is supported.\nTest is not applicable, PASSED");
    }
    settings.add(pr);
    if (args.length > 0 && (args[0].equalsIgnoreCase("fidelity"))) {
        settings.add(Fidelity.FIDELITY_TRUE);
        System.out.println("Adding Fidelity.FIDELITY_TRUE attribute");
   }

   if (job.printDialog(settings))
   {
        try {
            job.print(settings);
        } catch (PrinterException e) {
            e.printStackTrace();
        }
    }
}
 
Example #2
Source File: PageSetupPanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private static String generateResolutionTitle(PrinterResolution res) {
    StringBuilder buffer = new StringBuilder();
    int           x      = res.getCrossFeedResolution(ResolutionSyntax.DPI);
    int           y      = res.getFeedResolution(ResolutionSyntax.DPI);

    buffer.append(Integer.toString(x));
    if (x != y) {
        buffer.append(" x ");
        buffer.append(Integer.toString(y));
    }
    buffer.append(I18n.Text(" dpi"));
    return buffer.toString();
}
 
Example #3
Source File: DimensionUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Validates the dpi value. If the value is invalid, try to use the JVM
 * defined value and model defined default value.
 * 
 * @param dpi
 *            the dpi value
 * @return the validated dpi value
 */
private static int validateDPI( int dpi )
{
	if ( dpi <= 0 )
		// Try to use JVM defined value if the dpi value is invalid.
		dpi = ResolutionSyntax.DPI;
	if ( dpi <= 0 )
		// Use the default value if the JVM defined is invalid.
		dpi = DEFAULT_DPI;
	return dpi;
}
 
Example #4
Source File: DimensionUtilTest.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Tests for dimension merging.
 */
public void testMerge( ) throws Exception
{
	DimensionValue in = DimensionValue.parse( "1in" );
	DimensionValue cm = DimensionValue.parse( "1cm" );
	DimensionValue mm = DimensionValue.parse( "10mm" );
	DimensionValue percentage = DimensionValue.parse( "25%" );
	DimensionValue px = DimensionValue.parse( "10px" );
	DimensionValue ex = DimensionValue.parse( "10ex" );

	// Merge between same absolute unit.
	assertEquals( "2in", DimensionUtil.mergeDimension( in, in ).toString( ) );
	assertEquals( "2cm", DimensionUtil.mergeDimension( cm, cm ).toString( ) );
	assertEquals( "20mm", DimensionUtil.mergeDimension( mm, mm ).toString( ) );
	// Merge between different absolute units.
	assertEquals( "2cm", DimensionUtil.mergeDimension( cm, mm ).toString( ) );
	assertEquals( "20mm", DimensionUtil.mergeDimension( mm, cm ).toString( ) );
	// Merge between same relative unit.
	assertEquals( "50%", DimensionUtil.mergeDimension( percentage,
			percentage ).toString( ) );
	assertEquals( "20px", DimensionUtil.mergeDimension( px, px ).toString( ) );
	assertEquals( "20ex", DimensionUtil.mergeDimension( ex, ex ).toString( ) );
	// Merge between absolute unit and pixel
	assertEquals( "2in", DimensionUtil.mergeDimension( in, px, 10 )
			.toString( ) );
	if ( ResolutionSyntax.DPI > 0 )
	{
		// Try default dpi value
		assertEquals( DimensionUtil.mergeDimension( px, in,
				ResolutionSyntax.DPI ).toString( ), DimensionUtil
				.mergeDimension( px, in ).toString( ) );
	}
	// Merge between different relative unit.
	assertNull( DimensionUtil.mergeDimension( percentage, ex ) );
	assertNull( DimensionUtil.mergeDimension( percentage, px ) );
	assertNull( DimensionUtil.mergeDimension( px, ex ) );
	// Merge between absolute unit and relative unit.
	assertNull( DimensionUtil.mergeDimension( cm, percentage ) );
	assertNull( DimensionUtil.mergeDimension( cm, ex ) );
	assertNull( DimensionUtil.mergeDimension( mm, percentage ) );
	assertNull( DimensionUtil.mergeDimension( mm, ex ) );
}