]> O.S.I.I.S - jp/crow.git/commitdiff
text run and fill rule in vkvg, bitmaps, non-zero fill rule for clipping solve lots...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 30 Apr 2019 22:36:26 +0000 (00:36 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 30 Apr 2019 22:36:26 +0000 (00:36 +0200)
12 files changed:
Crow/Crow.csproj
Crow/packages.config
Crow/src/BmpPicture.cs
Crow/src/Cairo/DrawingHelpers.cs
Crow/src/Gradient.cs
Crow/src/Interface.cs
Crow/src/SvgPicture.cs
Crow/src/vkvg/Context.cs
Crow/src/vkvg/Enums.cs
Crow/src/vkvg/NativeMethods.cs
Crow/src/vkvg/Pattern.cs
Crow/src/vkvg/TextRun.cs [new file with mode: 0644]

index 1fa7c4388e78fefb31f26980c1be0c56f93b0c73..ac334f25005f79c7287b212e02463cda43931373 100644 (file)
@@ -53,7 +53,7 @@
     <Reference Include="Microsoft.CSharp" />
     <Reference Include="System.Drawing" />
     <Reference Include="VK">
-      <HintPath>..\..\packages\Vulkan.0.1.2.5-alpha\lib\netstandard2.0\VK.dll</HintPath>
+      <HintPath>..\..\packages\Vulkan.0.1.2.6\lib\netstandard2.0\VK.dll</HintPath>
     </Reference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
index 16d6f60e18adab1469166e73204364189eaeec2d..b38bd1a124d5c222e969c4157d0a00e76ebaf76a 100644 (file)
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="Vulkan" version="0.1.2.5-alpha" targetFramework="net461" />
+  <package id="Vulkan" version="0.1.2.6" targetFramework="net461" />
 </packages>
\ No newline at end of file
index 76cd3439c2c16af4b2808cca01e57be76bc98829..b4080428ee21ead8f53b7bacd41a432e91345abb 100644 (file)
@@ -36,7 +36,7 @@ namespace Crow
        /// </summary>
        public class BmpPicture : Picture
        {
-               byte[] image = null;
+               Surface imgSurface;
 
                #region CTOR
                /// <summary>
@@ -49,46 +49,31 @@ namespace Crow
                /// </summary>
                /// <param name="path">image path, may be embedded</param>
                public BmpPicture (string path) : base(path)
-               {}
+               {
+                       Load ();
+               }
                #endregion
                /// <summary>
                /// load the image for rendering from the path given as argument
                /// </summary>
                /// <param name="path">image path, may be embedded</param>
                void Load ()
-               {                       
-                       if (sharedResources.ContainsKey (Path)) {
-                               sharedPicture sp = sharedResources [Path];
-                               image = (byte[])sp.Data;
-                               Dimensions = sp.Dims;
-                               return;
-                       }
-                       using (Stream stream = Interface.StaticGetStreamFromPath (Path)) {                              
-                               //loadBitmap (new System.Drawing.Bitmap (stream));      
-                       }
-                       sharedResources [Path] = new sharedPicture (image, Dimensions);
-               }
-
-               //load image via System.Drawing.Bitmap, cairo load png only
-               /*void loadBitmap (System.Drawing.Bitmap bitmap)
                {
-                       if (bitmap == null)
-                               return;
-
-                       System.Drawing.Imaging.BitmapData data = bitmap.LockBits
-                               (new System.Drawing.Rectangle (0, 0, bitmap.Width, bitmap.Height),
-                                       System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
-
-                       Dimensions = new Size (bitmap.Width, bitmap.Height);
-
-                       int stride = data.Stride;
-                       int bitmapSize = Math.Abs (data.Stride) * bitmap.Height;
-
-                       image = new byte[bitmapSize];
-                       System.Runtime.InteropServices.Marshal.Copy (data.Scan0, image, 0, bitmapSize);
+                       //if (sharedResources.ContainsKey (Path)) {
+                       //      sharedPicture sp = sharedResources [Path];
+                       //      image = (byte[])sp.Data;
+                       //      Dimensions = sp.Dims;
+                       //      return;
+                       //}
 
-                       bitmap.UnlockBits (data);           
-               }*/
+                       imgSurface = new Surface (Interface.CurrentInterface.dev, Path);
+                       Dimensions.Width = imgSurface.Width;
+                       Dimensions.Height = imgSurface.Height;
+                       //using (Stream stream = Interface.StaticGetStreamFromPath (Path)) {                            
+                       //      loadBitmap (new System.Drawing.Bitmap (stream));        
+                       //}
+                       //sharedResources [Path] = new sharedPicture (image, Dimensions);
+               }                       
 
                #region implemented abstract members of Fill
 
@@ -109,20 +94,16 @@ namespace Crow
                                        widthRatio = heightRatio;
                        }
 
