예제 #1
0
 public void LoadFrom(AppEnvironment appEnvironment)
 {
     this.textAlignment            = appEnvironment.textAlignment;
     this.gradientInfo             = appEnvironment.gradientInfo.Clone();
     this.fontSmoothing            = appEnvironment.fontSmoothing;
     this.fontInfo                 = appEnvironment.fontInfo.Clone();
     this.penInfo                  = appEnvironment.penInfo.Clone();
     this.brushInfo                = appEnvironment.brushInfo.Clone();
     this.primaryColor             = appEnvironment.primaryColor;
     this.secondaryColor           = appEnvironment.secondaryColor;
     this.alphaBlending            = appEnvironment.alphaBlending;
     this.shapeDrawType            = appEnvironment.shapeDrawType;
     this.antiAliasing             = appEnvironment.antiAliasing;
     this.colorPickerClickBehavior = appEnvironment.colorPickerClickBehavior;
     this.resamplingAlgorithm      = appEnvironment.resamplingAlgorithm;
     this.tolerance                = appEnvironment.tolerance;
     PerformAllChanged();
 }
예제 #2
0
 public void LoadFrom(ToolEnvironment toolEnvironment)
 {
     this.textAlignment            = toolEnvironment.textAlignment;
     this.gradientInfo             = toolEnvironment.gradientInfo.Clone();
     this.fontSmoothing            = toolEnvironment.fontSmoothing;
     this.fontInfo                 = toolEnvironment.fontInfo.Clone();
     this.penInfo                  = toolEnvironment.penInfo.Clone();
     this.brushInfo                = toolEnvironment.brushInfo.Clone();
     this.primaryColor             = toolEnvironment.primaryColor;
     this.secondaryColor           = toolEnvironment.secondaryColor;
     this.alphaBlending            = toolEnvironment.alphaBlending;
     this.shapeDrawType            = toolEnvironment.shapeDrawType;
     this.antiAliasing             = toolEnvironment.antiAliasing;
     this.colorPickerClickBehavior = toolEnvironment.colorPickerClickBehavior;
     this.resamplingAlgorithm      = toolEnvironment.resamplingAlgorithm;
     this.tolerance                = toolEnvironment.tolerance;
     this.selectionCombineMode     = toolEnvironment.selectionCombineMode;
     this.floodMode                = toolEnvironment.floodMode;
     this.selectionDrawModeInfo    = toolEnvironment.selectionDrawModeInfo.Clone();
     PerformAllChanged();
 }
예제 #3
0
        public void SetToDefaults()
        {
            this.antiAliasing = true;
            this.fontSmoothing = FontSmoothing.Smooth;
            this.primaryColor = ColorBgra.FromBgra(0, 0, 0, 255);
            this.secondaryColor = ColorBgra.FromBgra(255, 255, 255, 255);
            this.gradientInfo = new GradientInfo(GradientType.LinearClamped, false);
            this.penInfo = new PenInfo(PenInfo.DefaultDashStyle, 2.0f, PenInfo.DefaultLineCap, PenInfo.DefaultLineCap, PenInfo.DefaultCapScale);
            this.brushInfo = new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);

            try
            {
                this.fontInfo = new FontInfo(new FontFamily("Arial"), 12, FontStyle.Regular);
            }

            catch (Exception)
            {
                this.fontInfo = new FontInfo(new FontFamily(GenericFontFamilies.SansSerif), 12, FontStyle.Regular);
            }

            this.textAlignment = TextAlignment.Left;
            this.shapeDrawType = ShapeDrawType.Outline;
            this.alphaBlending = true;
            this.tolerance = 0.5f;

            this.colorPickerClickBehavior = ColorPickerClickBehavior.NoToolSwitch;
            this.resamplingAlgorithm = ResamplingAlgorithm.Bilinear;
            this.selectionCombineMode = CombineMode.Replace;
            this.floodMode = FloodMode.Local;
            this.selectionDrawModeInfo = SelectionDrawModeInfo.CreateDefault();
        }
