private ImageRenderInfo(GraphicsState gs, InlineImageInfo inlineImageInfo, PdfDictionary colorSpaceDictionary)
 {
     this.gs = gs;
     this.refi = null;
     this.inlineImageInfo = inlineImageInfo;
     this.colorSpaceDictionary = colorSpaceDictionary;
 }
Example #2
0
        public void SetControlValueTable(FUnit[] cvt, float scale, float ppem, byte[] cvProgram)
        {
            if (this.scale == scale || cvt == null)
                return;

            if (controlValueTable == null)
                controlValueTable = new float[cvt.Length];
            for (int i = 0; i < cvt.Length; i++)
                controlValueTable[i] = cvt[i] * scale;

            this.scale = scale;
            this.ppem = (int)Math.Round(ppem);
            zp0 = zp1 = zp2 = points;
            state.Reset();
            stack.Clear();

            if (cvProgram != null)
            {
                Execute(new InstructionStream(cvProgram), false, false);

                // save off the CVT graphics state so that we can restore it for each glyph we hint
                if ((state.InstructionControl & InstructionControlFlags.UseDefaultGraphicsState) != 0)
                    cvtState.Reset();
                else
                {
                    // always reset a few fields; copy the reset
                    cvtState = state;
                    cvtState.Freedom = Vector2.UnitX;
                    cvtState.Projection = Vector2.UnitX;
                    cvtState.DualProjection = Vector2.UnitX;
                    cvtState.RoundState = RoundMode.ToGrid;
                    cvtState.Loop = 1;
                }
            }
        }
 private ImageRenderInfo(GraphicsState gs, PdfIndirectReference refi, PdfDictionary colorSpaceDictionary)
 {
     this.gs = gs;
     this.refi = refi;
     this.inlineImageInfo = null;
     this.colorSpaceDictionary = colorSpaceDictionary;
 }
Example #4
0
 /**
  * Creates a new TextRenderInfo object
  * @param text the text that should be displayed
  * @param gs the graphics state (note: at this time, this is not immutable, so don't cache it)
  * @param textMatrix the text matrix at the time of the render operation
  * @param markedContentInfo the marked content sequence, if available
  */
 internal TextRenderInfo(String text, GraphicsState gs, Matrix textMatrix, ICollection markedContentInfo) {
     this.text = text;
     this.textToUserSpaceTransformMatrix = textMatrix.Multiply(gs.ctm);
     this.gs = gs;
     this.markedContentInfos = new List<MarkedContentInfo>();
     foreach (MarkedContentInfo m in markedContentInfo) {
         this.markedContentInfos.Add(m);
     }
 }
Example #5
0
 public Interpreter(int maxStack, int maxStorage, int maxFunctions, int maxInstructionDefs, int maxTwilightPoints)
 {
     stack = new ExecutionStack(maxStack);
     storage = new int[maxStorage];
     functions = new InstructionStream[maxFunctions];
     instructionDefs = new InstructionStream[maxInstructionDefs > 0 ? 256 : 0];
     state = new GraphicsState();
     cvtState = new GraphicsState();
     twilight = new Zone(new PointF[maxTwilightPoints], isTwilight: true);
 }
Example #6
0
        public void setState(GraphicsState state)
        {
            switch (currentState)
            {
                case GraphicsState.ClientLoading:
                    quitState_ClientLoading();
                    break;
                case GraphicsState.Login:
                    quitState_Login();
                    break;
                case GraphicsState.LobbyLoading:
                    quitState_LobbyLoading();
                    break;
                case GraphicsState.Lobby:
                    quitState_Lobby();
                    break;
                case GraphicsState.GameLoading:
                    quitState_GameLoading();
                    break;
                case GraphicsState.Game:
                    quitState_Game();
                    break;
            }

            currentState = state;

            switch (currentState)
            {
                case GraphicsState.ClientLoading:
                    enterState_ClientLoading();
                    break;
                case GraphicsState.Login:
                    enterState_Login();
                    break;
                case GraphicsState.LobbyLoading:
                    enterState_LobbyLoading();
                    break;
                case GraphicsState.Lobby:
                    enterState_Lobby();
                    break;
                case GraphicsState.GameLoading:
                    enterState_GameLoading();
                    break;
                case GraphicsState.Game:
                    enterState_Game();
                    break;
            }
        }
            public virtual void OnPrintCtrl(object sender, PrintPageEventArgs e)
            {
                if (_ctrl == null || _printHandler._drawFunc == null)
                {
                    return;
                }

                RectangleF rf = _printRect;

                // if the print rectangle is empty, adjust it to margin limit
                if (rf.Width == 0)
                {
                    rf.Width = e.MarginBounds.Width;
                }
                if (rf.Height == 0)
                {
                    rf.Height = e.MarginBounds.Height;
                }

                float wRatio = 1f, hRatio = 1f;

                Matrix m = new Matrix();

                rf.Offset(e.MarginBounds.Location);
                m.Translate(rf.X, rf.Y);        // always translate, as ctrl is zero upper left

                switch (_printScale)
                {
                case PrintScale.None:
                    // None means print/draw ctrl in specified space
                    rf.Size = _ctrlSize;
                    break;

                case PrintScale.Fit:
                    // Fit means draw the chart assuming it should fill the specified space.
                    // No sizing transforms are used.  Does not preserve aspect ratio.
                    _resizeControl = true;
                    break;

                case PrintScale.Stretch:
                    // Stretch means draw the ctrl so it contains
                    // the same view, but shrink or stretch so it fills
                    // the specified region.  This does not maintain aspect ratio.
                    wRatio = rf.Width / _ctrlSize.Width;
                    hRatio = rf.Height / _ctrlSize.Height;
                    break;

                default:                            // aka Zoom
                    // Zoom means draw the ctrl, preserving the
                    // aspect ratio, but scale it so that printed image fits
                    // entirely in the specified region.  Either the Width
                    // or the Height will be filled.
                    wRatio = rf.Width / _ctrlSize.Width;
                    hRatio = rf.Height / _ctrlSize.Height;
                    if (wRatio < hRatio)
                    {
                        hRatio = wRatio;
                    }
                    else
                    {
                        wRatio = hRatio;
                    }
                    break;
                }

                if (wRatio != 1f || hRatio != 1f)
                {
                    m.Scale(wRatio, hRatio);
                }

                Rectangle r = new Rectangle(Point.Empty, Size.Round(_resizeControl ? rf.Size : _ctrlSize));

                Graphics      g     = e.Graphics;
                GraphicsState gsave = g.Save();

                g.MultiplyTransform(m, MatrixOrder.Append);

                Graphics gbits        = null;
                Bitmap   bitMapBuffer = null;

                if (_bitmap)
                {
                    gbits        = g;
                    bitMapBuffer = new Bitmap(r.Width, r.Height);
                    g            = Graphics.FromImage(bitMapBuffer);
                }

                bool inPreview = sender is PrintDocument && ((PrintDocument)sender).PrintController.IsPreview;

                if (_printHandler._ia_grayscale != null && (e.PageSettings.Color || inPreview))
                {
                    Graphics gc  = _ctrl.CreateGraphics();
                    IntPtr   hdc = gc.GetHdc();
                    Metafile mf  = new Metafile(hdc, r, MetafileFrameUnit.Pixel, EmfType.EmfPlusDual);
                    if (mf != null)
                    {
                        Graphics gmf = Graphics.FromImage(mf);
                        if (gmf != null)
                        {
                            _printHandler._drawFunc(gmf, r, _resizeControl);
                            gmf.Dispose();
                        }
                        g.DrawImage(mf, r, r.X, r.Y, r.Width, r.Height, GraphicsUnit.Pixel,
                                    _printHandler._ia_grayscale);

                        mf.Dispose();
                        mf = null;
                    }
                    if (gc != null)
                    {
                        gc.Dispose();
                    }
                }
                else
                {
                    _printHandler._drawFunc(g, r, _resizeControl);
                }

                if (_bitmap)
                {
                    g.Flush();
                    g.Dispose();

                    g = gbits;
                    g.DrawImage(bitMapBuffer, r);
                    bitMapBuffer.Dispose();
                    bitMapBuffer = null;
                }
                m.Dispose();
                g.Restore(gsave);

                e.HasMorePages = false;

                // Since values may have been recalculated in the ctrl
                // during the draw, but based on the printer graphics
                // object, repaint the ctrl on the screen so the internal
                // variables are recalculated for the screen.
                // this will need to be address more completely.
                _ctrl.Invalidate();
            }
Example #8
0
        private void redraw(Rectangle rect)
        {
            SuspendLayout();
            // #1.02.001 - new line
            if (!redraw_allowed)
            {
                return;
            }

            Graphics      g  = this.CreateGraphics();
            GraphicsState gs = g.Save();

            // #1.02.001 new lines
            Region reg = null;

            if (move || cs_up || cs_down)
            {
                drawTempRect(g);
            }

// #1.01.002 - new functionality
            if (rect.Height != 0)
            {
                reg = new Region(rect);
//				reg.Exclude(Sheet.getResourceBoxesRegion(g,0,0,1,1,14));
//				reg.Exclude(curr_rect);
//				g.SetClip(reg, CombineMode.Replace);
            }
            else
            {
                reg = g.Clip;
//				g.SetClip(reg, CombineMode.Replace);
//				Region reg = g.Clip;
//				reg.Exclude(Sheet.getResourceBoxesRegion(g,0,0,1,1,14));
//				reg.Exclude(curr_rect);
//				g.SetClip(reg, CombineMode.Replace);
            }

            // #1.02.001 - row removed
//			g.FillRectangle(new SolidBrush(Color.WhiteSmoke),0,0,this.Width,this.Height);

            // Check if size changed, then the whole control should be cleared
// #1.01.002 - moved lines

/*			if ( oldsize_ != this.Size )
 *                      {
 *                              g.Clear(Color.WhiteSmoke);
 *                      }
 */

            Region skel_reg = new Region(new Rectangle(0, 0, 0, 0));

            skel_reg.Union(reg);
            skel_reg.Exclude(Sheet.getResourceBoxesRegion(g, 0, 0, 1, 1, 14));
            if (move || cs_up || cs_down)
            {
                skel_reg.Exclude(new Rectangle(curr_rect.X, curr_rect.Y, curr_rect.Width, curr_rect.Height));
            }
            g.SetClip(skel_reg, CombineMode.Replace);
            Sheet.drawSkeleton(this, g, 0, 0, 1, 1, 13);
//			g.SetClip(reg, CombineMode.Replace);

            // HACK: Better way? Do this, else it dont work
// #1.01.002 - removed lines

/*			if ( oldsize_ != this.Size )
 *                      {
 *                              oldsize_ = this.Size;
 *                              g.Clear(Color.WhiteSmoke);
 *                      }	 */
// #1.02.001 - rows added - start
            g.Clip = reg;
            Sheet.drawResourceBoxes(g, 0, 0, 1, 1, SchemaUI.DAYS_SHOWN);
            if (move || cs_up || cs_down)
            {
                drawTempRect(g);
            }
            g.Flush();
            g.Restore(gs);
// #1.02.001 - rows added - end
            g.Dispose();
            this.ResumeLayout();
        }
