internal EMFSetPageTransform(int flags, byte[] RecordData)
        {
            MemoryStream _fs = null;
            BinaryReader _fr = null;
            try
            {
                _fs = new MemoryStream(BitConverter.GetBytes(flags));
                _fr = new BinaryReader(_fs);

                //PageUnit...
                UInt16 PageU = _fr.ReadByte();
                PageUnit = (System.Drawing.GraphicsUnit)PageU;

                UInt16 RealFlags = _fr.ReadByte();
                //XXXXXAXX - if A = 1 the transform matrix is post-multiplied else pre-multiplied...
                //01234567
                postMultiplyTransform = ((RealFlags & (UInt16)Math.Pow(2, 5)) == Math.Pow(2, 5));
                PageScale = BitConverter.ToSingle(RecordData, 0);
                
            }
            finally
           {
               if (_fr != null)
                   _fr.Close();
               if (_fs != null)
                   _fs.Dispose();
               
           }
        }
        /// <summary>
        /// 获得一个单位占据的英寸数
        /// </summary>
        /// <param name="unit">单位类型</param>
        /// <returns>英寸数</returns>
        private static double GetUnit(System.Drawing.GraphicsUnit unit)
        {
            switch (unit)
            {
            case System.Drawing.GraphicsUnit.Display:
                return(1 / fDpi);

            case System.Drawing.GraphicsUnit.Document:
                return(1 / 300.0);

            case System.Drawing.GraphicsUnit.Inch:
                return(1);

            case System.Drawing.GraphicsUnit.Millimeter:
                return(1 / 25.4);

            case System.Drawing.GraphicsUnit.Pixel:
                return(1 / fDpi);

            case System.Drawing.GraphicsUnit.Point:
                return(1 / 72.0);

            default:
                throw new System.NotSupportedException("Not support " + unit.ToString());
            }
        }
Beispiel #3
0
        } // isMiscFile

        private void createThumbnail(string strFilename, string strThumbFilename)
        {
            System.Drawing.Image.GetThumbnailImageAbort objCallback;
            System.Drawing.Image        objFSImage;
            System.Drawing.Image        objTNImage;
            System.Drawing.RectangleF   objRect;
            System.Drawing.GraphicsUnit objUnits = System.Drawing.GraphicsUnit.Pixel;
            int intHeight = 0;
            int intWidth  = 0;

            // open image and get dimensions in pixels
            objFSImage = System.Drawing.Image.FromFile(strFilename);
            objRect    = objFSImage.GetBounds(ref objUnits);

            // what are we going to resize to, to fit inside 156x78
            getProportionalResize(Convert.ToInt32(objRect.Width), Convert.ToInt32(objRect.Height), ref intWidth, ref intHeight);

            // create thumbnail
            objCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
            objTNImage  = objFSImage.GetThumbnailImage(intWidth, intHeight, objCallback, IntPtr.Zero);

            // finish up
            objFSImage.Dispose();
            objTNImage.Save(strThumbFilename);
            objTNImage.Dispose();
        } // createThumbnail
        internal EMFSetPageTransform(int flags, byte[] RecordData)
        {
            MemoryStream _fs = null;
            BinaryReader _fr = null;

            try
            {
                _fs = new MemoryStream(BitConverter.GetBytes(flags));
                _fr = new BinaryReader(_fs);

                //PageUnit...
                UInt16 PageU = _fr.ReadByte();
                PageUnit = (System.Drawing.GraphicsUnit)PageU;

                UInt16 RealFlags = _fr.ReadByte();
                //XXXXXAXX - if A = 1 the transform matrix is post-multiplied else pre-multiplied...
                //01234567
                postMultiplyTransform = ((RealFlags & (UInt16)Math.Pow(2, 5)) == Math.Pow(2, 5));
                PageScale             = BitConverter.ToSingle(RecordData, 0);
            }
            finally
            {
                if (_fr != null)
                {
                    _fr.Close();
                }
                if (_fs != null)
                {
                    _fs.Dispose();
                }
            }
        }