예제 #4
0
 public void LoadFrom(AppEnvironment appEnvironment)
 {
     this.textAlignment = appEnvironment.textAlignment;
     this.gradientInfo = appEnvironment.gradientInfo.Clone();
     this.fontSmoothing = appEnvironment.fontSmoothing;
     this.fontInfo = appEnvironment.fontInfo.Clone();
     this.penInfo = appEnvironment.penInfo.Clone();
     this.brushInfo = appEnvironment.brushInfo.Clone();
     this.primaryColor = appEnvironment.primaryColor;
     this.secondaryColor = appEnvironment.secondaryColor;
     this.alphaBlending = appEnvironment.alphaBlending;
     this.shapeDrawType = appEnvironment.shapeDrawType;
     this.antiAliasing = appEnvironment.antiAliasing;
     this.colorPickerClickBehavior = appEnvironment.colorPickerClickBehavior;
     this.resamplingAlgorithm = appEnvironment.resamplingAlgorithm;
     this.tolerance = appEnvironment.tolerance;
     this.selectionCombineMode = appEnvironment.selectionCombineMode;
     this.floodMode = appEnvironment.floodMode;
     this.selectionDrawModeInfo = appEnvironment.selectionDrawModeInfo.Clone();
     PerformAllChanged();
 }
예제 #5
0
        /// <summary>
        /// Renders text with the given graphics context, font, string, location, and anti-aliasing flag.
        /// </summary>
        /// <param name="g">The Graphics context to render to.</param>
        /// <param name="font">The Font to render with.</param>
        /// <param name="text">The string of text to draw.</param>
        /// <param name="pt">The offset of where to start drawing (upper-left of rendering rectangle).</param>
        /// <param name="antiAliasing">Whether the font should be rendered with anti-aliasing.</param>
        public static void DrawText(Graphics g, Font font, string text, Point pt, bool antiAliasing, FontSmoothing fontSmoothing)
        {
            if (fontSmoothing == FontSmoothing.Smooth && antiAliasing)
            {
                PixelOffsetMode oldPOM = g.PixelOffsetMode;
                g.PixelOffsetMode = PixelOffsetMode.Half;

                TextRenderingHint oldTRH = g.TextRenderingHint;
                g.TextRenderingHint = TextRenderingHint.AntiAlias;

                StringFormat format = (StringFormat)StringFormat.GenericTypographic.Clone();
                format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;

                g.DrawString(text, font, Brushes.Black, pt, format);

                g.PixelOffsetMode = oldPOM;
                g.TextRenderingHint = oldTRH;
            }
            else if (fontSmoothing == FontSmoothing.Sharp || !antiAliasing)
            {
                IntPtr hdc = IntPtr.Zero;
                IntPtr hFont = IntPtr.Zero;
                IntPtr hOldObject = IntPtr.Zero;

                try
                {
                    hdc = g.GetHdc();
                    hFont = CreateFontObject(font, antiAliasing);
                    hOldObject = SafeNativeMethods.SelectObject(hdc, hFont);

                    NativeStructs.RECT rect = new NativeStructs.RECT();
                    rect.left = pt.X;
                    rect.top = pt.Y;
                    rect.right = rect.left;
                    rect.bottom = rect.top;

                    int result = SafeNativeMethods.DrawTextW(
                        hdc,
                        text,
                        text.Length,
                        ref rect,
                        NativeConstants.DT_LEFT |
                            NativeConstants.DT_NOCLIP |
                            NativeConstants.DT_NOPREFIX |
                            NativeConstants.DT_SINGLELINE |
                            NativeConstants.DT_TOP);

                    if (result == 0)
                    {
                        NativeMethods.ThrowOnWin32Error("DrawTextW returned 0");
                    }
                }

                finally
                {
                    if (hOldObject != IntPtr.Zero)
                    {
                        SafeNativeMethods.SelectObject(hdc, hOldObject);
                        hOldObject = IntPtr.Zero;
                    }

                    if (hFont != IntPtr.Zero)
                    {
                        SafeNativeMethods.DeleteObject(hFont);
                        hFont = IntPtr.Zero;
                    }

                    if (hdc != IntPtr.Zero)
                    {
                        g.ReleaseHdc(hdc);
                        hdc = IntPtr.Zero;
                    }
                }
            }
            else
            {
                throw new InvalidEnumArgumentException("fontSmoothing = " + (int)fontSmoothing);
            }
        }
