}
MediaSizeName bestMedia = null;
float bestFit = Float.MAX_VALUE;
for (MediaSizeName media : getSplitMedia()) {
MediaSize mediaSize = MediaSize.getMediaSizeForName(media);
if( mediaSize!=null ){
if( DEBUGMODE ){
System.out.print(mediaSize.toString(MediaSize.MM, "mm")); //$NON-NLS-1$
System.out.println(" - " + media); //$NON-NLS-1$
}
float dy = mediaSize.getY(MediaSize.INCH) - height;
float dx = mediaSize.getY(MediaSize.INCH) - width;
float fit = dy + dx;
if( dy >= 0 && dx >= 0 && fit <= bestFit ){
bestFit = fit;
bestMedia = media;
}
}
}
if( bestMedia==null ){
bestMedia = MediaSize.findMedia(width, height, MediaSize.INCH);
geco().debug(Messages.getString("SingleSplitPrinter.SmallTicketSizeWarning")); //$NON-NLS-1$
if( DEBUGMODE ){
System.out.print("Found: "); //$NON-NLS-1$
}
} else {
if( DEBUGMODE ){
System.out.print("Chosen: "); //$NON-NLS-1$
}
}
if( bestMedia!=null ){
attributes.add(bestMedia);
MediaSize fitSize = MediaSize.getMediaSizeForName(bestMedia);
if( DEBUGMODE ){
System.out.println(fitSize.toString(MediaSize.MM, "mm")); //$NON-NLS-1$
}
} else {
geco().log(Messages.getString("SingleSplitPrinter.NoMatchingTicketSizeWarning")); //$NON-NLS-1$
}
}