Beispiel #5
0
        public static System.Drawing.RectangleF FixClipBounds(System.Drawing.Graphics g, float left, float top, float width, float height)
        {
            System.Drawing.GraphicsUnit unit = g.PageUnit;
            double ratex = g.DpiX;
            double ratey = g.DpiY;

            switch (unit)
            {
            case System.Drawing.GraphicsUnit.Document:
                ratex = 300;
                ratey = 300;
                break;

            case System.Drawing.GraphicsUnit.Inch:
                ratex = 1;
                ratey = 1;
                break;

            case System.Drawing.GraphicsUnit.Millimeter:
                ratex = 25.4;
                ratey = 25.4;
                break;

            case System.Drawing.GraphicsUnit.Point:
                ratex = 72;
                ratey = 72;
                break;
            }
            ratex = ratex / g.DpiX;
            ratey = ratey / g.DpiY;

            double left2   = Math.Ceiling(left / ratex) * ratex;
            double top2    = Math.Ceiling(top / ratey) * ratey;
            double width2  = Math.Ceiling(width / ratex) * ratex;
            double height2 = Math.Ceiling(height / ratey) * ratey;

            if (left2 > left)
            {
                left2 = left2 - ratex;
                if (width2 < width)
                {
                    width2 += ratex;
                }
                width2 += ratex;
            }
            if (top2 > top)
            {
                top2 = top - ratey;
                if (height2 < height)
                {
                    height2 += ratey;
                }
                height2 += ratey;
            }
            return(new System.Drawing.RectangleF(( float )left2, ( float )top2, ( float )width2, ( float )height2));
        }
 public static int Convert(int vValue, System.Drawing.GraphicsUnit OldUnit, System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(vValue);
     }
     else
     {
         return((int)(vValue * GetRate(NewUnit, OldUnit)));
     }
 }
 public static System.Drawing.Point Convert(System.Drawing.Point p, System.Drawing.GraphicsUnit OldUnit, System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(p);
     }
     else
     {
         double rate = GetRate(NewUnit, OldUnit);
         return(new System.Drawing.Point((int)(p.X * rate), (int)(p.Y * rate)));
     }
 }
Beispiel #8
0
        protected void DoPrint(PrintPageEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (_distributor == null)
            {
                _distributor = CreateDistributor();
                _distributor.Initialize(this, e);
            }

            if (e.Cancel == true)
            {
                e.HasMorePages = false;
                return;
            }

            System.Drawing.GraphicsUnit     originUnit      = e.Graphics.PageUnit;
            System.Drawing.Drawing2D.Matrix originTransform = e.Graphics.Transform;
            try
            {
                e.Graphics.PageUnit  = System.Drawing.GraphicsUnit.Pixel;
                e.Graphics.Transform = new System.Drawing.Drawing2D.Matrix();

                _distributor.FillPage(e, _items, _coords);
                if (e.Cancel == true)
                {
                    _items.Clear();
                    _coords.Clear();
                    return;
                }

                if (_items.Count != _coords.Count)
                {
                    throw new UnexpectedException();
                }

                for (int i = 0; i < _items.Count; i++)
                {
                    ((ImagePrintItem)_items[i]).Print(e.Graphics, (Point)_coords[i]);
                }
            }
            finally
            {
                e.Graphics.PageUnit  = originUnit;
                e.Graphics.Transform = originTransform;
                _items.Clear();
                _coords.Clear();
            }
        }
 public static System.Drawing.SizeF Convert(System.Drawing.SizeF size, System.Drawing.GraphicsUnit OldUnit, System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(size);
     }
     else
     {
         double rate = GetRate(NewUnit, OldUnit);
         return(new System.Drawing.SizeF(
                    (float)(size.Width * rate),
                    (float)(size.Height * rate)));
     }
 }
Beispiel #10
0
 public static System.Drawing.Point Convert(int x, int y, System.Drawing.GraphicsUnit OldUnit, System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(new System.Drawing.Point(x, y));
     }
     else
     {
         double rate = GetRate(NewUnit, OldUnit);
         return(new System.Drawing.Point(
                    (int)(x * rate),
                    (int)(y * rate)));
     }
 }
