예제 #1
0
        protected static RectDouble?TryGetInsetInteriorFillBounds(RectDouble bounds, double penWidth)
        {
            double left   = bounds.Left + penWidth;
            double top    = bounds.Top + penWidth;
            double right  = bounds.Right - penWidth;
            double bottom = bounds.Bottom - penWidth;

            if ((left <= right) && (top <= bottom))
            {
                return(new RectDouble?(RectDouble.FromEdges(left, top, right, bottom)));
            }
            return(null);
        }
예제 #2
0
        protected static RectDouble?TryGetInsetOutlineDrawBounds(RectDouble bounds, double penWidth)
        {
            double num    = penWidth / 2.0;
            double left   = bounds.Left + num;
            double top    = bounds.Top + num;
            double right  = bounds.Right - num;
            double bottom = bounds.Bottom - num;

            if ((left <= right) && (top <= bottom))
            {
                return(new RectDouble?(RectDouble.FromEdges(left, top, right, bottom)));
            }
            return(null);
        }
예제 #3
0
        private PlacedBitmap CreateFontPreview(string gdiFontName, float fontSize, PaintDotNet.UI.Media.Brush textBrush)
        {
            FontProperties  fontProperties;
            TextMetrics     metrics;
            OverhangMetrics overhangMetrics;

            try
            {
                fontProperties = this.fontMap.GetFontProperties(gdiFontName);
                using (IDrawingContext context = DrawingContext.CreateNull(FactorySource.PerThread))
                {
                    TextLayoutAlgorithm?layoutAlgorithm        = null;
                    TextLayout          resourceSource         = UIText.CreateLayout(context, this.fontSampleText, fontProperties, (double)fontSize, layoutAlgorithm, HotkeyRenderMode.Ignore, 65535.0, 65535.0);
                    ITextLayout         cachedOrCreateResource = context.GetCachedOrCreateResource <ITextLayout>(resourceSource);
                    metrics         = cachedOrCreateResource.Metrics;
                    overhangMetrics = cachedOrCreateResource.OverhangMetrics;
                }
            }
            catch (Exception exception)
            {
                if ((!(exception is NoFontException) && !(exception is FontFileAccessException)) && (!(exception is FontFileFormatException) && !(exception is FontFileNotFoundException)))
                {
                    throw;
                }
                Surface     cleanupObject = Surface.CopyFromGdipImage(PdnResources.GetImageResource("Icons.WarningIcon.png").Reference);
                BitmapProxy proxy         = new BitmapProxy(cleanupObject.CreateAliasedImagingBitmap(), ObjectRefProxyOptions.AssumeOwnership);
                proxy.AddCleanupObject(cleanupObject);
                return(new PlacedBitmap(proxy, new RectDouble(0.0, 0.0, (double)proxy.Size.Width, (double)proxy.Size.Height), true));
            }
            RectDouble a      = new RectDouble((double)metrics.Left, (double)metrics.Top, (double)(metrics.Left + metrics.WidthMax), (double)(metrics.Top + metrics.Height));
            RectDouble b      = RectDouble.FromEdges((double)(metrics.Left - overhangMetrics.Left), (double)(metrics.Top - overhangMetrics.Top), (double)(metrics.LayoutWidth + overhangMetrics.Right), (double)(metrics.LayoutHeight + overhangMetrics.Bottom));
            RectInt32  num4   = RectDouble.Union(a, b).Int32Bound;
            IBitmap    bitmap = new PaintDotNet.Imaging.Bitmap(num4.Width, num4.Height, PixelFormats.Pbgra32, BitmapCreateCacheOption.CacheOnLoad);

            using (IDrawingContext context2 = DrawingContext.FromBitmap(bitmap, FactorySource.PerThread))
            {
                context2.Clear(null);
                using (context2.UseTranslateTransform((float)-num4.X, (float)-num4.Y, MatrixMultiplyOrder.Prepend))
                {
                    using (context2.UseTextRenderingMode(TextRenderingMode.Outline))
                    {
                        TextLayout textLayout = UIText.CreateLayout(context2, this.fontSampleText, fontProperties, (double)fontSize, null, HotkeyRenderMode.Ignore, 65535.0, 65535.0);
                        context2.TextAntialiasMode = TextAntialiasMode.Grayscale;
                        context2.DrawTextLayout(0.0, 0.0, textLayout, textBrush, DrawTextOptions.None);
                    }
                }
            }
            return(new PlacedBitmap(bitmap, b, true));
        }
