当前位置: 首页>>代码示例>>Java>>正文


Java Size2DSyntax类代码示例

本文整理汇总了Java中javax.print.attribute.Size2DSyntax的典型用法代码示例。如果您正苦于以下问题:Java Size2DSyntax类的具体用法?Java Size2DSyntax怎么用?Java Size2DSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Size2DSyntax类属于javax.print.attribute包,在下文中一共展示了Size2DSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doTest

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:WrongPaperPrintingTest.java

示例2: setMediaSize

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
/**
 * Set Media Size
 * @param x the value to which to set this <code>Paper</code> object's width
 * @param y the value to which to set this <code>Paper</code> object's height
 * @param units number of microns (see Size2DSyntax.INCH, Size2DSyntax.MM)
 * @param landscape true if it's landscape format
 * @see Paper#setSize(double, double)
 */
public void setMediaSize (double x, double y, int units, boolean landscape)
{
	if (x == 0 || y == 0)
		throw new IllegalArgumentException("MediaSize is null");
	
	m_landscape = landscape;

	//	Get Sise in Inch * 72
	final double mult = (double)units / (double)Size2DSyntax.INCH * (double)72;
	final double width = x * mult;
	final double height = y * mult;
	//	Set Size
	setSize (width, height);
	log.debug("Width & Height" + ": " + x + "/" + y  + " - Landscape=" + m_landscape);
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:24,代码来源:CPaper.java

示例3: getPaper

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
public Paper getPaper() {
    final short size = getDmPaperSize(structPtr);
    Paper p = StdPaper.getPaper(size);

    if (p == null) {
        final long fields = getDmFields();

        if (((fields & DM_PAPERLENGTH) != 0)
                        && ((fields & DM_PAPERWIDTH) != 0)) {
            p = new CustomPaper(size, new MediaSize(
                            getDmPaperWidth(structPtr) / 10,
                            getDmPaperLength(structPtr) / 10,
                            Size2DSyntax.MM));
        }
    }

    return p;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:DevmodeStructWrapper.java

示例4: getSupportedMediaSizeNames

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
public static MediaSizeName[] getSupportedMediaSizeNames(final long handle)
                throws PrintException {
    final MediaSizeName[] names;
    final int[] sizes = getSupportedPaperSizes(handle);
    final Vector<MediaSizeName> v = new Vector<MediaSizeName>(
                    sizes.length / 2);

    for (int i = 0; i < sizes.length; i += 2) {
        if ((sizes[i] > 0) && (sizes[i + 1] > 0)) {
            final MediaSizeName name = MediaSize.findMedia(sizes[i] / 10,
                            sizes[i + 1] / 10, Size2DSyntax.MM);

            if ((name != null) && !v.contains(name)) {
                v.add(name);
            }
        }
    }

    names = new MediaSizeName[v.size()];
    return v.toArray(names);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:WinPrinterFactory.java

示例5: mapMedia

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
public static MediaSizeName mapMedia(MediaType mType) {
    MediaSizeName media = null;

    // JAVAXSIZES.length and SIZES.length must be equal!
    // Attempt to recover by getting the smaller size.
    int length = Math.min(SIZES.length, JAVAXSIZES.length);

    for (int i=0; i < length; i++) {
        if (SIZES[i] == mType) {
            if ((JAVAXSIZES[i] != null) &&
                MediaSize.getMediaSizeForName(JAVAXSIZES[i]) != null) {
                media = JAVAXSIZES[i];
                break;
            } else {
                /* create Custom Media */
                media = new CustomMediaSizeName(SIZES[i].toString());

                float w = (float)Math.rint(WIDTHS[i]  / 72.0);
                float h = (float)Math.rint(LENGTHS[i] / 72.0);
                if (w > 0.0 && h > 0.0) {
                    // add new created MediaSize to our static map
                    // so it will be found when we call findMedia
                    new MediaSize(w, h, Size2DSyntax.INCH, media);
                }

                break;
            }
        }
    }
    return media;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:PrintJob2D.java

示例6: print

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
private void print(final PrintPackageRequest request) throws PrinterException
{
	logger.log(Level.FINE, "Printing request {}", request);

	// Create Print Job
	final PrinterJob pjob = PrinterJob.getPrinterJob();
	pjob.setJobName(request.getPrintJobName());

	final PageFormat pf = pjob.defaultPage();
	final Paper paper = pjob.defaultPage().getPaper();
	final MediaSize size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A4);

	paper.setSize(size.getSize(Size2DSyntax.INCH)[0] * 72, size.getSize(Size2DSyntax.INCH)[1] * 72);
	paper.setImageableArea(0, 0, size.getSize(Size2DSyntax.INCH)[0] * 72, size.getSize(Size2DSyntax.INCH)[1] * 72);
	pf.setPaper(paper);

	final Book book = new Book();// java.awt.print.Book
	book.append(request.getPrintable(), pf, request.getNumPages());
	pjob.setPageable(book);

	pjob.setPrintService(request.getPrintService());
	pjob.print(request.getAttributes());

	// task 09618: allow us to configure the client to return an error even if everything went OK, so we can test
	final String alwaysReturnError = Context.getContext().getProperty(Context.CTX_Testing_AlwaysReturnError, Context.DEFAULT_AlwaysReturnError);
	if (Boolean.parseBoolean(alwaysReturnError))
	{
		logger.log(Level.INFO, "{} is true, so we report an error, despite the print was OK", Context.CTX_Testing_AlwaysReturnError);

		final String errorMsg = Context.getContext().getProperty(Context.CTX_Testing_ErrorMessage, Context.DEFAULT_ErrorMessage);
		throw new PrinterException(errorMsg);
	}
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:34,代码来源:PrintingEngine.java

示例7: getUnitsInt

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
/**
 * 	Get Units Int
 *	@return units
 */
public int getUnitsInt()
{
	String du = getDimensionUnits();
	if (du == null || DIMENSIONUNITS_MM.equals(du))
		return Size2DSyntax.MM;
	else if (DIMENSIONUNITS_Inch.equals(du))
		return Size2DSyntax.INCH; 
	else
		throw new AdempiereException("@[email protected] @[email protected] : "+du);
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:15,代码来源:MPrintPaper.java

示例8: setPaper

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
public void setPaper(final Paper paper) {
    if (paper != null) {
        if (paper.getDmPaperSize() > 0) {
            setDmPaperSize(structPtr, paper.getDmPaperSize());
        } else {
            setDmPaperWidth(structPtr, (short) (paper.getSize().getX(
                            Size2DSyntax.MM) * 10));
            setDmPaperLength(structPtr, (short) (paper.getSize().getY(
                            Size2DSyntax.MM) * 10));
        }
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:13,代码来源:DevmodeStructWrapper.java

示例9: PPDMediaSizeName

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
protected PPDMediaSizeName(int value, float x, float y) {
    super(value);
    if (x > y) {
        float z = x;
        y = x;
        x = z;
    }
    new MediaSize(x / 72, y / 72, Size2DSyntax.INCH, this);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:10,代码来源:PPDMediaSizeName.java

示例10: getAttrsForPageFormat

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
protected HashPrintRequestAttributeSet 
        getAttrsForPageFormat(PageFormat page) {

    HashPrintRequestAttributeSet lattrs=new HashPrintRequestAttributeSet();

    /* Add Orientation attribute */
    switch (page.getOrientation()) {
        case PageFormat.LANDSCAPE:
            lattrs.add(OrientationRequested.LANDSCAPE);
            break;
        case PageFormat.PORTRAIT:
            lattrs.add(OrientationRequested.PORTRAIT);
            break;
        case PageFormat.REVERSE_LANDSCAPE:
            lattrs.add(OrientationRequested.REVERSE_LANDSCAPE);
            break;
    }

    /* Add Media attribute */
    MediaSizeName media = MediaSize.findMedia(
            (float) (page.getWidth() / 72.0),
            (float) (page.getHeight() / 72.0), 
            Size2DSyntax.INCH);
    if (media != null) {
        lattrs.add(media);
    }

    /* Add MediaMargins attribute */
    lattrs.add(new MediaMargins((float) (page.getImageableX() / 72.0), 
            (float) (page.getImageableY() / 72.0), 
            (float) ((page.getWidth() - page.getImageableX() -
                    page.getImageableWidth()) / 72.0),
            (float) ((page.getHeight() - page.getImageableHeight() -
                    page.getImageableY()) / 72.0), 
            MediaMargins.INCH));

    return lattrs;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:39,代码来源:PSPrinterJob.java

示例11: formatToAttrs

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
private static PrintRequestAttributeSet formatToAttrs(
                final PageFormat format) {
    final PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

    if (format != null) {
        attributes.add(new MediaPrintableArea((float) (format
                        .getImageableX() / 72.0), (float) (format
                        .getImageableY() / 72.0), (float) (format
                        .getWidth() / 72.0),
                        (float) (format.getHeight() / 72.0),
                        Size2DSyntax.INCH));

        switch (format.getOrientation()) {
        case PageFormat.PORTRAIT:
            attributes.add(OrientationRequested.PORTRAIT);
            break;
        case PageFormat.LANDSCAPE:
            attributes.add(OrientationRequested.LANDSCAPE);
            break;
        case PageFormat.REVERSE_LANDSCAPE:
            attributes.add(OrientationRequested.REVERSE_LANDSCAPE);
            break;
        }
    }

    return attributes;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:28,代码来源:PrinterJobImpl.java

示例12: getMediaDimensions

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
/**
 * @param media The {@link Media} to extract dimensions for.
 * @param units The units to return.
 * @return The dimensions of the specified {@link Media}.
 */
public static double[] getMediaDimensions(Media media, LengthUnits units) {
	MediaSize size = media instanceof MediaSizeName ? MediaSize.getMediaSizeForName((MediaSizeName) media) : null;

	if (size == null) {
		size = MediaSize.NA.LETTER;
	}
	return new double[] { units.convert(LengthUnits.IN, size.getX(Size2DSyntax.INCH)), units.convert(LengthUnits.IN, size.getY(Size2DSyntax.INCH)) };
}
 
开发者ID:Ayutac,项目名称:toolkit,代码行数:14,代码来源:PrintUtilities.java

示例13: setPaperSize

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
/**
 * Sets the paper size.
 *
 * @param service The {@link PrintService} to use.
 * @param set The {@link PrintRequestAttributeSet} to use.
 * @param size The size of the paper.
 * @param units The type of units being used.
 */
public static void setPaperSize(PrintService service, PrintRequestAttributeSet set, double[] size, LengthUnits units) {
	double[] margins = getPaperMargins(service, set, units);
	MediaSizeName mediaSizeName = MediaSize.findMedia((float) LengthUnits.IN.convert(units, size[0]), (float) LengthUnits.IN.convert(units, size[1]), Size2DSyntax.INCH);

	if (mediaSizeName == null) {
		mediaSizeName = MediaSizeName.NA_LETTER;
	}
	set.add(mediaSizeName);
	setPaperMargins(service, set, margins, units);
}
 
开发者ID:Ayutac,项目名称:toolkit,代码行数:19,代码来源:PrintUtilities.java

示例14: getMediaSizeName

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
public static MediaSizeName getMediaSizeName(PDDocument document) throws IOException {
    PDFRenderer renderer = new PDFRenderer(document);
    BufferedImage image = renderer.renderImageWithDPI(0, 72f);
    float w, h, swp;
    w = image.getWidth() / 72f;
    h = image.getHeight() / 72f;
    if (w > h) {
        swp = w;
        w = h;
        h = swp;
    }
    return MediaSize.findMedia(w, h, Size2DSyntax.INCH);
}
 
开发者ID:montsuqi,项目名称:monsiaj,代码行数:14,代码来源:PDFPrint.java

示例15: getPageFormat

import javax.print.attribute.Size2DSyntax; //导入依赖的package包/类
private PageFormat getPageFormat(final AttributeSet... attrSets) {
    final Paper paper = new Paper();
    final PageFormat format = new PageFormat();
    final DevmodeStructWrapper dm = service.getPrinterProps();
    final OrientationRequested o = dm.getOrientation();
    final MediaPrintableArea area = getAttribute(
                    MediaPrintableArea.class, attrSets);
    DevmodeStructWrapper.Paper p = dm.getPaper();

    if (p == null) {
        p = (DevmodeStructWrapper.Paper) service
                        .getDefaultAttributeValue(DevmodeStructWrapper.Paper.class);
        dm.setPaper(p);
    }

    paper.setSize(p.getSize().getX(Size2DSyntax.INCH) * 72.0, p
                    .getSize().getY(Size2DSyntax.INCH) * 72.0);
    format.setPaper(paper);

    if (OrientationRequested.LANDSCAPE.equals(o)
                    || OrientationRequested.REVERSE_LANDSCAPE.equals(o)) {
        format.setOrientation(PageFormat.LANDSCAPE);
    } else {
        format.setOrientation(PageFormat.PORTRAIT);
    }

    if (area != null) {
        paper.setImageableArea(area.getX(MediaPrintableArea.INCH) * 72,
                        area.getY(MediaPrintableArea.INCH) * 72,
                        area.getWidth(MediaPrintableArea.INCH) * 72,
                        area.getHeight(MediaPrintableArea.INCH) * 72);
    } else {
        final double x = paper.getWidth() / 10;
        final double y = paper.getHeight() / 10;

        paper.setImageableArea(x, y, (paper.getWidth() - 2 * x), (paper
                        .getHeight() - 2 * y));
    }

    return format;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:42,代码来源:WinPrintJob.java


注:本文中的javax.print.attribute.Size2DSyntax类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。