Beispiel #11
0
 public void Parse(String UnitsAsString)
 {
     if (UnitsAsString.Trim().Equals("MILLIMETER", StringComparison.OrdinalIgnoreCase))
     {
         UnitType = System.Drawing.GraphicsUnit.Millimeter;
     }
     else if (UnitsAsString.Trim().Equals("PIXELS", StringComparison.OrdinalIgnoreCase))
     {
         throw new ApplicationException("Not allowed");
     }
     else if (UnitsAsString.Trim().Equals("INCH", StringComparison.OrdinalIgnoreCase))
     {
         UnitType = System.Drawing.GraphicsUnit.Inch;
     }
 }
Beispiel #12
0
        protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs ev)
        {
            ev.HasMorePages = false;

            //draw a fullsize bitmap of the grid...
            int gridHeight = _grid.Model.RowHeights.GetTotal(0, _grid.Model.RowCount);
            int gridWidth  = _grid.Model.ColWidths.GetTotal(0, _grid.Model.ColCount);

            Bitmap gridBM = new Bitmap(gridWidth, gridHeight);

            Graphics g = Graphics.FromImage(gridBM);

            this._grid.GridBounds = new Rectangle(0, 0, gridWidth, gridHeight);
            this._grid.DrawGrid(g);
            this._grid.ResetGridBounds();

            g.Dispose();

            Rectangle destRect = ev.MarginBounds;


            //use the printer graphics
            g = ev.Graphics;

            //draw grid bitmap into the rect on the print page
            System.Drawing.GraphicsUnit gu = System.Drawing.GraphicsUnit.Point;
            RectangleF srcRect             = gridBM.GetBounds(ref gu);


            //adjust destRect to make sizing proportional
            // you can comment this out this block if you don't want proportional fit
            float srcRatio = srcRect.Width / srcRect.Height;
            float tarRatio = (float)destRect.Width / destRect.Height;

            if (tarRatio < srcRatio)
            {
                destRect.Height = (int)(destRect.Width / srcRatio);
            }
            else
            {
                destRect.Width = (int)(destRect.Height * srcRatio);
            }
            //////////////endof proportional fit//////////////////////////

            g.DrawImage(gridBM, destRect, srcRect, gu);
        }
Beispiel #13
0
        public object Deserialize <T>(MemoryStream ms)
        {
            // ToDo:
            if (typeof(T) == typeof(System.Drawing.Font))
            {
                var         soap = Encoding.ASCII.GetString(ms.ToArray());
                XmlDocument doc  = new XmlDocument();
                doc.LoadXml(soap);

                string name = "Arial";
                float  size = 8;
                System.Drawing.FontStyle    fontStyle = System.Drawing.FontStyle.Regular;
                System.Drawing.GraphicsUnit grUnit    = System.Drawing.GraphicsUnit.Point;

                XmlNode nameNode = doc.SelectSingleNode("//Name");
                if (nameNode != null)
                {
                    name = nameNode.InnerText;
                }

                XmlNode sizeNode = doc.SelectSingleNode("//Size");
                if (sizeNode != null)
                {
                    size = NumberConverter.ToFloat(sizeNode.InnerText);
                }

                XmlNode styleNode = doc.SelectSingleNode("//Style");
                if (styleNode != null)
                {
                    fontStyle = (System.Drawing.FontStyle)Enum.Parse(typeof(System.Drawing.FontStyle), styleNode.InnerText);
                }

                XmlNode unitNode = doc.SelectSingleNode("//Unit");
                if (styleNode != null)
                {
                    grUnit = (System.Drawing.GraphicsUnit)Enum.Parse(typeof(System.Drawing.GraphicsUnit), unitNode.InnerText);
                }


                var font = new System.Drawing.Font(name, size, fontStyle, grUnit);
                return(font);
            }

            return(default(T));
        }
