/// <summary> /// Construct a new media size attribute from the given int values /// </summary> /// <param name="x">X dimension.</param> /// <param name="y">Y dimension.</param> /// <param name="units">Unit conversion factor, e.g. Size2DSyntax.INCH or Size2DSyntax.MM</param> /// <param name="media">a media name to associate with this MediaSize</param> public MediaSize(int x, int y, int units, MediaSizeName media) : base(x, y, units) { if (x > y) { throw new ArgumentException("X dimension > Y dimension"); } mediaName = media; if (mediaMap.ContainsKey(mediaName)) { mediaMap[mediaName] = this; } else { mediaMap.Add(mediaName, this); } sizeVector.Add(this); }
/// <summary> /// Constructor /// Derive Paper from PageForamt /// </summary> /// <param name="pf">PageFormat</param> public CPaper(PageFormat pf) : base() { m_landscape = pf.GetOrientation() != PageFormat.PORTRAIT; // try to find MediaSize float x = (float)pf.GetWidth(); float y = (float)pf.GetHeight(); MediaSizeName msn = MediaSize.FindMedia(x / 72, y / 72, MediaSize.INCH); MediaSize ms = null; if (msn == null) { msn = MediaSize.FindMedia(y / 72, x / 72, MediaSize.INCH); // flip it } if (msn != null) { ms = MediaSize.GetMediaSizeForName(msn); } SetMediaSize(ms, m_landscape); // set size directly SetSize(pf.GetWidth(), pf.GetHeight()); SetImageableArea(pf.GetImageableX(), pf.GetImageableY(), pf.GetImageableWidth(), pf.GetImageableHeight()); } // CPaper
/// <summary> /// Get the MediaSize for the specified named media. /// </summary> /// <param name="media">the name of the media for which the size is sought</param> /// <returns>size of the media, or null if this media is not associated with any size</returns> public static MediaSize GetMediaSizeForName(MediaSizeName media) { return((MediaSize)mediaMap[media]); }