示例#1
0
        /// <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
示例#2
0
        /// <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());
        }
示例#3
0
        /// <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
示例#4
0
        }       //	CPaper

        /// <summary>
        /// Detail Constructor
        /// </summary>
        /// <param name="mediaSize">media size</param>
        /// <param name="landscape"></param>
        /// <param name="left">x in 1/72 inch</param>
        /// <param name="top">y in 1/72 inch</param>
        /// <param name="right">right x in 1/72</param>
        /// <param name="bottom"> bottom y in 1/72</param>
        public CPaper(MediaSize mediaSize, bool landscape, float left, float top, float right, float bottom)
            : base()
        {
            SetMediaSize(mediaSize, landscape);
            SetImageableArea(left, top, GetWidth() - left - right, GetHeight() - top - bottom);
        }       //	CPaper
示例#5
0
        }       //	CPaper

        /// <summary>
        /// Constructor
        /// Get Media Size from Default Language
        /// </summary>
        /// <param name="landscape">true if landscape, false if portrait</param>
        //public CPaper(bool landscape)
        //    : this(Language.GetLoginLanguage(), landscape)
        //{

        //}	//	CPaper

        /// <summary>
        /// Detail Constructor 1/2 inch on all sides
        /// </summary>
        /// <param name="mediaSize"> media size</param>
        /// <param name="landscape">true if landscape, false if portrait</param>
        private CPaper(MediaSize mediaSize, bool landscape)
            : this(mediaSize, landscape, 36, 36, 36, 36)
        {
        }       //	CPaper