-                       //using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) {
-                       //      using (Context gr = new Context (tmp)) {
-                       //              gr.Translate (bounds.Left, bounds.Top);
-                       //              gr.Scale (widthRatio, heightRatio);
-                       //              gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2);
-
-                       //              using (ImageSurface imgSurf = new ImageSurface (image, Format.Argb32, 
-                       //                      Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) {
-                       //                      gr.SetSourceSurface (imgSurf, 0,0);
-                       //                      gr.Paint ();
-                       //              }
-                       //      }
-                       //      ctx.SetSource (tmp);
-                       //}                             
+                       using (Surface tmp = new Surface (Interface.CurrentInterface.dev, bounds.Width, bounds.Height)) {
+                               using (Context gr = new Context (tmp)) {
+                                       gr.Translate (bounds.Left, bounds.Top);
+                                       gr.Scale (widthRatio, heightRatio);
+                                       gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2);
+                                       gr.SetSourceSurface (imgSurface, 0,0);
+                                       gr.Paint ();
+                               }
+                               ctx.SetSource (tmp);
+                       }                               
                }
                #endregion
 
@@ -155,12 +136,8 @@ namespace Crow
                        gr.Translate (rect.Left,rect.Top);
                        gr.Scale (widthRatio, heightRatio);
                        gr.Translate ((rect.Width/widthRatio - Dimensions.Width)/2, (rect.Height/heightRatio - Dimensions.Height)/2);
-                       
-                       //using (Surface imgSurf = new Surface (. image, Format.Argb32, 
-                       //      Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) {
-                       //      gr.SetSourceSurface (imgSurf, 0,0);
-                       //      gr.Paint ();
-                       //}
+                       gr.SetSourceSurface (imgSurface, 0,0);
+                       gr.Paint ();
                        gr.Restore ();
                }
        }
index 8fe7f62a3ed53e96d259e86d0ed0f34ab0630721..83bb10ccb4099e887762864a018826171d288d34 100644 (file)
@@ -91,6 +91,7 @@ namespace Crow {
             gr.LineTo(x + radius, y + height);
             gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI);
             gr.ClosePath();
+
             gr.Restore();
         }
         public static void StrokeRaisedRectangle(Context gr, Rectangle r, double width = 1)
index 25f662ed988625e1cded5a2f53644b011abb555b..64bd30efba48be796a381e5839b2f6a7281edd42 100644 (file)
@@ -39,6 +39,7 @@ namespace Crow
                        Oblic,
                        Radial
                }
+
                public class ColorStop
                {
                        public double Offset;
@@ -64,6 +65,7 @@ namespace Crow
                                return new ColorStop (-1, (Color)parts [0]);
                        }
                }
+
                public Gradient.Type GradientType = Type.Vertical;
 //             public double x0;
 //             public double y0;
@@ -81,29 +83,29 @@ namespace Crow
 
                public override void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle))
                {
-                       //Gradient grad = null;
-                       //switch (GradientType) {
-                       //case Type.Vertical:
-                       //      grad = new LinearGradient (bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
-                       //      break;
-                       //case Type.Horizontal:
-                       //      grad = new LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Top);
-                       //      break;
-                       //case Type.Oblic:
-                       //      grad = new LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
-                       //      break;
-                       //case Type.Radial:
-                       //      throw new NotImplementedException ();
-                       //}
-
-                       //foreach (ColorStop cs in Stops) {
-                       //      if (cs == null)
-                       //              continue;
-                       //      grad.AddColorStop (cs.Offset, cs.Color);
-                       //}
+                       Pattern grad = null;
+                       switch (GradientType) {
+                       case Type.Vertical:
+                               grad = Pattern.CreateLinearGradient (bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
+                               break;
+                       case Type.Horizontal:
+                               grad = Pattern.CreateLinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Top);
+                               break;
+                       case Type.Oblic:
+                               grad = Pattern.CreateLinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
+                               break;
+                       case Type.Radial:
+                               throw new NotImplementedException ();
+                       }
+
+                       foreach (ColorStop cs in Stops) {
+                               if (cs == null)
+                                       continue;
+                               grad.AddColorStop ((float)cs.Offset, cs.Color);
+                       }
                        
-                       //ctx.SetSource (grad);
-                       //grad.Dispose ();
+                       ctx.SetSource (grad);
+                       grad.Dispose ();
                }
                #endregion
 