Example #9
0
 internal MapGraphState(GraphicsState state, int width, int height)
 {
     this.state  = state;
     this.width  = width;
     this.height = height;
 }
Example #10
0
 public static void SaveGraphicsState(Graphics g, ref GraphicsState state)
 {
     state = g.Save();
 }
Example #11
0
 public override void Scan(GraphicsState state)
 {
     state.CharSpace = Value;
 }
Example #12
0
        public override void DrawItem(TabItemPaintEventArgs e)
        {
            Rectangle rect = e.Bounds;

            if (rect.Width <= 0 || rect.Height <= 0)
            {
                return;
            }

            // draw background
            DrawItemBackground(e);

            rect = e.ContentRectangle;
            // draw icon
            if (e.Item.Icon != null)
            {
                Rectangle rect_icon;
                if (e.IsHorizontal)
                {
                    if (string.IsNullOrEmpty(e.Item.Text) && !e.Item.CanClose)
                    {
                        rect_icon = new Rectangle(rect.Left + (rect.Width - e.IconSize.Width) / 2, rect.Top + (rect.Height - e.IconSize.Height) / 2, e.IconSize.Width, e.IconSize.Height);
                    }
                    else
                    {
                        rect_icon = new Rectangle(rect.Left, rect.Top + (rect.Height - e.IconSize.Height) / 2, e.IconSize.Width, e.IconSize.Height);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(e.Item.Text) && !e.Item.CanClose)
                    {
                        rect_icon = new Rectangle(rect.Left + (rect.Width - e.IconSize.Width) / 2, rect.Top + (rect.Height - e.IconSize.Height) / 2, e.IconSize.Width, e.IconSize.Height);
                    }
                    else
                    {
                        rect_icon = new Rectangle(rect.Left + (rect.Width - e.IconSize.Width) / 2, rect.Top, e.IconSize.Width, e.IconSize.Height);
                    }
                }

                PaintHelper.DrawImageInRange(e.Graphics, e.Item.Icon, rect_icon);
                if (e.IsHorizontal)
                {
                    rect.X     += rect_icon.Width;
                    rect.Width -= rect_icon.Width;
                }
                else
                {
                    rect.Y      += rect_icon.Height;
                    rect.Height -= rect_icon.Height;
                }
            }

            if (e.Item.CanClose)
            {
                //System.Diagnostics.Debug.WriteLine(string.Format("> {0}, {1}", HoverHitResult.Item, HoverHitResult.InCloseButton));

                Rectangle rect_close_btn = e.Item.GetCloseButtonRect();
                DrawCloseButton(e, rect_close_btn);
                if (e.IsHorizontal)
                {
                    rect.Width -= e.Bar.CloseButtonSize.Width;
                }
                else
                {
                    rect.Height -= e.Bar.CloseButtonSize.Height;
                }
            }

            if (!string.IsNullOrEmpty(e.Item.Text))
            {
                Rectangle     rect_text = rect;
                GraphicsState gs        = null;
                if (!e.IsHorizontal)
                {
                    gs = e.Graphics.Save();
                    e.Graphics.RotateTransform(90);
                    rect_text = new Rectangle(rect.Y, -rect.X - rect.Width, rect.Height, rect.Width);
                    //e.Graphics.DrawRectangle(Pens.Blue, rect_text);
                }

                DrawItemText(e, rect_text);

                if (!e.IsHorizontal)
                {
                    e.Graphics.Restore(gs);
                }
            }
        }
Example #13
0
        public static Bitmap ToBitmap(this Graphics graphics, bool visibleClipOnly)
        {
            if (!OSUtils.IsWindows)
            {
                throw new PlatformNotSupportedException(Res.RequiresWindows);
            }

            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics), PublicResources.ArgumentNull);
            }

            if (visibleClipOnly && graphics.IsVisibleClipEmpty)
            {
                return(null);
            }

            Bitmap        result;
            RectangleF    visibleRect;
            int           sourceLeft, sourceTop, targetWidth, targetHeight;
            GraphicsState state = graphics.Save();

            try
            {
                // resetting the identity matrix so VisibleClipBounds will be correct
                graphics.Transform = new Matrix();

                // obtaining size in pixels
                graphics.PageUnit = GraphicsUnit.Pixel;
                visibleRect       = graphics.VisibleClipBounds;
                sourceLeft        = (int)visibleRect.Left;
                sourceTop         = (int)visibleRect.Top;
                targetWidth       = (int)visibleRect.Width;
                targetHeight      = (int)visibleRect.Height;

                // there is a source image: copying so transparency is preserved
                Image imgSource = graphics.GetBackingImage();
                if (imgSource != null)
                {
                    if (imgSource is Metafile)
                    {
                        throw new NotSupportedException(Res.GraphicsExtensionsToBitmapMetafileNotSupported);
                    }
                    if (!visibleClipOnly)
                    {
                        return((Bitmap)imgSource.Clone());
                    }

                    if (targetWidth == 0 || targetHeight == 0)
                    {
                        return(null);
                    }

                    result = new Bitmap(targetWidth, targetHeight, imgSource.PixelFormat);
                    using IReadableBitmapData src = ((Bitmap)imgSource).GetReadableBitmapData();
                    using IWritableBitmapData dst = result.GetWritableBitmapData();
                    src.CopyTo(dst, new Rectangle(sourceLeft, sourceTop, targetWidth, targetHeight), Point.Empty);
                    return(result);
                }
            }
            finally
            {
                graphics.Restore(state);
            }

            IntPtr dcSource = graphics.GetHdc();

            if (!visibleClipOnly)
            {
                sourceLeft = 0;
                sourceTop  = 0;

                // obtaining container Window
                IntPtr hwnd = User32.WindowFromDC(dcSource);
                if (hwnd != IntPtr.Zero)
                {
                    //// Show in whole screen
                    //RECT rect;
                    //GetWindowRect(hwnd, out rect); // the full rect of self control on screen
                    //// Show in screen
                    //GetWindowRect(hwnd, out rect);
                    //left = -rect.Left;
                    //top = -rect.Top;
                    //width = GetDeviceCaps(dcSource, DeviceCap.HORZRES);
                    //height = GetDeviceCaps(dcSource, DeviceCap.VERTRES);
                    //visibleRect.Offset(rect.Left, rect.Top);

                    //// Show in parent control
                    //IntPtr hwndParent = GetParent(hwnd);
                    //if (hwndParent != IntPtr.Zero)
                    //{
                    //    RECT rectParent;
                    //    GetWindowRect(hwndParent, out rectParent);
                    //    left = rectParent.Left - rect.Left;
                    //    top = rectParent.Top - rect.Top;
                    //    width = rectParent.Right - rectParent.Left;
                    //    height = rectParent.Bottom - rectParent.Top;
                    //    visibleRect.Offset(-left, -top);
                    //}
                    //else

                    // Show in container control
                    Rectangle rect = User32.GetClientRect(hwnd);
                    if (rect.Right < visibleRect.Right && rect.Bottom < visibleRect.Bottom)
                    {
                        // Visible rect is larger than client rect: calculating from full size.
                        // This is usually the case when Graphics is created for nonclient area
                        rect = User32.GetWindowRect(hwnd);
                    }

                    targetWidth  = rect.Right - rect.Left;
                    targetHeight = rect.Bottom - rect.Top;
                }
                else if (visibleRect.Location != Point.Empty)
                {
                    // no window: surrounding symmetrically or max 100 px
                    targetWidth  = (int)(visibleRect.Right + Math.Min(visibleRect.Left, 100f));
                    targetHeight = (int)(visibleRect.Bottom + Math.Min(visibleRect.Top, 100f));
                }
            }

            // the container control is too small
            if (targetWidth <= 0 || targetHeight <= 0)
            {
                graphics.ReleaseHdc(dcSource);
                return(null);
            }

            // creating a compatible bitmap
            IntPtr dcTarget  = Gdi32.CreateCompatibleDC(dcSource);
            IntPtr hbmResult = Gdi32.CreateCompatibleBitmap(dcSource, targetWidth, targetHeight);

            Gdi32.SelectObject(dcTarget, hbmResult);

            // Copy content
            Gdi32.BitBlt(dcTarget, 0, 0, targetWidth, targetHeight, dcSource, sourceLeft, sourceTop);
            result = Image.FromHbitmap(hbmResult);

            //cleanup
            graphics.ReleaseHdc(dcSource);
            Gdi32.DeleteDC(dcTarget);
            Gdi32.DeleteObject(hbmResult);

            return(result);
        }