Beispiel #14
0
        internal static MeasureUnit xlat(System.Drawing.GraphicsUnit unit)
        {
            switch (unit)
            {
            case System.Drawing.GraphicsUnit.Display:    return(MeasureUnit.Display);

            case System.Drawing.GraphicsUnit.Document:   return(MeasureUnit.Document);

            case System.Drawing.GraphicsUnit.Inch:       return(MeasureUnit.Inch);

            case System.Drawing.GraphicsUnit.Millimeter: return(MeasureUnit.Millimeter);

            case System.Drawing.GraphicsUnit.Pixel:      return(MeasureUnit.Pixel);

            case System.Drawing.GraphicsUnit.Point:      return(MeasureUnit.Point);

            case System.Drawing.GraphicsUnit.World:      return(MeasureUnit.World);

            default: return(MeasureUnit.World);
            }
        }
 public void FromStreamShouldWorkTest(string filename)
 {
     using (System.IO.StreamReader reader = new System.IO.StreamReader(filename))
     {
         Assert.DoesNotThrow(() => _texture = Texture2D.FromStream(gd, reader.BaseStream));
     }
     Assert.NotNull(_texture);
     try
     {
         System.Drawing.Bitmap       bitmap = new System.Drawing.Bitmap(filename);
         System.Drawing.GraphicsUnit gu     = System.Drawing.GraphicsUnit.Pixel;
         System.Drawing.RectangleF   rf     = bitmap.GetBounds(ref gu);
         Rectangle rt = _texture.Bounds;
         Assert.AreEqual((int)rf.Bottom, rt.Bottom);
         Assert.AreEqual((int)rf.Left, rt.Left);
         Assert.AreEqual((int)rf.Right, rt.Right);
         Assert.AreEqual((int)rf.Top, rt.Top);
         bitmap.Dispose();
     }//The dds file test case can't be checked with System.Drawing because it does not understand this format
     catch { }
     _texture.Dispose();
     _texture = null;
 }
Beispiel #16
0
        public static double GetDpi(System.Drawing.GraphicsUnit unit)
        {
            switch (unit)
            {
            case System.Drawing.GraphicsUnit.Display:
                return(fDpi);

            case System.Drawing.GraphicsUnit.Document:
                return(300);

            case System.Drawing.GraphicsUnit.Inch:
                return(1);

            case System.Drawing.GraphicsUnit.Millimeter:
                return(25.4);

            case System.Drawing.GraphicsUnit.Pixel:
                return(fDpi);

            case System.Drawing.GraphicsUnit.Point:
                return(72);
            }
            return(fDpi);
        }
Beispiel #17
0
 /// <summary>
 /// 将图形坐标单位转换为图元坐标单位
 /// </summary>
 /// <param name="unit">图形坐标单位</param>
 /// <returns>图元坐标单位</returns>
 public static System.Drawing.Imaging.MetafileFrameUnit ConvertUnit(System.Drawing.GraphicsUnit unit)
 {
     if (unit == System.Drawing.GraphicsUnit.Document)
     {
         return(System.Drawing.Imaging.MetafileFrameUnit.Document);
     }
     if (unit == System.Drawing.GraphicsUnit.Inch)
     {
         return(System.Drawing.Imaging.MetafileFrameUnit.Inch);
     }
     if (unit == System.Drawing.GraphicsUnit.Millimeter)
     {
         return(System.Drawing.Imaging.MetafileFrameUnit.Millimeter);
     }
     if (unit == System.Drawing.GraphicsUnit.Pixel)
     {
         return(System.Drawing.Imaging.MetafileFrameUnit.Pixel);
     }
     if (unit == System.Drawing.GraphicsUnit.Point)
     {
         return(System.Drawing.Imaging.MetafileFrameUnit.Point);
     }
     return(System.Drawing.Imaging.MetafileFrameUnit.Pixel);
 }
Beispiel #18
0
 public static double GetRate(System.Drawing.GraphicsUnit unit)
 {
     return(GraphicsUnitConvert.GetRate(unit, System.Drawing.GraphicsUnit.Document) / 3.0);
 }
