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


Java MediaSize.getSize方法代码示例

本文整理汇总了Java中javax.print.attribute.standard.MediaSize.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSize.getSize方法的具体用法?Java MediaSize.getSize怎么用?Java MediaSize.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.print.attribute.standard.MediaSize的用法示例。


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

示例1: doTest

import javax.print.attribute.standard.MediaSize; //导入方法依赖的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: findMedia

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
/**
 * Returns closest matching MediaSizeName among given array of Media
 */
public static MediaSizeName findMedia(Media[] media, float x, float y,
                                      int units) {


    if (x <= 0.0f || y <= 0.0f || units < 1) {
        throw new IllegalArgumentException("args must be +ve values");
    }

    if (media == null || media.length == 0) {
        throw new IllegalArgumentException("args must have valid array of media");
    }

    int size =0;
    MediaSizeName[] msn = new MediaSizeName[media.length];
    for (int i=0; i<media.length; i++) {
        if (media[i] instanceof MediaSizeName) {
            msn[size++] = (MediaSizeName)media[i];
        }
    }

    if (size == 0) {
        return null;
    }

    int match = 0;

    double ls = x * x + y * y;
    double tmp_ls;
    float []dim;
    float diffx = x;
    float diffy = y;

    for (int i=0; i < size ; i++) {
        MediaSize mediaSize = MediaSize.getMediaSizeForName(msn[i]);
        if (mediaSize == null) {
            continue;
        }
        dim = mediaSize.getSize(units);
        if (x == dim[0] && y == dim[1]) {
            match = i;
            break;
        } else {
            diffx = x - dim[0];
            diffy = y - dim[1];
            tmp_ls = diffx * diffx + diffy * diffy;
            if (tmp_ls < ls) {
                ls = tmp_ls;
                match = i;
            }
        }
    }

    return msn[match];
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:58,代码来源:CustomMediaSizeName.java


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