From b25ad7a6e15a7284e40407377a1624747ffe42e5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Wed, 24 Nov 2021 23:50:38 +0100 Subject: IBackend instead of IDevice to bind to Interface --- Backends/CairoBackend/src/Device.cs | 98 +++---------------------------------- 1 file changed, 8 insertions(+), 90 deletions(-) (limited to 'Backends/CairoBackend/src/Device.cs') diff --git a/Backends/CairoBackend/src/Device.cs b/Backends/CairoBackend/src/Device.cs index c87b494b..2efe76ec 100644 --- a/Backends/CairoBackend/src/Device.cs +++ b/Backends/CairoBackend/src/Device.cs @@ -77,18 +77,9 @@ namespace Crow.CairoBackend } public class Device : IDevice { - /// Global font rendering settings for Cairo - FontOptions FontRenderingOptions; - /// Global font rendering settings for Cairo - Antialias Antialias = Antialias.Subpixel; public Device() { - FontRenderingOptions = new FontOptions (); - FontRenderingOptions.Antialias = Antialias.Subpixel; - FontRenderingOptions.HintMetrics = HintMetrics.On; - FontRenderingOptions.HintStyle = HintStyle.Full; - FontRenderingOptions.SubpixelOrder = SubpixelOrder.Default; } ~Device () @@ -106,87 +97,12 @@ namespace Crow.CairoBackend { throw new NotImplementedException(); } - public IRegion CreateRegion () => new Region (); - public virtual ISurface CreateSurface(int width, int height) - => new ImageSurface (Format.ARGB32, width, height); - public virtual ISurface CreateSurface(byte[] data, int width, int height) - => new ImageSurface (data, Format.ARGB32, width, height, 4 * width); - - public virtual ISurface CreateSurface (IntPtr nativeWindoPointer, int width, int height) { - switch (Environment.OSVersion.Platform) { - case PlatformID.Unix: - IntPtr disp = Glfw3.GetX11Display (); - IntPtr nativeWin = Glfw3.GetX11Window (nativeWindoPointer); - Int32 scr = Glfw3.GetX11DefaultScreen (disp); - IntPtr visual = Glfw3.GetX11DefaultVisual (disp, scr); - return new XlibSurface (disp, nativeWin, visual, width, height); - case PlatformID.Win32NT: - case PlatformID.Win32S: - case PlatformID.Win32Windows: - IntPtr hWin32 = Glfw3.GetWin32Window (nativeWindoPointer); - IntPtr hdc = Glfw3.GetWin32DC (hWin32); - return new Win32Surface (hdc); - } - throw new PlatformNotSupportedException ("Unable to create cairo surface."); - } - public virtual IContext CreateContext(ISurface surf) - { - Context gr = new Context (surf); - gr.FontOptions = FontRenderingOptions; - gr.Antialias = Antialias; - return gr; - } - public byte[] LoadBitmap (Stream stream, out Size dimensions) { - byte[] image; -#if STB_SHARP - StbImageSharp.ImageResult stbi = StbImageSharp.ImageResult.FromStream (stream, StbImageSharp.ColorComponents.RedGreenBlueAlpha); - image = new byte[stbi.Data.Length]; - //rgba to argb for cairo. - for (int i = 0; i < stbi.Data.Length; i += 4) { - image[i] = stbi.Data[i + 2]; - image[i + 1] = stbi.Data[i + 1]; - image[i + 2] = stbi.Data[i]; - image[i + 3] = stbi.Data[i + 3]; - } - dimensions = new Size (stbi.Width, stbi.Height); -#else - using (StbImage stbi = new StbImage (stream)) { - image = new byte [stbi.Size]; - for (int i = 0; i < stbi.Size; i+=4) { - //rgba to argb for cairo. ???? looks like bgra to me. - image [i] = Marshal.ReadByte (stbi.Handle, i + 2); - image [i + 1] = Marshal.ReadByte (stbi.Handle, i + 1); - image [i + 2] = Marshal.ReadByte (stbi.Handle, i); - image [i + 3] = Marshal.ReadByte (stbi.Handle, i + 3); - } - dimensions = new Size (stbi.Width, stbi.Height); - } -#endif - return image; - } - public ISvgHandle LoadSvg(Stream stream) - { - using (BinaryReader sr = new BinaryReader (stream)) - return new SvgHandle (sr.ReadBytes ((int)stream.Length)); - } - public ISvgHandle LoadSvg(string svgFragment) => - new SvgHandle (System.Text.Encoding.Unicode.GetBytes (svgFragment)); - - public IGradient CreateGradient (GradientType gradientType, Rectangle bounds) { - switch (gradientType) { - case GradientType.Vertical: - return new LinearGradient (bounds.Left, bounds.Top, bounds.Left, bounds.Bottom); - case GradientType.Horizontal: - return new LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Top); - case GradientType.Oblic: - return new LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); - case GradientType.Radial: - throw new NotImplementedException (); - } - return null; - } + + + + #endregion #region IDispose implementation @@ -198,8 +114,10 @@ namespace Crow.CairoBackend protected virtual void Dispose (bool disposing) { - if (disposing) - FontRenderingOptions.Dispose (); + if (disposing){ + + } + } #endregion } -- cgit v1.3.1-4-g156e