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)); }
public void ShowImageList(Item[] items) { this.HideImageList(); this.comboBox.Items.AddRange(items); using (IDrawingContext context = DrawingContext.CreateNull(FactorySource.PerThread)) { this.DetermineMaxItemSize(context, items, out this.itemSize, out this.maxImageSize); } this.comboBox.ItemHeight = this.itemSize.Height; this.comboBox.DropDownWidth = (this.itemSize.Width + SystemInformation.VerticalScrollBarWidth) + UIUtil.ScaleWidth(2); System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromControl(this); PointInt32 num = this.PointToScreen(new PointInt32(this.comboBox.Left, this.comboBox.Bottom)); int num2 = screen.WorkingArea.Height - num.Y; num2 = this.itemSize.Height * (num2 / this.itemSize.Height); num2 += 2; int num3 = 2 + (this.itemSize.Height * 3); int num4 = Math.Max(num2, num3); this.comboBox.DropDownHeight = num4; int num5 = Array.FindIndex <Item>(items, item => item.Selected); this.comboBox.SelectedIndex = num5; int x = this.PointToScreen(new PointInt32(0, base.Height)).X; if ((x + this.comboBox.DropDownWidth) > screen.WorkingArea.Right) { x = screen.WorkingArea.Right - this.comboBox.DropDownWidth; } PointInt32 num7 = this.PointToClient(new PointInt32(x, num.Y)); base.SuspendLayout(); this.comboBox.Left = num7.X; base.ResumeLayout(false); this.comboBox.Focus(); UIUtil.ShowComboBox(this.comboBox, true); }