Example #14
0
 internal static extern GpStatus GdipRestoreGraphics(GpGraphics graphics, GraphicsState state);
Example #15
0
        /// <summary>
        /// 创建验证码图片
        /// </summary>
        /// <param name="width">图片宽度</param>
        /// <param name="height">图片高度</param>
        /// <param name="validationCode">验证码</param>
        public Image CreateImage(int width, int height, string validationCode)
        {
            // 生成 BITMAP 图像
            Bitmap bitmapImg = new Bitmap(width, height);

            // 获取绘制器对象
            Graphics g = Graphics.FromImage(bitmapImg);

            // 清除图片
            //g.Clear(Color.White);
            g.Clear(_COLOR_BACKGROUND[new Random().Next(9)]); ////背景色,可自行设置
            // 获得字符数组
            char[] charList = validationCode.ToCharArray();
            // 字符索引
            int i = 0;

            // 坐标位置
            int startX = 0, startY = 0;
            // 上一字符大小
            Size lastCharSize = new Size(0, 0);

            // 贝塞尔曲线范围
            Rectangle beziersRect = new Rectangle();



            while (i < charList.Length)
            {
                // 创建自定义字符对象
                MyChar2G charObj = new MyChar2G(charList[i]);
                // 字体
                Font charFont = this.NextFont();
                // 字符大小
                SizeF charSize = g.MeasureString(Convert.ToString(charList[i]), charFont);

                // 旋转方向
                int rotateDirection = (g_random.Next(0, 256) >= 128) ? +1 : -1;
                // 旋转角度, 最大为 30 度
                float angle = Convert.ToSingle(g_random.NextDouble() * 60.00f) * rotateDirection;

                // 设置字体
                charObj.Font = charFont;
                // 设置字符大小
                charObj.OldSize = new Size((int)charSize.Width, (int)charSize.Height);
                // 设置角度
                charObj.Angle = angle;
                // 设置前景色
                charObj.ForeColor = new SolidBrush(_COLOR_FACE[i]);
                // 设置背景色
                charObj.BackColor = Brushes.White;



                if (i == 0)
                {
                    // 坐标起始位置
                    startX = g_random.Next(0, width / (charList.Length * 4));
                    startY = g_random.Next(0, height / 4);

                    beziersRect.X = startX;
                    beziersRect.Y = startY;
                }
                else
                {
                    startX += lastCharSize.Width * 4 / 7;
                }

                // 保存当前状态
                GraphicsState gs = g.Save();

                // 高质量
                g.SmoothingMode = SmoothingMode.HighQuality;

                // 平移绘制器
                g.TranslateTransform(
                    startX + charObj.ComputeLdx(),
                    startY + charObj.ComputeTdy());

                // 旋转角度
                g.RotateTransform(angle);



                // 绘制字符
                g.DrawString(Convert.ToString(charObj.CharObj), charObj.Font, charObj.ForeColor, 0, 0);

                // 还原绘制工具
                g.Restore(gs);

                // 计算新字符大小
                lastCharSize = charObj.ComputeNewSize();

                i++;
            }

            // 设置贝塞尔曲线范围的宽度, 高度
            beziersRect.Width  = startX + lastCharSize.Width;
            beziersRect.Height = lastCharSize.Height;

            // 绘制贝塞尔曲线
            this.DrawBeziers(g, beziersRect);

            return(bitmapImg);
        }
Example #16
0
        private void SlidingPanel_Paint(object sender, PaintEventArgs e)
        {
            int pos = 0;

            if (AnchorSide == Side.Right)
            {
                pos = 0;
            }
            else
            {
                pos = Width - m_BorderWidth;
            }
            Rectangle rect = new Rectangle(pos, 0, m_BorderWidth - 1, Height - 1);

            if (Enabled)
            {
                e.Graphics.FillRectangle(m_BorderBrush, rect);
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.Gray, rect);
            }
            e.Graphics.DrawRectangle(Pens.White, rect);
            Font         drawFont   = new Font("Arial", 12);
            StringFormat drawFormat = new StringFormat();

            // X centered
            drawFormat.LineAlignment = StringAlignment.Center;
            GraphicsState state = e.Graphics.Save();

            e.Graphics.ResetTransform();
            // Vertical directionality
            if (m_TitleDirectionality == e_TitleDirectionality.TTB)
            {
                e.Graphics.RotateTransform(90);
            }
            if (m_TitleDirectionality == e_TitleDirectionality.BTT)
            {
                e.Graphics.RotateTransform(-90);
            }
            // Vertical position
            float yPos    = 0;
            float yMargin = 2;

            if (m_TitlePosition == e_TitlePosition.Top)
            {
                yPos = 1 + yMargin;
            }
            if (m_TitlePosition == e_TitlePosition.Bottom)
            {
                yPos = Height - yMargin;
            }
            e.Graphics.TranslateTransform(pos + m_BorderWidth / 2, yPos, MatrixOrder.Append);
            // Vertical directionality and position

            if ((m_TitlePosition == e_TitlePosition.Top && m_TitleDirectionality == e_TitleDirectionality.TTB) || (m_TitlePosition == e_TitlePosition.Bottom && m_TitleDirectionality == e_TitleDirectionality.BTT))
            {
                drawFormat.Alignment = StringAlignment.Near;
            }
            if ((m_TitlePosition == e_TitlePosition.Top && m_TitleDirectionality == e_TitleDirectionality.BTT) || (m_TitlePosition == e_TitlePosition.Bottom && m_TitleDirectionality == e_TitleDirectionality.TTB))
            {
                drawFormat.Alignment = StringAlignment.Far;
            }
            e.Graphics.DrawString(m_Title, m_Font, Brushes.White, 0, 0, drawFormat);
            e.Graphics.Restore(state);
        }
Example #17
0
 public override void Scan(GraphicsState state)
 {
     state.LineWidth = Value;
 }
Example #18
0
        internal static float DrawRollAngleIndexMarks(Graphics g, int width, int height, float pixelsPerDegreePitch, ref GraphicsState basicState, out Pen rollIndexPen)
        {
            rollIndexPen = RollIndexPen.Value;
            GraphicsUtil.RestoreGraphicsState(g, ref basicState);
            const float majorIndexLineLength = 15;
            const float minorIndexLineLength = majorIndexLineLength / 2.0f;
            var         radiusFromCenterToBottomOfIndexLine = pixelsPerDegreePitch * 20.0f;
            var         startingTransform = g.Transform;

            for (var i = -60; i <= 60; i += 5)
            {
                var drawLine   = false;
                var lineLength = minorIndexLineLength;
                if (Math.Abs(i) == 60 || Math.Abs(i) == 30)
                {
                    drawLine   = true;
                    lineLength = majorIndexLineLength;
                }
                else if (Math.Abs(i) == 45 || Math.Abs(i) == 20 || Math.Abs(i) == 10)
                {
                    drawLine = true;
                }
                g.Transform = startingTransform;
                g.TranslateTransform(width / 2.0f, height / 2.0f);
                g.RotateTransform(i);
                g.TranslateTransform(-(float)width / 2.0f, -(float)height / 2.0f);

                if (drawLine)
                {
                    g.DrawLineFast(
                        RollIndexPen.Value, new PointF(width / 2.0f, height / 2.0f - radiusFromCenterToBottomOfIndexLine),
                        new PointF(width / 2.0f, height / 2.0f - radiusFromCenterToBottomOfIndexLine - lineLength));
                }
            }

            GraphicsUtil.RestoreGraphicsState(g, ref basicState);
            return(radiusFromCenterToBottomOfIndexLine);
        }
Example #19
0
    public Example_16()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_16.pdf", FileMode.Create)));

        Font f1 = new Font(pdf, CoreFont.HELVETICA);

        f1.SetSize(14f);

        Page page = new Page(pdf, Letter.PORTRAIT);

        Dictionary <String, Int32> colors = new Dictionary <String, Int32>();

        colors["Lorem"]       = Color.blue;
        colors["ipsum"]       = Color.red;
        colors["dolor"]       = Color.green;
        colors["ullamcorper"] = Color.gray;

        f1.SetSize(72f);

        GraphicsState gs = new GraphicsState();

        gs.SetAlphaStroking(0.5f);      // Set alpha for stroking operations
        gs.SetAlphaNonStroking(0.5f);   // Set alpha for nonstroking operations
        page.SetGraphicsState(gs);

        TextLine text = new TextLine(f1, "Hello, World");

        text.SetLocation(50f, 300f);
        text.DrawOn(page);

        String latinText = File.ReadAllText("data/latin.txt");

        f1.SetSize(14f);
        TextBox textBox = new TextBox(f1, latinText);

        textBox.SetLocation(50f, 50f);
        textBox.SetWidth(400f);
        // If no height is specified the height will be calculated based on the text.
        // textBox.SetHeight(400f);

        // textBox.SetVerticalAlignment(Align.TOP);
        // textBox.SetVerticalAlignment(Align.BOTTOM);
        // textBox.SetVerticalAlignment(Align.CENTER);
        textBox.SetBgColor(Color.whitesmoke);
        textBox.SetTextColors(colors);

        // Find x and y without actually drawing the text box.
        // float[] xy = textBox.DrawOn(page, false);
        float[] xy = textBox.DrawOn(page);

        page.SetGraphicsState(new GraphicsState()); // Reset GS

        Box box = new Box();

        box.SetLocation(xy[0], xy[1]);
        box.SetSize(20f, 20f);
        box.DrawOn(page);

        pdf.Complete();
    }
Example #20
0
 /**
  * Used for creating sub-TextRenderInfos for each individual character
  * @param parent the parent TextRenderInfo
  * @param charIndex the index of the character that this TextRenderInfo will represent
  * @param horizontalOffset the unscaled horizontal offset of the character that this TextRenderInfo represents
  * @since 5.3.3
  */
 private TextRenderInfo(TextRenderInfo parent, int charIndex, float horizontalOffset)
 {
     this.text = parent.text.Substring(charIndex, 1);
     this.textToUserSpaceTransformMatrix = new Matrix(horizontalOffset, 0).Multiply(parent.textToUserSpaceTransformMatrix);
     this.gs = parent.gs;
     this.markedContentInfos = parent.markedContentInfos;
 }
