Пример #1
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));
        }
Пример #2
0
 public Item(System.Drawing.Image image, string name, bool selected)
 {
     this.image    = image;
     this.name     = name;
     this.selected = selected;
     if (image != null)
     {
         Surface cleanupObject = Surface.CopyFromGdipImage(this.image);
         using (BitmapProxy proxy = new BitmapProxy(cleanupObject.CreateAliasedImagingBitmap(), ObjectRefProxyOptions.AssumeOwnership))
         {
             proxy.AddCleanupObject(cleanupObject);
             this.deviceImage = new DeviceBitmap(proxy);
         }
     }
 }