예제 #4
0
        protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
        {
            SizeDouble        canvasSize = canvasView.CanvasSize;
            RectDouble        num2       = RectDouble.FromEdges(-131072.0, 0.0, 0.0, canvasSize.Height);
            RectDouble        num3       = RectDouble.FromEdges(-131072.0, -131072.0, 131072.0, 0.0);
            RectDouble        num4       = RectDouble.FromEdges(canvasSize.Width, 0.0, 131072.0, canvasSize.Height);
            RectDouble        num5       = RectDouble.FromEdges(-131072.0, canvasSize.Height, 131072.0, 131072.0);
            ColorRgba128Float num6       = (ThemeConfig.EffectiveTheme == PdnTheme.Aero) ? AeroColors.CanvasBackFillColor : ClassicColors.CanvasBackFillColor;

            dc.Clear((RectFloat)num2, AntialiasMode.Aliased, new ColorRgba128Float?(num6));
            dc.Clear((RectFloat)num3, AntialiasMode.Aliased, new ColorRgba128Float?(num6));
            dc.Clear((RectFloat)num4, AntialiasMode.Aliased, new ColorRgba128Float?(num6));
            dc.Clear((RectFloat)num5, AntialiasMode.Aliased, new ColorRgba128Float?(num6));
            base.OnRender(dc, clipRect, canvasView);
        }
예제 #5
0
        protected override SegmentedList <PointDouble> CreateShape(SegmentedList <PointDouble> tracePoints)
        {
            RectDouble        num3;
            double            num6;
            double            num7;
            PointDouble       a           = tracePoints[0];
            PointDouble       b           = tracePoints[tracePoints.Count - 1];
            SelectionDrawMode mode        = base.ToolSettings.Selection.DrawMode.Value;
            double            num4        = base.ToolSettings.Selection.DrawWidth.Value;
            double            num5        = base.ToolSettings.Selection.DrawHeight.Value;
            MeasurementUnit   sourceUnits = base.ToolSettings.Selection.DrawUnits.Value;

            switch (mode)
            {
            case SelectionDrawMode.FixedRatio:
            case SelectionDrawMode.FixedSize:
                num6 = Math.Abs(num4);
                num7 = Math.Abs(num5);
                break;

            default:
                num6 = num4;
                num7 = num5;
                break;
            }
            switch (mode)
            {
            case SelectionDrawMode.Normal:
                if ((base.ModifierKeys & Keys.Shift) == Keys.None)
                {
                    num3 = RectDoubleUtil.FromPixelPoints(a, b);
                    break;
                }
                num3 = RectDoubleUtil.FromPixelPointsConstrained(a, b);
                break;

            case SelectionDrawMode.FixedRatio:
                try
                {
                    double num13 = b.X - a.X;
                    double num14 = b.Y - a.Y;
                    double num15 = num13 / num6;
                    double num16 = Math.Sign(num15);
                    double num17 = num14 / num7;
                    double num18 = Math.Sign(num17);
                    double num19 = num6 / num7;
                    if (num15 < num17)
                    {
                        double x      = a.X;
                        double y      = a.Y;
                        double right  = a.X + num13;
                        double bottom = a.Y + (num18 * Math.Abs((double)(num13 / num19)));
                        num3 = RectDouble.FromEdges(x, y, right, bottom);
                    }
                    else
                    {
                        double left  = a.X;
                        double top   = a.Y;
                        double num26 = a.X + (num16 * Math.Abs((double)(num14 * num19)));
                        double num27 = a.Y + num14;
                        num3 = RectDouble.FromEdges(left, top, num26, num27);
                    }
                }
                catch (ArithmeticException)
                {
                    num3 = new RectDouble(a.X, a.Y, 0.0, 0.0);
                }
                break;

            case SelectionDrawMode.FixedSize:
            {
                double width  = Document.ConvertMeasurement(num6, sourceUnits, base.Document.DpuUnit, base.Document.DpuX, MeasurementUnit.Pixel);
                double height = Document.ConvertMeasurement(num7, sourceUnits, base.Document.DpuUnit, base.Document.DpuY, MeasurementUnit.Pixel);
                num3 = new RectDouble(b.X, b.Y, width, height);
                break;
            }

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <SelectionDrawMode>(mode, "drawMode");
            }
            RectDouble num8  = RectDouble.Intersect(num3, base.Document.Bounds());
            RectDouble num10 = num8.Int32Bound;

            if (num8.HasPositiveArea)
            {
                SegmentedList <PointDouble> list = new SegmentedList <PointDouble>(5, 7)
                {
                    new PointDouble(num10.Left, num10.Top),
                    new PointDouble(num10.Right, num10.Top),
                    new PointDouble(num10.Right, num10.Bottom),
                    new PointDouble(num10.Left, num10.Bottom)
                };
                list.Add(list[0]);
                return(list);
            }
            return(new SegmentedList <PointDouble>(0, 7));
        }