Example #21
0
        public void Draw(Graphics g)
        {
            foreach (var v in network.Vertices) //vertices
            {
                Point     p         = v.Data.Position;
                Point     pointFont = new Point(p.X - NODE_RADIUS - 10, p.Y - NODE_RADIUS - 10);
                Rectangle rect      = new Rectangle(p.X - NODE_RADIUS, p.Y - NODE_RADIUS, NODE_RADIUS * 2, NODE_RADIUS * 2);
                g.FillEllipse(nodeBrush, rect);
                string glyph = GetGlyph(v);
                if (!v.Data.IsStartElement)
                {
                    g.DrawString(glyph, drawFont, nodeBrush, pointFont);
                }
                else
                {
                    g.DrawString(glyph, boldDrawFont, nodeBrush, pointFont);
                }
                g.DrawString(glyph, drawFont, nodeBrush, pointFont);

                //drawing nodes loss
                List <Vertex <Node> > adjVertexes = network.GetAdjacentVerticesTo(v);
                if (v.Data.Type == NodeType.Node && adjVertexes.Count() > 1)
                {
                    float maxAngle = 0;
                    Point pBisect  = new Point();
                    for (int i = 0; i < adjVertexes.Count(); i++)
                    {
                        Point pf = adjVertexes[i].Data.Position;
                        Point pn;
                        if (i + 1 != adjVertexes.Count())
                        {
                            pn = adjVertexes[i + 1].Data.Position;
                        }
                        else
                        {
                            pn = adjVertexes[0].Data.Position;
                        }
                        float angle = MathHelper.P3A(pf, p, pn);
                        if (Math.Abs(angle) > maxAngle)
                        {
                            maxAngle = angle;
                        }
                    }
                    GraphicsState state = g.Save();
                    g.TranslateTransform(p.X, p.Y);
                    g.RotateTransform(360 - maxAngle);
                    pBisect = new Point(0, LOSS_LENGTH);
                    lossPen.CustomEndCap = new AdjustableArrowCap(2, 4);
                    g.DrawLine(lossPen, new Point(), pBisect);
                    g.TranslateTransform(pBisect.X, pBisect.Y);
                    g.RotateTransform(270);
                    g.DrawString(v.Data.NodeLoss.ToString(), lossFont, lossBrush, new Point());
                    g.Restore(state);
                }

                if (v.Data.IsLocked)
                {
                    Rectangle r = new Rectangle(p.X - LOCK_RADIUS, p.Y - LOCK_RADIUS, LOCK_RADIUS * 2, LOCK_RADIUS * 2);
                    g.DrawRectangle(lockPen, r);
                }
            }

            for (int i = 0; i < network.Edges.Count; i++)
            {
                List <Edge <Node> > edgesRow = network.Edges[i];
                for (int j = i; j < edgesRow.Count; j++)
                {
                    Edge <Node> e = edgesRow[j];
                    if (e.Value)
                    {
                        Point p1;
                        Point p2;
                        if (!e.DrawReversed)
                        {
                            p1 = network.Vertices[i].Data.Position;
                            p2 = network.Vertices[j].Data.Position;
                        }
                        else
                        {
                            p1 = network.Vertices[j].Data.Position;
                            p2 = network.Vertices[i].Data.Position;
                        }
                        double lenX         = p1.X - p2.X;
                        double lenY         = p1.Y - p2.Y;
                        double absLenX      = Math.Abs(lenX);
                        double absLenY      = Math.Abs(lenY);
                        int    x            = (int)Math.Floor(absLenX / 2 + Math.Min(p1.X, p2.X));
                        int    y            = (int)Math.Floor(absLenY / 2 + Math.Min(p1.Y, p2.Y));
                        Point  middlePoint  = new Point(x, y);
                        float  angleDegrees = (float)(Math.Atan2(lenY, lenX) * 180 / Math.PI);
                        if (!e.IsLocked)
                        {
                            g.DrawLine(pipePen, p1, p2);
                            DrawHelper.DrawRotatedString(e.Length.ToString(), drawFont, edgeBrush, middlePoint, angleDegrees, 0.0f, drawFont.Size * 0.5, g);
                            DrawHelper.DrawRotatedString(e.PipeLoss.ToString(), drawFont, edgeBrush, middlePoint, angleDegrees, 0.0f, drawFont.Size * -2.5, g);
                            DrawHelper.DrawRotatedArrow(pipePen, middlePoint, PIPE_LENGTH, angleDegrees, 0.0f, drawFont.Size * -0.5, false /*e.CounterClockwise*/, g);
                        }
                        else
                        {
                            g.DrawLine(lockedPipePen, p1, p2);
                            DrawHelper.DrawRotatedString(e.Length.ToString(), drawFont, lockedEdgeBrush, middlePoint, angleDegrees, 0.0f, drawFont.Size * 0.5, g);
                            DrawHelper.DrawRotatedString(e.PipeLoss.ToString(), drawFont, lockedEdgeBrush, middlePoint, angleDegrees, 0.0f, drawFont.Size * -2.5, g);
                            DrawHelper.DrawRotatedArrow(lockedPipePen, middlePoint, PIPE_LENGTH, angleDegrees, 0.0f, drawFont.Size * -0.5, false /*e.CounterClockwise*/, g);
                        }

                        //drawind qs
                        int           angleSign = Math.Sign(angleDegrees);
                        GraphicsState state     = g.Save();
                        g.TranslateTransform(p1.X, p1.Y);
                        g.RotateTransform(angleDegrees);
                        PointF inOutStart = new PointF(-INOUTS_OFFSET, 0);
                        PointF inOutEnd   = new PointF(-INOUTS_OFFSET, INOUTS_LENGTH * angleSign);
                        g.DrawLine(inOutPen, inOutStart, inOutEnd);
                        g.TranslateTransform(inOutStart.X, inOutStart.Y);
                        g.RotateTransform(90 * angleSign);
                        Point pText = new Point(INOUTS_LENGTH, 0);
                        g.TranslateTransform(pText.X, pText.Y);
                        g.RotateTransform(180);
                        pText = new Point(0, 0);
                        g.DrawString(e.Qstart.ToString(), normalFont, inOutsBrush, pText);
                        g.Restore(state);

                        //drawing qe
                        state = g.Save();
                        g.TranslateTransform(p2.X, p2.Y);
                        g.RotateTransform(angleDegrees);
                        inOutStart = new PointF(INOUTS_OFFSET, 0);
                        inOutEnd   = new PointF(INOUTS_OFFSET, INOUTS_LENGTH * angleSign);
                        g.DrawLine(inOutPen, inOutStart, inOutEnd);
                        g.TranslateTransform(inOutStart.X, inOutStart.Y);
                        g.RotateTransform(90 * angleSign);
                        pText = new Point(INOUTS_LENGTH, 0);
                        g.TranslateTransform(pText.X, pText.Y);
                        g.RotateTransform(180);
                        pText = new Point(0, 0);
                        g.DrawString(e.Qend.ToString(), normalFont, inOutsBrush, pText);
                        g.Restore(state);
                    }
                }
            }
        }
Example #22
0
        public void HintGlyph(PointF[] glyphPoints, int[] contours, byte[] instructions)
        {
            if (instructions == null || instructions.Length == 0)
                return;

            // check if the CVT program disabled hinting
            if ((state.InstructionControl & InstructionControlFlags.InhibitGridFitting) != 0)
                return;

            // TODO: composite glyphs
            // TODO: round the phantom points?

            // save contours and points
            this.contours = contours;
            zp0 = zp1 = zp2 = points = new Zone(glyphPoints, isTwilight: false);

            // reset all of our shared state
            state = cvtState;
            callStackSize = 0;
            debugList.Clear();
            stack.Clear();
            OnVectorsUpdated();

            // normalize the round state settings
            switch (state.RoundState)
            {
                case RoundMode.Super: SetSuperRound(1.0f); break;
                case RoundMode.Super45: SetSuperRound(Sqrt2Over2); break;
            }

            Execute(new InstructionStream(instructions), false, false);
        }