index 36b3d9c68c15a23833dc649014354a1a4a97f009..df36403816ab75e0afe5e4bff8c072b2f547d619 100644 (file)
@@ -251,7 +251,7 @@ namespace Crow
                /// Each control need a ref to the root interface containing it, if not set in GraphicObject.currentInterface,
                /// the ref of this one will be stored in GraphicObject.currentInterface
                /// </summary>
-               protected static Interface CurrentInterface;
+               public static Interface CurrentInterface;
                Stopwatch lastClickTime = new Stopwatch();
                internal Widget armedClick;//store widget with double click on first click
                internal MouseButtonEventArgs armedClickEventArgs;
@@ -733,6 +733,7 @@ namespace Crow
                        clippingMeasure.StopCycle();
                        #endif
                }
+               Color clippingStrokeColor = Color.Magenta.AdjustAlpha(0.8);
                /// <summary>Clipping Rectangles drive the drawing process. For compositing, each object under a clip rectangle should be
                /// repainted. If it contains also clip rectangles, its cache will be update, or if not cached a full redraw will take place</summary>
                void processDrawing(){
@@ -781,8 +782,11 @@ namespace Crow
                                        //}
 
 #if DEBUG_CLIP_RECTANGLE
+                                       clippingStrokeColor.R += 0.1f;
+                                       if (clippingStrokeColor.R > 1f)
+                                               clippingStrokeColor.R = 0;
                                        ctx.LineWidth = 1;
-                                       clipping.stroke (ctx, Color.Magenta.AdjustAlpha (0.5));
+                                       clipping.stroke (ctx, clippingStrokeColor);
                                        ctx.Stroke ();
 #endif
                                        //clipping.stroke (ctx, new Color (1, 0, 0));
index cf7c39b0fa3afed0c68d0e140751d9cf069ab09a..96d42ac8b9479831070d5269f8f79f795dbcd22f 100644 (file)
@@ -140,10 +140,10 @@ namespace Crow
                        gr.Scale (widthRatio, heightRatio);
                        gr.Translate (((float)rect.Width/widthRatio - Dimensions.Width)/2f, ((float)rect.Height/heightRatio - Dimensions.Height)/2f);
 
-                       if (string.IsNullOrEmpty (subPart))
+                       /*if (string.IsNullOrEmpty (subPart))
                                hSVG.RenderCairo (gr);
                        else
-                               hSVG.RenderCairoSub (gr, "#" + subPart);
+                               hSVG.RenderCairoSub (gr, "#" + subPart);*/
                        
                        gr.Restore ();                  
                }
index 0cf3195e22ad90128cc1df55fe62e6cd411c341f..3186444f05ab65da46b69b885a282bdd1ae121c8 100644 (file)
@@ -63,6 +63,10 @@ namespace vkvg
                        set { NativeMethods.vkvg_set_operator (handle, value); }
                        get { return NativeMethods.vkvg_get_operator (handle); }
                }
