/// <summary> /// Set Media Size /// </summary> /// <param name="mediaSize">Set Media Size</param> /// <param name="landscape">true if landscape, false if portrait</param> public void SetMediaSize(MediaSize mediaSize, bool landscape) { if (mediaSize == null) { throw new ArgumentException("MediaSize is null"); } m_mediaSize = mediaSize; m_landscape = landscape; // Get Sise in Inch * 72 float width = m_mediaSize.GetX(MediaSize.INCH) * 72; float height = m_mediaSize.GetY(MediaSize.INCH) * 72; // Set Size SetSize(width, height); log.Fine(mediaSize.GetMediaSizeName() + ": " + m_mediaSize + " - Landscape=" + m_landscape); } // setMediaSize
/// <summary> /// The specified dimensions are used to locate a matching MediaSize /// instance from amongst all the standard MediaSize instances. /// If there is no exact match, the closest match is used. /// </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> /// <returns>matching these dimensions, or null.</returns> public static MediaSizeName FindMedia(float x, float y, int units) { MediaSize match = MediaSize.ISO.A4; if (x <= 0.0f || y <= 0.0f || units < 1) { throw new ArgumentException("args must be +ve values"); } double ls = x * x + y * y; double tmp_ls; float[] dim; float diffx = x; float diffy = y; for (int i = 0; i < sizeVector.Count; i++) { MediaSize mediaSize = (MediaSize)sizeVector[i]; dim = mediaSize.GetSize(units); if (x == dim[0] && y == dim[1]) { match = mediaSize; break; } else { diffx = x - dim[0]; diffy = y - dim[1]; tmp_ls = diffx * diffx + diffy * diffy; if (tmp_ls < ls) { ls = tmp_ls; match = mediaSize; } } } return(match.GetMediaSizeName()); }
} // setMediaSize /// <summary> /// Get Media Size /// </summary> /// <returns>media size</returns> public MediaSizeName GetMediaSizeName() { return(m_mediaSize.GetMediaSizeName()); } // getMediaSizeName