Example #23
0
        DrawAxisLabels
        (
            String sXAxisLabel,
            String sYAxisLabel,
            String sYAxisLabelSecondary,
            Graphics oGraphics,
            Rectangle oChartRectangle,
            Rectangle oPlotRectangle,
            Font oFont,
            Color oXAxisLabelColor,
            Color oYAxisLabelColor,
            Color oYAxisLabelColorSecondary,
            Single fLabelHeightMultiple
        )
        {
            Debug.Assert(oGraphics != null);
            Debug.Assert(oChartRectangle.Width > 0);
            Debug.Assert(oChartRectangle.Height > 0);
            Debug.Assert(oPlotRectangle.Width > 0);
            Debug.Assert(oPlotRectangle.Height > 0);
            Debug.Assert(oFont != null);
            Debug.Assert(fLabelHeightMultiple >= 1F);

            SolidBrush   oLabelBrush   = new SolidBrush(Color.Black);
            Single       fLabelHeight  = oFont.GetHeight(oGraphics);
            StringFormat oStringFormat = new StringFormat();

            oStringFormat.Alignment     = StringAlignment.Center;
            oStringFormat.LineAlignment = StringAlignment.Center;

            if (sXAxisLabel != null)
            {
                // Draw the label for the x axis.  Center it horizontally within
                // the width of the plot rectangle.  Center it vertically within
                // the total space reserved for the label.

                oLabelBrush.Color = oXAxisLabelColor;

                oGraphics.DrawString(
                    sXAxisLabel,
                    oFont,
                    oLabelBrush,
                    oPlotRectangle.Left + oPlotRectangle.Width / 2,

                    oChartRectangle.Bottom
                    - (fLabelHeightMultiple * fLabelHeight) / 2,

                    oStringFormat
                    );
            }

            if (sYAxisLabel != null)
            {
                oLabelBrush.Color = oYAxisLabelColor;

                GraphicsState oGraphicsState = oGraphics.Save();

                // Translate the Graphics object so that a coordinate of (0,0) is
                // centered horizontally within the total space reserved for the
                // label, and vertically within the height of the plot rectangle.

                oGraphics.TranslateTransform(

                    oChartRectangle.Left +
                    (fLabelHeightMultiple * fLabelHeight) / 2,

                    oPlotRectangle.Top + oPlotRectangle.Height / 2
                    );

                // Force the text to be displayed vertically from bottom to top.
                // (Note: The StringFormatFlags.DirectionVertical flag causes text
                // to be displayed from top to bottom, which is why a transform is
                // used here instead.)

                oGraphics.RotateTransform(-90F);

                // Draw the label for the y axis.

                oGraphics.DrawString(sYAxisLabel, oFont, oLabelBrush,
                                     0, 0, oStringFormat);

                oGraphics.Restore(oGraphicsState);
            }

            if (sYAxisLabelSecondary != null)
            {
                oLabelBrush.Color = oYAxisLabelColorSecondary;

                GraphicsState oGraphicsState = oGraphics.Save();

                // Translate the Graphics object so that a coordinate of (0,0) is
                // centered horizontally within the total space reserved for the
                // label, and vertically within the height of the plot rectangle.

                oGraphics.TranslateTransform(

                    oChartRectangle.Right -
                    (fLabelHeightMultiple * fLabelHeight) / 2,

                    oPlotRectangle.Top + oPlotRectangle.Height / 2
                    );

                // Force the text to be displayed vertically from bottom to top.

                oGraphics.RotateTransform(-90F);

                // Draw the label for the y axis.

                oGraphics.DrawString(sYAxisLabelSecondary, oFont, oLabelBrush,
                                     0, 0, oStringFormat);

                oGraphics.Restore(oGraphicsState);
            }

            oLabelBrush.Dispose();
        }
        public int SaveHdc() 
        {
            HandleRef hdc = new HandleRef( this, this.Hdc);
            int state = IntUnsafeNativeMethods.SaveDC(hdc);

            if (contextStack == null) {
                contextStack = new Stack();
            }

            GraphicsState g = new GraphicsState();
            g.hBitmap = hCurrentBmp;
            g.hBrush  = hCurrentBrush;
            g.hPen    = hCurrentPen;            
            g.hFont   = hCurrentFont;

#if !DRAWING_NAMESPACE
            g.font    = new WeakReference(selectedFont);
#endif


            contextStack.Push(g);
                                   
#if TRACK_HDC
            Debug.WriteLine( DbgUtil.StackTraceToStr( String.Format("state[0]=DC.SaveHdc(hDc=0x{1:x8})", state, unchecked((int) this.hDC)) ));
#endif 

            return state;
        }
 public void Restore(GraphicsState gstate)
 {
     this.graphics.Restore(gstate);
     this.Transform = this.graphics.Transform;
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            if (_palette != null)
            {
                // Save the original state, so any changes we make are easy to undo
                GraphicsState state = e.Graphics.Save();

                // We want the inner part of the control to act like a button, so
                // we need to find the correct palette state based on if the mouse
                // is over the control and currently being pressed down or not.
                PaletteState buttonState = GetButtonState();

                /////////////////////////////////////////////////////
                // Get the various palette details needed to draw //
                // our fish in the various states we implement    //
                /////////////////////////////////////////////////////

                // Get the two colors and angle used to draw the control background
                Color backColor1     = _palette.GetBackColor1(PaletteBackStyle.PanelAlternate, Enabled ? PaletteState.Normal : PaletteState.Disabled);
                Color backColor2     = _palette.GetBackColor2(PaletteBackStyle.PanelAlternate, Enabled ? PaletteState.Normal : PaletteState.Disabled);
                float backColorAngle = _palette.GetBackColorAngle(PaletteBackStyle.PanelAlternate, Enabled ? PaletteState.Normal : PaletteState.Disabled);

                // Get the two colors and angle used to draw the fish area background
                Color fillColor1     = _palette.GetBackColor1(PaletteBackStyle.ButtonStandalone, buttonState);
                Color fillColor2     = _palette.GetBackColor2(PaletteBackStyle.ButtonStandalone, buttonState);
                float fillColorAngle = _palette.GetBackColorAngle(PaletteBackStyle.ButtonStandalone, buttonState);

                // Get the color used to draw the fish border
                Color borderColor = _palette.GetBorderColor1(PaletteBorderStyle.ButtonStandalone, buttonState);

                // Get the color and font used to draw the text
                Color textColor = _palette.GetContentShortTextColor1(PaletteContentStyle.ButtonStandalone, buttonState);
                Font  textFont  = _palette.GetContentShortTextFont(PaletteContentStyle.ButtonStandalone, buttonState);

                /////////////////////////////////////////////////////
                // Perform actual drawing using the palette values //
                /////////////////////////////////////////////////////

                // Populate a graphics path to describe the shape we want to draw
                using (GraphicsPath path = CreateFishPath())
                {
                    // We want to anti alias the drawing for nice smooth curves
                    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                    // Fill the entire background in the control background color
                    using (Brush backBrush = new LinearGradientBrush(ClientRectangle, backColor1, backColor2, backColorAngle))
                    {
                        e.Graphics.FillRectangle(backBrush, e.ClipRectangle);
                    }

                    // Fill the entire fish background using a gradient
                    using (Brush fillBrush = new LinearGradientBrush(ClientRectangle, fillColor1, fillColor2, fillColorAngle))
                    {
                        e.Graphics.FillPath(fillBrush, path);
                    }

                    // Draw the fish border using a single color
                    using (Pen borderPen = new Pen(borderColor))
                    {
                        e.Graphics.DrawPath(borderPen, path);
                    }

                    // Draw the text in about the center of the control
                    using (Brush textBrush = new SolidBrush(textColor))
                    {
                        e.Graphics.DrawString("Click me!", textFont, textBrush, Width / 2 - 10, Height / 2 - 5);
                    }
                }

                // Put graphics back into original state before returning
                e.Graphics.Restore(state);
            }

            base.OnPaint(e);
        }
Example #27
0
 public void Restore(GraphicsState gstate)
 {
     RenderingObject.Restore(gstate);
 }
Example #28
0
        private void DrawObjectCollider(Graphics g, TmxObject tmxObject, Color color)
        {
            Color brushColor = Color.FromArgb(128, color);

            using (Brush brush = new HatchBrush(HatchStyle.BackwardDiagonal, color, brushColor))
                using (Pen pen = new Pen(color))
                {
                    pen.Alignment = PenAlignment.Inset;

                    GraphicsState state = g.Save();

                    PointF xfPosition = TmxMath.ObjectPointFToMapSpace(this.tmxMap, tmxObject.Position);
                    g.TranslateTransform(xfPosition.X, xfPosition.Y);
                    g.RotateTransform(tmxObject.Rotation);

                    if (tmxObject.GetType() == typeof(TmxObjectPolygon))
                    {
                        DrawPolygon(g, pen, brush, tmxObject as TmxObjectPolygon);
                    }
                    else if (tmxObject.GetType() == typeof(TmxObjectRectangle))
                    {
                        if (this.tmxMap.Orientation == TmxMap.MapOrientation.Isometric)
                        {
                            TmxObjectPolygon tmxIsometricRectangle = TmxObjectPolygon.FromIsometricRectangle(this.tmxMap, tmxObject as TmxObjectRectangle);
                            DrawPolygon(g, pen, brush, tmxIsometricRectangle);
                        }
                        else
                        {
                            // Rectangles are polygons
                            DrawPolygon(g, pen, brush, tmxObject as TmxObjectPolygon);
                        }
                    }
                    else if (tmxObject.GetType() == typeof(TmxObjectEllipse))
                    {
                        DrawEllipse(g, pen, brush, tmxObject as TmxObjectEllipse);
                    }
                    else if (tmxObject.GetType() == typeof(TmxObjectPolyline))
                    {
                        DrawPolyline(g, pen, tmxObject as TmxObjectPolyline);
                    }
                    else if (tmxObject.GetType() == typeof(TmxObjectTile))
                    {
                        TmxObjectTile tmxObjectTile = tmxObject as TmxObjectTile;

                        RectangleF rcTile = new RectangleF();
                        rcTile.X    = 0;
                        rcTile.Y    = -tmxObjectTile.Tile.TileSize.Height;
                        rcTile.Size = tmxObjectTile.Tile.TileSize;

                        g.FillRectangle(brush, rcTile);
                        g.DrawRectangle(pen, rcTile.X, rcTile.Y, rcTile.Width - 1, rcTile.Height - 1);
                    }
                    else
                    {
                        g.Restore(state);
                        RectangleF bounds = tmxObject.GetWorldBounds();
                        g.FillRectangle(Brushes.Red, bounds.X, bounds.Y, bounds.Width, bounds.Height);
                        g.DrawRectangle(Pens.White, bounds.X, bounds.Y, bounds.Width, bounds.Height);
                        string message = String.Format("Unhandled object: {0}", tmxObject.GetNonEmptyName());
                        DrawString(g, message, bounds.X, bounds.Y);
                    }

                    // Restore our state
                    g.Restore(state);
                }
        }
Example #29
0
 public void Restore(GraphicsState gstate)
 {
     this.graphics.Restore(gstate);
 }
Example #30
0
 public static void RestoreGraphicsState(Graphics g, ref GraphicsState state)
 {
     g.Restore(state);
     state = g.Save();
 }