예제 #6
0
        private void DrawFunction(PaintEventArgs e)
        {
            //Define font
            //Define string
            string drawText = "ABC";
            //Define XY
            Point pt = new Point(0, 0);
            //Define anti
            bool antiAliasing = false;
            //Define Smoothing
            FontSmoothing smoothType = FontSmoothing.Sharp;

            //Fonts.DrawText(e.Graphics, font, "A", new Point(0, 0), false, FontSmoothing.Sharp);

            // Panel handle
            IntPtr destDC     = IntPtr.Zero;
            IntPtr hOldObject = IntPtr.Zero;
            IntPtr dcMemery   = IntPtr.Zero;
            IntPtr pbitmap    = IntPtr.Zero;
            //IntPtr pTemp = IntPtr.Zero;
            Graphics g = e.Graphics;

            NativeStructs.RECT destBounds = new NativeStructs.RECT();
            destBounds.left   = 0;
            destBounds.top    = 0;
            destBounds.bottom = 20;
            destBounds.right  = 20;

            destDC = g.GetHdc();

            //pTemp = SafeNativeMethods.CreateCompatibleDC(destDC);
            dcMemery = SafeNativeMethods.CreateCompatibleDC(destDC);

            // Font
            Font   font  = new Font("宋体", 10.0f, FontStyle.Regular, GraphicsUnit.Pixel);
            IntPtr hFont = IntPtr.Zero;

            hFont = Fonts.CreateFontObject(font, antiAliasing);
            SafeNativeMethods.SelectObject(dcMemery, hFont);


            pbitmap = SafeNativeMethods.CreateCompatibleBitmap(destDC, 20, 20);

            SafeNativeMethods.SelectObject(dcMemery, pbitmap);

            NativeStructs.RGBQUAD rgb = new NativeStructs.RGBQUAD();
            rgb.rgbBlue = 255;

            NativeStructs.RGBQUAD rgbBG = new NativeStructs.RGBQUAD();
            rgbBG.rgbBlue  = 0;
            rgbBG.rgbRed   = 0;
            rgbBG.rgbGreen = 0;

            //Graphics gSource = new Graphics();
            //gSource.
            //IntPtr gPtr = gSource.GetHdc();
            //gPtr = dcMemery;
            //gSource

            SafeNativeMethods.SetTextColor(dcMemery, rgb);
            SafeNativeMethods.SetBkColor(dcMemery, rgbBG);
            SafeNativeMethods.DrawTextW(dcMemery, drawText, drawText.Length, ref destBounds, NativeConstants.DT_CENTER);

            //SafeNativeMethods.TransparentBlt(pTemp, destBounds.left, destBounds.top, destBounds.right, destBounds.bottom, dcMemery, destBounds.left, destBounds.top, destBounds.right, destBounds.bottom, 0);

            SafeNativeMethods.StretchBlt(destDC, 0, 0, 20 * 10, 20 * 10, dcMemery, 0, 0, 20, 20, NativeConstants.SRCCOPY);

            //dcMemery.

            //pbitmap = bit.GetHbitmap();

            //dcMemery = SafeNativeMethods.CreateCompatibleBitmap(pdc, 20, 20);


            //SafeNativeMethods.

            //hFont = CreateFontObject(font, antiAliasing);
            //hOldObject = SafeNativeMethods.SelectObject(pdc, hFont);



            //SafeNativeMethods.CreateCompatibleDC(pdc);
            //uint result1 = SafeNativeMethods.StretchBlt(
            //    0,
            //    0,
            //    20,
            //    20,
            //    pdc,
            //    0,
            //    0,
            //    20 * 1000,
            //    20 * 1000,
            //    NativeConstants.SRCCOPY);
        }