Beispiel #19
0
        /// <summary>
        /// Select a font used to draw text on this <see cref="Canvas"/> class.
        /// </summary>
        /// <param name="fontName">The name of the font used to draw on the canvas.</param>
        /// <param name="fontSize">The size of the font used to draw on the canvas.</param>
        /// <param name="fontStyle">The style of the font used to draw on the canvas.</param>
        /// <param name="unit">The GraphicsUnit of the new font. </param>
        public void SelectFont(string fontName, float fontSize, System.Drawing.FontStyle fontStyle, System.Drawing.GraphicsUnit unit)
        {
            if (this.hdc != null)
            {
                if (this.hfont != null)
                {
                    this.hfont.Dispose();
                    this.hfont = null;
                }

                // get a handle to the Font object.
                using (System.Drawing.Font font = new System.Drawing.Font(fontName, fontSize, fontStyle, unit))
                {
                    this.hfont = new SafeGdiObjectHandle(font.ToHfont(), true);
                    NativeMethods.SelectObject(this.hdc, this.hfont);
                }

                // select color
                NativeMethods.SetBkMode(this.hdc, NativeMethods.TRANSPARENT);
                NativeMethods.SetTextColor(this.hdc, System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.Black));
            }
        }
Beispiel #20
0
 public Length(float Length, System.Drawing.GraphicsUnit Units)
 {
     this.length = Length;
     this.units  = new CoordinateSystem.Units(Units);
 }
Beispiel #21
0
 public double GetWidth(System.Drawing.GraphicsUnit unit)
 {
     return(GraphicsUnitConvert.Convert(intWidth * 3, System.Drawing.GraphicsUnit.Document, unit));
 }
Beispiel #22
0
 public Offset(System.Drawing.GraphicsUnit Unit)
 {
     DefaultUnits = new ACA.LabelX.Tools.CoordinateSystem.Units(Unit);
 }
Beispiel #23
0
 public LabelLayout(System.Drawing.GraphicsUnit unit)
 {
     this.DefaultUnits = new ACA.LabelX.Tools.CoordinateSystem.Units(unit);
 }
Beispiel #24
0
 /// <summary>
 /// 将一个长度从旧单位换算成新单位使用的比率
 /// </summary>
 /// <param name="NewUnit">新单位</param>
 /// <param name="OldUnit">旧单位</param>
 /// <returns>比率数</returns>
 public static double GetRate(System.Drawing.GraphicsUnit NewUnit, System.Drawing.GraphicsUnit OldUnit)
 {
     return(GetUnit(OldUnit) / GetUnit(NewUnit));
 }
Beispiel #25
0
 public double GetHeight(System.Drawing.GraphicsUnit unit)
 {
     return((int)GraphicsUnitConvert.Convert(intHeight * 3, System.Drawing.GraphicsUnit.Document, unit));
 }
Beispiel #26
0
 public void SetWidth(double vWidth, System.Drawing.GraphicsUnit unit)
 {
     intWidth = (int)(GraphicsUnitConvert.Convert(vWidth, unit, System.Drawing.GraphicsUnit.Document) / 3.0);
 }
Beispiel #27
0
 public System.Drawing.RectangleF GetBounds(System.Drawing.GraphicsUnit& pageUnit)
 {
 }
Beispiel #28
0
 public void SetHeight(double vHeight, System.Drawing.GraphicsUnit unit)
 {
     intHeight = (int)(GraphicsUnitConvert.Convert(vHeight, unit, System.Drawing.GraphicsUnit.Document) / 3.0);
 }
Beispiel #29
0
 internal void DrawImage(System.Drawing.Bitmap bitmap, int p, int p_2, System.Drawing.Rectangle rectangle, System.Drawing.GraphicsUnit graphicsUnit)
 {
     throw new NotImplementedException();
 }
Beispiel #30
0
 internal void DrawImage(System.Drawing.Image paintBuffer, System.Drawing.RectangleF rectangleF, System.Drawing.RectangleF rectangleF_2, System.Drawing.GraphicsUnit graphicsUnit)
 {
     throw new NotImplementedException();
 }
Beispiel #31
0
 public static System.Drawing.RectangleF Convert(System.Drawing.RectangleF rect, System.Drawing.GraphicsUnit OldUnit, System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(rect);
     }
     else
     {
         double rate = GetRate(NewUnit, OldUnit);
         return(new System.Drawing.RectangleF(
                    (float)(rect.X * rate),
                    (float)(rect.Y * rate),
                    (float)(rect.Width * rate),
                    (float)(rect.Height * rate)));
     }
 }