Example #31
0
        private float DrawLegend(Graphics g, AdvancedRect area)
        {
            // function returns the height necessary for the legend.

            GraphicsState _s = g.Save();

            g.SmoothingMode = SmoothingMode.AntiAlias;

            float maxWidth = 0, maxHeight = 0;
            List <LegendEntry> entries     = new List <LegendEntry>();
            List <string>      seriesNames = new List <string>();

            foreach (KeyValuePair <string, Series> kv in series)
            {
                foreach (LegendEntry entry in kv.Value.LegendEntries)
                {
                    entries.Add(entry);
                    seriesNames.Add(kv.Key);
                    SizeF sz = entry.CalculateSize(g, kv.Key);
                    maxWidth  = Math.Max(maxWidth, sz.Width);
                    maxHeight = Math.Max(maxHeight, sz.Height);
                }
            }

            //float totalWidth = maxWidth * entries.Count;
            int entriesPerRow = (int)Math.Floor(area.Width / maxWidth);

            if (entriesPerRow == 0)
            {
                entriesPerRow = 1;
            }
            else if (entriesPerRow > entries.Count)
            {
                entriesPerRow = entries.Count;
            }
            int numRows = (int)Math.Ceiling((float)entries.Count / entriesPerRow);
            //int entriesPerRow = (int)Math.Ceiling((float)entries.Count / numRows);

            float leftX = area.Center.X - ((float)entriesPerRow / 2) * maxWidth;

            for (int r = 0; r < numRows; r++)
            {
                for (int c = 0; c < entriesPerRow; c++)
                {
                    int idx = (r * entriesPerRow) + c;
                    if (idx >= entries.Count)
                    {
                        continue;
                    }

                    LegendEntry entry = entries[idx];
                    entry.Draw(g, new AdvancedRect(
                                   new PointF(leftX + (c * maxWidth), area.BottomRight.Y - (maxHeight * (numRows - r))),
                                   new PointF(leftX + ((c + 1) * maxWidth), area.BottomRight.Y - (maxHeight * (numRows - r - 1)))),
                               seriesNames[idx]
                               );
                }
            }

            g.Restore(_s); // turn off antialiasing

            /*
             * using (Pen p = legendBorder.CreatePen())
             * {
             *  g.DrawRectangle(p,
             *      area.Center.X - (width / 2), area.BottomRight.Y - height,
             *      width, height);
             * }
             */

            return(maxHeight * numRows);
        }
Example #32
0
 public override void Scan(GraphicsState state)
 {
 }
Example #33
0
        public void PaintOn(Graphics g, RectangleF _area)
        {
            GraphicsState _s = g.Save();

            // _area is assumed to be provided in the same coordinate system as
            // g.PageUnit provides.  The plotting library works assuming that
            // PageUnit is Inch, so we must transform the Rectangle into the
            // appropriate rect.
            PointF[] trans = new PointF[] {
                new PointF(_area.Left, _area.Top),
                new PointF(_area.Left + _area.Width, _area.Top + _area.Height)
            };
            g.TransformPoints(CoordinateSpace.Device, CoordinateSpace.Page, trans);
            g.PageUnit = GraphicsUnit.Inch;
            g.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, trans);
            AdvancedRect area = new AdvancedRect(trans[0], trans[1]);

            using (Brush bg = background.CreateBrush())
                g.FillRectangle(bg, area.Rect);

            outerMargins.Apply(ref area);

            //using (Brush tmp = new SolidBrush(Color.Red))
            //    g.FillRectangle(tmp, area.Rect);

            SizeF headerSize = new SizeF(0, 0);

            if (centerHeader != null)
            {
                using (Brush br = centerHeaderFont.CreateBrush())
                    using (Font f = centerHeaderFont.CreateFont())
                    {
                        headerSize = g.MeasureString(centerHeader, f);
                        g.DrawString(centerHeader, f, br, area.Center.X - (headerSize.Width / 2), area.TopLeft.Y);
                    }
            }
            if (rightHeader != null || leftHeader != null)
            {
                using (Brush left_br = leftHeaderFont.CreateBrush())
                    using (Font left_f = leftHeaderFont.CreateFont())
                        using (Brush right_br = rightHeaderFont.CreateBrush())
                            using (Font right_f = rightHeaderFont.CreateFont())
                            {
                                SizeF leftHeaderSize  = (leftHeader != null) ? g.MeasureString(leftHeader, left_f) : new SizeF(0, 0);
                                SizeF rightHeaderSize = (rightHeader != null) ? g.MeasureString(rightHeader, right_f) : new SizeF(0, 0);

                                // determine y location = is this going to be aligned to the bottom of the center
                                // header, or underneath it?  underneath is necessary if the two will hit each other.
                                float left_xLoc  = area.TopLeft.X;
                                float right_xLoc = area.BottomRight.X - rightHeaderSize.Width;
                                float left_yLoc;
                                float right_yLoc;
                                if ((right_xLoc - 0.2f) < (area.Center.X + (headerSize.Width / 2)) ||
                                    (left_xLoc + leftHeaderSize.Width + 0.2f) > (area.Center.X - (headerSize.Width / 2)))
                                {
                                    // looks like we're too close - have to move down a bit.
                                    left_yLoc          = right_yLoc = area.TopLeft.Y + headerSize.Height;
                                    headerSize.Height += Math.Max(rightHeaderSize.Height, leftHeaderSize.Height);
                                }
                                else
                                {
                                    // We're good to place it next to the header.
                                    // But, check our height - are the side headers bigger than the center header?
                                    if (rightHeaderSize.Height > headerSize.Height || leftHeaderSize.Height > headerSize.Height)
                                    {
                                        // the side headers are bigger than the center header.  Make enough room.
                                        headerSize.Height = Math.Max(leftHeaderSize.Height, rightHeaderSize.Height);
                                    }
                                    right_yLoc = area.TopLeft.Y + (headerSize.Height - rightHeaderSize.Height);
                                    left_yLoc  = area.TopLeft.Y + (headerSize.Height - leftHeaderSize.Height);
                                }
                                if (rightHeader != null)
                                {
                                    g.DrawString(rightHeader, right_f, right_br, right_xLoc, right_yLoc);
                                }
                                if (leftHeader != null)
                                {
                                    g.DrawString(leftHeader, left_f, left_br, left_xLoc, left_yLoc);
                                }
                            }
            }
            if (headerSize.Height != 0)
            {
                area.TopLeft.Y += headerSize.Height;
                area.TopLeft.Y += 0.1f;
            }

            if (displayLegend)
            {
                area.BottomRight.Y -= DrawLegend(g, area);
            }

            float yAxisWidthLeft  = yAxes.CalculateWidthLeft(g);
            float yAxisWidthRight = yAxes.CalculateWidthRight(g);
            float xAxisHeight     = xAxis.CalculateHeight(g, area.Width - yAxisWidthLeft - yAxisWidthRight);

            AdvancedRect xAxisArea = area.Clone();

            xAxisArea.TopLeft.X     += yAxisWidthLeft;
            xAxisArea.BottomRight.X -= yAxisWidthRight;
            xAxisArea.TopLeft.Y      = xAxisArea.BottomRight.Y - xAxisHeight;

            // calculate internal data area
            area.TopLeft.X     += yAxisWidthLeft;
            area.BottomRight.X -= yAxisWidthRight;
            area.BottomRight.Y -= xAxisHeight;

            yAxes.Draw(g, area);
            xAxis.DrawX(g, xAxisArea, area);

            series.Draw(g, yAxes, xAxis, area);

            annotations.Draw(g, area);

            using (Pen p = borderPen.CreatePen())
            {
                g.DrawLine(p, area.TopLeft.X, area.TopLeft.Y, area.TopLeft.X, area.BottomRight.Y);
                g.DrawLine(p, area.TopLeft.X, area.TopLeft.Y, area.BottomRight.X, area.TopLeft.Y);
                g.DrawLine(p, area.BottomRight.X, area.BottomRight.Y, area.BottomRight.X, area.TopLeft.Y);
                g.DrawLine(p, area.BottomRight.X, area.BottomRight.Y, area.TopLeft.X, area.BottomRight.Y);
            }

            dataArea = area;

            g.Restore(_s);
        }
Example #34
0
        private void Draw(SurfaceState s, SurfaceDrawInstance inst)
        {
            mDisplay.CheckInFrame("Surface.Draw");
            System.Diagnostics.Debug.Assert(mImage != null);

            Geometry.SizeF  displaySize    = s.GetDisplaySize(SurfaceSize);
            Geometry.PointF rotationCenter = s.GetRotationCenter(displaySize);

            Drawing_Display disp  = Display.Impl as Drawing_Display;
            Graphics        g     = disp.FrameGraphics;
            GraphicsState   state = g.Save();

            Geometry.PointF translatePoint = Origin.CalcF(s.DisplayAlignment, displaySize);

            if (displaySize.Width < 0)
            {
                translatePoint.X += displaySize.Width;
                rotationCenter.X += displaySize.Width;
            }
            if (displaySize.Height < 0)
            {
                translatePoint.Y += displaySize.Height;
                rotationCenter.Y += displaySize.Height;
            }

            if (s.RotationAngle != 0)
            {
                // translate to rotation point, rotate, and translate back.
                // System.Drawing rotates Clockwise!  So we must reverse the
                // rotation angle.
                g.TranslateTransform(-rotationCenter.X, -rotationCenter.Y, MatrixOrder.Append);
                g.RotateTransform(-(float)s.RotationAngleDegrees, MatrixOrder.Append);
                g.TranslateTransform(rotationCenter.X, rotationCenter.Y, MatrixOrder.Append);
            }

            g.TranslateTransform(inst.DestLocation.X - translatePoint.X,
                                 inst.DestLocation.Y - translatePoint.Y, MatrixOrder.Append);

            SetInterpolation(g);

            Geometry.Rectangle srcRect = inst.GetSourceRect(SurfaceSize);

            if (s.Color != Geometry.Color.White)
            {
                ImageAttributes imageAttributes = new ImageAttributes();

                ColorMatrix colorMatrix = new ColorMatrix(new float[][] {
                    new float[] { s.Color.R / 255.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, s.Color.G / 255.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, s.Color.B / 255.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, 0.0f, (float)s.Alpha, 0.0f },
                    new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                });

                imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                g.DrawImage(mImage, Interop.Convert(DestRect(0, 0, srcRect, s.ScaleWidth, s.ScaleHeight)),
                            srcRect.X,
                            srcRect.Y,
                            srcRect.Width,
                            srcRect.Height,
                            GraphicsUnit.Pixel,
                            imageAttributes);
            }
            else
            {
                g.DrawImage(mImage, Interop.Convert(DestRect(0, 0, srcRect, s.ScaleWidth, s.ScaleHeight)),
                            srcRect.X,
                            srcRect.Y,
                            srcRect.Width,
                            srcRect.Height,
                            GraphicsUnit.Pixel);
            }

            g.Restore(state);
        }