+               public FillRule FillRule {
+                       set { NativeMethods.vkvg_set_fill_rule (handle, value); }
+                       get { return NativeMethods.vkvg_get_fill_rule (handle); }
+               }
                public FontExtents FontExtents {
                        get {
                                FontExtents f_extents;
@@ -79,6 +83,9 @@ namespace vkvg
                public void ShowText (string txt) {
                        NativeMethods.vkvg_show_text (handle, txt);
                }
+               public void ShowText (TextRun textRun) {
+                       NativeMethods.vkvg_show_text_run (handle, textRun.Handle);
+               }
                public void Save () {
                        NativeMethods.vkvg_save (handle);
                }
@@ -232,7 +239,7 @@ namespace vkvg
                        NativeMethods.vkvg_set_source_surface (handle, surf.Handle, x, y);
                }
 
-               private static byte[] TerminateUtf8(string s)
+               internal static byte[] TerminateUtf8(string s)
                {
                        // compute the byte count including the trailing \0
                        var byteCount = Encoding.UTF8.GetMaxByteCount(s.Length + 1);
index 44b0d087023f708240ca2963c94768b4fd24d4ff..f6fedd54052b542748cb3c66006fa1c154662a52 100644 (file)
@@ -136,4 +136,8 @@ namespace vkvg {
                Round,
                Bevel
        }
+       public enum FillRule {
+               EvenOdd,
+               NonZero,
+       }
 }
\ No newline at end of file
index e598170d68efc9c2f2a867827ca1b4e835c5bcac..7b6dfdf0abce4796bffbfe96dbf539a8e5348b47 100644 (file)
@@ -122,6 +122,10 @@ namespace vkvg
                internal static extern void vkvg_set_line_join (IntPtr ctx, LineJoin join);
                [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
                internal static extern void vkvg_set_operator (IntPtr ctx, Operator op);
+               [DllImport (libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern FillRule vkvg_get_fill_rule (IntPtr ctx);
+               [DllImport (libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_fill_rule (IntPtr ctx, FillRule fr);
                [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
                internal static extern Operator vkvg_get_operator (IntPtr ctx);
                [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
@@ -168,7 +172,7 @@ namespace vkvg
                [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
                internal static extern void vkvg_show_text_run (IntPtr ctx, IntPtr textRun);
                [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
-               internal static extern void vkvg_text_run_get_extents (IntPtr textRun);
+               internal static extern void vkvg_text_run_get_extents (IntPtr textRun, out TextExtents extents);
                #endregion
 
                #region Pattern
index f6746ffb9704ae31f6afe87f3d8db122b5529622..096a7e5a0d695a2c9d51e628cfaccb297e79c876 100644 (file)
@@ -78,6 +78,9 @@ namespace vkvg {
                public void AddColorStop (float offset, float r, float g, float b, float a = 1f) {
                        NativeMethods.vkvg_patter_add_color_stop (handle, offset, r, g, b, a);
                }
+               public void AddColorStop (float offset, Crow.Color c) {
+                       NativeMethods.vkvg_patter_add_color_stop (Handle, offset, (float)c.R, (float)c.G, (float)c.B, (float)c.A);
+               }
 
                #region IDisposable implementation
                public void Dispose () {
diff --git a/Crow/src/vkvg/TextRun.cs b/Crow/src/vkvg/TextRun.cs
new file mode 100644 (file)
index 0000000..e748d7f
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// TextRun.cs
+//
+// Author:
+//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2019 jp
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+namespace vkvg {
+       public class TextRun : IDisposable {
+
+               IntPtr handle = IntPtr.Zero;
+
+               #region CTORS & DTOR
+               protected TextRun(IntPtr handle) {
+                       this.handle = handle;
+               }
+               public TextRun(string text) {
+                       handle = NativeMethods.vkvg_text_run_create (handle, Context.TerminateUtf8(text));
+               }
+
+               ~TextRun() {
+                       Dispose (false);
+               }
+               #endregion
+
+               //public void AddReference () {
+               //      NativeMethods.vkvg_pattern_reference (handle);
+               //}
+               //public uint References () => NativeMethods.vkvg_pattern_get_reference_count (handle);
+
+               public IntPtr Handle { get { return handle; } }
+
+               public TextExtents Extents {
+                       get {
+                               TextExtents extents;
+                               NativeMethods.vkvg_text_run_get_extents (handle, out extents);
+                               return extents;
+                       }
+               }
+
+               #region IDisposable implementation
+               public void Dispose () {
+                       Dispose (true);
+                       GC.SuppressFinalize (this);
+               }
+
+               protected virtual void Dispose (bool disposing) {
+                       if (!disposing || handle == IntPtr.Zero)
+                               return;
+
+                       NativeMethods.vkvg_text_run_destroy (handle);
+                       handle = IntPtr.Zero;
+               }
+               #endregion
+       }
+}
\ No newline at end of file