resolution = (mOutputType == POSTSCRIPT) ? 300 : Constants.SCREEN_RESOLUTION;
if (mOutputType == POSTSCRIPT) resolution = 300; else resolution = Constants.getScreenResolution();
	private void setOutput(String filename, double width, double height, String extras)		throws IOException, MapyrusException	{		/*		 * Parse list of additional options given by caller.		 */		ArrayList fontList = new ArrayList();		mEncodeAsISOLatin1 = new HashSet();		mTTFFonts = new HashMap();		mAfmFiles = new ArrayList();		int resolution;		resolution = (mOutputType == POSTSCRIPT) ? 300 : Constants.SCREEN_RESOLUTION;		/*		 * Reading all font metrics information takes some time.		 * Wait until we really need it before loading it.		 */		mAdobeFontMetrics = null;			StringTokenizer st = new StringTokenizer(extras);		while (st.hasMoreTokens())		{			String token = st.nextToken();			if (token.startsWith("pfafiles="))			{				/*				 * Build list of font filenames user wants				 * to include in this PostScript file.				 */				StringTokenizer st2 = new StringTokenizer(token.substring(9), ",");				while (st2.hasMoreTokens())				{					String pfaFilename = st2.nextToken();					if (pfaFilename.length() > 0)					{						/*						 * Accept wildcards in filenames.						 */						WildcardFile wildcard = new WildcardFile(pfaFilename);						Iterator it = wildcard.getMatchingFiles();						while (it.hasNext())							fontList.add(new PostScriptFont((String)it.next()));					}				}			}			if (token.startsWith("afmfiles="))			{				StringTokenizer st2 = new StringTokenizer(token.substring(9), ",");				while (st2.hasMoreTokens())				{					String afmFilename = st2.nextToken();					if (afmFilename.length() > 0)					{						/*						 * Accept wildcards in filenames.						 */						WildcardFile wildcard = new WildcardFile(afmFilename);						Iterator it = wildcard.getMatchingFiles();						while (it.hasNext())						{							mAfmFiles.add(it.next());						}															}				}			}			else if (token.startsWith("isolatinfonts="))			{				/*				 * Build list of fonts to encode in ISOLatin1.				 */				StringTokenizer st2 = new StringTokenizer(token.substring(14), ",");				while (st2.hasMoreTokens())				{					String fontName = st2.nextToken();					if (fontName.length() > 0)						mEncodeAsISOLatin1.add(fontName);				}			}			else if (token.startsWith("resolution="))			{				String r = token.substring(11);				try				{					resolution = Integer.parseInt(r);				}				catch (NumberFormatException e)				{					throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.INVALID_PAGE_RESOLUTION) +						": " + r);				}				if (resolution < 1)				{					throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.INVALID_PAGE_RESOLUTION) +						": " + r);				}				}			else if (token.startsWith("ttffiles="))			{				/*				 * Build list of TrueType font filenames user wants				 * to open with Java methods.				 */				StringTokenizer st2 = new StringTokenizer(token.substring(9), ",");				while (st2.hasMoreTokens())				{					String ttfFilename = st2.nextToken();											/*					 * Accept wildcards in filenames.					 */					if (ttfFilename.length() > 0)					{						WildcardFile wildcard = new WildcardFile(ttfFilename);						Iterator it = wildcard.getMatchingFiles();						while (it.hasNext())						{							String s = (String)it.next();							TrueTypeFont ttf = new TrueTypeFont(s);							mTTFFonts.put(ttf.getName(), ttf);						}					}				}			}		}			/*		 * Setup file we are writing to.		 */		if (mOutputType == POSTSCRIPT)		{			mWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(mOutputStream)));							mSuppliedFontResources = new HashSet();				writePostScriptHeader(width, height, resolution, fontList);				mPostScriptIndent = 0;			mNeededFontResources = new HashSet();		}		else		{			if (mOutputType == IMAGE_FILE)			{				/*				 * Create a BufferedImage to draw into.  We'll save it to a file				 * when user has finished drawing to it.				 */				int widthInPixels = (int)Math.round(width / Constants.MM_PER_INCH * resolution);				int heightInPixels = (int)Math.round(height / Constants.MM_PER_INCH * resolution);				int imageType;				/*				 * Create images with transparency for all formats except				 * JPEG (which does not support it).				 */				if (mFormatName.equals("jpg") || mFormatName.equals("jpeg"))					imageType = BufferedImage.TYPE_3BYTE_BGR;				else					imageType = BufferedImage.TYPE_INT_ARGB;				mImage = new BufferedImage(widthInPixels, heightInPixels,					imageType);			}			else if (mOutputType == INTERNAL_IMAGE)			{				/*				 * Calculate width of page, based on image and resolution given				 * by user.				 */				width = mImage.getWidth() / (resolution / Constants.MM_PER_INCH);				height = mImage.getHeight() / (resolution / Constants.MM_PER_INCH);			}			mGraphics2D = (Graphics2D)(mImage.getGraphics());			setupBufferedImage(resolution);			/*			 * Fonts look so much better with anti-aliasing so always use it.			 */			mGraphics2D.addRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,				RenderingHints.VALUE_TEXT_ANTIALIAS_ON));		}		mFilename = filename;		mPageWidth = width;		mPageHeight = height;		mResolution = Constants.MM_PER_INCH / resolution;		mFontCache = new FontCache();		mJustificationShiftX = mJustificationShiftY = 0.0;		/*		 * Set impossible current font rotation so first font		 * accessed will be loaded.		 */		mFontRotation = Double.MAX_VALUE;				/*		 * Do not allocate page mask until needed to save memory.		 */		mPageMask = null;	}