Example #35
0
 internal XGraphicsContainer(GraphicsState state)
 {
     GdiState = state;
 }
 public int SaveHdc()
 {
     HandleRef hDC = new HandleRef(this, this.Hdc);
     int num = IntUnsafeNativeMethods.SaveDC(hDC);
     if (this.contextStack == null)
     {
         this.contextStack = new Stack();
     }
     GraphicsState state = new GraphicsState {
         hBitmap = this.hCurrentBmp,
         hBrush = this.hCurrentBrush,
         hPen = this.hCurrentPen,
         hFont = this.hCurrentFont,
         font = new WeakReference(this.selectedFont)
     };
     this.contextStack.Push(state);
     return num;
 }
Example #37
0
 /**
  * Create an ImageRenderInfo object based on an XObject (this is the most common way of including an image in PDF)
  * @param ctm the coordinate transformation matrix at the time the image is rendered
  * @param ref a reference to the image XObject
  * @return the ImageRenderInfo representing the rendered XObject
  * @since 5.0.1
  */
 public static ImageRenderInfo CreateForXObject(GraphicsState gs, PdfIndirectReference refi, PdfDictionary colorSpaceDictionary)
 {
     return new ImageRenderInfo(gs, refi, colorSpaceDictionary);
 }
Example #38
0
 public void Restore(GraphicsState gstate)
 {
     SetStatus(GdiPlus.GdipRestoreGraphics(nativeGraphics, gstate));
 }
Example #39
0
 /**
  * Copy constructor.
  * @param source    another GraphicsState object
  */
 public GraphicsState(GraphicsState source){
     // note: all of the following are immutable, with the possible exception of font
     // so it is safe to copy them as-is
     ctm = source.ctm;
     characterSpacing = source.characterSpacing;
     wordSpacing = source.wordSpacing;
     horizontalScaling = source.horizontalScaling;
     leading = source.leading;
     font = source.font;
     fontSize = source.fontSize;
     renderMode = source.renderMode;
     rise = source.rise;
     knockout = source.knockout;
 }
Example #40
0
 /**
  * Create an ImageRenderInfo object based on inline image data.  This is nowhere near completely thought through
  * and really just acts as a placeholder.
  * @param ctm the coordinate transformation matrix at the time the image is rendered
  * @param imageObject the image object representing the inline image
  * @return the ImageRenderInfo representing the rendered embedded image
  * @since 5.0.1
  */
 protected internal static ImageRenderInfo CreateForEmbeddedImage(GraphicsState gs, InlineImageInfo inlineImageInfo, PdfDictionary colorSpaceDictionary)
 {
     ImageRenderInfo renderInfo = new ImageRenderInfo(gs, inlineImageInfo, colorSpaceDictionary);
     return renderInfo;
 }
Example #41
0
        public override void OnDraw(Graphics g)
        {
            SizeF szText     = g.MeasureString(text, font);
            Brush _textBrush = new SolidBrush(Color);
            SizeF szText2    = new SizeF(TextBoxSize.Width, TextBoxSize.Height);

            if (szText2.Height < szText.Height)
            {
                szText2.Height = szText.Height;
            }
            if (szText2.Height > Rectangle.Height)
            {
                szText2.Height = Rectangle.Height;
            }
            //create big rectangle from half of text height
            float topx    = szText2.Height / 2F;
            float heightx = Rectangle.Height - topx;             //it will be greater than or equal to half the text box height
            float txtLeft = Rectangle.Width - szText2.Width;

            if (txtLeft < 0)
            {
                txtLeft = 0;
            }
            else
            {
                txtLeft = txtLeft / 2F;
            }
            if (RotateAngle == 0)
            {
                Rectangle    rc   = new Rectangle(Rectangle.X, Rectangle.Top + (int)topx, Rectangle.Width, (int)heightx);
                GraphicsPath path = getGraphicsPath(rc, this.CornerRadius);
                if (Fill)
                {
                    g.FillPath(new SolidBrush(FillColor), path);
                }
                else
                {
                    g.DrawPath(new Pen(this.Color, this.LineWidth), path);
                }
                Rectangle rcTxtBox = new Rectangle(Rectangle.X + (int)txtLeft, Rectangle.Top, (int)szText2.Width, (int)szText2.Height);
                path = getGraphicsPath(rcTxtBox, _cornerRadius);
                if (_useFormBackGroundColor)
                {
                    if (Page != null)
                    {
                        g.FillPath(new SolidBrush(Page.BackColor), path);
                    }
                    else
                    {
                        g.FillPath(new SolidBrush(this.TextBackColor), path);
                    }
                }
                else
                {
                    g.FillPath(new SolidBrush(this.TextBackColor), path);
                }
                float x = rcTxtBox.Width - szText.Width;
                if (x < 0)
                {
                    x = rcTxtBox.X;
                }
                else
                {
                    x = rcTxtBox.X + x / 2F;
                }
                float y = rcTxtBox.Height - szText.Height;
                if (y < 0)
                {
                    y = rcTxtBox.Y;
                }
                else
                {
                    y = rcTxtBox.Y + y / 2F;
                }
                g.DrawString(text, font, _textBrush, x, y);
            }
            else
            {
                GraphicsState transState = g.Save();
                double        angle      = (RotateAngle / 180) * Math.PI;
                Rectangle     rc         = this.Rectangle;
                //
                g.TranslateTransform(
                    (rc.Width + (float)(rc.Height * Math.Sin(angle)) - (float)(rc.Width * Math.Cos(angle))) / 2 + rc.X,
                    (rc.Height - (float)(rc.Height * Math.Cos(angle)) - (float)(rc.Width * Math.Sin(angle))) / 2 + rc.Y);
                g.RotateTransform((float)RotateAngle);

                Rectangle    rcx  = new Rectangle(0, (int)topx, rc.Width, (int)heightx);
                GraphicsPath path = getGraphicsPath(rcx, this.CornerRadius);
                if (Fill)
                {
                    g.FillPath(new SolidBrush(FillColor), path);
                }
                else
                {
                    g.DrawPath(new Pen(this.Color, this.LineWidth), path);
                }
                Rectangle rcTxtBox = new Rectangle((int)txtLeft, 0, (int)szText2.Width, (int)szText2.Height);
                path = getGraphicsPath(rcTxtBox, _cornerRadius);
                if (_useFormBackGroundColor)
                {
                    if (Page != null)
                    {
                        g.FillPath(new SolidBrush(Page.BackColor), path);
                    }
                    else
                    {
                        g.FillPath(new SolidBrush(this.TextBackColor), path);
                    }
                }
                else
                {
                    g.FillPath(new SolidBrush(this.TextBackColor), path);
                }
                float x = rcTxtBox.Width - szText.Width;
                if (x < 0)
                {
                    x = rcTxtBox.X;
                }
                else
                {
                    x = rcTxtBox.X + x / 2F;
                }
                float y = rcTxtBox.Height - szText.Height;
                if (y < 0)
                {
                    y = rcTxtBox.Y;
                }
                else
                {
                    y = rcTxtBox.Y + y / 2F;
                }
                g.DrawString(text, font, _textBrush, x, y);
                g.Restore(transState);
            }
        }
Example #42
0
        /**
         * Copy constructor.
         * @param source    another GraphicsState object
         */
        public GraphicsState(GraphicsState source){
            // note: all of the following are immutable, with the possible exception of font
            // so it is safe to copy them as-is
            ctm = source.ctm;
            characterSpacing = source.characterSpacing;
            wordSpacing = source.wordSpacing;
            horizontalScaling = source.horizontalScaling;
            leading = source.leading;
            font = source.font;
            fontSize = source.fontSize;
            renderMode = source.renderMode;
            rise = source.rise;
            knockout = source.knockout;
            colorSpaceFill = source.colorSpaceFill;
            colorSpaceStroke = source.colorSpaceStroke;
            fillColor = source.fillColor;
            strokeColor = source.strokeColor;
            lineWidth = source.lineWidth;
            lineCapStyle = source.lineCapStyle;
            lineJoinStyle = source.lineJoinStyle;
            miterLimit = source.miterLimit;

            if (source.lineDashPattern != null) {
                lineDashPattern = new LineDashPattern(source.lineDashPattern.DashArray, source.lineDashPattern.DashPhase);
            }
        }
