public Dictionary<int, string> ConvertPages(string path, List<PairOfNumbers> pairs, Dpi dpi) { Dpi = dpi; CreateRasterizer(path); pageStore = new Dictionary<int, string>(); ManualResetEvent[] manualEvents = new ManualResetEvent[pairs.Count]; ThreadPool.SetMaxThreads(MaxThreads, MaxThreads); int number = 0; foreach (PairOfNumbers pair in pairs) { manualEvents[number] = new ManualResetEvent(false); WorkInfo workInfo = new WorkInfo(pair, path, manualEvents[number]); ThreadPool.QueueUserWorkItem(PdfProcessing, workInfo); number ++; } foreach (var manualEvent in manualEvents) { manualEvent.WaitOne(); } //WaitHandle.WaitAll(manualEvents); return pageStore; }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendLine("Compression=" + Compression.ToString()); sb.AppendLine("Dpi=" + Dpi.ToString()); sb.AppendLine("Enabled=" + Enabled.ToString()); sb.AppendLine("Resampling=" + Resampling.ToString()); return(sb.ToString()); }
private void AdjustHeight() { var h = (int)Math.Round( (double)((IView)FindForm()).Settings.Get <EnvironmentSettings>().Font.Height() + Dpi.GetHeight(4), MidpointRounding.AwayFromZero); if (Height != h) { Height = h; } }
private void Window_Loaded(object sender, RoutedEventArgs e) { this.systemDpi = this.window.GetSystemDpi(); this.hwndSource = PresentationSource.FromVisual(this.window) as HwndSource; if (this.hwndSource != null) { this.currentDpi = this.hwndSource.GetDpi(); this.ChangeDpi(this.currentDpi); this.hwndSource.AddHook(this.WndProc); this.window.Closed += this.Window_Closed; } }
private void ChangeDpi(Dpi dpi) { if (!PerMonitorDpi.IsSupported) { return; } this.DpiScaleTransform = dpi == this._systemDpi ? Transform.Identity : new ScaleTransform((double)dpi.X / this._systemDpi.X, (double)dpi.Y / this._systemDpi.Y); this.CurrentDpi = dpi; }
void StatusWindow_Loaded(object sender, RoutedEventArgs e) { AMing.Plugins.Core.Helper.ToolWindowHelper.SetToolWindow(this); Dpi dpi = this.GetSystemDpi() ?? Dpi.Default; this.Top = forms.Screen.PrimaryScreen.WorkingArea.Height / dpi.ScaleY - this.Height; this.Left = forms.Screen.PrimaryScreen.WorkingArea.Width / dpi.ScaleX - this.Width; //AMing.Plugins.Core.Helper.PenetrateHelper.SetPenetrate(this); //this.Opacity = 0.8; }
public static Dpi GetCurrentDpi() { var g = Graphics.FromHwnd(IntPtr.Zero); var desktop = g.GetHdc(); var dpi = new Dpi { HorizontalDpi = GetDeviceCaps(desktop, (int)DeviceCap.LOGPIXELSX), VerticalDpi = GetDeviceCaps(desktop, (int)DeviceCap.LOGPIXELSY) }; return(dpi); }
public static Rect GetScreenWpfBounds(Screen screen) { Dpi systemDpi = GetSystemDpi(); Rect wpfBounds = new Rect(screen.Bounds.X, screen.Bounds.Y, screen.Bounds.Width, screen.Bounds.Height); wpfBounds.X = wpfBounds.X * (double)Dpi.Default.X / (double)systemDpi.X; wpfBounds.Y = wpfBounds.Y * (double)Dpi.Default.Y / (double)systemDpi.Y; wpfBounds.Width = wpfBounds.Width * (double)Dpi.Default.X / (double)systemDpi.X; wpfBounds.Height = wpfBounds.Height * (double)Dpi.Default.Y / (double)systemDpi.Y; return(wpfBounds); }
public ViewForm() { editor = new StandardEditor(Settings.Get <EditorSettings>()); statusBar = new StatusBarControl(editor); commandBar = new CommandBarControl(editor); header = new HeaderControl(editor); Initialize(); if (!ReadState()) { Width = 800 * Dpi.GetWidth(1); Height = 600 * Dpi.GetWidth(1); } }
public D3DAngleInterop(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags) { _d3d9_interop = new D3D9Interop(); _dpi = new Dpi(); _control = new Control(); var win = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(_control.Handle); _window_info = OpenTK.Platform.Utilities.CreateAngleWindowInfo(win); _context = new GraphicsContext(mode, _window_info, major, minor, flags); _context.MakeCurrent(_window_info); _context.LoadAll(); }
private static double GetDpiMultiplier(Dpi dpi) { switch (dpi) { case Dpi.DPI200: return(1); case Dpi.DPI300: return(1.5); default: throw new NotImplementedException("Dpi não implementado!"); } }
private void SavePdfAnnotations(string fileName) { using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { PdfAnnotationDataExporter exp = new PdfAnnotationDataExporter(); System.Drawing.Size sz = this.AnnotationViewer.ImageViewer.Image.Size; SizeF pageSize = new SizeF(sz.Width, sz.Height); Dpi resolution = this.AnnotationViewer.ImageViewer.Image.Resolution; LayerData data = (LayerData)this.AnnotationViewer.Annotations.CurrentLayer.CreateDataSnapshot(); exp.ExportOver(fs, pageSize, AnnotationUnit.Pixel, resolution, data, 0); } }
private void LoadDefaultLayout() { int idx = 0, y = 43; for (var row = 0; row < 3; row++) { var x = 9; for (var col = 0; col < 3; col++) { bounds.Add(idx++, Dpi.ScaleRectangle(new Rectangle(x, y, 70, 70))); x += 76; } y += 76; } }
public override string ToString() { var sb = new StringBuilder(); sb.Append("ID: "); sb.AppendLine(MonitorId); sb.Append("DPI: "); sb.AppendLine(Dpi.ToString()); sb.Append("X: "); sb.AppendLine(LeftCoordinate.ToString()); sb.Append("Y: "); sb.AppendLine(TopCoordinate.ToString()); return(sb.ToString()); }
public override string ToString() { var sb = new StringBuilder(); sb.Append("ID: "); sb.AppendLine(Id); sb.Append("DPI: "); sb.AppendLine(Dpi.ToString()); sb.Append("X: "); sb.AppendLine(X.ToString()); sb.Append("Y: "); sb.AppendLine(Y.ToString()); return(sb.ToString()); }
//public void zSetMarginWidth(int margin, string textToMeasureWidth) { // int n = zStyleMeasureStringWidth(STYLE_LINENUMBER, textToMeasureWidth); // Call(SCI_SETMARGINWIDTHN, margin, n + 4); //} //not used //public int zGetMarginWidth(int margin, bool dpiUnscale) { // int R = Call(SCI_GETMARGINWIDTHN, margin); // if (dpiUnscale && R > 0) { // var a = _marginDpi; // var v = a?[margin] ?? 0; // if (v > 0) R = v; // } // return R; //} internal void zMarginWidthsDpiChanged_() { var a = _marginDpi; if (a == null) { return; } for (int i = a.Length; --i >= 0;) { if (a[i] > 0) { Call(SCI_SETMARGINWIDTHN, i, Dpi.Scale(a[i], _dpi)); } } }
public void WriteXml(XmlWriter writer) { writer.WriteAttributeString("DPI", Dpi.ToString()); if (Width.HasValue) { writer.WriteAttributeString("Width", Width.Value.ToString()); } if (Height.HasValue) { writer.WriteAttributeString("Height", Height.Value.ToString()); } if (!string.IsNullOrWhiteSpace(OutputDirectory)) { writer.WriteAttributeString("OutputDirectory", OutputDirectory); } }
private void ChangeDpi(Dpi dpi) { if (!PerMonitorDpi.IsSupported) { return; } this.DpiScaleTransform = (dpi == this.systemDpi) ? Transform.Identity : new ScaleTransform((double)dpi.X / this.systemDpi.X, (double)dpi.Y / this.systemDpi.Y); this.Width = this.Width * dpi.X / this.currentDpi.X; this.Height = this.Height * dpi.Y / this.currentDpi.Y; this.currentDpi = dpi; }
private static void main(string[] args) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); AppDomain.CurrentDomain.UnhandledException += unhandledException; Application.ThreadException += threadException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); _kernel.Load <CoreModule>(); _kernel.Load <DalModule>(); _kernel.Load <DownloaderModule>(); _kernel.Load <GuiModule>(); Dpi.Set(_kernel.Get <UiConfigRepository>().Config.UiScalePercent); var installer = _kernel.Get <Installer>(); installer.MtgjsonFileUpdated += mtgjsonFileUpdated; installer.BeginInstall += beginInstall; installer.EndInstall += endInstall; _kernel.Get <PriceDownloader>().PricesDownloaded += pricesDownloaded; var loader = _kernel.Get <GuiLoader>(); loader.AsyncRun(); TaskEx.Run(loader.AsyncConvertLegacyCardId).Wait(); var colorSchemeEditorForm = _kernel.Get <ColorSchemeEditor>(); colorSchemeEditorForm.SaveDirectory = AppDir.ColorSchemes; colorSchemeEditorForm.LoadCurrentColorScheme(); _kernel.Get <TooltipConfiguration>().Setup(); Application.AddMessageFilter(MessageFilter.Instance); var application = _kernel.Get <App>(); application.MigrateHistoryFiles(); application.CreateForm(); Application.Run(application); Application.RemoveMessageFilter(MessageFilter.Instance); application.CancelAllTasks(); }
public override string ToString() { var sb = new StringBuilder(); // using CultureInfo.InvariantCulture since this is internal data sb.Append("ID: "); sb.AppendLine(MonitorId); sb.Append("DPI: "); sb.AppendLine(Dpi.ToString(CultureInfo.InvariantCulture)); sb.Append("X: "); sb.AppendLine(LeftCoordinate.ToString(CultureInfo.InvariantCulture)); sb.Append("Y: "); sb.AppendLine(TopCoordinate.ToString(CultureInfo.InvariantCulture)); return(sb.ToString()); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); if (!PerMonitorDpiService.IsSupported) { return; } this.systemDpi = this.GetSystemDpi(); this.source = PresentationSource.FromVisual(this) as HwndSource; if (this.source != null) { this.currentDpi = this.source.GetDpi(); this.ChangeDpi(this.currentDpi); this.source.AddHook(this.WndProc); } }
private int AddButton(int x, int y, MessageButtons button, bool selected = false, bool cancel = false) { var but = new MessageButton(button, selected, cancel) { Top = y, Left = x }; but.ButtonClick += (o, e) => { ButtonClicked = e.Button; AllowClose = true; Close(); }; Controls.Add(but); but.Invalidate(); return(but.Width + Dpi.GetWidth(10)); }
public static string GetJpegSize(Dpi dpi) { int sleepInMs; if (dpi == Dpi.Standard) { sleepInMs = 12000; } else { sleepInMs = 35000; } (byte[] response, int byteRead) = SendMessage(GET_JPEG_SIZE, sleepInMs, 100); string responseStr = System.Text.Encoding.ASCII.GetString(response, 0, byteRead); return(responseStr); }
public unsafe NativeFont_(int dpi, bool bold, bool italic, int height = 0) { Api.LOGFONT m = default; Dpi.SystemParametersInfo(Api.SPI_GETICONTITLELOGFONT, sizeof(Api.LOGFONT), &m, dpi); if (bold) { m.lfWeight = 700; } if (italic) { m.lfItalic = 1; } if (height != 0) { m.lfHeight = -Math2.MulDiv(height, dpi, 72); } _h = Api.CreateFontIndirect(m); }
protected override void ZOnHandleCreated() { base.ZOnHandleCreated(); zStyleBackColor(Sci.STYLE_DEFAULT, 0xf8fff0); if (ZInitUseSystemFont) { zStyleFont(Sci.STYLE_DEFAULT); //Segoe UI 9 is narrower but taller than the default Verdana 8. Also tested Calibri 9, but Verdana looks better. } zStyleClearAll(); zSetMarginWidth(1, 0); SIZE z = ZInitBlankMargins; z = Dpi.Scale(z, this.Hwnd); Call(Sci.SCI_SETMARGINLEFT, 0, z.width); Call(Sci.SCI_SETMARGINRIGHT, 0, z.height); }
/// <summary> /// Takes screenshot of specified rectangle in screen, quantizes colors to make smaller, compresses, Base64 encodes and returns comment string like <c>" /*image:...*/"</c>. /// If fails, prints warning and returns null. /// </summary> public static string MakeScreenshotComment(RECT r, DpiOf dpi = default) { if (dpi != default) { int i = dpi.Dpi; if (i != 96) { r.Inflate((Dpi.Scale(r.Width, i) - r.Width) / 2, (Dpi.Scale(r.Height, i) - r.Height) / 2); } } try { var b = uiimage.capture(r); var a = Quantize(b, 16); var z = Convert2.BrotliCompress(a); return("/*image:" //+ "\r\n" //rejected + "WkJN" + Convert.ToBase64String(z) + "*/"); } catch (Exception e1) { print.warning("MakeScreenshotComment() failed. " + e1.ToStringWithoutStack()); return(null); } }
/// <summary> /// Draws the <see cref="BackgroundImage"/> property onto <see cref="MobileUserControl"/> /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (BackgroundImage == null) { return; } var image = BackgroundImage; if (AutoScaleBackgroundImage && Dpi.IsHiDpi) { image = ImageManipulator.Stretch(BackgroundImage, Dpi.ScaleSize(BackgroundImage.Size)); } var gfx = GraphicsEx.FromGraphics(e.Graphics); gfx.DrawImage(image, ClientSize, BackgroundDrawMode); }
internal protected virtual void ChangeDpi(IntPtr hWnd, Dpi dpi, RECT rect) { this.DpiScaleTransform = dpi == this.SystemDpi ? Transform.Identity : new ScaleTransform((double)dpi.X / this.SystemDpi.X, (double)dpi.Y / this.SystemDpi.Y); User32.SetWindowPos( hWnd, IntPtr.Zero, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOOWNERZORDER); var oldDpi = this.WindowDpi; this.WindowDpi = dpi; this.OnDpiChanged(oldDpi, dpi); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); this.source = PresentationSource.FromVisual(this) as HwndSource; if (this.source == null) { return; } this.systemDpi = this.GetSystemDpi() ?? Dpi.Default; if (PerMonitorDpi.IsSupported) { this.currentDpi = this.source.GetDpi(); this.ChangeDpi(this.currentDpi); this.source.AddHook(this.WndProc); } else { this.currentDpi = this.systemDpi; } if (this.WindowSettings == null) { this.WindowSettings = new WindowSettings(this); } if (this.IsRestoringWindowPlacement) { this.WindowSettings.Reload(); if (this.WindowSettings.Placement.HasValue) { var placement = this.WindowSettings.Placement.Value; placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); placement.flags = 0; placement.showCmd = (placement.showCmd == SW.SHOWMINIMIZED ? SW.SHOWNORMAL : placement.showCmd); NativeMethods.SetWindowPlacement(this.source.Handle, ref placement); } } }
protected override void OnPaint(PaintEventArgs e) { var theme = App.Component <ITheme>(); var g = e.Graphics; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.FillRectangle(theme.GetStyle(StandardStyle.PopupBorder).ForeColor.Brush(), ClientRectangle); g.FillRectangle(theme.GetStyle(StandardStyle.Popup).BackColor.Brush(), new Rectangle(ClientRectangle.X + Padding.Left, ClientRectangle.Y + Padding.Top, ClientRectangle.Width - Padding.Right - Padding.Left, ClientRectangle.Height - Padding.Top - Padding.Bottom)); var env = App.Component <IViewManager>().ActiveView.Settings.Get <EnvironmentSettings>(); var padx = Dpi.GetWidth(30); var pady = Dpi.GetWidth(20); using (var bigfont = new Font(env.FontName, env.FontSize + 3)) { var x = Padding.Left + padx; var y = Padding.Top + pady + 0f; var width = Width - Padding.Left - Padding.Right - padx * 2; var size = g.MeasureString(Caption, bigfont, width, TextFormats.Wrap); g.DrawString(Caption, bigfont, theme.GetStyle(StandardStyle.Keyword).ForeColor.Brush(), new RectangleF(x, y, width, Height), TextFormats.Wrap); y += size.Height + bigfont.Height; foreach (var str in Detail.Split('\n')) { size = g.MeasureString(str, env.Font, width, TextFormats.Wrap); g.DrawString(str, env.Font, theme.GetStyle(StandardStyle.Default).ForeColor.Brush(), new RectangleF(x, y, width, Height), TextFormats.Wrap); y += size.Height; } y += bigfont.Height; AddButtons(x, (int)y); } base.OnPaint(e); }
/// <summary> /// </summary> /// <param name="screen"></param> /// <returns></returns> public static float GetScreenScaleFromSystem(Screen screen) { float dpiScale; try { Dpi systemDPI = GetSystemDpi(); uint dpiXEffective, dpiYEffective; GetDpi(screen, DpiType.Effective, out dpiXEffective, out dpiYEffective); dpiScale = (float)dpiXEffective / (float)systemDPI.X; } catch (Exception) { // assume 1 in case the RAW cannot be retrieved dpiScale = 1.0F; } // todo: https://code.msdn.microsoft.com/windowsdesktop/Per-Monitor-Aware-WPF-e43cde33/sourcecode?fileId=102792&pathId=841375614 return(dpiScale); }
private static void CreateMillimiterGridBrush(Dpi dpi) { SizeF sizeMM = new SizeF(500.0f, 250.0f); Size sizePx = new Size(dpi.GetPxFromMM_X(sizeMM.Width), dpi.GetPxFromMM_Y(sizeMM.Height)); // 30.07.2011 (FK) PixelFormat.Format32bppPArgb by mel byt nejoptimalnejsi format bitmapy pro GDI+ _millimeterGridBitmap = new Bitmap(sizePx.Width, sizePx.Height, PixelFormat.Format32bppPArgb); _millimeterGridBitmap.SetResolution(dpi.DpiX, dpi.DpiY); using (Graphics bg = Graphics.FromImage(_millimeterGridBitmap)) { RectangleF gridRectMM = new RectangleF(PointF.Empty, sizeMM); bg.Clear(_gridBackgroundColor); bg.PageUnit = GraphicsUnit.Millimeter; bg.SmoothingMode = SmoothingMode.HighQuality; Pen gridPen1 = new Pen(Color.FromArgb(20, _gridColor), 0.0f); DrawGrid(bg, gridPen1, gridRectMM, 1.0f); bg.SmoothingMode = SmoothingMode.None; Pen gridPen5 = new Pen(Color.FromArgb(30, _gridColor), 0.0f); DrawGrid(bg, gridPen5, gridRectMM, 5.0f); Pen gridPen10 = new Pen(Color.FromArgb(40, _gridColor), 0.0f); DrawGrid(bg, gridPen10, gridRectMM, 10.0f); } // 30.07.2011 (FK) Texture brush je asi nejrychlejsi moznost jak kreslit vetsi plochy stejnou bitmapou v GDI+ // viz http://stackoverflow.com/questions/264720/gdi-graphicsdrawimage-really-slow _millimeterGridBrush = new TextureBrush(_millimeterGridBitmap, WrapMode.Tile); }
private void ChangeDpi(Dpi dpi) { if (!PerMonitorDpiService.IsSupported) return; this.DpiScaleTransform = (dpi == this.systemDpi) ? Transform.Identity : new ScaleTransform((double)dpi.X / this.systemDpi.X, (double)dpi.Y / this.systemDpi.Y); this.Width = this.Width * dpi.X / this.currentDpi.X; this.Height = this.Height * dpi.Y / this.currentDpi.Y; this.currentDpi = dpi; }
public static void DrawMillimeterGridInPixels(IGraphics g, Rectangle rectPx) { Dpi dpi = new Dpi(g.DpiX, g.DpiY); if (_millimeterGridBitmap == null) CreateMillimiterGridBrush(dpi); g.CompositingMode = CompositingMode.SourceCopy; _millimeterGridBrush.ResetTransform(); _millimeterGridBrush.TranslateTransform(rectPx.Left, rectPx.Top); g.FillRectangle(_millimeterGridBrush, rectPx); g.CompositingMode = CompositingMode.SourceOver; }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); if (!PerMonitorDpiService.IsSupported) return; this.systemDpi = this.GetSystemDpi(); this.source = PresentationSource.FromVisual(this) as HwndSource; if (this.source != null) { this.currentDpi = this.source.GetDpi(); this.ChangeDpi(this.currentDpi); this.source.AddHook(this.WndProc); } }
private string GetImagePath(string path, Dpi dpi) { string[] splitPath = path.Split('\\'); int len = splitPath.Length; string[] splitPathDpi = new string[len]; splitPath.CopyTo(splitPathDpi, 0); splitPathDpi[len - 1] = "drawable-" + dpi.ToString() + @"\" + splitPath[len - 1]; string fn = CancelSplitString(splitPathDpi); return fn; }