Example #43
0
        public void CreateBarcode(Graphics g)
        {
            //g.DrawString("Code 39", new Font("Vendana", 9), Brushes.Blue, barcodeRect);
            g.SetClip(barcodeRect);
            GraphicsState state             = g.Save();
            Matrix        RotationTransform = new Matrix(1, 0, 0, 1, 1, 1); //rotation matrix

            PointF TheRotationPoint;

            switch (Rotation)
            {
            case BarcodeRotation.Rotation90:
                TheRotationPoint = new PointF(barcodeRect.X, barcodeRect.Y);
                RotationTransform.RotateAt(90, TheRotationPoint);
                g.Transform = RotationTransform;
                g.TranslateTransform(0, -barcodeRect.Width);
                break;

            case BarcodeRotation.Rotation270:
                TheRotationPoint = new PointF(barcodeRect.X, barcodeRect.Y + barcodeRect.Height);
                RotationTransform.RotateAt(270, TheRotationPoint);
                g.Transform = RotationTransform;
                g.TranslateTransform(0, barcodeRect.Height);
                break;
            }

            int encodedStringLength = encodedString.Length;

            int x    = (int)barcodeRect.X;
            int wid  = 0;
            int yTop = (int)barcodeRect.Y;

            yTop = (int)barcodeRect.Y;

            if (bShowText)
            {
                using (StringFormat sf = new StringFormat())
                {
                    switch (align)
                    {
                    case BarcodeTextAlign.Left:
                        sf.Alignment = StringAlignment.Near;
                        break;

                    case BarcodeTextAlign.Center:
                        sf.Alignment = StringAlignment.Center;
                        break;

                    case BarcodeTextAlign.Right:
                        sf.Alignment = StringAlignment.Far;
                        break;
                    }
                    switch (Rotation)
                    {
                    case BarcodeRotation.Rotation90:
                        break;

                    case BarcodeRotation.Rotation270:
                        break;
                    }
                    if (bShowTextOnTop)
                    {
                        //yTop += height;
                        if (Rotation == BarcodeRotation.Rotation0)
                        {
                            g.DrawString(code, textFont, Brushes.Black, new RectangleF(barcodeRect.X, yTop, barcodeRect.Width, g.MeasureString("s", textFont).Height), sf);
                        }
                        else
                        {
                            g.DrawString(code, textFont, Brushes.Black, new RectangleF(barcodeRect.X, yTop, barcodeRect.Height, g.MeasureString("s", textFont).Height), sf);
                        }
                        yTop += Convert.ToInt32(g.MeasureString("s", textFont).Height);
                    }
                    else
                    {
                        yTop += height;
                        if (Rotation == BarcodeRotation.Rotation0)
                        {
                            g.DrawString(code, textFont, Brushes.Black, new RectangleF(barcodeRect.X, yTop, barcodeRect.Width, barcodeRect.Height - height), sf);
                        }
                        else
                        {
                            g.DrawString(code, textFont, Brushes.Black, new RectangleF(barcodeRect.X, yTop, barcodeRect.Height, barcodeRect.Width), sf);
                        }
                        yTop -= height;
                    }
                }
            }
            for (int i = 0; i < encodedStringLength; i++)
            {
                if (encodedString[i] == '1')
                {
                    wid = (int)(wideToNarrowRatio * (int)weight + 0.5);
                    g.FillRectangle(Brushes.Black, x, yTop, wid, height);
                }
                else
                {
                    wid = (int)(wideToNarrowRatio * (int)weight + 0.5);
                }


                x += wid;
            }
            g.Restore(state);
            g.ResetClip();
        }
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            TransparentInPaint(e.Graphics);
            e.Graphics.SmoothingMode     = SmoothingMode.HighQuality;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            Rectangle    rect = Shrink(new Rectangle(0, 0, this.Width, this.Height), 3);
            GraphicsPath path = new GraphicsPath();

            e.Graphics.FillEllipse(new SolidBrush(outerColor), new Rectangle(0, 0, this.Width, this.Height));
            path.AddEllipse(rect);
            PathGradientBrush pgb1 = new PathGradientBrush(path);

            pgb1.CenterColor    = this._endColor;
            pgb1.SurroundColors = new Color[] { this._mainColor };
            pgb1.FocusScales    = new PointF(_focus - _focusEffects, _focus - _focusEffects);
            e.Graphics.FillEllipse(pgb1, rect);
            Rectangle    small = Shrink(rect, (int)(rect.Width * shrink));
            GraphicsPath p2    = new GraphicsPath();

            p2.AddEllipse(small);
            if (!_mouseDown)
            {
                PathGradientBrush pgb = new PathGradientBrush(p2);
                pgb.CenterColor    = Color.FromArgb(0, this._mainColor);
                pgb.SurroundColors = new Color[] { this._mainColor };
                pgb.CenterPoint    = new PointF(small.Left, small.Top);
                pgb.FocusScales    = new PointF(focusScales, focusScales);
                e.Graphics.FillEllipse(pgb, small);
            }
            else
            {
                LinearGradientBrush lgb2 = new LinearGradientBrush(small, _mainColor, _endColor, 225);

                e.Graphics.FillEllipse(lgb2, small);
            }
            GraphicsState state = e.Graphics.Save();

            e.Graphics.SetClip(p2);
            if (_icoImage != null && _text != "")
            {
                float side = Side(small) / 3f;
                float left = small.Left + small.Width / 2f - side / 2f;
                float top  = small.Top + small.Height / 2f - side;
                e.Graphics.DrawImage(_icoImage, new RectangleF(left, top, side, side),
                                     new RectangleF(0, 0, _icoImage.Width, _icoImage.Height),
                                     GraphicsUnit.Pixel);

                Size s = TextRenderer.MeasureText(_text, base.Font);
                e.Graphics.DrawString(_text, base.Font, new SolidBrush(_fontColor),
                                      new PointF(small.Left + small.Width / 2f - s.Width / 2,
                                                 small.Top + small.Height / 2f));
            }
            else
            {
                if (_text != "")
                {
                    Size s = TextRenderer.MeasureText(_text, base.Font);
                    e.Graphics.DrawString(_text, base.Font, new SolidBrush(_fontColor),
                                          new PointF(small.Left + small.Width / 2f - s.Width / 2,
                                                     small.Top + small.Height / 2f - s.Height / 2));
                }
                if (_icoImage != null)
                {
                    float side = Side(small) / 3f;
                    float left = small.Left + small.Width / 2f - side / 2f;
                    float top  = small.Top + small.Height / 2f - side / 2f;
                    e.Graphics.DrawImage(_icoImage, new RectangleF(left, top, side, side),
                                         new RectangleF(0, 0, _icoImage.Width, _icoImage.Height),
                                         GraphicsUnit.Pixel);
                }
            }

            e.Graphics.Restore(state);

            e.Graphics.DrawEllipse(new Pen(_borderColor, 1), rect);
            e.Graphics.DrawEllipse(new Pen(_borderColor, 1), small);


            base.OnPaint(e);
        }
Example #45
0
 public override void Scan(GraphicsState state)
 {
     state.MiterLimit = Value;
 }
Example #46
0
 GpStatus Restore(GraphicsState gstate)
 {
     return SetStatus(NativeMethods.GdipRestoreGraphics(nativeGraphics,
                                                      gstate));
 }
Example #47
0
        /// <summary>
        /// Draws the shape's shadow.
        /// </summary>
        /// <remarks>
        /// The shadow is replaced with a glow.
        /// </remarks>
        protected override void DoPaintShadow(DiagramPaintEventArgs e, IGeometryHost geometryHost)
        {
            Guard.NotNull(() => geometryHost, geometryHost);
            Guard.NotNull(() => e, e);

            Graphics      graphics     = e.Graphics;
            GraphicsState state        = graphics.Save();
            SizeD         shadowOffset = this.ShadowOffset;

            try
            {
                GraphicsPath shapePath      = this.GetPath(geometryHost);
                RectangleF   shapeRectangle = shapePath.GetBounds();

                // Create shadow path
                GraphicsPath shadowPath = shapePath.Clone() as GraphicsPath;

                // Enlarge the shadow (by fixed magnifier amount)
                using (Matrix scaleMatrix = new Matrix())
                {
                    scaleMatrix.Scale(
                        (ShadowMagnifier / shapeRectangle.Width) + 1,
                        (ShadowMagnifier / shapeRectangle.Height) + 1);
                    shadowPath.Transform(scaleMatrix);

                    // Center shadow back on the shape
                    RectangleF shadowRectangle = shadowPath.GetBounds();
                    scaleMatrix.Reset();
                    scaleMatrix.Translate(
                        -((shadowRectangle.X + (shadowRectangle.Width / 2)) - (shapeRectangle.X + (shapeRectangle.Width / 2))),
                        -((shadowRectangle.Y + (shadowRectangle.Height / 2)) - (shapeRectangle.Y + (shapeRectangle.Height / 2))));
                    shadowPath.Transform(scaleMatrix);
                }

                // Set the clip region (on the shape)
                using (Region clip = graphics.Clip)
                {
                    graphics.SetClip(shapePath);

                    // Offset the shadow path (move diagonally down-right) from shape
                    using (Matrix translateMatrix = new Matrix())
                    {
                        translateMatrix.Translate((float)shadowOffset.Width, (float)shadowOffset.Height);
                        shadowPath.Transform(translateMatrix);
                    }

                    // Mask-off the shadow from the original shape
                    graphics.SetClip(shadowPath, CombineMode.Complement);
                    graphics.SetClip(clip, CombineMode.Intersect);

                    // Fill the shadow
                    using (PathGradientBrush shadowBrush = new PathGradientBrush(shadowPath))
                    {
                        shadowBrush.CenterColor    = Color.FromArgb(ShadowColorOpacity, ShadowColor);
                        shadowBrush.SurroundColors = new Color[] { Color.Transparent };
                        shadowBrush.FocusScales    = new PointF(ShadowGradientFocalPoint, ShadowGradientFocalPoint);
                        graphics.FillPath(shadowBrush, shadowPath);
                        graphics.ResetClip();
                    }
                }
            }
            finally
            {
                graphics.Restore(state);
            }
        }
Example #48
0
 internal static extern GpStatus GdipSaveGraphics(GpGraphics graphics, out GraphicsState state);
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     GraphicsState gs = processor.gsStack.Peek();
     GraphicsState copy = new GraphicsState(gs);
     processor.gsStack.Push(copy);
 }